ssh_agent_new:
  136|  1.31k|{
  137|  1.31k|    ssh_agent agent = NULL;
  138|       |
  139|  1.31k|    agent = calloc(1, sizeof(struct ssh_agent_struct));
  140|  1.31k|    if (agent == NULL) {
  ------------------
  |  Branch (140:9): [True: 0, False: 1.31k]
  ------------------
  141|      0|        return NULL;
  142|      0|    }
  143|       |
  144|  1.31k|    agent->count = 0;
  145|  1.31k|    agent->sock = ssh_socket_new(session);
  146|  1.31k|    if (agent->sock == NULL) {
  ------------------
  |  Branch (146:9): [True: 0, False: 1.31k]
  ------------------
  147|      0|        SAFE_FREE(agent);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  148|      0|        return NULL;
  149|      0|    }
  150|  1.31k|    agent->channel = NULL;
  151|  1.31k|    return agent;
  152|  1.31k|}
ssh_agent_close:
  221|  1.31k|{
  222|  1.31k|    if (agent == NULL) {
  ------------------
  |  Branch (222:9): [True: 0, False: 1.31k]
  ------------------
  223|      0|        return;
  224|      0|    }
  225|       |
  226|  1.31k|    ssh_socket_close(agent->sock);
  227|  1.31k|}
ssh_agent_free:
  230|  1.31k|{
  231|  1.31k|    if (agent) {
  ------------------
  |  Branch (231:9): [True: 1.31k, False: 0]
  ------------------
  232|  1.31k|        if (agent->ident) {
  ------------------
  |  Branch (232:13): [True: 0, False: 1.31k]
  ------------------
  233|      0|            SSH_BUFFER_FREE(agent->ident);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  234|      0|        }
  235|  1.31k|        if (agent->sock) {
  ------------------
  |  Branch (235:13): [True: 1.31k, False: 0]
  ------------------
  236|  1.31k|            ssh_agent_close(agent);
  237|  1.31k|            ssh_socket_free(agent->sock);
  238|  1.31k|        }
  239|       |        SAFE_FREE(agent);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  240|  1.31k|    }
  241|  1.31k|}

ssh_packet_userauth_success:
  336|    657|{
  337|    657|  struct ssh_crypto_struct *crypto = NULL;
  338|       |
  339|    657|  (void)packet;
  340|    657|  (void)type;
  341|    657|  (void)user;
  342|       |
  343|    657|  SSH_LOG(SSH_LOG_DEBUG, "Authentication successful");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  344|    657|  SSH_LOG(SSH_LOG_TRACE, "Received SSH_USERAUTH_SUCCESS");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  345|       |
  346|    657|  session->auth.state = SSH_AUTH_STATE_SUCCESS;
  347|    657|  session->session_state = SSH_SESSION_STATE_AUTHENTICATED;
  348|    657|  session->flags |= SSH_SESSION_FLAG_AUTHENTICATED;
  ------------------
  |  |   78|    657|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  349|       |
  350|    657|  crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
  351|    657|  if (crypto != NULL && crypto->delayed_compress_out) {
  ------------------
  |  Branch (351:7): [True: 657, False: 0]
  |  Branch (351:25): [True: 0, False: 657]
  ------------------
  352|      0|      SSH_LOG(SSH_LOG_DEBUG, "Enabling delayed compression OUT");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  353|      0|      crypto->do_compress_out = 1;
  354|      0|  }
  355|       |
  356|    657|  crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
  357|    657|  if (crypto != NULL && crypto->delayed_compress_in) {
  ------------------
  |  Branch (357:7): [True: 657, False: 0]
  |  Branch (357:25): [True: 0, False: 657]
  ------------------
  358|      0|      SSH_LOG(SSH_LOG_DEBUG, "Enabling delayed compression IN");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  359|      0|      crypto->do_compress_in = 1;
  360|      0|  }
  361|       |
  362|       |    /* Reset errors by previous authentication methods. */
  363|    657|    ssh_reset_error(session);
  364|    657|    session->auth.current_method = SSH_AUTH_METHOD_UNKNOWN;
  ------------------
  |  |  155|    657|#define SSH_AUTH_METHOD_UNKNOWN      0x0000u
  ------------------
  365|    657|  return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
  366|    657|}
ssh_userauth_none:
  515|    657|{
  516|    657|    int rc;
  517|       |
  518|    657|    switch (session->pending_call_state) {
  519|    657|        case SSH_PENDING_CALL_NONE:
  ------------------
  |  Branch (519:9): [True: 657, False: 0]
  ------------------
  520|    657|            break;
  521|      0|        case SSH_PENDING_CALL_AUTH_NONE:
  ------------------
  |  Branch (521:9): [True: 0, False: 657]
  ------------------
  522|      0|            goto pending;
  523|      0|        default:
  ------------------
  |  Branch (523:9): [True: 0, False: 657]
  ------------------
  524|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  525|      0|                          "Wrong state (%d) during pending SSH call",
  526|      0|                          session->pending_call_state);
  527|      0|            return SSH_AUTH_ERROR;
  528|    657|    }
  529|       |
  530|    657|    rc = ssh_userauth_request_service(session);
  531|    657|    if (rc == SSH_AGAIN) {
  ------------------
  |  |  318|    657|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (531:9): [True: 0, False: 657]
  ------------------
  532|      0|        return SSH_AUTH_AGAIN;
  533|    657|    } else if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (533:16): [True: 0, False: 657]
  ------------------
  534|      0|        return SSH_AUTH_ERROR;
  535|      0|    }
  536|       |
  537|       |    /* request */
  538|    657|    rc = ssh_buffer_pack(session->out_buffer, "bsss",
  ------------------
  |  |   50|  1.31k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  |  |  |  Branch (50:68): [True: 0, False: 657]
  |  |  ------------------
  ------------------
  539|    657|            SSH2_MSG_USERAUTH_REQUEST,
  540|    657|            username ? username : session->opts.username,
  541|    657|            "ssh-connection",
  542|    657|            "none"
  543|    657|            );
  544|    657|    if (rc < 0) {
  ------------------
  |  Branch (544:9): [True: 0, False: 657]
  ------------------
  545|      0|        goto fail;
  546|      0|    }
  547|       |
  548|    657|    session->auth.current_method = SSH_AUTH_METHOD_NONE;
  ------------------
  |  |  156|    657|#define SSH_AUTH_METHOD_NONE         0x0001u
  ------------------
  549|    657|    session->auth.state = SSH_AUTH_STATE_AUTH_NONE_SENT;
  550|    657|    session->pending_call_state = SSH_PENDING_CALL_AUTH_NONE;
  551|    657|    rc = ssh_packet_send(session);
  552|    657|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (552:9): [True: 0, False: 657]
  ------------------
  553|      0|        return SSH_AUTH_ERROR;
  554|      0|    }
  555|       |
  556|    657|pending:
  557|    657|    rc = ssh_userauth_get_response(session);
  558|    657|    if (rc != SSH_AUTH_AGAIN) {
  ------------------
  |  Branch (558:9): [True: 657, False: 0]
  ------------------
  559|    657|        session->pending_call_state = SSH_PENDING_CALL_NONE;
  560|    657|    }
  561|       |
  562|    657|    return rc;
  563|      0|fail:
  564|      0|    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  565|      0|    ssh_buffer_reinit(session->out_buffer);
  566|       |
  567|      0|    return SSH_AUTH_ERROR;
  568|    657|}
ssh_agent_state_free:
 1148|  1.31k|{
 1149|  1.31k|    struct ssh_agent_state_struct *state = data;
 1150|       |
 1151|  1.31k|    if (state) {
  ------------------
  |  Branch (1151:9): [True: 0, False: 1.31k]
  ------------------
 1152|       |        SSH_STRING_FREE_CHAR(state->comment);
  ------------------
  |  |  919|      0|    do { if ((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (919:14): [True: 0, False: 0]
  |  |  |  Branch (919:74): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1153|      0|        ssh_key_free(state->pubkey);
 1154|      0|        free(state);
 1155|      0|    }
 1156|  1.31k|}
auth.c:ssh_userauth_request_service:
   70|    657|{
   71|    657|    int rc;
   72|       |
   73|    657|    rc = ssh_service_request(session, "ssh-userauth");
   74|    657|    if ((rc != SSH_OK) && (rc != SSH_AGAIN)) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
                  if ((rc != SSH_OK) && (rc != SSH_AGAIN)) {
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (74:9): [True: 0, False: 657]
  |  Branch (74:27): [True: 0, False: 0]
  ------------------
   75|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   76|      0|                "Failed to request \"ssh-userauth\" service");
   77|      0|    }
   78|       |
   79|    657|    return rc;
   80|    657|}
auth.c:ssh_userauth_get_response:
  151|    657|{
  152|    657|    int rc = SSH_AUTH_ERROR;
  153|       |
  154|    657|    rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_USER,
  ------------------
  |  |  101|    657|#define SSH_TIMEOUT_USER -2
  ------------------
  155|    657|        ssh_auth_response_termination, session);
  156|    657|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (156:9): [True: 0, False: 657]
  ------------------
  157|      0|        return SSH_AUTH_ERROR;
  158|      0|    }
  159|    657|    if (!ssh_auth_response_termination(session)) {
  ------------------
  |  Branch (159:9): [True: 0, False: 657]
  ------------------
  160|      0|        return SSH_AUTH_AGAIN;
  161|      0|    }
  162|       |
  163|    657|    switch(session->auth.state) {
  ------------------
  |  Branch (163:12): [True: 657, False: 0]
  ------------------
  164|      0|        case SSH_AUTH_STATE_ERROR:
  ------------------
  |  Branch (164:9): [True: 0, False: 657]
  ------------------
  165|      0|            rc = SSH_AUTH_ERROR;
  166|      0|            break;
  167|      0|        case SSH_AUTH_STATE_FAILED:
  ------------------
  |  Branch (167:9): [True: 0, False: 657]
  ------------------
  168|      0|            rc = SSH_AUTH_DENIED;
  169|      0|            break;
  170|      0|        case SSH_AUTH_STATE_INFO:
  ------------------
  |  Branch (170:9): [True: 0, False: 657]
  ------------------
  171|      0|            rc = SSH_AUTH_INFO;
  172|      0|            break;
  173|      0|        case SSH_AUTH_STATE_PARTIAL:
  ------------------
  |  Branch (173:9): [True: 0, False: 657]
  ------------------
  174|      0|            rc = SSH_AUTH_PARTIAL;
  175|      0|            break;
  176|      0|        case SSH_AUTH_STATE_PK_OK:
  ------------------
  |  Branch (176:9): [True: 0, False: 657]
  ------------------
  177|    657|        case SSH_AUTH_STATE_SUCCESS:
  ------------------
  |  Branch (177:9): [True: 657, False: 0]
  ------------------
  178|    657|            rc = SSH_AUTH_SUCCESS;
  179|    657|            break;
  180|      0|        case SSH_AUTH_STATE_KBDINT_SENT:
  ------------------
  |  Branch (180:9): [True: 0, False: 657]
  ------------------
  181|      0|        case SSH_AUTH_STATE_GSSAPI_REQUEST_SENT:
  ------------------
  |  Branch (181:9): [True: 0, False: 657]
  ------------------
  182|      0|        case SSH_AUTH_STATE_GSSAPI_TOKEN:
  ------------------
  |  Branch (182:9): [True: 0, False: 657]
  ------------------
  183|      0|        case SSH_AUTH_STATE_GSSAPI_MIC_SENT:
  ------------------
  |  Branch (183:9): [True: 0, False: 657]
  ------------------
  184|      0|        case SSH_AUTH_STATE_GSSAPI_KEYEX_MIC_SENT:
  ------------------
  |  Branch (184:9): [True: 0, False: 657]
  ------------------
  185|      0|        case SSH_AUTH_STATE_PUBKEY_OFFER_SENT:
  ------------------
  |  Branch (185:9): [True: 0, False: 657]
  ------------------
  186|      0|        case SSH_AUTH_STATE_PUBKEY_AUTH_SENT:
  ------------------
  |  Branch (186:9): [True: 0, False: 657]
  ------------------
  187|      0|        case SSH_AUTH_STATE_PASSWORD_AUTH_SENT:
  ------------------
  |  Branch (187:9): [True: 0, False: 657]
  ------------------
  188|      0|        case SSH_AUTH_STATE_AUTH_NONE_SENT:
  ------------------
  |  Branch (188:9): [True: 0, False: 657]
  ------------------
  189|      0|        case SSH_AUTH_STATE_NONE:
  ------------------
  |  Branch (189:9): [True: 0, False: 657]
  ------------------
  190|       |            /* not reached */
  191|      0|            rc = SSH_AUTH_ERROR;
  192|      0|            break;
  193|    657|    }
  194|       |
  195|    657|    return rc;
  196|    657|}
auth.c:ssh_auth_response_termination:
   83|  2.62k|{
   84|  2.62k|    ssh_session session = (ssh_session)user;
   85|  2.62k|    switch (session->auth.state) {
   86|      0|        case SSH_AUTH_STATE_NONE:
  ------------------
  |  Branch (86:9): [True: 0, False: 2.62k]
  ------------------
   87|      0|        case SSH_AUTH_STATE_KBDINT_SENT:
  ------------------
  |  Branch (87:9): [True: 0, False: 2.62k]
  ------------------
   88|      0|        case SSH_AUTH_STATE_GSSAPI_REQUEST_SENT:
  ------------------
  |  Branch (88:9): [True: 0, False: 2.62k]
  ------------------
   89|      0|        case SSH_AUTH_STATE_GSSAPI_TOKEN:
  ------------------
  |  Branch (89:9): [True: 0, False: 2.62k]
  ------------------
   90|      0|        case SSH_AUTH_STATE_GSSAPI_MIC_SENT:
  ------------------
  |  Branch (90:9): [True: 0, False: 2.62k]
  ------------------
   91|      0|        case SSH_AUTH_STATE_GSSAPI_KEYEX_MIC_SENT:
  ------------------
  |  Branch (91:9): [True: 0, False: 2.62k]
  ------------------
   92|      0|        case SSH_AUTH_STATE_PUBKEY_AUTH_SENT:
  ------------------
  |  Branch (92:9): [True: 0, False: 2.62k]
  ------------------
   93|      0|        case SSH_AUTH_STATE_PUBKEY_OFFER_SENT:
  ------------------
  |  Branch (93:9): [True: 0, False: 2.62k]
  ------------------
   94|      0|        case SSH_AUTH_STATE_PASSWORD_AUTH_SENT:
  ------------------
  |  Branch (94:9): [True: 0, False: 2.62k]
  ------------------
   95|  1.31k|        case SSH_AUTH_STATE_AUTH_NONE_SENT:
  ------------------
  |  Branch (95:9): [True: 1.31k, False: 1.31k]
  ------------------
   96|  1.31k|            return 0;
   97|  1.31k|        default:
  ------------------
  |  Branch (97:9): [True: 1.31k, False: 1.31k]
  ------------------
   98|  1.31k|            return 1;
   99|  2.62k|    }
  100|  2.62k|}

base64_to_bin:
   64|    657|{
   65|    657|    ssh_buffer buffer = NULL;
   66|    657|    unsigned char block[3];
   67|    657|    char *base64 = NULL;
   68|    657|    char *ptr = NULL;
   69|    657|    size_t len;
   70|    657|    int equals;
   71|       |
   72|    657|    base64 = strdup(source);
   73|    657|    if (base64 == NULL) {
  ------------------
  |  Branch (73:9): [True: 0, False: 657]
  ------------------
   74|      0|        return NULL;
   75|      0|    }
   76|    657|    ptr = base64;
   77|       |
   78|       |    /* Get the number of equals signs, which mirrors the padding */
   79|    657|    equals = get_equals(ptr);
   80|    657|    if (equals > 2) {
  ------------------
  |  Branch (80:9): [True: 0, False: 657]
  ------------------
   81|      0|        SAFE_FREE(base64);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
   82|      0|        return NULL;
   83|      0|    }
   84|       |
   85|    657|    buffer = ssh_buffer_new();
   86|    657|    if (buffer == NULL) {
  ------------------
  |  Branch (86:9): [True: 0, False: 657]
  ------------------
   87|      0|        SAFE_FREE(base64);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
   88|      0|        return NULL;
   89|      0|    }
   90|       |    /*
   91|       |     * The base64 buffer often contains sensitive data. Make sure we don't leak
   92|       |     * sensitive data
   93|       |     */
   94|    657|    ssh_buffer_set_secure(buffer);
   95|       |
   96|    657|    len = strlen(ptr);
   97|  55.1k|    while (len > 4) {
  ------------------
  |  Branch (97:12): [True: 54.5k, False: 657]
  ------------------
   98|  54.5k|        if (_base64_to_bin(block, ptr, 3) < 0) {
  ------------------
  |  Branch (98:13): [True: 0, False: 54.5k]
  ------------------
   99|      0|            goto error;
  100|      0|        }
  101|  54.5k|        if (ssh_buffer_add_data(buffer, block, 3) < 0) {
  ------------------
  |  Branch (101:13): [True: 0, False: 54.5k]
  ------------------
  102|      0|            goto error;
  103|      0|        }
  104|  54.5k|        len -= 4;
  105|  54.5k|        ptr += 4;
  106|  54.5k|    }
  107|       |
  108|       |    /*
  109|       |     * Depending on the number of bytes resting, there are 3 possibilities
  110|       |     * from the RFC.
  111|       |     */
  112|    657|    switch (len) {
  113|       |    /*
  114|       |     * (1) The final quantum of encoding input is an integral multiple of
  115|       |     *     24 bits. Here, the final unit of encoded output will be an integral
  116|       |     *     multiple of 4 characters with no "=" padding
  117|       |     */
  118|      0|    case 4:
  ------------------
  |  Branch (118:5): [True: 0, False: 657]
  ------------------
  119|      0|        if (equals != 0) {
  ------------------
  |  Branch (119:13): [True: 0, False: 0]
  ------------------
  120|      0|            goto error;
  121|      0|        }
  122|      0|        if (_base64_to_bin(block, ptr, 3) < 0) {
  ------------------
  |  Branch (122:13): [True: 0, False: 0]
  ------------------
  123|      0|            goto error;
  124|      0|        }
  125|      0|        if (ssh_buffer_add_data(buffer, block, 3) < 0) {
  ------------------
  |  Branch (125:13): [True: 0, False: 0]
  ------------------
  126|      0|            goto error;
  127|      0|        }
  128|      0|        SAFE_FREE(base64);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  129|       |
  130|      0|        return buffer;
  131|       |    /*
  132|       |     * (2) The final quantum of encoding input is exactly 8 bits; here, the
  133|       |     *     final unit of encoded output will be two characters followed by
  134|       |     *     two "=" padding characters.
  135|       |     */
  136|    657|    case 2:
  ------------------
  |  Branch (136:5): [True: 657, False: 0]
  ------------------
  137|    657|        if (equals != 2) {
  ------------------
  |  Branch (137:13): [True: 0, False: 657]
  ------------------
  138|      0|            goto error;
  139|      0|        }
  140|       |
  141|    657|        if (_base64_to_bin(block, ptr, 1) < 0) {
  ------------------
  |  Branch (141:13): [True: 0, False: 657]
  ------------------
  142|      0|            goto error;
  143|      0|        }
  144|    657|        if (ssh_buffer_add_data(buffer, block, 1) < 0) {
  ------------------
  |  Branch (144:13): [True: 0, False: 657]
  ------------------
  145|      0|            goto error;
  146|      0|        }
  147|    657|        SAFE_FREE(base64);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  148|       |
  149|    657|        return buffer;
  150|       |    /*
  151|       |     * The final quantum of encoding input is exactly 16 bits. Here, the final
  152|       |     * unit of encoded output will be three characters followed by one "="
  153|       |     * padding character.
  154|       |     */
  155|      0|    case 3:
  ------------------
  |  Branch (155:5): [True: 0, False: 657]
  ------------------
  156|      0|        if (equals != 1) {
  ------------------
  |  Branch (156:13): [True: 0, False: 0]
  ------------------
  157|      0|            goto error;
  158|      0|        }
  159|      0|        if (_base64_to_bin(block, ptr, 2) < 0) {
  ------------------
  |  Branch (159:13): [True: 0, False: 0]
  ------------------
  160|      0|            goto error;
  161|      0|        }
  162|      0|        if (ssh_buffer_add_data(buffer, block, 2) < 0) {
  ------------------
  |  Branch (162:13): [True: 0, False: 0]
  ------------------
  163|      0|            goto error;
  164|      0|        }
  165|      0|        SAFE_FREE(base64);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  166|       |
  167|      0|        return buffer;
  168|      0|    default:
  ------------------
  |  Branch (168:5): [True: 0, False: 657]
  ------------------
  169|       |        /* 4,3,2 are the only padding size allowed */
  170|      0|        goto error;
  171|    657|    }
  172|       |
  173|      0|error:
  174|      0|    SAFE_FREE(base64);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  175|      0|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  176|       |    return NULL;
  177|    657|}
base64.c:_base64_to_bin:
  216|  55.1k|{
  217|  55.1k|    unsigned long block;
  218|       |
  219|  55.1k|    if (to_block4(&block, source, num) < 0) {
  ------------------
  |  Branch (219:9): [True: 0, False: 55.1k]
  ------------------
  220|      0|        return -1;
  221|      0|    }
  222|  55.1k|    dest[0] = GET_A(block);
  ------------------
  |  |   46|  55.1k|#define GET_A(n) (unsigned char) (((n) & 0xff0000) >> 16)
  ------------------
  223|  55.1k|    dest[1] = GET_B(block);
  ------------------
  |  |   47|  55.1k|#define GET_B(n) (unsigned char) (((n) & 0xff00) >> 8)
  ------------------
  224|  55.1k|    dest[2] = GET_C(block);
  ------------------
  |  |   48|  55.1k|#define GET_C(n) (unsigned char) ((n) & 0xff)
  ------------------
  225|       |
  226|  55.1k|    return 0;
  227|  55.1k|}
base64.c:to_block4:
  187|  55.1k|{
  188|  55.1k|    const char *ptr = NULL;
  189|  55.1k|    size_t i;
  190|       |
  191|  55.1k|    *block = 0;
  192|  55.1k|    if (num < 1) {
  ------------------
  |  Branch (192:9): [True: 0, False: 55.1k]
  ------------------
  193|      0|        return 0;
  194|      0|    }
  195|       |
  196|  55.1k|    BLOCK(A, 0); /* 6 bit */
  ------------------
  |  |  179|  55.1k|#define BLOCK(letter, n) do {ptr = strchr((const char *)alphabet, source[n]); \
  |  |  180|  55.1k|                             if(!ptr) return -1; \
  |  |  ------------------
  |  |  |  Branch (180:33): [True: 0, False: 55.1k]
  |  |  ------------------
  |  |  181|  55.1k|                             i = ptr - (const char *)alphabet; \
  |  |  182|  55.1k|                             SET_##letter(*block, i); \
  |  |  ------------------
  |  |  |  |   41|  55.1k|#define SET_A(n, i) do { (n) |= ((i) & 63) <<18; } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (41:59): [Folded, False: 55.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  55.1k|                         } while(0)
  |  |  ------------------
  |  |  |  Branch (183:34): [Folded, False: 55.1k]
  |  |  ------------------
  ------------------
  197|  55.1k|    BLOCK(B, 1); /* 12 bit */
  ------------------
  |  |  179|  55.1k|#define BLOCK(letter, n) do {ptr = strchr((const char *)alphabet, source[n]); \
  |  |  180|  55.1k|                             if(!ptr) return -1; \
  |  |  ------------------
  |  |  |  Branch (180:33): [True: 0, False: 55.1k]
  |  |  ------------------
  |  |  181|  55.1k|                             i = ptr - (const char *)alphabet; \
  |  |  182|  55.1k|                             SET_##letter(*block, i); \
  |  |  ------------------
  |  |  |  |   42|  55.1k|#define SET_B(n, i) do { (n) |= ((i) & 63) <<12; } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (42:59): [Folded, False: 55.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  55.1k|                         } while(0)
  |  |  ------------------
  |  |  |  Branch (183:34): [Folded, False: 55.1k]
  |  |  ------------------
  ------------------
  198|       |
  199|  55.1k|    if (num < 2) {
  ------------------
  |  Branch (199:9): [True: 657, False: 54.5k]
  ------------------
  200|    657|        return 0;
  201|    657|    }
  202|       |
  203|  54.5k|    BLOCK(C, 2); /* 18 bit */
  ------------------
  |  |  179|  54.5k|#define BLOCK(letter, n) do {ptr = strchr((const char *)alphabet, source[n]); \
  |  |  180|  54.5k|                             if(!ptr) return -1; \
  |  |  ------------------
  |  |  |  Branch (180:33): [True: 0, False: 54.5k]
  |  |  ------------------
  |  |  181|  54.5k|                             i = ptr - (const char *)alphabet; \
  |  |  182|  54.5k|                             SET_##letter(*block, i); \
  |  |  ------------------
  |  |  |  |   43|  54.5k|#define SET_C(n, i) do { (n) |= ((i) & 63) << 6; } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:59): [Folded, False: 54.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  54.5k|                         } while(0)
  |  |  ------------------
  |  |  |  Branch (183:34): [Folded, False: 54.5k]
  |  |  ------------------
  ------------------
  204|       |
  205|  54.5k|    if (num < 3) {
  ------------------
  |  Branch (205:9): [True: 0, False: 54.5k]
  ------------------
  206|      0|        return 0;
  207|      0|    }
  208|       |
  209|  54.5k|    BLOCK(D, 3); /* 24 bit */
  ------------------
  |  |  179|  54.5k|#define BLOCK(letter, n) do {ptr = strchr((const char *)alphabet, source[n]); \
  |  |  180|  54.5k|                             if(!ptr) return -1; \
  |  |  ------------------
  |  |  |  Branch (180:33): [True: 0, False: 54.5k]
  |  |  ------------------
  |  |  181|  54.5k|                             i = ptr - (const char *)alphabet; \
  |  |  182|  54.5k|                             SET_##letter(*block, i); \
  |  |  ------------------
  |  |  |  |   44|  54.5k|#define SET_D(n, i) do { (n) |= ((i) & 63); } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (44:54): [Folded, False: 54.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  54.5k|                         } while(0)
  |  |  ------------------
  |  |  |  Branch (183:34): [Folded, False: 54.5k]
  |  |  ------------------
  ------------------
  210|       |
  211|  54.5k|    return 0;
  212|  54.5k|}
base64.c:get_equals:
  231|    657|{
  232|    657|    char *ptr = string;
  233|    657|    int num = 0;
  234|       |
  235|  1.97k|    while ((ptr = strchr(ptr, '=')) != NULL) {
  ------------------
  |  Branch (235:12): [True: 1.31k, False: 657]
  ------------------
  236|  1.31k|        num++;
  237|  1.31k|        *ptr = '\0';
  238|  1.31k|        ptr++;
  239|  1.31k|    }
  240|       |
  241|    657|    return num;
  242|    657|}

ssh_bind_new:
  136|    657|{
  137|    657|    ssh_bind ptr = NULL;
  138|       |
  139|    657|    ptr = calloc(1, sizeof(struct ssh_bind_struct));
  140|    657|    if (ptr == NULL) {
  ------------------
  |  Branch (140:9): [True: 0, False: 657]
  ------------------
  141|      0|        return NULL;
  142|      0|    }
  143|    657|    ptr->bindfd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|    657|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  144|    657|    ptr->bindport = 22;
  145|    657|    ptr->common.log_verbosity = 0;
  146|       |
  147|    657|    return ptr;
  148|    657|}
ssh_bind_free:
  372|    657|void ssh_bind_free(ssh_bind sshbind){
  373|    657|  int i;
  374|       |
  375|    657|  if (sshbind == NULL) {
  ------------------
  |  Branch (375:7): [True: 0, False: 657]
  ------------------
  376|      0|    return;
  377|      0|  }
  378|       |
  379|    657|  if (sshbind->bindfd >= 0) {
  ------------------
  |  Branch (379:7): [True: 0, False: 657]
  ------------------
  380|      0|      CLOSE_SOCKET(sshbind->bindfd);
  ------------------
  |  |  472|      0|#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |               #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  199|      0|#define _XCLOSESOCKET close
  |  |  ------------------
  |  |               #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |  |  Branch (472:34): [True: 0, False: 0]
  |  |  |  Branch (472:116): [Folded, False: 0]
  |  |  ------------------
  ------------------
  381|      0|  }
  382|    657|  sshbind->bindfd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|    657|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  383|       |
  384|       |  /* options */
  385|    657|  SAFE_FREE(sshbind->banner);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  386|    657|  SAFE_FREE(sshbind->moduli_file);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  387|    657|  SAFE_FREE(sshbind->bindaddr);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  388|    657|  SAFE_FREE(sshbind->config_dir);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  389|    657|  SAFE_FREE(sshbind->pubkey_accepted_key_types);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  390|       |
  391|    657|  SAFE_FREE(sshbind->rsakey);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  392|    657|  SAFE_FREE(sshbind->ecdsakey);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  393|    657|  SAFE_FREE(sshbind->ed25519key);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  394|    657|  SAFE_FREE(sshbind->gssapi_key_exchange_algs);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  395|       |
  396|    657|  ssh_key_free(sshbind->rsa);
  397|    657|  sshbind->rsa = NULL;
  398|    657|  ssh_key_free(sshbind->ecdsa);
  399|    657|  sshbind->ecdsa = NULL;
  400|    657|  ssh_key_free(sshbind->ed25519);
  401|    657|  sshbind->ed25519 = NULL;
  402|       |
  403|  7.22k|  for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  7.22k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (403:15): [True: 6.57k, False: 657]
  ------------------
  404|  6.57k|    if (sshbind->wanted_methods[i]) {
  ------------------
  |  Branch (404:9): [True: 2.62k, False: 3.94k]
  ------------------
  405|  2.62k|      SAFE_FREE(sshbind->wanted_methods[i]);
  ------------------
  |  |  373|  2.62k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.62k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.62k]
  |  |  ------------------
  ------------------
  406|  2.62k|    }
  407|  6.57k|  }
  408|       |
  409|       |  SAFE_FREE(sshbind);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  410|    657|}
ssh_bind_accept_fd:
  413|    657|{
  414|    657|    ssh_poll_handle handle = NULL;
  415|    657|    int i, rc;
  416|       |
  417|    657|    if (sshbind == NULL) {
  ------------------
  |  Branch (417:9): [True: 0, False: 657]
  ------------------
  418|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  419|      0|    }
  420|       |
  421|    657|    if (session == NULL){
  ------------------
  |  Branch (421:9): [True: 0, False: 657]
  ------------------
  422|      0|        ssh_set_error(sshbind, SSH_FATAL,"session is null");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  423|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  424|      0|    }
  425|       |
  426|    657|    session->server = 1;
  427|       |
  428|       |    /* Copy options from bind to session */
  429|  7.22k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  7.22k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (429:17): [True: 6.57k, False: 657]
  ------------------
  430|  6.57k|      if (sshbind->wanted_methods[i]) {
  ------------------
  |  Branch (430:11): [True: 2.62k, False: 3.94k]
  ------------------
  431|  2.62k|        session->opts.wanted_methods[i] = strdup(sshbind->wanted_methods[i]);
  432|  2.62k|        if (session->opts.wanted_methods[i] == NULL) {
  ------------------
  |  Branch (432:13): [True: 0, False: 2.62k]
  ------------------
  433|      0|          return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  434|      0|        }
  435|  2.62k|      }
  436|  6.57k|    }
  437|       |
  438|    657|    if (sshbind->bindaddr == NULL)
  ------------------
  |  Branch (438:9): [True: 657, False: 0]
  ------------------
  439|    657|      session->opts.bindaddr = NULL;
  440|      0|    else {
  441|      0|      SAFE_FREE(session->opts.bindaddr);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  442|      0|      session->opts.bindaddr = strdup(sshbind->bindaddr);
  443|      0|      if (session->opts.bindaddr == NULL) {
  ------------------
  |  Branch (443:11): [True: 0, False: 0]
  ------------------
  444|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  445|      0|      }
  446|      0|    }
  447|       |
  448|    657|    if (sshbind->pubkey_accepted_key_types != NULL) {
  ------------------
  |  Branch (448:9): [True: 0, False: 657]
  ------------------
  449|      0|        if (session->opts.pubkey_accepted_types == NULL) {
  ------------------
  |  Branch (449:13): [True: 0, False: 0]
  ------------------
  450|      0|            session->opts.pubkey_accepted_types = strdup(sshbind->pubkey_accepted_key_types);
  451|      0|            if (session->opts.pubkey_accepted_types == NULL) {
  ------------------
  |  Branch (451:17): [True: 0, False: 0]
  ------------------
  452|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  453|      0|                return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  454|      0|            }
  455|      0|        } else {
  456|      0|            char *p = NULL;
  457|       |            /* If something was set to the session prior to calling this
  458|       |             * function, keep only what is allowed by the options set in
  459|       |             * sshbind */
  460|      0|            p = ssh_find_all_matching(sshbind->pubkey_accepted_key_types,
  461|      0|                                      session->opts.pubkey_accepted_types);
  462|      0|            if (p == NULL) {
  ------------------
  |  Branch (462:17): [True: 0, False: 0]
  ------------------
  463|      0|                return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  464|      0|            }
  465|       |
  466|      0|            SAFE_FREE(session->opts.pubkey_accepted_types);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  467|      0|            session->opts.pubkey_accepted_types = p;
  468|      0|        }
  469|      0|    }
  470|       |
  471|    657|    session->common.log_verbosity = sshbind->common.log_verbosity;
  472|    657|    session->opts.gssapi_key_exchange = sshbind->gssapi_key_exchange;
  473|       |
  474|    657|    if (sshbind->gssapi_key_exchange_algs != NULL) {
  ------------------
  |  Branch (474:9): [True: 0, False: 657]
  ------------------
  475|      0|        SAFE_FREE(session->opts.gssapi_key_exchange_algs);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  476|      0|        session->opts.gssapi_key_exchange_algs =
  477|      0|            strdup(sshbind->gssapi_key_exchange_algs);
  478|      0|        if (session->opts.gssapi_key_exchange_algs == NULL) {
  ------------------
  |  Branch (478:13): [True: 0, False: 0]
  ------------------
  479|      0|            ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  480|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  481|      0|        }
  482|      0|    }
  483|       |
  484|    657|    if (sshbind->banner != NULL) {
  ------------------
  |  Branch (484:9): [True: 0, False: 657]
  ------------------
  485|      0|        session->server_opts.custombanner = strdup(sshbind->banner);
  486|      0|        if (session->server_opts.custombanner == NULL) {
  ------------------
  |  Branch (486:13): [True: 0, False: 0]
  ------------------
  487|      0|            ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  488|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  489|      0|        }
  490|      0|    }
  491|       |
  492|    657|    if (sshbind->moduli_file != NULL) {
  ------------------
  |  Branch (492:9): [True: 0, False: 657]
  ------------------
  493|      0|        session->server_opts.moduli_file = strdup(sshbind->moduli_file);
  494|      0|        if (session->server_opts.moduli_file == NULL) {
  ------------------
  |  Branch (494:13): [True: 0, False: 0]
  ------------------
  495|      0|            ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  496|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  497|      0|        }
  498|      0|    }
  499|       |
  500|    657|    session->opts.rsa_min_size = sshbind->rsa_min_size;
  501|       |
  502|    657|    ssh_socket_free(session->socket);
  503|    657|    session->socket = ssh_socket_new(session);
  504|    657|    if (session->socket == NULL) {
  ------------------
  |  Branch (504:9): [True: 0, False: 657]
  ------------------
  505|       |      /* perhaps it may be better to copy the error from session to sshbind */
  506|      0|      ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  507|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  508|      0|    }
  509|    657|    rc = ssh_socket_set_fd(session->socket, fd);
  510|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (510:9): [True: 0, False: 657]
  ------------------
  511|      0|        return rc;
  512|      0|    }
  513|    657|    handle = ssh_socket_get_poll_handle(session->socket);
  514|    657|    if (handle == NULL) {
  ------------------
  |  Branch (514:9): [True: 0, False: 657]
  ------------------
  515|      0|        ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  516|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  517|      0|    }
  518|    657|    ssh_socket_set_connected(session->socket, handle);
  519|       |
  520|       |    /* We must try to import any keys that could be imported in case
  521|       |     * we are not using ssh_bind_listen (which is the other place
  522|       |     * where keys can be imported) on this ssh_bind and are instead
  523|       |     * only using ssh_bind_accept_fd to manage sockets ourselves.
  524|       |     */
  525|    657|    if (sshbind->rsa == NULL &&
  ------------------
  |  Branch (525:9): [True: 657, False: 0]
  ------------------
  526|    657|        sshbind->ecdsa == NULL &&
  ------------------
  |  Branch (526:9): [True: 657, False: 0]
  ------------------
  527|    657|        sshbind->ed25519 == NULL) {
  ------------------
  |  Branch (527:9): [True: 0, False: 657]
  ------------------
  528|      0|        rc = ssh_bind_import_keys(sshbind);
  529|      0|        if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (529:13): [True: 0, False: 0]
  ------------------
  530|      0|            if (!sshbind->gssapi_key_exchange) {
  ------------------
  |  Branch (530:17): [True: 0, False: 0]
  ------------------
  531|      0|                ssh_set_error(sshbind, SSH_FATAL, "No usable hostkeys found");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  532|      0|                return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  533|      0|            }
  534|      0|            SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  535|      0|                    "No usable hostkeys found: Using \"null\" hostkey algorithm");
  536|      0|        }
  537|      0|    }
  538|       |
  539|    657|#ifdef HAVE_ECC
  540|    657|    if (sshbind->ecdsa) {
  ------------------
  |  Branch (540:9): [True: 0, False: 657]
  ------------------
  541|      0|        session->srv.ecdsa_key = ssh_key_dup(sshbind->ecdsa);
  542|      0|        if (session->srv.ecdsa_key == NULL) {
  ------------------
  |  Branch (542:13): [True: 0, False: 0]
  ------------------
  543|      0|          ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  544|      0|          return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  545|      0|        }
  546|      0|    }
  547|    657|#endif
  548|    657|    if (sshbind->rsa) {
  ------------------
  |  Branch (548:9): [True: 0, False: 657]
  ------------------
  549|      0|        session->srv.rsa_key = ssh_key_dup(sshbind->rsa);
  550|      0|        if (session->srv.rsa_key == NULL) {
  ------------------
  |  Branch (550:13): [True: 0, False: 0]
  ------------------
  551|      0|          ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  552|      0|          return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  553|      0|        }
  554|      0|    }
  555|    657|    if (sshbind->ed25519 != NULL) {
  ------------------
  |  Branch (555:9): [True: 657, False: 0]
  ------------------
  556|    657|        session->srv.ed25519_key = ssh_key_dup(sshbind->ed25519);
  557|    657|        if (session->srv.ed25519_key == NULL){
  ------------------
  |  Branch (557:13): [True: 0, False: 657]
  ------------------
  558|      0|            ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  559|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  560|      0|        }
  561|    657|    }
  562|       |
  563|       |    /* force PRNG to change state in case we fork after ssh_bind_accept */
  564|    657|    ssh_reseed();
  565|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  566|    657|}

ssh_buffer_new:
  126|  27.5k|{
  127|  27.5k|    struct ssh_buffer_struct *buf = NULL;
  128|  27.5k|    int rc;
  129|       |
  130|  27.5k|    buf = calloc(1, sizeof(struct ssh_buffer_struct));
  131|  27.5k|    if (buf == NULL) {
  ------------------
  |  Branch (131:9): [True: 0, False: 27.5k]
  ------------------
  132|      0|        return NULL;
  133|      0|    }
  134|       |
  135|       |    /*
  136|       |     * Always preallocate 64 bytes.
  137|       |     *
  138|       |     * -1 for realloc_buffer magic.
  139|       |     */
  140|  27.5k|    rc = ssh_buffer_allocate_size(buf, 64 - 1);
  141|  27.5k|    if (rc != 0) {
  ------------------
  |  Branch (141:9): [True: 0, False: 27.5k]
  ------------------
  142|      0|        SAFE_FREE(buf);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  143|      0|        return NULL;
  144|      0|    }
  145|  27.5k|    buffer_verify(buf);
  146|       |
  147|  27.5k|    return buf;
  148|  27.5k|}
ssh_buffer_free:
  156|  27.5k|{
  157|  27.5k|    if (buffer == NULL) {
  ------------------
  |  Branch (157:9): [True: 0, False: 27.5k]
  ------------------
  158|      0|        return;
  159|      0|    }
  160|  27.5k|    buffer_verify(buffer);
  161|       |
  162|  27.5k|    if (buffer->secure && buffer->allocated > 0) {
  ------------------
  |  Branch (162:9): [True: 5.91k, False: 21.6k]
  |  Branch (162:27): [True: 5.91k, False: 0]
  ------------------
  163|       |        /* burn the data */
  164|  5.91k|        ssh_burn(buffer->data, buffer->allocated);
  ------------------
  |  |  388|  5.91k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  165|  5.91k|        SAFE_FREE(buffer->data);
  ------------------
  |  |  373|  5.91k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 5.91k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 5.91k]
  |  |  ------------------
  ------------------
  166|       |
  167|  5.91k|        ssh_burn(buffer, sizeof(struct ssh_buffer_struct));
  ------------------
  |  |  388|  5.91k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  168|  21.6k|    } else {
  169|  21.6k|        SAFE_FREE(buffer->data);
  ------------------
  |  |  373|  21.6k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 21.6k, False: 2]
  |  |  |  Branch (373:71): [Folded, False: 21.6k]
  |  |  ------------------
  ------------------
  170|  21.6k|    }
  171|       |    SAFE_FREE(buffer);
  ------------------
  |  |  373|  27.5k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 27.5k, False: 6]
  |  |  |  Branch (373:71): [Folded, False: 27.5k]
  |  |  ------------------
  ------------------
  172|  27.5k|}
ssh_buffer_set_secure:
  183|  5.91k|{
  184|       |    buffer->secure = true;
  185|  5.91k|}
ssh_buffer_reinit:
  266|  30.1k|{
  267|  30.1k|    if (buffer == NULL) {
  ------------------
  |  Branch (267:9): [True: 0, False: 30.1k]
  ------------------
  268|      0|        return -1;
  269|      0|    }
  270|       |
  271|  30.1k|    buffer_verify(buffer);
  272|       |
  273|  30.1k|    if (buffer->secure && buffer->allocated > 0) {
  ------------------
  |  Branch (273:9): [True: 0, False: 30.1k]
  |  Branch (273:27): [True: 0, False: 0]
  ------------------
  274|      0|        ssh_burn(buffer->data, buffer->allocated);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  275|      0|    }
  276|  30.1k|    buffer->used = 0;
  277|  30.1k|    buffer->pos = 0;
  278|       |
  279|       |    /* If the buffer is bigger then 64K, reset it to 64K */
  280|  30.1k|    if (buffer->allocated > 65536) {
  ------------------
  |  Branch (280:9): [True: 0, False: 30.1k]
  ------------------
  281|      0|        int rc;
  282|       |
  283|       |        /* -1 for realloc_buffer magic */
  284|      0|        rc = realloc_buffer(buffer, 65536 - 1);
  285|      0|        if (rc != 0) {
  ------------------
  |  Branch (285:13): [True: 0, False: 0]
  ------------------
  286|      0|            return -1;
  287|      0|        }
  288|      0|    }
  289|       |
  290|  30.1k|    buffer_verify(buffer);
  291|       |
  292|  30.1k|    return 0;
  293|  30.1k|}
ssh_buffer_add_data:
  307|   230k|{
  308|   230k|    if (buffer == NULL) {
  ------------------
  |  Branch (308:9): [True: 0, False: 230k]
  ------------------
  309|      0|        return -1;
  310|      0|    }
  311|       |
  312|   230k|    buffer_verify(buffer);
  313|       |
  314|   230k|    if (data == NULL) {
  ------------------
  |  Branch (314:9): [True: 0, False: 230k]
  ------------------
  315|      0|        return -1;
  316|      0|    }
  317|       |
  318|   230k|    if (buffer->used + len < len) {
  ------------------
  |  Branch (318:9): [True: 0, False: 230k]
  ------------------
  319|      0|        return -1;
  320|      0|    }
  321|       |
  322|   230k|    if (buffer->allocated < (buffer->used + len)) {
  ------------------
  |  Branch (322:9): [True: 16.4k, False: 214k]
  ------------------
  323|  16.4k|        if (buffer->pos > 0) {
  ------------------
  |  Branch (323:13): [True: 0, False: 16.4k]
  ------------------
  324|      0|            buffer_shift(buffer);
  325|      0|        }
  326|  16.4k|        if (realloc_buffer(buffer, buffer->used + len) < 0) {
  ------------------
  |  Branch (326:13): [True: 0, False: 16.4k]
  ------------------
  327|      0|            return -1;
  328|      0|        }
  329|  16.4k|    }
  330|       |
  331|   230k|    memcpy(buffer->data + buffer->used, data, len);
  332|   230k|    buffer->used += len;
  333|   230k|    buffer_verify(buffer);
  334|   230k|    return 0;
  335|   230k|}
ssh_buffer_allocate_size:
  348|  55.1k|{
  349|  55.1k|    buffer_verify(buffer);
  350|       |
  351|  55.1k|    if (buffer->allocated < len) {
  ------------------
  |  Branch (351:9): [True: 32.7k, False: 22.4k]
  ------------------
  352|  32.7k|        if (buffer->pos > 0) {
  ------------------
  |  Branch (352:13): [True: 0, False: 32.7k]
  ------------------
  353|      0|            buffer_shift(buffer);
  354|      0|        }
  355|  32.7k|        if (realloc_buffer(buffer, len) < 0) {
  ------------------
  |  Branch (355:13): [True: 0, False: 32.7k]
  ------------------
  356|      0|            return -1;
  357|      0|        }
  358|  32.7k|    }
  359|       |
  360|  55.1k|    buffer_verify(buffer);
  361|       |
  362|  55.1k|    return 0;
  363|  55.1k|}
ssh_buffer_allocate:
  378|  34.6k|{
  379|  34.6k|    void *ptr = NULL;
  380|       |
  381|  34.6k|    buffer_verify(buffer);
  382|       |
  383|  34.6k|    if (buffer->used + len < len) {
  ------------------
  |  Branch (383:9): [True: 0, False: 34.6k]
  ------------------
  384|      0|        return NULL;
  385|      0|    }
  386|       |
  387|  34.6k|    if (buffer->allocated < (buffer->used + len)) {
  ------------------
  |  Branch (387:9): [True: 4.48k, False: 30.2k]
  ------------------
  388|  4.48k|        if (buffer->pos > 0) {
  ------------------
  |  Branch (388:13): [True: 0, False: 4.48k]
  ------------------
  389|      0|            buffer_shift(buffer);
  390|      0|        }
  391|       |
  392|  4.48k|        if (realloc_buffer(buffer, buffer->used + len) < 0) {
  ------------------
  |  Branch (392:13): [True: 0, False: 4.48k]
  ------------------
  393|      0|            return NULL;
  394|      0|        }
  395|  4.48k|    }
  396|       |
  397|  34.6k|    ptr = buffer->data + buffer->used;
  398|  34.6k|    buffer->used+=len;
  399|  34.6k|    buffer_verify(buffer);
  400|       |
  401|  34.6k|    return ptr;
  402|  34.6k|}
ssh_buffer_add_ssh_string:
  418|  50.9k|{
  419|  50.9k|    size_t len;
  420|  50.9k|    int rc;
  421|       |
  422|  50.9k|    if (string == NULL) {
  ------------------
  |  Branch (422:9): [True: 0, False: 50.9k]
  ------------------
  423|      0|        return -1;
  424|      0|    }
  425|       |
  426|  50.9k|    len = ssh_string_len(string) + sizeof(uint32_t);
  427|       |    /* this can't overflow the uint32_t as the
  428|       |     * STRING_SIZE_MAX is (UINT32_MAX >> 8) + 1 */
  429|  50.9k|    rc = ssh_buffer_add_data(buffer, string, (uint32_t)len);
  430|  50.9k|    if (rc < 0) {
  ------------------
  |  Branch (430:9): [True: 0, False: 50.9k]
  ------------------
  431|      0|        return -1;
  432|      0|    }
  433|       |
  434|  50.9k|    return 0;
  435|  50.9k|}
ssh_buffer_add_u32:
  449|  33.5k|{
  450|  33.5k|    int rc;
  451|       |
  452|  33.5k|    rc = ssh_buffer_add_data(buffer, &data, sizeof(data));
  453|  33.5k|    if (rc < 0) {
  ------------------
  |  Branch (453:9): [True: 0, False: 33.5k]
  ------------------
  454|      0|        return -1;
  455|      0|    }
  456|       |
  457|  33.5k|    return 0;
  458|  33.5k|}
ssh_buffer_add_u8:
  518|  21.0k|{
  519|  21.0k|    int rc;
  520|       |
  521|  21.0k|    rc = ssh_buffer_add_data(buffer, &data, sizeof(uint8_t));
  522|  21.0k|    if (rc < 0) {
  ------------------
  |  Branch (522:9): [True: 0, False: 21.0k]
  ------------------
  523|      0|        return -1;
  524|      0|    }
  525|       |
  526|  21.0k|    return 0;
  527|  21.0k|}
ssh_buffer_prepend_data:
  543|  13.1k|    uint32_t len) {
  544|  13.1k|  buffer_verify(buffer);
  545|       |
  546|  13.1k|  if(len <= buffer->pos){
  ------------------
  |  Branch (546:6): [True: 0, False: 13.1k]
  ------------------
  547|       |    /* It's possible to insert data between begin and pos */
  548|      0|    memcpy(buffer->data + (buffer->pos - len), data, len);
  549|      0|    buffer->pos -= len;
  550|      0|    buffer_verify(buffer);
  551|      0|    return 0;
  552|      0|  }
  553|       |  /* pos isn't high enough */
  554|  13.1k|  if (buffer->used - buffer->pos + len < len) {
  ------------------
  |  Branch (554:7): [True: 0, False: 13.1k]
  ------------------
  555|      0|    return -1;
  556|      0|  }
  557|       |
  558|  13.1k|  if (buffer->allocated < (buffer->used - buffer->pos + len)) {
  ------------------
  |  Branch (558:7): [True: 41, False: 13.0k]
  ------------------
  559|     41|    if (realloc_buffer(buffer, buffer->used - buffer->pos + len) < 0) {
  ------------------
  |  Branch (559:9): [True: 0, False: 41]
  ------------------
  560|      0|      return -1;
  561|      0|    }
  562|     41|  }
  563|  13.1k|  memmove(buffer->data + len, buffer->data + buffer->pos, buffer->used - buffer->pos);
  564|  13.1k|  memcpy(buffer->data, data, len);
  565|  13.1k|  buffer->used += len - buffer->pos;
  566|  13.1k|  buffer->pos = 0;
  567|  13.1k|  buffer_verify(buffer);
  568|  13.1k|  return 0;
  569|  13.1k|}
ssh_buffer_get:
  607|   110k|void *ssh_buffer_get(struct ssh_buffer_struct *buffer){
  608|   110k|    return buffer->data + buffer->pos;
  609|   110k|}
ssh_buffer_get_len:
  620|   259k|uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
  621|   259k|  buffer_verify(buffer);
  622|   259k|  return buffer->used - buffer->pos;
  623|   259k|}
ssh_buffer_pass_bytes:
  685|  51.8k|uint32_t ssh_buffer_pass_bytes(struct ssh_buffer_struct *buffer, uint32_t len){
  686|  51.8k|    buffer_verify(buffer);
  687|       |
  688|  51.8k|    if (buffer->pos + len < len || buffer->used < buffer->pos + len) {
  ------------------
  |  Branch (688:9): [True: 0, False: 51.8k]
  |  Branch (688:36): [True: 0, False: 51.8k]
  ------------------
  689|      0|        return 0;
  690|      0|    }
  691|       |
  692|  51.8k|    buffer->pos+=len;
  693|       |    /* if the buffer is empty after having passed the whole bytes into it, we can clean it */
  694|  51.8k|    if(buffer->pos==buffer->used){
  ------------------
  |  Branch (694:8): [True: 34.9k, False: 16.9k]
  ------------------
  695|  34.9k|        buffer->pos=0;
  696|  34.9k|        buffer->used=0;
  697|  34.9k|    }
  698|  51.8k|    buffer_verify(buffer);
  699|  51.8k|    return len;
  700|  51.8k|}
ssh_buffer_pass_bytes_end:
  713|  23.5k|uint32_t ssh_buffer_pass_bytes_end(struct ssh_buffer_struct *buffer, uint32_t len){
  714|  23.5k|  buffer_verify(buffer);
  715|       |
  716|  23.5k|  if (buffer->used < len) {
  ------------------
  |  Branch (716:7): [True: 0, False: 23.5k]
  ------------------
  717|      0|      return 0;
  718|      0|  }
  719|       |
  720|  23.5k|  buffer->used-=len;
  721|  23.5k|  buffer_verify(buffer);
  722|  23.5k|  return len;
  723|  23.5k|}
ssh_buffer_get_data:
  737|   109k|{
  738|   109k|    int rc;
  739|       |
  740|       |    /*
  741|       |     * Check for a integer overflow first, then check if not enough data is in
  742|       |     * the buffer.
  743|       |     */
  744|   109k|    rc = ssh_buffer_validate_length(buffer, len);
  745|   109k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|   109k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (745:9): [True: 0, False: 109k]
  ------------------
  746|      0|        return 0;
  747|      0|    }
  748|   109k|    memcpy(data,buffer->data+buffer->pos,len);
  749|   109k|    buffer->pos+=len;
  750|   109k|    return len;   /* no yet support for partial reads (is it really needed ?? ) */
  751|   109k|}
ssh_buffer_get_u8:
  765|  27.5k|uint32_t ssh_buffer_get_u8(struct ssh_buffer_struct *buffer, uint8_t *data){
  766|  27.5k|    return ssh_buffer_get_data(buffer,data,sizeof(uint8_t));
  767|  27.5k|}
ssh_buffer_get_u32:
  780|  44.0k|uint32_t ssh_buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
  781|  44.0k|    return ssh_buffer_get_data(buffer,data,sizeof(uint32_t));
  782|  44.0k|}
ssh_buffer_validate_length:
  809|   143k|{
  810|   143k|    if (buffer == NULL || buffer->pos + len < len ||
  ------------------
  |  Branch (810:9): [True: 18.4E, False: 143k]
  |  Branch (810:27): [True: 4, False: 143k]
  ------------------
  811|   143k|        buffer->pos + len > buffer->used) {
  ------------------
  |  Branch (811:9): [True: 18.4E, False: 143k]
  ------------------
  812|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  813|      0|    }
  814|       |
  815|   143k|    return SSH_OK;
  ------------------
  |  |  316|   143k|#define SSH_OK 0     /* No error */
  ------------------
  816|   143k|}
ssh_buffer_get_ssh_string:
  829|  23.6k|{
  830|  23.6k|    uint32_t stringlen;
  831|  23.6k|    uint32_t hostlen;
  832|  23.6k|    struct ssh_string_struct *str = NULL;
  833|  23.6k|    int rc;
  834|       |
  835|  23.6k|    rc = ssh_buffer_get_u32(buffer, &stringlen);
  836|  23.6k|    if (rc == 0) {
  ------------------
  |  Branch (836:9): [True: 0, False: 23.6k]
  ------------------
  837|      0|        return NULL;
  838|      0|    }
  839|  23.6k|    hostlen = ntohl(stringlen);
  840|       |    /* verify if there is enough space in buffer to get it */
  841|  23.6k|    rc = ssh_buffer_validate_length(buffer, hostlen);
  842|  23.6k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  23.6k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (842:9): [True: 0, False: 23.6k]
  ------------------
  843|      0|      return NULL; /* it is indeed */
  844|      0|    }
  845|  23.6k|    str = ssh_string_new(hostlen);
  846|  23.6k|    if (str == NULL) {
  ------------------
  |  Branch (846:9): [True: 0, False: 23.6k]
  ------------------
  847|      0|        return NULL;
  848|      0|    }
  849|       |
  850|  23.6k|    stringlen = ssh_buffer_get_data(buffer, ssh_string_data(str), hostlen);
  851|  23.6k|    if (stringlen != hostlen) {
  ------------------
  |  Branch (851:9): [True: 0, False: 23.6k]
  ------------------
  852|       |        /* should never happen */
  853|      0|        SAFE_FREE(str);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  854|      0|        return NULL;
  855|      0|    }
  856|       |
  857|  23.6k|    return str;
  858|  23.6k|}
_ssh_buffer_pack:
 1135|  24.9k|{
 1136|  24.9k|    va_list ap;
 1137|  24.9k|    int rc;
 1138|       |
 1139|  24.9k|    if (argc > 256) {
  ------------------
  |  Branch (1139:9): [True: 0, False: 24.9k]
  ------------------
 1140|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1141|      0|    }
 1142|       |
 1143|  24.9k|    va_start(ap, argc);
 1144|  24.9k|    rc = ssh_buffer_pack_allocate_va(buffer, format, argc, ap);
 1145|  24.9k|    va_end(ap);
 1146|       |
 1147|  24.9k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  24.9k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1147:9): [True: 0, False: 24.9k]
  ------------------
 1148|      0|        return rc;
 1149|      0|    }
 1150|       |
 1151|  24.9k|    va_start(ap, argc);
 1152|  24.9k|    rc = ssh_buffer_pack_va(buffer, format, argc, ap);
 1153|  24.9k|    va_end(ap);
 1154|       |
 1155|  24.9k|    return rc;
 1156|  24.9k|}
ssh_buffer_unpack_va:
 1173|  12.4k|{
 1174|  12.4k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  12.4k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1175|  12.4k|    const char *p = format, *last = NULL;
 1176|  12.4k|    union {
 1177|  12.4k|        uint8_t *byte;
 1178|  12.4k|        uint16_t *word;
 1179|  12.4k|        uint32_t *dword;
 1180|  12.4k|        uint64_t *qword;
 1181|  12.4k|        ssh_string *string;
 1182|  12.4k|        char **cstring;
 1183|  12.4k|        bignum *bignum;
 1184|  12.4k|        void **data;
 1185|  12.4k|    } o;
 1186|  12.4k|    size_t len;
 1187|  12.4k|    uint32_t rlen, max_len;
 1188|  12.4k|    ssh_string tmp_string = NULL;
 1189|  12.4k|    va_list ap_copy;
 1190|  12.4k|    size_t count;
 1191|       |
 1192|  12.4k|    max_len = ssh_buffer_get_len(buffer);
 1193|       |
 1194|       |    /* copy the argument list in case a rollback is needed */
 1195|  12.4k|    va_copy(ap_copy, ap);
 1196|       |
 1197|  12.4k|    if (argc > 256) {
  ------------------
  |  Branch (1197:9): [True: 0, False: 12.4k]
  ------------------
 1198|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1199|      0|        goto cleanup;
 1200|      0|    }
 1201|       |
 1202|  36.7k|    for (count = 0; *p != '\0'; p++, count++) {
  ------------------
  |  Branch (1202:21): [True: 24.3k, False: 12.4k]
  ------------------
 1203|       |        /* Invalid number of arguments passed */
 1204|  24.3k|        if (count > argc) {
  ------------------
  |  Branch (1204:13): [True: 0, False: 24.3k]
  ------------------
 1205|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1206|      0|            goto cleanup;
 1207|      0|        }
 1208|       |
 1209|  24.3k|        rc = SSH_ERROR;
  ------------------
  |  |  317|  24.3k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1210|  24.3k|        switch (*p) {
 1211|    657|        case 'b':
  ------------------
  |  Branch (1211:9): [True: 657, False: 23.6k]
  ------------------
 1212|    657|            o.byte = va_arg(ap, uint8_t *);
 1213|    657|            rlen = ssh_buffer_get_u8(buffer, o.byte);
 1214|    657|            rc = rlen==1 ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
                          rc = rlen==1 ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1214:18): [True: 657, False: 0]
  ------------------
 1215|    657|            break;
 1216|      0|        case 'w':
  ------------------
  |  Branch (1216:9): [True: 0, False: 24.3k]
  ------------------
 1217|      0|            o.word = va_arg(ap,  uint16_t *);
 1218|      0|            rlen = ssh_buffer_get_data(buffer, o.word, sizeof(uint16_t));
 1219|      0|            if (rlen == 2) {
  ------------------
  |  Branch (1219:17): [True: 0, False: 0]
  ------------------
 1220|      0|                *o.word = ntohs(*o.word);
 1221|      0|                rc = SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1222|      0|            }
 1223|      0|            break;
 1224|  9.19k|        case 'd':
  ------------------
  |  Branch (1224:9): [True: 9.19k, False: 15.1k]
  ------------------
 1225|  9.19k|            o.dword = va_arg(ap, uint32_t *);
 1226|  9.19k|            rlen = ssh_buffer_get_u32(buffer, o.dword);
 1227|  9.19k|            if (rlen == 4) {
  ------------------
  |  Branch (1227:17): [True: 9.19k, False: 0]
  ------------------
 1228|  9.19k|                *o.dword = ntohl(*o.dword);
 1229|  9.19k|                rc = SSH_OK;
  ------------------
  |  |  316|  9.19k|#define SSH_OK 0     /* No error */
  ------------------
 1230|  9.19k|            }
 1231|  9.19k|            break;
 1232|      0|        case 'q':
  ------------------
  |  Branch (1232:9): [True: 0, False: 24.3k]
  ------------------
 1233|      0|            o.qword = va_arg(ap, uint64_t*);
 1234|      0|            rlen = ssh_buffer_get_u64(buffer, o.qword);
 1235|      0|            if (rlen == 8) {
  ------------------
  |  Branch (1235:17): [True: 0, False: 0]
  ------------------
 1236|      0|                *o.qword = ntohll(*o.qword);
  ------------------
  |  |  488|      0|    (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
  ------------------
 1237|      0|                rc = SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1238|      0|            }
 1239|      0|            break;
 1240|      0|        case 'B':
  ------------------
  |  Branch (1240:9): [True: 0, False: 24.3k]
  ------------------
 1241|      0|            o.bignum = va_arg(ap, bignum *);
 1242|      0|            *o.bignum = NULL;
 1243|      0|            tmp_string = ssh_buffer_get_ssh_string(buffer);
 1244|      0|            if (tmp_string == NULL) {
  ------------------
  |  Branch (1244:17): [True: 0, False: 0]
  ------------------
 1245|      0|                break;
 1246|      0|            }
 1247|      0|            *o.bignum = ssh_make_string_bn(tmp_string);
 1248|      0|            ssh_string_burn(tmp_string);
 1249|      0|            SSH_STRING_FREE(tmp_string);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1250|      0|            rc = (*o.bignum != NULL) ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
                          rc = (*o.bignum != NULL) ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1250:18): [True: 0, False: 0]
  ------------------
 1251|      0|            break;
 1252|  3.28k|        case 'S':
  ------------------
  |  Branch (1252:9): [True: 3.28k, False: 21.0k]
  ------------------
 1253|  3.28k|            o.string = va_arg(ap, ssh_string *);
 1254|  3.28k|            *o.string = ssh_buffer_get_ssh_string(buffer);
 1255|  3.28k|            rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|  3.28k|#define SSH_OK 0     /* No error */
  ------------------
                          rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  317|  3.28k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1255:18): [True: 3.28k, False: 0]
  ------------------
 1256|  3.28k|            o.string = NULL;
 1257|  3.28k|            break;
 1258|  10.5k|        case 's': {
  ------------------
  |  Branch (1258:9): [True: 10.5k, False: 13.7k]
  ------------------
 1259|  10.5k|            uint32_t u32len = 0;
 1260|       |
 1261|  10.5k|            o.cstring = va_arg(ap, char **);
 1262|  10.5k|            *o.cstring = NULL;
 1263|  10.5k|            rlen = ssh_buffer_get_u32(buffer, &u32len);
 1264|  10.5k|            if (rlen != 4){
  ------------------
  |  Branch (1264:17): [True: 0, False: 10.5k]
  ------------------
 1265|      0|                break;
 1266|      0|            }
 1267|  10.5k|            u32len = ntohl(u32len);
 1268|  10.5k|            if (u32len > max_len - 1) {
  ------------------
  |  Branch (1268:17): [True: 0, False: 10.5k]
  ------------------
 1269|      0|                break;
 1270|      0|            }
 1271|       |
 1272|  10.5k|            rc = ssh_buffer_validate_length(buffer, u32len);
 1273|  10.5k|            if (rc != SSH_OK) {
  ------------------
  |  |  316|  10.5k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1273:17): [True: 0, False: 10.5k]
  ------------------
 1274|      0|                break;
 1275|      0|            }
 1276|       |
 1277|  10.5k|            *o.cstring = malloc(u32len + 1);
 1278|  10.5k|            if (*o.cstring == NULL){
  ------------------
  |  Branch (1278:17): [True: 0, False: 10.5k]
  ------------------
 1279|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1280|      0|                break;
 1281|      0|            }
 1282|  10.5k|            rlen = ssh_buffer_get_data(buffer, *o.cstring, u32len);
 1283|  10.5k|            if (rlen != u32len) {
  ------------------
  |  Branch (1283:17): [True: 0, False: 10.5k]
  ------------------
 1284|      0|                SAFE_FREE(*o.cstring);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1285|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1286|      0|                break;
 1287|      0|            }
 1288|  10.5k|            (*o.cstring)[u32len] = '\0';
 1289|  10.5k|            o.cstring = NULL;
 1290|  10.5k|            rc = SSH_OK;
  ------------------
  |  |  316|  10.5k|#define SSH_OK 0     /* No error */
  ------------------
 1291|  10.5k|            break;
 1292|  10.5k|        }
 1293|    657|        case 'P':
  ------------------
  |  Branch (1293:9): [True: 657, False: 23.6k]
  ------------------
 1294|    657|            len = va_arg(ap, size_t);
 1295|    657|            if (len > max_len - 1) {
  ------------------
  |  Branch (1295:17): [True: 0, False: 657]
  ------------------
 1296|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1297|      0|                break;
 1298|      0|            }
 1299|       |
 1300|    657|            rc = ssh_buffer_validate_length(buffer, len);
 1301|    657|            if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1301:17): [True: 0, False: 657]
  ------------------
 1302|      0|                break;
 1303|      0|            }
 1304|       |
 1305|    657|            o.data = va_arg(ap, void **);
 1306|    657|            count++;
 1307|       |
 1308|    657|            *o.data = malloc(len);
 1309|    657|            if(*o.data == NULL){
  ------------------
  |  Branch (1309:16): [True: 0, False: 657]
  ------------------
 1310|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1311|      0|                break;
 1312|      0|            }
 1313|    657|            rlen = ssh_buffer_get_data(buffer, *o.data, (uint32_t)len);
 1314|    657|            if (rlen != len){
  ------------------
  |  Branch (1314:17): [True: 0, False: 657]
  ------------------
 1315|      0|                SAFE_FREE(*o.data);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1316|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1317|      0|                break;
 1318|      0|            }
 1319|    657|            o.data = NULL;
 1320|    657|            rc = SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
 1321|    657|            break;
 1322|      0|        default:
  ------------------
  |  Branch (1322:9): [True: 0, False: 24.3k]
  ------------------
 1323|      0|            SSH_LOG(SSH_LOG_TRACE, "Invalid buffer format %c", *p);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1324|  24.3k|        }
 1325|  24.3k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  24.3k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1325:13): [True: 0, False: 24.3k]
  ------------------
 1326|      0|            break;
 1327|      0|        }
 1328|  24.3k|    }
 1329|       |
 1330|  12.4k|    if (argc != count) {
  ------------------
  |  Branch (1330:9): [True: 0, False: 12.4k]
  ------------------
 1331|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1332|      0|    }
 1333|       |
 1334|  12.4k|cleanup:
 1335|  12.4k|    if (rc != SSH_ERROR){
  ------------------
  |  |  317|  12.4k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1335:9): [True: 12.4k, False: 0]
  ------------------
 1336|       |        /* Check if our canary is intact, if not something really bad happened */
 1337|  12.4k|        uint32_t canary = va_arg(ap, uint32_t);
 1338|  12.4k|        if (canary != SSH_BUFFER_PACK_END){
  ------------------
  |  |   28|  12.4k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  ------------------
  |  Branch (1338:13): [True: 0, False: 12.4k]
  ------------------
 1339|      0|            abort();
 1340|      0|        }
 1341|  12.4k|    }
 1342|       |
 1343|  12.4k|    if (rc != SSH_OK){
  ------------------
  |  |  316|  12.4k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1343:9): [True: 0, False: 12.4k]
  ------------------
 1344|       |        /* Reset the format string and erase everything that was allocated */
 1345|      0|        last = p;
 1346|      0|        for(p=format;p<last;++p){
  ------------------
  |  Branch (1346:22): [True: 0, False: 0]
  ------------------
 1347|      0|            switch(*p){
 1348|      0|            case 'b':
  ------------------
  |  Branch (1348:13): [True: 0, False: 0]
  ------------------
 1349|      0|                o.byte = va_arg(ap_copy, uint8_t *);
 1350|      0|                if (buffer->secure) {
  ------------------
  |  Branch (1350:21): [True: 0, False: 0]
  ------------------
 1351|      0|                    ssh_burn(o.byte, sizeof(uint8_t));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1352|      0|                    break;
 1353|      0|                }
 1354|      0|                break;
 1355|      0|            case 'w':
  ------------------
  |  Branch (1355:13): [True: 0, False: 0]
  ------------------
 1356|      0|                o.word = va_arg(ap_copy, uint16_t *);
 1357|      0|                if (buffer->secure) {
  ------------------
  |  Branch (1357:21): [True: 0, False: 0]
  ------------------
 1358|      0|                    ssh_burn(o.word, sizeof(uint16_t));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1359|      0|                    break;
 1360|      0|                }
 1361|      0|                break;
 1362|      0|            case 'd':
  ------------------
  |  Branch (1362:13): [True: 0, False: 0]
  ------------------
 1363|      0|                o.dword = va_arg(ap_copy, uint32_t *);
 1364|      0|                if (buffer->secure) {
  ------------------
  |  Branch (1364:21): [True: 0, False: 0]
  ------------------
 1365|      0|                    ssh_burn(o.dword, sizeof(uint32_t));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1366|      0|                    break;
 1367|      0|                }
 1368|      0|                break;
 1369|      0|            case 'q':
  ------------------
  |  Branch (1369:13): [True: 0, False: 0]
  ------------------
 1370|      0|                o.qword = va_arg(ap_copy, uint64_t *);
 1371|      0|                if (buffer->secure) {
  ------------------
  |  Branch (1371:21): [True: 0, False: 0]
  ------------------
 1372|      0|                    ssh_burn(o.qword, sizeof(uint64_t));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1373|      0|                    break;
 1374|      0|                }
 1375|      0|                break;
 1376|      0|            case 'B':
  ------------------
  |  Branch (1376:13): [True: 0, False: 0]
  ------------------
 1377|      0|                o.bignum = va_arg(ap_copy, bignum *);
 1378|      0|                bignum_safe_free(*o.bignum);
  ------------------
  |  |   71|      0|#define bignum_safe_free(num) do { \
  |  |   72|      0|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 0]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1379|      0|                break;
 1380|      0|            case 'S':
  ------------------
  |  Branch (1380:13): [True: 0, False: 0]
  ------------------
 1381|      0|                o.string = va_arg(ap_copy, ssh_string *);
 1382|      0|                if (buffer->secure) {
  ------------------
  |  Branch (1382:21): [True: 0, False: 0]
  ------------------
 1383|      0|                    ssh_string_burn(*o.string);
 1384|      0|                }
 1385|      0|                SAFE_FREE(*o.string);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1386|      0|                break;
 1387|      0|            case 's':
  ------------------
  |  Branch (1387:13): [True: 0, False: 0]
  ------------------
 1388|      0|                o.cstring = va_arg(ap_copy, char **);
 1389|      0|                if (buffer->secure) {
  ------------------
  |  Branch (1389:21): [True: 0, False: 0]
  ------------------
 1390|      0|                    ssh_burn(*o.cstring, strlen(*o.cstring));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1391|      0|                }
 1392|      0|                SAFE_FREE(*o.cstring);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1393|      0|                break;
 1394|      0|            case 'P':
  ------------------
  |  Branch (1394:13): [True: 0, False: 0]
  ------------------
 1395|      0|                len = va_arg(ap_copy, size_t);
 1396|      0|                o.data = va_arg(ap_copy, void **);
 1397|      0|                if (buffer->secure) {
  ------------------
  |  Branch (1397:21): [True: 0, False: 0]
  ------------------
 1398|      0|                    ssh_burn(*o.data, len);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1399|      0|                }
 1400|      0|                SAFE_FREE(*o.data);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1401|      0|                break;
 1402|      0|            default:
  ------------------
  |  Branch (1402:13): [True: 0, False: 0]
  ------------------
 1403|      0|                (void)va_arg(ap_copy, void *);
 1404|      0|                break;
 1405|      0|            }
 1406|      0|        }
 1407|      0|    }
 1408|  12.4k|    va_end(ap_copy);
 1409|       |
 1410|  12.4k|    return rc;
 1411|  12.4k|}
_ssh_buffer_unpack:
 1439|  12.4k|{
 1440|  12.4k|    va_list ap;
 1441|  12.4k|    int rc;
 1442|       |
 1443|  12.4k|    va_start(ap, argc);
 1444|  12.4k|    rc = ssh_buffer_unpack_va(buffer, format, argc, ap);
 1445|       |    va_end(ap);
 1446|  12.4k|    return rc;
 1447|  12.4k|}
buffer.c:realloc_buffer:
  188|  53.6k|{
  189|  53.6k|    uint32_t smallest = 1;
  190|  53.6k|    uint8_t *new = NULL;
  191|       |
  192|  53.6k|    buffer_verify(buffer);
  193|       |
  194|       |    /* Find the smallest power of two which is greater or equal to needed */
  195|   487k|    while(smallest <= needed) {
  ------------------
  |  Branch (195:11): [True: 434k, False: 53.6k]
  ------------------
  196|   434k|        if (smallest == 0) {
  ------------------
  |  Branch (196:13): [True: 0, False: 434k]
  ------------------
  197|      0|            return -1;
  198|      0|        }
  199|   434k|        smallest <<= 1;
  200|   434k|    }
  201|  53.6k|    needed = smallest;
  202|       |
  203|  53.6k|    if (needed > BUFFER_SIZE_MAX) {
  ------------------
  |  |   57|  53.6k|#define BUFFER_SIZE_MAX 0x10000000
  ------------------
  |  Branch (203:9): [True: 0, False: 53.6k]
  ------------------
  204|      0|        return -1;
  205|      0|    }
  206|       |
  207|  53.6k|    if (buffer->secure) {
  ------------------
  |  Branch (207:9): [True: 1.97k, False: 51.6k]
  ------------------
  208|  1.97k|        new = malloc(needed);
  209|  1.97k|        if (new == NULL) {
  ------------------
  |  Branch (209:13): [True: 0, False: 1.97k]
  ------------------
  210|      0|            return -1;
  211|      0|        }
  212|  1.97k|        memcpy(new, buffer->data, buffer->used);
  213|  1.97k|        ssh_burn(buffer->data, buffer->used);
  ------------------
  |  |  388|  1.97k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  214|  1.97k|        SAFE_FREE(buffer->data);
  ------------------
  |  |  373|  1.97k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.97k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.97k]
  |  |  ------------------
  ------------------
  215|  51.6k|    } else {
  216|  51.6k|        new = realloc(buffer->data, needed);
  217|  51.6k|        if (new == NULL) {
  ------------------
  |  Branch (217:13): [True: 0, False: 51.6k]
  ------------------
  218|      0|            return -1;
  219|      0|        }
  220|  51.6k|    }
  221|  53.6k|    buffer->data = new;
  222|  53.6k|    buffer->allocated = needed;
  223|       |
  224|  53.6k|    buffer_verify(buffer);
  225|  53.6k|    return 0;
  226|  53.6k|}
buffer.c:ssh_buffer_pack_allocate_va:
  880|  24.9k|{
  881|  24.9k|    const char *p = NULL;
  882|  24.9k|    ssh_string string = NULL;
  883|  24.9k|    char *cstring = NULL;
  884|  24.9k|    bignum b = NULL;
  885|  24.9k|    size_t needed_size = 0;
  886|  24.9k|    size_t len;
  887|  24.9k|    size_t count;
  888|  24.9k|    int rc = SSH_OK;
  ------------------
  |  |  316|  24.9k|#define SSH_OK 0     /* No error */
  ------------------
  889|       |
  890|  88.0k|    for (p = format, count = 0; *p != '\0'; p++, count++) {
  ------------------
  |  Branch (890:33): [True: 63.0k, False: 24.9k]
  ------------------
  891|       |        /* Invalid number of arguments passed */
  892|  63.0k|        if (count > argc) {
  ------------------
  |  Branch (892:13): [True: 0, False: 63.0k]
  ------------------
  893|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  894|      0|        }
  895|       |
  896|  63.0k|        switch(*p) {
  897|  13.1k|        case 'b':
  ------------------
  |  Branch (897:9): [True: 13.1k, False: 49.9k]
  ------------------
  898|  13.1k|            va_arg(ap, unsigned int);
  899|  13.1k|            needed_size += sizeof(uint8_t);
  900|  13.1k|            break;
  901|      0|        case 'w':
  ------------------
  |  Branch (901:9): [True: 0, False: 63.0k]
  ------------------
  902|      0|            va_arg(ap, unsigned int);
  903|      0|            needed_size += sizeof(uint16_t);
  904|      0|            break;
  905|  17.7k|        case 'd':
  ------------------
  |  Branch (905:9): [True: 17.7k, False: 45.3k]
  ------------------
  906|  17.7k|            va_arg(ap, uint32_t);
  907|  17.7k|            needed_size += sizeof(uint32_t);
  908|  17.7k|            break;
  909|      0|        case 'q':
  ------------------
  |  Branch (909:9): [True: 0, False: 63.0k]
  ------------------
  910|      0|            va_arg(ap, uint64_t);
  911|      0|            needed_size += sizeof(uint64_t);
  912|      0|            break;
  913|  5.91k|        case 'S':
  ------------------
  |  Branch (913:9): [True: 5.91k, False: 57.1k]
  ------------------
  914|  5.91k|            string = va_arg(ap, ssh_string);
  915|  5.91k|            needed_size += sizeof(uint32_t) + ssh_string_len(string);
  916|  5.91k|            string = NULL;
  917|  5.91k|            break;
  918|  13.1k|        case 's':
  ------------------
  |  Branch (918:9): [True: 13.1k, False: 49.9k]
  ------------------
  919|  13.1k|            cstring = va_arg(ap, char *);
  920|  13.1k|            needed_size += sizeof(uint32_t) + strlen(cstring);
  921|  13.1k|            cstring = NULL;
  922|  13.1k|            break;
  923|  13.1k|        case 'P':
  ------------------
  |  Branch (923:9): [True: 13.1k, False: 49.9k]
  ------------------
  924|  13.1k|            len = va_arg(ap, size_t);
  925|  13.1k|            needed_size += len;
  926|  13.1k|            va_arg(ap, void *);
  927|  13.1k|            count++; /* increase argument count */
  928|  13.1k|            break;
  929|      0|        case 'B':
  ------------------
  |  Branch (929:9): [True: 0, False: 63.0k]
  ------------------
  930|      0|            b = va_arg(ap, bignum);
  931|       |            /* The bignum bytes + 1 for possible padding */
  932|      0|            needed_size += sizeof(uint32_t) + bignum_num_bytes(b) + 1;
  ------------------
  |  |   98|      0|#define bignum_num_bytes(num) (size_t)BN_num_bytes(num)
  ------------------
  933|      0|            break;
  934|      0|        case 't':
  ------------------
  |  Branch (934:9): [True: 0, False: 63.0k]
  ------------------
  935|      0|            cstring = va_arg(ap, char *);
  936|      0|            needed_size += strlen(cstring);
  937|      0|            cstring = NULL;
  938|      0|            break;
  939|      0|        default:
  ------------------
  |  Branch (939:9): [True: 0, False: 63.0k]
  ------------------
  940|      0|            SSH_LOG(SSH_LOG_TRACE, "Invalid buffer format %c", *p);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  941|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  942|  63.0k|        }
  943|  63.0k|        if (rc != SSH_OK){
  ------------------
  |  |  316|  63.0k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (943:13): [True: 0, False: 63.0k]
  ------------------
  944|      0|            break;
  945|      0|        }
  946|  63.0k|    }
  947|       |
  948|  24.9k|    if (argc != count) {
  ------------------
  |  Branch (948:9): [True: 0, False: 24.9k]
  ------------------
  949|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  950|      0|    }
  951|       |
  952|  24.9k|    if (rc != SSH_ERROR){
  ------------------
  |  |  317|  24.9k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (952:9): [True: 24.9k, False: 10]
  ------------------
  953|       |        /*
  954|       |         * Check if our canary is intact, if not, something really bad happened.
  955|       |         */
  956|  24.9k|        uint32_t canary = va_arg(ap, uint32_t);
  957|  24.9k|        if (canary != SSH_BUFFER_PACK_END) {
  ------------------
  |  |   28|  24.9k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  ------------------
  |  Branch (957:13): [True: 0, False: 24.9k]
  ------------------
  958|      0|            abort();
  959|      0|        }
  960|  24.9k|    }
  961|       |
  962|  24.9k|    rc = ssh_buffer_allocate_size(buffer, (uint32_t)needed_size);
  963|  24.9k|    if (rc != 0) {
  ------------------
  |  Branch (963:9): [True: 0, False: 24.9k]
  ------------------
  964|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  965|      0|    }
  966|       |
  967|  24.9k|    return SSH_OK;
  ------------------
  |  |  316|  24.9k|#define SSH_OK 0     /* No error */
  ------------------
  968|  24.9k|}
buffer.c:ssh_buffer_pack_va:
  987|  24.9k|{
  988|  24.9k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  24.9k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  989|  24.9k|    const char *p = NULL;
  990|  24.9k|    union {
  991|  24.9k|        uint8_t byte;
  992|  24.9k|        uint16_t word;
  993|  24.9k|        uint32_t dword;
  994|  24.9k|        uint64_t qword;
  995|  24.9k|        ssh_string string;
  996|  24.9k|        void *data;
  997|  24.9k|    } o;
  998|  24.9k|    char *cstring = NULL;
  999|  24.9k|    bignum b;
 1000|  24.9k|    size_t len;
 1001|  24.9k|    size_t count;
 1002|       |
 1003|  24.9k|    if (argc > 256) {
  ------------------
  |  Branch (1003:9): [True: 0, False: 24.9k]
  ------------------
 1004|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1005|      0|    }
 1006|       |
 1007|  88.0k|    for (p = format, count = 0; *p != '\0'; p++, count++) {
  ------------------
  |  Branch (1007:33): [True: 63.0k, False: 24.9k]
  ------------------
 1008|       |        /* Invalid number of arguments passed */
 1009|  63.0k|        if (count > argc) {
  ------------------
  |  Branch (1009:13): [True: 0, False: 63.0k]
  ------------------
 1010|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1011|      0|        }
 1012|       |
 1013|  63.0k|        switch(*p) {
 1014|  13.1k|        case 'b':
  ------------------
  |  Branch (1014:9): [True: 13.1k, False: 49.9k]
  ------------------
 1015|  13.1k|            o.byte = (uint8_t)va_arg(ap, unsigned int);
 1016|  13.1k|            rc = ssh_buffer_add_u8(buffer, o.byte);
 1017|  13.1k|            break;
 1018|      0|        case 'w':
  ------------------
  |  Branch (1018:9): [True: 0, False: 63.0k]
  ------------------
 1019|      0|            o.word = (uint16_t)va_arg(ap, unsigned int);
 1020|      0|            o.word = htons(o.word);
 1021|      0|            rc = ssh_buffer_add_u16(buffer, o.word);
 1022|      0|            break;
 1023|  17.7k|        case 'd':
  ------------------
  |  Branch (1023:9): [True: 17.7k, False: 45.3k]
  ------------------
 1024|  17.7k|            o.dword = va_arg(ap, uint32_t);
 1025|  17.7k|            o.dword = htonl(o.dword);
 1026|  17.7k|            rc = ssh_buffer_add_u32(buffer, o.dword);
 1027|  17.7k|            break;
 1028|      0|        case 'q':
  ------------------
  |  Branch (1028:9): [True: 0, False: 63.0k]
  ------------------
 1029|      0|            o.qword = va_arg(ap, uint64_t);
 1030|      0|            o.qword = htonll(o.qword);
  ------------------
  |  |  479|      0|    (((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
  ------------------
 1031|      0|            rc = ssh_buffer_add_u64(buffer, o.qword);
 1032|      0|            break;
 1033|  5.91k|        case 'S':
  ------------------
  |  Branch (1033:9): [True: 5.91k, False: 57.1k]
  ------------------
 1034|  5.91k|            o.string = va_arg(ap, ssh_string);
 1035|  5.91k|            rc = ssh_buffer_add_ssh_string(buffer, o.string);
 1036|  5.91k|            o.string = NULL;
 1037|  5.91k|            break;
 1038|  13.1k|        case 's':
  ------------------
  |  Branch (1038:9): [True: 13.1k, False: 49.9k]
  ------------------
 1039|  13.1k|            cstring = va_arg(ap, char *);
 1040|  13.1k|            len = strlen(cstring);
 1041|  13.1k|            if (len > UINT32_MAX) {
  ------------------
  |  Branch (1041:17): [True: 0, False: 13.1k]
  ------------------
 1042|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1043|      0|                break;
 1044|      0|            }
 1045|  13.1k|            o.dword = (uint32_t)len;
 1046|  13.1k|            rc = ssh_buffer_add_u32(buffer, htonl(o.dword));
 1047|  13.1k|            if (rc == SSH_OK){
  ------------------
  |  |  316|  13.1k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1047:17): [True: 13.1k, False: 0]
  ------------------
 1048|  13.1k|                rc = ssh_buffer_add_data(buffer, cstring, o.dword);
 1049|  13.1k|            }
 1050|  13.1k|            cstring = NULL;
 1051|  13.1k|            break;
 1052|  13.1k|        case 'P':
  ------------------
  |  Branch (1052:9): [True: 13.1k, False: 49.9k]
  ------------------
 1053|  13.1k|            len = va_arg(ap, size_t);
 1054|  13.1k|            if (len > UINT32_MAX) {
  ------------------
  |  Branch (1054:17): [True: 0, False: 13.1k]
  ------------------
 1055|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1056|      0|                break;
 1057|      0|            }
 1058|       |
 1059|  13.1k|            o.data = va_arg(ap, void *);
 1060|  13.1k|            count++; /* increase argument count */
 1061|       |
 1062|  13.1k|            rc = ssh_buffer_add_data(buffer, o.data, (uint32_t)len);
 1063|  13.1k|            o.data = NULL;
 1064|  13.1k|            break;
 1065|      0|        case 'B':
  ------------------
  |  Branch (1065:9): [True: 0, False: 63.0k]
  ------------------
 1066|      0|            b = va_arg(ap, bignum);
 1067|      0|            o.string = ssh_make_bignum_string(b);
 1068|      0|            if(o.string == NULL){
  ------------------
  |  Branch (1068:16): [True: 0, False: 0]
  ------------------
 1069|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1070|      0|                break;
 1071|      0|            }
 1072|      0|            rc = ssh_buffer_add_ssh_string(buffer, o.string);
 1073|      0|            SAFE_FREE(o.string);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1074|      0|            break;
 1075|      0|        case 't':
  ------------------
  |  Branch (1075:9): [True: 0, False: 63.0k]
  ------------------
 1076|      0|            cstring = va_arg(ap, char *);
 1077|      0|            len = strlen(cstring);
 1078|      0|            if (len > UINT32_MAX) {
  ------------------
  |  Branch (1078:17): [True: 0, False: 0]
  ------------------
 1079|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1080|      0|                break;
 1081|      0|            }
 1082|      0|            rc = ssh_buffer_add_data(buffer, cstring, (uint32_t)len);
 1083|      0|            cstring = NULL;
 1084|      0|            break;
 1085|      0|        default:
  ------------------
  |  Branch (1085:9): [True: 0, False: 63.0k]
  ------------------
 1086|      0|            SSH_LOG(SSH_LOG_TRACE, "Invalid buffer format %c", *p);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1087|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1088|  63.0k|        }
 1089|  63.0k|        if (rc != SSH_OK){
  ------------------
  |  |  316|  63.0k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1089:13): [True: 0, False: 63.0k]
  ------------------
 1090|      0|            break;
 1091|      0|        }
 1092|  63.0k|    }
 1093|       |
 1094|  24.9k|    if (argc != count) {
  ------------------
  |  Branch (1094:9): [True: 0, False: 24.9k]
  ------------------
 1095|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1096|      0|    }
 1097|       |
 1098|  24.9k|    if (rc != SSH_ERROR){
  ------------------
  |  |  317|  24.9k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1098:9): [True: 24.9k, False: 18.4E]
  ------------------
 1099|       |        /* Check if our canary is intact, if not something really bad happened */
 1100|  24.9k|        uint32_t canary = va_arg(ap, uint32_t);
 1101|  24.9k|        if (canary != SSH_BUFFER_PACK_END) {
  ------------------
  |  |   28|  24.9k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  ------------------
  |  Branch (1101:13): [True: 0, False: 24.9k]
  ------------------
 1102|      0|            abort();
 1103|      0|        }
 1104|  24.9k|    }
 1105|  24.9k|    return rc;
 1106|  24.9k|}

_ssh_remove_legacy_log_cb:
   49|  1.31k|{
   50|  1.31k|    if (ssh_get_log_callback() == ssh_legacy_log_callback) {
  ------------------
  |  Branch (50:9): [True: 0, False: 1.31k]
  ------------------
   51|      0|        _ssh_reset_log_cb();
   52|       |        ssh_set_log_userdata(NULL);
   53|      0|    }
   54|  1.31k|}
ssh_set_channel_callbacks:
  114|    657|{
  115|    657|    return ssh_add_set_channel_callbacks(channel, cb, 1);
  116|    657|}
ssh_set_server_callbacks:
  142|    657|{
  143|    657|    if (session == NULL || cb == NULL) {
  ------------------
  |  Branch (143:9): [True: 0, False: 657]
  |  Branch (143:28): [True: 0, False: 657]
  ------------------
  144|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  145|      0|    }
  146|       |
  147|    657|    if (!is_callback_valid(session, cb)) {
  ------------------
  |  |   31|    657|    (cb->size > 0 || cb->size <= 1024 * sizeof(void *))
  |  |  ------------------
  |  |  |  Branch (31:6): [True: 657, False: 0]
  |  |  |  Branch (31:22): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  148|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  149|      0|                      SSH_FATAL,
  150|      0|                      "Invalid callback passed in (badly initialized)");
  151|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  152|    657|    };
  153|    657|    session->server_callbacks = cb;
  154|       |
  155|    657|    return 0;
  156|    657|}
callbacks.c:ssh_add_set_channel_callbacks:
   82|    657|{
   83|    657|    ssh_session session = NULL;
   84|    657|    int rc;
   85|       |
   86|    657|    if (channel == NULL || cb == NULL) {
  ------------------
  |  Branch (86:9): [True: 0, False: 657]
  |  Branch (86:28): [True: 0, False: 657]
  ------------------
   87|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   88|      0|    }
   89|    657|    session = channel->session;
   90|       |
   91|    657|    if (!is_callback_valid(session, cb)) {
  ------------------
  |  |   31|    657|    (cb->size > 0 || cb->size <= 1024 * sizeof(void *))
  |  |  ------------------
  |  |  |  Branch (31:6): [True: 657, False: 0]
  |  |  |  Branch (31:22): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   92|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   93|      0|                      SSH_FATAL,
   94|      0|                      "Invalid callback passed in (badly initialized)");
   95|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   96|    657|    };
   97|    657|    if (channel->callbacks == NULL) {
  ------------------
  |  Branch (97:9): [True: 657, False: 0]
  ------------------
   98|    657|        channel->callbacks = ssh_list_new();
   99|    657|        if (channel->callbacks == NULL) {
  ------------------
  |  Branch (99:13): [True: 0, False: 657]
  ------------------
  100|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  101|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  102|      0|        }
  103|    657|    }
  104|    657|    if (prepend) {
  ------------------
  |  Branch (104:9): [True: 657, False: 0]
  ------------------
  105|    657|        rc = ssh_list_prepend(channel->callbacks, cb);
  106|    657|    } else {
  107|      0|        rc = ssh_list_append(channel->callbacks, cb);
  108|      0|    }
  109|       |
  110|    657|    return rc;
  111|    657|}

ssh_channel_new:
   91|  1.31k|{
   92|  1.31k|    ssh_channel channel = NULL;
   93|       |
   94|  1.31k|    if (session == NULL) {
  ------------------
  |  Branch (94:9): [True: 0, False: 1.31k]
  ------------------
   95|      0|        return NULL;
   96|      0|    }
   97|       |
   98|       |    /* Check if we have an authenticated session */
   99|  1.31k|    if (!(session->flags & SSH_SESSION_FLAG_AUTHENTICATED)) {
  ------------------
  |  |   78|  1.31k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (99:9): [True: 0, False: 1.31k]
  ------------------
  100|      0|        return NULL;
  101|      0|    }
  102|       |
  103|  1.31k|    channel = calloc(1, sizeof(struct ssh_channel_struct));
  104|  1.31k|    if (channel == NULL) {
  ------------------
  |  Branch (104:9): [True: 0, False: 1.31k]
  ------------------
  105|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  106|      0|        return NULL;
  107|      0|    }
  108|       |
  109|  1.31k|    channel->stdout_buffer = ssh_buffer_new();
  110|  1.31k|    if (channel->stdout_buffer == NULL) {
  ------------------
  |  Branch (110:9): [True: 0, False: 1.31k]
  ------------------
  111|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  112|      0|        SAFE_FREE(channel);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  113|      0|        return NULL;
  114|      0|    }
  115|       |
  116|  1.31k|    channel->stderr_buffer = ssh_buffer_new();
  117|  1.31k|    if (channel->stderr_buffer == NULL) {
  ------------------
  |  Branch (117:9): [True: 0, False: 1.31k]
  ------------------
  118|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  119|      0|        SSH_BUFFER_FREE(channel->stdout_buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  120|      0|        SAFE_FREE(channel);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  121|      0|        return NULL;
  122|      0|    }
  123|       |
  124|  1.31k|    channel->session = session;
  125|  1.31k|    channel->exit.code = (uint32_t)-1;
  126|  1.31k|    channel->flags = SSH_CHANNEL_FLAG_NOT_BOUND;
  ------------------
  |  |   64|  1.31k|#define SSH_CHANNEL_FLAG_NOT_BOUND 0x0008
  ------------------
  127|       |
  128|  1.31k|    if (session->channels == NULL) {
  ------------------
  |  Branch (128:9): [True: 1.31k, False: 1]
  ------------------
  129|  1.31k|        session->channels = ssh_list_new();
  130|  1.31k|        if (session->channels == NULL) {
  ------------------
  |  Branch (130:13): [True: 0, False: 1.31k]
  ------------------
  131|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  132|      0|            SSH_BUFFER_FREE(channel->stdout_buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  133|      0|            SSH_BUFFER_FREE(channel->stderr_buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  134|      0|            SAFE_FREE(channel);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  135|      0|            return NULL;
  136|      0|        }
  137|  1.31k|    }
  138|       |
  139|  1.31k|    ssh_list_prepend(session->channels, channel);
  140|       |
  141|       |    /* Set states explicitly */
  142|  1.31k|    channel->state = SSH_CHANNEL_STATE_NOT_OPEN;
  143|  1.31k|    channel->request_state = SSH_CHANNEL_REQ_STATE_NONE;
  144|       |
  145|  1.31k|    return channel;
  146|  1.31k|}
ssh_channel_new_id:
  158|  1.31k|{
  159|  1.31k|    return ++(session->maxchannel);
  160|  1.31k|}
ssh_packet_channel_open_conf:
  170|    657|{
  171|    657|    uint32_t channelid = 0;
  172|    657|    ssh_channel channel = NULL;
  173|    657|    int rc;
  174|    657|    (void)type;
  175|    657|    (void)user;
  176|       |
  177|    657|    SSH_LOG(SSH_LOG_PACKET, "Received SSH2_MSG_CHANNEL_OPEN_CONFIRMATION");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  178|       |
  179|    657|    rc = ssh_buffer_unpack(packet, "d", &channelid);
  ------------------
  |  |   60|    657|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  180|    657|    if (rc != SSH_OK)
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (180:9): [True: 0, False: 657]
  ------------------
  181|      0|        goto error;
  182|    657|    channel = ssh_channel_from_local(session, channelid);
  183|    657|    if (channel == NULL) {
  ------------------
  |  Branch (183:9): [True: 0, False: 657]
  ------------------
  184|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  185|      0|                      SSH_FATAL,
  186|      0|                      "Unknown channel id %" PRIu32,
  187|      0|                      (uint32_t)channelid);
  188|       |        /* TODO: Set error marking in channel object */
  189|       |
  190|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  191|      0|    }
  192|       |
  193|    657|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|    657|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  194|    657|                           "ddd",
  195|    657|                           &channel->remote_channel,
  196|    657|                           &channel->remote_window,
  197|    657|                           &channel->remote_maxpacket);
  198|    657|    if (rc != SSH_OK)
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (198:9): [True: 0, False: 657]
  ------------------
  199|      0|        goto error;
  200|       |
  201|    657|    if (channel->remote_maxpacket == 0) {
  ------------------
  |  Branch (201:9): [True: 0, False: 657]
  ------------------
  202|      0|        SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  203|      0|                "Invalid maximum packet size 0 in "
  204|      0|                "SSH2_MSG_CHANNEL_OPEN_CONFIRMATION");
  205|      0|        goto error;
  206|      0|    }
  207|       |
  208|    657|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  209|    657|            "Received a CHANNEL_OPEN_CONFIRMATION for channel %" PRIu32
  210|    657|            ":%" PRIu32,
  211|    657|            channel->local_channel,
  212|    657|            channel->remote_channel);
  213|       |
  214|    657|    if (channel->state != SSH_CHANNEL_STATE_OPENING) {
  ------------------
  |  Branch (214:9): [True: 0, False: 657]
  ------------------
  215|      0|        SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  216|      0|                "SSH2_MSG_CHANNEL_OPEN_CONFIRMATION received in incorrect "
  217|      0|                "channel state %d",
  218|      0|                channel->state);
  219|      0|        goto error;
  220|      0|    }
  221|       |
  222|    657|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  223|    657|            "Remote window : %" PRIu32 ", maxpacket : %" PRIu32,
  224|    657|            channel->remote_window,
  225|    657|            channel->remote_maxpacket);
  226|       |
  227|    657|    channel->state = SSH_CHANNEL_STATE_OPEN;
  228|    657|    channel->flags &= ~SSH_CHANNEL_FLAG_NOT_BOUND;
  ------------------
  |  |   64|    657|#define SSH_CHANNEL_FLAG_NOT_BOUND 0x0008
  ------------------
  229|       |
  230|    657|    ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|    657|    do {                                                      \
  |  |  567|    657|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|    657|        cbtype cb;                                            \
  |  |  569|    657|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 0, False: 657]
  |  |  ------------------
  |  |  570|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  571|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  |  |  572|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  573|      0|            i = i->next;                                      \
  |  |  574|      0|        }                                                     \
  |  |  575|    657|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 657]
  |  |  ------------------
  ------------------
  231|    657|                               ssh_channel_callbacks,
  232|    657|                               channel_open_response_function,
  233|    657|                               channel->session,
  234|    657|                               channel,
  235|    657|                               true /* is_success */);
  236|       |
  237|    657|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
  238|       |
  239|      0|error:
  240|      0|    ssh_set_error(session, SSH_FATAL, "Invalid packet");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  241|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  242|    657|}
ssh_channel_from_local:
  420|  3.28k|{
  421|  3.28k|    struct ssh_iterator *it = NULL;
  422|  3.28k|    ssh_channel channel = NULL;
  423|       |
  424|  3.28k|    for (it = ssh_list_get_iterator(session->channels); it != NULL;
  ------------------
  |  Branch (424:57): [True: 3.28k, False: 0]
  ------------------
  425|  3.28k|         it = it->next) {
  426|  3.28k|        channel = ssh_iterator_value(ssh_channel, it);
  ------------------
  |  |  114|  3.28k|  ((type)((iterator)->data))
  ------------------
  427|  3.28k|        if (channel == NULL) {
  ------------------
  |  Branch (427:13): [True: 0, False: 3.28k]
  ------------------
  428|      0|            continue;
  429|      0|        }
  430|  3.28k|        if (channel->local_channel == id) {
  ------------------
  |  Branch (430:13): [True: 3.28k, False: 0]
  ------------------
  431|  3.28k|            return channel;
  432|  3.28k|        }
  433|  3.28k|    }
  434|       |
  435|      0|    return NULL;
  436|  3.28k|}
channel_rcv_data:
  603|    657|{
  604|    657|    ssh_channel channel = NULL;
  605|    657|    ssh_string str = NULL;
  606|    657|    ssh_buffer buf = NULL;
  607|    657|    void *data = NULL;
  608|    657|    uint32_t len;
  609|    657|    int extended, is_stderr = 0;
  610|    657|    int rest;
  611|       |
  612|    657|    (void)user;
  613|       |
  614|    657|    if (type == SSH2_MSG_CHANNEL_DATA) {
  ------------------
  |  |   58|    657|#define SSH2_MSG_CHANNEL_DATA 94
  ------------------
  |  Branch (614:9): [True: 657, False: 0]
  ------------------
  615|    657|        extended = 0;
  616|    657|    } else { /* SSH_MSG_CHANNEL_EXTENDED_DATA */
  617|      0|        extended = 1;
  618|      0|    }
  619|       |
  620|    657|    channel = channel_from_msg(session, packet);
  621|    657|    if (channel == NULL) {
  ------------------
  |  Branch (621:9): [True: 0, False: 657]
  ------------------
  622|      0|        SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  623|       |
  624|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  625|      0|    }
  626|       |
  627|    657|    if (extended) {
  ------------------
  |  Branch (627:9): [True: 0, False: 657]
  ------------------
  628|      0|        uint32_t data_type_code, rc;
  629|      0|        rc = ssh_buffer_get_u32(packet, &data_type_code);
  630|      0|        if (rc != sizeof(uint32_t)) {
  ------------------
  |  Branch (630:13): [True: 0, False: 0]
  ------------------
  631|      0|            SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  632|      0|                    "Failed to read data type code: rc = %" PRIu32, rc);
  633|       |
  634|      0|            return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  635|      0|        }
  636|      0|        is_stderr = 1;
  637|      0|        data_type_code = ntohl(data_type_code);
  638|      0|        if (data_type_code != SSH2_EXTENDED_DATA_STDERR) {
  ------------------
  |  |   94|      0|#define SSH2_EXTENDED_DATA_STDERR			1
  ------------------
  |  Branch (638:13): [True: 0, False: 0]
  ------------------
  639|      0|            SSH_LOG(SSH_LOG_PACKET, "Invalid data type code %" PRIu32 "!",
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  640|      0|                    data_type_code);
  641|      0|        }
  642|      0|    }
  643|       |
  644|    657|    str = ssh_buffer_get_ssh_string(packet);
  645|    657|    if (str == NULL) {
  ------------------
  |  Branch (645:9): [True: 0, False: 657]
  ------------------
  646|      0|        SSH_LOG(SSH_LOG_PACKET, "Invalid data packet!");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  647|       |
  648|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  649|      0|    }
  650|       |    /* STRING_SIZE_MAX < UINT32_MAX */
  651|    657|    len = (uint32_t)ssh_string_len(str);
  652|       |
  653|    657|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  1.31k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 657]
  |  |  ------------------
  ------------------
  654|    657|            "Channel receiving %" PRIu32 " bytes data%s (local win=%" PRIu32
  655|    657|            " remote win=%" PRIu32 ") on channel %" PRIu32 ":%" PRIu32,
  656|    657|            len,
  657|    657|            is_stderr ? " in stderr" : "",
  658|    657|            channel->local_window,
  659|    657|            channel->remote_window,
  660|    657|            channel->local_channel,
  661|    657|            channel->remote_channel);
  662|       |
  663|    657|    if (len > channel->local_window) {
  ------------------
  |  Branch (663:9): [True: 0, False: 657]
  ------------------
  664|      0|        SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  665|      0|                "Data packet too big for our window(%" PRIu32 " vs %" PRIu32 ")",
  666|      0|                len,
  667|      0|                channel->local_window);
  668|       |
  669|      0|        SSH_STRING_FREE(str);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  670|       |
  671|      0|        ssh_set_error(session, SSH_FATAL, "Window exceeded");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  672|       |
  673|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  674|      0|    }
  675|       |
  676|    657|    data = ssh_string_data(str);
  677|    657|    if (channel_default_bufferize(channel, data, len, is_stderr) < 0) {
  ------------------
  |  Branch (677:9): [True: 0, False: 657]
  ------------------
  678|      0|        SSH_STRING_FREE(str);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  679|       |
  680|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  681|      0|    }
  682|       |
  683|    657|    channel->local_window -= len;
  684|       |
  685|    657|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  686|    657|            "Channel windows are now (local win=%" PRIu32 " remote win=%" PRIu32 ")",
  687|    657|            channel->local_window,
  688|    657|            channel->remote_window);
  689|       |
  690|    657|    SSH_STRING_FREE(str);
  ------------------
  |  |  910|    657|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 657, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
  691|       |
  692|    657|    if (is_stderr) {
  ------------------
  |  Branch (692:9): [True: 0, False: 657]
  ------------------
  693|      0|        buf = channel->stderr_buffer;
  694|    657|    } else {
  695|    657|        buf = channel->stdout_buffer;
  696|    657|    }
  697|       |
  698|    657|    ssh_callbacks_iterate(channel->callbacks,
  ------------------
  |  |  598|    657|    do {                                                              \
  |  |  599|    657|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  600|    657|        _cb_type _cb;                                                 \
  |  |  601|    657|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (601:16): [True: 0, False: 657]
  |  |  ------------------
  |  |  602|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  603|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  ------------------
  699|    657|                          ssh_channel_callbacks,
  700|    657|                          channel_data_function) {
  701|      0|        if (ssh_buffer_get(buf) == NULL) {
  ------------------
  |  Branch (701:13): [True: 0, False: 0]
  ------------------
  702|      0|            break;
  703|      0|        }
  704|      0|        rest = ssh_callbacks_iterate_exec(channel_data_function,
  ------------------
  |  |  612|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  705|      0|                                          channel->session,
  706|      0|                                          channel,
  707|      0|                                          ssh_buffer_get(buf),
  708|      0|                                          ssh_buffer_get_len(buf),
  709|      0|                                          is_stderr);
  710|      0|        if (rest > 0) {
  ------------------
  |  Branch (710:13): [True: 0, False: 0]
  ------------------
  711|      0|            int rc;
  712|      0|            if (channel->counter != NULL) {
  ------------------
  |  Branch (712:17): [True: 0, False: 0]
  ------------------
  713|      0|                channel->counter->in_bytes += rest;
  714|      0|            }
  715|      0|            ssh_buffer_pass_bytes(buf, rest);
  716|       |
  717|      0|            rc = grow_window(session, channel);
  718|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (718:17): [True: 0, False: 0]
  ------------------
  719|      0|              return -1;
  720|      0|            }
  721|      0|        }
  722|      0|    }
  723|    657|    ssh_callbacks_iterate_end();
  ------------------
  |  |  618|      0|        }                           \
  |  |  619|    657|    } while(0)
  |  |  ------------------
  |  |  |  Branch (619:13): [Folded, False: 657]
  |  |  ------------------
  ------------------
  724|       |
  725|    657|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
  726|    657|}
channel_rcv_eof:
  729|    657|{
  730|    657|    ssh_channel channel = NULL;
  731|    657|    (void)user;
  732|    657|    (void)type;
  733|       |
  734|    657|    channel = channel_from_msg(session, packet);
  735|    657|    if (channel == NULL) {
  ------------------
  |  Branch (735:9): [True: 0, False: 657]
  ------------------
  736|      0|        SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  737|       |
  738|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  739|      0|    }
  740|       |
  741|    657|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  742|    657|            "Received eof on channel (%" PRIu32 ":%" PRIu32 ")",
  743|    657|            channel->local_channel,
  744|    657|            channel->remote_channel);
  745|       |    /* channel->remote_window = 0; */
  746|    657|    channel->remote_eof = 1;
  747|       |
  748|    657|    ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|    657|    do {                                                      \
  |  |  567|    657|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|    657|        cbtype cb;                                            \
  |  |  569|    657|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 0, False: 657]
  |  |  ------------------
  |  |  570|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  571|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  |  |  572|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  573|      0|            i = i->next;                                      \
  |  |  574|      0|        }                                                     \
  |  |  575|    657|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 657]
  |  |  ------------------
  ------------------
  749|    657|                               ssh_channel_callbacks,
  750|    657|                               channel_eof_function,
  751|    657|                               channel->session,
  752|    657|                               channel);
  753|       |
  754|    657|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
  755|    657|}
channel_rcv_close:
  775|    657|{
  776|    657|    ssh_channel channel = NULL;
  777|    657|    (void)user;
  778|    657|    (void)type;
  779|       |
  780|    657|    channel = channel_from_msg(session,packet);
  781|    657|    if (channel == NULL) {
  ------------------
  |  Branch (781:9): [True: 0, False: 657]
  ------------------
  782|      0|        SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  783|       |
  784|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  785|      0|    }
  786|       |
  787|    657|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  788|    657|        "Received close on channel (%" PRIu32 ":%" PRIu32 ")",
  789|    657|        channel->local_channel,
  790|    657|        channel->remote_channel);
  791|       |
  792|    657|    if (!ssh_channel_has_unread_data(channel)) {
  ------------------
  |  Branch (792:9): [True: 0, False: 657]
  ------------------
  793|      0|        channel->state = SSH_CHANNEL_STATE_CLOSED;
  794|    657|    } else {
  795|    657|        channel->delayed_close = 1;
  796|    657|    }
  797|       |
  798|    657|    if (channel->remote_eof == 0) {
  ------------------
  |  Branch (798:9): [True: 0, False: 657]
  ------------------
  799|      0|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  800|      0|            "Remote host not polite enough to send an eof before close");
  801|      0|    }
  802|       |    /*
  803|       |    * The remote eof doesn't break things if there was still data into read
  804|       |    * buffer because the eof is ignored until the buffer is empty.
  805|       |    */
  806|    657|    channel->remote_eof = 1;
  807|       |
  808|    657|    ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|    657|    do {                                                      \
  |  |  567|    657|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|    657|        cbtype cb;                                            \
  |  |  569|    657|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 0, False: 657]
  |  |  ------------------
  |  |  570|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  571|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  |  |  572|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  573|      0|            i = i->next;                                      \
  |  |  574|      0|        }                                                     \
  |  |  575|    657|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 657]
  |  |  ------------------
  ------------------
  809|    657|                               ssh_channel_callbacks,
  810|    657|                               channel_close_function,
  811|    657|                               channel->session,
  812|    657|                               channel);
  813|       |
  814|    657|    channel->flags |= SSH_CHANNEL_FLAG_CLOSED_REMOTE;
  ------------------
  |  |   55|    657|#define SSH_CHANNEL_FLAG_CLOSED_REMOTE 0x0001
  ------------------
  815|    657|    if(channel->flags & SSH_CHANNEL_FLAG_FREED_LOCAL)
  ------------------
  |  |   61|    657|#define SSH_CHANNEL_FLAG_FREED_LOCAL 0x0004
  ------------------
  |  Branch (815:8): [True: 0, False: 657]
  ------------------
  816|      0|        ssh_channel_do_free(channel);
  817|       |
  818|    657|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
  819|    657|}
channel_rcv_request:
  822|    657|{
  823|    657|    ssh_channel channel = NULL;
  824|    657|    char *request = NULL;
  825|    657|    uint8_t want_reply;
  826|    657|    int rc;
  827|    657|    (void)user;
  828|    657|    (void)type;
  829|       |
  830|    657|    channel = channel_from_msg(session, packet);
  831|    657|    if (channel == NULL) {
  ------------------
  |  Branch (831:9): [True: 0, False: 657]
  ------------------
  832|      0|        SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  833|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  834|      0|    }
  835|       |
  836|    657|    rc = ssh_buffer_unpack(packet, "sb", &request, &want_reply);
  ------------------
  |  |   60|    657|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  837|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (837:9): [True: 0, False: 657]
  ------------------
  838|      0|        SSH_LOG(SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  839|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  840|      0|    }
  841|       |
  842|    657|    if (strcmp(request, "exit-status") == 0) {
  ------------------
  |  Branch (842:9): [True: 0, False: 657]
  ------------------
  843|      0|        SAFE_FREE(request);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  844|      0|        rc = ssh_buffer_unpack(packet, "d", &channel->exit.code);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  845|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (845:13): [True: 0, False: 0]
  ------------------
  846|      0|            SSH_LOG(SSH_LOG_PACKET, "Invalid exit-status packet");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  847|      0|            return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  848|      0|        }
  849|      0|        channel->exit.status = true;
  850|       |
  851|      0|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  852|      0|                "received exit-status %u on channel %" PRIu32 ":%" PRIu32,
  853|      0|                channel->exit.code,
  854|      0|                channel->local_channel,
  855|      0|                channel->remote_channel);
  856|       |
  857|      0|        ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|      0|    do {                                                      \
  |  |  567|      0|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|      0|        cbtype cb;                                            \
  |  |  569|      0|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  570|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  571|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  |  |  572|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  573|      0|            i = i->next;                                      \
  |  |  574|      0|        }                                                     \
  |  |  575|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  858|      0|                                   ssh_channel_callbacks,
  859|      0|                                   channel_exit_status_function,
  860|      0|                                   channel->session,
  861|      0|                                   channel,
  862|      0|                                   channel->exit.code);
  863|       |
  864|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  865|      0|    }
  866|       |
  867|    657|    if (strcmp(request, "signal") == 0) {
  ------------------
  |  Branch (867:9): [True: 0, False: 657]
  ------------------
  868|      0|        char *sig = NULL;
  869|       |
  870|      0|        SAFE_FREE(request);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  871|      0|        SSH_LOG(SSH_LOG_PACKET, "received signal");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  872|       |
  873|      0|        rc = ssh_buffer_unpack(packet, "s", &sig);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  874|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (874:13): [True: 0, False: 0]
  ------------------
  875|      0|            SSH_LOG(SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  876|      0|            return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  877|      0|        }
  878|       |
  879|      0|        SSH_LOG(SSH_LOG_PACKET, "Remote connection sent a signal SIG %s", sig);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  880|      0|        ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|      0|    do {                                                      \
  |  |  567|      0|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|      0|        cbtype cb;                                            \
  |  |  569|      0|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  570|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  571|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  |  |  572|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  573|      0|            i = i->next;                                      \
  |  |  574|      0|        }                                                     \
  |  |  575|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  881|      0|                                   ssh_channel_callbacks,
  882|      0|                                   channel_signal_function,
  883|      0|                                   channel->session,
  884|      0|                                   channel,
  885|      0|                                   sig);
  886|      0|        SAFE_FREE(sig);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  887|       |
  888|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  889|      0|    }
  890|       |
  891|    657|    if (strcmp(request, "exit-signal") == 0) {
  ------------------
  |  Branch (891:9): [True: 0, False: 657]
  ------------------
  892|      0|        const char *core = "(core dumped)";
  893|      0|        char *sig = NULL;
  894|      0|        char *errmsg = NULL;
  895|      0|        char *lang = NULL;
  896|      0|        uint8_t core_dumped;
  897|       |
  898|      0|        SAFE_FREE(request);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  899|       |
  900|      0|        rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  901|      0|                               "sbss",
  902|      0|                               &sig,         /* signal name */
  903|      0|                               &core_dumped, /* core dumped */
  904|      0|                               &errmsg,      /* error message */
  905|      0|                               &lang);
  906|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (906:13): [True: 0, False: 0]
  ------------------
  907|      0|            SSH_LOG(SSH_LOG_PACKET, "Invalid MSG_CHANNEL_REQUEST");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  908|      0|            return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  909|      0|        }
  910|       |
  911|      0|        if (core_dumped == 0) {
  ------------------
  |  Branch (911:13): [True: 0, False: 0]
  ------------------
  912|      0|            core = "";
  913|      0|        }
  914|       |
  915|      0|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  916|      0|                "Remote connection closed by signal SIG %s %s",
  917|      0|                sig,
  918|      0|                core);
  919|      0|        ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|      0|    do {                                                      \
  |  |  567|      0|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|      0|        cbtype cb;                                            \
  |  |  569|      0|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  570|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  571|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  |  |  572|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  573|      0|            i = i->next;                                      \
  |  |  574|      0|        }                                                     \
  |  |  575|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  920|      0|                                   ssh_channel_callbacks,
  921|      0|                                   channel_exit_signal_function,
  922|      0|                                   channel->session,
  923|      0|                                   channel,
  924|      0|                                   sig,
  925|      0|                                   core_dumped,
  926|      0|                                   errmsg,
  927|      0|                                   lang);
  928|       |
  929|      0|        channel->exit.core_dumped = core_dumped;
  930|      0|        if (sig != NULL) {
  ------------------
  |  Branch (930:13): [True: 0, False: 0]
  ------------------
  931|      0|            SAFE_FREE(channel->exit.signal);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  932|      0|            channel->exit.signal = sig;
  933|      0|        }
  934|      0|        channel->exit.status = true;
  935|       |
  936|      0|        SAFE_FREE(lang);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  937|      0|        SAFE_FREE(errmsg);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  938|       |
  939|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  940|      0|    }
  941|    657|    if (strcmp(request, "keepalive@openssh.com") == 0) {
  ------------------
  |  Branch (941:9): [True: 0, False: 657]
  ------------------
  942|      0|        SAFE_FREE(request);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  943|      0|        SSH_LOG(SSH_LOG_DEBUG, "Responding to Openssh's keepalive");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  944|       |
  945|      0|        rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  946|      0|                             "bd",
  947|      0|                             SSH2_MSG_CHANNEL_FAILURE,
  948|      0|                             channel->remote_channel);
  949|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (949:13): [True: 0, False: 0]
  ------------------
  950|      0|            return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  951|      0|        }
  952|      0|        ssh_packet_send(session);
  953|       |
  954|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  955|      0|    }
  956|       |
  957|    657|    if (strcmp(request, "auth-agent-req") == 0 ||
  ------------------
  |  Branch (957:9): [True: 0, False: 657]
  ------------------
  958|    657|        strcmp(request, "auth-agent-req@openssh.com") == 0) {
  ------------------
  |  Branch (958:9): [True: 0, False: 657]
  ------------------
  959|      0|        int status;
  960|       |
  961|      0|        SAFE_FREE(request);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  962|      0|        SSH_LOG(SSH_LOG_DEBUG, "Received an auth-agent-req request");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  963|       |
  964|      0|        status = SSH2_MSG_CHANNEL_FAILURE;
  ------------------
  |  |   64|      0|#define SSH2_MSG_CHANNEL_FAILURE 100
  ------------------
  965|      0|        ssh_callbacks_iterate (channel->callbacks,
  ------------------
  |  |  598|      0|    do {                                                              \
  |  |  599|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  600|      0|        _cb_type _cb;                                                 \
  |  |  601|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (601:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  602|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  603|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  ------------------
  966|      0|                               ssh_channel_callbacks,
  967|      0|                               channel_auth_agent_req_function) {
  968|      0|            ssh_callbacks_iterate_exec(channel_auth_agent_req_function,
  ------------------
  |  |  612|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  969|      0|                                       channel->session,
  970|      0|                                       channel);
  971|       |            /* in lieu of a return value, if the callback exists it's supported
  972|       |             */
  973|      0|            status = SSH2_MSG_CHANNEL_SUCCESS;
  ------------------
  |  |   63|      0|#define SSH2_MSG_CHANNEL_SUCCESS 99
  ------------------
  974|      0|            break;
  975|      0|        }
  976|      0|        ssh_callbacks_iterate_end();
  ------------------
  |  |  618|      0|        }                           \
  |  |  619|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (619:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  977|       |
  978|      0|        if (want_reply) {
  ------------------
  |  Branch (978:13): [True: 0, False: 0]
  ------------------
  979|      0|            rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  980|      0|                                 "bd",
  981|      0|                                 status,
  982|      0|                                 channel->remote_channel);
  983|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (983:17): [True: 0, False: 0]
  ------------------
  984|      0|                return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  985|      0|            }
  986|      0|            ssh_packet_send(session);
  987|      0|        }
  988|       |
  989|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  990|      0|    }
  991|    657|#ifdef WITH_SERVER
  992|       |    /* If we are here, that means we have a request that is not in the
  993|       |     * understood client requests. That means we need to create a ssh message to
  994|       |     * be passed to the user code handling ssh messages
  995|       |     */
  996|    657|    ssh_message_handle_channel_request(session,
  997|    657|                                       channel,
  998|    657|                                       packet,
  999|    657|                                       request,
 1000|    657|                                       want_reply);
 1001|       |#else
 1002|       |    SSH_LOG(SSH_LOG_DEBUG, "Unhandled channel request %s", request);
 1003|       |#endif
 1004|       |
 1005|    657|    SAFE_FREE(request);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
 1006|       |
 1007|    657|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
 1008|    657|}
channel_default_bufferize:
 1019|    657|{
 1020|    657|    ssh_session session = NULL;
 1021|       |
 1022|    657|    if (channel == NULL) {
  ------------------
  |  Branch (1022:9): [True: 0, False: 657]
  ------------------
 1023|      0|        return -1;
 1024|      0|    }
 1025|       |
 1026|    657|    session = channel->session;
 1027|       |
 1028|    657|    if (data == NULL) {
  ------------------
  |  Branch (1028:9): [True: 0, False: 657]
  ------------------
 1029|      0|        ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1030|      0|        return -1;
 1031|      0|    }
 1032|       |
 1033|    657|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  1.31k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 657]
  |  |  ------------------
  ------------------
 1034|    657|            "placing %" PRIu32 " bytes into channel buffer (%s)",
 1035|    657|            len,
 1036|    657|            is_stderr ? "stderr" : "stdout");
 1037|    657|    if (!is_stderr) {
  ------------------
  |  Branch (1037:9): [True: 657, False: 0]
  ------------------
 1038|       |        /* stdout */
 1039|    657|        if (channel->stdout_buffer == NULL) {
  ------------------
  |  Branch (1039:13): [True: 0, False: 657]
  ------------------
 1040|      0|            channel->stdout_buffer = ssh_buffer_new();
 1041|      0|            if (channel->stdout_buffer == NULL) {
  ------------------
  |  Branch (1041:17): [True: 0, False: 0]
  ------------------
 1042|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1043|      0|                return -1;
 1044|      0|            }
 1045|      0|        }
 1046|       |
 1047|    657|        if (ssh_buffer_add_data(channel->stdout_buffer, data, len) < 0) {
  ------------------
  |  Branch (1047:13): [True: 0, False: 657]
  ------------------
 1048|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1049|      0|            SSH_BUFFER_FREE(channel->stdout_buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1050|      0|            channel->stdout_buffer = NULL;
 1051|      0|            return -1;
 1052|      0|        }
 1053|    657|    } else {
 1054|       |        /* stderr */
 1055|      0|        if (channel->stderr_buffer == NULL) {
  ------------------
  |  Branch (1055:13): [True: 0, False: 0]
  ------------------
 1056|      0|            channel->stderr_buffer = ssh_buffer_new();
 1057|      0|            if (channel->stderr_buffer == NULL) {
  ------------------
  |  Branch (1057:17): [True: 0, False: 0]
  ------------------
 1058|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1059|      0|                return -1;
 1060|      0|            }
 1061|      0|        }
 1062|       |
 1063|      0|        if (ssh_buffer_add_data(channel->stderr_buffer, data, len) < 0) {
  ------------------
  |  Branch (1063:13): [True: 0, False: 0]
  ------------------
 1064|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1065|      0|            SSH_BUFFER_FREE(channel->stderr_buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1066|      0|            channel->stderr_buffer = NULL;
 1067|      0|            return -1;
 1068|      0|        }
 1069|      0|    }
 1070|       |
 1071|    657|    return 0;
 1072|    657|}
ssh_channel_open_session:
 1090|    658|{
 1091|    658|  if (channel == NULL) {
  ------------------
  |  Branch (1091:7): [True: 0, False: 658]
  ------------------
 1092|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1093|      0|  }
 1094|       |
 1095|    658|  return channel_open(channel,
 1096|    658|                      "session",
 1097|    658|                      WINDOW_DEFAULT,
  ------------------
  |  |   67|    658|#define WINDOW_DEFAULT (64*CHANNEL_MAX_PACKET)
  |  |  ------------------
  |  |  |  |   60|    658|#define CHANNEL_MAX_PACKET 32768
  |  |  ------------------
  ------------------
 1098|    658|                      CHANNEL_MAX_PACKET,
  ------------------
  |  |   60|    658|#define CHANNEL_MAX_PACKET 32768
  ------------------
 1099|       |                      NULL);
 1100|    658|}
ssh_channel_free:
 1294|    658|{
 1295|    658|    ssh_session session = NULL;
 1296|       |
 1297|    658|    if (channel == NULL) {
  ------------------
  |  Branch (1297:9): [True: 0, False: 658]
  ------------------
 1298|      0|        return;
 1299|      0|    }
 1300|       |
 1301|    658|    session = channel->session;
 1302|    658|    if (session->alive) {
  ------------------
  |  Branch (1302:9): [True: 0, False: 658]
  ------------------
 1303|      0|        bool send_close = false;
 1304|       |
 1305|      0|        switch (channel->state) {
 1306|      0|        case SSH_CHANNEL_STATE_OPEN:
  ------------------
  |  Branch (1306:9): [True: 0, False: 0]
  ------------------
 1307|      0|            send_close = true;
 1308|      0|            break;
 1309|      0|        case SSH_CHANNEL_STATE_CLOSED:
  ------------------
  |  Branch (1309:9): [True: 0, False: 0]
  ------------------
 1310|      0|            if (channel->flags & SSH_CHANNEL_FLAG_CLOSED_REMOTE) {
  ------------------
  |  |   55|      0|#define SSH_CHANNEL_FLAG_CLOSED_REMOTE 0x0001
  ------------------
  |  Branch (1310:17): [True: 0, False: 0]
  ------------------
 1311|      0|                send_close = true;
 1312|      0|            }
 1313|      0|            if (channel->flags & SSH_CHANNEL_FLAG_CLOSED_LOCAL) {
  ------------------
  |  |   58|      0|#define SSH_CHANNEL_FLAG_CLOSED_LOCAL 0x0002
  ------------------
  |  Branch (1313:17): [True: 0, False: 0]
  ------------------
 1314|      0|                send_close = false;
 1315|      0|            }
 1316|      0|            break;
 1317|      0|        default:
  ------------------
  |  Branch (1317:9): [True: 0, False: 0]
  ------------------
 1318|      0|            send_close = false;
 1319|      0|            break;
 1320|      0|        }
 1321|       |
 1322|      0|        if (send_close) {
  ------------------
  |  Branch (1322:13): [True: 0, False: 0]
  ------------------
 1323|      0|            ssh_channel_close(channel);
 1324|      0|        }
 1325|      0|    }
 1326|    658|    channel->flags |= SSH_CHANNEL_FLAG_FREED_LOCAL;
  ------------------
  |  |   61|    658|#define SSH_CHANNEL_FLAG_FREED_LOCAL 0x0004
  ------------------
 1327|       |
 1328|    658|    if (channel->callbacks != NULL) {
  ------------------
  |  Branch (1328:9): [True: 0, False: 658]
  ------------------
 1329|      0|        ssh_list_free(channel->callbacks);
 1330|      0|        channel->callbacks = NULL;
 1331|      0|    }
 1332|       |
 1333|       |    /* The idea behind the flags is the following : it is well possible
 1334|       |     * that a client closes a channel that still exists on the server side.
 1335|       |     * We definitively close the channel when we receive a close message *and*
 1336|       |     * the user closed it.
 1337|       |     */
 1338|    658|    if ((channel->flags & SSH_CHANNEL_FLAG_CLOSED_REMOTE) ||
  ------------------
  |  |   55|    658|#define SSH_CHANNEL_FLAG_CLOSED_REMOTE 0x0001
  ------------------
  |  Branch (1338:9): [True: 657, False: 1]
  ------------------
 1339|    658|        (channel->flags & SSH_CHANNEL_FLAG_NOT_BOUND)) {
  ------------------
  |  |   64|      1|#define SSH_CHANNEL_FLAG_NOT_BOUND 0x0008
  ------------------
  |  Branch (1339:9): [True: 1, False: 0]
  ------------------
 1340|    658|        ssh_channel_do_free(channel);
 1341|    658|    }
 1342|    658|}
ssh_channel_do_free:
 1350|  1.31k|{
 1351|  1.31k|    struct ssh_iterator *it = NULL;
 1352|  1.31k|    ssh_session session = channel->session;
 1353|       |
 1354|  1.31k|    it = ssh_list_find(session->channels, channel);
 1355|  1.31k|    if (it != NULL) {
  ------------------
  |  Branch (1355:9): [True: 1.31k, False: 0]
  ------------------
 1356|  1.31k|        ssh_list_remove(session->channels, it);
 1357|  1.31k|    }
 1358|       |
 1359|  1.31k|    SSH_BUFFER_FREE(channel->stdout_buffer);
  ------------------
  |  |  951|  1.31k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 1.31k, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 1360|  1.31k|    SSH_BUFFER_FREE(channel->stderr_buffer);
  ------------------
  |  |  951|  1.31k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 1.31k, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 1361|       |
 1362|  1.31k|    if (channel->callbacks != NULL) {
  ------------------
  |  Branch (1362:9): [True: 657, False: 658]
  ------------------
 1363|    657|        ssh_list_free(channel->callbacks);
 1364|    657|        channel->callbacks = NULL;
 1365|    657|    }
 1366|  1.31k|    SAFE_FREE(channel->exit.signal);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 1367|       |
 1368|  1.31k|    channel->session = NULL;
 1369|       |    SAFE_FREE(channel);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 1370|  1.31k|}
ssh_channel_send_eof:
 1401|  2.63k|{
 1402|  2.63k|    ssh_session session = NULL;
 1403|  2.63k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  2.63k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1404|  2.63k|    int err;
 1405|       |
 1406|  2.63k|    if (channel == NULL || channel->session == NULL) {
  ------------------
  |  Branch (1406:9): [True: 0, False: 2.63k]
  |  Branch (1406:28): [True: 0, False: 2.63k]
  ------------------
 1407|      0|        return rc;
 1408|      0|    }
 1409|       |
 1410|       |    /* If the EOF has already been sent we're done here. */
 1411|  2.63k|    if (channel->local_eof != 0) {
  ------------------
  |  Branch (1411:9): [True: 1.31k, False: 1.31k]
  ------------------
 1412|  1.31k|        return SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
 1413|  1.31k|    }
 1414|       |
 1415|  1.31k|    session = channel->session;
 1416|       |
 1417|  1.31k|    err = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|  1.31k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.31k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.31k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.31k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.31k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1418|  1.31k|                          "bd",
 1419|  1.31k|                          SSH2_MSG_CHANNEL_EOF,
 1420|  1.31k|                          channel->remote_channel);
 1421|  1.31k|    if (err != SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1421:9): [True: 0, False: 1.31k]
  ------------------
 1422|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1423|      0|        goto error;
 1424|      0|    }
 1425|       |
 1426|  1.31k|    rc = ssh_packet_send(session);
 1427|  1.31k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  1.31k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1428|  1.31k|        "Sent a EOF on client channel (%" PRIu32 ":%" PRIu32 ")",
 1429|  1.31k|        channel->local_channel,
 1430|  1.31k|        channel->remote_channel);
 1431|  1.31k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1431:9): [True: 4, False: 1.31k]
  ------------------
 1432|      4|        goto error;
 1433|      4|    }
 1434|       |
 1435|  1.31k|    rc = ssh_channel_flush(channel);
 1436|  1.31k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1436:9): [True: 0, False: 1.31k]
  ------------------
 1437|      0|        goto error;
 1438|      0|    }
 1439|  1.31k|    channel->local_eof = 1;
 1440|       |
 1441|  1.31k|    return rc;
 1442|      4|error:
 1443|      4|    ssh_buffer_reinit(session->out_buffer);
 1444|       |
 1445|      4|    return rc;
 1446|  1.31k|}
ssh_channel_close:
 1462|  1.31k|{
 1463|  1.31k|    ssh_session session = NULL;
 1464|  1.31k|    int rc = 0;
 1465|       |
 1466|  1.31k|    if(channel == NULL) {
  ------------------
  |  Branch (1466:8): [True: 0, False: 1.31k]
  ------------------
 1467|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1468|      0|    }
 1469|       |
 1470|       |    /* If the channel close has already been sent we're done here. */
 1471|  1.31k|    if (channel->flags & SSH_CHANNEL_FLAG_CLOSED_LOCAL) {
  ------------------
  |  |   58|  1.31k|#define SSH_CHANNEL_FLAG_CLOSED_LOCAL 0x0002
  ------------------
  |  Branch (1471:9): [True: 0, False: 1.31k]
  ------------------
 1472|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1473|      0|    }
 1474|       |
 1475|  1.31k|    session = channel->session;
 1476|       |
 1477|  1.31k|    rc = ssh_channel_send_eof(channel);
 1478|  1.31k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1478:9): [True: 0, False: 1.31k]
  ------------------
 1479|      0|        return rc;
 1480|      0|    }
 1481|       |
 1482|  1.31k|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|  1.31k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.31k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.31k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.31k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.31k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1483|  1.31k|                         "bd",
 1484|  1.31k|                         SSH2_MSG_CHANNEL_CLOSE,
 1485|  1.31k|                         channel->remote_channel);
 1486|  1.31k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1486:9): [True: 0, False: 1.31k]
  ------------------
 1487|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1488|      0|        goto error;
 1489|      0|    }
 1490|       |
 1491|  1.31k|    rc = ssh_packet_send(session);
 1492|  1.31k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  1.31k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1493|  1.31k|            "Sent a close on client channel (%" PRIu32 ":%" PRIu32 ")",
 1494|  1.31k|            channel->local_channel,
 1495|  1.31k|            channel->remote_channel);
 1496|       |
 1497|  1.31k|    if (rc == SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1497:9): [True: 657, False: 656]
  ------------------
 1498|    657|        channel->state = SSH_CHANNEL_STATE_CLOSED;
 1499|    657|        channel->flags |= SSH_CHANNEL_FLAG_CLOSED_LOCAL;
  ------------------
  |  |   58|    657|#define SSH_CHANNEL_FLAG_CLOSED_LOCAL 0x0002
  ------------------
 1500|    657|    }
 1501|       |
 1502|  1.31k|    rc = ssh_channel_flush(channel);
 1503|  1.31k|    if(rc == SSH_ERROR) {
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1503:8): [True: 0, False: 1.31k]
  ------------------
 1504|      0|        goto error;
 1505|      0|    }
 1506|       |
 1507|  1.31k|    return rc;
 1508|      0|error:
 1509|      0|    ssh_buffer_reinit(session->out_buffer);
 1510|       |
 1511|      0|    return rc;
 1512|  1.31k|}
ssh_channel_flush:
 1551|  3.28k|{
 1552|  3.28k|    return ssh_blocking_flush(channel->session, SSH_TIMEOUT_DEFAULT);
  ------------------
  |  |  103|  3.28k|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
 1553|  3.28k|}
ssh_channel_write:
 1744|    658|{
 1745|    658|    return channel_write_common(channel, data, len, 0);
 1746|    658|}
ssh_channel_is_closed:
 1775|  1.97k|{
 1776|  1.97k|    if (channel == NULL || channel->session == NULL) {
  ------------------
  |  Branch (1776:9): [True: 0, False: 1.97k]
  |  Branch (1776:28): [True: 0, False: 1.97k]
  ------------------
 1777|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1778|      0|    }
 1779|  1.97k|    return (channel->state != SSH_CHANNEL_STATE_OPEN || channel->session->alive == 0);
  ------------------
  |  Branch (1779:13): [True: 657, False: 1.31k]
  |  Branch (1779:57): [True: 0, False: 1.31k]
  ------------------
 1780|  1.97k|}
ssh_channel_is_eof:
 1790|  1.97k|{
 1791|  1.97k|    if (channel == NULL) {
  ------------------
  |  Branch (1791:9): [True: 0, False: 1.97k]
  ------------------
 1792|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1793|      0|    }
 1794|  1.97k|    if (ssh_channel_has_unread_data(channel)) {
  ------------------
  |  Branch (1794:9): [True: 656, False: 1.31k]
  ------------------
 1795|    656|        return 0;
 1796|    656|    }
 1797|       |
 1798|  1.31k|    return (channel->remote_eof != 0);
 1799|  1.97k|}
ssh_packet_channel_success:
 1826|      1|{
 1827|      1|    ssh_channel channel = NULL;
 1828|      1|    (void)type;
 1829|      1|    (void)user;
 1830|       |
 1831|      1|    channel = channel_from_msg(session, packet);
 1832|      1|    if (channel == NULL) {
  ------------------
  |  Branch (1832:9): [True: 0, False: 1]
  ------------------
 1833|      0|        SSH_LOG(SSH_LOG_FUNCTIONS, "%s", ssh_get_error(session));
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1834|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
 1835|      0|    }
 1836|       |
 1837|      1|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1838|      1|            "Received SSH_CHANNEL_SUCCESS on channel (%" PRIu32 ":%" PRIu32 ")",
 1839|      1|            channel->local_channel,
 1840|      1|            channel->remote_channel);
 1841|      1|    if (channel->request_state != SSH_CHANNEL_REQ_STATE_PENDING) {
  ------------------
  |  Branch (1841:9): [True: 0, False: 1]
  ------------------
 1842|      0|        SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1843|      0|                "SSH_CHANNEL_SUCCESS received in incorrect state %d",
 1844|      0|                channel->request_state);
 1845|      1|    } else {
 1846|      1|        channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED;
 1847|       |
 1848|      1|        ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|      1|    do {                                                      \
  |  |  567|      1|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|      1|        cbtype cb;                                            \
  |  |  569|      1|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 0, False: 1]
  |  |  ------------------
  |  |  570|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  571|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  |  |  572|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  573|      0|            i = i->next;                                      \
  |  |  574|      0|        }                                                     \
  |  |  575|      1|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 1]
  |  |  ------------------
  ------------------
 1849|      1|                                   ssh_channel_callbacks,
 1850|      1|                                   channel_request_response_function,
 1851|      1|                                   channel->session,
 1852|      1|                                   channel);
 1853|      1|    }
 1854|       |
 1855|      1|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      1|#define SSH_PACKET_USED 1
  ------------------
 1856|      1|}
ssh_channel_request_exec:
 2877|    657|{
 2878|    657|  ssh_buffer buffer = NULL;
 2879|    657|  int rc = SSH_ERROR;
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2880|       |
 2881|    657|  if(channel == NULL) {
  ------------------
  |  Branch (2881:6): [True: 0, False: 657]
  ------------------
 2882|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2883|      0|  }
 2884|    657|  if(cmd == NULL) {
  ------------------
  |  Branch (2884:6): [True: 0, False: 657]
  ------------------
 2885|      0|      ssh_set_error_invalid(channel->session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2886|      0|      return rc;
 2887|      0|  }
 2888|       |
 2889|    657|  switch(channel->request_state){
 2890|    657|  case SSH_CHANNEL_REQ_STATE_NONE:
  ------------------
  |  Branch (2890:3): [True: 657, False: 0]
  ------------------
 2891|    657|    break;
 2892|      0|  default:
  ------------------
  |  Branch (2892:3): [True: 0, False: 657]
  ------------------
 2893|      0|    goto pending;
 2894|    657|  }
 2895|    657|  buffer = ssh_buffer_new();
 2896|    657|  if (buffer == NULL) {
  ------------------
  |  Branch (2896:7): [True: 0, False: 657]
  ------------------
 2897|      0|    ssh_set_error_oom(channel->session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2898|      0|    goto error;
 2899|      0|  }
 2900|       |
 2901|    657|  rc = ssh_buffer_pack(buffer, "s", cmd);
  ------------------
  |  |   50|    657|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 2902|       |
 2903|    657|  if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2903:7): [True: 0, False: 657]
  ------------------
 2904|      0|    ssh_set_error_oom(channel->session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2905|      0|    goto error;
 2906|      0|  }
 2907|    657|pending:
 2908|    657|  rc = channel_request(channel, "exec", buffer, 1);
 2909|    657|error:
 2910|       |  SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|    657|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 657, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
 2911|    657|  return rc;
 2912|    657|}
ssh_channel_read:
 3139|  4.75k|{
 3140|  4.75k|    return ssh_channel_read_timeout(channel,
 3141|  4.75k|                                    dest,
 3142|  4.75k|                                    count,
 3143|  4.75k|                                    is_stderr,
 3144|  4.75k|                                    SSH_TIMEOUT_DEFAULT);
  ------------------
  |  |  103|  4.75k|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
 3145|  4.75k|}
ssh_channel_read_timeout:
 3172|  4.75k|{
 3173|  4.75k|    ssh_session session = NULL;
 3174|  4.75k|    ssh_buffer stdbuf = NULL;
 3175|  4.75k|    uint32_t len;
 3176|  4.75k|    struct ssh_channel_read_termination_struct ctx;
 3177|  4.75k|    int rc;
 3178|       |
 3179|  4.75k|    if (channel == NULL) {
  ------------------
  |  Branch (3179:9): [True: 0, False: 4.75k]
  ------------------
 3180|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3181|      0|    }
 3182|  4.75k|    if (dest == NULL) {
  ------------------
  |  Branch (3182:9): [True: 0, False: 4.75k]
  ------------------
 3183|      0|        ssh_set_error_invalid(channel->session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3184|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3185|      0|    }
 3186|       |
 3187|  4.75k|    session = channel->session;
 3188|  4.75k|    stdbuf = channel->stdout_buffer;
 3189|       |
 3190|  4.75k|    if (count == 0) {
  ------------------
  |  Branch (3190:9): [True: 0, False: 4.75k]
  ------------------
 3191|      0|        return 0;
 3192|      0|    }
 3193|       |
 3194|  4.75k|    if (is_stderr) {
  ------------------
  |  Branch (3194:9): [True: 0, False: 4.75k]
  ------------------
 3195|      0|        stdbuf = channel->stderr_buffer;
 3196|      0|    }
 3197|       |
 3198|  4.75k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  4.75k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3199|  4.75k|            "Read (%" PRIu32 ") buffered : %" PRIu32 " bytes. Window: %" PRIu32,
 3200|  4.75k|            count,
 3201|  4.75k|            ssh_buffer_get_len(stdbuf),
 3202|  4.75k|            channel->local_window);
 3203|       |
 3204|       |    /* block reading until at least one byte has been read
 3205|       |     * and ignore the trivial case count=0
 3206|       |     */
 3207|  4.75k|    ctx.channel = channel;
 3208|  4.75k|    ctx.buffer = stdbuf;
 3209|       |
 3210|  4.75k|    if (timeout_ms < SSH_TIMEOUT_DEFAULT) {
  ------------------
  |  |  103|  4.75k|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
  |  Branch (3210:9): [True: 0, False: 4.75k]
  ------------------
 3211|      0|        timeout_ms = SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|      0|#define SSH_TIMEOUT_INFINITE -1
  ------------------
 3212|      0|    }
 3213|       |
 3214|  4.75k|    rc = ssh_handle_packets_termination(session,
 3215|  4.75k|                                        timeout_ms,
 3216|  4.75k|                                        ssh_channel_read_termination,
 3217|  4.75k|                                        &ctx);
 3218|  4.75k|    if (rc == SSH_ERROR || rc == SSH_AGAIN) {
  ------------------
  |  |  317|  9.50k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
                  if (rc == SSH_ERROR || rc == SSH_AGAIN) {
  ------------------
  |  |  318|  4.75k|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (3218:9): [True: 0, False: 4.75k]
  |  Branch (3218:28): [True: 0, False: 4.75k]
  ------------------
 3219|      0|        return rc;
 3220|      0|    }
 3221|       |
 3222|       |    /*
 3223|       |     * If the channel is closed or in an error state, reading from it is an
 3224|       |     * error
 3225|       |     */
 3226|  4.75k|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (3226:9): [True: 656, False: 4.09k]
  ------------------
 3227|    656|        return SSH_ERROR;
  ------------------
  |  |  317|    656|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3228|    656|    }
 3229|       |    /* If the server closed the channel properly, there is nothing to do */
 3230|  4.09k|    if (channel->remote_eof && ssh_buffer_get_len(stdbuf) == 0) {
  ------------------
  |  Branch (3230:9): [True: 4.09k, False: 0]
  |  Branch (3230:32): [True: 1, False: 4.09k]
  ------------------
 3231|      1|        return 0;
 3232|      1|    }
 3233|  4.09k|    if (channel->state == SSH_CHANNEL_STATE_CLOSED) {
  ------------------
  |  Branch (3233:9): [True: 0, False: 4.09k]
  ------------------
 3234|      0|        ssh_set_error(session, SSH_FATAL, "Remote channel is closed.");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3235|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3236|      0|    }
 3237|  4.09k|    len = ssh_buffer_get_len(stdbuf);
 3238|       |    /* Read count bytes if len is greater, everything otherwise */
 3239|  4.09k|    len = (len > count ? count : len);
  ------------------
  |  Branch (3239:12): [True: 4.09k, False: 1]
  ------------------
 3240|  4.09k|    memcpy(dest, ssh_buffer_get(stdbuf), len);
 3241|  4.09k|    ssh_buffer_pass_bytes(stdbuf, len);
 3242|  4.09k|    if (channel->counter != NULL) {
  ------------------
  |  Branch (3242:9): [True: 0, False: 4.09k]
  ------------------
 3243|      0|        channel->counter->in_bytes += len;
 3244|      0|    }
 3245|       |    /* Try completing the delayed_close */
 3246|  4.09k|    if (channel->delayed_close && !ssh_channel_has_unread_data(channel)) {
  ------------------
  |  Branch (3246:9): [True: 4.09k, False: 0]
  |  Branch (3246:35): [True: 1, False: 4.09k]
  ------------------
 3247|      1|        channel->state = SSH_CHANNEL_STATE_CLOSED;
 3248|      1|    }
 3249|       |
 3250|  4.09k|    rc = grow_window(session, channel);
 3251|  4.09k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  4.09k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (3251:9): [True: 0, False: 4.09k]
  ------------------
 3252|      0|        return -1;
 3253|      0|    }
 3254|       |
 3255|  4.09k|    return len;
 3256|  4.09k|}
channels.c:channel_from_msg:
  518|  2.62k|{
  519|  2.62k|    ssh_channel channel = NULL;
  520|  2.62k|    uint32_t chan;
  521|  2.62k|    int rc;
  522|       |
  523|  2.62k|    rc = ssh_buffer_unpack(packet, "d", &chan);
  ------------------
  |  |   60|  2.62k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  2.62k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  2.62k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  2.62k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  2.62k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  2.62k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  2.62k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  524|  2.62k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  2.62k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (524:9): [True: 0, False: 2.62k]
  ------------------
  525|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  526|      0|                      SSH_FATAL,
  527|      0|                      "Getting channel from message: short read");
  528|      0|        return NULL;
  529|      0|    }
  530|       |
  531|  2.62k|    channel = ssh_channel_from_local(session, chan);
  532|  2.62k|    if (channel == NULL) {
  ------------------
  |  Branch (532:9): [True: 0, False: 2.62k]
  ------------------
  533|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  534|      0|                      SSH_FATAL,
  535|      0|                      "Server specified invalid channel %" PRIu32,
  536|      0|                      (uint32_t)chan);
  537|      0|    }
  538|       |
  539|  2.62k|    return channel;
  540|  2.62k|}
channels.c:grow_window:
  447|  4.09k|{
  448|  4.09k|  uint32_t used;
  449|  4.09k|  uint32_t increment;
  450|  4.09k|  int rc;
  451|       |
  452|       |  /* Calculate the increment taking into account what the peer may still send
  453|       |   * (local_window) and what we've already buffered (stdout_buffer and
  454|       |   * stderr_buffer).
  455|       |  */
  456|  4.09k|  used = channel->local_window;
  457|  4.09k|  if (channel->stdout_buffer != NULL) {
  ------------------
  |  Branch (457:7): [True: 4.09k, False: 0]
  ------------------
  458|  4.09k|    used += ssh_buffer_get_len(channel->stdout_buffer);
  459|  4.09k|  }
  460|  4.09k|  if (channel->stderr_buffer != NULL) {
  ------------------
  |  Branch (460:7): [True: 4.09k, False: 0]
  ------------------
  461|  4.09k|    used += ssh_buffer_get_len(channel->stderr_buffer);
  462|  4.09k|  }
  463|       |  /* Avoid a negative increment in case the peer sent more than the window allowed */
  464|  4.09k|  increment = WINDOW_DEFAULT > used ? WINDOW_DEFAULT - used : 0;
  ------------------
  |  |   67|  4.09k|#define WINDOW_DEFAULT (64*CHANNEL_MAX_PACKET)
  |  |  ------------------
  |  |  |  |   60|  4.09k|#define CHANNEL_MAX_PACKET 32768
  |  |  ------------------
  ------------------
                increment = WINDOW_DEFAULT > used ? WINDOW_DEFAULT - used : 0;
  ------------------
  |  |   67|  4.09k|#define WINDOW_DEFAULT (64*CHANNEL_MAX_PACKET)
  |  |  ------------------
  |  |  |  |   60|  4.09k|#define CHANNEL_MAX_PACKET 32768
  |  |  ------------------
  ------------------
  |  Branch (464:15): [True: 4.09k, False: 0]
  ------------------
  465|       |  /* Don't grow until we can request at least half a window */
  466|  4.09k|  if (increment < (WINDOW_DEFAULT / 2)) {
  ------------------
  |  |   67|  4.09k|#define WINDOW_DEFAULT (64*CHANNEL_MAX_PACKET)
  |  |  ------------------
  |  |  |  |   60|  4.09k|#define CHANNEL_MAX_PACKET 32768
  |  |  ------------------
  ------------------
  |  Branch (466:7): [True: 4.09k, False: 0]
  ------------------
  467|  4.09k|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|  4.09k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  468|  4.09k|        "growing window (channel %" PRIu32 ":%" PRIu32 ") to %" PRIu32 " bytes : not needed (%" PRIu32 " bytes)",
  469|  4.09k|        channel->local_channel, channel->remote_channel, WINDOW_DEFAULT,
  470|  4.09k|        channel->local_window);
  471|       |
  472|  4.09k|    return SSH_OK;
  ------------------
  |  |  316|  4.09k|#define SSH_OK 0     /* No error */
  ------------------
  473|  4.09k|  }
  474|       |
  475|      0|  rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  476|      0|                       "bdd",
  477|      0|                       SSH2_MSG_CHANNEL_WINDOW_ADJUST,
  478|      0|                       channel->remote_channel,
  479|      0|                       increment);
  480|      0|  if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (480:7): [True: 0, False: 0]
  ------------------
  481|      0|    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  482|      0|    goto error;
  483|      0|  }
  484|       |
  485|      0|  if (ssh_packet_send(session) == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (485:7): [True: 0, False: 0]
  ------------------
  486|      0|    goto error;
  487|      0|  }
  488|       |
  489|      0|  SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  490|      0|      "growing window (channel %" PRIu32 ":%" PRIu32 ") by %" PRIu32 " bytes",
  491|      0|      channel->local_channel,
  492|      0|      channel->remote_channel,
  493|      0|      increment);
  494|       |
  495|      0|  channel->local_window += increment;
  496|       |
  497|      0|  return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  498|      0|error:
  499|      0|  ssh_buffer_reinit(session->out_buffer);
  500|       |
  501|      0|  return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  502|      0|}
channels.c:ssh_channel_has_unread_data:
  758|  6.72k|{
  759|  6.72k|    if (channel == NULL) {
  ------------------
  |  Branch (759:9): [True: 0, False: 6.72k]
  ------------------
  760|      0|        return false;
  761|      0|    }
  762|       |
  763|  6.72k|    if ((channel->stdout_buffer &&
  ------------------
  |  Branch (763:10): [True: 6.72k, False: 0]
  ------------------
  764|  6.72k|         ssh_buffer_get_len(channel->stdout_buffer) > 0) ||
  ------------------
  |  Branch (764:10): [True: 5.40k, False: 1.31k]
  ------------------
  765|  1.31k|        (channel->stderr_buffer &&
  ------------------
  |  Branch (765:10): [True: 1.31k, False: 0]
  ------------------
  766|  1.31k|         ssh_buffer_get_len(channel->stderr_buffer) > 0))
  ------------------
  |  Branch (766:10): [True: 0, False: 1.31k]
  ------------------
  767|  5.40k|    {
  768|  5.40k|        return true;
  769|  5.40k|    }
  770|       |
  771|  1.31k|    return false;
  772|  6.72k|}
channels.c:channel_open:
  339|    658|{
  340|    658|    ssh_session session = channel->session;
  341|    658|    int err = SSH_ERROR;
  ------------------
  |  |  317|    658|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  342|    658|    int rc;
  343|       |
  344|    658|    switch (channel->state) {
  345|    658|    case SSH_CHANNEL_STATE_NOT_OPEN:
  ------------------
  |  Branch (345:5): [True: 658, False: 0]
  ------------------
  346|    658|        break;
  347|      0|    case SSH_CHANNEL_STATE_OPENING:
  ------------------
  |  Branch (347:5): [True: 0, False: 658]
  ------------------
  348|      0|        goto pending;
  349|      0|    case SSH_CHANNEL_STATE_OPEN:
  ------------------
  |  Branch (349:5): [True: 0, False: 658]
  ------------------
  350|      0|    case SSH_CHANNEL_STATE_CLOSED:
  ------------------
  |  Branch (350:5): [True: 0, False: 658]
  ------------------
  351|      0|    case SSH_CHANNEL_STATE_OPEN_DENIED:
  ------------------
  |  Branch (351:5): [True: 0, False: 658]
  ------------------
  352|      0|        goto end;
  353|      0|    default:
  ------------------
  |  Branch (353:5): [True: 0, False: 658]
  ------------------
  354|      0|        ssh_set_error(session, SSH_FATAL, "Bad state in channel_open: %d",
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  355|    658|                      channel->state);
  356|    658|    }
  357|       |
  358|    658|    channel->local_channel = ssh_channel_new_id(session);
  359|    658|    channel->local_maxpacket = maxpacket;
  360|    658|    channel->local_window = window;
  361|       |
  362|    658|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    658|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  363|    658|            "Creating a channel %" PRIu32 " with %" PRIu32 " window and %" PRIu32 " max packet",
  364|    658|            channel->local_channel, window, maxpacket);
  365|       |
  366|    658|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    658|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    658|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    658|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    658|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    658|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    658|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    658|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  367|    658|                         "bsddd",
  368|    658|                         SSH2_MSG_CHANNEL_OPEN,
  369|    658|                         type,
  370|    658|                         channel->local_channel,
  371|    658|                         channel->local_window,
  372|    658|                         channel->local_maxpacket);
  373|    658|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    658|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (373:9): [True: 0, False: 658]
  ------------------
  374|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  375|      0|        return err;
  376|      0|    }
  377|       |
  378|    658|    if (payload != NULL) {
  ------------------
  |  Branch (378:9): [True: 0, False: 658]
  ------------------
  379|      0|        if (ssh_buffer_add_buffer(session->out_buffer, payload) < 0) {
  ------------------
  |  Branch (379:13): [True: 0, False: 0]
  ------------------
  380|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  381|       |
  382|      0|            return err;
  383|      0|        }
  384|      0|    }
  385|    658|    channel->state = SSH_CHANNEL_STATE_OPENING;
  386|    658|    if (ssh_packet_send(session) == SSH_ERROR) {
  ------------------
  |  |  317|    658|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (386:9): [True: 0, False: 658]
  ------------------
  387|      0|        return err;
  388|      0|    }
  389|       |
  390|    658|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    658|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  391|    658|            "Sent a SSH_MSG_CHANNEL_OPEN type %s for channel %" PRIu32,
  392|    658|            type, channel->local_channel);
  393|       |
  394|    658|pending:
  395|       |    /* wait until channel is opened by server */
  396|    658|    err = ssh_handle_packets_termination(session,
  397|    658|                                         SSH_TIMEOUT_DEFAULT,
  ------------------
  |  |  103|    658|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
  398|    658|                                         ssh_channel_open_termination,
  399|    658|                                         channel);
  400|       |
  401|    658|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (401:9): [True: 1, False: 657]
  ------------------
  402|      1|        err = SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  403|      1|    }
  404|       |
  405|    658|end:
  406|       |    /* This needs to pass the SSH_AGAIN from the above,
  407|       |     * but needs to catch failed channel states */
  408|    658|    if (channel->state == SSH_CHANNEL_STATE_OPEN) {
  ------------------
  |  Branch (408:9): [True: 657, False: 1]
  ------------------
  409|    657|        err = SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  410|    657|    } else if (err != SSH_AGAIN) {
  ------------------
  |  |  318|      1|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (410:16): [True: 1, False: 0]
  ------------------
  411|       |        /* Messages were handled correctly, but the channel state is invalid */
  412|      1|        err = SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  413|      1|    }
  414|       |
  415|    658|    return err;
  416|    658|}
channels.c:ssh_channel_open_termination:
  304|  1.97k|{
  305|  1.97k|  ssh_channel channel = (ssh_channel) c;
  306|  1.97k|  if (channel->state != SSH_CHANNEL_STATE_OPENING ||
  ------------------
  |  Branch (306:7): [True: 657, False: 1.31k]
  ------------------
  307|  1.31k|      channel->session->session_state == SSH_SESSION_STATE_ERROR)
  ------------------
  |  Branch (307:7): [True: 1, False: 1.31k]
  ------------------
  308|    658|    return 1;
  309|  1.31k|  else
  310|  1.31k|    return 0;
  311|  1.97k|}
channels.c:channel_write_common:
 1558|    658|{
 1559|    658|    ssh_session session = NULL;
 1560|    658|    uint32_t origlen = len;
 1561|    658|    uint32_t effectivelen;
 1562|    658|    int rc;
 1563|       |
 1564|    658|    if (channel == NULL) {
  ------------------
  |  Branch (1564:9): [True: 0, False: 658]
  ------------------
 1565|      0|        return -1;
 1566|      0|    }
 1567|    658|    session = channel->session;
 1568|    658|    if (data == NULL) {
  ------------------
  |  Branch (1568:9): [True: 0, False: 658]
  ------------------
 1569|      0|        ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1570|      0|        return -1;
 1571|      0|    }
 1572|       |
 1573|    658|    if (len > INT_MAX) {
  ------------------
  |  Branch (1573:9): [True: 0, False: 658]
  ------------------
 1574|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1575|      0|                "Length (%" PRIu32 ") is bigger than INT_MAX",
 1576|      0|                len);
 1577|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1578|      0|    }
 1579|       |
 1580|    658|    if (channel->local_eof) {
  ------------------
  |  Branch (1580:9): [True: 0, False: 658]
  ------------------
 1581|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1582|      0|                      SSH_REQUEST_DENIED,
 1583|      0|                      "Can't write to channel %" PRIu32 ":%" PRIu32
 1584|      0|                      " after EOF was sent",
 1585|      0|                      channel->local_channel,
 1586|      0|                      channel->remote_channel);
 1587|      0|        return -1;
 1588|      0|    }
 1589|       |
 1590|    658|    if (channel->state != SSH_CHANNEL_STATE_OPEN ||
  ------------------
  |  Branch (1590:9): [True: 0, False: 658]
  ------------------
 1591|    658|        channel->delayed_close != 0) {
  ------------------
  |  Branch (1591:9): [True: 1, False: 657]
  ------------------
 1592|      1|        ssh_set_error(session, SSH_REQUEST_DENIED, "Remote channel is closed");
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1593|       |
 1594|      1|        return -1;
 1595|      1|    }
 1596|       |
 1597|    657|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (1597:9): [True: 0, False: 657]
  ------------------
 1598|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1599|      0|    }
 1600|       |
 1601|    657|    if (ssh_waitsession_unblocked(session) == 0) {
  ------------------
  |  Branch (1601:9): [True: 0, False: 657]
  ------------------
 1602|      0|        rc = ssh_handle_packets_termination(session,
 1603|      0|                                            SSH_TIMEOUT_DEFAULT,
  ------------------
  |  |  103|      0|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
 1604|      0|                                            ssh_waitsession_unblocked,
 1605|      0|                                            session);
 1606|      0|        if (rc == SSH_ERROR || !ssh_waitsession_unblocked(session))
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1606:13): [True: 0, False: 0]
  |  Branch (1606:32): [True: 0, False: 0]
  ------------------
 1607|      0|            goto out;
 1608|      0|    }
 1609|  1.31k|    while (len > 0) {
  ------------------
  |  Branch (1609:12): [True: 657, False: 657]
  ------------------
 1610|    657|        if (channel->remote_window < len) {
  ------------------
  |  Branch (1610:13): [True: 0, False: 657]
  ------------------
 1611|      0|            SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1612|      0|                    "Remote window is %" PRIu32
 1613|      0|                    " bytes. going to write %" PRIu32 " bytes",
 1614|      0|                    channel->remote_window,
 1615|      0|                    len);
 1616|       |            /* When the window is zero, wait for it to grow */
 1617|      0|            if (channel->remote_window == 0) {
  ------------------
  |  Branch (1617:17): [True: 0, False: 0]
  ------------------
 1618|       |                /* nothing can be written */
 1619|      0|                SSH_LOG(SSH_LOG_DEBUG, "Wait for a growing window message...");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1620|      0|                rc = ssh_handle_packets_termination(
 1621|      0|                    session,
 1622|      0|                    SSH_TIMEOUT_DEFAULT,
  ------------------
  |  |  103|      0|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
 1623|      0|                    ssh_channel_waitwindow_termination,
 1624|      0|                    channel);
 1625|      0|                if (rc == SSH_ERROR ||
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1625:21): [True: 0, False: 0]
  ------------------
 1626|      0|                    !ssh_channel_waitwindow_termination(channel) ||
  ------------------
  |  Branch (1626:21): [True: 0, False: 0]
  ------------------
 1627|      0|                    session->session_state == SSH_SESSION_STATE_ERROR ||
  ------------------
  |  Branch (1627:21): [True: 0, False: 0]
  ------------------
 1628|      0|                    channel->state == SSH_CHANNEL_STATE_CLOSED)
  ------------------
  |  Branch (1628:21): [True: 0, False: 0]
  ------------------
 1629|      0|                    goto out;
 1630|      0|                continue;
 1631|      0|            }
 1632|       |            /* When the window is non-zero, accept data up to the window size */
 1633|      0|            effectivelen = MIN(len, channel->remote_window);
  ------------------
  |  |  365|      0|#define MIN(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (365:19): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1634|    657|        } else {
 1635|    657|            effectivelen = len;
 1636|    657|        }
 1637|       |
 1638|       |        /*
 1639|       |         * Like OpenSSH, don't subtract bytes for the header fields
 1640|       |         * and allow to send a payload of remote_maxpacket length.
 1641|       |         */
 1642|    657|        effectivelen = MIN(effectivelen, channel->remote_maxpacket);
  ------------------
  |  |  365|    657|#define MIN(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (365:19): [True: 657, False: 0]
  |  |  ------------------
  ------------------
 1643|       |
 1644|    657|        rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|  1.31k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  |  |  |  Branch (50:68): [True: 0, False: 657]
  |  |  ------------------
  ------------------
 1645|    657|                             "bd",
 1646|    657|                             is_stderr ? SSH2_MSG_CHANNEL_EXTENDED_DATA
 1647|    657|                                       : SSH2_MSG_CHANNEL_DATA,
 1648|    657|                             channel->remote_channel);
 1649|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1649:13): [True: 0, False: 657]
  ------------------
 1650|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1651|      0|            goto error;
 1652|      0|        }
 1653|       |
 1654|       |        /* stderr message has an extra field */
 1655|    657|        if (is_stderr) {
  ------------------
  |  Branch (1655:13): [True: 0, False: 657]
  ------------------
 1656|      0|            rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1657|      0|                                 "d",
 1658|      0|                                 SSH2_EXTENDED_DATA_STDERR);
 1659|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1659:17): [True: 0, False: 0]
  ------------------
 1660|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1661|      0|                goto error;
 1662|      0|            }
 1663|      0|        }
 1664|       |
 1665|       |        /* append payload data */
 1666|    657|        rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    657|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1667|    657|                             "dP",
 1668|    657|                             effectivelen,
 1669|    657|                             (size_t)effectivelen,
 1670|    657|                             data);
 1671|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1671:13): [True: 0, False: 657]
  ------------------
 1672|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1673|      0|            goto error;
 1674|      0|        }
 1675|       |
 1676|    657|        rc = ssh_packet_send(session);
 1677|    657|        if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1677:13): [True: 0, False: 657]
  ------------------
 1678|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1679|      0|        }
 1680|       |
 1681|    657|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1682|    657|                "ssh_channel_write wrote %" PRIu32 " bytes",
 1683|    657|                effectivelen);
 1684|       |
 1685|    657|        channel->remote_window -= effectivelen;
 1686|    657|        len -= effectivelen;
 1687|    657|        data = ((uint8_t *)data + effectivelen);
 1688|    657|        if (channel->counter != NULL) {
  ------------------
  |  Branch (1688:13): [True: 0, False: 657]
  ------------------
 1689|      0|            channel->counter->out_bytes += effectivelen;
 1690|      0|        }
 1691|    657|    }
 1692|       |
 1693|       |    /* it's a good idea to flush the socket now */
 1694|    657|    rc = ssh_channel_flush(channel);
 1695|    657|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1695:9): [True: 0, False: 657]
  ------------------
 1696|      0|        goto error;
 1697|      0|    }
 1698|       |
 1699|    657|out:
 1700|    657|    return (int)(origlen - len);
 1701|       |
 1702|      0|error:
 1703|      0|    ssh_buffer_reinit(session->out_buffer);
 1704|       |
 1705|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1706|    657|}
channels.c:ssh_waitsession_unblocked:
 1530|    657|{
 1531|    657|    ssh_session session = (ssh_session)s;
 1532|    657|    switch (session->session_state){
 1533|      0|        case SSH_SESSION_STATE_DH:
  ------------------
  |  Branch (1533:9): [True: 0, False: 657]
  ------------------
 1534|      0|        case SSH_SESSION_STATE_INITIAL_KEX:
  ------------------
  |  Branch (1534:9): [True: 0, False: 657]
  ------------------
 1535|      0|        case SSH_SESSION_STATE_KEXINIT_RECEIVED:
  ------------------
  |  Branch (1535:9): [True: 0, False: 657]
  ------------------
 1536|      0|            return 0;
 1537|    657|        default:
  ------------------
  |  Branch (1537:9): [True: 657, False: 0]
  ------------------
 1538|    657|            return 1;
 1539|    657|    }
 1540|    657|}
channels.c:channel_request:
 1909|    657|{
 1910|    657|  ssh_session session = channel->session;
 1911|    657|  int rc = SSH_ERROR;
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1912|    657|  int ret;
 1913|       |
 1914|    657|  switch(channel->request_state){
 1915|    657|  case SSH_CHANNEL_REQ_STATE_NONE:
  ------------------
  |  Branch (1915:3): [True: 657, False: 0]
  ------------------
 1916|    657|    break;
 1917|      0|  default:
  ------------------
  |  Branch (1917:3): [True: 0, False: 657]
  ------------------
 1918|      0|    goto pending;
 1919|    657|  }
 1920|       |
 1921|    657|  ret = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|  1.31k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  |  |  |  Branch (50:68): [True: 0, False: 657]
  |  |  ------------------
  ------------------
 1922|    657|                        "bdsb",
 1923|    657|                        SSH2_MSG_CHANNEL_REQUEST,
 1924|    657|                        channel->remote_channel,
 1925|    657|                        request,
 1926|    657|                        reply == 0 ? 0 : 1);
 1927|    657|  if (ret != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1927:7): [True: 0, False: 657]
  ------------------
 1928|      0|    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1929|      0|    goto error;
 1930|      0|  }
 1931|       |
 1932|    657|  if (buffer != NULL) {
  ------------------
  |  Branch (1932:7): [True: 657, False: 0]
  ------------------
 1933|    657|    if (ssh_buffer_add_data(session->out_buffer, ssh_buffer_get(buffer),
  ------------------
  |  Branch (1933:9): [True: 0, False: 657]
  ------------------
 1934|    657|        ssh_buffer_get_len(buffer)) < 0) {
 1935|      0|      ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1936|      0|      goto error;
 1937|      0|    }
 1938|    657|  }
 1939|    657|  channel->request_state = SSH_CHANNEL_REQ_STATE_PENDING;
 1940|    657|  if (ssh_packet_send(session) == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1940:7): [True: 0, False: 657]
  ------------------
 1941|      0|    return rc;
 1942|      0|  }
 1943|       |
 1944|    657|  SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1945|    657|          "Sent a SSH_MSG_CHANNEL_REQUEST %s on channel %" PRIu32 ":%" PRIu32,
 1946|    657|          request,
 1947|    657|          channel->local_channel,
 1948|    657|          channel->remote_channel);
 1949|    657|  if (reply == 0) {
  ------------------
  |  Branch (1949:7): [True: 0, False: 657]
  ------------------
 1950|      0|    channel->request_state = SSH_CHANNEL_REQ_STATE_NONE;
 1951|      0|    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1952|      0|  }
 1953|    657|pending:
 1954|    657|  rc = ssh_handle_packets_termination(session,
 1955|    657|                                      SSH_TIMEOUT_DEFAULT,
  ------------------
  |  |  103|    657|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
 1956|    657|                                      ssh_channel_request_termination,
 1957|    657|                                      channel);
 1958|       |
 1959|    657|  if(session->session_state == SSH_SESSION_STATE_ERROR || rc == SSH_ERROR) {
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1959:6): [True: 656, False: 1]
  |  Branch (1959:59): [True: 0, False: 1]
  ------------------
 1960|    656|      channel->request_state = SSH_CHANNEL_REQ_STATE_ERROR;
 1961|    656|  }
 1962|       |  /* we received something */
 1963|    657|  switch (channel->request_state){
  ------------------
  |  Branch (1963:11): [True: 657, False: 0]
  ------------------
 1964|    656|    case SSH_CHANNEL_REQ_STATE_ERROR:
  ------------------
  |  Branch (1964:5): [True: 656, False: 1]
  ------------------
 1965|    656|      rc=SSH_ERROR;
  ------------------
  |  |  317|    656|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1966|    656|      break;
 1967|      0|    case SSH_CHANNEL_REQ_STATE_DENIED:
  ------------------
  |  Branch (1967:5): [True: 0, False: 657]
  ------------------
 1968|      0|      ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1969|      0|                    SSH_REQUEST_DENIED,
 1970|      0|                    "Channel request %s failed on channel %" PRIu32 ":%" PRIu32,
 1971|      0|                    request,
 1972|      0|                    channel->local_channel,
 1973|      0|                    channel->remote_channel);
 1974|      0|      rc=SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1975|      0|      break;
 1976|      1|    case SSH_CHANNEL_REQ_STATE_ACCEPTED:
  ------------------
  |  Branch (1976:5): [True: 1, False: 656]
  ------------------
 1977|      1|      SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1978|      1|              "Channel request %s success on channel %" PRIu32 ":%" PRIu32,
 1979|      1|              request,
 1980|      1|              channel->local_channel,
 1981|      1|              channel->remote_channel);
 1982|      1|      rc=SSH_OK;
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
 1983|      1|      break;
 1984|      0|    case SSH_CHANNEL_REQ_STATE_PENDING:
  ------------------
  |  Branch (1984:5): [True: 0, False: 657]
  ------------------
 1985|      0|      rc = SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
 1986|      0|      return rc;
 1987|      0|    case SSH_CHANNEL_REQ_STATE_NONE:
  ------------------
  |  Branch (1987:5): [True: 0, False: 657]
  ------------------
 1988|       |      /* Never reached */
 1989|      0|      ssh_set_error(session, SSH_FATAL, "Invalid state in channel_request()");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1990|      0|      rc=SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1991|      0|      break;
 1992|    657|  }
 1993|    657|  channel->request_state=SSH_CHANNEL_REQ_STATE_NONE;
 1994|       |
 1995|    657|  return rc;
 1996|      0|error:
 1997|      0|  ssh_buffer_reinit(session->out_buffer);
 1998|       |
 1999|      0|  return rc;
 2000|    657|}
channels.c:ssh_channel_request_termination:
 1898|  3.26k|{
 1899|  3.26k|  ssh_channel channel = (ssh_channel)c;
 1900|  3.26k|  if(channel->request_state != SSH_CHANNEL_REQ_STATE_PENDING ||
  ------------------
  |  Branch (1900:6): [True: 1, False: 3.25k]
  ------------------
 1901|  3.25k|      channel->session->session_state == SSH_SESSION_STATE_ERROR)
  ------------------
  |  Branch (1901:7): [True: 0, False: 3.25k]
  ------------------
 1902|      1|    return 1;
 1903|  3.25k|  else
 1904|  3.25k|    return 0;
 1905|  3.26k|}
channels.c:ssh_channel_read_termination:
 3111|  4.75k|{
 3112|  4.75k|  struct ssh_channel_read_termination_struct *ctx = s;
 3113|  4.75k|  if (ssh_buffer_get_len(ctx->buffer) >= 1 ||
  ------------------
  |  Branch (3113:7): [True: 4.75k, False: 1]
  ------------------
 3114|      1|      ctx->channel->remote_eof ||
  ------------------
  |  Branch (3114:7): [True: 1, False: 0]
  ------------------
 3115|      0|      ctx->channel->session->session_state == SSH_SESSION_STATE_ERROR)
  ------------------
  |  Branch (3115:7): [True: 0, False: 0]
  ------------------
 3116|  4.75k|    return 1;
 3117|      0|  else
 3118|      0|    return 0;
 3119|  4.75k|}

ssh_send_banner:
  187|  1.31k|{
  188|  1.31k|    const char *banner = CLIENT_BANNER_SSH2;
  ------------------
  |  |  223|  1.31k|#define CLIENT_BANNER_SSH2 "SSH-2.0-libssh_" SSH_STRINGIFY(LIBSSH_VERSION)
  |  |  ------------------
  |  |  |  |   71|  1.31k|#define SSH_STRINGIFY(s) SSH_TOSTRING(s)
  |  |  |  |  ------------------
  |  |  |  |  |  |   72|  1.31k|#define SSH_TOSTRING(s) #s
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|  1.31k|    const char *terminator = "\r\n";
  190|       |    /* The maximum banner length is 255 for SSH2 */
  191|  1.31k|    char buffer[256] = {0};
  192|  1.31k|    size_t len;
  193|  1.31k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  194|       |
  195|  1.31k|    if (server == 1) {
  ------------------
  |  Branch (195:9): [True: 657, False: 657]
  ------------------
  196|    657|        if (session->server_opts.custombanner == NULL) {
  ------------------
  |  Branch (196:13): [True: 657, False: 0]
  ------------------
  197|    657|            session->serverbanner = strdup(banner);
  198|    657|            if (session->serverbanner == NULL) {
  ------------------
  |  Branch (198:17): [True: 0, False: 657]
  ------------------
  199|      0|                goto end;
  200|      0|            }
  201|    657|        } else {
  202|      0|            len = strlen(session->server_opts.custombanner);
  203|      0|            session->serverbanner = malloc(len + 8 + 1);
  204|      0|            if(session->serverbanner == NULL) {
  ------------------
  |  Branch (204:16): [True: 0, False: 0]
  ------------------
  205|      0|                goto end;
  206|      0|            }
  207|      0|            snprintf(session->serverbanner,
  208|      0|                     len + 8 + 1,
  209|      0|                     "SSH-2.0-%s",
  210|      0|                     session->server_opts.custombanner);
  211|      0|        }
  212|       |
  213|    657|        snprintf(buffer,
  214|    657|                 sizeof(buffer),
  215|    657|                 "%s%s",
  216|    657|                 session->serverbanner,
  217|    657|                 terminator);
  218|    657|    } else {
  219|    657|        session->clientbanner = strdup(banner);
  220|    657|        if (session->clientbanner == NULL) {
  ------------------
  |  Branch (220:13): [True: 0, False: 657]
  ------------------
  221|      0|            goto end;
  222|      0|        }
  223|       |
  224|    657|        snprintf(buffer,
  225|    657|                 sizeof(buffer),
  226|    657|                 "%s%s",
  227|    657|                 session->clientbanner,
  228|    657|                 terminator);
  229|    657|    }
  230|       |
  231|  1.31k|    rc = ssh_socket_write(session->socket, buffer, (uint32_t)strlen(buffer));
  232|  1.31k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (232:9): [True: 0, False: 1.31k]
  ------------------
  233|      0|        goto end;
  234|      0|    }
  235|  1.31k|#ifdef WITH_PCAP
  236|  1.31k|    if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (236:9): [True: 0, False: 1.31k]
  ------------------
  237|      0|        ssh_pcap_context_write(session->pcap_ctx,
  238|      0|                               SSH_PCAP_DIR_OUT,
  239|      0|                               buffer,
  240|      0|                               (uint32_t)strlen(buffer),
  241|      0|                               (uint32_t)strlen(buffer));
  242|      0|    }
  243|  1.31k|#endif
  244|       |
  245|  1.31k|    rc = SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  246|  1.31k|end:
  247|  1.31k|    return rc;
  248|  1.31k|}
dh_handshake:
  258|    657|{
  259|    657|    int rc = SSH_AGAIN;
  ------------------
  |  |  318|    657|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  260|       |
  261|    657|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  262|    657|            "dh_handshake_state = %d, kex_type = %d",
  263|    657|            session->dh_handshake_state,
  264|    657|            session->next_crypto->kex_type);
  265|       |
  266|    657|    switch (session->dh_handshake_state) {
  267|    657|    case DH_STATE_INIT:
  ------------------
  |  Branch (267:5): [True: 657, False: 0]
  ------------------
  268|    657|        switch (session->next_crypto->kex_type) {
  269|       |#ifdef WITH_GSSAPI
  270|       |        case SSH_GSS_KEX_DH_GROUP14_SHA256:
  271|       |        case SSH_GSS_KEX_DH_GROUP16_SHA512:
  272|       |        case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  273|       |        case SSH_GSS_KEX_CURVE25519_SHA256:
  274|       |            rc = ssh_client_gss_kex_init(session);
  275|       |            break;
  276|       |#endif
  277|      0|        case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (277:9): [True: 0, False: 657]
  ------------------
  278|      0|        case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (278:9): [True: 0, False: 657]
  ------------------
  279|      0|        case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (279:9): [True: 0, False: 657]
  ------------------
  280|      0|        case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (280:9): [True: 0, False: 657]
  ------------------
  281|      0|        case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (281:9): [True: 0, False: 657]
  ------------------
  282|      0|            rc = ssh_client_dh_init(session);
  283|      0|            break;
  284|      0|#ifdef WITH_GEX
  285|      0|        case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (285:9): [True: 0, False: 657]
  ------------------
  286|      0|        case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (286:9): [True: 0, False: 657]
  ------------------
  287|      0|            rc = ssh_client_dhgex_init(session);
  288|      0|            break;
  289|      0|#endif /* WITH_GEX */
  290|      0|#ifdef HAVE_ECDH
  291|      0|        case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (291:9): [True: 0, False: 657]
  ------------------
  292|      0|        case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (292:9): [True: 0, False: 657]
  ------------------
  293|      0|        case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (293:9): [True: 0, False: 657]
  ------------------
  294|      0|            rc = ssh_client_ecdh_init(session);
  295|      0|            break;
  296|      0|#endif
  297|      0|#ifdef HAVE_CURVE25519
  298|      0|        case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (298:9): [True: 0, False: 657]
  ------------------
  299|      0|        case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (299:9): [True: 0, False: 657]
  ------------------
  300|      0|            rc = ssh_client_curve25519_init(session);
  301|      0|            break;
  302|      0|#endif
  303|      0|#ifdef HAVE_SNTRUP761
  304|      0|        case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (304:9): [True: 0, False: 657]
  ------------------
  305|      0|        case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (305:9): [True: 0, False: 657]
  ------------------
  306|      0|            rc = ssh_client_sntrup761x25519_init(session);
  307|      0|            break;
  308|      0|#endif
  309|    657|        case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (309:9): [True: 657, False: 0]
  ------------------
  310|    657|        case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (310:9): [True: 0, False: 657]
  ------------------
  311|       |#ifdef HAVE_MLKEM1024
  312|       |        case SSH_KEX_MLKEM1024NISTP384_SHA384:
  313|       |#endif
  314|    657|            rc = ssh_client_hybrid_mlkem_init(session);
  315|    657|            break;
  316|      0|        default:
  ------------------
  |  Branch (316:9): [True: 0, False: 657]
  ------------------
  317|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  318|    657|        }
  319|       |
  320|    657|        break;
  321|    657|    case DH_STATE_INIT_SENT:
  ------------------
  |  Branch (321:5): [True: 0, False: 657]
  ------------------
  322|       |    	/* wait until ssh_packet_dh_reply is called */
  323|      0|    	break;
  324|      0|    case DH_STATE_NEWKEYS_SENT:
  ------------------
  |  Branch (324:5): [True: 0, False: 657]
  ------------------
  325|       |    	/* wait until ssh_packet_newkeys is called */
  326|      0|    	break;
  327|      0|    case DH_STATE_FINISHED:
  ------------------
  |  Branch (327:5): [True: 0, False: 657]
  ------------------
  328|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  329|      0|    default:
  ------------------
  |  Branch (329:5): [True: 0, False: 657]
  ------------------
  330|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  331|      0|                      SSH_FATAL,
  332|      0|                      "Invalid state in dh_handshake(): %d",
  333|      0|                      session->dh_handshake_state);
  334|       |
  335|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  336|    657|    }
  337|       |
  338|    657|    return rc;
  339|    657|}
ssh_service_request:
  373|    657|{
  374|    657|  int rc = SSH_ERROR;
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  375|       |
  376|    657|  if(session->auth.service_state != SSH_AUTH_SERVICE_NONE)
  ------------------
  |  Branch (376:6): [True: 0, False: 657]
  ------------------
  377|      0|    goto pending;
  378|       |
  379|    657|  rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    657|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  380|    657|                       "bs",
  381|    657|                       SSH2_MSG_SERVICE_REQUEST,
  382|    657|                       service);
  383|    657|  if (rc != SSH_OK){
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (383:7): [True: 0, False: 657]
  ------------------
  384|      0|      ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  385|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  386|      0|  }
  387|    657|  session->auth.service_state = SSH_AUTH_SERVICE_SENT;
  388|    657|  if (ssh_packet_send(session) == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (388:7): [True: 0, False: 657]
  ------------------
  389|      0|    ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  390|      0|        "Sending SSH2_MSG_SERVICE_REQUEST failed.");
  391|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  392|      0|  }
  393|       |
  394|    657|  SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  395|    657|      "Sent SSH_MSG_SERVICE_REQUEST (service %s)", service);
  396|    657|pending:
  397|    657|  rc=ssh_handle_packets_termination(session,SSH_TIMEOUT_USER,
  ------------------
  |  |  101|    657|#define SSH_TIMEOUT_USER -2
  ------------------
  398|    657|      ssh_service_request_termination, session);
  399|    657|  if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (399:7): [True: 0, False: 657]
  ------------------
  400|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  401|      0|  }
  402|    657|  switch(session->auth.service_state) {
  ------------------
  |  Branch (402:10): [True: 657, False: 0]
  ------------------
  403|      0|  case SSH_AUTH_SERVICE_DENIED:
  ------------------
  |  Branch (403:3): [True: 0, False: 657]
  ------------------
  404|      0|    ssh_set_error(session,SSH_FATAL,"ssh_auth_service request denied");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  405|      0|    break;
  406|    657|  case SSH_AUTH_SERVICE_ACCEPTED:
  ------------------
  |  Branch (406:3): [True: 657, False: 0]
  ------------------
  407|    657|    rc=SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  408|    657|    break;
  409|      0|  case SSH_AUTH_SERVICE_SENT:
  ------------------
  |  Branch (409:3): [True: 0, False: 657]
  ------------------
  410|      0|    rc=SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  411|      0|    break;
  412|      0|  case SSH_AUTH_SERVICE_NONE:
  ------------------
  |  Branch (412:3): [True: 0, False: 657]
  ------------------
  413|      0|    rc=SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  414|      0|    break;
  415|    657|  }
  416|       |
  417|    657|  return rc;
  418|    657|}
ssh_connect:
  556|    657|{
  557|    657|    int ret;
  558|       |
  559|    657|    if (!is_ssh_initialized()) {
  ------------------
  |  Branch (559:9): [True: 0, False: 657]
  ------------------
  560|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  561|      0|                      "Library not initialized.");
  562|       |
  563|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  564|      0|    }
  565|       |
  566|    657|    if (session == NULL) {
  ------------------
  |  Branch (566:9): [True: 0, False: 657]
  ------------------
  567|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  568|      0|    }
  569|       |
  570|    657|    switch(session->pending_call_state) {
  571|    657|    case SSH_PENDING_CALL_NONE:
  ------------------
  |  Branch (571:5): [True: 657, False: 0]
  ------------------
  572|    657|        break;
  573|      0|    case SSH_PENDING_CALL_CONNECT:
  ------------------
  |  Branch (573:5): [True: 0, False: 657]
  ------------------
  574|      0|        goto pending;
  575|      0|    default:
  ------------------
  |  Branch (575:5): [True: 0, False: 657]
  ------------------
  576|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  577|      0|                      "Bad call during pending SSH call in ssh_connect");
  578|       |
  579|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  580|    657|    }
  581|    657|    session->alive = 0;
  582|    657|    session->client = 1;
  583|       |
  584|    657|    if (session->opts.fd == SSH_INVALID_SOCKET &&
  ------------------
  |  |  124|  1.31k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  |  Branch (584:9): [True: 0, False: 657]
  ------------------
  585|      0|        session->opts.originalhost == NULL &&
  ------------------
  |  Branch (585:9): [True: 0, False: 0]
  ------------------
  586|      0|        session->opts.ProxyCommand == NULL) {
  ------------------
  |  Branch (586:9): [True: 0, False: 0]
  ------------------
  587|      0|        ssh_set_error(session, SSH_FATAL, "Hostname required");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  588|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  589|      0|    }
  590|       |
  591|       |    /* If the system configuration files were not yet processed, do it now */
  592|    657|    if (!session->opts.config_processed) {
  ------------------
  |  Branch (592:9): [True: 0, False: 657]
  ------------------
  593|      0|        ret = ssh_options_parse_config(session, NULL);
  594|      0|        if (ret != 0) {
  ------------------
  |  Branch (594:13): [True: 0, False: 0]
  ------------------
  595|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  596|      0|                          "Failed to process system configuration files");
  597|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  598|      0|        }
  599|      0|    }
  600|       |
  601|    657|    ret = ssh_options_apply(session);
  602|    657|    if (ret < 0) {
  ------------------
  |  Branch (602:9): [True: 0, False: 657]
  ------------------
  603|      0|        ssh_set_error(session, SSH_FATAL, "Couldn't apply options");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  604|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  605|      0|    }
  606|       |
  607|    657|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  608|    657|            "libssh %s, using threading %s",
  609|    657|            ssh_copyright(),
  610|    657|            ssh_threads_get_type());
  611|       |
  612|    657|    session->ssh_connection_callback = ssh_client_connection_callback;
  613|    657|    session->session_state = SSH_SESSION_STATE_CONNECTING;
  614|    657|    ssh_socket_set_callbacks(session->socket, &session->socket_callbacks);
  615|    657|    session->socket_callbacks.connected = socket_callback_connected;
  616|    657|    session->socket_callbacks.data = callback_receive_banner;
  617|    657|    session->socket_callbacks.exception = ssh_socket_exception_callback;
  618|    657|    session->socket_callbacks.userdata = session;
  619|       |
  620|    657|    if (session->opts.fd != SSH_INVALID_SOCKET) {
  ------------------
  |  |  124|    657|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  |  Branch (620:9): [True: 657, False: 0]
  ------------------
  621|    657|        session->session_state = SSH_SESSION_STATE_SOCKET_CONNECTED;
  622|    657|        ret = ssh_socket_set_fd(session->socket, session->opts.fd);
  623|    657|#ifndef _WIN32
  624|    657|#ifdef HAVE_PTHREAD
  625|    657|    } else if (ssh_libssh_proxy_jumps() &&
  ------------------
  |  Branch (625:16): [True: 0, False: 0]
  ------------------
  626|      0|               ssh_list_count(session->opts.proxy_jumps) != 0) {
  ------------------
  |  Branch (626:16): [True: 0, False: 0]
  ------------------
  627|      0|        ret = ssh_socket_connect_proxyjump(session->socket);
  628|      0|#endif /* HAVE_PTHREAD */
  629|      0|#endif /* _WIN32 */
  630|      0|    } else if (session->opts.ProxyCommand != NULL) {
  ------------------
  |  Branch (630:16): [True: 0, False: 0]
  ------------------
  631|       |#ifdef WITH_EXEC
  632|       |        ret = ssh_socket_connect_proxycommand(session->socket,
  633|       |                session->opts.ProxyCommand);
  634|       |#else
  635|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  636|      0|                      SSH_FATAL,
  637|      0|                      "The libssh is built without support for proxy commands.");
  638|      0|        ret = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  639|      0|#endif /* WITH_EXEC */
  640|      0|    } else {
  641|      0|        ret = ssh_socket_connect(session->socket,
  642|      0|                                 session->opts.host,
  643|      0|                                 session->opts.port > 0 ? session->opts.port : 22,
  ------------------
  |  Branch (643:34): [True: 0, False: 0]
  ------------------
  644|      0|                                 session->opts.bindaddr);
  645|      0|    }
  646|    657|    if (ret == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (646:9): [True: 0, False: 657]
  ------------------
  647|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  648|      0|    }
  649|       |
  650|    657|    set_status(session, 0.2f);
  ------------------
  |  |   58|    657|#define set_status(session, status) do {\
  |  |   59|    657|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (59:13): [True: 0, False: 657]
  |  |  |  Branch (59:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   60|    657|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   61|    657|    } while (0)
  |  |  ------------------
  |  |  |  Branch (61:14): [Folded, False: 657]
  |  |  ------------------
  ------------------
  651|       |
  652|    657|    session->alive = 1;
  653|    657|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  654|    657|            "Socket connecting, now waiting for the callbacks to work");
  655|       |
  656|    657|pending:
  657|    657|    session->pending_call_state = SSH_PENDING_CALL_CONNECT;
  658|    657|    if(ssh_is_blocking(session)) {
  ------------------
  |  Branch (658:8): [True: 657, False: 0]
  ------------------
  659|    657|        int timeout = ssh_make_milliseconds(session->opts.timeout,
  660|    657|                                            session->opts.timeout_usec);
  661|    657|        SSH_LOG(SSH_LOG_PACKET, "Actual timeout : %d", timeout);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  662|    657|        ret = ssh_handle_packets_termination(session, timeout,
  663|    657|                                             ssh_connect_termination, session);
  664|    657|        if (session->session_state != SSH_SESSION_STATE_ERROR &&
  ------------------
  |  Branch (664:13): [True: 657, False: 0]
  ------------------
  665|    657|            (ret == SSH_ERROR || !ssh_connect_termination(session)))
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (665:14): [True: 0, False: 657]
  |  Branch (665:34): [True: 0, False: 657]
  ------------------
  666|      0|        {
  667|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  668|      0|                          "Timeout connecting to %s", session->opts.host);
  669|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
  670|      0|        }
  671|    657|    } else {
  672|      0|        ret = ssh_handle_packets_termination(session,
  673|      0|                                             SSH_TIMEOUT_NONBLOCKING,
  ------------------
  |  |  105|      0|#define SSH_TIMEOUT_NONBLOCKING 0
  ------------------
  674|      0|                                             ssh_connect_termination,
  675|      0|                                             session);
  676|      0|        if (ret == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (676:13): [True: 0, False: 0]
  ------------------
  677|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
  678|      0|        }
  679|      0|    }
  680|       |
  681|    657|    SSH_LOG(SSH_LOG_PACKET, "current state : %d", session->session_state);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  682|    657|    if (!ssh_is_blocking(session) && !ssh_connect_termination(session)) {
  ------------------
  |  Branch (682:9): [True: 0, False: 657]
  |  Branch (682:38): [True: 0, False: 0]
  ------------------
  683|      0|        return SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  684|      0|    }
  685|       |
  686|    657|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  687|    657|    if (session->session_state == SSH_SESSION_STATE_ERROR ||
  ------------------
  |  Branch (687:9): [True: 0, False: 657]
  ------------------
  688|    657|        session->session_state == SSH_SESSION_STATE_DISCONNECTED)
  ------------------
  |  Branch (688:9): [True: 0, False: 657]
  ------------------
  689|      0|    {
  690|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  691|      0|    }
  692|       |
  693|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  694|    657|}
ssh_disconnect:
  809|  1.31k|{
  810|  1.31k|    struct ssh_iterator *it = NULL;
  811|  1.31k|    int rc;
  812|       |
  813|  1.31k|    if (session == NULL) {
  ------------------
  |  Branch (813:9): [True: 0, False: 1.31k]
  ------------------
  814|      0|        return;
  815|      0|    }
  816|       |
  817|  1.31k|#ifndef _WIN32
  818|  1.31k|#ifdef HAVE_PTHREAD
  819|       |    /* Only send the disconnect to all other threads when the root session calls
  820|       |     * ssh_disconnect() */
  821|  1.31k|    if (session->proxy_root) {
  ------------------
  |  Branch (821:9): [True: 1.31k, False: 0]
  ------------------
  822|  1.31k|        proxy_disconnect = 1;
  823|  1.31k|    }
  824|  1.31k|#endif /* HAVE_PTHREAD */
  825|  1.31k|#endif /* _WIN32 */
  826|       |
  827|  1.31k|    if (session->disconnect_message == NULL) {
  ------------------
  |  Branch (827:9): [True: 1.31k, False: 0]
  ------------------
  828|  1.31k|        session->disconnect_message = strdup("Bye Bye") ;
  829|  1.31k|        if (session->disconnect_message == NULL) {
  ------------------
  |  Branch (829:13): [True: 0, False: 1.31k]
  ------------------
  830|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  831|      0|            goto error;
  832|      0|        }
  833|  1.31k|    }
  834|       |
  835|  1.31k|    if (session->socket != NULL && ssh_socket_is_open(session->socket)) {
  ------------------
  |  Branch (835:9): [True: 1.31k, False: 0]
  |  Branch (835:36): [True: 657, False: 657]
  ------------------
  836|    657|        rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    657|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  837|    657|                             "bdss",
  838|    657|                             SSH2_MSG_DISCONNECT,
  839|    657|                             SSH2_DISCONNECT_BY_APPLICATION,
  840|    657|                             session->disconnect_message,
  841|    657|                             ""); /* language tag */
  842|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (842:13): [True: 0, False: 657]
  ------------------
  843|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  844|      0|            goto error;
  845|      0|        }
  846|       |
  847|    657|        ssh_packet_send(session);
  848|    657|        ssh_session_socket_close(session);
  849|    657|    }
  850|       |
  851|  1.31k|error:
  852|  1.31k|    session->recv_seq = 0;
  853|  1.31k|    session->send_seq = 0;
  854|  1.31k|    session->alive = 0;
  855|  1.31k|    if (session->socket != NULL){
  ------------------
  |  Branch (855:9): [True: 1.31k, False: 0]
  ------------------
  856|  1.31k|        ssh_socket_reset(session->socket);
  857|  1.31k|    }
  858|  1.31k|    session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|  1.31k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  859|  1.31k|    session->session_state = SSH_SESSION_STATE_DISCONNECTED;
  860|  1.31k|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  861|  1.31k|    session->packet_state = PACKET_STATE_INIT;
  862|       |
  863|  1.97k|    while ((it = ssh_list_get_iterator(session->channels)) != NULL) {
  ------------------
  |  Branch (863:12): [True: 657, False: 1.31k]
  ------------------
  864|    657|        ssh_channel_do_free(ssh_iterator_value(ssh_channel, it));
  ------------------
  |  |  114|    657|  ((type)((iterator)->data))
  ------------------
  865|    657|        ssh_list_remove(session->channels, it);
  866|    657|    }
  867|  1.31k|    if (session->current_crypto) {
  ------------------
  |  Branch (867:9): [True: 1.31k, False: 0]
  ------------------
  868|  1.31k|      crypto_free(session->current_crypto);
  869|  1.31k|      session->current_crypto = NULL;
  870|  1.31k|    }
  871|  1.31k|    if (session->next_crypto) {
  ------------------
  |  Branch (871:9): [True: 1.31k, False: 0]
  ------------------
  872|  1.31k|        crypto_free(session->next_crypto);
  873|  1.31k|        session->next_crypto = crypto_new();
  874|  1.31k|        if (session->next_crypto == NULL) {
  ------------------
  |  Branch (874:13): [True: 0, False: 1.31k]
  ------------------
  875|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  876|      0|        }
  877|  1.31k|    }
  878|  1.31k|    if (session->in_buffer) {
  ------------------
  |  Branch (878:9): [True: 1.31k, False: 0]
  ------------------
  879|  1.31k|        ssh_buffer_reinit(session->in_buffer);
  880|  1.31k|    }
  881|  1.31k|    if (session->out_buffer) {
  ------------------
  |  Branch (881:9): [True: 1.31k, False: 0]
  ------------------
  882|  1.31k|        ssh_buffer_reinit(session->out_buffer);
  883|  1.31k|    }
  884|  1.31k|    if (session->in_hashbuf) {
  ------------------
  |  Branch (884:9): [True: 0, False: 1.31k]
  ------------------
  885|      0|        ssh_buffer_reinit(session->in_hashbuf);
  886|      0|    }
  887|  1.31k|    if (session->out_hashbuf) {
  ------------------
  |  Branch (887:9): [True: 0, False: 1.31k]
  ------------------
  888|      0|        ssh_buffer_reinit(session->out_hashbuf);
  889|      0|    }
  890|  1.31k|    session->auth.supported_methods = 0;
  891|  1.31k|    SAFE_FREE(session->serverbanner);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  892|  1.31k|    SAFE_FREE(session->clientbanner);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  893|  1.31k|    SAFE_FREE(session->disconnect_message);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  894|       |
  895|  1.31k|    if (session->ssh_message_list) {
  ------------------
  |  Branch (895:9): [True: 0, False: 1.31k]
  ------------------
  896|      0|        ssh_message msg = NULL;
  897|       |
  898|      0|        while ((msg = ssh_list_pop_head(ssh_message,
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  |  Branch (898:16): [True: 0, False: 0]
  ------------------
  899|      0|                                        session->ssh_message_list)) != NULL) {
  900|      0|              ssh_message_free(msg);
  901|      0|        }
  902|      0|        ssh_list_free(session->ssh_message_list);
  903|      0|        session->ssh_message_list = NULL;
  904|      0|    }
  905|       |
  906|  1.31k|    if (session->packet_callbacks) {
  ------------------
  |  Branch (906:9): [True: 1.31k, False: 0]
  ------------------
  907|  1.31k|        ssh_list_free(session->packet_callbacks);
  908|       |        session->packet_callbacks = NULL;
  909|  1.31k|    }
  910|  1.31k|}
ssh_copyright:
  920|    657|{
  921|    657|    return SSH_STRINGIFY(LIBSSH_VERSION) " (c) 2003-2026 "
  ------------------
  |  |   71|    657|#define SSH_STRINGIFY(s) SSH_TOSTRING(s)
  |  |  ------------------
  |  |  |  |   72|    657|#define SSH_TOSTRING(s) #s
  |  |  ------------------
  ------------------
  922|    657|           "Aris Adamantiadis, Andreas Schneider "
  923|    657|           "and libssh contributors. "
  924|    657|           "Distributed under the LGPL, please refer to COPYING "
  925|    657|           "file for information about your rights";
  926|    657|}
client.c:ssh_service_request_termination:
  342|  2.62k|{
  343|  2.62k|    ssh_session session = (ssh_session)s;
  344|       |
  345|  2.62k|    if (session->session_state == SSH_SESSION_STATE_ERROR ||
  ------------------
  |  Branch (345:9): [True: 0, False: 2.62k]
  ------------------
  346|  2.62k|        session->auth.service_state != SSH_AUTH_SERVICE_SENT)
  ------------------
  |  Branch (346:9): [True: 657, False: 1.97k]
  ------------------
  347|    657|        return 1;
  348|  1.97k|    else
  349|  1.97k|        return 0;
  350|  2.62k|}
client.c:ssh_client_connection_callback:
  427|  3.94k|{
  428|  3.94k|    int rc;
  429|       |
  430|  3.94k|    SSH_LOG(SSH_LOG_DEBUG, "session_state=%d", session->session_state);
  ------------------
  |  |  281|  3.94k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  431|       |
  432|  3.94k|    switch (session->session_state) {
  433|      0|    case SSH_SESSION_STATE_NONE:
  ------------------
  |  Branch (433:5): [True: 0, False: 3.94k]
  ------------------
  434|      0|    case SSH_SESSION_STATE_CONNECTING:
  ------------------
  |  Branch (434:5): [True: 0, False: 3.94k]
  ------------------
  435|      0|        break;
  436|    657|    case SSH_SESSION_STATE_SOCKET_CONNECTED:
  ------------------
  |  Branch (436:5): [True: 657, False: 3.28k]
  ------------------
  437|    657|        ssh_set_fd_towrite(session);
  438|    657|        ssh_send_banner(session, 0);
  439|       |
  440|    657|        break;
  441|    657|    case SSH_SESSION_STATE_BANNER_RECEIVED:
  ------------------
  |  Branch (441:5): [True: 657, False: 3.28k]
  ------------------
  442|    657|        if (session->serverbanner == NULL) {
  ------------------
  |  Branch (442:13): [True: 0, False: 657]
  ------------------
  443|      0|            goto error;
  444|      0|        }
  445|    657|        set_status(session, 0.4f);
  ------------------
  |  |   58|    657|#define set_status(session, status) do {\
  |  |   59|    657|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (59:13): [True: 0, False: 657]
  |  |  |  Branch (59:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   60|    657|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   61|    657|    } while (0)
  |  |  ------------------
  |  |  |  Branch (61:14): [Folded, False: 657]
  |  |  ------------------
  ------------------
  446|    657|        SSH_LOG(SSH_LOG_DEBUG, "SSH server banner: %s", session->serverbanner);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  447|       |
  448|       |        /* Here we analyze the different protocols the server allows. */
  449|    657|        rc = ssh_analyze_banner(session, 0);
  450|    657|        if (rc < 0) {
  ------------------
  |  Branch (450:13): [True: 0, False: 657]
  ------------------
  451|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  452|      0|                          "No version of SSH protocol usable (banner: %s)",
  453|      0|                          session->serverbanner);
  454|      0|            goto error;
  455|      0|        }
  456|       |
  457|    657|        ssh_packet_register_socket_callback(session, session->socket);
  458|       |
  459|    657|        ssh_packet_set_default_callbacks(session);
  460|    657|        session->session_state = SSH_SESSION_STATE_INITIAL_KEX;
  461|    657|        rc = ssh_set_client_kex(session);
  462|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (462:13): [True: 0, False: 657]
  ------------------
  463|      0|            goto error;
  464|      0|        }
  465|    657|        rc = ssh_send_kex(session);
  466|    657|        if (rc < 0) {
  ------------------
  |  Branch (466:13): [True: 0, False: 657]
  ------------------
  467|      0|            goto error;
  468|      0|        }
  469|    657|        set_status(session, 0.5f);
  ------------------
  |  |   58|    657|#define set_status(session, status) do {\
  |  |   59|    657|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (59:13): [True: 0, False: 657]
  |  |  |  Branch (59:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   60|    657|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   61|    657|    } while (0)
  |  |  ------------------
  |  |  |  Branch (61:14): [Folded, False: 657]
  |  |  ------------------
  ------------------
  470|       |
  471|    657|        break;
  472|      0|    case SSH_SESSION_STATE_INITIAL_KEX:
  ------------------
  |  Branch (472:5): [True: 0, False: 3.94k]
  ------------------
  473|       |        /* TODO: This state should disappear in favor of get_key handle */
  474|      0|        break;
  475|    657|    case SSH_SESSION_STATE_KEXINIT_RECEIVED:
  ------------------
  |  Branch (475:5): [True: 657, False: 3.28k]
  ------------------
  476|    657|        set_status(session, 0.6f);
  ------------------
  |  |   58|    657|#define set_status(session, status) do {\
  |  |   59|    657|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (59:13): [True: 0, False: 657]
  |  |  |  Branch (59:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   60|    657|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   61|    657|    } while (0)
  |  |  ------------------
  |  |  |  Branch (61:14): [Folded, False: 657]
  |  |  ------------------
  ------------------
  477|    657|        ssh_list_kex(&session->next_crypto->server_kex);
  478|    657|        if ((session->flags & SSH_SESSION_FLAG_KEXINIT_SENT) == 0) {
  ------------------
  |  |   86|    657|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
  |  Branch (478:13): [True: 0, False: 657]
  ------------------
  479|       |            /* in rekeying state if next_crypto client_kex might be empty */
  480|      0|            rc = ssh_set_client_kex(session);
  481|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (481:17): [True: 0, False: 0]
  ------------------
  482|      0|                goto error;
  483|      0|            }
  484|      0|            rc = ssh_send_kex(session);
  485|      0|            if (rc < 0) {
  ------------------
  |  Branch (485:17): [True: 0, False: 0]
  ------------------
  486|      0|                goto error;
  487|      0|            }
  488|      0|        }
  489|    657|        if (ssh_kex_select_methods(session) == SSH_ERROR)
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (489:13): [True: 0, False: 657]
  ------------------
  490|      0|            goto error;
  491|    657|        set_status(session, 0.8f);
  ------------------
  |  |   58|    657|#define set_status(session, status) do {\
  |  |   59|    657|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (59:13): [True: 0, False: 657]
  |  |  |  Branch (59:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   60|    657|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   61|    657|    } while (0)
  |  |  ------------------
  |  |  |  Branch (61:14): [Folded, False: 657]
  |  |  ------------------
  ------------------
  492|    657|        session->session_state = SSH_SESSION_STATE_DH;
  493|       |
  494|       |        /* If the init packet was already sent in previous step, this will be no
  495|       |         * operation */
  496|    657|        if (dh_handshake(session) == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (496:13): [True: 0, False: 657]
  ------------------
  497|      0|            goto error;
  498|      0|        }
  499|    657|        FALL_THROUGH;
  ------------------
  |  |  494|    657|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
  500|  1.31k|    case SSH_SESSION_STATE_DH:
  ------------------
  |  Branch (500:5): [True: 657, False: 3.28k]
  ------------------
  501|  1.31k|        if (session->dh_handshake_state == DH_STATE_FINISHED) {
  ------------------
  |  Branch (501:13): [True: 657, False: 657]
  ------------------
  502|    657|            set_status(session, 1.0f);
  ------------------
  |  |   58|    657|#define set_status(session, status) do {\
  |  |   59|    657|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (59:13): [True: 0, False: 657]
  |  |  |  Branch (59:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   60|    657|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   61|    657|    } while (0)
  |  |  ------------------
  |  |  |  Branch (61:14): [Folded, False: 657]
  |  |  ------------------
  ------------------
  503|    657|            session->connected = 1;
  504|    657|            if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) {
  ------------------
  |  |   78|    657|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (504:17): [True: 0, False: 657]
  ------------------
  505|      0|                session->session_state = SSH_SESSION_STATE_AUTHENTICATED;
  506|    657|            } else {
  507|    657|                session->session_state = SSH_SESSION_STATE_AUTHENTICATING;
  508|    657|            }
  509|    657|        }
  510|  1.31k|        break;
  511|      0|    case SSH_SESSION_STATE_AUTHENTICATING:
  ------------------
  |  Branch (511:5): [True: 0, False: 3.94k]
  ------------------
  512|      0|        break;
  513|  1.31k|    case SSH_SESSION_STATE_ERROR:
  ------------------
  |  Branch (513:5): [True: 1.31k, False: 2.62k]
  ------------------
  514|  1.31k|        goto error;
  515|      0|    default:
  ------------------
  |  Branch (515:5): [True: 0, False: 3.94k]
  ------------------
  516|      0|        ssh_set_error(session, SSH_FATAL, "Invalid state %d",
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  517|  3.94k|                      session->session_state);
  518|  3.94k|    }
  519|       |
  520|  2.62k|    return;
  521|  2.62k|error:
  522|  1.31k|    ssh_session_socket_close(session);
  523|  1.31k|    SSH_LOG(SSH_LOG_WARN, "%s", ssh_get_error(session));
  ------------------
  |  |  281|  1.31k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  524|  1.31k|}
client.c:socket_callback_connected:
   72|    657|{
   73|    657|	ssh_session session=(ssh_session)user;
   74|       |
   75|    657|	if (session->session_state != SSH_SESSION_STATE_CONNECTING &&
  ------------------
  |  Branch (75:6): [True: 657, False: 0]
  ------------------
   76|    657|	    session->session_state != SSH_SESSION_STATE_SOCKET_CONNECTED)
  ------------------
  |  Branch (76:6): [True: 0, False: 657]
  ------------------
   77|      0|	{
   78|      0|		ssh_set_error(session,SSH_FATAL, "Wrong state in socket_callback_connected : %d",
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   79|      0|				session->session_state);
   80|       |
   81|      0|		return;
   82|      0|	}
   83|       |
   84|    657|	SSH_LOG(SSH_LOG_TRACE,"Socket connection callback: %d (%d)",code, errno_code);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   85|    657|	if(code == SSH_SOCKET_CONNECTED_OK)
  ------------------
  |  |  523|    657|#define SSH_SOCKET_CONNECTED_OK 			1
  ------------------
  |  Branch (85:5): [True: 657, False: 0]
  ------------------
   86|    657|		session->session_state=SSH_SESSION_STATE_SOCKET_CONNECTED;
   87|      0|	else {
   88|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};
   89|      0|		session->session_state=SSH_SESSION_STATE_ERROR;
   90|      0|		ssh_set_error(session,SSH_FATAL,"%s",
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   91|      0|                      ssh_strerror(errno_code, err_msg, SSH_ERRNO_MSG_MAX));
   92|      0|	}
   93|    657|	session->ssh_connection_callback(session);
   94|    657|}
client.c:callback_receive_banner:
  108|    657|{
  109|    657|    char *buffer = (char *)data;
  110|    657|    ssh_session session = (ssh_session) user;
  111|    657|    char *str = NULL;
  112|    657|    uint32_t i;
  113|    657|    int ret=0;
  114|       |
  115|    657|    if (session->session_state != SSH_SESSION_STATE_SOCKET_CONNECTED) {
  ------------------
  |  Branch (115:9): [True: 0, False: 657]
  ------------------
  116|      0|        ssh_set_error(session,SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  117|      0|                      "Wrong state in callback_receive_banner : %d",
  118|      0|                      session->session_state);
  119|       |
  120|      0|        return 0;
  121|      0|    }
  122|  15.1k|    for (i = 0; i < len; ++i) {
  ------------------
  |  Branch (122:17): [True: 15.1k, False: 0]
  ------------------
  123|  15.1k|#ifdef WITH_PCAP
  124|  15.1k|        if (session->pcap_ctx && buffer[i] == '\n') {
  ------------------
  |  Branch (124:13): [True: 0, False: 15.1k]
  |  Branch (124:34): [True: 0, False: 0]
  ------------------
  125|      0|            ssh_pcap_context_write(session->pcap_ctx,
  126|      0|                                   SSH_PCAP_DIR_IN,
  127|      0|                                   buffer,i+1,
  128|      0|                                   i+1);
  129|      0|        }
  130|  15.1k|#endif
  131|  15.1k|        if (buffer[i] == '\r') {
  ------------------
  |  Branch (131:13): [True: 657, False: 14.4k]
  ------------------
  132|    657|            buffer[i] = '\0';
  133|    657|        }
  134|  15.1k|        if (buffer[i] == '\n') {
  ------------------
  |  Branch (134:13): [True: 657, False: 14.4k]
  ------------------
  135|    657|            int cmp;
  136|       |
  137|    657|            buffer[i] = '\0';
  138|       |
  139|       |            /* The server MAY send other lines of data... */
  140|    657|            cmp = strncmp(buffer, "SSH-", 4);
  141|    657|            if (cmp == 0) {
  ------------------
  |  Branch (141:17): [True: 657, False: 0]
  ------------------
  142|    657|                str = strdup(buffer);
  143|    657|                if (str == NULL) {
  ------------------
  |  Branch (143:21): [True: 0, False: 657]
  ------------------
  144|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  145|      0|                }
  146|       |                /* number of bytes read */
  147|    657|                ret = i + 1;
  148|    657|                session->serverbanner = str;
  149|    657|                session->session_state = SSH_SESSION_STATE_BANNER_RECEIVED;
  150|    657|                SSH_LOG(SSH_LOG_PACKET, "Received banner: %s", str);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  151|    657|                session->ssh_connection_callback(session);
  152|       |
  153|    657|                return ret;
  154|    657|            } else {
  155|      0|                SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  156|      0|                        "ssh_protocol_version_exchange: %s",
  157|      0|                        buffer);
  158|      0|                ret = i + 1;
  159|      0|                break;
  160|      0|            }
  161|    657|        }
  162|       |        /* According to RFC 4253 the max banner length is 255 */
  163|  14.4k|        if (i > 255) {
  ------------------
  |  Branch (163:13): [True: 0, False: 14.4k]
  ------------------
  164|       |            /* Too big banner */
  165|      0|            session->session_state=SSH_SESSION_STATE_ERROR;
  166|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  167|      0|                          SSH_FATAL,
  168|      0|                          "Receiving banner: too large banner");
  169|       |
  170|      0|            return 0;
  171|      0|        }
  172|  14.4k|    }
  173|       |
  174|      0|    return ret;
  175|    657|}
client.c:ssh_connect_termination:
  530|  4.78k|{
  531|  4.78k|    ssh_session session = (ssh_session)user;
  532|       |
  533|  4.78k|    switch (session->session_state) {
  534|      0|    case SSH_SESSION_STATE_ERROR:
  ------------------
  |  Branch (534:5): [True: 0, False: 4.78k]
  ------------------
  535|  1.31k|    case SSH_SESSION_STATE_AUTHENTICATING:
  ------------------
  |  Branch (535:5): [True: 1.31k, False: 3.46k]
  ------------------
  536|  1.31k|    case SSH_SESSION_STATE_DISCONNECTED:
  ------------------
  |  Branch (536:5): [True: 0, False: 4.78k]
  ------------------
  537|  1.31k|        return 1;
  538|  3.46k|    default:
  ------------------
  |  Branch (538:5): [True: 3.46k, False: 1.31k]
  ------------------
  539|  3.46k|        return 0;
  540|  4.78k|    }
  541|  4.78k|}

ssh_config_parse_uri:
  248|  1.31k|{
  249|  1.31k|    const char *endp = NULL;
  250|  1.31k|    long port_n;
  251|  1.31k|    int rc;
  252|       |
  253|       |    /* Sanitize inputs */
  254|  1.31k|    if (username != NULL) {
  ------------------
  |  Branch (254:9): [True: 657, False: 657]
  ------------------
  255|    657|        *username = NULL;
  256|    657|    }
  257|  1.31k|    if (hostname != NULL) {
  ------------------
  |  Branch (257:9): [True: 1.31k, False: 0]
  ------------------
  258|  1.31k|        *hostname = NULL;
  259|  1.31k|    }
  260|  1.31k|    if (port != NULL) {
  ------------------
  |  Branch (260:9): [True: 0, False: 1.31k]
  ------------------
  261|      0|        *port = NULL;
  262|      0|    }
  263|       |
  264|       |    /* Username part (optional) */
  265|  1.31k|    endp = strrchr(tok, '@');
  266|  1.31k|    if (endp != NULL) {
  ------------------
  |  Branch (266:9): [True: 0, False: 1.31k]
  ------------------
  267|       |        /* Zero-length username is not valid */
  268|      0|        if (tok == endp) {
  ------------------
  |  Branch (268:13): [True: 0, False: 0]
  ------------------
  269|      0|            goto error;
  270|      0|        }
  271|      0|        if (username != NULL) {
  ------------------
  |  Branch (271:13): [True: 0, False: 0]
  ------------------
  272|      0|            *username = strndup(tok, endp - tok);
  273|      0|            if (*username == NULL) {
  ------------------
  |  Branch (273:17): [True: 0, False: 0]
  ------------------
  274|      0|                goto error;
  275|      0|            }
  276|      0|            rc = ssh_check_username_syntax(*username);
  277|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (277:17): [True: 0, False: 0]
  ------------------
  278|      0|                goto error;
  279|      0|            }
  280|      0|        }
  281|      0|        tok = endp + 1;
  282|       |        /* If there is second @ character, this does not look like our URI */
  283|      0|        endp = strchr(tok, '@');
  284|      0|        if (endp != NULL) {
  ------------------
  |  Branch (284:13): [True: 0, False: 0]
  ------------------
  285|      0|            goto error;
  286|      0|        }
  287|      0|    }
  288|       |
  289|       |    /* Hostname */
  290|  1.31k|    if (*tok == '[') {
  ------------------
  |  Branch (290:9): [True: 0, False: 1.31k]
  ------------------
  291|       |        /* IPv6 address is enclosed with square brackets */
  292|      0|        tok++;
  293|      0|        endp = strchr(tok, ']');
  294|      0|        if (endp == NULL) {
  ------------------
  |  Branch (294:13): [True: 0, False: 0]
  ------------------
  295|      0|            goto error;
  296|      0|        }
  297|  1.31k|    } else if (!ignore_port) {
  ------------------
  |  Branch (297:16): [True: 0, False: 1.31k]
  ------------------
  298|       |        /* Hostnames or aliases expand to the last colon (if port is requested)
  299|       |         * or to the end */
  300|      0|        endp = strrchr(tok, ':');
  301|      0|        if (endp == NULL) {
  ------------------
  |  Branch (301:13): [True: 0, False: 0]
  ------------------
  302|      0|            endp = strchr(tok, '\0');
  303|      0|        }
  304|  1.31k|    } else {
  305|       |        /* If no port is requested, expand to the end of line
  306|       |         * (to accommodate the IPv6 addresses) */
  307|  1.31k|        endp = strchr(tok, '\0');
  308|  1.31k|    }
  309|  1.31k|    if (tok == endp) {
  ------------------
  |  Branch (309:9): [True: 0, False: 1.31k]
  ------------------
  310|       |        /* Zero-length hostnames are not valid */
  311|      0|        goto error;
  312|      0|    }
  313|  1.31k|    if (hostname != NULL) {
  ------------------
  |  Branch (313:9): [True: 1.31k, False: 0]
  ------------------
  314|  1.31k|        *hostname = strndup(tok, endp - tok);
  315|  1.31k|        if (*hostname == NULL) {
  ------------------
  |  Branch (315:13): [True: 0, False: 1.31k]
  ------------------
  316|      0|            goto error;
  317|      0|        }
  318|  1.31k|        if (strict) {
  ------------------
  |  Branch (318:13): [True: 657, False: 657]
  ------------------
  319|       |            /* if not an ip, check syntax */
  320|    657|            rc = ssh_is_ipaddr(*hostname);
  321|    657|            if (rc == 0) {
  ------------------
  |  Branch (321:17): [True: 657, False: 0]
  ------------------
  322|    657|                rc = ssh_check_hostname_syntax(*hostname);
  323|    657|                if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (323:21): [True: 0, False: 657]
  ------------------
  324|      0|                    goto error;
  325|      0|                }
  326|    657|            }
  327|    657|        } else {
  328|       |            /* Reject shell metacharacters to allow config aliases with
  329|       |             * non-RFC1035 chars (e.g. %, _). Modeled on OpenSSH's
  330|       |             * valid_hostname() in ssh.c. */
  331|    657|            const char *c = NULL;
  332|    657|            if ((*hostname)[0] == '-') {
  ------------------
  |  Branch (332:17): [True: 0, False: 657]
  ------------------
  333|      0|                goto error;
  334|      0|            }
  335|  6.57k|            for (c = *hostname; *c != '\0'; c++) {
  ------------------
  |  Branch (335:33): [True: 5.91k, False: 657]
  ------------------
  336|  5.91k|                const char *is_meta = strchr("'`\"$\\;&<>|(){},", *c);
  337|  5.91k|                int is_space = isspace((unsigned char)*c);
  338|  5.91k|                int is_ctrl = iscntrl((unsigned char)*c);
  339|  5.91k|                if (is_meta != NULL || is_space || is_ctrl) {
  ------------------
  |  Branch (339:21): [True: 0, False: 5.91k]
  |  Branch (339:40): [True: 0, False: 5.91k]
  |  Branch (339:52): [True: 0, False: 5.91k]
  ------------------
  340|      0|                    goto error;
  341|      0|                }
  342|  5.91k|            }
  343|    657|        }
  344|  1.31k|    }
  345|       |    /* Skip also the closing bracket */
  346|  1.31k|    if (*endp == ']') {
  ------------------
  |  Branch (346:9): [True: 0, False: 1.31k]
  ------------------
  347|      0|        endp++;
  348|      0|    }
  349|       |
  350|       |    /* Port (optional) */
  351|  1.31k|    if (*endp != '\0') {
  ------------------
  |  Branch (351:9): [True: 0, False: 1.31k]
  ------------------
  352|      0|        char *port_end = NULL;
  353|       |
  354|       |        /* Verify the port is valid positive number */
  355|      0|        port_n = strtol(endp + 1, &port_end, 10);
  356|      0|        if (port_n < 1 || *port_end != '\0') {
  ------------------
  |  Branch (356:13): [True: 0, False: 0]
  |  Branch (356:27): [True: 0, False: 0]
  ------------------
  357|      0|            SSH_LOG(SSH_LOG_TRACE, "Failed to parse port number."
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  358|      0|                    " The value '%ld' is invalid or there are some"
  359|      0|                    " trailing characters: '%s'", port_n, port_end);
  360|      0|            goto error;
  361|      0|        }
  362|      0|        if (port != NULL) {
  ------------------
  |  Branch (362:13): [True: 0, False: 0]
  ------------------
  363|      0|            *port = strdup(endp + 1);
  364|      0|            if (*port == NULL) {
  ------------------
  |  Branch (364:17): [True: 0, False: 0]
  ------------------
  365|      0|                goto error;
  366|      0|            }
  367|      0|        }
  368|      0|    }
  369|       |
  370|  1.31k|    return SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  371|       |
  372|      0|error:
  373|      0|    if (username != NULL) {
  ------------------
  |  Branch (373:9): [True: 0, False: 0]
  ------------------
  374|      0|        SAFE_FREE(*username);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  375|      0|    }
  376|      0|    if (hostname != NULL) {
  ------------------
  |  Branch (376:9): [True: 0, False: 0]
  ------------------
  377|      0|        SAFE_FREE(*hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  378|      0|    }
  379|      0|    if (port != NULL) {
  ------------------
  |  Branch (379:9): [True: 0, False: 0]
  ------------------
  380|      0|        SAFE_FREE(*port);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  381|      0|    }
  382|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  383|  1.31k|}

secure_memcmp:
   25|  5.54k|{
   26|  5.54k|    size_t i;
   27|  5.54k|    uint8_t status = 0;
   28|  5.54k|    const uint8_t *p1 = s1;
   29|  5.54k|    const uint8_t *p2 = s2;
   30|       |
   31|   132k|    for (i = 0; i < n; i++) {
  ------------------
  |  Branch (31:17): [True: 126k, False: 5.54k]
  ------------------
   32|   126k|        status |= (p1[i] ^ p2[i]);
   33|   126k|    }
   34|       |
   35|  5.54k|    return (status != 0);
   36|  5.54k|}

ssh_curve25519_create_k:
   52|  1.31k|{
   53|  1.31k|    int rc;
   54|       |
   55|       |#ifdef DEBUG_CRYPTO
   56|       |    ssh_log_hexdump("Session server cookie",
   57|       |                    session->next_crypto->server_kex.cookie,
   58|       |                    16);
   59|       |    ssh_log_hexdump("Session client cookie",
   60|       |                    session->next_crypto->client_kex.cookie,
   61|       |                    16);
   62|       |#endif
   63|       |
   64|  1.31k|    rc = curve25519_do_create_k(session, k);
   65|  1.31k|    return rc;
   66|  1.31k|}

ssh_curve25519_init:
   34|  1.31k|{
   35|  1.31k|    ssh_curve25519_pubkey *pubkey_loc = NULL;
   36|  1.31k|    EVP_PKEY_CTX *pctx = NULL;
   37|  1.31k|    EVP_PKEY *pkey = NULL;
   38|  1.31k|    size_t pubkey_len = CURVE25519_PUBKEY_SIZE;
  ------------------
  |  |   40|  1.31k|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
   39|  1.31k|    int rc;
   40|       |
   41|  1.31k|    if (session->server) {
  ------------------
  |  Branch (41:9): [True: 657, False: 657]
  ------------------
   42|    657|        pubkey_loc = &session->next_crypto->curve25519_server_pubkey;
   43|    657|    } else {
   44|    657|        pubkey_loc = &session->next_crypto->curve25519_client_pubkey;
   45|    657|    }
   46|       |
   47|  1.31k|    pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_X25519, NULL);
   48|  1.31k|    if (pctx == NULL) {
  ------------------
  |  Branch (48:9): [True: 0, False: 1.31k]
  ------------------
   49|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   50|      0|                "Failed to initialize X25519 context: %s",
   51|      0|                ERR_error_string(ERR_get_error(), NULL));
   52|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   53|      0|    }
   54|       |
   55|  1.31k|    rc = EVP_PKEY_keygen_init(pctx);
   56|  1.31k|    if (rc != 1) {
  ------------------
  |  Branch (56:9): [True: 0, False: 1.31k]
  ------------------
   57|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   58|      0|                "Failed to initialize X25519 keygen: %s",
   59|      0|                ERR_error_string(ERR_get_error(), NULL));
   60|      0|        EVP_PKEY_CTX_free(pctx);
   61|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   62|      0|    }
   63|       |
   64|  1.31k|    rc = EVP_PKEY_keygen(pctx, &pkey);
   65|  1.31k|    EVP_PKEY_CTX_free(pctx);
   66|  1.31k|    if (rc != 1) {
  ------------------
  |  Branch (66:9): [True: 0, False: 1.31k]
  ------------------
   67|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   68|      0|                "Failed to generate X25519 keys: %s",
   69|      0|                ERR_error_string(ERR_get_error(), NULL));
   70|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   71|      0|    }
   72|       |
   73|  1.31k|    rc = EVP_PKEY_get_raw_public_key(pkey, *pubkey_loc, &pubkey_len);
   74|  1.31k|    if (rc != 1) {
  ------------------
  |  Branch (74:9): [True: 0, False: 1.31k]
  ------------------
   75|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   76|      0|                "Failed to get X25519 raw public key: %s",
   77|      0|                ERR_error_string(ERR_get_error(), NULL));
   78|      0|        EVP_PKEY_free(pkey);
   79|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   80|      0|    }
   81|       |
   82|       |    /* Free any previously allocated privkey */
   83|  1.31k|    if (session->next_crypto->curve25519_privkey != NULL) {
  ------------------
  |  Branch (83:9): [True: 0, False: 1.31k]
  ------------------
   84|      0|        EVP_PKEY_free(session->next_crypto->curve25519_privkey);
   85|      0|        session->next_crypto->curve25519_privkey = NULL;
   86|      0|    }
   87|       |
   88|  1.31k|    session->next_crypto->curve25519_privkey = pkey;
   89|  1.31k|    pkey = NULL;
   90|       |
   91|  1.31k|    return SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
   92|  1.31k|}
curve25519_do_create_k:
   95|  1.31k|{
   96|  1.31k|    ssh_curve25519_pubkey *peer_pubkey_loc = NULL;
   97|  1.31k|    int rc, ret = SSH_ERROR;
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   98|  1.31k|    EVP_PKEY_CTX *pctx = NULL;
   99|  1.31k|    EVP_PKEY *pkey = NULL, *pubkey = NULL;
  100|  1.31k|    size_t shared_key_len = CURVE25519_PUBKEY_SIZE;
  ------------------
  |  |   40|  1.31k|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  101|       |
  102|  1.31k|    if (session->server) {
  ------------------
  |  Branch (102:9): [True: 657, False: 657]
  ------------------
  103|    657|        peer_pubkey_loc = &session->next_crypto->curve25519_client_pubkey;
  104|    657|    } else {
  105|    657|        peer_pubkey_loc = &session->next_crypto->curve25519_server_pubkey;
  106|    657|    }
  107|       |
  108|  1.31k|    pkey = session->next_crypto->curve25519_privkey;
  109|  1.31k|    if (pkey == NULL) {
  ------------------
  |  Branch (109:9): [True: 0, False: 1.31k]
  ------------------
  110|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  111|      0|                "Failed to create X25519 EVP_PKEY: %s",
  112|      0|                ERR_error_string(ERR_get_error(), NULL));
  113|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  114|      0|    }
  115|       |
  116|  1.31k|    pctx = EVP_PKEY_CTX_new(pkey, NULL);
  117|  1.31k|    if (pctx == NULL) {
  ------------------
  |  Branch (117:9): [True: 0, False: 1.31k]
  ------------------
  118|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  119|      0|                "Failed to initialize X25519 context: %s",
  120|      0|                ERR_error_string(ERR_get_error(), NULL));
  121|      0|        goto out;
  122|      0|    }
  123|       |
  124|  1.31k|    rc = EVP_PKEY_derive_init(pctx);
  125|  1.31k|    if (rc != 1) {
  ------------------
  |  Branch (125:9): [True: 0, False: 1.31k]
  ------------------
  126|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  127|      0|                "Failed to initialize X25519 key derivation: %s",
  128|      0|                ERR_error_string(ERR_get_error(), NULL));
  129|      0|        goto out;
  130|      0|    }
  131|       |
  132|  1.31k|    pubkey = EVP_PKEY_new_raw_public_key(EVP_PKEY_X25519,
  133|  1.31k|                                         NULL,
  134|  1.31k|                                         *peer_pubkey_loc,
  135|  1.31k|                                         CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   40|  1.31k|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  136|  1.31k|    if (pubkey == NULL) {
  ------------------
  |  Branch (136:9): [True: 0, False: 1.31k]
  ------------------
  137|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  138|      0|                "Failed to create X25519 public key EVP_PKEY: %s",
  139|      0|                ERR_error_string(ERR_get_error(), NULL));
  140|      0|        goto out;
  141|      0|    }
  142|       |
  143|  1.31k|    rc = EVP_PKEY_derive_set_peer(pctx, pubkey);
  144|  1.31k|    if (rc != 1) {
  ------------------
  |  Branch (144:9): [True: 0, False: 1.31k]
  ------------------
  145|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  146|      0|                "Failed to set peer X25519 public key: %s",
  147|      0|                ERR_error_string(ERR_get_error(), NULL));
  148|      0|        goto out;
  149|      0|    }
  150|       |
  151|  1.31k|    rc = EVP_PKEY_derive(pctx, k, &shared_key_len);
  152|  1.31k|    if (rc != 1) {
  ------------------
  |  Branch (152:9): [True: 0, False: 1.31k]
  ------------------
  153|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  154|      0|                "Failed to derive X25519 shared secret: %s",
  155|      0|                ERR_error_string(ERR_get_error(), NULL));
  156|      0|        goto out;
  157|      0|    }
  158|  1.31k|    ret = SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  159|       |
  160|  1.31k|out:
  161|  1.31k|    EVP_PKEY_free(pubkey);
  162|  1.31k|    EVP_PKEY_CTX_free(pctx);
  163|  1.31k|    return ret;
  164|  1.31k|}

ssh_dh_init:
  235|      2|{
  236|      2|    unsigned long g_int = 2 ;	/* G is defined as 2 by the ssh2 standards */
  237|      2|    int rc;
  238|      2|    if (dh_crypto_initialized) {
  ------------------
  |  Branch (238:9): [True: 0, False: 2]
  ------------------
  239|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  240|      0|    }
  241|      2|    dh_crypto_initialized = 1;
  242|       |
  243|      2|    ssh_dh_generator = bignum_new();
  ------------------
  |  |   70|      2|#define bignum_new() BN_new()
  ------------------
  244|      2|    if (ssh_dh_generator == NULL) {
  ------------------
  |  Branch (244:9): [True: 0, False: 2]
  ------------------
  245|      0|        goto error;
  246|      0|    }
  247|      2|    rc = bignum_set_word(ssh_dh_generator, g_int);
  ------------------
  |  |   77|      2|#define bignum_set_word(bn,n) BN_set_word(bn,n)
  ------------------
  248|      2|    if (rc != 1) {
  ------------------
  |  Branch (248:9): [True: 0, False: 2]
  ------------------
  249|      0|        goto error;
  250|      0|    }
  251|       |
  252|      2|    bignum_bin2bn(p_group1_value, P_GROUP1_LEN, &ssh_dh_group1);
  ------------------
  |  |   79|      2|    do {                                     \
  |  |   80|      2|        (*dest) = BN_new();                  \
  |  |   81|      2|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 2, False: 0]
  |  |  ------------------
  |  |   82|      2|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|      2|        }                                    \
  |  |   84|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  253|      2|    if (ssh_dh_group1 == NULL) {
  ------------------
  |  Branch (253:9): [True: 0, False: 2]
  ------------------
  254|      0|        goto error;
  255|      0|    }
  256|      2|    bignum_bin2bn(p_group14_value, P_GROUP14_LEN, &ssh_dh_group14);
  ------------------
  |  |   79|      2|    do {                                     \
  |  |   80|      2|        (*dest) = BN_new();                  \
  |  |   81|      2|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 2, False: 0]
  |  |  ------------------
  |  |   82|      2|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|      2|        }                                    \
  |  |   84|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  257|      2|    if (ssh_dh_group14 == NULL) {
  ------------------
  |  Branch (257:9): [True: 0, False: 2]
  ------------------
  258|      0|        goto error;
  259|      0|    }
  260|      2|    bignum_bin2bn(p_group16_value, P_GROUP16_LEN, &ssh_dh_group16);
  ------------------
  |  |   79|      2|    do {                                     \
  |  |   80|      2|        (*dest) = BN_new();                  \
  |  |   81|      2|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 2, False: 0]
  |  |  ------------------
  |  |   82|      2|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|      2|        }                                    \
  |  |   84|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  261|      2|    if (ssh_dh_group16 == NULL) {
  ------------------
  |  Branch (261:9): [True: 0, False: 2]
  ------------------
  262|      0|        goto error;
  263|      0|    }
  264|      2|    bignum_bin2bn(p_group18_value, P_GROUP18_LEN, &ssh_dh_group18);
  ------------------
  |  |   79|      2|    do {                                     \
  |  |   80|      2|        (*dest) = BN_new();                  \
  |  |   81|      2|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 2, False: 0]
  |  |  ------------------
  |  |   82|      2|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|      2|        }                                    \
  |  |   84|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  265|      2|    if (ssh_dh_group18 == NULL) {
  ------------------
  |  Branch (265:9): [True: 0, False: 2]
  ------------------
  266|      0|        goto error;
  267|      0|    }
  268|       |
  269|      2|    return 0;
  270|      0|error:
  271|      0|    ssh_dh_finalize();
  272|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  273|      2|}
ssh_dh_import_next_pubkey_blob:
  295|  1.31k|{
  296|  1.31k|    return ssh_pki_import_pubkey_blob(pubkey_blob,
  297|  1.31k|                                      &session->next_crypto->server_pubkey);
  298|       |
  299|  1.31k|}
ssh_dh_get_next_server_publickey:
  676|  2.62k|{
  677|  2.62k|    return session->next_crypto->server_pubkey;
  678|  2.62k|}
ssh_dh_get_next_server_publickey_blob:
  683|  1.97k|{
  684|  1.97k|    const ssh_key pubkey = ssh_dh_get_next_server_publickey(session);
  685|       |
  686|  1.97k|    return ssh_pki_export_pubkey_blob(pubkey, pubkey_blob);
  687|  1.97k|}

ssh_dh_cleanup:
  449|  3.94k|{
  450|  3.94k|    if (crypto->dh_ctx != NULL) {
  ------------------
  |  Branch (450:9): [True: 0, False: 3.94k]
  ------------------
  451|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  452|      0|        DH_free(crypto->dh_ctx->keypair[0]);
  453|      0|        DH_free(crypto->dh_ctx->keypair[1]);
  454|       |#else
  455|       |        EVP_PKEY_free(crypto->dh_ctx->keypair[0]);
  456|       |        EVP_PKEY_free(crypto->dh_ctx->keypair[1]);
  457|       |#endif /* OPENSSL_VERSION_NUMBER */
  458|      0|        free(crypto->dh_ctx);
  459|       |        crypto->dh_ctx = NULL;
  460|      0|    }
  461|  3.94k|}

_ssh_set_error:
   55|  1.97k|{
   56|  1.97k|    struct ssh_common_struct *err = error;
   57|  1.97k|    va_list va;
   58|       |
   59|  1.97k|    va_start(va, descr);
   60|  1.97k|    vsnprintf(err->error.error_buffer, ERROR_BUFFERLEN, descr, va);
  ------------------
  |  |  219|  1.97k|#define ERROR_BUFFERLEN 1024
  ------------------
   61|  1.97k|    va_end(va);
   62|       |
   63|  1.97k|    err->error.error_code = code;
   64|  1.97k|    if (ssh_get_log_level() == SSH_LOG_TRACE) {
  ------------------
  |  |  363|  1.97k|#define SSH_LOG_TRACE 4
  ------------------
  |  Branch (64:9): [True: 0, False: 1.97k]
  ------------------
   65|      0|        ssh_log_function(SSH_LOG_TRACE,
  ------------------
  |  |  363|      0|#define SSH_LOG_TRACE 4
  ------------------
   66|      0|                         function,
   67|      0|                         err->error.error_buffer);
   68|      0|    }
   69|  1.97k|}
ssh_reset_error:
  113|    657|{
  114|    657|    struct ssh_common_struct *err = error;
  115|       |
  116|    657|    ZERO_STRUCT(err->error.error_buffer);
  ------------------
  |  |  376|    657|#define ZERO_STRUCT(x) memset(&(x), 0, sizeof(x))
  ------------------
  117|    657|    err->error.error_code = 0;
  118|    657|}
ssh_get_error:
  127|  1.31k|const char *ssh_get_error(void *error) {
  128|  1.31k|  struct error_struct *err = error;
  129|       |
  130|  1.31k|  return err->error_buffer;
  131|  1.31k|}

libcrux_ml_kem_mlkem768_portable_decapsulate:
 8039|    657|    libcrux_ml_kem_mlkem768_MlKem768Ciphertext *ciphertext, uint8_t ret[32U]) {
 8040|    657|  libcrux_ml_kem_ind_cca_instantiations_portable_decapsulate_35(
 8041|    657|      private_key, ciphertext, ret);
 8042|    657|}
libcrux_ml_kem_mlkem768_portable_encapsulate:
 8172|    657|    uint8_t randomness[32U]) {
 8173|    657|  return libcrux_ml_kem_ind_cca_instantiations_portable_encapsulate_cd(
 8174|    657|      public_key, randomness);
 8175|    657|}
libcrux_ml_kem_mlkem768_portable_generate_key_pair:
 8762|    657|libcrux_ml_kem_mlkem768_portable_generate_key_pair(uint8_t randomness[64U]) {
 8763|    657|  return libcrux_ml_kem_ind_cca_instantiations_portable_generate_keypair_ce(
 8764|    657|      randomness);
 8765|    657|}
libcrux_ml_kem_mlkem768_portable_validate_public_key:
 8876|    657|    libcrux_ml_kem_types_MlKemPublicKey_30 *public_key) {
 8877|    657|  return libcrux_ml_kem_ind_cca_instantiations_portable_validate_public_key_41(
 8878|    657|      public_key->value);
 8879|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_instantiations_portable_decapsulate_35:
 8026|    657|    libcrux_ml_kem_mlkem768_MlKem768Ciphertext *ciphertext, uint8_t ret[32U]) {
 8027|    657|  libcrux_ml_kem_ind_cca_decapsulate_62(private_key, ciphertext, ret);
 8028|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_decapsulate_62:
 7937|    657|    libcrux_ml_kem_mlkem768_MlKem768Ciphertext *ciphertext, uint8_t ret[32U]) {
 7938|    657|  Eurydice_slice_uint8_t_x4 uu____0 =
 7939|    657|      libcrux_ml_kem_types_unpack_private_key_b4(
 7940|    657|          Eurydice_array_to_slice((size_t)2400U, private_key->value, uint8_t));
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7941|    657|  Eurydice_slice ind_cpa_secret_key = uu____0.fst;
 7942|    657|  Eurydice_slice ind_cpa_public_key = uu____0.snd;
 7943|    657|  Eurydice_slice ind_cpa_public_key_hash = uu____0.thd;
 7944|    657|  Eurydice_slice implicit_rejection_value = uu____0.f3;
 7945|    657|  uint8_t decrypted[32U];
 7946|    657|  libcrux_ml_kem_ind_cpa_decrypt_42(ind_cpa_secret_key, ciphertext->value,
 7947|    657|                                    decrypted);
 7948|    657|  uint8_t to_hash0[64U];
 7949|    657|  libcrux_ml_kem_utils_into_padded_array_24(
 7950|    657|      Eurydice_array_to_slice((size_t)32U, decrypted, uint8_t), to_hash0);
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7951|    657|  Eurydice_slice_copy(
  ------------------
  |  |  229|    657|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 7952|    657|      Eurydice_array_to_subslice_from(
 7953|    657|          (size_t)64U, to_hash0, LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
 7954|    657|          uint8_t, size_t, uint8_t[]),
 7955|    657|      ind_cpa_public_key_hash, uint8_t);
 7956|    657|  uint8_t hashed[64U];
 7957|    657|  libcrux_ml_kem_hash_functions_portable_G_4a_e0(
 7958|    657|      Eurydice_array_to_slice((size_t)64U, to_hash0, uint8_t), hashed);
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7959|    657|  Eurydice_slice_uint8_t_x2 uu____1 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    657|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    657|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    657|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    657|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    657|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    657|  }
  ------------------
 7960|    657|      Eurydice_array_to_slice((size_t)64U, hashed, uint8_t),
 7961|    657|      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE, uint8_t,
 7962|    657|      Eurydice_slice_uint8_t_x2);
 7963|    657|  Eurydice_slice shared_secret0 = uu____1.fst;
 7964|    657|  Eurydice_slice pseudorandomness = uu____1.snd;
 7965|    657|  uint8_t to_hash[1120U];
 7966|    657|  libcrux_ml_kem_utils_into_padded_array_15(implicit_rejection_value, to_hash);
 7967|    657|  Eurydice_slice uu____2 = Eurydice_array_to_subslice_from(
  ------------------
  |  |  225|    657|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7968|    657|      (size_t)1120U, to_hash, LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
 7969|    657|      uint8_t, size_t, uint8_t[]);
 7970|    657|  Eurydice_slice_copy(uu____2, libcrux_ml_kem_types_as_ref_d3_80(ciphertext),
  ------------------
  |  |  229|    657|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 7971|    657|                      uint8_t);
 7972|    657|  uint8_t implicit_rejection_shared_secret0[32U];
 7973|    657|  libcrux_ml_kem_hash_functions_portable_PRF_4a_41(
 7974|    657|      Eurydice_array_to_slice((size_t)1120U, to_hash, uint8_t),
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7975|    657|      implicit_rejection_shared_secret0);
 7976|    657|  uint8_t expected_ciphertext[1088U];
 7977|    657|  libcrux_ml_kem_ind_cpa_encrypt_2a(ind_cpa_public_key, decrypted,
 7978|    657|                                    pseudorandomness, expected_ciphertext);
 7979|    657|  uint8_t implicit_rejection_shared_secret[32U];
 7980|    657|  libcrux_ml_kem_variant_kdf_39_d6(
 7981|    657|      Eurydice_array_to_slice((size_t)32U, implicit_rejection_shared_secret0,
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7982|    657|                              uint8_t),
 7983|    657|      libcrux_ml_kem_types_as_slice_a9_80(ciphertext),
 7984|    657|      implicit_rejection_shared_secret);
 7985|    657|  uint8_t shared_secret[32U];
 7986|    657|  libcrux_ml_kem_variant_kdf_39_d6(
 7987|    657|      shared_secret0, libcrux_ml_kem_types_as_slice_a9_80(ciphertext),
 7988|    657|      shared_secret);
 7989|    657|  uint8_t ret0[32U];
 7990|    657|  libcrux_ml_kem_constant_time_ops_compare_ciphertexts_select_shared_secret_in_constant_time(
 7991|    657|      libcrux_ml_kem_types_as_ref_d3_80(ciphertext),
 7992|    657|      Eurydice_array_to_slice((size_t)1088U, expected_ciphertext, uint8_t),
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7993|    657|      Eurydice_array_to_slice((size_t)32U, shared_secret, uint8_t),
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7994|    657|      Eurydice_array_to_slice((size_t)32U, implicit_rejection_shared_secret,
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7995|    657|                              uint8_t),
 7996|    657|      ret0);
 7997|    657|  memcpy(ret, ret0, (size_t)32U * sizeof(uint8_t));
 7998|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_unpack_private_key_b4:
  989|    657|libcrux_ml_kem_types_unpack_private_key_b4(Eurydice_slice private_key) {
  990|    657|  Eurydice_slice_uint8_t_x2 uu____0 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    657|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    657|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    657|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    657|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    657|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    657|  }
  ------------------
  991|    657|      private_key, (size_t)1152U, uint8_t, Eurydice_slice_uint8_t_x2);
  992|    657|  Eurydice_slice ind_cpa_secret_key = uu____0.fst;
  993|    657|  Eurydice_slice secret_key0 = uu____0.snd;
  994|    657|  Eurydice_slice_uint8_t_x2 uu____1 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    657|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    657|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    657|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    657|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    657|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    657|  }
  ------------------
  995|    657|      secret_key0, (size_t)1184U, uint8_t, Eurydice_slice_uint8_t_x2);
  996|    657|  Eurydice_slice ind_cpa_public_key = uu____1.fst;
  997|    657|  Eurydice_slice secret_key = uu____1.snd;
  998|    657|  Eurydice_slice_uint8_t_x2 uu____2 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    657|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    657|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    657|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    657|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    657|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    657|  }
  ------------------
  999|    657|      secret_key, LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE, uint8_t,
 1000|    657|      Eurydice_slice_uint8_t_x2);
 1001|    657|  Eurydice_slice ind_cpa_public_key_hash = uu____2.fst;
 1002|    657|  Eurydice_slice implicit_rejection_value = uu____2.snd;
 1003|    657|  return (
 1004|    657|      KRML_CLITERAL(Eurydice_slice_uint8_t_x4){.fst = ind_cpa_secret_key,
  ------------------
  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  ------------------
 1005|    657|                                               .snd = ind_cpa_public_key,
 1006|    657|                                               .thd = ind_cpa_public_key_hash,
 1007|    657|                                               .f3 = implicit_rejection_value});
 1008|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_decrypt_42:
 6268|    657|    Eurydice_slice secret_key, uint8_t *ciphertext, uint8_t ret[32U]) {
 6269|    657|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPrivateKeyUnpacked_a0
 6270|    657|      secret_key_unpacked;
 6271|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret0[3U];
 6272|  2.62k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6272:31): [True: 1.97k, False: 657]
  ------------------
 6273|       |    /* original Rust expression is not an lvalue in C */
 6274|  1.97k|    void *lvalue = (void *)0U;
 6275|  1.97k|    ret0[i] = libcrux_ml_kem_ind_cpa_decrypt_call_mut_0b_42(&lvalue, i);
 6276|  1.97k|  }
 6277|    657|  memcpy(
 6278|    657|      secret_key_unpacked.secret_as_ntt, ret0,
 6279|    657|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 6280|    657|  libcrux_ml_kem_ind_cpa_deserialize_vector_1b(
 6281|    657|      secret_key, secret_key_unpacked.secret_as_ntt);
 6282|    657|  uint8_t ret1[32U];
 6283|    657|  libcrux_ml_kem_ind_cpa_decrypt_unpacked_42(&secret_key_unpacked, ciphertext,
 6284|    657|                                             ret1);
 6285|    657|  memcpy(ret, ret1, (size_t)32U * sizeof(uint8_t));
 6286|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_decrypt_call_mut_0b_42:
 5348|  1.97k|libcrux_ml_kem_ind_cpa_decrypt_call_mut_0b_42(void **_, size_t tupled_args) {
 5349|  1.97k|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 5350|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_ZERO_d6_ea:
 5317|  61.1k|libcrux_ml_kem_polynomial_ZERO_d6_ea(void) {
 5318|  61.1k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d lit;
 5319|  61.1k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector
 5320|  61.1k|      repeat_expression[16U];
 5321|  1.03M|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5321:31): [True: 977k, False: 61.1k]
  ------------------
 5322|   977k|    repeat_expression[i] = libcrux_ml_kem_vector_portable_ZERO_b8();
 5323|   977k|  }
 5324|  61.1k|  memcpy(lit.coefficients, repeat_expression,
 5325|  61.1k|         (size_t)16U *
 5326|  61.1k|             sizeof(libcrux_ml_kem_vector_portable_vector_type_PortableVector));
 5327|  61.1k|  return lit;
 5328|  61.1k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ZERO_b8:
 3836|  1.85M|libcrux_ml_kem_vector_portable_ZERO_b8(void) {
 3837|  1.85M|  return libcrux_ml_kem_vector_portable_vector_type_zero();
 3838|  1.85M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_vector_type_zero:
 3822|  2.24M|libcrux_ml_kem_vector_portable_vector_type_zero(void) {
 3823|  2.24M|  libcrux_ml_kem_vector_portable_vector_type_PortableVector lit;
 3824|  2.24M|  int16_t ret[16U];
 3825|  2.24M|  int16_t buf[16U] = {0U};
 3826|  2.24M|  libcrux_secrets_int_public_integers_classify_27_46(buf, ret);
 3827|  2.24M|  memcpy(lit.elements, ret, (size_t)16U * sizeof(int16_t));
 3828|  2.24M|  return lit;
 3829|  2.24M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_46:
 1075|  2.24M|    int16_t self[16U], int16_t ret[16U]) {
 1076|  2.24M|  memcpy(ret, self, (size_t)16U * sizeof(int16_t));
 1077|  2.24M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_deserialize_vector_1b:
 5387|    657|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *secret_as_ntt) {
 5388|  2.62k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (5388:31): [True: 1.97k, False: 657]
  ------------------
 5389|  1.97k|    size_t i0 = i;
 5390|  1.97k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0 =
 5391|  1.97k|        libcrux_ml_kem_serialize_deserialize_to_uncompressed_ring_element_ea(
 5392|  1.97k|            Eurydice_slice_subslice3(
  ------------------
  |  |  195|  1.97k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  1.97k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.97k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5393|  1.97k|                secret_key,
 5394|  1.97k|                i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 5395|  1.97k|                (i0 + (size_t)1U) *
 5396|  1.97k|                    LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 5397|  1.97k|                uint8_t *));
 5398|  1.97k|    secret_as_ntt[i0] = uu____0;
 5399|  1.97k|  }
 5400|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_to_uncompressed_ring_element_ea:
 5360|  1.97k|    Eurydice_slice serialized) {
 5361|  1.97k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d re =
 5362|  1.97k|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 5363|  1.97k|  for (size_t i = (size_t)0U;
 5364|  33.5k|       i < Eurydice_slice_len(serialized, uint8_t) / (size_t)24U; i++) {
  ------------------
  |  |  173|  33.5k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5364:8): [True: 31.5k, False: 1.97k]
  ------------------
 5365|  31.5k|    size_t i0 = i;
 5366|  31.5k|    Eurydice_slice bytes =
 5367|  31.5k|        Eurydice_slice_subslice3(serialized, i0 * (size_t)24U,
  ------------------
  |  |  195|  31.5k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  31.5k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  31.5k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5368|  31.5k|                                 i0 * (size_t)24U + (size_t)24U, uint8_t *);
 5369|  31.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5370|  31.5k|        libcrux_ml_kem_vector_portable_deserialize_12_b8(bytes);
 5371|  31.5k|    re.coefficients[i0] = uu____0;
 5372|  31.5k|  }
 5373|  1.97k|  return re;
 5374|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_12_b8:
 5179|   126k|libcrux_ml_kem_vector_portable_deserialize_12_b8(Eurydice_slice a) {
 5180|   126k|  return libcrux_ml_kem_vector_portable_deserialize_12(a);
 5181|   126k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_12:
 5169|   126k|libcrux_ml_kem_vector_portable_deserialize_12(Eurydice_slice a) {
 5170|   126k|  return libcrux_ml_kem_vector_portable_serialize_deserialize_12(
 5171|   126k|      libcrux_secrets_int_classify_public_classify_ref_9b_90(a));
 5172|   126k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_12:
 5140|   126k|libcrux_ml_kem_vector_portable_serialize_deserialize_12(Eurydice_slice bytes) {
 5141|   126k|  int16_t_x2 v0_1 = libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5142|   126k|      Eurydice_slice_subslice3(bytes, (size_t)0U, (size_t)3U, uint8_t *));
  ------------------
  |  |  195|   126k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   126k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   126k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5143|   126k|  int16_t_x2 v2_3 = libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5144|   126k|      Eurydice_slice_subslice3(bytes, (size_t)3U, (size_t)6U, uint8_t *));
  ------------------
  |  |  195|   126k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   126k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   126k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5145|   126k|  int16_t_x2 v4_5 = libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5146|   126k|      Eurydice_slice_subslice3(bytes, (size_t)6U, (size_t)9U, uint8_t *));
  ------------------
  |  |  195|   126k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   126k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   126k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5147|   126k|  int16_t_x2 v6_7 = libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5148|   126k|      Eurydice_slice_subslice3(bytes, (size_t)9U, (size_t)12U, uint8_t *));
  ------------------
  |  |  195|   126k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   126k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   126k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5149|   126k|  int16_t_x2 v8_9 = libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5150|   126k|      Eurydice_slice_subslice3(bytes, (size_t)12U, (size_t)15U, uint8_t *));
  ------------------
  |  |  195|   126k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   126k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   126k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5151|   126k|  int16_t_x2 v10_11 =
 5152|   126k|      libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5153|   126k|          Eurydice_slice_subslice3(bytes, (size_t)15U, (size_t)18U, uint8_t *));
  ------------------
  |  |  195|   126k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   126k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   126k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5154|   126k|  int16_t_x2 v12_13 =
 5155|   126k|      libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5156|   126k|          Eurydice_slice_subslice3(bytes, (size_t)18U, (size_t)21U, uint8_t *));
  ------------------
  |  |  195|   126k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   126k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   126k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5157|   126k|  int16_t_x2 v14_15 =
 5158|   126k|      libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5159|   126k|          Eurydice_slice_subslice3(bytes, (size_t)21U, (size_t)24U, uint8_t *));
  ------------------
  |  |  195|   126k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   126k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   126k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5160|   126k|  return (
 5161|   126k|      KRML_CLITERAL(libcrux_ml_kem_vector_portable_vector_type_PortableVector){
  ------------------
  |  |  154|   126k|#define KRML_CLITERAL(type) (type)
  ------------------
 5162|   126k|          .elements = {v0_1.fst, v0_1.snd, v2_3.fst, v2_3.snd, v4_5.fst,
 5163|   126k|                       v4_5.snd, v6_7.fst, v6_7.snd, v8_9.fst, v8_9.snd,
 5164|   126k|                       v10_11.fst, v10_11.snd, v12_13.fst, v12_13.snd,
 5165|   126k|                       v14_15.fst, v14_15.snd}});
 5166|   126k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_12_int:
 5127|  1.00M|    Eurydice_slice bytes) {
 5128|  1.00M|  int16_t byte0 = libcrux_secrets_int_as_i16_59(
 5129|  1.00M|      Eurydice_slice_index(bytes, (size_t)0U, uint8_t, uint8_t *));
  ------------------
  |  |  180|  1.00M|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5130|  1.00M|  int16_t byte1 = libcrux_secrets_int_as_i16_59(
 5131|  1.00M|      Eurydice_slice_index(bytes, (size_t)1U, uint8_t, uint8_t *));
  ------------------
  |  |  180|  1.00M|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5132|  1.00M|  int16_t byte2 = libcrux_secrets_int_as_i16_59(
 5133|  1.00M|      Eurydice_slice_index(bytes, (size_t)2U, uint8_t, uint8_t *));
  ------------------
  |  |  180|  1.00M|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5134|  1.00M|  int16_t r0 = (byte1 & (int16_t)15) << 8U | (byte0 & (int16_t)255);
 5135|  1.00M|  int16_t r1 = byte2 << 4U | (byte1 >> 4U & (int16_t)15);
 5136|  1.00M|  return (KRML_CLITERAL(int16_t_x2){.fst = r0, .snd = r1});
  ------------------
  |  |  154|  1.00M|#define KRML_CLITERAL(type) (type)
  ------------------
 5137|  1.00M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i16_59:
  535|  4.70M|static KRML_MUSTINLINE int16_t libcrux_secrets_int_as_i16_59(uint8_t self) {
  536|  4.70M|  return libcrux_secrets_int_public_integers_classify_27_39(
  537|  4.70M|      (int16_t)libcrux_secrets_int_public_integers_declassify_d8_90(self));
  538|  4.70M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_39:
  515|   151M|libcrux_secrets_int_public_integers_classify_27_39(int16_t self) {
  516|   151M|  return self;
  517|   151M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_90:
  528|  4.70M|libcrux_secrets_int_public_integers_declassify_d8_90(uint8_t self) {
  529|  4.70M|  return self;
  530|  4.70M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_classify_public_classify_ref_9b_90:
 1089|   189k|libcrux_secrets_int_classify_public_classify_ref_9b_90(Eurydice_slice self) {
 1090|   189k|  return self;
 1091|   189k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_decrypt_unpacked_42:
 6241|    657|    uint8_t *ciphertext, uint8_t ret[32U]) {
 6242|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d u_as_ntt[3U];
 6243|    657|  libcrux_ml_kem_ind_cpa_deserialize_then_decompress_u_6c(ciphertext, u_as_ntt);
 6244|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d v =
 6245|    657|      libcrux_ml_kem_serialize_deserialize_then_decompress_ring_element_v_89(
 6246|    657|          Eurydice_array_to_subslice_from((size_t)1088U, ciphertext,
  ------------------
  |  |  225|    657|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6247|    657|                                          (size_t)960U, uint8_t, size_t,
 6248|    657|                                          uint8_t[]));
 6249|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d message =
 6250|    657|      libcrux_ml_kem_matrix_compute_message_1b(&v, secret_key->secret_as_ntt,
 6251|    657|                                               u_as_ntt);
 6252|    657|  uint8_t ret0[32U];
 6253|    657|  libcrux_ml_kem_serialize_compress_then_serialize_message_ea(message, ret0);
 6254|    657|  memcpy(ret, ret0, (size_t)32U * sizeof(uint8_t));
 6255|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_deserialize_then_decompress_u_6c:
 5694|    657|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret[3U]) {
 5695|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d u_as_ntt[3U];
 5696|  2.62k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (5696:31): [True: 1.97k, False: 657]
  ------------------
 5697|       |    /* original Rust expression is not an lvalue in C */
 5698|  1.97k|    void *lvalue = (void *)0U;
 5699|  1.97k|    u_as_ntt[i] =
 5700|  1.97k|        libcrux_ml_kem_ind_cpa_deserialize_then_decompress_u_call_mut_35_6c(
 5701|  1.97k|            &lvalue, i);
 5702|  1.97k|  }
 5703|    657|  for (size_t i = (size_t)0U;
 5704|  2.62k|       i < Eurydice_slice_len(
  ------------------
  |  |  173|  2.62k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5704:8): [True: 1.97k, False: 657]
  ------------------
 5705|  2.62k|               Eurydice_array_to_slice((size_t)1088U, ciphertext, uint8_t),
 5706|  2.62k|               uint8_t) /
 5707|  2.62k|               (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT *
  ------------------
  |  |  447|  2.62k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 5708|  2.62k|                (size_t)10U / (size_t)8U);
 5709|  1.97k|       i++) {
 5710|  1.97k|    size_t i0 = i;
 5711|  1.97k|    Eurydice_slice u_bytes = Eurydice_array_to_subslice3(
  ------------------
  |  |  215|  1.97k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  1.97k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.97k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5712|  1.97k|        ciphertext,
 5713|  1.97k|        i0 * (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT *
 5714|  1.97k|              (size_t)10U / (size_t)8U),
 5715|  1.97k|        i0 * (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT *
 5716|  1.97k|              (size_t)10U / (size_t)8U) +
 5717|  1.97k|            LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT *
 5718|  1.97k|                (size_t)10U / (size_t)8U,
 5719|  1.97k|        uint8_t *);
 5720|  1.97k|    u_as_ntt[i0] =
 5721|  1.97k|        libcrux_ml_kem_serialize_deserialize_then_decompress_ring_element_u_0a(
 5722|  1.97k|            u_bytes);
 5723|  1.97k|    libcrux_ml_kem_ntt_ntt_vector_u_0a(&u_as_ntt[i0]);
 5724|  1.97k|  }
 5725|    657|  memcpy(
 5726|    657|      ret, u_as_ntt,
 5727|    657|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 5728|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_deserialize_then_decompress_u_call_mut_35_6c:
 5419|  1.97k|    void **_, size_t tupled_args) {
 5420|  1.97k|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 5421|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_then_decompress_ring_element_u_0a:
 5499|  1.97k|    Eurydice_slice serialized) {
 5500|  1.97k|  return libcrux_ml_kem_serialize_deserialize_then_decompress_10_ea(serialized);
 5501|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_then_decompress_10_ea:
 5472|  1.97k|    Eurydice_slice serialized) {
 5473|  1.97k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d re =
 5474|  1.97k|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 5475|  1.97k|  for (size_t i = (size_t)0U;
 5476|  33.5k|       i < Eurydice_slice_len(serialized, uint8_t) / (size_t)20U; i++) {
  ------------------
  |  |  173|  33.5k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5476:8): [True: 31.5k, False: 1.97k]
  ------------------
 5477|  31.5k|    size_t i0 = i;
 5478|  31.5k|    Eurydice_slice bytes =
 5479|  31.5k|        Eurydice_slice_subslice3(serialized, i0 * (size_t)20U,
  ------------------
  |  |  195|  31.5k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  31.5k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  31.5k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5480|  31.5k|                                 i0 * (size_t)20U + (size_t)20U, uint8_t *);
 5481|  31.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 5482|  31.5k|        libcrux_ml_kem_vector_portable_deserialize_10_b8(bytes);
 5483|  31.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5484|  31.5k|        libcrux_ml_kem_vector_portable_decompress_ciphertext_coefficient_b8_ef(
 5485|  31.5k|            coefficient);
 5486|  31.5k|    re.coefficients[i0] = uu____0;
 5487|  31.5k|  }
 5488|  1.97k|  return re;
 5489|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_10_b8:
 5024|  31.5k|libcrux_ml_kem_vector_portable_deserialize_10_b8(Eurydice_slice a) {
 5025|  31.5k|  return libcrux_ml_kem_vector_portable_deserialize_10(a);
 5026|  31.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_10:
 5014|  31.5k|libcrux_ml_kem_vector_portable_deserialize_10(Eurydice_slice a) {
 5015|  31.5k|  return libcrux_ml_kem_vector_portable_serialize_deserialize_10(
 5016|  31.5k|      libcrux_secrets_int_classify_public_classify_ref_9b_90(a));
 5017|  31.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_10:
 5000|  31.5k|libcrux_ml_kem_vector_portable_serialize_deserialize_10(Eurydice_slice bytes) {
 5001|  31.5k|  int16_t_x8 v0_7 = libcrux_ml_kem_vector_portable_serialize_deserialize_10_int(
 5002|  31.5k|      Eurydice_slice_subslice3(bytes, (size_t)0U, (size_t)10U, uint8_t *));
  ------------------
  |  |  195|  31.5k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  31.5k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  31.5k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5003|  31.5k|  int16_t_x8 v8_15 =
 5004|  31.5k|      libcrux_ml_kem_vector_portable_serialize_deserialize_10_int(
 5005|  31.5k|          Eurydice_slice_subslice3(bytes, (size_t)10U, (size_t)20U, uint8_t *));
  ------------------
  |  |  195|  31.5k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  31.5k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  31.5k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5006|  31.5k|  return (
 5007|  31.5k|      KRML_CLITERAL(libcrux_ml_kem_vector_portable_vector_type_PortableVector){
  ------------------
  |  |  154|  31.5k|#define KRML_CLITERAL(type) (type)
  ------------------
 5008|  31.5k|          .elements = {v0_7.fst, v0_7.snd, v0_7.thd, v0_7.f3, v0_7.f4, v0_7.f5,
 5009|  31.5k|                       v0_7.f6, v0_7.f7, v8_15.fst, v8_15.snd, v8_15.thd,
 5010|  31.5k|                       v8_15.f3, v8_15.f4, v8_15.f5, v8_15.f6, v8_15.f7}});
 5011|  31.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_10_int:
 4926|  63.0k|    Eurydice_slice bytes) {
 4927|  63.0k|  int16_t r0 = libcrux_secrets_int_as_i16_f5(
 4928|  63.0k|      (libcrux_secrets_int_as_i16_59(
 4929|  63.0k|           Eurydice_slice_index(bytes, (size_t)1U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4930|  63.0k|       (int16_t)3)
 4931|  63.0k|          << 8U |
 4932|  63.0k|      (libcrux_secrets_int_as_i16_59(
 4933|  63.0k|           Eurydice_slice_index(bytes, (size_t)0U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4934|  63.0k|       (int16_t)255));
 4935|  63.0k|  int16_t r1 = libcrux_secrets_int_as_i16_f5(
 4936|  63.0k|      (libcrux_secrets_int_as_i16_59(
 4937|  63.0k|           Eurydice_slice_index(bytes, (size_t)2U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4938|  63.0k|       (int16_t)15)
 4939|  63.0k|          << 6U |
 4940|  63.0k|      libcrux_secrets_int_as_i16_59(
 4941|  63.0k|          Eurydice_slice_index(bytes, (size_t)1U, uint8_t, uint8_t *)) >>
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4942|  63.0k|          2U);
 4943|  63.0k|  int16_t r2 = libcrux_secrets_int_as_i16_f5(
 4944|  63.0k|      (libcrux_secrets_int_as_i16_59(
 4945|  63.0k|           Eurydice_slice_index(bytes, (size_t)3U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4946|  63.0k|       (int16_t)63)
 4947|  63.0k|          << 4U |
 4948|  63.0k|      libcrux_secrets_int_as_i16_59(
 4949|  63.0k|          Eurydice_slice_index(bytes, (size_t)2U, uint8_t, uint8_t *)) >>
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4950|  63.0k|          4U);
 4951|  63.0k|  int16_t r3 = libcrux_secrets_int_as_i16_f5(
 4952|  63.0k|      libcrux_secrets_int_as_i16_59(
 4953|  63.0k|          Eurydice_slice_index(bytes, (size_t)4U, uint8_t, uint8_t *))
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4954|  63.0k|          << 2U |
 4955|  63.0k|      libcrux_secrets_int_as_i16_59(
 4956|  63.0k|          Eurydice_slice_index(bytes, (size_t)3U, uint8_t, uint8_t *)) >>
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4957|  63.0k|          6U);
 4958|  63.0k|  int16_t r4 = libcrux_secrets_int_as_i16_f5(
 4959|  63.0k|      (libcrux_secrets_int_as_i16_59(
 4960|  63.0k|           Eurydice_slice_index(bytes, (size_t)6U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4961|  63.0k|       (int16_t)3)
 4962|  63.0k|          << 8U |
 4963|  63.0k|      (libcrux_secrets_int_as_i16_59(
 4964|  63.0k|           Eurydice_slice_index(bytes, (size_t)5U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4965|  63.0k|       (int16_t)255));
 4966|  63.0k|  int16_t r5 = libcrux_secrets_int_as_i16_f5(
 4967|  63.0k|      (libcrux_secrets_int_as_i16_59(
 4968|  63.0k|           Eurydice_slice_index(bytes, (size_t)7U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4969|  63.0k|       (int16_t)15)
 4970|  63.0k|          << 6U |
 4971|  63.0k|      libcrux_secrets_int_as_i16_59(
 4972|  63.0k|          Eurydice_slice_index(bytes, (size_t)6U, uint8_t, uint8_t *)) >>
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4973|  63.0k|          2U);
 4974|  63.0k|  int16_t r6 = libcrux_secrets_int_as_i16_f5(
 4975|  63.0k|      (libcrux_secrets_int_as_i16_59(
 4976|  63.0k|           Eurydice_slice_index(bytes, (size_t)8U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4977|  63.0k|       (int16_t)63)
 4978|  63.0k|          << 4U |
 4979|  63.0k|      libcrux_secrets_int_as_i16_59(
 4980|  63.0k|          Eurydice_slice_index(bytes, (size_t)7U, uint8_t, uint8_t *)) >>
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4981|  63.0k|          4U);
 4982|  63.0k|  int16_t r7 = libcrux_secrets_int_as_i16_f5(
 4983|  63.0k|      libcrux_secrets_int_as_i16_59(
 4984|  63.0k|          Eurydice_slice_index(bytes, (size_t)9U, uint8_t, uint8_t *))
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4985|  63.0k|          << 2U |
 4986|  63.0k|      libcrux_secrets_int_as_i16_59(
 4987|  63.0k|          Eurydice_slice_index(bytes, (size_t)8U, uint8_t, uint8_t *)) >>
  ------------------
  |  |  180|  63.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4988|  63.0k|          6U);
 4989|  63.0k|  return (KRML_CLITERAL(int16_t_x8){.fst = r0,
  ------------------
  |  |  154|  63.0k|#define KRML_CLITERAL(type) (type)
  ------------------
 4990|  63.0k|                                    .snd = r1,
 4991|  63.0k|                                    .thd = r2,
 4992|  63.0k|                                    .f3 = r3,
 4993|  63.0k|                                    .f4 = r4,
 4994|  63.0k|                                    .f5 = r5,
 4995|  63.0k|                                    .f6 = r6,
 4996|  63.0k|                                    .f7 = r7});
 4997|  63.0k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i16_f5:
  711|  1.85M|static KRML_MUSTINLINE int16_t libcrux_secrets_int_as_i16_f5(int16_t self) {
  712|  1.85M|  return libcrux_secrets_int_public_integers_classify_27_39(
  713|  1.85M|      libcrux_secrets_int_public_integers_declassify_d8_39(self));
  714|  1.85M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_39:
  494|   155M|libcrux_secrets_int_public_integers_declassify_d8_39(int16_t self) {
  495|   155M|  return self;
  496|   155M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_decompress_ciphertext_coefficient_b8_ef:
 5459|  31.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 5460|  31.5k|  return libcrux_ml_kem_vector_portable_compress_decompress_ciphertext_coefficient_ef(
 5461|  31.5k|      a);
 5462|  31.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_decompress_ciphertext_coefficient_ef:
 5431|  31.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 5432|  31.5k|  for (size_t i = (size_t)0U;
 5433|   536k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   536k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (5433:8): [True: 504k, False: 31.5k]
  ------------------
 5434|   504k|    size_t i0 = i;
 5435|   504k|    int32_t decompressed =
 5436|   504k|        libcrux_secrets_int_as_i32_f5(a.elements[i0]) *
 5437|   504k|        libcrux_secrets_int_as_i32_f5(
 5438|   504k|            libcrux_secrets_int_public_integers_classify_27_39(
 5439|   504k|                LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS));
  ------------------
  |  | 3777|   504k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 5440|   504k|    decompressed = (decompressed << 1U) + ((int32_t)1 << (uint32_t)(int32_t)10);
 5441|   504k|    decompressed = decompressed >> (uint32_t)((int32_t)10 + (int32_t)1);
 5442|   504k|    a.elements[i0] = libcrux_secrets_int_as_i16_36(decompressed);
 5443|   504k|  }
 5444|  31.5k|  return a;
 5445|  31.5k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i32_f5:
  556|   145M|static KRML_MUSTINLINE int32_t libcrux_secrets_int_as_i32_f5(int16_t self) {
  557|   145M|  return libcrux_secrets_int_public_integers_classify_27_a8(
  558|   145M|      (int32_t)libcrux_secrets_int_public_integers_declassify_d8_39(self));
  559|   145M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_a8:
  549|   170M|libcrux_secrets_int_public_integers_classify_27_a8(int32_t self) {
  550|   170M|  return self;
  551|   170M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i16_36:
  577|   108M|static KRML_MUSTINLINE int16_t libcrux_secrets_int_as_i16_36(int32_t self) {
  578|   108M|  return libcrux_secrets_int_public_integers_classify_27_39(
  579|   108M|      (int16_t)libcrux_secrets_int_public_integers_declassify_d8_a8(self));
  580|   108M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_a8:
  570|   108M|libcrux_secrets_int_public_integers_declassify_d8_a8(int32_t self) {
  571|   108M|  return self;
  572|   108M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_vector_u_0a:
 5663|  1.97k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 5664|  1.97k|  size_t zeta_i = (size_t)0U;
 5665|  1.97k|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)7U,
 5666|  1.97k|                                            (size_t)3328U);
 5667|  1.97k|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)6U,
 5668|  1.97k|                                            (size_t)2U * (size_t)3328U);
 5669|  1.97k|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)5U,
 5670|  1.97k|                                            (size_t)3U * (size_t)3328U);
 5671|  1.97k|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)4U,
 5672|  1.97k|                                            (size_t)4U * (size_t)3328U);
 5673|  1.97k|  libcrux_ml_kem_ntt_ntt_at_layer_3_ea(&zeta_i, re, (size_t)5U * (size_t)3328U);
 5674|  1.97k|  libcrux_ml_kem_ntt_ntt_at_layer_2_ea(&zeta_i, re, (size_t)6U * (size_t)3328U);
 5675|  1.97k|  libcrux_ml_kem_ntt_ntt_at_layer_1_ea(&zeta_i, re, (size_t)7U * (size_t)3328U);
 5676|  1.97k|  libcrux_ml_kem_polynomial_poly_barrett_reduce_d6_ea(re);
 5677|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea:
 5538|  31.5k|    size_t layer, size_t _initial_coefficient_bound) {
 5539|  31.5k|  size_t step = (size_t)1U << (uint32_t)layer;
 5540|   171k|  for (size_t i0 = (size_t)0U; i0 < (size_t)128U >> (uint32_t)layer; i0++) {
  ------------------
  |  Branch (5540:32): [True: 139k, False: 31.5k]
  ------------------
 5541|   139k|    size_t round = i0;
 5542|   139k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5543|   139k|    size_t offset = round * step * (size_t)2U;
 5544|   139k|    size_t offset_vec = offset / (size_t)16U;
 5545|   139k|    size_t step_vec = step / (size_t)16U;
 5546|   392k|    for (size_t i = offset_vec; i < offset_vec + step_vec; i++) {
  ------------------
  |  Branch (5546:33): [True: 252k, False: 139k]
  ------------------
 5547|   252k|      size_t j = i;
 5548|   252k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2 uu____0 =
 5549|   252k|          libcrux_ml_kem_ntt_ntt_layer_int_vec_step_ea(
 5550|   252k|              re->coefficients[j], re->coefficients[j + step_vec],
 5551|   252k|              libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
 5552|   252k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector x = uu____0.fst;
 5553|   252k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector y = uu____0.snd;
 5554|   252k|      re->coefficients[j] = x;
 5555|   252k|      re->coefficients[j + step_vec] = y;
 5556|   252k|    }
 5557|   139k|  }
 5558|  31.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_layer_int_vec_step_ea:
 5519|   252k|        int16_t zeta_r) {
 5520|   252k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector t =
 5521|   252k|      libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(b,
 5522|   252k|                                                                        zeta_r);
 5523|   252k|  b = libcrux_ml_kem_vector_portable_sub_b8(a, &t);
 5524|   252k|  a = libcrux_ml_kem_vector_portable_add_b8(a, &t);
 5525|   252k|  return (KRML_CLITERAL(
  ------------------
  |  |  154|   252k|#define KRML_CLITERAL(type) (type)
  ------------------
 5526|   252k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2){.fst = a,
 5527|   252k|                                                                    .snd = b});
 5528|   252k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8:
 4077|   567k|    int16_t constant) {
 4078|   567k|  return libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_by_constant(
 4079|   567k|      vector, libcrux_secrets_int_public_integers_classify_27_39(constant));
 4080|   567k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_by_constant:
 4059|   567k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec, int16_t c) {
 4060|   567k|  for (size_t i = (size_t)0U;
 4061|  9.65M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  9.65M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (4061:8): [True: 9.08M, False: 567k]
  ------------------
 4062|  9.08M|    size_t i0 = i;
 4063|  9.08M|    vec.elements[i0] =
 4064|  9.08M|        libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer(
 4065|  9.08M|            vec.elements[i0], c);
 4066|  9.08M|  }
 4067|   567k|  return vec;
 4068|   567k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer:
 4050|  15.1M|    int16_t fe, int16_t fer) {
 4051|  15.1M|  int32_t product =
 4052|  15.1M|      libcrux_secrets_int_as_i32_f5(fe) * libcrux_secrets_int_as_i32_f5(fer);
 4053|  15.1M|  return libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(
 4054|  15.1M|      product);
 4055|  15.1M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element:
 4017|  24.2M|    int32_t value) {
 4018|  24.2M|  int32_t k =
 4019|  24.2M|      libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_as_i16_36(value)) *
 4020|  24.2M|      libcrux_secrets_int_as_i32_b8(
 4021|  24.2M|          libcrux_secrets_int_public_integers_classify_27_df(
 4022|  24.2M|              LIBCRUX_ML_KEM_VECTOR_TRAITS_INVERSE_OF_MODULUS_MOD_MONTGOMERY_R));
  ------------------
  |  | 3780|  24.2M|  (62209U)
  ------------------
 4023|  24.2M|  int32_t k_times_modulus =
 4024|  24.2M|      libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_as_i16_36(k)) *
 4025|  24.2M|      libcrux_secrets_int_as_i32_f5(
 4026|  24.2M|          libcrux_secrets_int_public_integers_classify_27_39(
 4027|  24.2M|              LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS));
  ------------------
  |  | 3777|  24.2M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 4028|  24.2M|  int16_t c = libcrux_secrets_int_as_i16_36(
 4029|  24.2M|      k_times_modulus >>
 4030|  24.2M|      (uint32_t)LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT);
  ------------------
  |  | 3997|  24.2M|#define LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT (16U)
  ------------------
 4031|  24.2M|  int16_t value_high = libcrux_secrets_int_as_i16_36(
 4032|  24.2M|      value >>
 4033|  24.2M|      (uint32_t)LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT);
  ------------------
  |  | 3997|  24.2M|#define LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT (16U)
  ------------------
 4034|  24.2M|  return value_high - c;
 4035|  24.2M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i32_b8:
  598|  24.2M|static KRML_MUSTINLINE int32_t libcrux_secrets_int_as_i32_b8(uint32_t self) {
  599|  24.2M|  return libcrux_secrets_int_public_integers_classify_27_a8(
  600|  24.2M|      (int32_t)libcrux_secrets_int_public_integers_declassify_d8_df(self));
  601|  24.2M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_df:
  591|  25.5M|libcrux_secrets_int_public_integers_declassify_d8_df(uint32_t self) {
  592|  25.5M|  return self;
  593|  25.5M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_df:
  675|  25.5M|libcrux_secrets_int_public_integers_classify_27_df(uint32_t self) {
  676|  25.5M|  return self;
  677|  25.5M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_sub_b8:
 3884|   515k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector *rhs) {
 3885|   515k|  return libcrux_ml_kem_vector_portable_arithmetic_sub(lhs, rhs);
 3886|   515k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_sub:
 3867|   536k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector *rhs) {
 3868|   536k|  for (size_t i = (size_t)0U;
 3869|  9.11M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  9.11M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3869:8): [True: 8.57M, False: 536k]
  ------------------
 3870|  8.57M|    size_t i0 = i;
 3871|  8.57M|    size_t uu____0 = i0;
 3872|  8.57M|    lhs.elements[uu____0] = lhs.elements[uu____0] - rhs->elements[i0];
 3873|  8.57M|  }
 3874|   536k|  return lhs;
 3875|   536k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_add_b8:
 3860|  1.01M|    libcrux_ml_kem_vector_portable_vector_type_PortableVector *rhs) {
 3861|  1.01M|  return libcrux_ml_kem_vector_portable_arithmetic_add(lhs, rhs);
 3862|  1.01M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_add:
 3843|  1.20M|    libcrux_ml_kem_vector_portable_vector_type_PortableVector *rhs) {
 3844|  1.20M|  for (size_t i = (size_t)0U;
 3845|  20.5M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  20.5M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3845:8): [True: 19.3M, False: 1.20M]
  ------------------
 3846|  19.3M|    size_t i0 = i;
 3847|  19.3M|    size_t uu____0 = i0;
 3848|  19.3M|    lhs.elements[uu____0] = lhs.elements[uu____0] + rhs->elements[i0];
 3849|  19.3M|  }
 3850|  1.20M|  return lhs;
 3851|  1.20M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_zeta:
 3766|  3.72M|static KRML_MUSTINLINE int16_t libcrux_ml_kem_polynomial_zeta(size_t i) {
 3767|  3.72M|  return libcrux_ml_kem_polynomial_ZETAS_TIMES_MONTGOMERY_R[i];
 3768|  3.72M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_3_ea:
 5568|  9.85k|    size_t _initial_coefficient_bound) {
 5569|   167k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5569:31): [True: 157k, False: 9.85k]
  ------------------
 5570|   157k|    size_t round = i;
 5571|   157k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5572|   157k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5573|   157k|        libcrux_ml_kem_vector_portable_ntt_layer_3_step_b8(
 5574|   157k|            re->coefficients[round],
 5575|   157k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
 5576|   157k|    re->coefficients[round] = uu____0;
 5577|   157k|  }
 5578|  9.85k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_layer_3_step_b8:
 4344|   157k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a, int16_t zeta) {
 4345|   157k|  return libcrux_ml_kem_vector_portable_ntt_ntt_layer_3_step(a, zeta);
 4346|   157k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_layer_3_step:
 4318|   157k|    int16_t zeta) {
 4319|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)0U,
 4320|   157k|                                              (size_t)8U);
 4321|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)1U,
 4322|   157k|                                              (size_t)9U);
 4323|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)2U,
 4324|   157k|                                              (size_t)10U);
 4325|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)3U,
 4326|   157k|                                              (size_t)11U);
 4327|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)4U,
 4328|   157k|                                              (size_t)12U);
 4329|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)5U,
 4330|   157k|                                              (size_t)13U);
 4331|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)6U,
 4332|   157k|                                              (size_t)14U);
 4333|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)7U,
 4334|   157k|                                              (size_t)15U);
 4335|   157k|  return vec;
 4336|   157k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_step:
 4235|  3.78M|    int16_t zeta, size_t i, size_t j) {
 4236|  3.78M|  int16_t t =
 4237|  3.78M|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer(
 4238|  3.78M|          vec->elements[j],
 4239|  3.78M|          libcrux_secrets_int_public_integers_classify_27_39(zeta));
 4240|  3.78M|  int16_t a_minus_t = vec->elements[i] - t;
 4241|  3.78M|  int16_t a_plus_t = vec->elements[i] + t;
 4242|  3.78M|  vec->elements[j] = a_minus_t;
 4243|  3.78M|  vec->elements[i] = a_plus_t;
 4244|  3.78M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_2_ea:
 5588|  9.85k|    size_t _initial_coefficient_bound) {
 5589|   167k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5589:31): [True: 157k, False: 9.85k]
  ------------------
 5590|   157k|    size_t round = i;
 5591|   157k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5592|   157k|    re->coefficients[round] =
 5593|   157k|        libcrux_ml_kem_vector_portable_ntt_layer_2_step_b8(
 5594|   157k|            re->coefficients[round], libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
 5595|   157k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)1U));
 5596|   157k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5597|   157k|  }
 5598|  9.85k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_layer_2_step_b8:
 4311|   157k|    int16_t zeta1) {
 4312|   157k|  return libcrux_ml_kem_vector_portable_ntt_ntt_layer_2_step(a, zeta0, zeta1);
 4313|   157k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_layer_2_step:
 4284|   157k|    int16_t zeta0, int16_t zeta1) {
 4285|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)0U,
 4286|   157k|                                              (size_t)4U);
 4287|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)1U,
 4288|   157k|                                              (size_t)5U);
 4289|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)2U,
 4290|   157k|                                              (size_t)6U);
 4291|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)3U,
 4292|   157k|                                              (size_t)7U);
 4293|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)8U,
 4294|   157k|                                              (size_t)12U);
 4295|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)9U,
 4296|   157k|                                              (size_t)13U);
 4297|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)10U,
 4298|   157k|                                              (size_t)14U);
 4299|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)11U,
 4300|   157k|                                              (size_t)15U);
 4301|   157k|  return vec;
 4302|   157k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_1_ea:
 5608|  9.85k|    size_t _initial_coefficient_bound) {
 5609|   167k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5609:31): [True: 157k, False: 9.85k]
  ------------------
 5610|   157k|    size_t round = i;
 5611|   157k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5612|   157k|    re->coefficients[round] =
 5613|   157k|        libcrux_ml_kem_vector_portable_ntt_layer_1_step_b8(
 5614|   157k|            re->coefficients[round], libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
 5615|   157k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)1U),
 5616|   157k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)2U),
 5617|   157k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)3U));
 5618|   157k|    zeta_i[0U] = zeta_i[0U] + (size_t)3U;
 5619|   157k|  }
 5620|  9.85k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_layer_1_step_b8:
 4276|   157k|    int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4277|   157k|  return libcrux_ml_kem_vector_portable_ntt_ntt_layer_1_step(a, zeta0, zeta1,
 4278|   157k|                                                             zeta2, zeta3);
 4279|   157k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_layer_1_step:
 4249|   157k|    int16_t zeta0, int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4250|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)0U,
 4251|   157k|                                              (size_t)2U);
 4252|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)1U,
 4253|   157k|                                              (size_t)3U);
 4254|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)4U,
 4255|   157k|                                              (size_t)6U);
 4256|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)5U,
 4257|   157k|                                              (size_t)7U);
 4258|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta2, (size_t)8U,
 4259|   157k|                                              (size_t)10U);
 4260|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta2, (size_t)9U,
 4261|   157k|                                              (size_t)11U);
 4262|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta3, (size_t)12U,
 4263|   157k|                                              (size_t)14U);
 4264|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta3, (size_t)13U,
 4265|   157k|                                              (size_t)15U);
 4266|   157k|  return vec;
 4267|   157k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_poly_barrett_reduce_d6_ea:
 5652|  15.7k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *self) {
 5653|  15.7k|  libcrux_ml_kem_polynomial_poly_barrett_reduce_ea(self);
 5654|  15.7k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_poly_barrett_reduce_ea:
 5629|  15.7k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *myself) {
 5630|  15.7k|  for (size_t i = (size_t)0U;
 5631|   268k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|   268k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (5631:8): [True: 252k, False: 15.7k]
  ------------------
 5632|   252k|    size_t i0 = i;
 5633|   252k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5634|   252k|        libcrux_ml_kem_vector_portable_barrett_reduce_b8(
 5635|   252k|            myself->coefficients[i0]);
 5636|   252k|    myself->coefficients[i0] = uu____0;
 5637|   252k|  }
 5638|  15.7k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_barrett_reduce_b8:
 3993|   567k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vector) {
 3994|   567k|  return libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce(vector);
 3995|   567k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce:
 3975|   567k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec) {
 3976|   567k|  for (size_t i = (size_t)0U;
 3977|  9.65M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  9.65M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3977:8): [True: 9.08M, False: 567k]
  ------------------
 3978|  9.08M|    size_t i0 = i;
 3979|  9.08M|    int16_t vi =
 3980|  9.08M|        libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce_element(
 3981|  9.08M|            vec.elements[i0]);
 3982|  9.08M|    vec.elements[i0] = vi;
 3983|  9.08M|  }
 3984|   567k|  return vec;
 3985|   567k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce_element:
 3964|  11.3M|    int16_t value) {
 3965|  11.3M|  int32_t t = libcrux_secrets_int_as_i32_f5(value) *
 3966|  11.3M|                  LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_BARRETT_MULTIPLIER +
  ------------------
  |  | 3940|  11.3M|  ((int32_t)20159)
  ------------------
 3967|  11.3M|              (LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_R >> 1U);
  ------------------
  |  | 3945|  11.3M|  ((int32_t)1 << (uint32_t)LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT)
  |  |  ------------------
  |  |  |  | 3942|  11.3M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT ((int32_t)26)
  |  |  ------------------
  ------------------
 3968|  11.3M|  int16_t quotient = libcrux_secrets_int_as_i16_36(
 3969|  11.3M|      t >> (uint32_t)LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT);
  ------------------
  |  | 3942|  11.3M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT ((int32_t)26)
  ------------------
 3970|  11.3M|  return value - quotient * LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS;
  ------------------
  |  | 3777|  11.3M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 3971|  11.3M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_then_decompress_ring_element_v_89:
 5806|    657|    Eurydice_slice serialized) {
 5807|    657|  return libcrux_ml_kem_serialize_deserialize_then_decompress_4_ea(serialized);
 5808|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_then_decompress_4_ea:
 5779|    657|    Eurydice_slice serialized) {
 5780|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d re =
 5781|    657|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 5782|    657|  for (size_t i = (size_t)0U;
 5783|  11.1k|       i < Eurydice_slice_len(serialized, uint8_t) / (size_t)8U; i++) {
  ------------------
  |  |  173|  11.1k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5783:8): [True: 10.5k, False: 657]
  ------------------
 5784|  10.5k|    size_t i0 = i;
 5785|  10.5k|    Eurydice_slice bytes = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  10.5k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  10.5k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  10.5k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5786|  10.5k|        serialized, i0 * (size_t)8U, i0 * (size_t)8U + (size_t)8U, uint8_t *);
 5787|  10.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 5788|  10.5k|        libcrux_ml_kem_vector_portable_deserialize_4_b8(bytes);
 5789|  10.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5790|  10.5k|        libcrux_ml_kem_vector_portable_decompress_ciphertext_coefficient_b8_d1(
 5791|  10.5k|            coefficient);
 5792|  10.5k|    re.coefficients[i0] = uu____0;
 5793|  10.5k|  }
 5794|    657|  return re;
 5795|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_4_b8:
 4824|  10.5k|libcrux_ml_kem_vector_portable_deserialize_4_b8(Eurydice_slice a) {
 4825|  10.5k|  return libcrux_ml_kem_vector_portable_deserialize_4(a);
 4826|  10.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_4:
 4814|  10.5k|libcrux_ml_kem_vector_portable_deserialize_4(Eurydice_slice a) {
 4815|  10.5k|  return libcrux_ml_kem_vector_portable_serialize_deserialize_4(
 4816|  10.5k|      libcrux_secrets_int_classify_public_classify_ref_9b_90(a));
 4817|  10.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_4:
 4801|  10.5k|libcrux_ml_kem_vector_portable_serialize_deserialize_4(Eurydice_slice bytes) {
 4802|  10.5k|  int16_t_x8 v0_7 = libcrux_ml_kem_vector_portable_serialize_deserialize_4_int(
 4803|  10.5k|      Eurydice_slice_subslice3(bytes, (size_t)0U, (size_t)4U, uint8_t *));
  ------------------
  |  |  195|  10.5k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  10.5k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  10.5k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4804|  10.5k|  int16_t_x8 v8_15 = libcrux_ml_kem_vector_portable_serialize_deserialize_4_int(
 4805|  10.5k|      Eurydice_slice_subslice3(bytes, (size_t)4U, (size_t)8U, uint8_t *));
  ------------------
  |  |  195|  10.5k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  10.5k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  10.5k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4806|  10.5k|  return (
 4807|  10.5k|      KRML_CLITERAL(libcrux_ml_kem_vector_portable_vector_type_PortableVector){
  ------------------
  |  |  154|  10.5k|#define KRML_CLITERAL(type) (type)
  ------------------
 4808|  10.5k|          .elements = {v0_7.fst, v0_7.snd, v0_7.thd, v0_7.f3, v0_7.f4, v0_7.f5,
 4809|  10.5k|                       v0_7.f6, v0_7.f7, v8_15.fst, v8_15.snd, v8_15.thd,
 4810|  10.5k|                       v8_15.f3, v8_15.f4, v8_15.f5, v8_15.f6, v8_15.f7}});
 4811|  10.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_4_int:
 4761|  21.0k|    Eurydice_slice bytes) {
 4762|  21.0k|  int16_t v0 = libcrux_secrets_int_as_i16_59(
 4763|  21.0k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)0U, uint8_t, uint8_t *) &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4764|  21.0k|      15U);
 4765|  21.0k|  int16_t v1 = libcrux_secrets_int_as_i16_59(
 4766|  21.0k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)0U, uint8_t, uint8_t *) >>
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4767|  21.0k|          4U &
 4768|  21.0k|      15U);
 4769|  21.0k|  int16_t v2 = libcrux_secrets_int_as_i16_59(
 4770|  21.0k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)1U, uint8_t, uint8_t *) &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4771|  21.0k|      15U);
 4772|  21.0k|  int16_t v3 = libcrux_secrets_int_as_i16_59(
 4773|  21.0k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)1U, uint8_t, uint8_t *) >>
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4774|  21.0k|          4U &
 4775|  21.0k|      15U);
 4776|  21.0k|  int16_t v4 = libcrux_secrets_int_as_i16_59(
 4777|  21.0k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)2U, uint8_t, uint8_t *) &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4778|  21.0k|      15U);
 4779|  21.0k|  int16_t v5 = libcrux_secrets_int_as_i16_59(
 4780|  21.0k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)2U, uint8_t, uint8_t *) >>
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4781|  21.0k|          4U &
 4782|  21.0k|      15U);
 4783|  21.0k|  int16_t v6 = libcrux_secrets_int_as_i16_59(
 4784|  21.0k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)3U, uint8_t, uint8_t *) &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4785|  21.0k|      15U);
 4786|  21.0k|  int16_t v7 = libcrux_secrets_int_as_i16_59(
 4787|  21.0k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)3U, uint8_t, uint8_t *) >>
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4788|  21.0k|          4U &
 4789|  21.0k|      15U);
 4790|  21.0k|  return (KRML_CLITERAL(int16_t_x8){.fst = v0,
  ------------------
  |  |  154|  21.0k|#define KRML_CLITERAL(type) (type)
  ------------------
 4791|  21.0k|                                    .snd = v1,
 4792|  21.0k|                                    .thd = v2,
 4793|  21.0k|                                    .f3 = v3,
 4794|  21.0k|                                    .f4 = v4,
 4795|  21.0k|                                    .f5 = v5,
 4796|  21.0k|                                    .f6 = v6,
 4797|  21.0k|                                    .f7 = v7});
 4798|  21.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_decompress_ciphertext_coefficient_b8_d1:
 5766|  10.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 5767|  10.5k|  return libcrux_ml_kem_vector_portable_compress_decompress_ciphertext_coefficient_d1(
 5768|  10.5k|      a);
 5769|  10.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_decompress_ciphertext_coefficient_d1:
 5738|  10.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 5739|  10.5k|  for (size_t i = (size_t)0U;
 5740|   178k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   178k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (5740:8): [True: 168k, False: 10.5k]
  ------------------
 5741|   168k|    size_t i0 = i;
 5742|   168k|    int32_t decompressed =
 5743|   168k|        libcrux_secrets_int_as_i32_f5(a.elements[i0]) *
 5744|   168k|        libcrux_secrets_int_as_i32_f5(
 5745|   168k|            libcrux_secrets_int_public_integers_classify_27_39(
 5746|   168k|                LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS));
  ------------------
  |  | 3777|   168k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 5747|   168k|    decompressed = (decompressed << 1U) + ((int32_t)1 << (uint32_t)(int32_t)4);
 5748|   168k|    decompressed = decompressed >> (uint32_t)((int32_t)4 + (int32_t)1);
 5749|   168k|    a.elements[i0] = libcrux_secrets_int_as_i16_36(decompressed);
 5750|   168k|  }
 5751|  10.5k|  return a;
 5752|  10.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_compute_message_1b:
 6150|    657|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *u_as_ntt) {
 6151|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d result =
 6152|    657|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 6153|  2.62k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6153:31): [True: 1.97k, False: 657]
  ------------------
 6154|  1.97k|    size_t i0 = i;
 6155|  1.97k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d product =
 6156|  1.97k|        libcrux_ml_kem_polynomial_ntt_multiply_d6_ea(&secret_as_ntt[i0],
 6157|  1.97k|                                                     &u_as_ntt[i0]);
 6158|  1.97k|    libcrux_ml_kem_polynomial_add_to_ring_element_d6_1b(&result, &product);
 6159|  1.97k|  }
 6160|    657|  libcrux_ml_kem_invert_ntt_invert_ntt_montgomery_1b(&result);
 6161|    657|  return libcrux_ml_kem_polynomial_subtract_reduce_d6_ea(v, result);
 6162|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_ntt_multiply_d6_ea:
 5901|  23.6k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *rhs) {
 5902|  23.6k|  return libcrux_ml_kem_polynomial_ntt_multiply_ea(self, rhs);
 5903|  23.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_ntt_multiply_ea:
 5866|  23.6k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *rhs) {
 5867|  23.6k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d out =
 5868|  23.6k|      libcrux_ml_kem_polynomial_ZERO_ea();
 5869|  23.6k|  for (size_t i = (size_t)0U;
 5870|   402k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|   402k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (5870:8): [True: 378k, False: 23.6k]
  ------------------
 5871|   378k|    size_t i0 = i;
 5872|   378k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5873|   378k|        libcrux_ml_kem_vector_portable_ntt_multiply_b8(
 5874|   378k|            &myself->coefficients[i0], &rhs->coefficients[i0],
 5875|   378k|            libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0),
 5876|   378k|            libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0 +
 5877|   378k|                                           (size_t)1U),
 5878|   378k|            libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0 +
 5879|   378k|                                           (size_t)2U),
 5880|   378k|            libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0 +
 5881|   378k|                                           (size_t)3U));
 5882|   378k|    out.coefficients[i0] = uu____0;
 5883|   378k|  }
 5884|  23.6k|  return out;
 5885|  23.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_ZERO_ea:
 5817|  54.5k|libcrux_ml_kem_polynomial_ZERO_ea(void) {
 5818|  54.5k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d lit;
 5819|  54.5k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector
 5820|  54.5k|      repeat_expression[16U];
 5821|   927k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5821:31): [True: 872k, False: 54.5k]
  ------------------
 5822|   872k|    repeat_expression[i] = libcrux_ml_kem_vector_portable_ZERO_b8();
 5823|   872k|  }
 5824|  54.5k|  memcpy(lit.coefficients, repeat_expression,
 5825|  54.5k|         (size_t)16U *
 5826|  54.5k|             sizeof(libcrux_ml_kem_vector_portable_vector_type_PortableVector));
 5827|  54.5k|  return lit;
 5828|  54.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_multiply_b8:
 4567|   378k|    int16_t zeta0, int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4568|   378k|  return libcrux_ml_kem_vector_portable_ntt_ntt_multiply(lhs, rhs, zeta0, zeta1,
 4569|   378k|                                                         zeta2, zeta3);
 4570|   378k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_multiply:
 4525|   378k|    int16_t zeta0, int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4526|   378k|  int16_t nzeta0 = -zeta0;
 4527|   378k|  int16_t nzeta1 = -zeta1;
 4528|   378k|  int16_t nzeta2 = -zeta2;
 4529|   378k|  int16_t nzeta3 = -zeta3;
 4530|   378k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector out =
 4531|   378k|      libcrux_ml_kem_vector_portable_vector_type_zero();
 4532|   378k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4533|   378k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(zeta0),
 4534|   378k|      (size_t)0U, &out);
 4535|   378k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4536|   378k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(nzeta0),
 4537|   378k|      (size_t)1U, &out);
 4538|   378k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4539|   378k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(zeta1),
 4540|   378k|      (size_t)2U, &out);
 4541|   378k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4542|   378k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(nzeta1),
 4543|   378k|      (size_t)3U, &out);
 4544|   378k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4545|   378k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(zeta2),
 4546|   378k|      (size_t)4U, &out);
 4547|   378k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4548|   378k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(nzeta2),
 4549|   378k|      (size_t)5U, &out);
 4550|   378k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4551|   378k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(zeta3),
 4552|   378k|      (size_t)6U, &out);
 4553|   378k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4554|   378k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(nzeta3),
 4555|   378k|      (size_t)7U, &out);
 4556|   378k|  return out;
 4557|   378k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials:
 4491|  3.02M|    size_t i, libcrux_ml_kem_vector_portable_vector_type_PortableVector *out) {
 4492|  3.02M|  int16_t ai = a->elements[(size_t)2U * i];
 4493|  3.02M|  int16_t bi = b->elements[(size_t)2U * i];
 4494|  3.02M|  int16_t aj = a->elements[(size_t)2U * i + (size_t)1U];
 4495|  3.02M|  int16_t bj = b->elements[(size_t)2U * i + (size_t)1U];
 4496|  3.02M|  int32_t ai_bi =
 4497|  3.02M|      libcrux_secrets_int_as_i32_f5(ai) * libcrux_secrets_int_as_i32_f5(bi);
 4498|  3.02M|  int32_t aj_bj_ =
 4499|  3.02M|      libcrux_secrets_int_as_i32_f5(aj) * libcrux_secrets_int_as_i32_f5(bj);
 4500|  3.02M|  int16_t aj_bj =
 4501|  3.02M|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(
 4502|  3.02M|          aj_bj_);
 4503|  3.02M|  int32_t aj_bj_zeta = libcrux_secrets_int_as_i32_f5(aj_bj) *
 4504|  3.02M|                       libcrux_secrets_int_as_i32_f5(zeta);
 4505|  3.02M|  int32_t ai_bi_aj_bj = ai_bi + aj_bj_zeta;
 4506|  3.02M|  int16_t o0 =
 4507|  3.02M|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(
 4508|  3.02M|          ai_bi_aj_bj);
 4509|  3.02M|  int32_t ai_bj =
 4510|  3.02M|      libcrux_secrets_int_as_i32_f5(ai) * libcrux_secrets_int_as_i32_f5(bj);
 4511|  3.02M|  int32_t aj_bi =
 4512|  3.02M|      libcrux_secrets_int_as_i32_f5(aj) * libcrux_secrets_int_as_i32_f5(bi);
 4513|  3.02M|  int32_t ai_bj_aj_bi = ai_bj + aj_bi;
 4514|  3.02M|  int16_t o1 =
 4515|  3.02M|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(
 4516|  3.02M|          ai_bj_aj_bi);
 4517|  3.02M|  out->elements[(size_t)2U * i] = o0;
 4518|  3.02M|  out->elements[(size_t)2U * i + (size_t)1U] = o1;
 4519|  3.02M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_to_ring_element_d6_1b:
 5946|  23.6k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *rhs) {
 5947|  23.6k|  libcrux_ml_kem_polynomial_add_to_ring_element_1b(self, rhs);
 5948|  23.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_to_ring_element_1b:
 5917|  23.6k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *rhs) {
 5918|  23.6k|  for (size_t i = (size_t)0U;
 5919|   402k|       i < Eurydice_slice_len(
  ------------------
  |  |  173|   402k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5919:8): [True: 378k, False: 23.6k]
  ------------------
 5920|  23.6k|               Eurydice_array_to_slice(
 5921|  23.6k|                   (size_t)16U, myself->coefficients,
 5922|  23.6k|                   libcrux_ml_kem_vector_portable_vector_type_PortableVector),
 5923|  23.6k|               libcrux_ml_kem_vector_portable_vector_type_PortableVector);
 5924|   378k|       i++) {
 5925|   378k|    size_t i0 = i;
 5926|   378k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5927|   378k|        libcrux_ml_kem_vector_portable_add_b8(myself->coefficients[i0],
 5928|   378k|                                              &rhs->coefficients[i0]);
 5929|   378k|    myself->coefficients[i0] = uu____0;
 5930|   378k|  }
 5931|  23.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_invert_ntt_invert_ntt_montgomery_1b:
 6072|  5.91k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 6073|  5.91k|  size_t zeta_i =
 6074|  5.91k|      LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT / (size_t)2U;
  ------------------
  |  |  447|  5.91k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6075|  5.91k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_1_ea(&zeta_i, re);
 6076|  5.91k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_2_ea(&zeta_i, re);
 6077|  5.91k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_3_ea(&zeta_i, re);
 6078|  5.91k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_4_plus_ea(&zeta_i, re,
 6079|  5.91k|                                                          (size_t)4U);
 6080|  5.91k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_4_plus_ea(&zeta_i, re,
 6081|  5.91k|                                                          (size_t)5U);
 6082|  5.91k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_4_plus_ea(&zeta_i, re,
 6083|  5.91k|                                                          (size_t)6U);
 6084|  5.91k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_4_plus_ea(&zeta_i, re,
 6085|  5.91k|                                                          (size_t)7U);
 6086|  5.91k|  libcrux_ml_kem_polynomial_poly_barrett_reduce_d6_ea(re);
 6087|  5.91k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_1_ea:
 5957|  5.91k|    size_t *zeta_i, libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 5958|   100k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5958:31): [True: 94.6k, False: 5.91k]
  ------------------
 5959|  94.6k|    size_t round = i;
 5960|  94.6k|    zeta_i[0U] = zeta_i[0U] - (size_t)1U;
 5961|  94.6k|    re->coefficients[round] =
 5962|  94.6k|        libcrux_ml_kem_vector_portable_inv_ntt_layer_1_step_b8(
 5963|  94.6k|            re->coefficients[round], libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
 5964|  94.6k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] - (size_t)1U),
 5965|  94.6k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] - (size_t)2U),
 5966|  94.6k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] - (size_t)3U));
 5967|  94.6k|    zeta_i[0U] = zeta_i[0U] - (size_t)3U;
 5968|  94.6k|  }
 5969|  5.91k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_inv_ntt_layer_1_step_b8:
 4392|  94.6k|    int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4393|  94.6k|  return libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_1_step(
 4394|  94.6k|      a, zeta0, zeta1, zeta2, zeta3);
 4395|  94.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_1_step:
 4365|  94.6k|    int16_t zeta0, int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4366|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)0U,
 4367|  94.6k|                                                  (size_t)2U);
 4368|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)1U,
 4369|  94.6k|                                                  (size_t)3U);
 4370|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)4U,
 4371|  94.6k|                                                  (size_t)6U);
 4372|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)5U,
 4373|  94.6k|                                                  (size_t)7U);
 4374|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta2, (size_t)8U,
 4375|  94.6k|                                                  (size_t)10U);
 4376|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta2, (size_t)9U,
 4377|  94.6k|                                                  (size_t)11U);
 4378|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta3, (size_t)12U,
 4379|  94.6k|                                                  (size_t)14U);
 4380|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta3, (size_t)13U,
 4381|  94.6k|                                                  (size_t)15U);
 4382|  94.6k|  return vec;
 4383|  94.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_inv_ntt_step:
 4350|  2.27M|    int16_t zeta, size_t i, size_t j) {
 4351|  2.27M|  int16_t a_minus_b = vec->elements[j] - vec->elements[i];
 4352|  2.27M|  int16_t a_plus_b = vec->elements[j] + vec->elements[i];
 4353|  2.27M|  int16_t o0 = libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce_element(
 4354|  2.27M|      a_plus_b);
 4355|  2.27M|  int16_t o1 =
 4356|  2.27M|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer(
 4357|  2.27M|          a_minus_b, libcrux_secrets_int_public_integers_classify_27_39(zeta));
 4358|  2.27M|  vec->elements[i] = o0;
 4359|  2.27M|  vec->elements[j] = o1;
 4360|  2.27M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_2_ea:
 5978|  5.91k|    size_t *zeta_i, libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 5979|   100k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5979:31): [True: 94.6k, False: 5.91k]
  ------------------
 5980|  94.6k|    size_t round = i;
 5981|  94.6k|    zeta_i[0U] = zeta_i[0U] - (size_t)1U;
 5982|  94.6k|    re->coefficients[round] =
 5983|  94.6k|        libcrux_ml_kem_vector_portable_inv_ntt_layer_2_step_b8(
 5984|  94.6k|            re->coefficients[round], libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
 5985|  94.6k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] - (size_t)1U));
 5986|  94.6k|    zeta_i[0U] = zeta_i[0U] - (size_t)1U;
 5987|  94.6k|  }
 5988|  5.91k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_inv_ntt_layer_2_step_b8:
 4427|  94.6k|    int16_t zeta1) {
 4428|  94.6k|  return libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_2_step(a, zeta0,
 4429|  94.6k|                                                                 zeta1);
 4430|  94.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_2_step:
 4400|  94.6k|    int16_t zeta0, int16_t zeta1) {
 4401|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)0U,
 4402|  94.6k|                                                  (size_t)4U);
 4403|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)1U,
 4404|  94.6k|                                                  (size_t)5U);
 4405|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)2U,
 4406|  94.6k|                                                  (size_t)6U);
 4407|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)3U,
 4408|  94.6k|                                                  (size_t)7U);
 4409|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)8U,
 4410|  94.6k|                                                  (size_t)12U);
 4411|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)9U,
 4412|  94.6k|                                                  (size_t)13U);
 4413|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)10U,
 4414|  94.6k|                                                  (size_t)14U);
 4415|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)11U,
 4416|  94.6k|                                                  (size_t)15U);
 4417|  94.6k|  return vec;
 4418|  94.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_3_ea:
 5997|  5.91k|    size_t *zeta_i, libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 5998|   100k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5998:31): [True: 94.6k, False: 5.91k]
  ------------------
 5999|  94.6k|    size_t round = i;
 6000|  94.6k|    zeta_i[0U] = zeta_i[0U] - (size_t)1U;
 6001|  94.6k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 6002|  94.6k|        libcrux_ml_kem_vector_portable_inv_ntt_layer_3_step_b8(
 6003|  94.6k|            re->coefficients[round],
 6004|  94.6k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
 6005|  94.6k|    re->coefficients[round] = uu____0;
 6006|  94.6k|  }
 6007|  5.91k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_inv_ntt_layer_3_step_b8:
 4461|  94.6k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a, int16_t zeta) {
 4462|  94.6k|  return libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_3_step(a, zeta);
 4463|  94.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_3_step:
 4435|  94.6k|    int16_t zeta) {
 4436|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)0U,
 4437|  94.6k|                                                  (size_t)8U);
 4438|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)1U,
 4439|  94.6k|                                                  (size_t)9U);
 4440|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)2U,
 4441|  94.6k|                                                  (size_t)10U);
 4442|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)3U,
 4443|  94.6k|                                                  (size_t)11U);
 4444|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)4U,
 4445|  94.6k|                                                  (size_t)12U);
 4446|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)5U,
 4447|  94.6k|                                                  (size_t)13U);
 4448|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)6U,
 4449|  94.6k|                                                  (size_t)14U);
 4450|  94.6k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)7U,
 4451|  94.6k|                                                  (size_t)15U);
 4452|  94.6k|  return vec;
 4453|  94.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_4_plus_ea:
 6041|  23.6k|    size_t layer) {
 6042|  23.6k|  size_t step = (size_t)1U << (uint32_t)layer;
 6043|   112k|  for (size_t i0 = (size_t)0U; i0 < (size_t)128U >> (uint32_t)layer; i0++) {
  ------------------
  |  Branch (6043:32): [True: 88.6k, False: 23.6k]
  ------------------
 6044|  88.6k|    size_t round = i0;
 6045|  88.6k|    zeta_i[0U] = zeta_i[0U] - (size_t)1U;
 6046|  88.6k|    size_t offset = round * step * (size_t)2U;
 6047|  88.6k|    size_t offset_vec =
 6048|  88.6k|        offset / LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR;
  ------------------
  |  | 3772|  88.6k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
 6049|  88.6k|    size_t step_vec =
 6050|  88.6k|        step / LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR;
  ------------------
  |  | 3772|  88.6k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
 6051|   277k|    for (size_t i = offset_vec; i < offset_vec + step_vec; i++) {
  ------------------
  |  Branch (6051:33): [True: 189k, False: 88.6k]
  ------------------
 6052|   189k|      size_t j = i;
 6053|   189k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2 uu____0 =
 6054|   189k|          libcrux_ml_kem_invert_ntt_inv_ntt_layer_int_vec_step_reduce_ea(
 6055|   189k|              re->coefficients[j], re->coefficients[j + step_vec],
 6056|   189k|              libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
 6057|   189k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector x = uu____0.fst;
 6058|   189k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector y = uu____0.snd;
 6059|   189k|      re->coefficients[j] = x;
 6060|   189k|      re->coefficients[j + step_vec] = y;
 6061|   189k|    }
 6062|  88.6k|  }
 6063|  23.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_invert_ntt_inv_ntt_layer_int_vec_step_reduce_ea:
 6020|   189k|        int16_t zeta_r) {
 6021|   189k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector a_minus_b =
 6022|   189k|      libcrux_ml_kem_vector_portable_sub_b8(b, &a);
 6023|   189k|  a = libcrux_ml_kem_vector_portable_barrett_reduce_b8(
 6024|   189k|      libcrux_ml_kem_vector_portable_add_b8(a, &b));
 6025|   189k|  b = libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(
 6026|   189k|      a_minus_b, zeta_r);
 6027|   189k|  return (KRML_CLITERAL(
  ------------------
  |  |  154|   189k|#define KRML_CLITERAL(type) (type)
  ------------------
 6028|   189k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2){.fst = a,
 6029|   189k|                                                                    .snd = b});
 6030|   189k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_subtract_reduce_d6_ea:
 6130|    657|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d b) {
 6131|    657|  return libcrux_ml_kem_polynomial_subtract_reduce_ea(self, b);
 6132|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_subtract_reduce_ea:
 6098|    657|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d b) {
 6099|    657|  for (size_t i = (size_t)0U;
 6100|  11.1k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  11.1k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (6100:8): [True: 10.5k, False: 657]
  ------------------
 6101|  10.5k|    size_t i0 = i;
 6102|  10.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 6103|  10.5k|        coefficient_normal_form =
 6104|  10.5k|            libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(
 6105|  10.5k|                b.coefficients[i0], (int16_t)1441);
 6106|  10.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector diff =
 6107|  10.5k|        libcrux_ml_kem_vector_portable_sub_b8(myself->coefficients[i0],
 6108|  10.5k|                                              &coefficient_normal_form);
 6109|  10.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector red =
 6110|  10.5k|        libcrux_ml_kem_vector_portable_barrett_reduce_b8(diff);
 6111|  10.5k|    b.coefficients[i0] = red;
 6112|  10.5k|  }
 6113|    657|  return b;
 6114|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_compress_then_serialize_message_ea:
 6184|    657|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d re, uint8_t ret[32U]) {
 6185|    657|  uint8_t serialized[32U] = {0U};
 6186|  11.1k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (6186:31): [True: 10.5k, False: 657]
  ------------------
 6187|  10.5k|    size_t i0 = i;
 6188|  10.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 6189|  10.5k|        libcrux_ml_kem_serialize_to_unsigned_field_modulus_ea(
 6190|  10.5k|            re.coefficients[i0]);
 6191|  10.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 6192|  10.5k|        coefficient_compressed =
 6193|  10.5k|            libcrux_ml_kem_vector_portable_compress_1_b8(coefficient);
 6194|  10.5k|    uint8_t bytes[2U];
 6195|  10.5k|    libcrux_ml_kem_vector_portable_serialize_1_b8(coefficient_compressed,
 6196|  10.5k|                                                  bytes);
 6197|  10.5k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  10.5k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 6198|  10.5k|        Eurydice_array_to_subslice3(serialized, (size_t)2U * i0,
 6199|  10.5k|                                    (size_t)2U * i0 + (size_t)2U, uint8_t *),
 6200|  10.5k|        Eurydice_array_to_slice((size_t)2U, bytes, uint8_t), uint8_t);
 6201|  10.5k|  }
 6202|    657|  memcpy(ret, serialized, (size_t)32U * sizeof(uint8_t));
 6203|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_to_unsigned_field_modulus_ea:
 6172|   189k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 6173|   189k|  return libcrux_ml_kem_vector_portable_to_unsigned_representative_b8(a);
 6174|   189k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_to_unsigned_representative_b8:
 4127|   189k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4128|   189k|  return libcrux_ml_kem_vector_portable_arithmetic_to_unsigned_representative(
 4129|   189k|      a);
 4130|   189k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_to_unsigned_representative:
 4112|   189k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4113|   189k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector t =
 4114|   189k|      libcrux_ml_kem_vector_portable_arithmetic_shift_right_ef(a);
 4115|   189k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector fm =
 4116|   189k|      libcrux_ml_kem_vector_portable_arithmetic_bitwise_and_with_constant(
 4117|   189k|          t, LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS);
  ------------------
  |  | 3777|   189k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 4118|   189k|  return libcrux_ml_kem_vector_portable_arithmetic_add(a, &fm);
 4119|   189k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_shift_right_ef:
 4101|   189k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec) {
 4102|   189k|  for (size_t i = (size_t)0U;
 4103|  3.21M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  3.21M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (4103:8): [True: 3.02M, False: 189k]
  ------------------
 4104|  3.02M|    size_t i0 = i;
 4105|  3.02M|    vec.elements[i0] = vec.elements[i0] >> (uint32_t)(int32_t)15;
 4106|  3.02M|  }
 4107|   189k|  return vec;
 4108|   189k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_bitwise_and_with_constant:
 4084|   210k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec, int16_t c) {
 4085|   210k|  for (size_t i = (size_t)0U;
 4086|  3.57M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  3.57M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (4086:8): [True: 3.36M, False: 210k]
  ------------------
 4087|  3.36M|    size_t i0 = i;
 4088|  3.36M|    size_t uu____0 = i0;
 4089|  3.36M|    vec.elements[uu____0] = vec.elements[uu____0] & c;
 4090|  3.36M|  }
 4091|   210k|  return vec;
 4092|   210k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_1_b8:
 4187|  10.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4188|  10.5k|  return libcrux_ml_kem_vector_portable_compress_compress_1(a);
 4189|  10.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_compress_1:
 4170|  10.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4171|  10.5k|  for (size_t i = (size_t)0U;
 4172|   178k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   178k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (4172:8): [True: 168k, False: 10.5k]
  ------------------
 4173|   168k|    size_t i0 = i;
 4174|   168k|    a.elements[i0] = libcrux_secrets_int_as_i16_59(
 4175|   168k|        libcrux_ml_kem_vector_portable_compress_compress_message_coefficient(
 4176|   168k|            libcrux_secrets_int_as_u16_f5(a.elements[i0])));
 4177|   168k|  }
 4178|  10.5k|  return a;
 4179|  10.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_compress_message_coefficient:
 4156|   168k|    uint16_t fe) {
 4157|   168k|  int16_t shifted =
 4158|   168k|      libcrux_secrets_int_public_integers_classify_27_39((int16_t)1664) -
 4159|   168k|      libcrux_secrets_int_as_i16_ca(fe);
 4160|   168k|  int16_t mask = shifted >> 15U;
 4161|   168k|  int16_t shifted_to_positive = mask ^ shifted;
 4162|   168k|  int16_t shifted_positive_in_range = shifted_to_positive - (int16_t)832;
 4163|   168k|  int16_t r0 = shifted_positive_in_range >> 15U;
 4164|   168k|  int16_t r1 = r0 & (int16_t)1;
 4165|   168k|  return libcrux_secrets_int_as_u8_f5(r1);
 4166|   168k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i16_ca:
  640|   168k|static KRML_MUSTINLINE int16_t libcrux_secrets_int_as_i16_ca(uint16_t self) {
  641|   168k|  return libcrux_secrets_int_public_integers_classify_27_39(
  642|   168k|      (int16_t)libcrux_secrets_int_public_integers_declassify_d8_de(self));
  643|   168k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_de:
  633|  1.51M|libcrux_secrets_int_public_integers_declassify_d8_de(uint16_t self) {
  634|  1.51M|  return self;
  635|  1.51M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_u8_f5:
  501|  4.96M|static KRML_MUSTINLINE uint8_t libcrux_secrets_int_as_u8_f5(int16_t self) {
  502|  4.96M|  return libcrux_secrets_int_public_integers_classify_27_90(
  503|  4.96M|      (uint8_t)libcrux_secrets_int_public_integers_declassify_d8_39(self));
  504|  4.96M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_90:
  481|  4.96M|libcrux_secrets_int_public_integers_classify_27_90(uint8_t self) {
  482|  4.96M|  return self;
  483|  4.96M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_u16_f5:
  619|  1.51M|static KRML_MUSTINLINE uint16_t libcrux_secrets_int_as_u16_f5(int16_t self) {
  620|  1.51M|  return libcrux_secrets_int_public_integers_classify_27_de(
  621|  1.51M|      (uint16_t)libcrux_secrets_int_public_integers_declassify_d8_39(self));
  622|  1.51M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_de:
  612|  1.51M|libcrux_secrets_int_public_integers_classify_27_de(uint16_t self) {
  613|  1.51M|  return self;
  614|  1.51M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_1_b8:
 4612|  10.5k|    uint8_t ret[2U]) {
 4613|  10.5k|  libcrux_ml_kem_vector_portable_serialize_1(a, ret);
 4614|  10.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_1:
 4600|  10.5k|    uint8_t ret[2U]) {
 4601|  10.5k|  uint8_t ret0[2U];
 4602|  10.5k|  libcrux_ml_kem_vector_portable_serialize_serialize_1(a, ret0);
 4603|  10.5k|  libcrux_secrets_int_public_integers_declassify_d8_d4(ret0, ret);
 4604|  10.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_1:
 4575|  10.5k|    uint8_t ret[2U]) {
 4576|  10.5k|  uint8_t result0 =
 4577|  10.5k|      (((((((uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[0U]) |
 4578|  10.5k|            (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[1U]) << 1U) |
 4579|  10.5k|           (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[2U]) << 2U) |
 4580|  10.5k|          (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[3U]) << 3U) |
 4581|  10.5k|         (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[4U]) << 4U) |
 4582|  10.5k|        (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[5U]) << 5U) |
 4583|  10.5k|       (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[6U]) << 6U) |
 4584|  10.5k|      (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[7U]) << 7U;
 4585|  10.5k|  uint8_t result1 =
 4586|  10.5k|      (((((((uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[8U]) |
 4587|  10.5k|            (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[9U]) << 1U) |
 4588|  10.5k|           (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[10U]) << 2U) |
 4589|  10.5k|          (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[11U]) << 3U) |
 4590|  10.5k|         (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[12U]) << 4U) |
 4591|  10.5k|        (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[13U]) << 5U) |
 4592|  10.5k|       (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[14U]) << 6U) |
 4593|  10.5k|      (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[15U]) << 7U;
 4594|  10.5k|  ret[0U] = result0;
 4595|  10.5k|  ret[1U] = result1;
 4596|  10.5k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_d4:
 1062|  10.5k|                                                     uint8_t ret[2U]) {
 1063|  10.5k|  memcpy(ret, self, (size_t)2U * sizeof(uint8_t));
 1064|  10.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_into_padded_array_24:
  955|  1.31k|    Eurydice_slice slice, uint8_t ret[64U]) {
  956|  1.31k|  uint8_t out[64U] = {0U};
  957|  1.31k|  uint8_t *uu____0 = out;
  958|  1.31k|  Eurydice_slice_copy(
  ------------------
  |  |  229|  1.31k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
  959|  1.31k|      Eurydice_array_to_subslice3(
  960|  1.31k|          uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *),
  961|  1.31k|      slice, uint8_t);
  962|  1.31k|  memcpy(ret, out, (size_t)64U * sizeof(uint8_t));
  963|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_G_4a_e0:
 6298|  1.97k|    Eurydice_slice input, uint8_t ret[64U]) {
 6299|  1.97k|  libcrux_ml_kem_hash_functions_portable_G(input, ret);
 6300|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_G:
 3717|  1.97k|    Eurydice_slice input, uint8_t ret[64U]) {
 3718|  1.97k|  uint8_t digest[64U] = {0U};
 3719|  1.97k|  libcrux_sha3_portable_sha512(
 3720|  1.97k|      Eurydice_array_to_slice((size_t)64U, digest, uint8_t), input);
  ------------------
  |  |  204|  1.97k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  1.97k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.97k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  1.97k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3721|  1.97k|  memcpy(ret, digest, (size_t)64U * sizeof(uint8_t));
 3722|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_sha512:
 3128|  1.97k|                                                         Eurydice_slice data) {
 3129|  1.97k|  libcrux_sha3_generic_keccak_portable_keccak1_96(data, digest);
 3130|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_keccak1_96:
 3092|  1.97k|    Eurydice_slice data, Eurydice_slice out) {
 3093|  1.97k|  libcrux_sha3_generic_keccak_KeccakState_17 s =
 3094|  1.97k|      libcrux_sha3_generic_keccak_new_80_04();
 3095|  1.97k|  size_t data_len = Eurydice_slice_len(data, uint8_t);
  ------------------
  |  |  173|  1.97k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3096|  1.97k|  for (size_t i = (size_t)0U; i < data_len / (size_t)72U; i++) {
  ------------------
  |  Branch (3096:31): [True: 0, False: 1.97k]
  ------------------
 3097|      0|    size_t i0 = i;
 3098|      0|    Eurydice_slice buf[1U] = {data};
 3099|      0|    libcrux_sha3_generic_keccak_absorb_block_80_c6(&s, buf, i0 * (size_t)72U);
 3100|      0|  }
 3101|  1.97k|  size_t rem = data_len % (size_t)72U;
 3102|  1.97k|  Eurydice_slice buf[1U] = {data};
 3103|  1.97k|  libcrux_sha3_generic_keccak_absorb_final_80_9e(&s, buf, data_len - rem, rem);
 3104|  1.97k|  size_t outlen = Eurydice_slice_len(out, uint8_t);
  ------------------
  |  |  173|  1.97k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3105|  1.97k|  size_t blocks = outlen / (size_t)72U;
 3106|  1.97k|  size_t last = outlen - outlen % (size_t)72U;
 3107|  1.97k|  if (blocks == (size_t)0U) {
  ------------------
  |  Branch (3107:7): [True: 1.97k, False: 0]
  ------------------
 3108|  1.97k|    libcrux_sha3_simd_portable_squeeze_13_f8(&s, out, (size_t)0U, outlen);
 3109|  1.97k|  } else {
 3110|      0|    libcrux_sha3_simd_portable_squeeze_13_f8(&s, out, (size_t)0U, (size_t)72U);
 3111|      0|    for (size_t i = (size_t)1U; i < blocks; i++) {
  ------------------
  |  Branch (3111:33): [True: 0, False: 0]
  ------------------
 3112|      0|      size_t i0 = i;
 3113|      0|      libcrux_sha3_generic_keccak_keccakf1600_80_04(&s);
 3114|      0|      libcrux_sha3_simd_portable_squeeze_13_f8(&s, out, i0 * (size_t)72U,
 3115|      0|                                               (size_t)72U);
 3116|      0|    }
 3117|      0|    if (last < outlen) {
  ------------------
  |  Branch (3117:9): [True: 0, False: 0]
  ------------------
 3118|      0|      libcrux_sha3_generic_keccak_keccakf1600_80_04(&s);
 3119|      0|      libcrux_sha3_simd_portable_squeeze_13_f8(&s, out, last, outlen - last);
 3120|      0|    }
 3121|      0|  }
 3122|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_new_80_04:
 1449|  34.8k|libcrux_sha3_generic_keccak_new_80_04(void) {
 1450|  34.8k|  libcrux_sha3_generic_keccak_KeccakState_17 lit;
 1451|  34.8k|  uint64_t repeat_expression[25U];
 1452|   905k|  for (size_t i = (size_t)0U; i < (size_t)25U; i++) {
  ------------------
  |  Branch (1452:31): [True: 870k, False: 34.8k]
  ------------------
 1453|   870k|    repeat_expression[i] = libcrux_sha3_simd_portable_zero_d2();
 1454|   870k|  }
 1455|  34.8k|  memcpy(lit.st, repeat_expression, (size_t)25U * sizeof(uint64_t));
 1456|  34.8k|  return lit;
 1457|  34.8k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_zero_d2:
 1320|   870k|static KRML_MUSTINLINE uint64_t libcrux_sha3_simd_portable_zero_d2(void) {
 1321|   870k|  return 0ULL;
 1322|   870k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_block_f8:
 1489|  1.97k|    uint64_t *state, Eurydice_slice blocks, size_t start) {
 1490|  1.97k|  uint64_t state_flat[25U] = {0U};
 1491|  19.7k|  for (size_t i = (size_t)0U; i < (size_t)72U / (size_t)8U; i++) {
  ------------------
  |  Branch (1491:31): [True: 17.7k, False: 1.97k]
  ------------------
 1492|  17.7k|    size_t i0 = i;
 1493|  17.7k|    size_t offset = start + (size_t)8U * i0;
 1494|  17.7k|    uint8_t uu____0[8U];
 1495|  17.7k|    Result_15 dst;
 1496|  17.7k|    Eurydice_slice_to_array2(
  ------------------
  |  |  277|  17.7k|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|  17.7k|                           sizeof(t_arr))
  ------------------
 1497|  17.7k|        &dst,
 1498|  17.7k|        Eurydice_slice_subslice3(blocks, offset, offset + (size_t)8U,
 1499|  17.7k|                                 uint8_t *),
 1500|  17.7k|        Eurydice_slice, uint8_t[8U], TryFromSliceError);
 1501|  17.7k|    unwrap_26_68(dst, uu____0);
 1502|  17.7k|    state_flat[i0] = core_num__u64__from_le_bytes(uu____0);
 1503|  17.7k|  }
 1504|  19.7k|  for (size_t i = (size_t)0U; i < (size_t)72U / (size_t)8U; i++) {
  ------------------
  |  Branch (1504:31): [True: 17.7k, False: 1.97k]
  ------------------
 1505|  17.7k|    size_t i0 = i;
 1506|  17.7k|    libcrux_sha3_traits_set_ij_04(
 1507|  17.7k|        state, i0 / (size_t)5U, i0 % (size_t)5U,
 1508|  17.7k|        libcrux_sha3_traits_get_ij_04(state, i0 / (size_t)5U,
 1509|  17.7k|                                      i0 % (size_t)5U)[0U] ^
 1510|  17.7k|            state_flat[i0]);
 1511|  17.7k|  }
 1512|  1.97k|}
libcrux_mlkem768_sha3.c:Eurydice_slice_to_array3:
  281|  1.40M|                                            Eurydice_slice src, size_t sz) {
  282|  1.40M|  *dst_tag = 0;
  283|  1.40M|  memcpy(dst_ok, src.ptr, sz);
  284|  1.40M|}
libcrux_mlkem768_sha3.c:unwrap_26_68:
 1163|   915k|static inline void unwrap_26_68(Result_15 self, uint8_t ret[8U]) {
 1164|   915k|  if (self.tag == Ok) {
  ------------------
  |  |  721|   915k|#define Ok 0
  ------------------
  |  Branch (1164:7): [True: 915k, False: 0]
  ------------------
 1165|   915k|    uint8_t f0[8U];
 1166|   915k|    memcpy(f0, self.val.case_Ok, (size_t)8U * sizeof(uint8_t));
 1167|   915k|    memcpy(ret, f0, (size_t)8U * sizeof(uint8_t));
 1168|   915k|  } else {
 1169|      0|    KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", __FILE__, __LINE__,
 1170|      0|                      "unwrap not Ok");
 1171|       |    KRML_HOST_EXIT(255U);
  ------------------
  |  |   41|      0|#define KRML_HOST_EXIT(x) do { \
  |  |   42|      0|    fprintf(stderr, "mlkem internal error"); \
  |  |   43|      0|    exit(x); \
  |  |   44|      0|} while (0)
  |  |  ------------------
  |  |  |  Branch (44:10): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1172|      0|  }
 1173|   915k|}
libcrux_mlkem768_sha3.c:core_num__u64__from_le_bytes:
  331|   915k|static inline uint64_t core_num__u64__from_le_bytes(uint8_t buf[8]) {
  332|   915k|  return load64_le(buf);
  333|   915k|}
libcrux_mlkem768_sha3.c:load64_le:
   61|   915k|{
   62|   915k|	return (uint64_t)(src[0]) |
   63|   915k|	    ((uint64_t)(src[1]) << 8) |
   64|   915k|	    ((uint64_t)(src[2]) << 16) |
   65|   915k|	    ((uint64_t)(src[3]) << 24) |
   66|   915k|	    ((uint64_t)(src[4]) << 32) |
   67|   915k|	    ((uint64_t)(src[5]) << 40) |
   68|   915k|	    ((uint64_t)(src[6]) << 48) |
   69|   915k|	    ((uint64_t)(src[7]) << 56);
   70|   915k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_traits_set_ij_04:
 1479|   156M|                                                          uint64_t value) {
 1480|   156M|  arr[(size_t)5U * j + i] = value;
 1481|   156M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_traits_get_ij_04:
 1467|   313M|                                                               size_t j) {
 1468|   313M|  return &arr[(size_t)5U * j + i];
 1469|   313M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_final_80_9e:
 3027|  1.97k|    size_t start, size_t len) {
 3028|  1.97k|  libcrux_sha3_simd_portable_load_last_a1_96(self, last, start, len);
 3029|  1.97k|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3030|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_a1_96:
 3009|  1.97k|    size_t start, size_t len) {
 3010|  1.97k|  libcrux_sha3_simd_portable_load_last_96(self->st, input[0U], start, len);
 3011|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_96:
 2983|  1.97k|    uint64_t *state, Eurydice_slice blocks, size_t start, size_t len) {
 2984|  1.97k|  uint8_t buffer[72U] = {0U};
 2985|  1.97k|  Eurydice_slice_copy(
  ------------------
  |  |  229|  1.97k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 2986|  1.97k|      Eurydice_array_to_subslice3(buffer, (size_t)0U, len, uint8_t *),
 2987|  1.97k|      Eurydice_slice_subslice3(blocks, start, start + len, uint8_t *), uint8_t);
 2988|  1.97k|  buffer[len] = 6U;
 2989|  1.97k|  size_t uu____0 = (size_t)72U - (size_t)1U;
 2990|  1.97k|  buffer[uu____0] = (uint32_t)buffer[uu____0] | 128U;
 2991|  1.97k|  libcrux_sha3_simd_portable_load_block_f8(
 2992|  1.97k|      state, Eurydice_array_to_slice((size_t)72U, buffer, uint8_t), (size_t)0U);
  ------------------
  |  |  204|  1.97k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  1.97k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.97k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  1.97k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 2993|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_squeeze_13_f8:
 3081|  1.97k|    size_t start, size_t len) {
 3082|  1.97k|  libcrux_sha3_simd_portable_store_block_f8(self->st, out, start, len);
 3083|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_store_block_f8:
 3038|  1.97k|    uint64_t *s, Eurydice_slice out, size_t start, size_t len) {
 3039|  1.97k|  size_t octets = len / (size_t)8U;
 3040|  17.7k|  for (size_t i = (size_t)0U; i < octets; i++) {
  ------------------
  |  Branch (3040:31): [True: 15.7k, False: 1.97k]
  ------------------
 3041|  15.7k|    size_t i0 = i;
 3042|  15.7k|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  15.7k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  15.7k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  15.7k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3043|  15.7k|        out, start + (size_t)8U * i0, start + (size_t)8U * i0 + (size_t)8U,
 3044|  15.7k|        uint8_t *);
 3045|  15.7k|    uint8_t ret[8U];
 3046|  15.7k|    core_num__u64__to_le_bytes(
 3047|  15.7k|        libcrux_sha3_traits_get_ij_04(s, i0 / (size_t)5U, i0 % (size_t)5U)[0U],
 3048|  15.7k|        ret);
 3049|  15.7k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  15.7k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3050|  15.7k|        uu____0, Eurydice_array_to_slice((size_t)8U, ret, uint8_t), uint8_t);
 3051|  15.7k|  }
 3052|  1.97k|  size_t remaining = len % (size_t)8U;
 3053|  1.97k|  if (remaining > (size_t)0U) {
  ------------------
  |  Branch (3053:7): [True: 0, False: 1.97k]
  ------------------
 3054|      0|    Eurydice_slice uu____1 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|      0|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|      0|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|      0|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3055|      0|        out, start + len - remaining, start + len, uint8_t *);
 3056|      0|    uint8_t ret[8U];
 3057|      0|    core_num__u64__to_le_bytes(
 3058|      0|        libcrux_sha3_traits_get_ij_04(s, octets / (size_t)5U,
 3059|      0|                                      octets % (size_t)5U)[0U],
 3060|      0|        ret);
 3061|      0|    Eurydice_slice_copy(
  ------------------
  |  |  229|      0|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3062|      0|        uu____1,
 3063|      0|        Eurydice_array_to_subslice3(ret, (size_t)0U, remaining, uint8_t *),
 3064|      0|        uint8_t);
 3065|      0|  }
 3066|  1.97k|}
libcrux_mlkem768_sha3.c:core_num__u64__to_le_bytes:
  327|  1.35M|static inline void core_num__u64__to_le_bytes(uint64_t v, uint8_t buf[8]) {
  328|  1.35M|  store64_le(buf, v);
  329|  1.35M|}
libcrux_mlkem768_sha3.c:store64_le:
   48|  1.35M|{
   49|  1.35M|	dst[0] = src & 0xff;
   50|  1.35M|	dst[1] = (src >> 8) & 0xff;
   51|  1.35M|	dst[2] = (src >> 16) & 0xff;
   52|  1.35M|	dst[3] = (src >> 24) & 0xff;
   53|  1.35M|	dst[4] = (src >> 32) & 0xff;
   54|  1.35M|	dst[5] = (src >> 40) & 0xff;
   55|  1.35M|	dst[6] = (src >> 48) & 0xff;
   56|  1.35M|	dst[7] = (src >> 56) & 0xff;
   57|  1.35M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_keccakf1600_80_04:
 2943|  86.3k|    libcrux_sha3_generic_keccak_KeccakState_17 *self) {
 2944|  2.15M|  for (size_t i = (size_t)0U; i < (size_t)24U; i++) {
  ------------------
  |  Branch (2944:31): [True: 2.07M, False: 86.3k]
  ------------------
 2945|  2.07M|    size_t i0 = i;
 2946|  2.07M|    uint64_t t[5U];
 2947|  2.07M|    libcrux_sha3_generic_keccak_theta_80_04(self, t);
 2948|  2.07M|    libcrux_sha3_generic_keccak_KeccakState_17 *uu____0 = self;
 2949|  2.07M|    uint64_t uu____1[5U];
 2950|  2.07M|    memcpy(uu____1, t, (size_t)5U * sizeof(uint64_t));
 2951|  2.07M|    libcrux_sha3_generic_keccak_rho_80_04(uu____0, uu____1);
 2952|  2.07M|    libcrux_sha3_generic_keccak_pi_80_04(self);
 2953|  2.07M|    libcrux_sha3_generic_keccak_chi_80_04(self);
 2954|  2.07M|    libcrux_sha3_generic_keccak_iota_80_04(self, i0);
 2955|  2.07M|  }
 2956|  86.3k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_theta_80_04:
 1557|  2.07M|    libcrux_sha3_generic_keccak_KeccakState_17 *self, uint64_t ret[5U]) {
 1558|  2.07M|  uint64_t c[5U] = {
 1559|  2.07M|      libcrux_sha3_simd_portable_xor5_d2(
 1560|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1561|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1562|  2.07M|                                              .snd = (size_t)0U}))[0U],
 1563|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1564|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1565|  2.07M|                                              .snd = (size_t)0U}))[0U],
 1566|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1567|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1568|  2.07M|                                              .snd = (size_t)0U}))[0U],
 1569|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1570|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1571|  2.07M|                                              .snd = (size_t)0U}))[0U],
 1572|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1573|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1574|  2.07M|                                              .snd = (size_t)0U}))[0U]),
 1575|  2.07M|      libcrux_sha3_simd_portable_xor5_d2(
 1576|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1577|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1578|  2.07M|                                              .snd = (size_t)1U}))[0U],
 1579|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1580|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1581|  2.07M|                                              .snd = (size_t)1U}))[0U],
 1582|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1583|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1584|  2.07M|                                              .snd = (size_t)1U}))[0U],
 1585|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1586|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1587|  2.07M|                                              .snd = (size_t)1U}))[0U],
 1588|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1589|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1590|  2.07M|                                              .snd = (size_t)1U}))[0U]),
 1591|  2.07M|      libcrux_sha3_simd_portable_xor5_d2(
 1592|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1593|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1594|  2.07M|                                              .snd = (size_t)2U}))[0U],
 1595|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1596|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1597|  2.07M|                                              .snd = (size_t)2U}))[0U],
 1598|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1599|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1600|  2.07M|                                              .snd = (size_t)2U}))[0U],
 1601|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1602|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1603|  2.07M|                                              .snd = (size_t)2U}))[0U],
 1604|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1605|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1606|  2.07M|                                              .snd = (size_t)2U}))[0U]),
 1607|  2.07M|      libcrux_sha3_simd_portable_xor5_d2(
 1608|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1609|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1610|  2.07M|                                              .snd = (size_t)3U}))[0U],
 1611|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1612|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1613|  2.07M|                                              .snd = (size_t)3U}))[0U],
 1614|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1615|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1616|  2.07M|                                              .snd = (size_t)3U}))[0U],
 1617|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1618|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1619|  2.07M|                                              .snd = (size_t)3U}))[0U],
 1620|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1621|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1622|  2.07M|                                              .snd = (size_t)3U}))[0U]),
 1623|  2.07M|      libcrux_sha3_simd_portable_xor5_d2(
 1624|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1625|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1626|  2.07M|                                              .snd = (size_t)4U}))[0U],
 1627|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1628|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1629|  2.07M|                                              .snd = (size_t)4U}))[0U],
 1630|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1631|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1632|  2.07M|                                              .snd = (size_t)4U}))[0U],
 1633|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1634|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1635|  2.07M|                                              .snd = (size_t)4U}))[0U],
 1636|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 1637|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 1638|  2.07M|                                              .snd = (size_t)4U}))[0U])};
 1639|  2.07M|  uint64_t uu____0 = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1640|  2.07M|      c[((size_t)0U + (size_t)4U) % (size_t)5U],
 1641|  2.07M|      c[((size_t)0U + (size_t)1U) % (size_t)5U]);
 1642|  2.07M|  uint64_t uu____1 = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1643|  2.07M|      c[((size_t)1U + (size_t)4U) % (size_t)5U],
 1644|  2.07M|      c[((size_t)1U + (size_t)1U) % (size_t)5U]);
 1645|  2.07M|  uint64_t uu____2 = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1646|  2.07M|      c[((size_t)2U + (size_t)4U) % (size_t)5U],
 1647|  2.07M|      c[((size_t)2U + (size_t)1U) % (size_t)5U]);
 1648|  2.07M|  uint64_t uu____3 = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1649|  2.07M|      c[((size_t)3U + (size_t)4U) % (size_t)5U],
 1650|  2.07M|      c[((size_t)3U + (size_t)1U) % (size_t)5U]);
 1651|  2.07M|  ret[0U] = uu____0;
 1652|  2.07M|  ret[1U] = uu____1;
 1653|  2.07M|  ret[2U] = uu____2;
 1654|  2.07M|  ret[3U] = uu____3;
 1655|  2.07M|  ret[4U] = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1656|  2.07M|      c[((size_t)4U + (size_t)4U) % (size_t)5U],
 1657|  2.07M|      c[((size_t)4U + (size_t)1U) % (size_t)5U]);
 1658|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor5_d2:
 1333|  10.3M|    uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e) {
 1334|  10.3M|  return libcrux_sha3_simd_portable__veor5q_u64(a, b, c, d, e);
 1335|  10.3M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__veor5q_u64:
 1325|  10.3M|    uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e) {
 1326|  10.3M|  return (((a ^ b) ^ c) ^ d) ^ e;
 1327|  10.3M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_index_c2_04:
 1542|   310M|    libcrux_sha3_generic_keccak_KeccakState_17 *self, size_t_x2 index) {
 1543|   310M|  return libcrux_sha3_traits_get_ij_04(self->st, index.fst, index.snd);
 1544|   310M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left1_and_xor_d2:
 1358|  10.3M|libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(uint64_t a, uint64_t b) {
 1359|  10.3M|  return libcrux_sha3_simd_portable__vrax1q_u64(a, b);
 1360|  10.3M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vrax1q_u64:
 1349|  10.3M|libcrux_sha3_simd_portable__vrax1q_u64(uint64_t a, uint64_t b) {
 1350|  10.3M|  uint64_t uu____0 = a;
 1351|  10.3M|  return uu____0 ^ libcrux_sha3_simd_portable_rotate_left_76(b);
 1352|  10.3M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_76:
 1344|  12.4M|libcrux_sha3_simd_portable_rotate_left_76(uint64_t x) {
 1345|  12.4M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)1);
 1346|  12.4M|}
libcrux_mlkem768_sha3.c:core_num__u64__rotate_left:
  342|  60.0M|static inline uint64_t core_num__u64__rotate_left(uint64_t x0, uint32_t x1) {
  343|  60.0M|  return (x0 << x1 | x0 >> (64 - x1));
  344|  60.0M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_rho_80_04:
 2540|  2.07M|    libcrux_sha3_generic_keccak_KeccakState_17 *self, uint64_t t[5U]) {
 2541|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2542|  2.07M|      self, (size_t)0U, (size_t)0U,
 2543|  2.07M|      libcrux_sha3_simd_portable_xor_d2(
 2544|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2545|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2546|  2.07M|                                              .snd = (size_t)0U}))[0U],
 2547|  2.07M|          t[0U]));
 2548|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____0 = self;
 2549|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2550|  2.07M|      uu____0, (size_t)1U, (size_t)0U,
 2551|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_02(
 2552|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2553|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2554|  2.07M|                                              .snd = (size_t)0U}))[0U],
 2555|  2.07M|          t[0U]));
 2556|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____1 = self;
 2557|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2558|  2.07M|      uu____1, (size_t)2U, (size_t)0U,
 2559|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_ac(
 2560|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2561|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2562|  2.07M|                                              .snd = (size_t)0U}))[0U],
 2563|  2.07M|          t[0U]));
 2564|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____2 = self;
 2565|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2566|  2.07M|      uu____2, (size_t)3U, (size_t)0U,
 2567|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_020(
 2568|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2569|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2570|  2.07M|                                              .snd = (size_t)0U}))[0U],
 2571|  2.07M|          t[0U]));
 2572|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____3 = self;
 2573|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2574|  2.07M|      uu____3, (size_t)4U, (size_t)0U,
 2575|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_a9(
 2576|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2577|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2578|  2.07M|                                              .snd = (size_t)0U}))[0U],
 2579|  2.07M|          t[0U]));
 2580|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____4 = self;
 2581|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2582|  2.07M|      uu____4, (size_t)0U, (size_t)1U,
 2583|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_76(
 2584|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2585|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2586|  2.07M|                                              .snd = (size_t)1U}))[0U],
 2587|  2.07M|          t[1U]));
 2588|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____5 = self;
 2589|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2590|  2.07M|      uu____5, (size_t)1U, (size_t)1U,
 2591|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_58(
 2592|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2593|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2594|  2.07M|                                              .snd = (size_t)1U}))[0U],
 2595|  2.07M|          t[1U]));
 2596|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____6 = self;
 2597|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2598|  2.07M|      uu____6, (size_t)2U, (size_t)1U,
 2599|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_e0(
 2600|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2601|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2602|  2.07M|                                              .snd = (size_t)1U}))[0U],
 2603|  2.07M|          t[1U]));
 2604|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____7 = self;
 2605|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2606|  2.07M|      uu____7, (size_t)3U, (size_t)1U,
 2607|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_63(
 2608|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2609|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2610|  2.07M|                                              .snd = (size_t)1U}))[0U],
 2611|  2.07M|          t[1U]));
 2612|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____8 = self;
 2613|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2614|  2.07M|      uu____8, (size_t)4U, (size_t)1U,
 2615|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_6a(
 2616|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2617|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2618|  2.07M|                                              .snd = (size_t)1U}))[0U],
 2619|  2.07M|          t[1U]));
 2620|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____9 = self;
 2621|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2622|  2.07M|      uu____9, (size_t)0U, (size_t)2U,
 2623|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_ab(
 2624|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2625|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2626|  2.07M|                                              .snd = (size_t)2U}))[0U],
 2627|  2.07M|          t[2U]));
 2628|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____10 = self;
 2629|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2630|  2.07M|      uu____10, (size_t)1U, (size_t)2U,
 2631|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_5b(
 2632|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2633|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2634|  2.07M|                                              .snd = (size_t)2U}))[0U],
 2635|  2.07M|          t[2U]));
 2636|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____11 = self;
 2637|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2638|  2.07M|      uu____11, (size_t)2U, (size_t)2U,
 2639|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_6f(
 2640|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2641|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2642|  2.07M|                                              .snd = (size_t)2U}))[0U],
 2643|  2.07M|          t[2U]));
 2644|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____12 = self;
 2645|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2646|  2.07M|      uu____12, (size_t)3U, (size_t)2U,
 2647|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_62(
 2648|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2649|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2650|  2.07M|                                              .snd = (size_t)2U}))[0U],
 2651|  2.07M|          t[2U]));
 2652|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____13 = self;
 2653|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2654|  2.07M|      uu____13, (size_t)4U, (size_t)2U,
 2655|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_23(
 2656|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2657|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2658|  2.07M|                                              .snd = (size_t)2U}))[0U],
 2659|  2.07M|          t[2U]));
 2660|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____14 = self;
 2661|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2662|  2.07M|      uu____14, (size_t)0U, (size_t)3U,
 2663|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_37(
 2664|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2665|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2666|  2.07M|                                              .snd = (size_t)3U}))[0U],
 2667|  2.07M|          t[3U]));
 2668|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____15 = self;
 2669|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2670|  2.07M|      uu____15, (size_t)1U, (size_t)3U,
 2671|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_bb(
 2672|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2673|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2674|  2.07M|                                              .snd = (size_t)3U}))[0U],
 2675|  2.07M|          t[3U]));
 2676|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____16 = self;
 2677|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2678|  2.07M|      uu____16, (size_t)2U, (size_t)3U,
 2679|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_b9(
 2680|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2681|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2682|  2.07M|                                              .snd = (size_t)3U}))[0U],
 2683|  2.07M|          t[3U]));
 2684|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____17 = self;
 2685|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2686|  2.07M|      uu____17, (size_t)3U, (size_t)3U,
 2687|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_54(
 2688|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2689|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2690|  2.07M|                                              .snd = (size_t)3U}))[0U],
 2691|  2.07M|          t[3U]));
 2692|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____18 = self;
 2693|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2694|  2.07M|      uu____18, (size_t)4U, (size_t)3U,
 2695|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_4c(
 2696|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2697|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2698|  2.07M|                                              .snd = (size_t)3U}))[0U],
 2699|  2.07M|          t[3U]));
 2700|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____19 = self;
 2701|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2702|  2.07M|      uu____19, (size_t)0U, (size_t)4U,
 2703|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_ce(
 2704|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2705|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2706|  2.07M|                                              .snd = (size_t)4U}))[0U],
 2707|  2.07M|          t[4U]));
 2708|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____20 = self;
 2709|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2710|  2.07M|      uu____20, (size_t)1U, (size_t)4U,
 2711|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_77(
 2712|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2713|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2714|  2.07M|                                              .snd = (size_t)4U}))[0U],
 2715|  2.07M|          t[4U]));
 2716|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____21 = self;
 2717|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2718|  2.07M|      uu____21, (size_t)2U, (size_t)4U,
 2719|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_25(
 2720|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2721|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2722|  2.07M|                                              .snd = (size_t)4U}))[0U],
 2723|  2.07M|          t[4U]));
 2724|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____22 = self;
 2725|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2726|  2.07M|      uu____22, (size_t)3U, (size_t)4U,
 2727|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_af(
 2728|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2729|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2730|  2.07M|                                              .snd = (size_t)4U}))[0U],
 2731|  2.07M|          t[4U]));
 2732|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____23 = self;
 2733|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2734|  2.07M|      uu____23, (size_t)4U, (size_t)4U,
 2735|  2.07M|      libcrux_sha3_simd_portable_xor_and_rotate_d2_fd(
 2736|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2737|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2738|  2.07M|                                              .snd = (size_t)4U}))[0U],
 2739|  2.07M|          t[4U]));
 2740|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_set_80_04:
 1672|   155M|    uint64_t v) {
 1673|   155M|  libcrux_sha3_traits_set_ij_04(self->st, i, j, v);
 1674|   155M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_d2:
 1392|  2.07M|                                                                  uint64_t b) {
 1393|  2.07M|  return a ^ b;
 1394|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_02:
 1708|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_02(uint64_t a, uint64_t b) {
 1709|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_02(a, b);
 1710|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_02:
 1694|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_02(uint64_t a, uint64_t b) {
 1695|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_02(a ^ b);
 1696|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_02:
 1683|  2.07M|libcrux_sha3_simd_portable_rotate_left_02(uint64_t x) {
 1684|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)36);
 1685|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_ac:
 1744|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_ac(uint64_t a, uint64_t b) {
 1745|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_ac(a, b);
 1746|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_ac:
 1730|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_ac(uint64_t a, uint64_t b) {
 1731|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_ac(a ^ b);
 1732|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_ac:
 1719|  2.07M|libcrux_sha3_simd_portable_rotate_left_ac(uint64_t x) {
 1720|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)3);
 1721|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_020:
 1780|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_020(uint64_t a, uint64_t b) {
 1781|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_020(a, b);
 1782|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_020:
 1766|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_020(uint64_t a, uint64_t b) {
 1767|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_020(a ^ b);
 1768|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_020:
 1755|  2.07M|libcrux_sha3_simd_portable_rotate_left_020(uint64_t x) {
 1756|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)41);
 1757|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_a9:
 1816|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_a9(uint64_t a, uint64_t b) {
 1817|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_a9(a, b);
 1818|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_a9:
 1802|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_a9(uint64_t a, uint64_t b) {
 1803|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_a9(a ^ b);
 1804|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_a9:
 1791|  2.07M|libcrux_sha3_simd_portable_rotate_left_a9(uint64_t x) {
 1792|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)18);
 1793|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_76:
 1841|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_76(uint64_t a, uint64_t b) {
 1842|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_76(a, b);
 1843|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_76:
 1827|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_76(uint64_t a, uint64_t b) {
 1828|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_76(a ^ b);
 1829|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_58:
 1877|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_58(uint64_t a, uint64_t b) {
 1878|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_58(a, b);
 1879|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_58:
 1863|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_58(uint64_t a, uint64_t b) {
 1864|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_58(a ^ b);
 1865|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_58:
 1852|  2.07M|libcrux_sha3_simd_portable_rotate_left_58(uint64_t x) {
 1853|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)44);
 1854|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_e0:
 1913|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_e0(uint64_t a, uint64_t b) {
 1914|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_e0(a, b);
 1915|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_e0:
 1899|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_e0(uint64_t a, uint64_t b) {
 1900|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_e0(a ^ b);
 1901|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_e0:
 1888|  2.07M|libcrux_sha3_simd_portable_rotate_left_e0(uint64_t x) {
 1889|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)10);
 1890|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_63:
 1949|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_63(uint64_t a, uint64_t b) {
 1950|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_63(a, b);
 1951|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_63:
 1935|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_63(uint64_t a, uint64_t b) {
 1936|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_63(a ^ b);
 1937|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_63:
 1924|  2.07M|libcrux_sha3_simd_portable_rotate_left_63(uint64_t x) {
 1925|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)45);
 1926|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_6a:
 1985|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_6a(uint64_t a, uint64_t b) {
 1986|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_6a(a, b);
 1987|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_6a:
 1971|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_6a(uint64_t a, uint64_t b) {
 1972|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_6a(a ^ b);
 1973|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_6a:
 1960|  2.07M|libcrux_sha3_simd_portable_rotate_left_6a(uint64_t x) {
 1961|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)2);
 1962|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_ab:
 2021|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_ab(uint64_t a, uint64_t b) {
 2022|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_ab(a, b);
 2023|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_ab:
 2007|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_ab(uint64_t a, uint64_t b) {
 2008|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_ab(a ^ b);
 2009|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_ab:
 1996|  2.07M|libcrux_sha3_simd_portable_rotate_left_ab(uint64_t x) {
 1997|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)62);
 1998|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_5b:
 2057|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_5b(uint64_t a, uint64_t b) {
 2058|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_5b(a, b);
 2059|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_5b:
 2043|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_5b(uint64_t a, uint64_t b) {
 2044|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_5b(a ^ b);
 2045|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_5b:
 2032|  2.07M|libcrux_sha3_simd_portable_rotate_left_5b(uint64_t x) {
 2033|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)6);
 2034|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_6f:
 2093|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_6f(uint64_t a, uint64_t b) {
 2094|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_6f(a, b);
 2095|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_6f:
 2079|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_6f(uint64_t a, uint64_t b) {
 2080|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_6f(a ^ b);
 2081|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_6f:
 2068|  2.07M|libcrux_sha3_simd_portable_rotate_left_6f(uint64_t x) {
 2069|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)43);
 2070|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_62:
 2129|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_62(uint64_t a, uint64_t b) {
 2130|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_62(a, b);
 2131|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_62:
 2115|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_62(uint64_t a, uint64_t b) {
 2116|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_62(a ^ b);
 2117|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_62:
 2104|  2.07M|libcrux_sha3_simd_portable_rotate_left_62(uint64_t x) {
 2105|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)15);
 2106|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_23:
 2165|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_23(uint64_t a, uint64_t b) {
 2166|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_23(a, b);
 2167|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_23:
 2151|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_23(uint64_t a, uint64_t b) {
 2152|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_23(a ^ b);
 2153|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_23:
 2140|  2.07M|libcrux_sha3_simd_portable_rotate_left_23(uint64_t x) {
 2141|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)61);
 2142|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_37:
 2201|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_37(uint64_t a, uint64_t b) {
 2202|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_37(a, b);
 2203|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_37:
 2187|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_37(uint64_t a, uint64_t b) {
 2188|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_37(a ^ b);
 2189|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_37:
 2176|  2.07M|libcrux_sha3_simd_portable_rotate_left_37(uint64_t x) {
 2177|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)28);
 2178|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_bb:
 2237|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_bb(uint64_t a, uint64_t b) {
 2238|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_bb(a, b);
 2239|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_bb:
 2223|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_bb(uint64_t a, uint64_t b) {
 2224|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_bb(a ^ b);
 2225|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_bb:
 2212|  2.07M|libcrux_sha3_simd_portable_rotate_left_bb(uint64_t x) {
 2213|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)55);
 2214|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_b9:
 2273|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_b9(uint64_t a, uint64_t b) {
 2274|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_b9(a, b);
 2275|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_b9:
 2259|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_b9(uint64_t a, uint64_t b) {
 2260|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_b9(a ^ b);
 2261|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_b9:
 2248|  2.07M|libcrux_sha3_simd_portable_rotate_left_b9(uint64_t x) {
 2249|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)25);
 2250|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_54:
 2309|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_54(uint64_t a, uint64_t b) {
 2310|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_54(a, b);
 2311|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_54:
 2295|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_54(uint64_t a, uint64_t b) {
 2296|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_54(a ^ b);
 2297|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_54:
 2284|  2.07M|libcrux_sha3_simd_portable_rotate_left_54(uint64_t x) {
 2285|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)21);
 2286|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_4c:
 2345|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_4c(uint64_t a, uint64_t b) {
 2346|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_4c(a, b);
 2347|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_4c:
 2331|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_4c(uint64_t a, uint64_t b) {
 2332|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_4c(a ^ b);
 2333|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_4c:
 2320|  2.07M|libcrux_sha3_simd_portable_rotate_left_4c(uint64_t x) {
 2321|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)56);
 2322|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_ce:
 2381|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_ce(uint64_t a, uint64_t b) {
 2382|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_ce(a, b);
 2383|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_ce:
 2367|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_ce(uint64_t a, uint64_t b) {
 2368|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_ce(a ^ b);
 2369|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_ce:
 2356|  2.07M|libcrux_sha3_simd_portable_rotate_left_ce(uint64_t x) {
 2357|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)27);
 2358|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_77:
 2417|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_77(uint64_t a, uint64_t b) {
 2418|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_77(a, b);
 2419|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_77:
 2403|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_77(uint64_t a, uint64_t b) {
 2404|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_77(a ^ b);
 2405|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_77:
 2392|  2.07M|libcrux_sha3_simd_portable_rotate_left_77(uint64_t x) {
 2393|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)20);
 2394|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_25:
 2453|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_25(uint64_t a, uint64_t b) {
 2454|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_25(a, b);
 2455|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_25:
 2439|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_25(uint64_t a, uint64_t b) {
 2440|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_25(a ^ b);
 2441|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_25:
 2428|  2.07M|libcrux_sha3_simd_portable_rotate_left_25(uint64_t x) {
 2429|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)39);
 2430|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_af:
 2489|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_af(uint64_t a, uint64_t b) {
 2490|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_af(a, b);
 2491|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_af:
 2475|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_af(uint64_t a, uint64_t b) {
 2476|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_af(a ^ b);
 2477|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_af:
 2464|  2.07M|libcrux_sha3_simd_portable_rotate_left_af(uint64_t x) {
 2465|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)8);
 2466|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_fd:
 2525|  2.07M|libcrux_sha3_simd_portable_xor_and_rotate_d2_fd(uint64_t a, uint64_t b) {
 2526|  2.07M|  return libcrux_sha3_simd_portable__vxarq_u64_fd(a, b);
 2527|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_fd:
 2511|  2.07M|libcrux_sha3_simd_portable__vxarq_u64_fd(uint64_t a, uint64_t b) {
 2512|  2.07M|  return libcrux_sha3_simd_portable_rotate_left_fd(a ^ b);
 2513|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_fd:
 2500|  2.07M|libcrux_sha3_simd_portable_rotate_left_fd(uint64_t x) {
 2501|  2.07M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)14);
 2502|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_pi_80_04:
 2753|  2.07M|    libcrux_sha3_generic_keccak_KeccakState_17 *self) {
 2754|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 old = self[0U];
 2755|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2756|  2.07M|      self, (size_t)1U, (size_t)0U,
 2757|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2758|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2759|  2.07M|                                          .snd = (size_t)3U}))[0U]);
 2760|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2761|  2.07M|      self, (size_t)2U, (size_t)0U,
 2762|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2763|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2764|  2.07M|                                          .snd = (size_t)1U}))[0U]);
 2765|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2766|  2.07M|      self, (size_t)3U, (size_t)0U,
 2767|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2768|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2769|  2.07M|                                          .snd = (size_t)4U}))[0U]);
 2770|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2771|  2.07M|      self, (size_t)4U, (size_t)0U,
 2772|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2773|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2774|  2.07M|                                          .snd = (size_t)2U}))[0U]);
 2775|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2776|  2.07M|      self, (size_t)0U, (size_t)1U,
 2777|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2778|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2779|  2.07M|                                          .snd = (size_t)1U}))[0U]);
 2780|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2781|  2.07M|      self, (size_t)1U, (size_t)1U,
 2782|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2783|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2784|  2.07M|                                          .snd = (size_t)4U}))[0U]);
 2785|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2786|  2.07M|      self, (size_t)2U, (size_t)1U,
 2787|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2788|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2789|  2.07M|                                          .snd = (size_t)2U}))[0U]);
 2790|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2791|  2.07M|      self, (size_t)3U, (size_t)1U,
 2792|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2793|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2794|  2.07M|                                          .snd = (size_t)0U}))[0U]);
 2795|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2796|  2.07M|      self, (size_t)4U, (size_t)1U,
 2797|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2798|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2799|  2.07M|                                          .snd = (size_t)3U}))[0U]);
 2800|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2801|  2.07M|      self, (size_t)0U, (size_t)2U,
 2802|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2803|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2804|  2.07M|                                          .snd = (size_t)2U}))[0U]);
 2805|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2806|  2.07M|      self, (size_t)1U, (size_t)2U,
 2807|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2808|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2809|  2.07M|                                          .snd = (size_t)0U}))[0U]);
 2810|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2811|  2.07M|      self, (size_t)2U, (size_t)2U,
 2812|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2813|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2814|  2.07M|                                          .snd = (size_t)3U}))[0U]);
 2815|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2816|  2.07M|      self, (size_t)3U, (size_t)2U,
 2817|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2818|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2819|  2.07M|                                          .snd = (size_t)1U}))[0U]);
 2820|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2821|  2.07M|      self, (size_t)4U, (size_t)2U,
 2822|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2823|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2824|  2.07M|                                          .snd = (size_t)4U}))[0U]);
 2825|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2826|  2.07M|      self, (size_t)0U, (size_t)3U,
 2827|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2828|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2829|  2.07M|                                          .snd = (size_t)3U}))[0U]);
 2830|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2831|  2.07M|      self, (size_t)1U, (size_t)3U,
 2832|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2833|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2834|  2.07M|                                          .snd = (size_t)1U}))[0U]);
 2835|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2836|  2.07M|      self, (size_t)2U, (size_t)3U,
 2837|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2838|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2839|  2.07M|                                          .snd = (size_t)4U}))[0U]);
 2840|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2841|  2.07M|      self, (size_t)3U, (size_t)3U,
 2842|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2843|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2844|  2.07M|                                          .snd = (size_t)2U}))[0U]);
 2845|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2846|  2.07M|      self, (size_t)4U, (size_t)3U,
 2847|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2848|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2849|  2.07M|                                          .snd = (size_t)0U}))[0U]);
 2850|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2851|  2.07M|      self, (size_t)0U, (size_t)4U,
 2852|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2853|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2854|  2.07M|                                          .snd = (size_t)4U}))[0U]);
 2855|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2856|  2.07M|      self, (size_t)1U, (size_t)4U,
 2857|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2858|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2859|  2.07M|                                          .snd = (size_t)2U}))[0U]);
 2860|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2861|  2.07M|      self, (size_t)2U, (size_t)4U,
 2862|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2863|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2864|  2.07M|                                          .snd = (size_t)0U}))[0U]);
 2865|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2866|  2.07M|      self, (size_t)3U, (size_t)4U,
 2867|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2868|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2869|  2.07M|                                          .snd = (size_t)3U}))[0U]);
 2870|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2871|  2.07M|      self, (size_t)4U, (size_t)4U,
 2872|  2.07M|      libcrux_sha3_generic_keccak_index_c2_04(
 2873|  2.07M|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2874|  2.07M|                                          .snd = (size_t)1U}))[0U]);
 2875|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_chi_80_04:
 2888|  2.07M|    libcrux_sha3_generic_keccak_KeccakState_17 *self) {
 2889|  2.07M|  libcrux_sha3_generic_keccak_KeccakState_17 old = self[0U];
 2890|  12.4M|  for (size_t i0 = (size_t)0U; i0 < (size_t)5U; i0++) {
  ------------------
  |  Branch (2890:32): [True: 10.3M, False: 2.07M]
  ------------------
 2891|  10.3M|    size_t i1 = i0;
 2892|  62.1M|    for (size_t i = (size_t)0U; i < (size_t)5U; i++) {
  ------------------
  |  Branch (2892:33): [True: 51.8M, False: 10.3M]
  ------------------
 2893|  51.8M|      size_t j = i;
 2894|  51.8M|      libcrux_sha3_generic_keccak_set_80_04(
 2895|  51.8M|          self, i1, j,
 2896|  51.8M|          libcrux_sha3_simd_portable_and_not_xor_d2(
 2897|  51.8M|              libcrux_sha3_generic_keccak_index_c2_04(
 2898|  51.8M|                  self, (KRML_CLITERAL(size_t_x2){.fst = i1, .snd = j}))[0U],
  ------------------
  |  |  154|  51.8M|#define KRML_CLITERAL(type) (type)
  ------------------
 2899|  51.8M|              libcrux_sha3_generic_keccak_index_c2_04(
 2900|  51.8M|                  &old,
 2901|  51.8M|                  (KRML_CLITERAL(size_t_x2){
  ------------------
  |  |  154|  51.8M|#define KRML_CLITERAL(type) (type)
  ------------------
 2902|  51.8M|                      .fst = i1, .snd = (j + (size_t)2U) % (size_t)5U}))[0U],
 2903|  51.8M|              libcrux_sha3_generic_keccak_index_c2_04(
 2904|  51.8M|                  &old,
 2905|  51.8M|                  (KRML_CLITERAL(size_t_x2){
  ------------------
  |  |  154|  51.8M|#define KRML_CLITERAL(type) (type)
  ------------------
 2906|  51.8M|                      .fst = i1, .snd = (j + (size_t)1U) % (size_t)5U}))[0U]));
 2907|  51.8M|    }
 2908|  10.3M|  }
 2909|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_and_not_xor_d2:
 1371|  51.8M|libcrux_sha3_simd_portable_and_not_xor_d2(uint64_t a, uint64_t b, uint64_t c) {
 1372|  51.8M|  return libcrux_sha3_simd_portable__vbcaxq_u64(a, b, c);
 1373|  51.8M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vbcaxq_u64:
 1363|  51.8M|libcrux_sha3_simd_portable__vbcaxq_u64(uint64_t a, uint64_t b, uint64_t c) {
 1364|  51.8M|  return a ^ (b & ~c);
 1365|  51.8M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_iota_80_04:
 2922|  2.07M|    libcrux_sha3_generic_keccak_KeccakState_17 *self, size_t i) {
 2923|  2.07M|  libcrux_sha3_generic_keccak_set_80_04(
 2924|  2.07M|      self, (size_t)0U, (size_t)0U,
 2925|  2.07M|      libcrux_sha3_simd_portable_xor_constant_d2(
 2926|  2.07M|          libcrux_sha3_generic_keccak_index_c2_04(
 2927|  2.07M|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|  2.07M|#define KRML_CLITERAL(type) (type)
  ------------------
 2928|  2.07M|                                              .snd = (size_t)0U}))[0U],
 2929|  2.07M|          libcrux_sha3_generic_keccak_constants_ROUNDCONSTANTS[i]));
 2930|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_constant_d2:
 1384|  2.07M|libcrux_sha3_simd_portable_xor_constant_d2(uint64_t a, uint64_t c) {
 1385|  2.07M|  return libcrux_sha3_simd_portable__veorq_n_u64(a, c);
 1386|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__veorq_n_u64:
 1376|  2.07M|libcrux_sha3_simd_portable__veorq_n_u64(uint64_t a, uint64_t c) {
 1377|  2.07M|  return a ^ c;
 1378|  2.07M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_into_padded_array_15:
  936|    657|    Eurydice_slice slice, uint8_t ret[1120U]) {
  937|    657|  uint8_t out[1120U] = {0U};
  938|    657|  uint8_t *uu____0 = out;
  939|    657|  Eurydice_slice_copy(
  ------------------
  |  |  229|    657|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
  940|    657|      Eurydice_array_to_subslice3(
  941|    657|          uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *),
  942|    657|      slice, uint8_t);
  943|    657|  memcpy(ret, out, (size_t)1120U * sizeof(uint8_t));
  944|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_as_ref_d3_80:
  923|  1.31k|    libcrux_ml_kem_mlkem768_MlKem768Ciphertext *self) {
  924|  1.31k|  return Eurydice_array_to_slice((size_t)1088U, self->value, uint8_t);
  ------------------
  |  |  204|  1.31k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  1.31k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.31k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  1.31k|                 end) /* x is already at an array type, no need for cast */
  ------------------
  925|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRF_4a_41:
 6326|    657|    Eurydice_slice input, uint8_t ret[32U]) {
 6327|    657|  libcrux_ml_kem_hash_functions_portable_PRF_9e(input, ret);
 6328|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRF_9e:
 6308|    657|    Eurydice_slice input, uint8_t ret[32U]) {
 6309|    657|  uint8_t digest[32U] = {0U};
 6310|    657|  libcrux_sha3_portable_shake256(
 6311|    657|      Eurydice_array_to_slice((size_t)32U, digest, uint8_t), input);
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6312|    657|  memcpy(ret, digest, (size_t)32U * sizeof(uint8_t));
 6313|    657|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_shake256:
 3455|  13.7k|    Eurydice_slice digest, Eurydice_slice data) {
 3456|  13.7k|  libcrux_sha3_generic_keccak_portable_keccak1_ad0(data, digest);
 3457|  13.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_keccak1_ad0:
 3419|  13.7k|    Eurydice_slice data, Eurydice_slice out) {
 3420|  13.7k|  libcrux_sha3_generic_keccak_KeccakState_17 s =
 3421|  13.7k|      libcrux_sha3_generic_keccak_new_80_04();
 3422|  13.7k|  size_t data_len = Eurydice_slice_len(data, uint8_t);
  ------------------
  |  |  173|  13.7k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3423|  19.0k|  for (size_t i = (size_t)0U; i < data_len / (size_t)136U; i++) {
  ------------------
  |  Branch (3423:31): [True: 5.25k, False: 13.7k]
  ------------------
 3424|  5.25k|    size_t i0 = i;
 3425|  5.25k|    Eurydice_slice buf[1U] = {data};
 3426|  5.25k|    libcrux_sha3_generic_keccak_absorb_block_80_c60(&s, buf, i0 * (size_t)136U);
 3427|  5.25k|  }
 3428|  13.7k|  size_t rem = data_len % (size_t)136U;
 3429|  13.7k|  Eurydice_slice buf[1U] = {data};
 3430|  13.7k|  libcrux_sha3_generic_keccak_absorb_final_80_9e1(&s, buf, data_len - rem, rem);
 3431|  13.7k|  size_t outlen = Eurydice_slice_len(out, uint8_t);
  ------------------
  |  |  173|  13.7k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3432|  13.7k|  size_t blocks = outlen / (size_t)136U;
 3433|  13.7k|  size_t last = outlen - outlen % (size_t)136U;
 3434|  13.7k|  if (blocks == (size_t)0U) {
  ------------------
  |  Branch (3434:7): [True: 13.7k, False: 0]
  ------------------
 3435|  13.7k|    libcrux_sha3_simd_portable_squeeze_13_5b(&s, out, (size_t)0U, outlen);
 3436|  13.7k|  } else {
 3437|      0|    libcrux_sha3_simd_portable_squeeze_13_5b(&s, out, (size_t)0U, (size_t)136U);
 3438|      0|    for (size_t i = (size_t)1U; i < blocks; i++) {
  ------------------
  |  Branch (3438:33): [True: 0, False: 0]
  ------------------
 3439|      0|      size_t i0 = i;
 3440|      0|      libcrux_sha3_generic_keccak_keccakf1600_80_04(&s);
 3441|      0|      libcrux_sha3_simd_portable_squeeze_13_5b(&s, out, i0 * (size_t)136U,
 3442|      0|                                               (size_t)136U);
 3443|      0|    }
 3444|      0|    if (last < outlen) {
  ------------------
  |  Branch (3444:9): [True: 0, False: 0]
  ------------------
 3445|      0|      libcrux_sha3_generic_keccak_keccakf1600_80_04(&s);
 3446|      0|      libcrux_sha3_simd_portable_squeeze_13_5b(&s, out, last, outlen - last);
 3447|      0|    }
 3448|      0|  }
 3449|  13.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_block_80_c60:
 3193|  15.7k|    size_t start) {
 3194|  15.7k|  libcrux_sha3_simd_portable_load_block_a1_5b(self, blocks, start);
 3195|  15.7k|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3196|  15.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_block_a1_5b:
 3176|  15.7k|    size_t start) {
 3177|  15.7k|  libcrux_sha3_simd_portable_load_block_5b(self->st, input[0U], start);
 3178|  15.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_block_5b:
 3138|  30.8k|    uint64_t *state, Eurydice_slice blocks, size_t start) {
 3139|  30.8k|  uint64_t state_flat[25U] = {0U};
 3140|   555k|  for (size_t i = (size_t)0U; i < (size_t)136U / (size_t)8U; i++) {
  ------------------
  |  Branch (3140:31): [True: 524k, False: 30.8k]
  ------------------
 3141|   524k|    size_t i0 = i;
 3142|   524k|    size_t offset = start + (size_t)8U * i0;
 3143|   524k|    uint8_t uu____0[8U];
 3144|   524k|    Result_15 dst;
 3145|   524k|    Eurydice_slice_to_array2(
  ------------------
  |  |  277|   524k|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|   524k|                           sizeof(t_arr))
  ------------------
 3146|   524k|        &dst,
 3147|   524k|        Eurydice_slice_subslice3(blocks, offset, offset + (size_t)8U,
 3148|   524k|                                 uint8_t *),
 3149|   524k|        Eurydice_slice, uint8_t[8U], TryFromSliceError);
 3150|   524k|    unwrap_26_68(dst, uu____0);
 3151|   524k|    state_flat[i0] = core_num__u64__from_le_bytes(uu____0);
 3152|   524k|  }
 3153|   555k|  for (size_t i = (size_t)0U; i < (size_t)136U / (size_t)8U; i++) {
  ------------------
  |  Branch (3153:31): [True: 524k, False: 30.8k]
  ------------------
 3154|   524k|    size_t i0 = i;
 3155|   524k|    libcrux_sha3_traits_set_ij_04(
 3156|   524k|        state, i0 / (size_t)5U, i0 % (size_t)5U,
 3157|   524k|        libcrux_sha3_traits_get_ij_04(state, i0 / (size_t)5U,
 3158|   524k|                                      i0 % (size_t)5U)[0U] ^
 3159|   524k|            state_flat[i0]);
 3160|   524k|  }
 3161|  30.8k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_final_80_9e1:
 3407|  13.7k|    size_t start, size_t len) {
 3408|  13.7k|  libcrux_sha3_simd_portable_load_last_a1_ad0(self, last, start, len);
 3409|  13.7k|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3410|  13.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_a1_ad0:
 3389|  13.7k|    size_t start, size_t len) {
 3390|  13.7k|  libcrux_sha3_simd_portable_load_last_ad0(self->st, input[0U], start, len);
 3391|  13.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_ad0:
 3362|  13.7k|    uint64_t *state, Eurydice_slice blocks, size_t start, size_t len) {
 3363|  13.7k|  uint8_t buffer[136U] = {0U};
 3364|  13.7k|  Eurydice_slice_copy(
  ------------------
  |  |  229|  13.7k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3365|  13.7k|      Eurydice_array_to_subslice3(buffer, (size_t)0U, len, uint8_t *),
 3366|  13.7k|      Eurydice_slice_subslice3(blocks, start, start + len, uint8_t *), uint8_t);
 3367|  13.7k|  buffer[len] = 31U;
 3368|  13.7k|  size_t uu____0 = (size_t)136U - (size_t)1U;
 3369|  13.7k|  buffer[uu____0] = (uint32_t)buffer[uu____0] | 128U;
 3370|  13.7k|  libcrux_sha3_simd_portable_load_block_5b(
 3371|  13.7k|      state, Eurydice_array_to_slice((size_t)136U, buffer, uint8_t),
  ------------------
  |  |  204|  13.7k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  13.7k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  13.7k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  13.7k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3372|  13.7k|      (size_t)0U);
 3373|  13.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_squeeze_13_5b:
 3304|  15.1k|    size_t start, size_t len) {
 3305|  15.1k|  libcrux_sha3_simd_portable_store_block_5b(self->st, out, start, len);
 3306|  15.1k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_store_block_5b:
 3261|  15.1k|    uint64_t *s, Eurydice_slice out, size_t start, size_t len) {
 3262|  15.1k|  size_t octets = len / (size_t)8U;
 3263|   233k|  for (size_t i = (size_t)0U; i < octets; i++) {
  ------------------
  |  Branch (3263:31): [True: 218k, False: 15.1k]
  ------------------
 3264|   218k|    size_t i0 = i;
 3265|   218k|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|   218k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   218k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   218k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3266|   218k|        out, start + (size_t)8U * i0, start + (size_t)8U * i0 + (size_t)8U,
 3267|   218k|        uint8_t *);
 3268|   218k|    uint8_t ret[8U];
 3269|   218k|    core_num__u64__to_le_bytes(
 3270|   218k|        libcrux_sha3_traits_get_ij_04(s, i0 / (size_t)5U, i0 % (size_t)5U)[0U],
 3271|   218k|        ret);
 3272|   218k|    Eurydice_slice_copy(
  ------------------
  |  |  229|   218k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3273|   218k|        uu____0, Eurydice_array_to_slice((size_t)8U, ret, uint8_t), uint8_t);
 3274|   218k|  }
 3275|  15.1k|  size_t remaining = len % (size_t)8U;
 3276|  15.1k|  if (remaining > (size_t)0U) {
  ------------------
  |  Branch (3276:7): [True: 0, False: 15.1k]
  ------------------
 3277|      0|    Eurydice_slice uu____1 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|      0|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|      0|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|      0|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3278|      0|        out, start + len - remaining, start + len, uint8_t *);
 3279|      0|    uint8_t ret[8U];
 3280|      0|    core_num__u64__to_le_bytes(
 3281|      0|        libcrux_sha3_traits_get_ij_04(s, octets / (size_t)5U,
 3282|      0|                                      octets % (size_t)5U)[0U],
 3283|      0|        ret);
 3284|      0|    Eurydice_slice_copy(
  ------------------
  |  |  229|      0|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3285|      0|        uu____1,
 3286|      0|        Eurydice_array_to_subslice3(ret, (size_t)0U, remaining, uint8_t *),
 3287|      0|        uint8_t);
 3288|      0|  }
 3289|  15.1k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_encrypt_2a:
 7881|  1.31k|    uint8_t ret[1088U]) {
 7882|  1.31k|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0
 7883|  1.31k|      unpacked_public_key =
 7884|  1.31k|          libcrux_ml_kem_ind_cpa_build_unpacked_public_key_3f(public_key);
 7885|  1.31k|  uint8_t ret0[1088U];
 7886|  1.31k|  libcrux_ml_kem_ind_cpa_encrypt_unpacked_2a(&unpacked_public_key, message,
 7887|  1.31k|                                             randomness, ret0);
 7888|  1.31k|  memcpy(ret, ret0, (size_t)1088U * sizeof(uint8_t));
 7889|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_build_unpacked_public_key_3f:
 6924|  1.31k|        Eurydice_slice public_key) {
 6925|  1.31k|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0
 6926|  1.31k|      unpacked_public_key = libcrux_ml_kem_ind_cpa_unpacked_default_8b_1b();
 6927|  1.31k|  libcrux_ml_kem_ind_cpa_build_unpacked_public_key_mut_3f(public_key,
 6928|  1.31k|                                                          &unpacked_public_key);
 6929|  1.31k|  return unpacked_public_key;
 6930|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_unpacked_default_8b_1b:
 6354|  1.97k|libcrux_ml_kem_ind_cpa_unpacked_default_8b_1b(void) {
 6355|  1.97k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0[3U];
 6356|  7.88k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6356:31): [True: 5.91k, False: 1.97k]
  ------------------
 6357|  5.91k|    uu____0[i] = libcrux_ml_kem_polynomial_ZERO_d6_ea();
 6358|  5.91k|  }
 6359|  1.97k|  uint8_t uu____1[32U] = {0U};
 6360|  1.97k|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0 lit;
 6361|  1.97k|  memcpy(
 6362|  1.97k|      lit.t_as_ntt, uu____0,
 6363|  1.97k|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 6364|  1.97k|  memcpy(lit.seed_for_A, uu____1, (size_t)32U * sizeof(uint8_t));
 6365|  1.97k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d repeat_expression0[3U][3U];
 6366|  7.88k|  for (size_t i0 = (size_t)0U; i0 < (size_t)3U; i0++) {
  ------------------
  |  Branch (6366:32): [True: 5.91k, False: 1.97k]
  ------------------
 6367|  5.91k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d repeat_expression[3U];
 6368|  23.6k|    for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6368:33): [True: 17.7k, False: 5.91k]
  ------------------
 6369|  17.7k|      repeat_expression[i] = libcrux_ml_kem_polynomial_ZERO_d6_ea();
 6370|  17.7k|    }
 6371|  5.91k|    memcpy(repeat_expression0[i0], repeat_expression,
 6372|  5.91k|           (size_t)3U *
 6373|  5.91k|               sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 6374|  5.91k|  }
 6375|  1.97k|  memcpy(lit.A, repeat_expression0,
 6376|  1.97k|         (size_t)3U *
 6377|  1.97k|             sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]));
 6378|  1.97k|  return lit;
 6379|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_build_unpacked_public_key_mut_3f:
 6899|  1.31k|        *unpacked_public_key) {
 6900|  1.31k|  Eurydice_slice uu____0 = Eurydice_slice_subslice_to(
  ------------------
  |  |  198|  1.31k|  EURYDICE_SLICE((t *)s.ptr, 0, subslice_end_pos)
  |  |  ------------------
  |  |  |  |  169|  1.31k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.31k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6901|  1.31k|      public_key, (size_t)1152U, uint8_t, size_t, uint8_t[]);
 6902|  1.31k|  libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_1b(
 6903|  1.31k|      uu____0, unpacked_public_key->t_as_ntt);
 6904|  1.31k|  Eurydice_slice seed = Eurydice_slice_subslice_from(
  ------------------
  |  |  201|  1.31k|  EURYDICE_SLICE((t *)s.ptr, subslice_start_pos, s.len)
  |  |  ------------------
  |  |  |  |  169|  1.31k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.31k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6905|  1.31k|      public_key, (size_t)1152U, uint8_t, size_t, uint8_t[]);
 6906|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d(*uu____1)[3U] =
 6907|  1.31k|      unpacked_public_key->A;
 6908|  1.31k|  uint8_t ret[34U];
 6909|  1.31k|  libcrux_ml_kem_utils_into_padded_array_b6(seed, ret);
 6910|       |  libcrux_ml_kem_matrix_sample_matrix_A_2b(uu____1, ret, false);
 6911|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_1b:
 6425|  1.97k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *deserialized_pk) {
 6426|  1.97k|  for (size_t i = (size_t)0U;
 6427|  7.88k|       i < Eurydice_slice_len(public_key, uint8_t) /
  ------------------
  |  |  173|  7.88k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (6427:8): [True: 5.91k, False: 1.97k]
  ------------------
 6428|  7.88k|               LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT;
  ------------------
  |  |  453|  7.88k|  (LIBCRUX_ML_KEM_CONSTANTS_BITS_PER_RING_ELEMENT / (size_t)8U)
  |  |  ------------------
  |  |  |  |  450|  7.88k|  (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)12U)
  |  |  |  |  ------------------
  |  |  |  |  |  |  447|  7.88k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6429|  5.91k|       i++) {
 6430|  5.91k|    size_t i0 = i;
 6431|  5.91k|    Eurydice_slice ring_element = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  5.91k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  5.91k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  5.91k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6432|  5.91k|        public_key, i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 6433|  5.91k|        i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT +
 6434|  5.91k|            LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 6435|  5.91k|        uint8_t *);
 6436|  5.91k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0 =
 6437|  5.91k|        libcrux_ml_kem_serialize_deserialize_to_reduced_ring_element_ea(
 6438|  5.91k|            ring_element);
 6439|  5.91k|    deserialized_pk[i0] = uu____0;
 6440|  5.91k|  }
 6441|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_to_reduced_ring_element_ea:
 6395|  5.91k|    Eurydice_slice serialized) {
 6396|  5.91k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d re =
 6397|  5.91k|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 6398|  5.91k|  for (size_t i = (size_t)0U;
 6399|   100k|       i < Eurydice_slice_len(serialized, uint8_t) / (size_t)24U; i++) {
  ------------------
  |  |  173|   100k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (6399:8): [True: 94.6k, False: 5.91k]
  ------------------
 6400|  94.6k|    size_t i0 = i;
 6401|  94.6k|    Eurydice_slice bytes =
 6402|  94.6k|        Eurydice_slice_subslice3(serialized, i0 * (size_t)24U,
  ------------------
  |  |  195|  94.6k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  94.6k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  94.6k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6403|  94.6k|                                 i0 * (size_t)24U + (size_t)24U, uint8_t *);
 6404|  94.6k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 6405|  94.6k|        libcrux_ml_kem_vector_portable_deserialize_12_b8(bytes);
 6406|  94.6k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 6407|  94.6k|        libcrux_ml_kem_vector_portable_cond_subtract_3329_b8(coefficient);
 6408|  94.6k|    re.coefficients[i0] = uu____0;
 6409|  94.6k|  }
 6410|  5.91k|  return re;
 6411|  5.91k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_cond_subtract_3329_b8:
 3935|  94.6k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector v) {
 3936|  94.6k|  return libcrux_ml_kem_vector_portable_arithmetic_cond_subtract_3329(v);
 3937|  94.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_cond_subtract_3329:
 3916|  94.6k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec) {
 3917|  94.6k|  for (size_t i = (size_t)0U;
 3918|  1.60M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  1.60M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3918:8): [True: 1.51M, False: 94.6k]
  ------------------
 3919|  1.51M|    size_t i0 = i;
 3920|  1.51M|    if (libcrux_secrets_int_public_integers_declassify_d8_39(
  ------------------
  |  Branch (3920:9): [True: 0, False: 1.51M]
  ------------------
 3921|  1.51M|            vec.elements[i0]) >= (int16_t)3329) {
 3922|      0|      size_t uu____0 = i0;
 3923|      0|      vec.elements[uu____0] = vec.elements[uu____0] - (int16_t)3329;
 3924|      0|    }
 3925|  1.51M|  }
 3926|  94.6k|  return vec;
 3927|  94.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_into_padded_array_b6:
  903|  1.97k|    Eurydice_slice slice, uint8_t ret[34U]) {
  904|  1.97k|  uint8_t out[34U] = {0U};
  905|  1.97k|  uint8_t *uu____0 = out;
  906|  1.97k|  Eurydice_slice_copy(
  ------------------
  |  |  229|  1.97k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
  907|  1.97k|      Eurydice_array_to_subslice3(
  908|  1.97k|          uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *),
  909|  1.97k|      slice, uint8_t);
  910|  1.97k|  memcpy(ret, out, (size_t)34U * sizeof(uint8_t));
  911|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_sample_matrix_A_2b:
 6854|  1.97k|    uint8_t *seed, bool transpose) {
 6855|  7.88k|  for (size_t i0 = (size_t)0U; i0 < (size_t)3U; i0++) {
  ------------------
  |  Branch (6855:32): [True: 5.91k, False: 1.97k]
  ------------------
 6856|  5.91k|    size_t i1 = i0;
 6857|  5.91k|    uint8_t seeds[3U][34U];
 6858|  23.6k|    for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6858:33): [True: 17.7k, False: 5.91k]
  ------------------
 6859|  17.7k|      core_array__core__clone__Clone_for__Array_T__N___clone(
  ------------------
  |  |  236|  17.7k|  (memcpy(dst, src, len * sizeof(elem_type)))
  ------------------
 6860|  17.7k|          (size_t)34U, seed, seeds[i], uint8_t, void *);
 6861|  17.7k|    }
 6862|  23.6k|    for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6862:33): [True: 17.7k, False: 5.91k]
  ------------------
 6863|  17.7k|      size_t j = i;
 6864|  17.7k|      seeds[j][32U] = (uint8_t)i1;
 6865|  17.7k|      seeds[j][33U] = (uint8_t)j;
 6866|  17.7k|    }
 6867|  5.91k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d sampled[3U];
 6868|  5.91k|    libcrux_ml_kem_sampling_sample_from_xof_2b(seeds, sampled);
 6869|  5.91k|    for (size_t i = (size_t)0U;
 6870|  23.6k|         i < Eurydice_slice_len(
  ------------------
  |  |  173|  23.6k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (6870:10): [True: 17.7k, False: 5.91k]
  ------------------
 6871|  5.91k|                 Eurydice_array_to_slice(
 6872|  5.91k|                     (size_t)3U, sampled,
 6873|  5.91k|                     libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 6874|  5.91k|                 libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 6875|  17.7k|         i++) {
 6876|  17.7k|      size_t j = i;
 6877|  17.7k|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d sample = sampled[j];
 6878|  17.7k|      if (transpose) {
  ------------------
  |  Branch (6878:11): [True: 5.91k, False: 11.8k]
  ------------------
 6879|  5.91k|        A_transpose[j][i1] = sample;
 6880|  11.8k|      } else {
 6881|  11.8k|        A_transpose[i1][j] = sample;
 6882|  11.8k|      }
 6883|  17.7k|    }
 6884|  5.91k|  }
 6885|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_xof_2b:
 6808|  5.91k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret[3U]) {
 6809|  5.91k|  size_t sampled_coefficients[3U] = {0U};
 6810|  5.91k|  int16_t out[3U][272U] = {{0U}};
 6811|  5.91k|  libcrux_ml_kem_hash_functions_portable_PortableHash_88 xof_state =
 6812|  5.91k|      libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_4a_e0(
 6813|  5.91k|          seeds);
 6814|  5.91k|  uint8_t randomness0[3U][504U];
 6815|  5.91k|  libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_4a_e0(
 6816|  5.91k|      &xof_state, randomness0);
 6817|  5.91k|  bool done = libcrux_ml_kem_sampling_sample_from_uniform_distribution_next_89(
 6818|  5.91k|      randomness0, sampled_coefficients, out);
 6819|  6.00k|  while (true) {
  ------------------
  |  Branch (6819:10): [True: 6.00k, Folded]
  ------------------
 6820|  6.00k|    if (done) {
  ------------------
  |  Branch (6820:9): [True: 5.91k, False: 90]
  ------------------
 6821|  5.91k|      break;
 6822|  5.91k|    } else {
 6823|     90|      uint8_t randomness[3U][168U];
 6824|     90|      libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_4a_e0(
 6825|     90|          &xof_state, randomness);
 6826|     90|      done = libcrux_ml_kem_sampling_sample_from_uniform_distribution_next_890(
 6827|     90|          randomness, sampled_coefficients, out);
 6828|     90|    }
 6829|  6.00k|  }
 6830|       |  /* Passing arrays by value in Rust generates a copy in C */
 6831|  5.91k|  int16_t copy_of_out[3U][272U];
 6832|  5.91k|  memcpy(copy_of_out, out, (size_t)3U * sizeof(int16_t[272U]));
 6833|  5.91k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret0[3U];
 6834|  23.6k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6834:31): [True: 17.7k, False: 5.91k]
  ------------------
 6835|       |    /* original Rust expression is not an lvalue in C */
 6836|  17.7k|    void *lvalue = (void *)0U;
 6837|  17.7k|    ret0[i] = libcrux_ml_kem_sampling_sample_from_xof_call_mut_e7_2b(
 6838|  17.7k|        &lvalue, copy_of_out[i]);
 6839|  17.7k|  }
 6840|  5.91k|  memcpy(
 6841|  5.91k|      ret, ret0,
 6842|  5.91k|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 6843|  5.91k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_4a_e0:
 6489|  5.91k|    uint8_t (*input)[34U]) {
 6490|  5.91k|  return libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_e0(
 6491|  5.91k|      input);
 6492|  5.91k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_e0:
 6460|  5.91k|    uint8_t (*input)[34U]) {
 6461|  5.91k|  libcrux_ml_kem_hash_functions_portable_PortableHash_88 shake128_state;
 6462|  5.91k|  libcrux_sha3_generic_keccak_KeccakState_17 repeat_expression[3U];
 6463|  23.6k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6463:31): [True: 17.7k, False: 5.91k]
  ------------------
 6464|  17.7k|    repeat_expression[i] = libcrux_sha3_portable_incremental_shake128_init();
 6465|  17.7k|  }
 6466|  5.91k|  memcpy(shake128_state.shake128_state, repeat_expression,
 6467|  5.91k|         (size_t)3U * sizeof(libcrux_sha3_generic_keccak_KeccakState_17));
 6468|  23.6k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6468:31): [True: 17.7k, False: 5.91k]
  ------------------
 6469|  17.7k|    size_t i0 = i;
 6470|  17.7k|    libcrux_sha3_portable_incremental_shake128_absorb_final(
 6471|  17.7k|        &shake128_state.shake128_state[i0],
 6472|  17.7k|        Eurydice_array_to_slice((size_t)34U, input[i0], uint8_t));
  ------------------
  |  |  204|  17.7k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  17.7k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  17.7k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  17.7k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6473|  17.7k|  }
 6474|  5.91k|  return shake128_state;
 6475|  5.91k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_incremental_shake128_init:
 3466|  17.7k|libcrux_sha3_portable_incremental_shake128_init(void) {
 3467|  17.7k|  return libcrux_sha3_generic_keccak_new_80_04();
 3468|  17.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_incremental_shake128_absorb_final:
 3563|  17.7k|    libcrux_sha3_generic_keccak_KeccakState_17 *s, Eurydice_slice data0) {
 3564|  17.7k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____0 = s;
 3565|  17.7k|  Eurydice_slice uu____1[1U] = {data0};
 3566|  17.7k|  libcrux_sha3_generic_keccak_absorb_final_80_9e2(
 3567|  17.7k|      uu____0, uu____1, (size_t)0U, Eurydice_slice_len(data0, uint8_t));
  ------------------
  |  |  173|  17.7k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3568|  17.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_final_80_9e2:
 3553|  17.7k|    size_t start, size_t len) {
 3554|  17.7k|  libcrux_sha3_simd_portable_load_last_a1_c6(self, last, start, len);
 3555|  17.7k|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3556|  17.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_a1_c6:
 3535|  17.7k|    size_t start, size_t len) {
 3536|  17.7k|  libcrux_sha3_simd_portable_load_last_c6(self->st, input[0U], start, len);
 3537|  17.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_c6:
 3508|  17.7k|    uint64_t *state, Eurydice_slice blocks, size_t start, size_t len) {
 3509|  17.7k|  uint8_t buffer[168U] = {0U};
 3510|  17.7k|  Eurydice_slice_copy(
  ------------------
  |  |  229|  17.7k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3511|  17.7k|      Eurydice_array_to_subslice3(buffer, (size_t)0U, len, uint8_t *),
 3512|  17.7k|      Eurydice_slice_subslice3(blocks, start, start + len, uint8_t *), uint8_t);
 3513|  17.7k|  buffer[len] = 31U;
 3514|  17.7k|  size_t uu____0 = (size_t)168U - (size_t)1U;
 3515|  17.7k|  buffer[uu____0] = (uint32_t)buffer[uu____0] | 128U;
 3516|  17.7k|  libcrux_sha3_simd_portable_load_block_3a(
 3517|  17.7k|      state, Eurydice_array_to_slice((size_t)168U, buffer, uint8_t),
  ------------------
  |  |  204|  17.7k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  17.7k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  17.7k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  17.7k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3518|  17.7k|      (size_t)0U);
 3519|  17.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_block_3a:
 3476|  17.7k|    uint64_t *state, Eurydice_slice blocks, size_t start) {
 3477|  17.7k|  uint64_t state_flat[25U] = {0U};
 3478|   390k|  for (size_t i = (size_t)0U; i < (size_t)168U / (size_t)8U; i++) {
  ------------------
  |  Branch (3478:31): [True: 372k, False: 17.7k]
  ------------------
 3479|   372k|    size_t i0 = i;
 3480|   372k|    size_t offset = start + (size_t)8U * i0;
 3481|   372k|    uint8_t uu____0[8U];
 3482|   372k|    Result_15 dst;
 3483|   372k|    Eurydice_slice_to_array2(
  ------------------
  |  |  277|   372k|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|   372k|                           sizeof(t_arr))
  ------------------
 3484|   372k|        &dst,
 3485|   372k|        Eurydice_slice_subslice3(blocks, offset, offset + (size_t)8U,
 3486|   372k|                                 uint8_t *),
 3487|   372k|        Eurydice_slice, uint8_t[8U], TryFromSliceError);
 3488|   372k|    unwrap_26_68(dst, uu____0);
 3489|   372k|    state_flat[i0] = core_num__u64__from_le_bytes(uu____0);
 3490|   372k|  }
 3491|   390k|  for (size_t i = (size_t)0U; i < (size_t)168U / (size_t)8U; i++) {
  ------------------
  |  Branch (3491:31): [True: 372k, False: 17.7k]
  ------------------
 3492|   372k|    size_t i0 = i;
 3493|   372k|    libcrux_sha3_traits_set_ij_04(
 3494|   372k|        state, i0 / (size_t)5U, i0 % (size_t)5U,
 3495|   372k|        libcrux_sha3_traits_get_ij_04(state, i0 / (size_t)5U,
 3496|   372k|                                      i0 % (size_t)5U)[0U] ^
 3497|   372k|            state_flat[i0]);
 3498|   372k|  }
 3499|  17.7k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_4a_e0:
 6527|  5.91k|    uint8_t ret[3U][504U]) {
 6528|  5.91k|  libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_e0(
 6529|  5.91k|      self, ret);
 6530|  5.91k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_e0:
 6503|  5.91k|    uint8_t ret[3U][504U]) {
 6504|  5.91k|  uint8_t out[3U][504U] = {{0U}};
 6505|  23.6k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6505:31): [True: 17.7k, False: 5.91k]
  ------------------
 6506|  17.7k|    size_t i0 = i;
 6507|  17.7k|    libcrux_sha3_portable_incremental_shake128_squeeze_first_three_blocks(
 6508|  17.7k|        &st->shake128_state[i0],
 6509|  17.7k|        Eurydice_array_to_slice((size_t)504U, out[i0], uint8_t));
  ------------------
  |  |  204|  17.7k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  17.7k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  17.7k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  17.7k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6510|  17.7k|  }
 6511|  5.91k|  memcpy(ret, out, (size_t)3U * sizeof(uint8_t[504U]));
 6512|  5.91k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_incremental_shake128_squeeze_first_three_blocks:
 3652|  17.7k|    libcrux_sha3_generic_keccak_KeccakState_17 *s, Eurydice_slice out0) {
 3653|  17.7k|  libcrux_sha3_generic_keccak_portable_squeeze_first_three_blocks_b4_3a(s,
 3654|  17.7k|                                                                        out0);
 3655|  17.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_squeeze_first_three_blocks_b4_3a:
 3637|  17.7k|    libcrux_sha3_generic_keccak_KeccakState_17 *self, Eurydice_slice out) {
 3638|  17.7k|  libcrux_sha3_simd_portable_squeeze_13_3a(self, out, (size_t)0U, (size_t)168U);
 3639|  17.7k|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3640|  17.7k|  libcrux_sha3_simd_portable_squeeze_13_3a(self, out, (size_t)168U,
 3641|  17.7k|                                           (size_t)168U);
 3642|  17.7k|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3643|  17.7k|  libcrux_sha3_simd_portable_squeeze_13_3a(self, out, (size_t)2U * (size_t)168U,
 3644|  17.7k|                                           (size_t)168U);
 3645|  17.7k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_squeeze_13_3a:
 3619|  53.4k|    size_t start, size_t len) {
 3620|  53.4k|  libcrux_sha3_simd_portable_store_block_3a(self->st, out, start, len);
 3621|  53.4k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_store_block_3a:
 3576|  53.4k|    uint64_t *s, Eurydice_slice out, size_t start, size_t len) {
 3577|  53.4k|  size_t octets = len / (size_t)8U;
 3578|  1.17M|  for (size_t i = (size_t)0U; i < octets; i++) {
  ------------------
  |  Branch (3578:31): [True: 1.12M, False: 53.4k]
  ------------------
 3579|  1.12M|    size_t i0 = i;
 3580|  1.12M|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  1.12M|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  1.12M|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.12M|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3581|  1.12M|        out, start + (size_t)8U * i0, start + (size_t)8U * i0 + (size_t)8U,
 3582|  1.12M|        uint8_t *);
 3583|  1.12M|    uint8_t ret[8U];
 3584|  1.12M|    core_num__u64__to_le_bytes(
 3585|  1.12M|        libcrux_sha3_traits_get_ij_04(s, i0 / (size_t)5U, i0 % (size_t)5U)[0U],
 3586|  1.12M|        ret);
 3587|  1.12M|    Eurydice_slice_copy(
  ------------------
  |  |  229|  1.12M|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3588|  1.12M|        uu____0, Eurydice_array_to_slice((size_t)8U, ret, uint8_t), uint8_t);
 3589|  1.12M|  }
 3590|  53.4k|  size_t remaining = len % (size_t)8U;
 3591|  53.4k|  if (remaining > (size_t)0U) {
  ------------------
  |  Branch (3591:7): [True: 0, False: 53.4k]
  ------------------
 3592|      0|    Eurydice_slice uu____1 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|      0|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|      0|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|      0|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3593|      0|        out, start + len - remaining, start + len, uint8_t *);
 3594|      0|    uint8_t ret[8U];
 3595|      0|    core_num__u64__to_le_bytes(
 3596|      0|        libcrux_sha3_traits_get_ij_04(s, octets / (size_t)5U,
 3597|      0|                                      octets % (size_t)5U)[0U],
 3598|      0|        ret);
 3599|      0|    Eurydice_slice_copy(
  ------------------
  |  |  229|      0|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3600|      0|        uu____1,
 3601|      0|        Eurydice_array_to_subslice3(ret, (size_t)0U, remaining, uint8_t *),
 3602|      0|        uint8_t);
 3603|      0|  }
 3604|  53.4k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_uniform_distribution_next_89:
 6583|  5.91k|    int16_t (*out)[272U]) {
 6584|  23.6k|  for (size_t i0 = (size_t)0U; i0 < (size_t)3U; i0++) {
  ------------------
  |  Branch (6584:32): [True: 17.7k, False: 5.91k]
  ------------------
 6585|  17.7k|    size_t i1 = i0;
 6586|   390k|    for (size_t i = (size_t)0U; i < (size_t)504U / (size_t)24U; i++) {
  ------------------
  |  Branch (6586:33): [True: 372k, False: 17.7k]
  ------------------
 6587|   372k|      size_t r = i;
 6588|   372k|      if (sampled_coefficients[i1] <
  ------------------
  |  Branch (6588:11): [True: 357k, False: 15.2k]
  ------------------
 6589|   372k|          LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT) {
  ------------------
  |  |  447|   372k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6590|   357k|        size_t sampled = libcrux_ml_kem_vector_portable_rej_sample_b8(
 6591|   357k|            Eurydice_array_to_subslice3(randomness[i1], r * (size_t)24U,
  ------------------
  |  |  215|   357k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   357k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   357k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6592|   357k|                                        r * (size_t)24U + (size_t)24U,
 6593|   357k|                                        uint8_t *),
 6594|   357k|            Eurydice_array_to_subslice3(out[i1], sampled_coefficients[i1],
  ------------------
  |  |  215|   357k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   357k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   357k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6595|   357k|                                        sampled_coefficients[i1] + (size_t)16U,
 6596|   357k|                                        int16_t *));
 6597|   357k|        size_t uu____0 = i1;
 6598|   357k|        sampled_coefficients[uu____0] = sampled_coefficients[uu____0] + sampled;
 6599|   357k|      }
 6600|   372k|    }
 6601|  17.7k|  }
 6602|  5.91k|  bool done = true;
 6603|  23.6k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6603:31): [True: 17.7k, False: 5.91k]
  ------------------
 6604|  17.7k|    size_t i0 = i;
 6605|  17.7k|    if (sampled_coefficients[i0] >=
  ------------------
  |  Branch (6605:9): [True: 17.6k, False: 90]
  ------------------
 6606|  17.7k|        LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT) {
  ------------------
  |  |  447|  17.7k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6607|  17.6k|      sampled_coefficients[i0] =
 6608|  17.6k|          LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT;
  ------------------
  |  |  447|  17.6k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6609|  17.6k|    } else {
 6610|       |      done = false;
 6611|     90|    }
 6612|  17.7k|  }
 6613|  5.91k|  return done;
 6614|  5.91k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_rej_sample_b8:
 5219|   357k|    Eurydice_slice a, Eurydice_slice out) {
 5220|   357k|  return libcrux_ml_kem_vector_portable_sampling_rej_sample(a, out);
 5221|   357k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_sampling_rej_sample:
 5185|   357k|                                                   Eurydice_slice result) {
 5186|   357k|  size_t sampled = (size_t)0U;
 5187|  3.21M|  for (size_t i = (size_t)0U; i < Eurydice_slice_len(a, uint8_t) / (size_t)3U;
  ------------------
  |  |  173|  3.21M|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5187:31): [True: 2.85M, False: 357k]
  ------------------
 5188|  2.85M|       i++) {
 5189|  2.85M|    size_t i0 = i;
 5190|  2.85M|    int16_t b1 = (int16_t)Eurydice_slice_index(a, i0 * (size_t)3U + (size_t)0U,
  ------------------
  |  |  180|  2.85M|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5191|  2.85M|                                               uint8_t, uint8_t *);
 5192|  2.85M|    int16_t b2 = (int16_t)Eurydice_slice_index(a, i0 * (size_t)3U + (size_t)1U,
  ------------------
  |  |  180|  2.85M|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5193|  2.85M|                                               uint8_t, uint8_t *);
 5194|  2.85M|    int16_t b3 = (int16_t)Eurydice_slice_index(a, i0 * (size_t)3U + (size_t)2U,
  ------------------
  |  |  180|  2.85M|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5195|  2.85M|                                               uint8_t, uint8_t *);
 5196|  2.85M|    int16_t d1 = (b2 & (int16_t)15) << 8U | b1;
 5197|  2.85M|    int16_t d2 = b3 << 4U | b2 >> 4U;
 5198|  2.85M|    if (d1 < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS) {
  ------------------
  |  | 3777|  2.85M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
  |  Branch (5198:9): [True: 2.32M, False: 535k]
  ------------------
 5199|  2.32M|      if (sampled < (size_t)16U) {
  ------------------
  |  Branch (5199:11): [True: 2.32M, False: 0]
  ------------------
 5200|  2.32M|        Eurydice_slice_index(result, sampled, int16_t, int16_t *) = d1;
  ------------------
  |  |  180|  2.32M|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5201|  2.32M|        sampled++;
 5202|  2.32M|      }
 5203|  2.32M|    }
 5204|  2.85M|    if (d2 < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS) {
  ------------------
  |  | 3777|  2.85M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
  |  Branch (5204:9): [True: 2.32M, False: 533k]
  ------------------
 5205|  2.32M|      if (sampled < (size_t)16U) {
  ------------------
  |  Branch (5205:11): [True: 2.32M, False: 0]
  ------------------
 5206|  2.32M|        Eurydice_slice_index(result, sampled, int16_t, int16_t *) = d2;
  ------------------
  |  |  180|  2.32M|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5207|  2.32M|        sampled++;
 5208|  2.32M|      }
 5209|  2.32M|    }
 5210|  2.85M|  }
 5211|   357k|  return sampled;
 5212|   357k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_4a_e0:
 6649|     90|    uint8_t ret[3U][168U]) {
 6650|     90|  libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_e0(self,
 6651|     90|                                                                        ret);
 6652|     90|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_e0:
 6625|     90|    uint8_t ret[3U][168U]) {
 6626|     90|  uint8_t out[3U][168U] = {{0U}};
 6627|    360|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6627:31): [True: 270, False: 90]
  ------------------
 6628|    270|    size_t i0 = i;
 6629|    270|    libcrux_sha3_portable_incremental_shake128_squeeze_next_block(
 6630|    270|        &st->shake128_state[i0],
 6631|    270|        Eurydice_array_to_slice((size_t)168U, out[i0], uint8_t));
  ------------------
  |  |  204|    270|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    270|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    270|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    270|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6632|    270|  }
 6633|     90|  memcpy(ret, out, (size_t)3U * sizeof(uint8_t[168U]));
 6634|     90|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_incremental_shake128_squeeze_next_block:
 3681|    270|    libcrux_sha3_generic_keccak_KeccakState_17 *s, Eurydice_slice out0) {
 3682|    270|  libcrux_sha3_generic_keccak_portable_squeeze_next_block_b4_3a(s, out0,
 3683|    270|                                                                (size_t)0U);
 3684|    270|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_squeeze_next_block_b4_3a:
 3671|    270|    size_t start) {
 3672|    270|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3673|    270|  libcrux_sha3_simd_portable_squeeze_13_3a(self, out, start, (size_t)168U);
 3674|    270|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_uniform_distribution_next_890:
 6705|     90|    int16_t (*out)[272U]) {
 6706|    360|  for (size_t i0 = (size_t)0U; i0 < (size_t)3U; i0++) {
  ------------------
  |  Branch (6706:32): [True: 270, False: 90]
  ------------------
 6707|    270|    size_t i1 = i0;
 6708|  2.16k|    for (size_t i = (size_t)0U; i < (size_t)168U / (size_t)24U; i++) {
  ------------------
  |  Branch (6708:33): [True: 1.89k, False: 270]
  ------------------
 6709|  1.89k|      size_t r = i;
 6710|  1.89k|      if (sampled_coefficients[i1] <
  ------------------
  |  Branch (6710:11): [True: 90, False: 1.80k]
  ------------------
 6711|  1.89k|          LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT) {
  ------------------
  |  |  447|  1.89k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6712|     90|        size_t sampled = libcrux_ml_kem_vector_portable_rej_sample_b8(
 6713|     90|            Eurydice_array_to_subslice3(randomness[i1], r * (size_t)24U,
  ------------------
  |  |  215|     90|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|     90|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|     90|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6714|     90|                                        r * (size_t)24U + (size_t)24U,
 6715|     90|                                        uint8_t *),
 6716|     90|            Eurydice_array_to_subslice3(out[i1], sampled_coefficients[i1],
  ------------------
  |  |  215|     90|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|     90|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|     90|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6717|     90|                                        sampled_coefficients[i1] + (size_t)16U,
 6718|     90|                                        int16_t *));
 6719|     90|        size_t uu____0 = i1;
 6720|     90|        sampled_coefficients[uu____0] = sampled_coefficients[uu____0] + sampled;
 6721|     90|      }
 6722|  1.89k|    }
 6723|    270|  }
 6724|     90|  bool done = true;
 6725|    360|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6725:31): [True: 270, False: 90]
  ------------------
 6726|    270|    size_t i0 = i;
 6727|    270|    if (sampled_coefficients[i0] >=
  ------------------
  |  Branch (6727:9): [True: 270, False: 0]
  ------------------
 6728|    270|        LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT) {
  ------------------
  |  |  447|    270|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6729|    270|      sampled_coefficients[i0] =
 6730|    270|          LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT;
  ------------------
  |  |  447|    270|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6731|    270|    } else {
 6732|       |      done = false;
 6733|      0|    }
 6734|    270|  }
 6735|     90|  return done;
 6736|     90|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_xof_call_mut_e7_2b:
 6792|  17.7k|    void **_, int16_t tupled_args[272U]) {
 6793|  17.7k|  int16_t s[272U];
 6794|  17.7k|  memcpy(s, tupled_args, (size_t)272U * sizeof(int16_t));
 6795|  17.7k|  return libcrux_ml_kem_polynomial_from_i16_array_d6_ea(
 6796|  17.7k|      Eurydice_array_to_subslice3(s, (size_t)0U, (size_t)256U, int16_t *));
  ------------------
  |  |  215|  17.7k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  17.7k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  17.7k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6797|  17.7k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_from_i16_array_d6_ea:
 6773|  30.8k|libcrux_ml_kem_polynomial_from_i16_array_d6_ea(Eurydice_slice a) {
 6774|  30.8k|  return libcrux_ml_kem_polynomial_from_i16_array_ea(a);
 6775|  30.8k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_from_i16_array_ea:
 6745|  30.8k|libcrux_ml_kem_polynomial_from_i16_array_ea(Eurydice_slice a) {
 6746|  30.8k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d result =
 6747|  30.8k|      libcrux_ml_kem_polynomial_ZERO_ea();
 6748|  30.8k|  for (size_t i = (size_t)0U;
 6749|   524k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|   524k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (6749:8): [True: 494k, False: 30.8k]
  ------------------
 6750|   494k|    size_t i0 = i;
 6751|   494k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 6752|   494k|        libcrux_ml_kem_vector_portable_from_i16_array_b8(
 6753|   494k|            Eurydice_slice_subslice3(a, i0 * (size_t)16U,
  ------------------
  |  |  195|   494k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   494k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   494k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6754|   494k|                                     (i0 + (size_t)1U) * (size_t)16U,
 6755|   494k|                                     int16_t *));
 6756|   494k|    result.coefficients[i0] = uu____0;
 6757|   494k|  }
 6758|  30.8k|  return result;
 6759|  30.8k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_from_i16_array_b8:
 3805|   494k|libcrux_ml_kem_vector_portable_from_i16_array_b8(Eurydice_slice array) {
 3806|   494k|  return libcrux_ml_kem_vector_portable_vector_type_from_i16_array(
 3807|   494k|      libcrux_secrets_int_classify_public_classify_ref_9b_39(array));
 3808|   494k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_vector_type_from_i16_array:
 3788|   494k|    Eurydice_slice array) {
 3789|   494k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector lit;
 3790|   494k|  int16_t ret[16U];
 3791|   494k|  Result_0a dst;
 3792|   494k|  Eurydice_slice_to_array2(
  ------------------
  |  |  277|   494k|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|   494k|                           sizeof(t_arr))
  ------------------
 3793|   494k|      &dst, Eurydice_slice_subslice3(array, (size_t)0U, (size_t)16U, int16_t *),
 3794|   494k|      Eurydice_slice, int16_t[16U], TryFromSliceError);
 3795|   494k|  unwrap_26_00(dst, ret);
 3796|   494k|  memcpy(lit.elements, ret, (size_t)16U * sizeof(int16_t));
 3797|   494k|  return lit;
 3798|   494k|}
libcrux_mlkem768_sha3.c:unwrap_26_00:
 1129|   494k|static inline void unwrap_26_00(Result_0a self, int16_t ret[16U]) {
 1130|   494k|  if (self.tag == Ok) {
  ------------------
  |  |  721|   494k|#define Ok 0
  ------------------
  |  Branch (1130:7): [True: 494k, False: 0]
  ------------------
 1131|   494k|    int16_t f0[16U];
 1132|   494k|    memcpy(f0, self.val.case_Ok, (size_t)16U * sizeof(int16_t));
 1133|   494k|    memcpy(ret, f0, (size_t)16U * sizeof(int16_t));
 1134|   494k|  } else {
 1135|      0|    KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", __FILE__, __LINE__,
 1136|      0|                      "unwrap not Ok");
 1137|       |    KRML_HOST_EXIT(255U);
  ------------------
  |  |   41|      0|#define KRML_HOST_EXIT(x) do { \
  |  |   42|      0|    fprintf(stderr, "mlkem internal error"); \
  |  |   43|      0|    exit(x); \
  |  |   44|      0|} while (0)
  |  |  ------------------
  |  |  |  Branch (44:10): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1138|      0|  }
 1139|   494k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_classify_public_classify_ref_9b_39:
 1103|   494k|libcrux_secrets_int_classify_public_classify_ref_9b_39(Eurydice_slice self) {
 1104|   494k|  return self;
 1105|   494k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_encrypt_unpacked_2a:
 7838|  1.31k|    uint8_t *message, Eurydice_slice randomness, uint8_t ret[1088U]) {
 7839|  1.31k|  uint8_t ciphertext[1088U] = {0U};
 7840|  1.31k|  tuple_ed uu____0 = libcrux_ml_kem_ind_cpa_encrypt_c1_85(
 7841|  1.31k|      randomness, public_key->A,
 7842|  1.31k|      Eurydice_array_to_subslice3(ciphertext, (size_t)0U, (size_t)960U,
  ------------------
  |  |  215|  1.31k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  1.31k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.31k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7843|  1.31k|                                  uint8_t *));
 7844|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d r_as_ntt[3U];
 7845|  1.31k|  memcpy(
 7846|  1.31k|      r_as_ntt, uu____0.fst,
 7847|  1.31k|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 7848|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d error_2 = uu____0.snd;
 7849|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d *uu____1 =
 7850|  1.31k|      public_key->t_as_ntt;
 7851|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d *uu____2 = r_as_ntt;
 7852|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d *uu____3 = &error_2;
 7853|  1.31k|  uint8_t *uu____4 = message;
 7854|  1.31k|  libcrux_ml_kem_ind_cpa_encrypt_c2_6c(
 7855|  1.31k|      uu____1, uu____2, uu____3, uu____4,
 7856|  1.31k|      Eurydice_array_to_subslice_from((size_t)1088U, ciphertext, (size_t)960U,
  ------------------
  |  |  225|  1.31k|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|  1.31k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.31k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7857|  1.31k|                                      uint8_t, size_t, uint8_t[]));
 7858|  1.31k|  memcpy(ret, ciphertext, (size_t)1088U * sizeof(uint8_t));
 7859|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_encrypt_c1_85:
 7528|  1.31k|    Eurydice_slice ciphertext) {
 7529|  1.31k|  uint8_t prf_input[33U];
 7530|  1.31k|  libcrux_ml_kem_utils_into_padded_array_c8(randomness, prf_input);
 7531|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d r_as_ntt[3U];
 7532|  5.25k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7532:31): [True: 3.94k, False: 1.31k]
  ------------------
 7533|       |    /* original Rust expression is not an lvalue in C */
 7534|  3.94k|    void *lvalue = (void *)0U;
 7535|  3.94k|    r_as_ntt[i] = libcrux_ml_kem_ind_cpa_encrypt_c1_call_mut_f1_85(&lvalue, i);
 7536|  3.94k|  }
 7537|  1.31k|  uint8_t domain_separator0 =
 7538|  1.31k|      libcrux_ml_kem_ind_cpa_sample_vector_cbd_then_ntt_3b(r_as_ntt, prf_input,
 7539|  1.31k|                                                           0U);
 7540|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d error_1[3U];
 7541|  5.25k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7541:31): [True: 3.94k, False: 1.31k]
  ------------------
 7542|       |    /* original Rust expression is not an lvalue in C */
 7543|  3.94k|    void *lvalue = (void *)0U;
 7544|  3.94k|    error_1[i] = libcrux_ml_kem_ind_cpa_encrypt_c1_call_mut_dd_85(&lvalue, i);
 7545|  3.94k|  }
 7546|  1.31k|  uint8_t domain_separator = libcrux_ml_kem_ind_cpa_sample_ring_element_cbd_3b(
 7547|  1.31k|      prf_input, domain_separator0, error_1);
 7548|  1.31k|  prf_input[32U] = domain_separator;
 7549|  1.31k|  uint8_t prf_output[128U];
 7550|  1.31k|  libcrux_ml_kem_hash_functions_portable_PRF_4a_410(
 7551|  1.31k|      Eurydice_array_to_slice((size_t)33U, prf_input, uint8_t), prf_output);
  ------------------
  |  |  204|  1.31k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  1.31k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.31k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  1.31k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7552|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d error_2 =
 7553|  1.31k|      libcrux_ml_kem_sampling_sample_from_binomial_distribution_a0(
 7554|  1.31k|          Eurydice_array_to_slice((size_t)128U, prf_output, uint8_t));
  ------------------
  |  |  204|  1.31k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  1.31k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.31k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  1.31k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7555|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d u[3U];
 7556|  1.31k|  libcrux_ml_kem_matrix_compute_vector_u_1b(matrix, r_as_ntt, error_1, u);
 7557|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0[3U];
 7558|  1.31k|  memcpy(
 7559|  1.31k|      uu____0, u,
 7560|  1.31k|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 7561|  1.31k|  libcrux_ml_kem_ind_cpa_compress_then_serialize_u_43(uu____0, ciphertext);
 7562|       |  /* Passing arrays by value in Rust generates a copy in C */
 7563|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d copy_of_r_as_ntt[3U];
 7564|  1.31k|  memcpy(
 7565|  1.31k|      copy_of_r_as_ntt, r_as_ntt,
 7566|  1.31k|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 7567|  1.31k|  tuple_ed lit;
 7568|  1.31k|  memcpy(
 7569|  1.31k|      lit.fst, copy_of_r_as_ntt,
 7570|  1.31k|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 7571|  1.31k|  lit.snd = error_2;
 7572|  1.31k|  return lit;
 7573|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_into_padded_array_c8:
  884|  1.97k|    Eurydice_slice slice, uint8_t ret[33U]) {
  885|  1.97k|  uint8_t out[33U] = {0U};
  886|  1.97k|  uint8_t *uu____0 = out;
  887|  1.97k|  Eurydice_slice_copy(
  ------------------
  |  |  229|  1.97k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
  888|  1.97k|      Eurydice_array_to_subslice3(
  889|  1.97k|          uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *),
  890|  1.97k|      slice, uint8_t);
  891|  1.97k|  memcpy(ret, out, (size_t)33U * sizeof(uint8_t));
  892|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_encrypt_c1_call_mut_f1_85:
 6968|  3.94k|libcrux_ml_kem_ind_cpa_encrypt_c1_call_mut_f1_85(void **_, size_t tupled_args) {
 6969|  3.94k|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 6970|  3.94k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_sample_vector_cbd_then_ntt_3b:
 7177|  2.62k|    uint8_t *prf_input, uint8_t domain_separator) {
 7178|  2.62k|  uint8_t prf_inputs[3U][33U];
 7179|  10.5k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7179:31): [True: 7.88k, False: 2.62k]
  ------------------
 7180|  7.88k|    core_array__core__clone__Clone_for__Array_T__N___clone(
  ------------------
  |  |  236|  7.88k|  (memcpy(dst, src, len * sizeof(elem_type)))
  ------------------
 7181|  7.88k|        (size_t)33U, prf_input, prf_inputs[i], uint8_t, void *);
 7182|  7.88k|  }
 7183|  2.62k|  domain_separator =
 7184|  2.62k|      libcrux_ml_kem_utils_prf_input_inc_e0(prf_inputs, domain_separator);
 7185|  2.62k|  uint8_t prf_outputs[3U][128U];
 7186|  2.62k|  libcrux_ml_kem_hash_functions_portable_PRFxN_4a_41(prf_inputs, prf_outputs);
 7187|  10.5k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7187:31): [True: 7.88k, False: 2.62k]
  ------------------
 7188|  7.88k|    size_t i0 = i;
 7189|  7.88k|    re_as_ntt[i0] =
 7190|  7.88k|        libcrux_ml_kem_sampling_sample_from_binomial_distribution_a0(
 7191|  7.88k|            Eurydice_array_to_slice((size_t)128U, prf_outputs[i0], uint8_t));
  ------------------
  |  |  204|  7.88k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  7.88k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  7.88k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  7.88k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7192|  7.88k|    libcrux_ml_kem_ntt_ntt_binomially_sampled_ring_element_ea(&re_as_ntt[i0]);
 7193|  7.88k|  }
 7194|  2.62k|  return domain_separator;
 7195|  2.62k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_prf_input_inc_e0:
  866|  3.94k|    uint8_t (*prf_inputs)[33U], uint8_t domain_separator) {
  867|  15.7k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (867:31): [True: 11.8k, False: 3.94k]
  ------------------
  868|  11.8k|    size_t i0 = i;
  869|  11.8k|    prf_inputs[i0][32U] = domain_separator;
  870|  11.8k|    domain_separator = (uint32_t)domain_separator + 1U;
  871|  11.8k|  }
  872|  3.94k|  return domain_separator;
  873|  3.94k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRFxN_4a_41:
 7001|  3.94k|    uint8_t (*input)[33U], uint8_t ret[3U][128U]) {
 7002|  3.94k|  libcrux_ml_kem_hash_functions_portable_PRFxN_41(input, ret);
 7003|  3.94k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRFxN_41:
 6979|  3.94k|    uint8_t (*input)[33U], uint8_t ret[3U][128U]) {
 6980|  3.94k|  uint8_t out[3U][128U] = {{0U}};
 6981|  15.7k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6981:31): [True: 11.8k, False: 3.94k]
  ------------------
 6982|  11.8k|    size_t i0 = i;
 6983|  11.8k|    libcrux_sha3_portable_shake256(
 6984|  11.8k|        Eurydice_array_to_slice((size_t)128U, out[i0], uint8_t),
  ------------------
  |  |  204|  11.8k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  11.8k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  11.8k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  11.8k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6985|  11.8k|        Eurydice_array_to_slice((size_t)33U, input[i0], uint8_t));
  ------------------
  |  |  204|  11.8k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  11.8k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  11.8k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  11.8k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6986|  11.8k|  }
 6987|  3.94k|  memcpy(ret, out, (size_t)3U * sizeof(uint8_t[128U]));
 6988|  3.94k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_binomially_sampled_ring_element_ea:
 7143|  7.88k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 7144|  7.88k|  libcrux_ml_kem_ntt_ntt_at_layer_7_ea(re);
 7145|  7.88k|  size_t zeta_i = (size_t)1U;
 7146|  7.88k|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)6U,
 7147|  7.88k|                                            (size_t)11207U);
 7148|  7.88k|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)5U,
 7149|  7.88k|                                            (size_t)11207U + (size_t)3328U);
 7150|  7.88k|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(
 7151|  7.88k|      &zeta_i, re, (size_t)4U, (size_t)11207U + (size_t)2U * (size_t)3328U);
 7152|  7.88k|  libcrux_ml_kem_ntt_ntt_at_layer_3_ea(
 7153|  7.88k|      &zeta_i, re, (size_t)11207U + (size_t)3U * (size_t)3328U);
 7154|  7.88k|  libcrux_ml_kem_ntt_ntt_at_layer_2_ea(
 7155|  7.88k|      &zeta_i, re, (size_t)11207U + (size_t)4U * (size_t)3328U);
 7156|  7.88k|  libcrux_ml_kem_ntt_ntt_at_layer_1_ea(
 7157|  7.88k|      &zeta_i, re, (size_t)11207U + (size_t)5U * (size_t)3328U);
 7158|  7.88k|  libcrux_ml_kem_polynomial_poly_barrett_reduce_d6_ea(re);
 7159|  7.88k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_7_ea:
 7120|  7.88k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 7121|  7.88k|  size_t step = LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT / (size_t)2U;
  ------------------
  |  | 3770|  7.88k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
 7122|  70.9k|  for (size_t i = (size_t)0U; i < step; i++) {
  ------------------
  |  Branch (7122:31): [True: 63.0k, False: 7.88k]
  ------------------
 7123|  63.0k|    size_t j = i;
 7124|  63.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector t =
 7125|  63.0k|        libcrux_ml_kem_vector_portable_multiply_by_constant_b8(
 7126|  63.0k|            re->coefficients[j + step], (int16_t)-1600);
 7127|  63.0k|    re->coefficients[j + step] =
 7128|  63.0k|        libcrux_ml_kem_vector_portable_sub_b8(re->coefficients[j], &t);
 7129|  63.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____1 =
 7130|  63.0k|        libcrux_ml_kem_vector_portable_add_b8(re->coefficients[j], &t);
 7131|  63.0k|    re->coefficients[j] = uu____1;
 7132|  63.0k|  }
 7133|  7.88k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_multiply_by_constant_b8:
 3906|  63.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec, int16_t c) {
 3907|  63.0k|  return libcrux_ml_kem_vector_portable_arithmetic_multiply_by_constant(vec, c);
 3908|  63.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_multiply_by_constant:
 3890|  63.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec, int16_t c) {
 3891|  63.0k|  for (size_t i = (size_t)0U;
 3892|  1.07M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  1.07M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3892:8): [True: 1.00M, False: 63.0k]
  ------------------
 3893|  1.00M|    size_t i0 = i;
 3894|  1.00M|    size_t uu____0 = i0;
 3895|  1.00M|    vec.elements[uu____0] = vec.elements[uu____0] * c;
 3896|  1.00M|  }
 3897|  63.0k|  return vec;
 3898|  63.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_encrypt_c1_call_mut_dd_85:
 7220|  3.94k|libcrux_ml_kem_ind_cpa_encrypt_c1_call_mut_dd_85(void **_, size_t tupled_args) {
 7221|  3.94k|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 7222|  3.94k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_sample_ring_element_cbd_3b:
 7239|  1.31k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error_1) {
 7240|  1.31k|  uint8_t prf_inputs[3U][33U];
 7241|  5.25k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7241:31): [True: 3.94k, False: 1.31k]
  ------------------
 7242|  3.94k|    core_array__core__clone__Clone_for__Array_T__N___clone(
  ------------------
  |  |  236|  3.94k|  (memcpy(dst, src, len * sizeof(elem_type)))
  ------------------
 7243|  3.94k|        (size_t)33U, prf_input, prf_inputs[i], uint8_t, void *);
 7244|  3.94k|  }
 7245|  1.31k|  domain_separator =
 7246|  1.31k|      libcrux_ml_kem_utils_prf_input_inc_e0(prf_inputs, domain_separator);
 7247|  1.31k|  uint8_t prf_outputs[3U][128U];
 7248|  1.31k|  libcrux_ml_kem_hash_functions_portable_PRFxN_4a_41(prf_inputs, prf_outputs);
 7249|  5.25k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7249:31): [True: 3.94k, False: 1.31k]
  ------------------
 7250|  3.94k|    size_t i0 = i;
 7251|  3.94k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0 =
 7252|  3.94k|        libcrux_ml_kem_sampling_sample_from_binomial_distribution_a0(
 7253|  3.94k|            Eurydice_array_to_slice((size_t)128U, prf_outputs[i0], uint8_t));
  ------------------
  |  |  204|  3.94k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  3.94k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  3.94k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  3.94k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7254|  3.94k|    error_1[i0] = uu____0;
 7255|  3.94k|  }
 7256|  1.31k|  return domain_separator;
 7257|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRF_4a_410:
 7283|  1.31k|    Eurydice_slice input, uint8_t ret[128U]) {
 7284|  1.31k|  libcrux_ml_kem_hash_functions_portable_PRF_a6(input, ret);
 7285|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRF_a6:
 7265|  1.31k|    Eurydice_slice input, uint8_t ret[128U]) {
 7266|  1.31k|  uint8_t digest[128U] = {0U};
 7267|  1.31k|  libcrux_sha3_portable_shake256(
 7268|  1.31k|      Eurydice_array_to_slice((size_t)128U, digest, uint8_t), input);
  ------------------
  |  |  204|  1.31k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  1.31k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.31k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  1.31k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7269|  1.31k|  memcpy(ret, digest, (size_t)128U * sizeof(uint8_t));
 7270|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_binomial_distribution_a0:
 7108|  13.1k|    Eurydice_slice randomness) {
 7109|  13.1k|  return libcrux_ml_kem_sampling_sample_from_binomial_distribution_2_ea(
 7110|  13.1k|      randomness);
 7111|  13.1k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_binomial_distribution_2_ea:
 7062|  13.1k|    Eurydice_slice randomness) {
 7063|  13.1k|  int16_t sampled_i16s[256U] = {0U};
 7064|  13.1k|  for (size_t i0 = (size_t)0U;
 7065|   433k|       i0 < Eurydice_slice_len(randomness, uint8_t) / (size_t)4U; i0++) {
  ------------------
  |  |  173|   433k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (7065:8): [True: 420k, False: 13.1k]
  ------------------
 7066|   420k|    size_t chunk_number = i0;
 7067|   420k|    Eurydice_slice byte_chunk = Eurydice_slice_subslice3(
  ------------------
  |  |  195|   420k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   420k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   420k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7068|   420k|        randomness, chunk_number * (size_t)4U,
 7069|   420k|        chunk_number * (size_t)4U + (size_t)4U, uint8_t *);
 7070|   420k|    uint32_t random_bits_as_u32 =
 7071|   420k|        (((uint32_t)Eurydice_slice_index(byte_chunk, (size_t)0U, uint8_t,
  ------------------
  |  |  180|   420k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 7072|   420k|                                         uint8_t *) |
 7073|   420k|          (uint32_t)Eurydice_slice_index(byte_chunk, (size_t)1U, uint8_t,
  ------------------
  |  |  180|   420k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 7074|   420k|                                         uint8_t *)
 7075|   420k|              << 8U) |
 7076|   420k|         (uint32_t)Eurydice_slice_index(byte_chunk, (size_t)2U, uint8_t,
  ------------------
  |  |  180|   420k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 7077|   420k|                                        uint8_t *)
 7078|   420k|             << 16U) |
 7079|   420k|        (uint32_t)Eurydice_slice_index(byte_chunk, (size_t)3U, uint8_t,
  ------------------
  |  |  180|   420k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 7080|   420k|                                       uint8_t *)
 7081|   420k|            << 24U;
 7082|   420k|    uint32_t even_bits = random_bits_as_u32 & 1431655765U;
 7083|   420k|    uint32_t odd_bits = random_bits_as_u32 >> 1U & 1431655765U;
 7084|   420k|    uint32_t coin_toss_outcomes = even_bits + odd_bits;
 7085|  3.78M|    for (uint32_t i = 0U; i < 32U / 4U; i++) {
  ------------------
  |  Branch (7085:27): [True: 3.36M, False: 420k]
  ------------------
 7086|  3.36M|      uint32_t outcome_set = i;
 7087|  3.36M|      uint32_t outcome_set0 = outcome_set * 4U;
 7088|  3.36M|      int16_t outcome_1 =
 7089|  3.36M|          (int16_t)(coin_toss_outcomes >> (uint32_t)outcome_set0 & 3U);
 7090|  3.36M|      int16_t outcome_2 =
 7091|  3.36M|          (int16_t)(coin_toss_outcomes >> (uint32_t)(outcome_set0 + 2U) & 3U);
 7092|  3.36M|      size_t offset = (size_t)(outcome_set0 >> 2U);
 7093|  3.36M|      sampled_i16s[(size_t)8U * chunk_number + offset] = outcome_1 - outcome_2;
 7094|  3.36M|    }
 7095|   420k|  }
 7096|  13.1k|  return libcrux_ml_kem_polynomial_from_i16_array_d6_ea(
 7097|  13.1k|      Eurydice_array_to_slice((size_t)256U, sampled_i16s, int16_t));
  ------------------
  |  |  204|  13.1k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  13.1k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  13.1k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  13.1k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7098|  13.1k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_compute_vector_u_1b:
 7360|  1.31k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret[3U]) {
 7361|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d result[3U];
 7362|  5.25k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7362:31): [True: 3.94k, False: 1.31k]
  ------------------
 7363|       |    /* original Rust expression is not an lvalue in C */
 7364|  3.94k|    void *lvalue = (void *)0U;
 7365|  3.94k|    result[i] =
 7366|  3.94k|        libcrux_ml_kem_matrix_compute_vector_u_call_mut_a8_1b(&lvalue, i);
 7367|  3.94k|  }
 7368|  1.31k|  for (size_t i0 = (size_t)0U;
 7369|  5.25k|       i0 < Eurydice_slice_len(
  ------------------
  |  |  173|  5.25k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (7369:8): [True: 3.94k, False: 1.31k]
  ------------------
 7370|  1.31k|                Eurydice_array_to_slice(
 7371|  1.31k|                    (size_t)3U, a_as_ntt,
 7372|  1.31k|                    libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]),
 7373|  1.31k|                libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]);
 7374|  3.94k|       i0++) {
 7375|  3.94k|    size_t i1 = i0;
 7376|  3.94k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *row = a_as_ntt[i1];
 7377|  3.94k|    for (size_t i = (size_t)0U;
 7378|  15.7k|         i < Eurydice_slice_len(
  ------------------
  |  |  173|  15.7k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (7378:10): [True: 11.8k, False: 3.94k]
  ------------------
 7379|  3.94k|                 Eurydice_array_to_slice(
 7380|  3.94k|                     (size_t)3U, row,
 7381|  3.94k|                     libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 7382|  3.94k|                 libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 7383|  11.8k|         i++) {
 7384|  11.8k|      size_t j = i;
 7385|  11.8k|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d *a_element = &row[j];
 7386|  11.8k|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d product =
 7387|  11.8k|          libcrux_ml_kem_polynomial_ntt_multiply_d6_ea(a_element, &r_as_ntt[j]);
 7388|  11.8k|      libcrux_ml_kem_polynomial_add_to_ring_element_d6_1b(&result[i1],
 7389|  11.8k|                                                          &product);
 7390|  11.8k|    }
 7391|  3.94k|    libcrux_ml_kem_invert_ntt_invert_ntt_montgomery_1b(&result[i1]);
 7392|  3.94k|    libcrux_ml_kem_polynomial_add_error_reduce_d6_ea(&result[i1], &error_1[i1]);
 7393|  3.94k|  }
 7394|  1.31k|  memcpy(
 7395|  1.31k|      ret, result,
 7396|  1.31k|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 7397|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_compute_vector_u_call_mut_a8_1b:
 7301|  3.94k|                                                      size_t tupled_args) {
 7302|  3.94k|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 7303|  3.94k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_error_reduce_d6_ea:
 7343|  3.94k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error) {
 7344|  3.94k|  libcrux_ml_kem_polynomial_add_error_reduce_ea(self, error);
 7345|  3.94k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_error_reduce_ea:
 7313|  3.94k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error) {
 7314|  3.94k|  for (size_t i = (size_t)0U;
 7315|  67.0k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  67.0k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (7315:8): [True: 63.0k, False: 3.94k]
  ------------------
 7316|  63.0k|    size_t j = i;
 7317|  63.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 7318|  63.0k|        coefficient_normal_form =
 7319|  63.0k|            libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(
 7320|  63.0k|                myself->coefficients[j], (int16_t)1441);
 7321|  63.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector sum =
 7322|  63.0k|        libcrux_ml_kem_vector_portable_add_b8(coefficient_normal_form,
 7323|  63.0k|                                              &error->coefficients[j]);
 7324|  63.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector red =
 7325|  63.0k|        libcrux_ml_kem_vector_portable_barrett_reduce_b8(sum);
 7326|  63.0k|    myself->coefficients[j] = red;
 7327|  63.0k|  }
 7328|  3.94k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_compress_then_serialize_u_43:
 7490|  1.31k|    Eurydice_slice out) {
 7491|  1.31k|  for (size_t i = (size_t)0U;
 7492|  5.25k|       i < Eurydice_slice_len(
  ------------------
  |  |  173|  5.25k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (7492:8): [True: 3.94k, False: 1.31k]
  ------------------
 7493|  1.31k|               Eurydice_array_to_slice(
 7494|  1.31k|                   (size_t)3U, input,
 7495|  1.31k|                   libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 7496|  1.31k|               libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 7497|  3.94k|       i++) {
 7498|  3.94k|    size_t i0 = i;
 7499|  3.94k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d re = input[i0];
 7500|  3.94k|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  3.94k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  3.94k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  3.94k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7501|  3.94k|        out, i0 * ((size_t)960U / (size_t)3U),
 7502|  3.94k|        (i0 + (size_t)1U) * ((size_t)960U / (size_t)3U), uint8_t *);
 7503|  3.94k|    uint8_t ret[320U];
 7504|  3.94k|    libcrux_ml_kem_serialize_compress_then_serialize_ring_element_u_fe(&re,
 7505|  3.94k|                                                                       ret);
 7506|  3.94k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  3.94k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 7507|  3.94k|        uu____0, Eurydice_array_to_slice((size_t)320U, ret, uint8_t), uint8_t);
 7508|  3.94k|  }
 7509|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_compress_then_serialize_ring_element_u_fe:
 7470|  3.94k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re, uint8_t ret[320U]) {
 7471|  3.94k|  uint8_t uu____0[320U];
 7472|  3.94k|  libcrux_ml_kem_serialize_compress_then_serialize_10_ff(re, uu____0);
 7473|  3.94k|  memcpy(ret, uu____0, (size_t)320U * sizeof(uint8_t));
 7474|  3.94k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_compress_then_serialize_10_ff:
 7442|  3.94k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re, uint8_t ret[320U]) {
 7443|  3.94k|  uint8_t serialized[320U] = {0U};
 7444|  3.94k|  for (size_t i = (size_t)0U;
 7445|  67.0k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  67.0k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (7445:8): [True: 63.0k, False: 3.94k]
  ------------------
 7446|  63.0k|    size_t i0 = i;
 7447|  63.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 7448|  63.0k|        libcrux_ml_kem_vector_portable_compress_b8_ef(
 7449|  63.0k|            libcrux_ml_kem_serialize_to_unsigned_field_modulus_ea(
 7450|  63.0k|                re->coefficients[i0]));
 7451|  63.0k|    uint8_t bytes[20U];
 7452|  63.0k|    libcrux_ml_kem_vector_portable_serialize_10_b8(coefficient, bytes);
 7453|  63.0k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  63.0k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 7454|  63.0k|        Eurydice_array_to_subslice3(serialized, (size_t)20U * i0,
 7455|  63.0k|                                    (size_t)20U * i0 + (size_t)20U, uint8_t *),
 7456|  63.0k|        Eurydice_array_to_slice((size_t)20U, bytes, uint8_t), uint8_t);
 7457|  63.0k|  }
 7458|  3.94k|  memcpy(ret, serialized, (size_t)320U * sizeof(uint8_t));
 7459|  3.94k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_b8_ef:
 7430|  63.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 7431|  63.0k|  return libcrux_ml_kem_vector_portable_compress_compress_ef(a);
 7432|  63.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_compress_ef:
 7406|  63.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 7407|  63.0k|  for (size_t i = (size_t)0U;
 7408|  1.07M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  1.07M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (7408:8): [True: 1.00M, False: 63.0k]
  ------------------
 7409|  1.00M|    size_t i0 = i;
 7410|  1.00M|    int16_t uu____0 = libcrux_secrets_int_as_i16_f5(
 7411|  1.00M|        libcrux_ml_kem_vector_portable_compress_compress_ciphertext_coefficient(
 7412|  1.00M|            (uint8_t)(int32_t)10,
 7413|  1.00M|            libcrux_secrets_int_as_u16_f5(a.elements[i0])));
 7414|  1.00M|    a.elements[i0] = uu____0;
 7415|  1.00M|  }
 7416|  63.0k|  return a;
 7417|  63.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_compress_ciphertext_coefficient:
 4199|  1.34M|    uint8_t coefficient_bits, uint16_t fe) {
 4200|  1.34M|  uint64_t compressed = libcrux_secrets_int_as_u64_ca(fe)
 4201|  1.34M|                        << (uint32_t)coefficient_bits;
 4202|  1.34M|  compressed = compressed + 1664ULL;
 4203|  1.34M|  compressed = compressed * 10321340ULL;
 4204|  1.34M|  compressed = compressed >> 35U;
 4205|  1.34M|  return libcrux_secrets_int_as_i16_b8(
 4206|  1.34M|      libcrux_ml_kem_vector_portable_arithmetic_get_n_least_significant_bits(
 4207|  1.34M|          coefficient_bits, libcrux_secrets_int_as_u32_a3(compressed)));
 4208|  1.34M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_u64_ca:
  661|  1.34M|static KRML_MUSTINLINE uint64_t libcrux_secrets_int_as_u64_ca(uint16_t self) {
  662|  1.34M|  return libcrux_secrets_int_public_integers_classify_27_49(
  663|  1.34M|      (uint64_t)libcrux_secrets_int_public_integers_declassify_d8_de(self));
  664|  1.34M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_49:
  654|  1.34M|libcrux_secrets_int_public_integers_classify_27_49(uint64_t self) {
  655|  1.34M|  return self;
  656|  1.34M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i16_b8:
  703|  1.34M|static KRML_MUSTINLINE int16_t libcrux_secrets_int_as_i16_b8(uint32_t self) {
  704|  1.34M|  return libcrux_secrets_int_public_integers_classify_27_39(
  705|  1.34M|      (int16_t)libcrux_secrets_int_public_integers_declassify_d8_df(self));
  706|  1.34M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_get_n_least_significant_bits:
 4193|  1.34M|    uint8_t n, uint32_t value) {
 4194|  1.34M|  return value & ((1U << (uint32_t)n) - 1U);
 4195|  1.34M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_u32_a3:
  695|  1.34M|static KRML_MUSTINLINE uint32_t libcrux_secrets_int_as_u32_a3(uint64_t self) {
  696|  1.34M|  return libcrux_secrets_int_public_integers_classify_27_df(
  697|  1.34M|      (uint32_t)libcrux_secrets_int_public_integers_declassify_d8_49(self));
  698|  1.34M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_49:
  688|  1.34M|libcrux_secrets_int_public_integers_declassify_d8_49(uint64_t self) {
  689|  1.34M|  return self;
  690|  1.34M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_10_b8:
 4920|  63.0k|    uint8_t ret[20U]) {
 4921|  63.0k|  libcrux_ml_kem_vector_portable_serialize_10(a, ret);
 4922|  63.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_10:
 4908|  63.0k|    uint8_t ret[20U]) {
 4909|  63.0k|  uint8_t ret0[20U];
 4910|  63.0k|  libcrux_ml_kem_vector_portable_serialize_serialize_10(a, ret0);
 4911|  63.0k|  libcrux_secrets_int_public_integers_declassify_d8_57(ret0, ret);
 4912|  63.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_10:
 4871|  63.0k|    uint8_t ret[20U]) {
 4872|  63.0k|  uint8_t_x5 r0_4 = libcrux_ml_kem_vector_portable_serialize_serialize_10_int(
 4873|  63.0k|      Eurydice_array_to_subslice3(v.elements, (size_t)0U, (size_t)4U,
  ------------------
  |  |  215|  63.0k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  63.0k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  63.0k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4874|  63.0k|                                  int16_t *));
 4875|  63.0k|  uint8_t_x5 r5_9 = libcrux_ml_kem_vector_portable_serialize_serialize_10_int(
 4876|  63.0k|      Eurydice_array_to_subslice3(v.elements, (size_t)4U, (size_t)8U,
  ------------------
  |  |  215|  63.0k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  63.0k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  63.0k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4877|  63.0k|                                  int16_t *));
 4878|  63.0k|  uint8_t_x5 r10_14 = libcrux_ml_kem_vector_portable_serialize_serialize_10_int(
 4879|  63.0k|      Eurydice_array_to_subslice3(v.elements, (size_t)8U, (size_t)12U,
  ------------------
  |  |  215|  63.0k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  63.0k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  63.0k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4880|  63.0k|                                  int16_t *));
 4881|  63.0k|  uint8_t_x5 r15_19 = libcrux_ml_kem_vector_portable_serialize_serialize_10_int(
 4882|  63.0k|      Eurydice_array_to_subslice3(v.elements, (size_t)12U, (size_t)16U,
  ------------------
  |  |  215|  63.0k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  63.0k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  63.0k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4883|  63.0k|                                  int16_t *));
 4884|  63.0k|  ret[0U] = r0_4.fst;
 4885|  63.0k|  ret[1U] = r0_4.snd;
 4886|  63.0k|  ret[2U] = r0_4.thd;
 4887|  63.0k|  ret[3U] = r0_4.f3;
 4888|  63.0k|  ret[4U] = r0_4.f4;
 4889|  63.0k|  ret[5U] = r5_9.fst;
 4890|  63.0k|  ret[6U] = r5_9.snd;
 4891|  63.0k|  ret[7U] = r5_9.thd;
 4892|  63.0k|  ret[8U] = r5_9.f3;
 4893|  63.0k|  ret[9U] = r5_9.f4;
 4894|  63.0k|  ret[10U] = r10_14.fst;
 4895|  63.0k|  ret[11U] = r10_14.snd;
 4896|  63.0k|  ret[12U] = r10_14.thd;
 4897|  63.0k|  ret[13U] = r10_14.f3;
 4898|  63.0k|  ret[14U] = r10_14.f4;
 4899|  63.0k|  ret[15U] = r15_19.fst;
 4900|  63.0k|  ret[16U] = r15_19.snd;
 4901|  63.0k|  ret[17U] = r15_19.thd;
 4902|  63.0k|  ret[18U] = r15_19.f3;
 4903|  63.0k|  ret[19U] = r15_19.f4;
 4904|  63.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_10_int:
 4837|   252k|libcrux_ml_kem_vector_portable_serialize_serialize_10_int(Eurydice_slice v) {
 4838|   252k|  uint8_t r0 = libcrux_secrets_int_as_u8_f5(
 4839|   252k|      Eurydice_slice_index(v, (size_t)0U, int16_t, int16_t *) & (int16_t)255);
  ------------------
  |  |  180|   252k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4840|   252k|  uint8_t r1 =
 4841|   252k|      (uint32_t)libcrux_secrets_int_as_u8_f5(
 4842|   252k|          Eurydice_slice_index(v, (size_t)1U, int16_t, int16_t *) & (int16_t)63)
  ------------------
  |  |  180|   252k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4843|   252k|          << 2U |
 4844|   252k|      (uint32_t)libcrux_secrets_int_as_u8_f5(
 4845|   252k|          Eurydice_slice_index(v, (size_t)0U, int16_t, int16_t *) >> 8U &
  ------------------
  |  |  180|   252k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4846|   252k|          (int16_t)3);
 4847|   252k|  uint8_t r2 =
 4848|   252k|      (uint32_t)libcrux_secrets_int_as_u8_f5(
 4849|   252k|          Eurydice_slice_index(v, (size_t)2U, int16_t, int16_t *) & (int16_t)15)
  ------------------
  |  |  180|   252k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4850|   252k|          << 4U |
 4851|   252k|      (uint32_t)libcrux_secrets_int_as_u8_f5(
 4852|   252k|          Eurydice_slice_index(v, (size_t)1U, int16_t, int16_t *) >> 6U &
  ------------------
  |  |  180|   252k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4853|   252k|          (int16_t)15);
 4854|   252k|  uint8_t r3 =
 4855|   252k|      (uint32_t)libcrux_secrets_int_as_u8_f5(
 4856|   252k|          Eurydice_slice_index(v, (size_t)3U, int16_t, int16_t *) & (int16_t)3)
  ------------------
  |  |  180|   252k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4857|   252k|          << 6U |
 4858|   252k|      (uint32_t)libcrux_secrets_int_as_u8_f5(
 4859|   252k|          Eurydice_slice_index(v, (size_t)2U, int16_t, int16_t *) >> 4U &
  ------------------
  |  |  180|   252k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4860|   252k|          (int16_t)63);
 4861|   252k|  uint8_t r4 = libcrux_secrets_int_as_u8_f5(
 4862|   252k|      Eurydice_slice_index(v, (size_t)3U, int16_t, int16_t *) >> 2U &
  ------------------
  |  |  180|   252k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4863|   252k|      (int16_t)255);
 4864|   252k|  return (KRML_CLITERAL(uint8_t_x5){
  ------------------
  |  |  154|   252k|#define KRML_CLITERAL(type) (type)
  ------------------
 4865|   252k|      .fst = r0, .snd = r1, .thd = r2, .f3 = r3, .f4 = r4});
 4866|   252k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_57:
 1034|  63.0k|                                                     uint8_t ret[20U]) {
 1035|  63.0k|  memcpy(ret, self, (size_t)20U * sizeof(uint8_t));
 1036|  63.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_encrypt_c2_6c:
 7767|  1.31k|    uint8_t *message, Eurydice_slice ciphertext) {
 7768|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d message_as_ring_element =
 7769|  1.31k|      libcrux_ml_kem_serialize_deserialize_then_decompress_message_ea(message);
 7770|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d v =
 7771|  1.31k|      libcrux_ml_kem_matrix_compute_ring_element_v_1b(
 7772|  1.31k|          t_as_ntt, r_as_ntt, error_2, &message_as_ring_element);
 7773|  1.31k|  libcrux_ml_kem_serialize_compress_then_serialize_ring_element_v_6c(
 7774|  1.31k|      v, ciphertext);
 7775|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_then_decompress_message_ea:
 7583|  1.31k|    uint8_t *serialized) {
 7584|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d re =
 7585|  1.31k|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 7586|  22.3k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (7586:31): [True: 21.0k, False: 1.31k]
  ------------------
 7587|  21.0k|    size_t i0 = i;
 7588|  21.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 7589|  21.0k|        coefficient_compressed =
 7590|  21.0k|            libcrux_ml_kem_vector_portable_deserialize_1_b8(
 7591|  21.0k|                Eurydice_array_to_subslice3(serialized, (size_t)2U * i0,
  ------------------
  |  |  215|  21.0k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  21.0k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  21.0k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7592|  21.0k|                                            (size_t)2U * i0 + (size_t)2U,
 7593|  21.0k|                                            uint8_t *));
 7594|  21.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 7595|  21.0k|        libcrux_ml_kem_vector_portable_decompress_1_b8(coefficient_compressed);
 7596|  21.0k|    re.coefficients[i0] = uu____0;
 7597|  21.0k|  }
 7598|  1.31k|  return re;
 7599|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_1_b8:
 4682|  21.0k|libcrux_ml_kem_vector_portable_deserialize_1_b8(Eurydice_slice a) {
 4683|  21.0k|  return libcrux_ml_kem_vector_portable_deserialize_1(a);
 4684|  21.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_1:
 4672|  21.0k|libcrux_ml_kem_vector_portable_deserialize_1(Eurydice_slice a) {
 4673|  21.0k|  return libcrux_ml_kem_vector_portable_serialize_deserialize_1(
 4674|  21.0k|      libcrux_secrets_int_classify_public_classify_ref_9b_90(a));
 4675|  21.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_1:
 4617|  21.0k|libcrux_ml_kem_vector_portable_serialize_deserialize_1(Eurydice_slice v) {
 4618|  21.0k|  int16_t result0 = libcrux_secrets_int_as_i16_59(
 4619|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) & 1U);
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4620|  21.0k|  int16_t result1 = libcrux_secrets_int_as_i16_59(
 4621|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 1U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4622|  21.0k|      1U);
 4623|  21.0k|  int16_t result2 = libcrux_secrets_int_as_i16_59(
 4624|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 2U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4625|  21.0k|      1U);
 4626|  21.0k|  int16_t result3 = libcrux_secrets_int_as_i16_59(
 4627|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 3U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4628|  21.0k|      1U);
 4629|  21.0k|  int16_t result4 = libcrux_secrets_int_as_i16_59(
 4630|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 4U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4631|  21.0k|      1U);
 4632|  21.0k|  int16_t result5 = libcrux_secrets_int_as_i16_59(
 4633|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 5U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4634|  21.0k|      1U);
 4635|  21.0k|  int16_t result6 = libcrux_secrets_int_as_i16_59(
 4636|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 6U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4637|  21.0k|      1U);
 4638|  21.0k|  int16_t result7 = libcrux_secrets_int_as_i16_59(
 4639|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 7U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4640|  21.0k|      1U);
 4641|  21.0k|  int16_t result8 = libcrux_secrets_int_as_i16_59(
 4642|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) & 1U);
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4643|  21.0k|  int16_t result9 = libcrux_secrets_int_as_i16_59(
 4644|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 1U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4645|  21.0k|      1U);
 4646|  21.0k|  int16_t result10 = libcrux_secrets_int_as_i16_59(
 4647|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 2U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4648|  21.0k|      1U);
 4649|  21.0k|  int16_t result11 = libcrux_secrets_int_as_i16_59(
 4650|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 3U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4651|  21.0k|      1U);
 4652|  21.0k|  int16_t result12 = libcrux_secrets_int_as_i16_59(
 4653|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 4U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4654|  21.0k|      1U);
 4655|  21.0k|  int16_t result13 = libcrux_secrets_int_as_i16_59(
 4656|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 5U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4657|  21.0k|      1U);
 4658|  21.0k|  int16_t result14 = libcrux_secrets_int_as_i16_59(
 4659|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 6U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4660|  21.0k|      1U);
 4661|  21.0k|  int16_t result15 = libcrux_secrets_int_as_i16_59(
 4662|  21.0k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 7U &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4663|  21.0k|      1U);
 4664|  21.0k|  return (
 4665|  21.0k|      KRML_CLITERAL(libcrux_ml_kem_vector_portable_vector_type_PortableVector){
  ------------------
  |  |  154|  21.0k|#define KRML_CLITERAL(type) (type)
  ------------------
 4666|  21.0k|          .elements = {result0, result1, result2, result3, result4, result5,
 4667|  21.0k|                       result6, result7, result8, result9, result10, result11,
 4668|  21.0k|                       result12, result13, result14, result15}});
 4669|  21.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_decompress_1_b8:
 4229|  21.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4230|  21.0k|  return libcrux_ml_kem_vector_portable_compress_decompress_1(a);
 4231|  21.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_decompress_1:
 4212|  21.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4213|  21.0k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector z =
 4214|  21.0k|      libcrux_ml_kem_vector_portable_vector_type_zero();
 4215|  21.0k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector s =
 4216|  21.0k|      libcrux_ml_kem_vector_portable_arithmetic_sub(z, &a);
 4217|  21.0k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector res =
 4218|  21.0k|      libcrux_ml_kem_vector_portable_arithmetic_bitwise_and_with_constant(
 4219|  21.0k|          s, (int16_t)1665);
 4220|  21.0k|  return res;
 4221|  21.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_compute_ring_element_v_1b:
 7665|  1.31k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *message) {
 7666|  1.31k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d result =
 7667|  1.31k|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 7668|  5.25k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7668:31): [True: 3.94k, False: 1.31k]
  ------------------
 7669|  3.94k|    size_t i0 = i;
 7670|  3.94k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d product =
 7671|  3.94k|        libcrux_ml_kem_polynomial_ntt_multiply_d6_ea(&t_as_ntt[i0],
 7672|  3.94k|                                                     &r_as_ntt[i0]);
 7673|  3.94k|    libcrux_ml_kem_polynomial_add_to_ring_element_d6_1b(&result, &product);
 7674|  3.94k|  }
 7675|  1.31k|  libcrux_ml_kem_invert_ntt_invert_ntt_montgomery_1b(&result);
 7676|  1.31k|  return libcrux_ml_kem_polynomial_add_message_error_reduce_d6_ea(
 7677|  1.31k|      error_2, message, result);
 7678|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_message_error_reduce_d6_ea:
 7646|  1.31k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d result) {
 7647|  1.31k|  return libcrux_ml_kem_polynomial_add_message_error_reduce_ea(self, message,
 7648|  1.31k|                                                               result);
 7649|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_message_error_reduce_ea:
 7611|  1.31k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d result) {
 7612|  1.31k|  for (size_t i = (size_t)0U;
 7613|  22.3k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  22.3k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (7613:8): [True: 21.0k, False: 1.31k]
  ------------------
 7614|  21.0k|    size_t i0 = i;
 7615|  21.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 7616|  21.0k|        coefficient_normal_form =
 7617|  21.0k|            libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(
 7618|  21.0k|                result.coefficients[i0], (int16_t)1441);
 7619|  21.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector sum1 =
 7620|  21.0k|        libcrux_ml_kem_vector_portable_add_b8(myself->coefficients[i0],
 7621|  21.0k|                                              &message->coefficients[i0]);
 7622|  21.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector sum2 =
 7623|  21.0k|        libcrux_ml_kem_vector_portable_add_b8(coefficient_normal_form, &sum1);
 7624|  21.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector red =
 7625|  21.0k|        libcrux_ml_kem_vector_portable_barrett_reduce_b8(sum2);
 7626|  21.0k|    result.coefficients[i0] = red;
 7627|  21.0k|  }
 7628|  1.31k|  return result;
 7629|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_compress_then_serialize_ring_element_v_6c:
 7751|  1.31k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d re, Eurydice_slice out) {
 7752|  1.31k|  libcrux_ml_kem_serialize_compress_then_serialize_4_ea(re, out);
 7753|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_compress_then_serialize_4_ea:
 7724|  1.31k|    Eurydice_slice serialized) {
 7725|  1.31k|  for (size_t i = (size_t)0U;
 7726|  22.3k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  22.3k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (7726:8): [True: 21.0k, False: 1.31k]
  ------------------
 7727|  21.0k|    size_t i0 = i;
 7728|  21.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 7729|  21.0k|        libcrux_ml_kem_vector_portable_compress_b8_d1(
 7730|  21.0k|            libcrux_ml_kem_serialize_to_unsigned_field_modulus_ea(
 7731|  21.0k|                re.coefficients[i0]));
 7732|  21.0k|    uint8_t bytes[8U];
 7733|  21.0k|    libcrux_ml_kem_vector_portable_serialize_4_b8(coefficient, bytes);
 7734|  21.0k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  21.0k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 7735|  21.0k|        Eurydice_slice_subslice3(serialized, (size_t)8U * i0,
 7736|  21.0k|                                 (size_t)8U * i0 + (size_t)8U, uint8_t *),
 7737|  21.0k|        Eurydice_array_to_slice((size_t)8U, bytes, uint8_t), uint8_t);
 7738|  21.0k|  }
 7739|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_b8_d1:
 7711|  21.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 7712|  21.0k|  return libcrux_ml_kem_vector_portable_compress_compress_d1(a);
 7713|  21.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_compress_d1:
 7687|  21.0k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 7688|  21.0k|  for (size_t i = (size_t)0U;
 7689|   357k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   357k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (7689:8): [True: 336k, False: 21.0k]
  ------------------
 7690|   336k|    size_t i0 = i;
 7691|   336k|    int16_t uu____0 = libcrux_secrets_int_as_i16_f5(
 7692|   336k|        libcrux_ml_kem_vector_portable_compress_compress_ciphertext_coefficient(
 7693|   336k|            (uint8_t)(int32_t)4,
 7694|   336k|            libcrux_secrets_int_as_u16_f5(a.elements[i0])));
 7695|   336k|    a.elements[i0] = uu____0;
 7696|   336k|  }
 7697|  21.0k|  return a;
 7698|  21.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_4_b8:
 4755|  21.0k|    uint8_t ret[8U]) {
 4756|  21.0k|  libcrux_ml_kem_vector_portable_serialize_4(a, ret);
 4757|  21.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_4:
 4743|  21.0k|    uint8_t ret[8U]) {
 4744|  21.0k|  uint8_t ret0[8U];
 4745|  21.0k|  libcrux_ml_kem_vector_portable_serialize_serialize_4(a, ret0);
 4746|  21.0k|  libcrux_secrets_int_public_integers_declassify_d8_76(ret0, ret);
 4747|  21.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_4:
 4722|  21.0k|    uint8_t ret[8U]) {
 4723|  21.0k|  uint8_t_x4 result0_3 =
 4724|  21.0k|      libcrux_ml_kem_vector_portable_serialize_serialize_4_int(
 4725|  21.0k|          Eurydice_array_to_subslice3(v.elements, (size_t)0U, (size_t)8U,
  ------------------
  |  |  215|  21.0k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  21.0k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  21.0k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4726|  21.0k|                                      int16_t *));
 4727|  21.0k|  uint8_t_x4 result4_7 =
 4728|  21.0k|      libcrux_ml_kem_vector_portable_serialize_serialize_4_int(
 4729|  21.0k|          Eurydice_array_to_subslice3(v.elements, (size_t)8U, (size_t)16U,
  ------------------
  |  |  215|  21.0k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  21.0k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  21.0k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4730|  21.0k|                                      int16_t *));
 4731|  21.0k|  ret[0U] = result0_3.fst;
 4732|  21.0k|  ret[1U] = result0_3.snd;
 4733|  21.0k|  ret[2U] = result0_3.thd;
 4734|  21.0k|  ret[3U] = result0_3.f3;
 4735|  21.0k|  ret[4U] = result4_7.fst;
 4736|  21.0k|  ret[5U] = result4_7.snd;
 4737|  21.0k|  ret[6U] = result4_7.thd;
 4738|  21.0k|  ret[7U] = result4_7.f3;
 4739|  21.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_4_int:
 4694|  42.0k|libcrux_ml_kem_vector_portable_serialize_serialize_4_int(Eurydice_slice v) {
 4695|  42.0k|  uint8_t result0 = (uint32_t)libcrux_secrets_int_as_u8_f5(
 4696|  42.0k|                        Eurydice_slice_index(v, (size_t)1U, int16_t, int16_t *))
  ------------------
  |  |  180|  42.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4697|  42.0k|                        << 4U |
 4698|  42.0k|                    (uint32_t)libcrux_secrets_int_as_u8_f5(Eurydice_slice_index(
  ------------------
  |  |  180|  42.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4699|  42.0k|                        v, (size_t)0U, int16_t, int16_t *));
 4700|  42.0k|  uint8_t result1 = (uint32_t)libcrux_secrets_int_as_u8_f5(
 4701|  42.0k|                        Eurydice_slice_index(v, (size_t)3U, int16_t, int16_t *))
  ------------------
  |  |  180|  42.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4702|  42.0k|                        << 4U |
 4703|  42.0k|                    (uint32_t)libcrux_secrets_int_as_u8_f5(Eurydice_slice_index(
  ------------------
  |  |  180|  42.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4704|  42.0k|                        v, (size_t)2U, int16_t, int16_t *));
 4705|  42.0k|  uint8_t result2 = (uint32_t)libcrux_secrets_int_as_u8_f5(
 4706|  42.0k|                        Eurydice_slice_index(v, (size_t)5U, int16_t, int16_t *))
  ------------------
  |  |  180|  42.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4707|  42.0k|                        << 4U |
 4708|  42.0k|                    (uint32_t)libcrux_secrets_int_as_u8_f5(Eurydice_slice_index(
  ------------------
  |  |  180|  42.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4709|  42.0k|                        v, (size_t)4U, int16_t, int16_t *));
 4710|  42.0k|  uint8_t result3 = (uint32_t)libcrux_secrets_int_as_u8_f5(
 4711|  42.0k|                        Eurydice_slice_index(v, (size_t)7U, int16_t, int16_t *))
  ------------------
  |  |  180|  42.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4712|  42.0k|                        << 4U |
 4713|  42.0k|                    (uint32_t)libcrux_secrets_int_as_u8_f5(Eurydice_slice_index(
  ------------------
  |  |  180|  42.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4714|  42.0k|                        v, (size_t)6U, int16_t, int16_t *));
 4715|  42.0k|  return (KRML_CLITERAL(uint8_t_x4){
  ------------------
  |  |  154|  42.0k|#define KRML_CLITERAL(type) (type)
  ------------------
 4716|  42.0k|      .fst = result0, .snd = result1, .thd = result2, .f3 = result3});
 4717|  42.0k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_76:
 1048|  21.0k|                                                     uint8_t ret[8U]) {
 1049|  21.0k|  memcpy(ret, self, (size_t)8U * sizeof(uint8_t));
 1050|  21.0k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_variant_kdf_39_d6:
 7903|  1.97k|    Eurydice_slice shared_secret, uint8_t *_, uint8_t ret[32U]) {
 7904|  1.97k|  uint8_t out[32U] = {0U};
 7905|  1.97k|  Eurydice_slice_copy(Eurydice_array_to_slice((size_t)32U, out, uint8_t),
  ------------------
  |  |  229|  1.97k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 7906|  1.97k|                      shared_secret, uint8_t);
 7907|  1.97k|  memcpy(ret, out, (size_t)32U * sizeof(uint8_t));
 7908|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_as_slice_a9_80:
  856|  1.31k|    libcrux_ml_kem_mlkem768_MlKem768Ciphertext *self) {
  857|  1.31k|  return self->value;
  858|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_compare_ciphertexts_select_shared_secret_in_constant_time:
 1277|    657|    Eurydice_slice rhs_s, uint8_t ret[32U]) {
 1278|    657|  uint8_t selector =
 1279|    657|      libcrux_ml_kem_constant_time_ops_compare_ciphertexts_in_constant_time(
 1280|    657|          lhs_c, rhs_c);
 1281|    657|  uint8_t ret0[32U];
 1282|    657|  libcrux_ml_kem_constant_time_ops_select_shared_secret_in_constant_time(
 1283|    657|      lhs_s, rhs_s, selector, ret0);
 1284|    657|  memcpy(ret, ret0, (size_t)32U * sizeof(uint8_t));
 1285|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_compare_ciphertexts_in_constant_time:
 1240|    657|    Eurydice_slice lhs, Eurydice_slice rhs) {
 1241|    657|  return libcrux_ml_kem_constant_time_ops_compare(lhs, rhs);
 1242|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_compare:
 1226|    657|    Eurydice_slice lhs, Eurydice_slice rhs) {
 1227|    657|  uint8_t r = 0U;
 1228|   715k|  for (size_t i = (size_t)0U; i < Eurydice_slice_len(lhs, uint8_t); i++) {
  ------------------
  |  |  173|   715k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (1228:31): [True: 714k, False: 657]
  ------------------
 1229|   714k|    size_t i0 = i;
 1230|   714k|    uint8_t nr = (uint32_t)r |
 1231|   714k|                 ((uint32_t)Eurydice_slice_index(lhs, i0, uint8_t, uint8_t *) ^
  ------------------
  |  |  180|   714k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 1232|   714k|                  (uint32_t)Eurydice_slice_index(rhs, i0, uint8_t, uint8_t *));
  ------------------
  |  |  180|   714k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 1233|   714k|    r = nr;
 1234|   714k|  }
 1235|    657|  return libcrux_ml_kem_constant_time_ops_is_non_zero(r);
 1236|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_is_non_zero:
 1217|  1.31k|libcrux_ml_kem_constant_time_ops_is_non_zero(uint8_t value) {
 1218|  1.31k|  return libcrux_ml_kem_constant_time_ops_inz(value);
 1219|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_inz:
 1209|  1.31k|libcrux_ml_kem_constant_time_ops_inz(uint8_t value) {
 1210|  1.31k|  uint16_t value0 = (uint16_t)value;
 1211|  1.31k|  uint8_t result =
 1212|  1.31k|      (uint8_t)((uint32_t)core_num__u16__wrapping_add(~value0, 1U) >> 8U);
 1213|  1.31k|  return (uint32_t)result & 1U;
 1214|  1.31k|}
libcrux_mlkem768_sha3.c:core_num__u16__wrapping_add:
  336|  1.31k|static inline uint16_t core_num__u16__wrapping_add(uint16_t x, uint16_t y) {
  337|  1.31k|  return x + y;
  338|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_select_shared_secret_in_constant_time:
 1270|    657|    uint8_t ret[32U]) {
 1271|    657|  libcrux_ml_kem_constant_time_ops_select_ct(lhs, rhs, selector, ret);
 1272|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_select_ct:
 1250|    657|    uint8_t ret[32U]) {
 1251|    657|  uint8_t mask = core_num__u8__wrapping_sub(
 1252|    657|      libcrux_ml_kem_constant_time_ops_is_non_zero(selector), 1U);
 1253|    657|  uint8_t out[32U] = {0U};
 1254|  21.6k|  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE;
  ------------------
  |  |  443|  21.6k|#define LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE ((size_t)32U)
  ------------------
  |  Branch (1254:31): [True: 21.0k, False: 657]
  ------------------
 1255|  21.0k|       i++) {
 1256|  21.0k|    size_t i0 = i;
 1257|  21.0k|    uint8_t outi =
 1258|  21.0k|        ((uint32_t)Eurydice_slice_index(lhs, i0, uint8_t, uint8_t *) &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 1259|  21.0k|         (uint32_t)mask) |
 1260|  21.0k|        ((uint32_t)Eurydice_slice_index(rhs, i0, uint8_t, uint8_t *) &
  ------------------
  |  |  180|  21.0k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 1261|  21.0k|         (uint32_t)~mask);
 1262|  21.0k|    out[i0] = outi;
 1263|  21.0k|  }
 1264|    657|  memcpy(ret, out, (size_t)32U * sizeof(uint8_t));
 1265|    657|}
libcrux_mlkem768_sha3.c:core_num__u8__wrapping_sub:
  339|    657|static inline uint8_t core_num__u8__wrapping_sub(uint8_t x, uint8_t y) {
  340|    657|  return x - y;
  341|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_instantiations_portable_encapsulate_cd:
 8159|    657|    libcrux_ml_kem_types_MlKemPublicKey_30 *public_key, uint8_t *randomness) {
 8160|    657|  return libcrux_ml_kem_ind_cca_encapsulate_ca(public_key, randomness);
 8161|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_encapsulate_ca:
 8096|    657|    libcrux_ml_kem_types_MlKemPublicKey_30 *public_key, uint8_t *randomness) {
 8097|    657|  uint8_t randomness0[32U];
 8098|    657|  libcrux_ml_kem_variant_entropy_preprocess_39_9c(
 8099|    657|      Eurydice_array_to_slice((size_t)32U, randomness, uint8_t), randomness0);
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8100|    657|  uint8_t to_hash[64U];
 8101|    657|  libcrux_ml_kem_utils_into_padded_array_24(
 8102|    657|      Eurydice_array_to_slice((size_t)32U, randomness0, uint8_t), to_hash);
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8103|    657|  Eurydice_slice uu____0 = Eurydice_array_to_subslice_from(
  ------------------
  |  |  225|    657|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8104|    657|      (size_t)64U, to_hash, LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE, uint8_t,
 8105|    657|      size_t, uint8_t[]);
 8106|    657|  uint8_t ret0[32U];
 8107|    657|  libcrux_ml_kem_hash_functions_portable_H_4a_e0(
 8108|    657|      Eurydice_array_to_slice((size_t)1184U,
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8109|    657|                              libcrux_ml_kem_types_as_slice_e6_d0(public_key),
 8110|    657|                              uint8_t),
 8111|    657|      ret0);
 8112|    657|  Eurydice_slice_copy(
  ------------------
  |  |  229|    657|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8113|    657|      uu____0, Eurydice_array_to_slice((size_t)32U, ret0, uint8_t), uint8_t);
 8114|    657|  uint8_t hashed[64U];
 8115|    657|  libcrux_ml_kem_hash_functions_portable_G_4a_e0(
 8116|    657|      Eurydice_array_to_slice((size_t)64U, to_hash, uint8_t), hashed);
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8117|    657|  Eurydice_slice_uint8_t_x2 uu____1 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    657|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    657|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    657|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    657|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    657|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    657|  }
  ------------------
 8118|    657|      Eurydice_array_to_slice((size_t)64U, hashed, uint8_t),
 8119|    657|      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE, uint8_t,
 8120|    657|      Eurydice_slice_uint8_t_x2);
 8121|    657|  Eurydice_slice shared_secret = uu____1.fst;
 8122|    657|  Eurydice_slice pseudorandomness = uu____1.snd;
 8123|    657|  uint8_t ciphertext[1088U];
 8124|    657|  libcrux_ml_kem_ind_cpa_encrypt_2a(
 8125|    657|      Eurydice_array_to_slice((size_t)1184U,
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8126|    657|                              libcrux_ml_kem_types_as_slice_e6_d0(public_key),
 8127|    657|                              uint8_t),
 8128|    657|      randomness0, pseudorandomness, ciphertext);
 8129|       |  /* Passing arrays by value in Rust generates a copy in C */
 8130|    657|  uint8_t copy_of_ciphertext[1088U];
 8131|    657|  memcpy(copy_of_ciphertext, ciphertext, (size_t)1088U * sizeof(uint8_t));
 8132|    657|  tuple_c2 lit;
 8133|    657|  lit.fst = libcrux_ml_kem_types_from_e0_80(copy_of_ciphertext);
 8134|    657|  uint8_t ret[32U];
 8135|    657|  libcrux_ml_kem_variant_kdf_39_d6(shared_secret, ciphertext, ret);
 8136|    657|  memcpy(lit.snd, ret, (size_t)32U * sizeof(uint8_t));
 8137|    657|  return lit;
 8138|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_variant_entropy_preprocess_39_9c:
 8055|    657|    Eurydice_slice randomness, uint8_t ret[32U]) {
 8056|    657|  uint8_t out[32U] = {0U};
 8057|    657|  Eurydice_slice_copy(Eurydice_array_to_slice((size_t)32U, out, uint8_t),
  ------------------
  |  |  229|    657|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8058|    657|                      randomness, uint8_t);
 8059|    657|  memcpy(ret, out, (size_t)32U * sizeof(uint8_t));
 8060|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_H_4a_e0:
 8072|  1.31k|    Eurydice_slice input, uint8_t ret[32U]) {
 8073|  1.31k|  libcrux_ml_kem_hash_functions_portable_H(input, ret);
 8074|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_H:
 3725|  1.31k|    Eurydice_slice input, uint8_t ret[32U]) {
 3726|  1.31k|  uint8_t digest[32U] = {0U};
 3727|  1.31k|  libcrux_sha3_portable_sha256(
 3728|  1.31k|      Eurydice_array_to_slice((size_t)32U, digest, uint8_t), input);
  ------------------
  |  |  204|  1.31k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  1.31k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.31k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  1.31k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3729|  1.31k|  memcpy(ret, digest, (size_t)32U * sizeof(uint8_t));
 3730|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_sha256:
 3351|  1.31k|                                                         Eurydice_slice data) {
 3352|  1.31k|  libcrux_sha3_generic_keccak_portable_keccak1_ad(data, digest);
 3353|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_keccak1_ad:
 3315|  1.31k|    Eurydice_slice data, Eurydice_slice out) {
 3316|  1.31k|  libcrux_sha3_generic_keccak_KeccakState_17 s =
 3317|  1.31k|      libcrux_sha3_generic_keccak_new_80_04();
 3318|  1.31k|  size_t data_len = Eurydice_slice_len(data, uint8_t);
  ------------------
  |  |  173|  1.31k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3319|  11.8k|  for (size_t i = (size_t)0U; i < data_len / (size_t)136U; i++) {
  ------------------
  |  Branch (3319:31): [True: 10.5k, False: 1.31k]
  ------------------
 3320|  10.5k|    size_t i0 = i;
 3321|  10.5k|    Eurydice_slice buf[1U] = {data};
 3322|  10.5k|    libcrux_sha3_generic_keccak_absorb_block_80_c60(&s, buf, i0 * (size_t)136U);
 3323|  10.5k|  }
 3324|  1.31k|  size_t rem = data_len % (size_t)136U;
 3325|  1.31k|  Eurydice_slice buf[1U] = {data};
 3326|  1.31k|  libcrux_sha3_generic_keccak_absorb_final_80_9e0(&s, buf, data_len - rem, rem);
 3327|  1.31k|  size_t outlen = Eurydice_slice_len(out, uint8_t);
  ------------------
  |  |  173|  1.31k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3328|  1.31k|  size_t blocks = outlen / (size_t)136U;
 3329|  1.31k|  size_t last = outlen - outlen % (size_t)136U;
 3330|  1.31k|  if (blocks == (size_t)0U) {
  ------------------
  |  Branch (3330:7): [True: 1.31k, False: 0]
  ------------------
 3331|  1.31k|    libcrux_sha3_simd_portable_squeeze_13_5b(&s, out, (size_t)0U, outlen);
 3332|  1.31k|  } else {
 3333|      0|    libcrux_sha3_simd_portable_squeeze_13_5b(&s, out, (size_t)0U, (size_t)136U);
 3334|      0|    for (size_t i = (size_t)1U; i < blocks; i++) {
  ------------------
  |  Branch (3334:33): [True: 0, False: 0]
  ------------------
 3335|      0|      size_t i0 = i;
 3336|      0|      libcrux_sha3_generic_keccak_keccakf1600_80_04(&s);
 3337|      0|      libcrux_sha3_simd_portable_squeeze_13_5b(&s, out, i0 * (size_t)136U,
 3338|      0|                                               (size_t)136U);
 3339|      0|    }
 3340|      0|    if (last < outlen) {
  ------------------
  |  Branch (3340:9): [True: 0, False: 0]
  ------------------
 3341|      0|      libcrux_sha3_generic_keccak_keccakf1600_80_04(&s);
 3342|      0|      libcrux_sha3_simd_portable_squeeze_13_5b(&s, out, last, outlen - last);
 3343|      0|    }
 3344|      0|  }
 3345|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_final_80_9e0:
 3250|  1.31k|    size_t start, size_t len) {
 3251|  1.31k|  libcrux_sha3_simd_portable_load_last_a1_ad(self, last, start, len);
 3252|  1.31k|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3253|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_a1_ad:
 3232|  1.31k|    size_t start, size_t len) {
 3233|  1.31k|  libcrux_sha3_simd_portable_load_last_ad(self->st, input[0U], start, len);
 3234|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_ad:
 3205|  1.31k|    uint64_t *state, Eurydice_slice blocks, size_t start, size_t len) {
 3206|  1.31k|  uint8_t buffer[136U] = {0U};
 3207|  1.31k|  Eurydice_slice_copy(
  ------------------
  |  |  229|  1.31k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3208|  1.31k|      Eurydice_array_to_subslice3(buffer, (size_t)0U, len, uint8_t *),
 3209|  1.31k|      Eurydice_slice_subslice3(blocks, start, start + len, uint8_t *), uint8_t);
 3210|  1.31k|  buffer[len] = 6U;
 3211|  1.31k|  size_t uu____0 = (size_t)136U - (size_t)1U;
 3212|  1.31k|  buffer[uu____0] = (uint32_t)buffer[uu____0] | 128U;
 3213|  1.31k|  libcrux_sha3_simd_portable_load_block_5b(
 3214|  1.31k|      state, Eurydice_array_to_slice((size_t)136U, buffer, uint8_t),
  ------------------
  |  |  204|  1.31k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  1.31k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.31k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  1.31k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3215|  1.31k|      (size_t)0U);
 3216|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_as_slice_e6_d0:
  843|  1.31k|    libcrux_ml_kem_types_MlKemPublicKey_30 *self) {
  844|  1.31k|  return self->value;
  845|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_from_e0_80:
  825|    657|libcrux_ml_kem_types_from_e0_80(uint8_t value[1088U]) {
  826|       |  /* Passing arrays by value in Rust generates a copy in C */
  827|    657|  uint8_t copy_of_value[1088U];
  828|    657|  memcpy(copy_of_value, value, (size_t)1088U * sizeof(uint8_t));
  829|    657|  libcrux_ml_kem_mlkem768_MlKem768Ciphertext lit;
  830|    657|  memcpy(lit.value, copy_of_value, (size_t)1088U * sizeof(uint8_t));
  831|    657|  return lit;
  832|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_instantiations_portable_generate_keypair_ce:
 8754|    657|    uint8_t *randomness) {
 8755|    657|  return libcrux_ml_kem_ind_cca_generate_keypair_15(randomness);
 8756|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_generate_keypair_15:
 8705|    657|libcrux_ml_kem_ind_cca_generate_keypair_15(uint8_t *randomness) {
 8706|    657|  Eurydice_slice ind_cpa_keypair_randomness = Eurydice_array_to_subslice3(
  ------------------
  |  |  215|    657|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8707|    657|      randomness, (size_t)0U,
 8708|    657|      LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE, uint8_t *);
 8709|    657|  Eurydice_slice implicit_rejection_value = Eurydice_array_to_subslice_from(
  ------------------
  |  |  225|    657|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8710|    657|      (size_t)64U, randomness,
 8711|    657|      LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE, uint8_t,
 8712|    657|      size_t, uint8_t[]);
 8713|    657|  libcrux_ml_kem_utils_extraction_helper_Keypair768 uu____0 =
 8714|    657|      libcrux_ml_kem_ind_cpa_generate_keypair_ea(ind_cpa_keypair_randomness);
 8715|    657|  uint8_t ind_cpa_private_key[1152U];
 8716|    657|  memcpy(ind_cpa_private_key, uu____0.fst, (size_t)1152U * sizeof(uint8_t));
 8717|    657|  uint8_t public_key[1184U];
 8718|    657|  memcpy(public_key, uu____0.snd, (size_t)1184U * sizeof(uint8_t));
 8719|    657|  uint8_t secret_key_serialized[2400U];
 8720|    657|  libcrux_ml_kem_ind_cca_serialize_kem_secret_key_d6(
 8721|    657|      Eurydice_array_to_slice((size_t)1152U, ind_cpa_private_key, uint8_t),
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8722|    657|      Eurydice_array_to_slice((size_t)1184U, public_key, uint8_t),
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8723|    657|      implicit_rejection_value, secret_key_serialized);
 8724|       |  /* Passing arrays by value in Rust generates a copy in C */
 8725|    657|  uint8_t copy_of_secret_key_serialized[2400U];
 8726|    657|  memcpy(copy_of_secret_key_serialized, secret_key_serialized,
 8727|    657|         (size_t)2400U * sizeof(uint8_t));
 8728|    657|  libcrux_ml_kem_types_MlKemPrivateKey_d9 private_key =
 8729|    657|      libcrux_ml_kem_types_from_77_28(copy_of_secret_key_serialized);
 8730|    657|  libcrux_ml_kem_types_MlKemPrivateKey_d9 uu____2 = private_key;
 8731|       |  /* Passing arrays by value in Rust generates a copy in C */
 8732|    657|  uint8_t copy_of_public_key[1184U];
 8733|    657|  memcpy(copy_of_public_key, public_key, (size_t)1184U * sizeof(uint8_t));
 8734|    657|  return libcrux_ml_kem_types_from_17_74(
 8735|    657|      uu____2, libcrux_ml_kem_types_from_fd_d0(copy_of_public_key));
 8736|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_generate_keypair_ea:
 8605|    657|libcrux_ml_kem_ind_cpa_generate_keypair_ea(Eurydice_slice key_generation_seed) {
 8606|    657|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPrivateKeyUnpacked_a0 private_key =
 8607|    657|      libcrux_ml_kem_ind_cpa_unpacked_default_70_1b();
 8608|    657|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0 public_key =
 8609|    657|      libcrux_ml_kem_ind_cpa_unpacked_default_8b_1b();
 8610|    657|  libcrux_ml_kem_ind_cpa_generate_keypair_unpacked_1c(
 8611|    657|      key_generation_seed, &private_key, &public_key);
 8612|    657|  return libcrux_ml_kem_ind_cpa_serialize_unpacked_secret_key_6c(&public_key,
 8613|    657|                                                                 &private_key);
 8614|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_unpacked_default_70_1b:
 8189|    657|libcrux_ml_kem_ind_cpa_unpacked_default_70_1b(void) {
 8190|    657|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPrivateKeyUnpacked_a0 lit;
 8191|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d repeat_expression[3U];
 8192|  2.62k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (8192:31): [True: 1.97k, False: 657]
  ------------------
 8193|  1.97k|    repeat_expression[i] = libcrux_ml_kem_polynomial_ZERO_d6_ea();
 8194|  1.97k|  }
 8195|    657|  memcpy(
 8196|    657|      lit.secret_as_ntt, repeat_expression,
 8197|    657|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 8198|    657|  return lit;
 8199|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_generate_keypair_unpacked_1c:
 8409|    657|    libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0 *public_key) {
 8410|    657|  uint8_t hashed[64U];
 8411|    657|  libcrux_ml_kem_variant_cpa_keygen_seed_39_9c(key_generation_seed, hashed);
 8412|    657|  Eurydice_slice_uint8_t_x2 uu____0 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    657|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    657|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    657|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    657|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    657|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    657|  }
  ------------------
 8413|    657|      Eurydice_array_to_slice((size_t)64U, hashed, uint8_t), (size_t)32U,
 8414|    657|      uint8_t, Eurydice_slice_uint8_t_x2);
 8415|    657|  Eurydice_slice seed_for_A = uu____0.fst;
 8416|    657|  Eurydice_slice seed_for_secret_and_error = uu____0.snd;
 8417|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d(*uu____1)[3U] =
 8418|    657|      public_key->A;
 8419|    657|  uint8_t ret[34U];
 8420|    657|  libcrux_ml_kem_utils_into_padded_array_b6(seed_for_A, ret);
 8421|    657|  libcrux_ml_kem_matrix_sample_matrix_A_2b(uu____1, ret, true);
 8422|    657|  uint8_t prf_input[33U];
 8423|    657|  libcrux_ml_kem_utils_into_padded_array_c8(seed_for_secret_and_error,
 8424|    657|                                            prf_input);
 8425|    657|  uint8_t domain_separator =
 8426|    657|      libcrux_ml_kem_ind_cpa_sample_vector_cbd_then_ntt_3b(
 8427|    657|          private_key->secret_as_ntt, prf_input, 0U);
 8428|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d error_as_ntt[3U];
 8429|  2.62k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (8429:31): [True: 1.97k, False: 657]
  ------------------
 8430|       |    /* original Rust expression is not an lvalue in C */
 8431|  1.97k|    void *lvalue = (void *)0U;
 8432|  1.97k|    error_as_ntt[i] =
 8433|  1.97k|        libcrux_ml_kem_ind_cpa_generate_keypair_unpacked_call_mut_73_1c(&lvalue,
 8434|  1.97k|                                                                        i);
 8435|  1.97k|  }
 8436|    657|  libcrux_ml_kem_ind_cpa_sample_vector_cbd_then_ntt_3b(error_as_ntt, prf_input,
 8437|    657|                                                       domain_separator);
 8438|    657|  libcrux_ml_kem_matrix_compute_As_plus_e_1b(
 8439|    657|      public_key->t_as_ntt, public_key->A, private_key->secret_as_ntt,
 8440|    657|      error_as_ntt);
 8441|    657|  uint8_t uu____2[32U];
 8442|    657|  Result_fb dst;
 8443|    657|  Eurydice_slice_to_array2(&dst, seed_for_A, Eurydice_slice, uint8_t[32U],
  ------------------
  |  |  277|    657|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|    657|                           sizeof(t_arr))
  ------------------
 8444|    657|                           TryFromSliceError);
 8445|    657|  unwrap_26_b3(dst, uu____2);
 8446|    657|  memcpy(public_key->seed_for_A, uu____2, (size_t)32U * sizeof(uint8_t));
 8447|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_variant_cpa_keygen_seed_39_9c:
 8212|    657|    Eurydice_slice key_generation_seed, uint8_t ret[64U]) {
 8213|    657|  uint8_t seed[33U] = {0U};
 8214|    657|  Eurydice_slice_copy(
  ------------------
  |  |  229|    657|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8215|    657|      Eurydice_array_to_subslice3(
 8216|    657|          seed, (size_t)0U,
 8217|    657|          LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE, uint8_t *),
 8218|    657|      key_generation_seed, uint8_t);
 8219|    657|  seed[LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE] =
  ------------------
  |  |  455|    657|#define LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE ((size_t)32U)
  ------------------
 8220|    657|      (uint8_t)(size_t)3U;
 8221|    657|  uint8_t ret0[64U];
 8222|    657|  libcrux_ml_kem_hash_functions_portable_G_4a_e0(
 8223|    657|      Eurydice_array_to_slice((size_t)33U, seed, uint8_t), ret0);
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8224|    657|  memcpy(ret, ret0, (size_t)64U * sizeof(uint8_t));
 8225|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_generate_keypair_unpacked_call_mut_73_1c:
 8247|  1.97k|    void **_, size_t tupled_args) {
 8248|  1.97k|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 8249|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_compute_As_plus_e_1b:
 8322|    657|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error_as_ntt) {
 8323|    657|  for (size_t i = (size_t)0U;
 8324|  2.62k|       i < Eurydice_slice_len(
  ------------------
  |  |  173|  2.62k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (8324:8): [True: 1.97k, False: 657]
  ------------------
 8325|    657|               Eurydice_array_to_slice(
 8326|    657|                   (size_t)3U, matrix_A,
 8327|    657|                   libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]),
 8328|    657|               libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]);
 8329|  1.97k|       i++) {
 8330|  1.97k|    size_t i0 = i;
 8331|  1.97k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *row = matrix_A[i0];
 8332|  1.97k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0 =
 8333|  1.97k|        libcrux_ml_kem_polynomial_ZERO_d6_ea();
 8334|  1.97k|    t_as_ntt[i0] = uu____0;
 8335|  1.97k|    for (size_t i1 = (size_t)0U;
 8336|  7.88k|         i1 < Eurydice_slice_len(
  ------------------
  |  |  173|  7.88k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (8336:10): [True: 5.91k, False: 1.97k]
  ------------------
 8337|  1.97k|                  Eurydice_array_to_slice(
 8338|  1.97k|                      (size_t)3U, row,
 8339|  1.97k|                      libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 8340|  1.97k|                  libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 8341|  5.91k|         i1++) {
 8342|  5.91k|      size_t j = i1;
 8343|  5.91k|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d *matrix_element =
 8344|  5.91k|          &row[j];
 8345|  5.91k|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d product =
 8346|  5.91k|          libcrux_ml_kem_polynomial_ntt_multiply_d6_ea(matrix_element,
 8347|  5.91k|                                                       &s_as_ntt[j]);
 8348|  5.91k|      libcrux_ml_kem_polynomial_add_to_ring_element_d6_1b(&t_as_ntt[i0],
 8349|  5.91k|                                                          &product);
 8350|  5.91k|    }
 8351|  1.97k|    libcrux_ml_kem_polynomial_add_standard_error_reduce_d6_ea(
 8352|  1.97k|        &t_as_ntt[i0], &error_as_ntt[i0]);
 8353|  1.97k|  }
 8354|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_standard_error_reduce_d6_ea:
 8305|  1.97k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error) {
 8306|  1.97k|  libcrux_ml_kem_polynomial_add_standard_error_reduce_ea(self, error);
 8307|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_standard_error_reduce_ea:
 8274|  1.97k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error) {
 8275|  1.97k|  for (size_t i = (size_t)0U;
 8276|  33.5k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  33.5k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (8276:8): [True: 31.5k, False: 1.97k]
  ------------------
 8277|  31.5k|    size_t j = i;
 8278|  31.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 8279|  31.5k|        coefficient_normal_form =
 8280|  31.5k|            libcrux_ml_kem_polynomial_to_standard_domain_ea(
 8281|  31.5k|                myself->coefficients[j]);
 8282|  31.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector sum =
 8283|  31.5k|        libcrux_ml_kem_vector_portable_add_b8(coefficient_normal_form,
 8284|  31.5k|                                              &error->coefficients[j]);
 8285|  31.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector red =
 8286|  31.5k|        libcrux_ml_kem_vector_portable_barrett_reduce_b8(sum);
 8287|  31.5k|    myself->coefficients[j] = red;
 8288|  31.5k|  }
 8289|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_to_standard_domain_ea:
 8259|  31.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vector) {
 8260|  31.5k|  return libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(
 8261|  31.5k|      vector,
 8262|  31.5k|      LIBCRUX_ML_KEM_VECTOR_TRAITS_MONTGOMERY_R_SQUARED_MOD_FIELD_MODULUS);
  ------------------
  |  | 3775|  31.5k|  ((int16_t)1353)
  ------------------
 8263|  31.5k|}
libcrux_mlkem768_sha3.c:unwrap_26_b3:
  803|    657|static inline void unwrap_26_b3(Result_fb self, uint8_t ret[32U]) {
  804|    657|  if (self.tag == Ok) {
  ------------------
  |  |  721|    657|#define Ok 0
  ------------------
  |  Branch (804:7): [True: 657, False: 0]
  ------------------
  805|    657|    uint8_t f0[32U];
  806|    657|    memcpy(f0, self.val.case_Ok, (size_t)32U * sizeof(uint8_t));
  807|    657|    memcpy(ret, f0, (size_t)32U * sizeof(uint8_t));
  808|    657|  } else {
  809|      0|    KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", __FILE__, __LINE__,
  810|      0|                      "unwrap not Ok");
  811|       |    KRML_HOST_EXIT(255U);
  ------------------
  |  |   41|      0|#define KRML_HOST_EXIT(x) do { \
  |  |   42|      0|    fprintf(stderr, "mlkem internal error"); \
  |  |   43|      0|    exit(x); \
  |  |   44|      0|} while (0)
  |  |  ------------------
  |  |  |  Branch (44:10): [Folded, False: 0]
  |  |  ------------------
  ------------------
  812|      0|  }
  813|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_serialize_unpacked_secret_key_6c:
 8567|    657|    libcrux_ml_kem_ind_cpa_unpacked_IndCpaPrivateKeyUnpacked_a0 *private_key) {
 8568|    657|  uint8_t public_key_serialized[1184U];
 8569|    657|  libcrux_ml_kem_ind_cpa_serialize_public_key_89(
 8570|    657|      public_key->t_as_ntt,
 8571|    657|      Eurydice_array_to_slice((size_t)32U, public_key->seed_for_A, uint8_t),
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8572|    657|      public_key_serialized);
 8573|    657|  uint8_t secret_key_serialized[1152U] = {0U};
 8574|    657|  libcrux_ml_kem_ind_cpa_serialize_vector_1b(
 8575|    657|      private_key->secret_as_ntt,
 8576|    657|      Eurydice_array_to_slice((size_t)1152U, secret_key_serialized, uint8_t));
  ------------------
  |  |  204|    657|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    657|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8577|       |  /* Passing arrays by value in Rust generates a copy in C */
 8578|    657|  uint8_t copy_of_secret_key_serialized[1152U];
 8579|    657|  memcpy(copy_of_secret_key_serialized, secret_key_serialized,
 8580|    657|         (size_t)1152U * sizeof(uint8_t));
 8581|       |  /* Passing arrays by value in Rust generates a copy in C */
 8582|    657|  uint8_t copy_of_public_key_serialized[1184U];
 8583|    657|  memcpy(copy_of_public_key_serialized, public_key_serialized,
 8584|    657|         (size_t)1184U * sizeof(uint8_t));
 8585|    657|  libcrux_ml_kem_utils_extraction_helper_Keypair768 lit;
 8586|    657|  memcpy(lit.fst, copy_of_secret_key_serialized,
 8587|    657|         (size_t)1152U * sizeof(uint8_t));
 8588|    657|  memcpy(lit.snd, copy_of_public_key_serialized,
 8589|    657|         (size_t)1184U * sizeof(uint8_t));
 8590|    657|  return lit;
 8591|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_serialize_public_key_89:
 8546|  1.31k|    Eurydice_slice seed_for_a, uint8_t ret[1184U]) {
 8547|  1.31k|  uint8_t public_key_serialized[1184U] = {0U};
 8548|  1.31k|  libcrux_ml_kem_ind_cpa_serialize_public_key_mut_89(t_as_ntt, seed_for_a,
 8549|  1.31k|                                                     public_key_serialized);
 8550|  1.31k|  memcpy(ret, public_key_serialized, (size_t)1184U * sizeof(uint8_t));
 8551|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_serialize_public_key_mut_89:
 8519|  1.31k|    Eurydice_slice seed_for_a, uint8_t *serialized) {
 8520|  1.31k|  libcrux_ml_kem_ind_cpa_serialize_vector_1b(
 8521|  1.31k|      t_as_ntt,
 8522|  1.31k|      Eurydice_array_to_subslice3(
  ------------------
  |  |  215|  1.31k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  1.31k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.31k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8523|  1.31k|          serialized, (size_t)0U,
 8524|  1.31k|          libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U),
 8525|  1.31k|          uint8_t *));
 8526|  1.31k|  Eurydice_slice_copy(
  ------------------
  |  |  229|  1.31k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8527|  1.31k|      Eurydice_array_to_subslice_from(
 8528|  1.31k|          (size_t)1184U, serialized,
 8529|  1.31k|          libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U),
 8530|  1.31k|          uint8_t, size_t, uint8_t[]),
 8531|  1.31k|      seed_for_a, uint8_t);
 8532|  1.31k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constants_ranked_bytes_per_ring_element:
  468|  8.54k|    size_t rank) {
  469|  8.54k|  return rank * LIBCRUX_ML_KEM_CONSTANTS_BITS_PER_RING_ELEMENT / (size_t)8U;
  ------------------
  |  |  450|  8.54k|  (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)12U)
  |  |  ------------------
  |  |  |  |  447|  8.54k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  |  |  ------------------
  ------------------
  470|  8.54k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_serialize_vector_1b:
 8486|  1.97k|    Eurydice_slice out) {
 8487|  1.97k|  for (size_t i = (size_t)0U;
 8488|  7.88k|       i < Eurydice_slice_len(
  ------------------
  |  |  173|  7.88k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (8488:8): [True: 5.91k, False: 1.97k]
  ------------------
 8489|  1.97k|               Eurydice_array_to_slice(
 8490|  1.97k|                   (size_t)3U, key,
 8491|  1.97k|                   libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 8492|  1.97k|               libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 8493|  5.91k|       i++) {
 8494|  5.91k|    size_t i0 = i;
 8495|  5.91k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d re = key[i0];
 8496|  5.91k|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  5.91k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  5.91k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  5.91k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8497|  5.91k|        out, i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 8498|  5.91k|        (i0 + (size_t)1U) * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 8499|  5.91k|        uint8_t *);
 8500|  5.91k|    uint8_t ret[384U];
 8501|  5.91k|    libcrux_ml_kem_serialize_serialize_uncompressed_ring_element_ea(&re, ret);
 8502|  5.91k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  5.91k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8503|  5.91k|        uu____0, Eurydice_array_to_slice((size_t)384U, ret, uint8_t), uint8_t);
 8504|  5.91k|  }
 8505|  1.97k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_serialize_uncompressed_ring_element_ea:
 8457|  5.91k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re, uint8_t ret[384U]) {
 8458|  5.91k|  uint8_t serialized[384U] = {0U};
 8459|  5.91k|  for (size_t i = (size_t)0U;
 8460|   100k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|   100k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (8460:8): [True: 94.6k, False: 5.91k]
  ------------------
 8461|  94.6k|    size_t i0 = i;
 8462|  94.6k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 8463|  94.6k|        libcrux_ml_kem_serialize_to_unsigned_field_modulus_ea(
 8464|  94.6k|            re->coefficients[i0]);
 8465|  94.6k|    uint8_t bytes[24U];
 8466|  94.6k|    libcrux_ml_kem_vector_portable_serialize_12_b8(coefficient, bytes);
 8467|  94.6k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  94.6k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8468|  94.6k|        Eurydice_array_to_subslice3(serialized, (size_t)24U * i0,
 8469|  94.6k|                                    (size_t)24U * i0 + (size_t)24U, uint8_t *),
 8470|  94.6k|        Eurydice_array_to_slice((size_t)24U, bytes, uint8_t), uint8_t);
 8471|  94.6k|  }
 8472|  5.91k|  memcpy(ret, serialized, (size_t)384U * sizeof(uint8_t));
 8473|  5.91k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_12_b8:
 5116|  94.6k|    uint8_t ret[24U]) {
 5117|  94.6k|  libcrux_ml_kem_vector_portable_serialize_12(a, ret);
 5118|  94.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_12:
 5104|  94.6k|    uint8_t ret[24U]) {
 5105|  94.6k|  uint8_t ret0[24U];
 5106|  94.6k|  libcrux_ml_kem_vector_portable_serialize_serialize_12(a, ret0);
 5107|  94.6k|  libcrux_secrets_int_public_integers_declassify_d8_d2(ret0, ret);
 5108|  94.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_12:
 5051|  94.6k|    uint8_t ret[24U]) {
 5052|  94.6k|  uint8_t_x3 r0_2 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5053|  94.6k|      Eurydice_array_to_subslice3(v.elements, (size_t)0U, (size_t)2U,
  ------------------
  |  |  215|  94.6k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  94.6k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  94.6k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5054|  94.6k|                                  int16_t *));
 5055|  94.6k|  uint8_t_x3 r3_5 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5056|  94.6k|      Eurydice_array_to_subslice3(v.elements, (size_t)2U, (size_t)4U,
  ------------------
  |  |  215|  94.6k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  94.6k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  94.6k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5057|  94.6k|                                  int16_t *));
 5058|  94.6k|  uint8_t_x3 r6_8 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5059|  94.6k|      Eurydice_array_to_subslice3(v.elements, (size_t)4U, (size_t)6U,
  ------------------
  |  |  215|  94.6k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  94.6k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  94.6k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5060|  94.6k|                                  int16_t *));
 5061|  94.6k|  uint8_t_x3 r9_11 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5062|  94.6k|      Eurydice_array_to_subslice3(v.elements, (size_t)6U, (size_t)8U,
  ------------------
  |  |  215|  94.6k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  94.6k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  94.6k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5063|  94.6k|                                  int16_t *));
 5064|  94.6k|  uint8_t_x3 r12_14 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5065|  94.6k|      Eurydice_array_to_subslice3(v.elements, (size_t)8U, (size_t)10U,
  ------------------
  |  |  215|  94.6k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  94.6k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  94.6k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5066|  94.6k|                                  int16_t *));
 5067|  94.6k|  uint8_t_x3 r15_17 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5068|  94.6k|      Eurydice_array_to_subslice3(v.elements, (size_t)10U, (size_t)12U,
  ------------------
  |  |  215|  94.6k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  94.6k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  94.6k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5069|  94.6k|                                  int16_t *));
 5070|  94.6k|  uint8_t_x3 r18_20 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5071|  94.6k|      Eurydice_array_to_subslice3(v.elements, (size_t)12U, (size_t)14U,
  ------------------
  |  |  215|  94.6k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  94.6k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  94.6k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5072|  94.6k|                                  int16_t *));
 5073|  94.6k|  uint8_t_x3 r21_23 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5074|  94.6k|      Eurydice_array_to_subslice3(v.elements, (size_t)14U, (size_t)16U,
  ------------------
  |  |  215|  94.6k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  94.6k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  94.6k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5075|  94.6k|                                  int16_t *));
 5076|  94.6k|  ret[0U] = r0_2.fst;
 5077|  94.6k|  ret[1U] = r0_2.snd;
 5078|  94.6k|  ret[2U] = r0_2.thd;
 5079|  94.6k|  ret[3U] = r3_5.fst;
 5080|  94.6k|  ret[4U] = r3_5.snd;
 5081|  94.6k|  ret[5U] = r3_5.thd;
 5082|  94.6k|  ret[6U] = r6_8.fst;
 5083|  94.6k|  ret[7U] = r6_8.snd;
 5084|  94.6k|  ret[8U] = r6_8.thd;
 5085|  94.6k|  ret[9U] = r9_11.fst;
 5086|  94.6k|  ret[10U] = r9_11.snd;
 5087|  94.6k|  ret[11U] = r9_11.thd;
 5088|  94.6k|  ret[12U] = r12_14.fst;
 5089|  94.6k|  ret[13U] = r12_14.snd;
 5090|  94.6k|  ret[14U] = r12_14.thd;
 5091|  94.6k|  ret[15U] = r15_17.fst;
 5092|  94.6k|  ret[16U] = r15_17.snd;
 5093|  94.6k|  ret[17U] = r15_17.thd;
 5094|  94.6k|  ret[18U] = r18_20.fst;
 5095|  94.6k|  ret[19U] = r18_20.snd;
 5096|  94.6k|  ret[20U] = r18_20.thd;
 5097|  94.6k|  ret[21U] = r21_23.fst;
 5098|  94.6k|  ret[22U] = r21_23.snd;
 5099|  94.6k|  ret[23U] = r21_23.thd;
 5100|  94.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_12_int:
 5035|   756k|libcrux_ml_kem_vector_portable_serialize_serialize_12_int(Eurydice_slice v) {
 5036|   756k|  uint8_t r0 = libcrux_secrets_int_as_u8_f5(
 5037|   756k|      Eurydice_slice_index(v, (size_t)0U, int16_t, int16_t *) & (int16_t)255);
  ------------------
  |  |  180|   756k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5038|   756k|  uint8_t r1 = libcrux_secrets_int_as_u8_f5(
 5039|   756k|      Eurydice_slice_index(v, (size_t)0U, int16_t, int16_t *) >> 8U |
  ------------------
  |  |  180|   756k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5040|   756k|      (Eurydice_slice_index(v, (size_t)1U, int16_t, int16_t *) & (int16_t)15)
  ------------------
  |  |  180|   756k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5041|   756k|          << 4U);
 5042|   756k|  uint8_t r2 = libcrux_secrets_int_as_u8_f5(
 5043|   756k|      Eurydice_slice_index(v, (size_t)1U, int16_t, int16_t *) >> 4U &
  ------------------
  |  |  180|   756k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5044|   756k|      (int16_t)255);
 5045|   756k|  return (KRML_CLITERAL(uint8_t_x3){.fst = r0, .snd = r1, .thd = r2});
  ------------------
  |  |  154|   756k|#define KRML_CLITERAL(type) (type)
  ------------------
 5046|   756k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_d2:
 1020|  94.6k|                                                     uint8_t ret[24U]) {
 1021|  94.6k|  memcpy(ret, self, (size_t)24U * sizeof(uint8_t));
 1022|  94.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_serialize_kem_secret_key_d6:
 8677|    657|    Eurydice_slice implicit_rejection_value, uint8_t ret[2400U]) {
 8678|    657|  uint8_t out[2400U] = {0U};
 8679|    657|  libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_d6(
 8680|    657|      private_key, public_key, implicit_rejection_value, out);
 8681|    657|  memcpy(ret, out, (size_t)2400U * sizeof(uint8_t));
 8682|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_d6:
 8629|    657|    Eurydice_slice implicit_rejection_value, uint8_t *serialized) {
 8630|    657|  size_t pointer = (size_t)0U;
 8631|    657|  uint8_t *uu____0 = serialized;
 8632|    657|  size_t uu____1 = pointer;
 8633|    657|  size_t uu____2 = pointer;
 8634|    657|  Eurydice_slice_copy(
  ------------------
  |  |  229|    657|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8635|    657|      Eurydice_array_to_subslice3(
 8636|    657|          uu____0, uu____1, uu____2 + Eurydice_slice_len(private_key, uint8_t),
 8637|    657|          uint8_t *),
 8638|    657|      private_key, uint8_t);
 8639|    657|  pointer = pointer + Eurydice_slice_len(private_key, uint8_t);
  ------------------
  |  |  173|    657|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 8640|    657|  uint8_t *uu____3 = serialized;
 8641|    657|  size_t uu____4 = pointer;
 8642|    657|  size_t uu____5 = pointer;
 8643|    657|  Eurydice_slice_copy(
  ------------------
  |  |  229|    657|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8644|    657|      Eurydice_array_to_subslice3(
 8645|    657|          uu____3, uu____4, uu____5 + Eurydice_slice_len(public_key, uint8_t),
 8646|    657|          uint8_t *),
 8647|    657|      public_key, uint8_t);
 8648|    657|  pointer = pointer + Eurydice_slice_len(public_key, uint8_t);
  ------------------
  |  |  173|    657|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 8649|    657|  Eurydice_slice uu____6 = Eurydice_array_to_subslice3(
  ------------------
  |  |  215|    657|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8650|    657|      serialized, pointer, pointer + LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE,
 8651|    657|      uint8_t *);
 8652|    657|  uint8_t ret[32U];
 8653|    657|  libcrux_ml_kem_hash_functions_portable_H_4a_e0(public_key, ret);
 8654|    657|  Eurydice_slice_copy(
  ------------------
  |  |  229|    657|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8655|    657|      uu____6, Eurydice_array_to_slice((size_t)32U, ret, uint8_t), uint8_t);
 8656|    657|  pointer = pointer + LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE;
  ------------------
  |  |  459|    657|#define LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE ((size_t)32U)
  ------------------
 8657|    657|  uint8_t *uu____7 = serialized;
 8658|    657|  size_t uu____8 = pointer;
 8659|    657|  size_t uu____9 = pointer;
 8660|    657|  Eurydice_slice_copy(
  ------------------
  |  |  229|    657|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8661|    657|      Eurydice_array_to_subslice3(
 8662|    657|          uu____7, uu____8,
 8663|    657|          uu____9 + Eurydice_slice_len(implicit_rejection_value, uint8_t),
 8664|    657|          uint8_t *),
 8665|    657|      implicit_rejection_value, uint8_t);
 8666|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_from_77_28:
  772|    657|libcrux_ml_kem_types_from_77_28(uint8_t value[2400U]) {
  773|       |  /* Passing arrays by value in Rust generates a copy in C */
  774|    657|  uint8_t copy_of_value[2400U];
  775|    657|  memcpy(copy_of_value, value, (size_t)2400U * sizeof(uint8_t));
  776|    657|  libcrux_ml_kem_types_MlKemPrivateKey_d9 lit;
  777|    657|  memcpy(lit.value, copy_of_value, (size_t)2400U * sizeof(uint8_t));
  778|    657|  return lit;
  779|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_from_17_74:
  757|    657|                                libcrux_ml_kem_types_MlKemPublicKey_30 pk) {
  758|    657|  return (KRML_CLITERAL(libcrux_ml_kem_mlkem768_MlKem768KeyPair){.sk = sk,
  ------------------
  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  ------------------
  759|    657|                                                                 .pk = pk});
  760|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_from_fd_d0:
  736|    657|libcrux_ml_kem_types_from_fd_d0(uint8_t value[1184U]) {
  737|       |  /* Passing arrays by value in Rust generates a copy in C */
  738|    657|  uint8_t copy_of_value[1184U];
  739|    657|  memcpy(copy_of_value, value, (size_t)1184U * sizeof(uint8_t));
  740|    657|  libcrux_ml_kem_types_MlKemPublicKey_30 lit;
  741|    657|  memcpy(lit.value, copy_of_value, (size_t)1184U * sizeof(uint8_t));
  742|    657|  return lit;
  743|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_instantiations_portable_validate_public_key_41:
 8866|    657|    uint8_t *public_key) {
 8867|    657|  return libcrux_ml_kem_ind_cca_validate_public_key_89(public_key);
 8868|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_validate_public_key_89:
 8833|    657|    uint8_t *public_key) {
 8834|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d deserialized_pk[3U];
 8835|    657|  libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_out_1b(
 8836|    657|      Eurydice_array_to_subslice_to(
  ------------------
  |  |  223|    657|  EURYDICE_SLICE((t *)x, 0, r)
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8837|    657|          (size_t)1184U, public_key,
 8838|    657|          libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U),
 8839|    657|          uint8_t, size_t, uint8_t[]),
 8840|    657|      deserialized_pk);
 8841|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d *uu____0 = deserialized_pk;
 8842|    657|  uint8_t public_key_serialized[1184U];
 8843|    657|  libcrux_ml_kem_ind_cpa_serialize_public_key_89(
 8844|    657|      uu____0,
 8845|    657|      Eurydice_array_to_subslice_from(
  ------------------
  |  |  225|    657|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|    657|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    657|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8846|    657|          (size_t)1184U, public_key,
 8847|    657|          libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U),
 8848|    657|          uint8_t, size_t, uint8_t[]),
 8849|    657|      public_key_serialized);
 8850|    657|  return Eurydice_array_eq((size_t)1184U, public_key, public_key_serialized,
  ------------------
  |  |  240|    657|#define Eurydice_array_eq(sz, a1, a2, t) (memcmp(a1, a2, sz * sizeof(t)) == 0)
  ------------------
 8851|    657|                           uint8_t);
 8852|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_out_1b:
 8802|    657|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret[3U]) {
 8803|    657|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d deserialized_pk[3U];
 8804|  2.62k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (8804:31): [True: 1.97k, False: 657]
  ------------------
 8805|       |    /* original Rust expression is not an lvalue in C */
 8806|  1.97k|    void *lvalue = (void *)0U;
 8807|  1.97k|    deserialized_pk[i] =
 8808|  1.97k|        libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_out_call_mut_0b_1b(
 8809|  1.97k|            &lvalue, i);
 8810|  1.97k|  }
 8811|    657|  libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_1b(
 8812|    657|      public_key, deserialized_pk);
 8813|    657|  memcpy(
 8814|    657|      ret, deserialized_pk,
 8815|    657|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 8816|    657|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_out_call_mut_0b_1b:
 8783|  1.97k|    void **_, size_t tupled_args) {
 8784|  1.97k|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 8785|  1.97k|}

ssh_get_random:
   48|  11.8k|{
   49|       |#ifdef HAVE_OPENSSL_RAND_PRIV_BYTES
   50|       |    if (strong) {
   51|       |        /* Returns -1 when not supported, 0 on error, 1 on success */
   52|       |        return !!RAND_priv_bytes(where, len);
   53|       |    }
   54|       |#else
   55|  11.8k|    (void)strong;
   56|  11.8k|#endif /* HAVE_RAND_PRIV_BYTES */
   57|       |
   58|       |    /* Returns -1 when not supported, 0 on error, 1 on success */
   59|  11.8k|    return !!RAND_bytes(where, len);
   60|  11.8k|}

compress_cleanup:
  268|  3.94k|{
  269|  3.94k|    if (crypto->compress_out_ctx) {
  ------------------
  |  Branch (269:9): [True: 0, False: 3.94k]
  ------------------
  270|      0|        deflateEnd(crypto->compress_out_ctx);
  271|      0|    }
  272|  3.94k|    SAFE_FREE(crypto->compress_out_ctx);
  ------------------
  |  |  373|  3.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 3.94k]
  |  |  |  Branch (373:71): [Folded, False: 3.94k]
  |  |  ------------------
  ------------------
  273|       |
  274|  3.94k|    if (crypto->compress_in_ctx) {
  ------------------
  |  Branch (274:9): [True: 0, False: 3.94k]
  ------------------
  275|      0|        inflateEnd(crypto->compress_in_ctx);
  276|      0|    }
  277|       |    SAFE_FREE(crypto->compress_in_ctx);
  ------------------
  |  |  373|  3.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 3.94k]
  |  |  |  Branch (373:71): [Folded, False: 3.94k]
  |  |  ------------------
  ------------------
  278|  3.94k|}

ssh_client_hybrid_mlkem_init:
  201|    657|{
  202|    657|    struct ssh_crypto_struct *crypto = session->next_crypto;
  203|    657|    ssh_buffer client_init_buffer = NULL;
  204|    657|    int rc, ret = SSH_ERROR;
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  205|       |
  206|    657|    SSH_LOG(SSH_LOG_TRACE, "Initializing hybrid ML-KEM key exchange");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  207|       |
  208|       |    /* Prepare a buffer to concatenate ML-KEM + ECDH public keys */
  209|    657|    client_init_buffer = ssh_buffer_new();
  210|    657|    if (client_init_buffer == NULL) {
  ------------------
  |  Branch (210:9): [True: 0, False: 657]
  ------------------
  211|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  212|      0|        goto cleanup;
  213|      0|    }
  214|       |
  215|       |    /* Generate an ML-KEM keypair */
  216|    657|    rc = ssh_mlkem_init(session);
  217|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (217:9): [True: 0, False: 657]
  ------------------
  218|      0|        ssh_set_error(session, SSH_FATAL, "Failed to generate an ML-KEM keypair");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  219|      0|        goto cleanup;
  220|      0|    }
  221|       |
  222|       |#ifdef DEBUG_CRYPTO
  223|       |    ssh_log_hexdump("ML-KEM client pubkey",
  224|       |                    ssh_string_data(crypto->mlkem_client_pubkey),
  225|       |                    ssh_string_len(crypto->mlkem_client_pubkey));
  226|       |#endif
  227|       |
  228|       |    /* Generate an ECDH keypair and concatenate the public keys  */
  229|    657|    switch (crypto->kex_type) {
  230|    657|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (230:5): [True: 657, False: 0]
  ------------------
  231|    657|        rc = ssh_curve25519_init(session);
  232|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (232:13): [True: 0, False: 657]
  ------------------
  233|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  234|      0|                          SSH_FATAL,
  235|      0|                          "Failed to generate a Curve25519 ECDH keypair");
  236|      0|            goto cleanup;
  237|      0|        }
  238|       |#ifdef DEBUG_CRYPTO
  239|       |        ssh_log_hexdump("Curve25519 client pubkey",
  240|       |                        crypto->curve25519_client_pubkey,
  241|       |                        CURVE25519_PUBKEY_SIZE);
  242|       |#endif
  243|    657|        rc = ssh_buffer_pack(client_init_buffer,
  ------------------
  |  |   50|    657|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  244|    657|                             "PP",
  245|    657|                             ssh_string_len(crypto->mlkem_client_pubkey),
  246|    657|                             ssh_string_data(crypto->mlkem_client_pubkey),
  247|    657|                             (size_t)CURVE25519_PUBKEY_SIZE,
  248|    657|                             crypto->curve25519_client_pubkey);
  249|    657|        break;
  250|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (250:5): [True: 0, False: 657]
  ------------------
  251|       |#ifdef HAVE_MLKEM1024
  252|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  253|       |#endif
  254|      0|        rc = ssh_ecdh_init(session);
  255|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (255:13): [True: 0, False: 0]
  ------------------
  256|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  257|      0|                          SSH_FATAL,
  258|      0|                          "Failed to generate a NIST-curve ECDH keypair");
  259|      0|            goto cleanup;
  260|      0|        }
  261|       |#ifdef DEBUG_CRYPTO
  262|       |        ssh_log_hexdump("ECDH client pubkey",
  263|       |                        ssh_string_data(crypto->ecdh_client_pubkey),
  264|       |                        ssh_string_len(crypto->ecdh_client_pubkey));
  265|       |#endif
  266|      0|        rc = ssh_buffer_pack(client_init_buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  267|      0|                             "PP",
  268|      0|                             ssh_string_len(crypto->mlkem_client_pubkey),
  269|      0|                             ssh_string_data(crypto->mlkem_client_pubkey),
  270|      0|                             ssh_string_len(crypto->ecdh_client_pubkey),
  271|      0|                             ssh_string_data(crypto->ecdh_client_pubkey));
  272|       |
  273|      0|        break;
  274|      0|    default:
  ------------------
  |  Branch (274:5): [True: 0, False: 657]
  ------------------
  275|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  276|      0|        goto cleanup;
  277|    657|    }
  278|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (278:9): [True: 0, False: 657]
  ------------------
  279|      0|        ssh_set_error(session, SSH_FATAL, "Failed to construct client init buffer");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  280|      0|        goto cleanup;
  281|      0|    }
  282|       |
  283|       |    /* Convert the client init buffer to an SSH string */
  284|    657|    ssh_string_free(crypto->hybrid_client_init);
  285|    657|    crypto->hybrid_client_init = ssh_string_new(ssh_buffer_get_len(client_init_buffer));
  286|    657|    if (crypto->hybrid_client_init == NULL) {
  ------------------
  |  Branch (286:9): [True: 0, False: 657]
  ------------------
  287|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  288|      0|        goto cleanup;
  289|      0|    }
  290|       |
  291|    657|    rc = ssh_string_fill(crypto->hybrid_client_init,
  292|    657|                         ssh_buffer_get(client_init_buffer),
  293|    657|                         ssh_buffer_get_len(client_init_buffer));
  294|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (294:9): [True: 0, False: 657]
  ------------------
  295|      0|        ssh_set_error(session, SSH_FATAL, "Failed to convert client init to string");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  296|      0|        goto cleanup;
  297|      0|    }
  298|       |
  299|    657|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    657|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  300|    657|                         "bS",
  301|    657|                         SSH2_MSG_KEX_HYBRID_INIT,
  302|    657|                         crypto->hybrid_client_init);
  303|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (303:9): [True: 0, False: 657]
  ------------------
  304|      0|        ssh_set_error(session, SSH_FATAL, "Failed to construct SSH_MSG_KEX_HYBRID_INIT");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  305|      0|        goto cleanup;
  306|      0|    }
  307|       |
  308|    657|    ssh_packet_set_callbacks(session, &ssh_hybrid_mlkem_client_callbacks);
  309|    657|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  310|       |
  311|    657|    rc = ssh_packet_send(session);
  312|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (312:9): [True: 0, False: 657]
  ------------------
  313|      0|        ssh_set_error(session, SSH_FATAL, "Failed to send SSH_MSG_KEX_HYBRID_INIT");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  314|      0|        goto cleanup;
  315|      0|    }
  316|       |
  317|    657|    ret = SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  318|       |
  319|    657|cleanup:
  320|    657|    ssh_buffer_free(client_init_buffer);
  321|    657|    return ret;
  322|    657|}
ssh_client_hybrid_mlkem_remove_callbacks:
  531|    657|{
  532|    657|    ssh_packet_remove_callbacks(session, &ssh_hybrid_mlkem_client_callbacks);
  533|    657|}
ssh_server_hybrid_mlkem_init:
  905|    657|{
  906|    657|    SSH_LOG(SSH_LOG_TRACE, "Setting up ML-KEM hybrid server callbacks");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  907|    657|    ssh_packet_set_callbacks(session, &ssh_hybrid_mlkem_server_callbacks);
  908|    657|}
hybrid_mlkem.c:ssh_packet_client_hybrid_mlkem_reply:
  325|    657|{
  326|    657|    struct ssh_crypto_struct *crypto = session->next_crypto;
  327|    657|    const struct mlkem_type_info *mlkem_info = NULL;
  328|    657|    ssh_string pubkey_blob = NULL;
  329|    657|    ssh_string signature = NULL;
  330|    657|    ssh_mlkem_shared_secret mlkem_shared_secret;
  331|    657|    ssh_string ecdh_shared_secret = NULL;
  332|    657|    ssh_buffer server_reply_buffer = NULL;
  333|    657|    size_t read_len;
  334|    657|    size_t ecdh_server_pubkey_size;
  335|    657|    int rc;
  336|    657|    (void)type;
  337|    657|    (void)user;
  338|       |
  339|    657|    SSH_LOG(SSH_LOG_TRACE, "Received ML-KEM hybrid server reply");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  340|       |
  341|    657|    ssh_client_hybrid_mlkem_remove_callbacks(session);
  342|       |
  343|    657|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
  344|    657|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (344:9): [True: 0, False: 657]
  ------------------
  345|      0|        ssh_set_error(session, SSH_FATAL, "Unknown ML-KEM type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  346|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  347|      0|        goto cleanup;
  348|      0|    }
  349|       |
  350|    657|    pubkey_blob = ssh_buffer_get_ssh_string(packet);
  351|    657|    if (pubkey_blob == NULL) {
  ------------------
  |  Branch (351:9): [True: 0, False: 657]
  ------------------
  352|      0|        ssh_set_error(session, SSH_FATAL, "No public key in packet");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  353|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  354|      0|        goto cleanup;
  355|      0|    }
  356|       |
  357|    657|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  358|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (358:9): [True: 0, False: 657]
  ------------------
  359|      0|        ssh_set_error(session, SSH_FATAL, "Failed to import public key");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  360|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  361|      0|        goto cleanup;
  362|      0|    }
  363|       |
  364|       |    /* Get server reply containing ML-KEM ciphertext + ECDH public key */
  365|    657|    ssh_string_free(crypto->hybrid_server_reply);
  366|    657|    crypto->hybrid_server_reply = ssh_buffer_get_ssh_string(packet);
  367|    657|    if (crypto->hybrid_server_reply == NULL) {
  ------------------
  |  Branch (367:9): [True: 0, False: 657]
  ------------------
  368|      0|        ssh_set_error(session, SSH_FATAL, "No server reply in packet");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  369|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  370|      0|        goto cleanup;
  371|      0|    }
  372|       |
  373|    657|    server_reply_buffer = ssh_buffer_new();
  374|    657|    if (server_reply_buffer == NULL) {
  ------------------
  |  Branch (374:9): [True: 0, False: 657]
  ------------------
  375|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  376|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  377|      0|        goto cleanup;
  378|      0|    }
  379|       |
  380|    657|    rc = ssh_buffer_add_data(server_reply_buffer,
  381|    657|                             ssh_string_data(crypto->hybrid_server_reply),
  382|    657|                             ssh_string_len(crypto->hybrid_server_reply));
  383|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (383:9): [True: 0, False: 657]
  ------------------
  384|      0|        ssh_set_error(session, SSH_FATAL, "Failed to pack server reply to a buffer");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  385|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  386|      0|        goto cleanup;
  387|      0|    }
  388|       |
  389|       |    /* Store ML-KEM ciphertext for decapsulation and sessionid calculation */
  390|    657|    ssh_string_free(crypto->mlkem_ciphertext);
  391|    657|    crypto->mlkem_ciphertext = ssh_string_new(mlkem_info->ciphertext_size);
  392|    657|    if (crypto->mlkem_ciphertext == NULL) {
  ------------------
  |  Branch (392:9): [True: 0, False: 657]
  ------------------
  393|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  394|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  395|      0|        goto cleanup;
  396|      0|    }
  397|       |
  398|    657|    read_len = ssh_buffer_get_data(server_reply_buffer,
  399|    657|                                   ssh_string_data(crypto->mlkem_ciphertext),
  400|    657|                                   mlkem_info->ciphertext_size);
  401|    657|    if (read_len != mlkem_info->ciphertext_size) {
  ------------------
  |  Branch (401:9): [True: 0, False: 657]
  ------------------
  402|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  403|      0|                      SSH_FATAL,
  404|      0|                      "Could not read ML-KEM ciphertext from "
  405|      0|                      "the server reply buffer, buffer too short");
  406|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  407|      0|        goto cleanup;
  408|      0|    }
  409|       |
  410|       |#ifdef DEBUG_CRYPTO
  411|       |    ssh_log_hexdump("ML-KEM ciphertext",
  412|       |                    ssh_string_data(crypto->mlkem_ciphertext),
  413|       |                    ssh_string_len(crypto->mlkem_ciphertext));
  414|       |#endif
  415|       |
  416|       |    /* Extract server ECDH public key */
  417|    657|    switch (crypto->kex_type) {
  418|    657|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (418:5): [True: 657, False: 0]
  ------------------
  419|    657|        read_len = ssh_buffer_get_data(server_reply_buffer,
  420|    657|                                       crypto->curve25519_server_pubkey,
  421|    657|                                       CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   40|    657|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  422|    657|        if (read_len != CURVE25519_PUBKEY_SIZE) {
  ------------------
  |  |   40|    657|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  |  Branch (422:13): [True: 0, False: 657]
  ------------------
  423|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  424|      0|                          SSH_FATAL,
  425|      0|                          "Could not read Curve25519 pubkey from "
  426|      0|                          "the server reply buffer, buffer too short");
  427|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
  428|      0|            goto cleanup;
  429|      0|        }
  430|    657|        if (ssh_buffer_get_len(server_reply_buffer) > 0) {
  ------------------
  |  Branch (430:13): [True: 0, False: 657]
  ------------------
  431|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  432|      0|                          SSH_FATAL,
  433|      0|                          "Unrecognized data in the server reply buffer");
  434|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
  435|      0|            goto cleanup;
  436|      0|        }
  437|       |#ifdef DEBUG_CRYPTO
  438|       |        ssh_log_hexdump("Curve25519 server pubkey",
  439|       |                        crypto->curve25519_server_pubkey,
  440|       |                        CURVE25519_PUBKEY_SIZE);
  441|       |#endif
  442|    657|        break;
  443|    657|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (443:5): [True: 0, False: 657]
  ------------------
  444|       |#ifdef HAVE_MLKEM1024
  445|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  446|       |#endif
  447|      0|        ecdh_server_pubkey_size = ssh_buffer_get_len(server_reply_buffer);
  448|      0|        ssh_string_free(crypto->ecdh_server_pubkey);
  449|      0|        crypto->ecdh_server_pubkey = ssh_string_new(ecdh_server_pubkey_size);
  450|      0|        if (crypto->ecdh_server_pubkey == NULL) {
  ------------------
  |  Branch (450:13): [True: 0, False: 0]
  ------------------
  451|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  452|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
  453|      0|            goto cleanup;
  454|      0|        }
  455|      0|        ssh_buffer_get_data(server_reply_buffer,
  456|      0|                            ssh_string_data(crypto->ecdh_server_pubkey),
  457|      0|                            ecdh_server_pubkey_size);
  458|       |#ifdef DEBUG_CRYPTO
  459|       |        ssh_log_hexdump("ECDH server pubkey",
  460|       |                        ssh_string_data(crypto->ecdh_server_pubkey),
  461|       |                        ssh_string_len(crypto->ecdh_server_pubkey));
  462|       |#endif
  463|      0|        break;
  464|      0|    default:
  ------------------
  |  Branch (464:5): [True: 0, False: 657]
  ------------------
  465|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  466|      0|        goto cleanup;
  467|    657|    }
  468|       |
  469|       |    /* Decapsulate ML-KEM shared secret */
  470|    657|    rc = ssh_mlkem_decapsulate(session, mlkem_shared_secret);
  471|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (471:9): [True: 0, False: 657]
  ------------------
  472|      0|        ssh_set_error(session, SSH_FATAL, "ML-KEM decapsulation failed");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  473|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  474|      0|        goto cleanup;
  475|      0|    }
  476|       |
  477|       |#ifdef DEBUG_CRYPTO
  478|       |    ssh_log_hexdump("ML-KEM shared secret",
  479|       |                    mlkem_shared_secret,
  480|       |                    MLKEM_SHARED_SECRET_SIZE);
  481|       |#endif
  482|       |
  483|       |    /* Derive the classical ECDH shared secret */
  484|    657|    ecdh_shared_secret = derive_ecdh_secret(session);
  485|    657|    if (ecdh_shared_secret == NULL) {
  ------------------
  |  Branch (485:9): [True: 0, False: 657]
  ------------------
  486|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  487|      0|        goto cleanup;
  488|      0|    }
  489|       |
  490|       |#ifdef DEBUG_CRYPTO
  491|       |    ssh_log_hexdump("ECDH shared secret",
  492|       |                    ssh_string_data(ecdh_shared_secret),
  493|       |                    ssh_string_len(ecdh_shared_secret));
  494|       |#endif
  495|       |
  496|       |    /* Derive the final shared secret */
  497|    657|    rc = derive_hybrid_secret(session, mlkem_shared_secret, ecdh_shared_secret);
  498|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (498:9): [True: 0, False: 657]
  ------------------
  499|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  500|      0|        goto cleanup;
  501|      0|    }
  502|       |
  503|       |    /* Get signature for verification */
  504|    657|    signature = ssh_buffer_get_ssh_string(packet);
  505|    657|    if (signature == NULL) {
  ------------------
  |  Branch (505:9): [True: 0, False: 657]
  ------------------
  506|      0|        ssh_set_error(session, SSH_FATAL, "No signature in packet");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  507|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  508|      0|        goto cleanup;
  509|      0|    }
  510|    657|    crypto->dh_server_signature = signature;
  511|       |
  512|       |    /* Send the MSG_NEWKEYS */
  513|    657|    rc = ssh_packet_send_newkeys(session);
  514|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (514:9): [True: 0, False: 657]
  ------------------
  515|      0|        ssh_set_error(session, SSH_FATAL, "Failed to send SSH_MSG_NEWKEYS");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  516|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  517|      0|        goto cleanup;
  518|      0|    }
  519|    657|    session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  520|       |
  521|    657|cleanup:
  522|    657|    ssh_burn(mlkem_shared_secret, sizeof(mlkem_shared_secret));
  ------------------
  |  |  388|    657|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  523|    657|    ssh_string_burn(ecdh_shared_secret);
  524|    657|    ssh_string_free(ecdh_shared_secret);
  525|    657|    ssh_string_free(pubkey_blob);
  526|    657|    ssh_buffer_free(server_reply_buffer);
  527|    657|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
  528|    657|}
hybrid_mlkem.c:derive_ecdh_secret:
   95|  1.31k|{
   96|  1.31k|    ssh_string secret = NULL;
   97|       |
   98|  1.31k|    switch (session->next_crypto->kex_type) {
   99|  1.31k|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (99:5): [True: 1.31k, False: 0]
  ------------------
  100|  1.31k|        secret = derive_curve25519_secret(session);
  101|  1.31k|        break;
  102|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (102:5): [True: 0, False: 1.31k]
  ------------------
  103|      0|        secret = derive_nist_curve_secret(session, NISTP256_SHARED_SECRET_SIZE);
  ------------------
  |  |   37|      0|#define NISTP256_SHARED_SECRET_SIZE 32
  ------------------
  104|      0|        break;
  105|       |#ifdef HAVE_MLKEM1024
  106|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  107|       |        secret = derive_nist_curve_secret(session, NISTP384_SHARED_SECRET_SIZE);
  108|       |        break;
  109|       |#endif
  110|      0|    default:
  ------------------
  |  Branch (110:5): [True: 0, False: 1.31k]
  ------------------
  111|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  112|      0|        return NULL;
  113|  1.31k|    }
  114|       |
  115|  1.31k|    return secret;
  116|  1.31k|}
hybrid_mlkem.c:derive_curve25519_secret:
   49|  1.31k|{
   50|  1.31k|    ssh_string secret = NULL;
   51|  1.31k|    int rc;
   52|       |
   53|  1.31k|    secret = ssh_string_new(CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   40|  1.31k|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
   54|  1.31k|    if (secret == NULL) {
  ------------------
  |  Branch (54:9): [True: 0, False: 1.31k]
  ------------------
   55|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
   56|      0|        return NULL;
   57|      0|    }
   58|       |
   59|  1.31k|    rc = ssh_curve25519_create_k(session, ssh_string_data(secret));
   60|  1.31k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (60:9): [True: 0, False: 1.31k]
  ------------------
   61|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   62|      0|                      SSH_FATAL,
   63|      0|                      "Curve25519 secret derivation failed");
   64|      0|        ssh_string_free(secret);
   65|      0|        return NULL;
   66|      0|    }
   67|       |
   68|  1.31k|    return secret;
   69|  1.31k|}
hybrid_mlkem.c:derive_hybrid_secret:
  121|  1.31k|{
  122|  1.31k|    struct ssh_crypto_struct *crypto = session->next_crypto;
  123|  1.31k|    ssh_buffer combined_secret = NULL;
  124|  1.31k|    int (*digest)(const unsigned char *, size_t, unsigned char *) = NULL;
  125|  1.31k|    size_t digest_len;
  126|  1.31k|    int rc, ret = SSH_ERROR;
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  127|       |
  128|  1.31k|    switch (crypto->kex_type) {
  129|  1.31k|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (129:5): [True: 1.31k, False: 0]
  ------------------
  130|  1.31k|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (130:5): [True: 0, False: 1.31k]
  ------------------
  131|  1.31k|        digest = sha256;
  132|  1.31k|        digest_len = SHA256_DIGEST_LEN;
  ------------------
  |  |   45|  1.31k|#define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
  ------------------
  133|  1.31k|        break;
  134|       |#ifdef HAVE_MLKEM1024
  135|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  136|       |        digest = sha384;
  137|       |        digest_len = SHA384_DIGEST_LEN;
  138|       |        break;
  139|       |#endif
  140|      0|    default:
  ------------------
  |  Branch (140:5): [True: 0, False: 1.31k]
  ------------------
  141|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  142|      0|        goto cleanup;
  143|  1.31k|    }
  144|       |
  145|       |    /* Concatenate the two shared secrets */
  146|  1.31k|    combined_secret = ssh_buffer_new();
  147|  1.31k|    if (combined_secret == NULL) {
  ------------------
  |  Branch (147:9): [True: 0, False: 1.31k]
  ------------------
  148|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  149|      0|        goto cleanup;
  150|      0|    }
  151|  1.31k|    ssh_buffer_set_secure(combined_secret);
  152|       |
  153|  1.31k|    rc = ssh_buffer_pack(combined_secret,
  ------------------
  |  |   50|  1.31k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.31k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.31k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.31k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.31k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  154|  1.31k|                         "PP",
  155|  1.31k|                         (size_t)MLKEM_SHARED_SECRET_SIZE,
  156|  1.31k|                         mlkem_shared_secret,
  157|  1.31k|                         ssh_string_len(ecdh_shared_secret),
  158|  1.31k|                         ssh_string_data(ecdh_shared_secret));
  159|  1.31k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (159:9): [True: 0, False: 1.31k]
  ------------------
  160|      0|        ssh_set_error(session, SSH_FATAL, "Failed to concatenate shared secrets");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  161|      0|        goto cleanup;
  162|      0|    }
  163|       |
  164|       |#ifdef DEBUG_CRYPTO
  165|       |    ssh_log_hexdump("Concatenated shared secrets",
  166|       |                    ssh_buffer_get(combined_secret),
  167|       |                    ssh_buffer_get_len(combined_secret));
  168|       |#endif
  169|       |
  170|       |    /* Store the hashed combined shared secrets */
  171|  1.31k|    ssh_string_burn(crypto->hybrid_shared_secret);
  172|  1.31k|    ssh_string_free(crypto->hybrid_shared_secret);
  173|  1.31k|    crypto->hybrid_shared_secret = ssh_string_new(digest_len);
  174|  1.31k|    if (crypto->hybrid_shared_secret == NULL) {
  ------------------
  |  Branch (174:9): [True: 0, False: 1.31k]
  ------------------
  175|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  176|      0|        goto cleanup;
  177|      0|    }
  178|       |
  179|  1.31k|    rc = digest(ssh_buffer_get(combined_secret),
  180|  1.31k|                ssh_buffer_get_len(combined_secret),
  181|  1.31k|                ssh_string_data(crypto->hybrid_shared_secret));
  182|  1.31k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (182:9): [True: 0, False: 1.31k]
  ------------------
  183|      0|        ssh_set_error(session, SSH_FATAL, "Shared secret hashing failed");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  184|      0|        goto cleanup;
  185|      0|    }
  186|       |
  187|       |#ifdef DEBUG_CRYPTO
  188|       |    ssh_log_hexdump("Hybrid shared secret",
  189|       |                    ssh_string_data(crypto->hybrid_shared_secret),
  190|       |                    digest_len);
  191|       |#endif
  192|       |
  193|  1.31k|    ret = SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  194|       |
  195|  1.31k|cleanup:
  196|  1.31k|    ssh_buffer_free(combined_secret);
  197|  1.31k|    return ret;
  198|  1.31k|}
hybrid_mlkem.c:ssh_packet_server_hybrid_mlkem_init:
  551|    657|{
  552|    657|    struct ssh_crypto_struct *crypto = session->next_crypto;
  553|    657|    const struct mlkem_type_info *mlkem_info = NULL;
  554|    657|    ssh_string ecdh_shared_secret = NULL;
  555|    657|    ssh_mlkem_shared_secret mlkem_shared_secret;
  556|    657|    ssh_buffer server_reply_buffer = NULL;
  557|    657|    ssh_buffer client_init_buffer = NULL;
  558|    657|    ssh_key privkey = NULL;
  559|    657|    enum ssh_digest_e digest = SSH_DIGEST_AUTO;
  560|    657|    ssh_string signature = NULL;
  561|    657|    ssh_string pubkey_blob = NULL;
  562|    657|    size_t ecdh_client_pubkey_size;
  563|    657|    size_t read_len;
  564|    657|    int rc;
  565|    657|    (void)type;
  566|    657|    (void)user;
  567|       |
  568|    657|    SSH_LOG(SSH_LOG_TRACE, "Received ML-KEM hybrid client init");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  569|       |
  570|    657|    ssh_packet_remove_callbacks(session, &ssh_hybrid_mlkem_server_callbacks);
  571|       |
  572|    657|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
  573|    657|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (573:9): [True: 0, False: 657]
  ------------------
  574|      0|        ssh_set_error(session, SSH_FATAL, "Unknown ML-KEM type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  575|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  576|      0|        goto cleanup;
  577|      0|    }
  578|       |
  579|       |    /* Generate an ECDH keypair  */
  580|    657|    switch (crypto->kex_type) {
  581|    657|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (581:5): [True: 657, False: 0]
  ------------------
  582|    657|        rc = ssh_curve25519_init(session);
  583|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (583:13): [True: 0, False: 657]
  ------------------
  584|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  585|      0|                          SSH_FATAL,
  586|      0|                          "Failed to generate a Curve25519 ECDH keypair");
  587|      0|            goto cleanup;
  588|      0|        }
  589|       |#ifdef DEBUG_CRYPTO
  590|       |        ssh_log_hexdump("Curve25519 server pubkey",
  591|       |                        crypto->curve25519_server_pubkey,
  592|       |                        CURVE25519_PUBKEY_SIZE);
  593|       |#endif
  594|    657|        break;
  595|    657|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (595:5): [True: 0, False: 657]
  ------------------
  596|       |#ifdef HAVE_MLKEM1024
  597|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  598|       |#endif
  599|      0|        rc = ssh_ecdh_init(session);
  600|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (600:13): [True: 0, False: 0]
  ------------------
  601|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  602|      0|                          SSH_FATAL,
  603|      0|                          "Failed to generate a NIST-curve ECDH keypair");
  604|      0|            goto cleanup;
  605|      0|        }
  606|       |#ifdef DEBUG_CRYPTO
  607|       |        ssh_log_hexdump("ECDH server pubkey",
  608|       |                        ssh_string_data(crypto->ecdh_server_pubkey),
  609|       |                        ssh_string_len(crypto->ecdh_server_pubkey));
  610|       |#endif
  611|      0|        break;
  612|      0|    default:
  ------------------
  |  Branch (612:5): [True: 0, False: 657]
  ------------------
  613|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  614|      0|        goto cleanup;
  615|    657|    }
  616|       |
  617|       |    /* Get client init: ML-KEM public key + ECDH public key */
  618|    657|    ssh_string_free(crypto->hybrid_client_init);
  619|    657|    crypto->hybrid_client_init = ssh_buffer_get_ssh_string(packet);
  620|    657|    if (crypto->hybrid_client_init == NULL) {
  ------------------
  |  Branch (620:9): [True: 0, False: 657]
  ------------------
  621|      0|        ssh_set_error(session, SSH_FATAL, "No client public keys in packet");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  622|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  623|      0|        goto cleanup;
  624|      0|    }
  625|       |
  626|    657|    client_init_buffer = ssh_buffer_new();
  627|    657|    if (client_init_buffer == NULL) {
  ------------------
  |  Branch (627:9): [True: 0, False: 657]
  ------------------
  628|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  629|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  630|      0|        goto cleanup;
  631|      0|    }
  632|       |
  633|    657|    rc = ssh_buffer_add_data(client_init_buffer,
  634|    657|                             ssh_string_data(crypto->hybrid_client_init),
  635|    657|                             ssh_string_len(crypto->hybrid_client_init));
  636|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (636:9): [True: 0, False: 657]
  ------------------
  637|      0|        ssh_set_error(session, SSH_FATAL, "Failed to pack client init to a buffer");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  638|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  639|      0|        goto cleanup;
  640|      0|    }
  641|       |
  642|       |    /* Extract client ML-KEM public key */
  643|    657|    ssh_string_free(crypto->mlkem_client_pubkey);
  644|    657|    crypto->mlkem_client_pubkey = ssh_string_new(mlkem_info->pubkey_size);
  645|    657|    if (crypto->mlkem_client_pubkey == NULL) {
  ------------------
  |  Branch (645:9): [True: 0, False: 657]
  ------------------
  646|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  647|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  648|      0|        goto cleanup;
  649|      0|    }
  650|       |
  651|    657|    read_len = ssh_buffer_get_data(client_init_buffer,
  652|    657|                                   ssh_string_data(crypto->mlkem_client_pubkey),
  653|    657|                                   mlkem_info->pubkey_size);
  654|    657|    if (read_len != mlkem_info->pubkey_size) {
  ------------------
  |  Branch (654:9): [True: 0, False: 657]
  ------------------
  655|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  656|      0|                      SSH_FATAL,
  657|      0|                      "Could not read ML-KEM pubkey from "
  658|      0|                      "the client init buffer, buffer too short");
  659|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  660|      0|        goto cleanup;
  661|      0|    }
  662|       |
  663|       |#ifdef DEBUG_CRYPTO
  664|       |    ssh_log_hexdump("ML-KEM client pubkey",
  665|       |                    ssh_string_data(crypto->mlkem_client_pubkey),
  666|       |                    ssh_string_len(crypto->mlkem_client_pubkey));
  667|       |#endif
  668|       |
  669|       |    /* Extract client ECDH public key */
  670|    657|    switch (crypto->kex_type) {
  671|    657|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (671:5): [True: 657, False: 0]
  ------------------
  672|    657|        read_len = ssh_buffer_get_data(client_init_buffer,
  673|    657|                                       crypto->curve25519_client_pubkey,
  674|    657|                                       CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   40|    657|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  675|    657|        if (read_len != CURVE25519_PUBKEY_SIZE) {
  ------------------
  |  |   40|    657|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  |  Branch (675:13): [True: 0, False: 657]
  ------------------
  676|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  677|      0|                          SSH_FATAL,
  678|      0|                          "Could not read Curve25519 pubkey from "
  679|      0|                          "the client init buffer, buffer too short");
  680|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
  681|      0|            goto cleanup;
  682|      0|        }
  683|    657|        if (ssh_buffer_get_len(client_init_buffer) > 0) {
  ------------------
  |  Branch (683:13): [True: 0, False: 657]
  ------------------
  684|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  685|      0|                          SSH_FATAL,
  686|      0|                          "Unrecognized data in the client init buffer");
  687|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
  688|      0|            goto cleanup;
  689|      0|        }
  690|       |#ifdef DEBUG_CRYPTO
  691|       |        ssh_log_hexdump("Curve25519 client pubkey",
  692|       |                        crypto->curve25519_client_pubkey,
  693|       |                        CURVE25519_PUBKEY_SIZE);
  694|       |#endif
  695|    657|        break;
  696|    657|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (696:5): [True: 0, False: 657]
  ------------------
  697|       |#ifdef HAVE_MLKEM1024
  698|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  699|       |#endif
  700|      0|        ecdh_client_pubkey_size = ssh_buffer_get_len(client_init_buffer);
  701|      0|        ssh_string_free(crypto->ecdh_client_pubkey);
  702|      0|        crypto->ecdh_client_pubkey = ssh_string_new(ecdh_client_pubkey_size);
  703|      0|        if (crypto->ecdh_client_pubkey == NULL) {
  ------------------
  |  Branch (703:13): [True: 0, False: 0]
  ------------------
  704|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  705|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
  706|      0|            goto cleanup;
  707|      0|        }
  708|      0|        ssh_buffer_get_data(client_init_buffer,
  709|      0|                            ssh_string_data(crypto->ecdh_client_pubkey),
  710|      0|                            ecdh_client_pubkey_size);
  711|       |#ifdef DEBUG_CRYPTO
  712|       |        ssh_log_hexdump("ECDH client pubkey",
  713|       |                        ssh_string_data(crypto->ecdh_client_pubkey),
  714|       |                        ssh_string_len(crypto->ecdh_client_pubkey));
  715|       |#endif
  716|      0|        break;
  717|      0|    default:
  ------------------
  |  Branch (717:5): [True: 0, False: 657]
  ------------------
  718|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  719|      0|        goto cleanup;
  720|    657|    }
  721|       |
  722|       |    /* Encapsulate an ML-KEM shared secret using client's ML-KEM public key */
  723|    657|    rc = ssh_mlkem_encapsulate(session, mlkem_shared_secret);
  724|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (724:9): [True: 0, False: 657]
  ------------------
  725|      0|        ssh_set_error(session, SSH_FATAL, "ML-KEM encapsulation failed");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  726|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  727|      0|        goto cleanup;
  728|      0|    }
  729|       |
  730|       |#ifdef DEBUG_CRYPTO
  731|       |    ssh_log_hexdump("ML-KEM shared secret",
  732|       |                    mlkem_shared_secret,
  733|       |                    MLKEM_SHARED_SECRET_SIZE);
  734|       |    ssh_log_hexdump("ML-KEM ciphertext",
  735|       |                    ssh_string_data(crypto->mlkem_ciphertext),
  736|       |                    ssh_string_len(crypto->mlkem_ciphertext));
  737|       |#endif
  738|       |
  739|       |    /* Derive the classical ECDH shared secret */
  740|    657|    ecdh_shared_secret = derive_ecdh_secret(session);
  741|    657|    if (ecdh_shared_secret == NULL) {
  ------------------
  |  Branch (741:9): [True: 0, False: 657]
  ------------------
  742|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  743|      0|        goto cleanup;
  744|      0|    }
  745|       |
  746|       |#ifdef DEBUG_CRYPTO
  747|       |    ssh_log_hexdump("ECDH shared secret",
  748|       |                    ssh_string_data(ecdh_shared_secret),
  749|       |                    ssh_string_len(ecdh_shared_secret));
  750|       |#endif
  751|       |
  752|       |    /* Derive the final shared secret */
  753|    657|    rc = derive_hybrid_secret(session, mlkem_shared_secret, ecdh_shared_secret);
  754|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (754:9): [True: 0, False: 657]
  ------------------
  755|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  756|      0|        goto cleanup;
  757|      0|    }
  758|       |
  759|       |    /* Create server reply: ML-KEM ciphertext + ECDH public key */
  760|    657|    server_reply_buffer = ssh_buffer_new();
  761|    657|    if (server_reply_buffer == NULL) {
  ------------------
  |  Branch (761:9): [True: 0, False: 657]
  ------------------
  762|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  763|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  764|      0|        goto cleanup;
  765|      0|    }
  766|       |
  767|    657|    switch (crypto->kex_type) {
  768|    657|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (768:5): [True: 657, False: 0]
  ------------------
  769|    657|        rc = ssh_buffer_pack(server_reply_buffer,
  ------------------
  |  |   50|    657|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  770|    657|                             "PP",
  771|    657|                             ssh_string_len(crypto->mlkem_ciphertext),
  772|    657|                             ssh_string_data(crypto->mlkem_ciphertext),
  773|    657|                             (size_t)CURVE25519_PUBKEY_SIZE,
  774|    657|                             crypto->curve25519_server_pubkey);
  775|    657|        break;
  776|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (776:5): [True: 0, False: 657]
  ------------------
  777|       |#ifdef HAVE_MLKEM1024
  778|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  779|       |#endif
  780|      0|        rc = ssh_buffer_pack(server_reply_buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  781|      0|                             "PP",
  782|      0|                             ssh_string_len(crypto->mlkem_ciphertext),
  783|      0|                             ssh_string_data(crypto->mlkem_ciphertext),
  784|      0|                             ssh_string_len(crypto->ecdh_server_pubkey),
  785|      0|                             ssh_string_data(crypto->ecdh_server_pubkey));
  786|      0|        break;
  787|      0|    default:
  ------------------
  |  Branch (787:5): [True: 0, False: 657]
  ------------------
  788|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  789|      0|        goto cleanup;
  790|    657|    }
  791|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (791:9): [True: 0, False: 657]
  ------------------
  792|      0|        ssh_set_error(session, SSH_FATAL, "Failed to construct server reply buffer");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  793|      0|        goto cleanup;
  794|      0|    }
  795|       |
  796|       |    /* Convert the reply buffer to an SSH string for sending */
  797|    657|    ssh_string_free(crypto->hybrid_server_reply);
  798|    657|    crypto->hybrid_server_reply = ssh_string_new(ssh_buffer_get_len(server_reply_buffer));
  799|    657|    if (crypto->hybrid_server_reply == NULL) {
  ------------------
  |  Branch (799:9): [True: 0, False: 657]
  ------------------
  800|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  801|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  802|      0|        goto cleanup;
  803|      0|    }
  804|       |
  805|    657|    rc = ssh_string_fill(crypto->hybrid_server_reply,
  806|    657|                         ssh_buffer_get(server_reply_buffer),
  807|    657|                         ssh_buffer_get_len(server_reply_buffer));
  808|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (808:9): [True: 0, False: 657]
  ------------------
  809|      0|        ssh_set_error(session, SSH_FATAL, "Failed to convert reply buffer to string");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  810|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  811|      0|        goto cleanup;
  812|      0|    }
  813|       |
  814|       |    /* Add MSG_KEX_ECDH_REPLY header */
  815|    657|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_KEX_HYBRID_REPLY);
  ------------------
  |  |   20|    657|#define SSH2_MSG_KEX_HYBRID_REPLY 31
  ------------------
  816|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (816:9): [True: 0, False: 657]
  ------------------
  817|      0|        ssh_set_error(session, SSH_FATAL, "Failed to add MSG_KEX_HYBRID_REPLY to buffer");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  818|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  819|      0|        goto cleanup;
  820|      0|    }
  821|       |
  822|       |    /* Get server host key */
  823|    657|    rc = ssh_get_key_params(session, &privkey, &digest);
  824|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (824:9): [True: 0, False: 657]
  ------------------
  825|      0|        ssh_set_error(session, SSH_FATAL, "Could not get server key params");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  826|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  827|      0|        goto cleanup;
  828|      0|    }
  829|       |
  830|       |    /* Build session ID */
  831|    657|    rc = ssh_make_sessionid(session);
  832|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (832:9): [True: 0, False: 657]
  ------------------
  833|      0|        ssh_set_error(session, SSH_FATAL, "Could not create a session id");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  834|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  835|      0|        goto cleanup;
  836|      0|    }
  837|       |
  838|    657|    rc = ssh_dh_get_next_server_publickey_blob(session, &pubkey_blob);
  839|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (839:9): [True: 0, False: 657]
  ------------------
  840|      0|        ssh_set_error(session, SSH_FATAL, "Could not export server public key");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  841|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  842|      0|        goto cleanup;
  843|      0|    }
  844|       |
  845|       |    /* Add server public key to output */
  846|    657|    rc = ssh_buffer_add_ssh_string(session->out_buffer, pubkey_blob);
  847|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (847:9): [True: 0, False: 657]
  ------------------
  848|      0|        ssh_set_error(session, SSH_FATAL, "Failed to add server hostkey to buffer");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  849|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  850|      0|        goto cleanup;
  851|      0|    }
  852|       |
  853|       |    /* Add server reply */
  854|    657|    rc = ssh_buffer_add_ssh_string(session->out_buffer, crypto->hybrid_server_reply);
  855|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (855:9): [True: 0, False: 657]
  ------------------
  856|      0|        ssh_set_error(session, SSH_FATAL, "Failed to add server reply to buffer");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  857|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  858|      0|        goto cleanup;
  859|      0|    }
  860|       |
  861|       |    /* Sign the exchange hash */
  862|    657|    signature = ssh_srv_pki_do_sign_sessionid(session, privkey, digest);
  863|    657|    if (signature == NULL) {
  ------------------
  |  Branch (863:9): [True: 0, False: 657]
  ------------------
  864|      0|        ssh_set_error(session, SSH_FATAL, "Could not sign the session id");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  865|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  866|      0|        goto cleanup;
  867|      0|    }
  868|       |
  869|       |    /* Add signature */
  870|    657|    rc = ssh_buffer_add_ssh_string(session->out_buffer, signature);
  871|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (871:9): [True: 0, False: 657]
  ------------------
  872|      0|        ssh_set_error(session, SSH_FATAL, "Failed to add signature to buffer");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  873|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  874|      0|        goto cleanup;
  875|      0|    }
  876|       |
  877|    657|    rc = ssh_packet_send(session);
  878|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (878:9): [True: 0, False: 657]
  ------------------
  879|      0|        ssh_set_error(session, SSH_FATAL, "Failed to send SSH_MSG_KEX_ECDH_REPLY");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  880|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  881|      0|        goto cleanup;
  882|      0|    }
  883|       |
  884|       |    /* Send the MSG_NEWKEYS */
  885|    657|    rc = ssh_packet_send_newkeys(session);
  886|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (886:9): [True: 0, False: 657]
  ------------------
  887|      0|        ssh_set_error(session, SSH_FATAL, "Failed to send SSH_MSG_NEWKEYS");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  888|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  889|      0|        goto cleanup;
  890|      0|    }
  891|    657|    session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  892|       |
  893|    657|cleanup:
  894|    657|    ssh_burn(mlkem_shared_secret, sizeof(mlkem_shared_secret));
  ------------------
  |  |  388|    657|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  895|    657|    ssh_string_burn(ecdh_shared_secret);
  896|    657|    ssh_string_free(ecdh_shared_secret);
  897|    657|    ssh_string_free(pubkey_blob);
  898|    657|    ssh_string_free(signature);
  899|    657|    ssh_buffer_free(client_init_buffer);
  900|    657|    ssh_buffer_free(server_reply_buffer);
  901|    657|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
  902|    657|}

libssh_constructor:
  114|      2|{
  115|       |
  116|      2|    int rc;
  117|       |
  118|      2|    rc = _ssh_init(1);
  119|       |
  120|      2|    if (rc < 0) {
  ------------------
  |  Branch (120:9): [True: 0, False: 2]
  ------------------
  121|      0|        fprintf(stderr, "Error in auto_init()\n");
  122|      0|    }
  123|       |
  124|      2|    return;
  125|      2|}
ssh_init:
  156|      2|int ssh_init(void) {
  157|      2|    return _ssh_init(0);
  158|      2|}
ssh_finalize:
  241|      2|int ssh_finalize(void) {
  242|      2|    return _ssh_finalize(0);
  243|      2|}
is_ssh_initialized:
  284|    657|bool is_ssh_initialized(void) {
  285|       |
  286|    657|    bool is_initialized = false;
  287|       |
  288|    657|    ssh_mutex_lock(&ssh_init_mutex);
  289|    657|    is_initialized = _ssh_initialized > 0;
  290|    657|    ssh_mutex_unlock(&ssh_init_mutex);
  291|       |
  292|    657|    return is_initialized;
  293|    657|}
init.c:_ssh_init:
   62|      4|static int _ssh_init(unsigned constructor) {
   63|       |
   64|      4|    int rc = 0;
   65|       |
   66|      4|    if (!constructor) {
  ------------------
  |  Branch (66:9): [True: 2, False: 2]
  ------------------
   67|      2|        ssh_mutex_lock(&ssh_init_mutex);
   68|      2|    }
   69|       |
   70|      4|    _ssh_initialized++;
   71|       |
   72|      4|    if (_ssh_initialized > 1) {
  ------------------
  |  Branch (72:9): [True: 2, False: 2]
  ------------------
   73|      2|        rc = _ssh_init_ret;
   74|      2|        goto _ret;
   75|      2|    }
   76|       |
   77|      2|    rc = ssh_threads_init();
   78|      2|    if (rc) {
  ------------------
  |  Branch (78:9): [True: 0, False: 2]
  ------------------
   79|      0|        goto _ret;
   80|      0|    }
   81|       |
   82|      2|    rc = ssh_crypto_init();
   83|      2|    if (rc) {
  ------------------
  |  Branch (83:9): [True: 0, False: 2]
  ------------------
   84|      0|        goto _ret;
   85|      0|    }
   86|       |
   87|      2|    rc = ssh_dh_init();
   88|      2|    if (rc) {
  ------------------
  |  Branch (88:9): [True: 0, False: 2]
  ------------------
   89|      0|        goto _ret;
   90|      0|    }
   91|       |
   92|      2|    rc = ssh_socket_init();
   93|      2|    if (rc) {
  ------------------
  |  Branch (93:9): [True: 0, False: 2]
  ------------------
   94|      0|        goto _ret;
   95|      0|    }
   96|       |
   97|      4|_ret:
   98|      4|    _ssh_init_ret = rc;
   99|       |
  100|      4|    if (!constructor) {
  ------------------
  |  Branch (100:9): [True: 2, False: 2]
  ------------------
  101|      2|        ssh_mutex_unlock(&ssh_init_mutex);
  102|      2|    }
  103|       |
  104|      4|    return rc;
  105|      2|}
init.c:_ssh_finalize:
  160|      2|static int _ssh_finalize(unsigned destructor) {
  161|       |
  162|      2|    if (!destructor) {
  ------------------
  |  Branch (162:9): [True: 2, False: 0]
  ------------------
  163|      2|        ssh_mutex_lock(&ssh_init_mutex);
  164|       |
  165|      2|        if (_ssh_initialized > 1) {
  ------------------
  |  Branch (165:13): [True: 2, False: 0]
  ------------------
  166|      2|            _ssh_initialized--;
  167|      2|            ssh_mutex_unlock(&ssh_init_mutex);
  168|      2|            return 0;
  169|      2|        }
  170|       |
  171|      0|        if (_ssh_initialized == 1) {
  ------------------
  |  Branch (171:13): [True: 0, False: 0]
  ------------------
  172|      0|            if (_ssh_init_ret < 0) {
  ------------------
  |  Branch (172:17): [True: 0, False: 0]
  ------------------
  173|      0|                ssh_mutex_unlock(&ssh_init_mutex);
  174|      0|                return 0;
  175|      0|            }
  176|      0|        }
  177|      0|    }
  178|       |
  179|       |    /* If the counter reaches zero or it is the destructor calling, finalize */
  180|      0|    ssh_dh_finalize();
  181|      0|    ssh_crypto_finalize();
  182|      0|    ssh_socket_cleanup();
  183|       |    /* It is important to finalize threading after CRYPTO because
  184|       |     * it still depends on it */
  185|      0|    ssh_threads_finalize();
  186|       |
  187|      0|    _ssh_initialized = 0;
  188|       |
  189|      0|    if (!destructor) {
  ------------------
  |  Branch (189:9): [True: 0, False: 0]
  ------------------
  190|      0|        ssh_mutex_unlock(&ssh_init_mutex);
  191|      0|    }
  192|       |
  193|       |#if (defined(_WIN32) && !defined(HAVE_PTHREAD))
  194|       |    if (ssh_init_mutex != NULL) {
  195|       |        DeleteCriticalSection(ssh_init_mutex);
  196|       |        SAFE_FREE(ssh_init_mutex);
  197|       |    }
  198|       |#endif
  199|       |
  200|      0|    return 0;
  201|      2|}

sshkdf_derive_key:
  158|  7.88k|{
  159|       |    /* Can't use VLAs with Visual Studio, so allocate the biggest
  160|       |     * digest buffer we can possibly need */
  161|  7.88k|    unsigned char digest[DIGEST_MAX_LEN];
  162|  7.88k|    size_t output_len = crypto->digest_len;
  163|  7.88k|    ssh_mac_ctx ctx;
  164|  7.88k|    int rc;
  165|       |
  166|  7.88k|    if (DIGEST_MAX_LEN < crypto->digest_len) {
  ------------------
  |  |   56|  7.88k|#define DIGEST_MAX_LEN 64
  ------------------
  |  Branch (166:9): [True: 0, False: 7.88k]
  ------------------
  167|      0|        return -1;
  168|      0|    }
  169|       |
  170|  7.88k|    ctx = ssh_mac_ctx_init(crypto->digest_type);
  171|  7.88k|    if (ctx == NULL) {
  ------------------
  |  Branch (171:9): [True: 0, False: 7.88k]
  ------------------
  172|      0|        return -1;
  173|      0|    }
  174|       |
  175|  7.88k|    rc = ssh_mac_update(ctx, key, key_len);
  176|  7.88k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  7.88k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (176:9): [True: 0, False: 7.88k]
  ------------------
  177|      0|        ssh_mac_ctx_free(ctx);
  178|      0|        return -1;
  179|      0|    }
  180|  7.88k|    rc = ssh_mac_update(ctx, crypto->secret_hash, crypto->digest_len);
  181|  7.88k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  7.88k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (181:9): [True: 0, False: 7.88k]
  ------------------
  182|      0|        ssh_mac_ctx_free(ctx);
  183|      0|        return -1;
  184|      0|    }
  185|  7.88k|    rc = ssh_mac_update(ctx, &key_type, 1);
  186|  7.88k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  7.88k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (186:9): [True: 0, False: 7.88k]
  ------------------
  187|      0|        ssh_mac_ctx_free(ctx);
  188|      0|        return -1;
  189|      0|    }
  190|  7.88k|    rc = ssh_mac_update(ctx, crypto->session_id, crypto->session_id_len);
  191|  7.88k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  7.88k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (191:9): [True: 0, False: 7.88k]
  ------------------
  192|      0|        ssh_mac_ctx_free(ctx);
  193|      0|        return -1;
  194|      0|    }
  195|  7.88k|    rc = ssh_mac_final(digest, ctx);
  196|  7.88k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  7.88k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (196:9): [True: 0, False: 7.88k]
  ------------------
  197|      0|        return -1;
  198|      0|    }
  199|       |
  200|  7.88k|    if (requested_len < output_len) {
  ------------------
  |  Branch (200:9): [True: 4.48k, False: 3.40k]
  ------------------
  201|  4.48k|        output_len = requested_len;
  202|  4.48k|    }
  203|  7.88k|    memcpy(output, digest, output_len);
  204|       |
  205|  7.88k|    while (requested_len > output_len) {
  ------------------
  |  Branch (205:12): [True: 0, False: 7.88k]
  ------------------
  206|      0|        ctx = ssh_mac_ctx_init(crypto->digest_type);
  207|      0|        if (ctx == NULL) {
  ------------------
  |  Branch (207:13): [True: 0, False: 0]
  ------------------
  208|      0|            return -1;
  209|      0|        }
  210|      0|        rc = ssh_mac_update(ctx, key, key_len);
  211|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (211:13): [True: 0, False: 0]
  ------------------
  212|      0|            ssh_mac_ctx_free(ctx);
  213|      0|            return -1;
  214|      0|        }
  215|      0|        rc = ssh_mac_update(ctx, crypto->secret_hash, crypto->digest_len);
  216|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (216:13): [True: 0, False: 0]
  ------------------
  217|      0|            ssh_mac_ctx_free(ctx);
  218|      0|            return -1;
  219|      0|        }
  220|      0|        rc = ssh_mac_update(ctx, output, output_len);
  221|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (221:13): [True: 0, False: 0]
  ------------------
  222|      0|            ssh_mac_ctx_free(ctx);
  223|      0|            return -1;
  224|      0|        }
  225|      0|        rc = ssh_mac_final(digest, ctx);
  226|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (226:13): [True: 0, False: 0]
  ------------------
  227|      0|            return -1;
  228|      0|        }
  229|      0|        if (requested_len < output_len + crypto->digest_len) {
  ------------------
  |  Branch (229:13): [True: 0, False: 0]
  ------------------
  230|      0|            memcpy(output + output_len, digest, requested_len - output_len);
  231|      0|        } else {
  232|      0|            memcpy(output + output_len, digest, crypto->digest_len);
  233|      0|        }
  234|      0|        output_len += crypto->digest_len;
  235|      0|    }
  236|       |
  237|  7.88k|    return 0;
  238|  7.88k|}
kdf.c:ssh_mac_ctx_init:
   54|  7.88k|{
   55|  7.88k|    ssh_mac_ctx ctx = malloc(sizeof(struct ssh_mac_ctx_struct));
   56|  7.88k|    if (ctx == NULL) {
  ------------------
  |  Branch (56:9): [True: 0, False: 7.88k]
  ------------------
   57|      0|        return NULL;
   58|      0|    }
   59|       |
   60|  7.88k|    ctx->digest_type = type;
   61|  7.88k|    switch (type) {
  ------------------
  |  Branch (61:13): [True: 7.88k, False: 0]
  ------------------
   62|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (62:5): [True: 0, False: 7.88k]
  ------------------
   63|      0|        ctx->ctx.sha1_ctx = sha1_init();
   64|      0|        if (ctx->ctx.sha1_ctx == NULL) {
  ------------------
  |  Branch (64:13): [True: 0, False: 0]
  ------------------
   65|      0|            goto err;
   66|      0|        }
   67|      0|        return ctx;
   68|  7.88k|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (68:5): [True: 7.88k, False: 0]
  ------------------
   69|  7.88k|        ctx->ctx.sha256_ctx = sha256_init();
   70|  7.88k|        if (ctx->ctx.sha256_ctx == NULL) {
  ------------------
  |  Branch (70:13): [True: 0, False: 7.88k]
  ------------------
   71|      0|            goto err;
   72|      0|        }
   73|  7.88k|        return ctx;
   74|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (74:5): [True: 0, False: 7.88k]
  ------------------
   75|      0|        ctx->ctx.sha384_ctx = sha384_init();
   76|      0|        if (ctx->ctx.sha384_ctx == NULL) {
  ------------------
  |  Branch (76:13): [True: 0, False: 0]
  ------------------
   77|      0|            goto err;
   78|      0|        }
   79|      0|        return ctx;
   80|      0|    case SSH_KDF_SHA512:
  ------------------
  |  Branch (80:5): [True: 0, False: 7.88k]
  ------------------
   81|      0|        ctx->ctx.sha512_ctx = sha512_init();
   82|      0|        if (ctx->ctx.sha512_ctx == NULL) {
  ------------------
  |  Branch (82:13): [True: 0, False: 0]
  ------------------
   83|      0|            goto err;
   84|      0|        }
   85|      0|        return ctx;
   86|  7.88k|    }
   87|      0|err:
   88|      0|    SAFE_FREE(ctx);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
   89|       |    return NULL;
   90|  7.88k|}
kdf.c:ssh_mac_update:
  116|  31.5k|{
  117|  31.5k|    switch (ctx->digest_type) {
  ------------------
  |  Branch (117:13): [True: 31.5k, False: 0]
  ------------------
  118|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (118:5): [True: 0, False: 31.5k]
  ------------------
  119|      0|        return sha1_update(ctx->ctx.sha1_ctx, data, len);
  120|  31.5k|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (120:5): [True: 31.5k, False: 0]
  ------------------
  121|  31.5k|        return sha256_update(ctx->ctx.sha256_ctx, data, len);
  122|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (122:5): [True: 0, False: 31.5k]
  ------------------
  123|      0|        return sha384_update(ctx->ctx.sha384_ctx, data, len);
  124|      0|    case SSH_KDF_SHA512:
  ------------------
  |  Branch (124:5): [True: 0, False: 31.5k]
  ------------------
  125|      0|        return sha512_update(ctx->ctx.sha512_ctx, data, len);
  126|  31.5k|    }
  127|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  128|  31.5k|}
kdf.c:ssh_mac_final:
  131|  7.88k|{
  132|  7.88k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  7.88k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  133|       |
  134|  7.88k|    switch (ctx->digest_type) {
  ------------------
  |  Branch (134:13): [True: 7.88k, False: 0]
  ------------------
  135|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (135:5): [True: 0, False: 7.88k]
  ------------------
  136|      0|        rc = sha1_final(md, ctx->ctx.sha1_ctx);
  137|      0|        break;
  138|  7.88k|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (138:5): [True: 7.88k, False: 0]
  ------------------
  139|  7.88k|        rc = sha256_final(md, ctx->ctx.sha256_ctx);
  140|  7.88k|        break;
  141|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (141:5): [True: 0, False: 7.88k]
  ------------------
  142|      0|        rc = sha384_final(md, ctx->ctx.sha384_ctx);
  143|      0|        break;
  144|      0|    case SSH_KDF_SHA512:
  ------------------
  |  Branch (144:5): [True: 0, False: 7.88k]
  ------------------
  145|      0|        rc = sha512_final(md, ctx->ctx.sha512_ctx);
  146|      0|        break;
  147|  7.88k|    }
  148|  7.88k|    SAFE_FREE(ctx);
  ------------------
  |  |  373|  7.88k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 7.88k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 7.88k]
  |  |  ------------------
  ------------------
  149|  7.88k|    return rc;
  150|  7.88k|}

ssh_kex_get_default_methods:
  300|  5.25k|{
  301|  5.25k|    if (type >= SSH_KEX_METHODS) {
  ------------------
  |  |   27|  5.25k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (301:9): [True: 0, False: 5.25k]
  ------------------
  302|      0|        return NULL;
  303|      0|    }
  304|       |
  305|  5.25k|    return default_methods[type];
  306|  5.25k|}
ssh_packet_kexinit:
  397|  1.30k|{
  398|  1.30k|    int i, ok;
  399|  1.30k|    struct ssh_crypto_struct *crypto = session->next_crypto;
  400|  1.30k|    int server_kex = session->server;
  401|  1.30k|    ssh_string str = NULL;
  402|  1.30k|    char *strings[SSH_KEX_METHODS] = {0};
  403|  1.30k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  1.30k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  404|  1.30k|    size_t len;
  405|       |
  406|  1.30k|    uint8_t first_kex_packet_follows = 0;
  407|  1.30k|    uint32_t kexinit_reserved = 0;
  408|       |
  409|  1.30k|    (void)type;
  410|  1.30k|    (void)user;
  411|       |
  412|  1.30k|    SSH_LOG(SSH_LOG_TRACE, "KEXINIT received");
  ------------------
  |  |  281|  1.30k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  413|       |
  414|  1.30k|    if (session->session_state == SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (414:9): [True: 0, False: 1.30k]
  ------------------
  415|      0|        if (session->dh_handshake_state == DH_STATE_FINISHED) {
  ------------------
  |  Branch (415:13): [True: 0, False: 0]
  ------------------
  416|      0|            SSH_LOG(SSH_LOG_DEBUG, "Peer initiated key re-exchange");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  417|       |            /* Reset the sent flag if the re-kex was initiated by the peer */
  418|      0|            session->flags &= ~SSH_SESSION_FLAG_KEXINIT_SENT;
  ------------------
  |  |   86|      0|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
  419|      0|        } else if (session->flags & SSH_SESSION_FLAG_KEXINIT_SENT &&
  ------------------
  |  |   86|      0|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
  |  Branch (419:20): [True: 0, False: 0]
  ------------------
  420|      0|                   session->dh_handshake_state == DH_STATE_INIT_SENT) {
  ------------------
  |  Branch (420:20): [True: 0, False: 0]
  ------------------
  421|       |            /* This happens only when we are sending our-guessed first kex
  422|       |             * packet right after our KEXINIT packet. */
  423|      0|            SSH_LOG(SSH_LOG_DEBUG, "Received peer kexinit answer.");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  424|      0|        } else if (session->session_state != SSH_SESSION_STATE_INITIAL_KEX) {
  ------------------
  |  Branch (424:20): [True: 0, False: 0]
  ------------------
  425|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  426|      0|                          "SSH_KEXINIT received in wrong state");
  427|      0|            goto error;
  428|      0|        }
  429|  1.30k|    } else if (session->session_state != SSH_SESSION_STATE_INITIAL_KEX) {
  ------------------
  |  Branch (429:16): [True: 0, False: 1.30k]
  ------------------
  430|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  431|      0|                      "SSH_KEXINIT received in wrong state");
  432|      0|        goto error;
  433|      0|    }
  434|       |
  435|  1.30k|    if (server_kex) {
  ------------------
  |  Branch (435:9): [True: 657, False: 646]
  ------------------
  436|    657|#ifdef WITH_SERVER
  437|    657|        len = ssh_buffer_get_data(packet, crypto->client_kex.cookie, 16);
  438|    657|        if (len != 16) {
  ------------------
  |  Branch (438:13): [True: 0, False: 657]
  ------------------
  439|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  440|      0|                          "ssh_packet_kexinit: no cookie in packet");
  441|      0|            goto error;
  442|      0|        }
  443|       |
  444|    657|        ok = ssh_hashbufin_add_cookie(session, crypto->client_kex.cookie);
  445|    657|        if (ok < 0) {
  ------------------
  |  Branch (445:13): [True: 0, False: 657]
  ------------------
  446|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  447|      0|                          "ssh_packet_kexinit: adding cookie failed");
  448|      0|            goto error;
  449|      0|        }
  450|       |
  451|    657|        ok = server_set_kex(session);
  452|    657|        if (ok == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (452:13): [True: 0, False: 657]
  ------------------
  453|      0|            goto error;
  454|      0|        }
  455|    657|#endif /* WITH_SERVER */
  456|    657|    } else {
  457|    646|        len = ssh_buffer_get_data(packet, crypto->server_kex.cookie, 16);
  458|    646|        if (len != 16) {
  ------------------
  |  Branch (458:13): [True: 0, False: 646]
  ------------------
  459|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  460|      0|                          "ssh_packet_kexinit: no cookie in packet");
  461|      0|            goto error;
  462|      0|        }
  463|       |
  464|    646|        ok = ssh_hashbufin_add_cookie(session, crypto->server_kex.cookie);
  465|    646|        if (ok < 0) {
  ------------------
  |  Branch (465:13): [True: 0, False: 646]
  ------------------
  466|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  467|      0|                          "ssh_packet_kexinit: adding cookie failed");
  468|      0|            goto error;
  469|      0|        }
  470|       |
  471|    646|        ok = ssh_set_client_kex(session);
  472|    646|        if (ok == SSH_ERROR) {
  ------------------
  |  |  317|    646|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (472:13): [True: 0, False: 646]
  ------------------
  473|      0|            goto error;
  474|      0|        }
  475|    646|    }
  476|       |
  477|  13.8k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  13.8k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (477:17): [True: 12.5k, False: 1.30k]
  ------------------
  478|  12.5k|        str = ssh_buffer_get_ssh_string(packet);
  479|  12.5k|        if (str == NULL) {
  ------------------
  |  Branch (479:13): [True: 0, False: 12.5k]
  ------------------
  480|      0|          goto error;
  481|      0|        }
  482|       |
  483|  12.5k|        rc = ssh_buffer_add_ssh_string(session->in_hashbuf, str);
  484|  12.5k|        if (rc < 0) {
  ------------------
  |  Branch (484:13): [True: 0, False: 12.5k]
  ------------------
  485|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  486|      0|                          "Error adding string in hash buffer");
  487|      0|            goto error;
  488|      0|        }
  489|       |
  490|  12.5k|        strings[i] = ssh_string_to_char(str);
  491|  12.5k|        if (strings[i] == NULL) {
  ------------------
  |  Branch (491:13): [True: 0, False: 12.5k]
  ------------------
  492|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  493|      0|            goto error;
  494|      0|        }
  495|  12.5k|        SSH_STRING_FREE(str);
  ------------------
  |  |  910|  12.5k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 12.5k, False: 18.4E]
  |  |  |  Branch (910:69): [Folded, False: 12.5k]
  |  |  ------------------
  ------------------
  496|  12.5k|        str = NULL;
  497|  12.5k|    }
  498|       |
  499|       |    /* copy the peer kex info into an array of strings */
  500|  1.30k|    if (server_kex) {
  ------------------
  |  Branch (500:9): [True: 657, False: 646]
  ------------------
  501|    657|#ifdef WITH_SERVER
  502|  7.22k|        for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  7.22k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (502:21): [True: 6.57k, False: 657]
  ------------------
  503|  6.57k|            crypto->client_kex.methods[i] = strings[i];
  504|  6.57k|        }
  505|    657|#endif /* WITH_SERVER */
  506|    657|    } else { /* client */
  507|  7.21k|        for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  7.21k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (507:21): [True: 6.57k, False: 646]
  ------------------
  508|  6.57k|            crypto->server_kex.methods[i] = strings[i];
  509|  6.57k|        }
  510|    646|    }
  511|       |
  512|       |    /*
  513|       |     * Handle the two final fields for the KEXINIT message (RFC 4253 7.1):
  514|       |     *
  515|       |     *      boolean      first_kex_packet_follows
  516|       |     *      uint32       0 (reserved for future extension)
  517|       |     *
  518|       |     * Notably if clients set 'first_kex_packet_follows', it is expected
  519|       |     * that its value is included when computing the session ID (see
  520|       |     * 'make_sessionid').
  521|       |     */
  522|       |
  523|  1.30k|    rc = ssh_buffer_get_u8(packet, &first_kex_packet_follows);
  524|  1.30k|    if (rc != 1) {
  ------------------
  |  Branch (524:9): [True: 0, False: 1.30k]
  ------------------
  525|      0|        goto error;
  526|      0|    }
  527|       |
  528|  1.30k|    rc = ssh_buffer_add_u8(session->in_hashbuf, first_kex_packet_follows);
  529|  1.30k|    if (rc < 0) {
  ------------------
  |  Branch (529:9): [True: 0, False: 1.30k]
  ------------------
  530|      0|        goto error;
  531|      0|    }
  532|       |
  533|  1.30k|    rc = ssh_buffer_add_u32(session->in_hashbuf, kexinit_reserved);
  534|  1.30k|    if (rc < 0) {
  ------------------
  |  Branch (534:9): [True: 0, False: 1.30k]
  ------------------
  535|      0|        goto error;
  536|      0|    }
  537|       |
  538|       |    /*
  539|       |     * Remember whether 'first_kex_packet_follows' was set and the client
  540|       |     * guess was wrong: in this case the next SSH_MSG_KEXDH_INIT message
  541|       |     * must be ignored on the server side.
  542|       |     * Client needs to start the Key exchange over with the correct method
  543|       |     */
  544|  1.30k|    if (first_kex_packet_follows || session->send_first_kex_follows) {
  ------------------
  |  Branch (544:9): [True: 18.4E, False: 1.30k]
  |  Branch (544:37): [True: 0, False: 1.30k]
  ------------------
  545|      0|        char **client_methods = crypto->client_kex.methods;
  546|      0|        char **server_methods = crypto->server_kex.methods;
  547|      0|        session->first_kex_follows_guess_wrong =
  548|      0|            cmp_first_kex_algo(client_methods[SSH_KEX],
  ------------------
  |  Branch (548:13): [True: 0, False: 0]
  ------------------
  549|      0|                               server_methods[SSH_KEX]) ||
  550|      0|            cmp_first_kex_algo(client_methods[SSH_HOSTKEYS],
  ------------------
  |  Branch (550:13): [True: 0, False: 0]
  ------------------
  551|      0|                               server_methods[SSH_HOSTKEYS]);
  552|      0|            SSH_LOG(SSH_LOG_DEBUG, "The initial guess was %s.",
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  553|      0|                    session->first_kex_follows_guess_wrong ? "wrong" : "right");
  554|      0|    }
  555|       |
  556|       |    /*
  557|       |     * handle the "strict KEX" feature. If supported by peer, then set up the
  558|       |     * flag and verify packet sequence numbers.
  559|       |     */
  560|  1.30k|    if (server_kex) {
  ------------------
  |  Branch (560:9): [True: 657, False: 646]
  ------------------
  561|    657|        ok = match_group(crypto->client_kex.methods[SSH_KEX],
  562|    657|                         KEX_STRICT_CLIENT);
  ------------------
  |  |  196|    657|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  563|    657|        if (ok) {
  ------------------
  |  Branch (563:13): [True: 657, False: 0]
  ------------------
  564|    657|            SSH_LOG(SSH_LOG_DEBUG, "Client supports strict kex, enabling.");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  565|    657|            session->flags |= SSH_SESSION_FLAG_KEX_STRICT;
  ------------------
  |  |   90|    657|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  566|    657|        }
  567|    657|    } else {
  568|       |        /* client kex */
  569|    646|        ok = match_group(crypto->server_kex.methods[SSH_KEX],
  570|    646|                         KEX_STRICT_SERVER);
  ------------------
  |  |  197|    646|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  571|    657|        if (ok) {
  ------------------
  |  Branch (571:13): [True: 657, False: 18.4E]
  ------------------
  572|    657|            SSH_LOG(SSH_LOG_DEBUG, "Server supports strict kex, enabling.");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  573|    657|            session->flags |= SSH_SESSION_FLAG_KEX_STRICT;
  ------------------
  |  |   90|    657|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  574|    657|        }
  575|    646|    }
  576|  1.30k|#ifdef WITH_SERVER
  577|  1.30k|    if (server_kex) {
  ------------------
  |  Branch (577:9): [True: 657, False: 646]
  ------------------
  578|       |        /*
  579|       |         * If client sent a ext-info-c message in the kex list, it supports
  580|       |         * RFC 8308 extension negotiation.
  581|       |         */
  582|    657|        ok = match_group(crypto->client_kex.methods[SSH_KEX],
  583|    657|                         KEX_EXTENSION_CLIENT);
  ------------------
  |  |  194|    657|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  584|    657|        if (ok) {
  ------------------
  |  Branch (584:13): [True: 657, False: 0]
  ------------------
  585|    657|            const char *hostkeys = NULL, *wanted_hostkeys = NULL;
  586|       |
  587|       |            /* The client supports extension negotiation */
  588|    657|            session->extensions |= SSH_EXT_NEGOTIATION;
  ------------------
  |  |  123|    657|#define SSH_EXT_NEGOTIATION     0x01
  ------------------
  589|       |            /*
  590|       |             * RFC 8332 Section 3.1: Use for Server Authentication
  591|       |             * Check what algorithms were provided in the SSH_HOSTKEYS list
  592|       |             * by the client and enable the respective extensions to provide
  593|       |             * correct signature in the next packet if RSA is negotiated
  594|       |             */
  595|    657|            hostkeys = crypto->client_kex.methods[SSH_HOSTKEYS];
  596|    657|            wanted_hostkeys = session->opts.wanted_methods[SSH_HOSTKEYS];
  597|    657|            ok = match_group(hostkeys, "rsa-sha2-512");
  598|    657|            if (ok) {
  ------------------
  |  Branch (598:17): [True: 657, False: 0]
  ------------------
  599|       |                /* Check if rsa-sha2-512 is allowed by config */
  600|    657|                if (wanted_hostkeys != NULL) {
  ------------------
  |  Branch (600:21): [True: 657, False: 0]
  ------------------
  601|    657|                    char *is_allowed = ssh_find_matching(wanted_hostkeys,
  602|    657|                                                         "rsa-sha2-512");
  603|    657|                    if (is_allowed != NULL) {
  ------------------
  |  Branch (603:25): [True: 0, False: 657]
  ------------------
  604|      0|                        session->extensions |= SSH_EXT_SIG_RSA_SHA512;
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  605|      0|                    }
  606|    657|                    SAFE_FREE(is_allowed);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  607|    657|                }
  608|    657|            }
  609|    657|            ok = match_group(hostkeys, "rsa-sha2-256");
  610|    657|            if (ok) {
  ------------------
  |  Branch (610:17): [True: 657, False: 0]
  ------------------
  611|       |                /* Check if rsa-sha2-256 is allowed by config */
  612|    657|                if (wanted_hostkeys != NULL) {
  ------------------
  |  Branch (612:21): [True: 657, False: 0]
  ------------------
  613|    657|                    char *is_allowed = ssh_find_matching(wanted_hostkeys,
  614|    657|                                                         "rsa-sha2-256");
  615|    657|                    if (is_allowed != NULL) {
  ------------------
  |  Branch (615:25): [True: 0, False: 657]
  ------------------
  616|      0|                        session->extensions |= SSH_EXT_SIG_RSA_SHA256;
  ------------------
  |  |  125|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  617|      0|                    }
  618|    657|                    SAFE_FREE(is_allowed);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  619|    657|                }
  620|    657|            }
  621|       |
  622|       |            /*
  623|       |             * Ensure that the client preference is honored for the case
  624|       |             * both signature types are enabled.
  625|       |             */
  626|    657|            if ((session->extensions & SSH_EXT_SIG_RSA_SHA256) &&
  ------------------
  |  |  125|    657|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  |  Branch (626:17): [True: 0, False: 657]
  ------------------
  627|      0|                (session->extensions & SSH_EXT_SIG_RSA_SHA512)) {
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  |  Branch (627:17): [True: 0, False: 0]
  ------------------
  628|      0|                char *rsa_sig_ext = NULL;
  629|      0|                session->extensions &= ~(SSH_EXT_SIG_RSA_SHA256 | SSH_EXT_SIG_RSA_SHA512);
  ------------------
  |  |  125|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
                              session->extensions &= ~(SSH_EXT_SIG_RSA_SHA256 | SSH_EXT_SIG_RSA_SHA512);
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  630|      0|                rsa_sig_ext = ssh_find_matching("rsa-sha2-512,rsa-sha2-256",
  631|      0|                                                hostkeys);
  632|      0|                if (rsa_sig_ext == NULL) {
  ------------------
  |  Branch (632:21): [True: 0, False: 0]
  ------------------
  633|      0|                    goto error; /* should never happen */
  634|      0|                } else if (strcmp(rsa_sig_ext, "rsa-sha2-512") == 0) {
  ------------------
  |  Branch (634:28): [True: 0, False: 0]
  ------------------
  635|      0|                    session->extensions |= SSH_EXT_SIG_RSA_SHA512;
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  636|      0|                } else if (strcmp(rsa_sig_ext, "rsa-sha2-256") == 0) {
  ------------------
  |  Branch (636:28): [True: 0, False: 0]
  ------------------
  637|      0|                    session->extensions |= SSH_EXT_SIG_RSA_SHA256;
  ------------------
  |  |  125|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  638|      0|                } else {
  639|      0|                    SAFE_FREE(rsa_sig_ext);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  640|      0|                    goto error; /* should never happen */
  641|      0|                }
  642|      0|                SAFE_FREE(rsa_sig_ext);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  643|      0|            }
  644|       |
  645|    657|            SSH_LOG(SSH_LOG_DEBUG, "The client supports extension "
  ------------------
  |  |  281|  2.62k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 657]
  |  |  |  Branch (281:34): [True: 0, False: 657]
  |  |  ------------------
  ------------------
  646|    657|                    "negotiation. Enabled signature algorithms: %s%s",
  647|    657|                    session->extensions & SSH_EXT_SIG_RSA_SHA256 ? "SHA256" : "",
  648|    657|                    session->extensions & SSH_EXT_SIG_RSA_SHA512 ? " SHA512" : "");
  649|    657|        }
  650|    657|    }
  651|  1.30k|#endif /* WITH_SERVER */
  652|       |
  653|       |    /* Note, that his overwrites authenticated state in case of rekeying */
  654|  1.30k|    session->session_state = SSH_SESSION_STATE_KEXINIT_RECEIVED;
  655|       |    /* if we already sent our initial key exchange packet, do not reset the
  656|       |     * DH state. We will know if we were right with our guess only in
  657|       |     * dh_handshake_state() */
  658|  1.31k|    if (session->send_first_kex_follows == false) {
  ------------------
  |  Branch (658:9): [True: 1.31k, False: 18.4E]
  ------------------
  659|  1.31k|        session->dh_handshake_state = DH_STATE_INIT;
  660|  1.31k|    }
  661|  1.30k|    session->ssh_connection_callback(session);
  662|  1.30k|    return SSH_PACKET_USED;
  ------------------
  |  |  637|  1.30k|#define SSH_PACKET_USED 1
  ------------------
  663|       |
  664|      0|error:
  665|      0|    SSH_STRING_FREE(str);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  666|      0|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|      0|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (666:17): [True: 0, False: 0]
  ------------------
  667|      0|        if (server_kex) {
  ------------------
  |  Branch (667:13): [True: 0, False: 0]
  ------------------
  668|      0|#ifdef WITH_SERVER
  669|      0|            session->next_crypto->client_kex.methods[i] = NULL;
  670|      0|#endif /* WITH_SERVER */
  671|      0|        } else { /* client */
  672|      0|            session->next_crypto->server_kex.methods[i] = NULL;
  673|      0|        }
  674|      0|        SAFE_FREE(strings[i]);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  675|      0|    }
  676|       |
  677|      0|    session->session_state = SSH_SESSION_STATE_ERROR;
  678|       |
  679|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  680|  1.30k|}
ssh_list_kex:
  682|  2.62k|void ssh_list_kex(struct ssh_kex_struct *kex) {
  683|  2.62k|  int i = 0;
  684|       |
  685|       |#ifdef DEBUG_CRYPTO
  686|       |  ssh_log_hexdump("session cookie", kex->cookie, 16);
  687|       |#endif
  688|       |
  689|  28.8k|  for(i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  28.8k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (689:14): [True: 26.1k, False: 2.62k]
  ------------------
  690|  26.1k|    if (kex->methods[i] == NULL) {
  ------------------
  |  Branch (690:9): [True: 0, False: 26.1k]
  ------------------
  691|      0|      continue;
  692|      0|    }
  693|  26.1k|    SSH_LOG(SSH_LOG_FUNCTIONS, "%s: %s",
  ------------------
  |  |  281|  26.1k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  694|  26.1k|        ssh_kex_descriptions[i], kex->methods[i]);
  695|  26.1k|  }
  696|  2.62k|}
ssh_client_select_hostkeys:
  708|    657|{
  709|    657|    const char *wanted = NULL;
  710|    657|    char *wanted_without_certs = NULL;
  711|    657|    char *known_hosts_algorithms = NULL;
  712|    657|    char *known_hosts_ordered = NULL;
  713|    657|    char *new_hostkeys = NULL;
  714|    657|    char *fips_hostkeys = NULL;
  715|       |
  716|    657|    wanted = session->opts.wanted_methods[SSH_HOSTKEYS];
  717|    657|    if (wanted == NULL) {
  ------------------
  |  Branch (717:9): [True: 657, False: 0]
  ------------------
  718|    657|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|    657|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 657]
  |  |  ------------------
  ------------------
  719|      0|            wanted = ssh_kex_get_fips_methods(SSH_HOSTKEYS);
  720|    657|        } else {
  721|    657|            wanted = ssh_kex_get_default_methods(SSH_HOSTKEYS);
  722|    657|        }
  723|    657|    }
  724|       |
  725|       |    /* This removes the certificate types, unsupported for now */
  726|    657|    wanted_without_certs = ssh_find_all_matching(HOSTKEYS, wanted);
  ------------------
  |  |  142|    657|#define HOSTKEYS "ssh-ed25519," \
  |  |  143|    657|                 EC_HOSTKEYS \
  |  |  144|    657|                 "sk-ssh-ed25519@openssh.com," \
  |  |  145|    657|                 EC_SK_HOSTKEYS \
  |  |  146|    657|                 "rsa-sha2-512," \
  |  |  147|    657|                 "rsa-sha2-256," \
  |  |  148|    657|                 "ssh-rsa"
  ------------------
  727|    657|    if (wanted_without_certs == NULL) {
  ------------------
  |  Branch (727:9): [True: 0, False: 657]
  ------------------
  728|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  729|      0|                "List of allowed host key algorithms is empty or contains only "
  730|      0|                "unsupported algorithms");
  731|      0|        return NULL;
  732|      0|    }
  733|       |
  734|    657|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  735|    657|            "Order of wanted host keys: \"%s\"",
  736|    657|            wanted_without_certs);
  737|       |
  738|    657|    known_hosts_algorithms = ssh_known_hosts_get_algorithms_names(session);
  739|    657|    if (known_hosts_algorithms == NULL) {
  ------------------
  |  Branch (739:9): [True: 657, False: 0]
  ------------------
  740|    657|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  741|    657|                "No key found in known_hosts; "
  742|    657|                "changing host key method to \"%s\"",
  743|    657|                wanted_without_certs);
  744|       |
  745|    657|        return wanted_without_certs;
  746|    657|    }
  747|       |
  748|      0|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  749|      0|            "Algorithms found in known_hosts files: \"%s\"",
  750|      0|            known_hosts_algorithms);
  751|       |
  752|       |    /* Filter and order the keys from known_hosts according to wanted list */
  753|      0|    known_hosts_ordered = ssh_find_all_matching(known_hosts_algorithms,
  754|      0|                                                wanted_without_certs);
  755|      0|    SAFE_FREE(known_hosts_algorithms);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  756|      0|    if (known_hosts_ordered == NULL) {
  ------------------
  |  Branch (756:9): [True: 0, False: 0]
  ------------------
  757|      0|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  758|      0|                "No key found in known_hosts is allowed; "
  759|      0|                "changing host key method to \"%s\"",
  760|      0|                wanted_without_certs);
  761|       |
  762|      0|        return wanted_without_certs;
  763|      0|    }
  764|       |
  765|       |    /* Append the other supported keys after the preferred ones
  766|       |     * This function tolerates NULL pointers in parameters */
  767|      0|    new_hostkeys = ssh_append_without_duplicates(known_hosts_ordered,
  768|      0|                                                 wanted_without_certs);
  769|      0|    SAFE_FREE(known_hosts_ordered);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  770|      0|    SAFE_FREE(wanted_without_certs);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  771|      0|    if (new_hostkeys == NULL) {
  ------------------
  |  Branch (771:9): [True: 0, False: 0]
  ------------------
  772|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  773|      0|        return NULL;
  774|      0|    }
  775|       |
  776|      0|    if (ssh_fips_mode()) {
  ------------------
  |  |  115|      0|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  777|       |        /* Filter out algorithms not allowed in FIPS mode */
  778|      0|        fips_hostkeys = ssh_keep_fips_algos(SSH_HOSTKEYS, new_hostkeys);
  779|      0|        SAFE_FREE(new_hostkeys);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  780|      0|        if (fips_hostkeys == NULL) {
  ------------------
  |  Branch (780:13): [True: 0, False: 0]
  ------------------
  781|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  782|      0|                    "None of the wanted host keys or keys in known_hosts files "
  783|      0|                    "is allowed in FIPS mode.");
  784|      0|            return NULL;
  785|      0|        }
  786|      0|        new_hostkeys = fips_hostkeys;
  787|      0|    }
  788|       |
  789|      0|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  790|      0|            "Changing host key method to \"%s\"",
  791|      0|            new_hostkeys);
  792|       |
  793|      0|    return new_hostkeys;
  794|      0|}
ssh_set_client_kex:
  801|  1.31k|{
  802|  1.31k|    struct ssh_kex_struct *client = &session->next_crypto->client_kex;
  803|  1.31k|    const char *wanted = NULL;
  804|  1.31k|    int ok;
  805|  1.31k|    int i;
  806|  1.31k|    bool gssapi_null_alg = false;
  807|  1.31k|    char *hostkeys = NULL;
  808|       |
  809|       |    /* Skip if already set, for example for the rekey or when we do the guessing
  810|       |     * it could have been already used to make some protocol decisions. */
  811|  1.31k|    if (client->methods[0] != NULL) {
  ------------------
  |  Branch (811:9): [True: 657, False: 657]
  ------------------
  812|    657|        return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  813|    657|    }
  814|       |
  815|    657|    ok = ssh_get_random(client->cookie, 16, 0);
  816|    657|    if (!ok) {
  ------------------
  |  Branch (816:9): [True: 0, False: 657]
  ------------------
  817|      0|        ssh_set_error(session, SSH_FATAL, "PRNG error");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  818|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  819|      0|    }
  820|       |#ifdef WITH_GSSAPI
  821|       |    if (session->opts.gssapi_key_exchange) {
  822|       |        char *gssapi_algs = NULL;
  823|       |
  824|       |        ok = ssh_gssapi_init(session);
  825|       |        if (ok != SSH_OK) {
  826|       |            ssh_set_error_oom(session);
  827|       |            return SSH_ERROR;
  828|       |        }
  829|       |
  830|       |        ok = ssh_gssapi_import_name(session->gssapi, session->opts.host);
  831|       |        if (ok != SSH_OK) {
  832|       |            return SSH_ERROR;
  833|       |        }
  834|       |
  835|       |        gssapi_algs = ssh_gssapi_kex_mechs(session);
  836|       |        if (gssapi_algs == NULL) {
  837|       |            return SSH_ERROR;
  838|       |        }
  839|       |
  840|       |        /* Prefix the default algorithms with gsskex algs */
  841|       |        if (ssh_fips_mode()) {
  842|       |            session->opts.wanted_methods[SSH_KEX] =
  843|       |                ssh_prefix_without_duplicates(fips_methods[SSH_KEX],
  844|       |                                              gssapi_algs);
  845|       |        } else {
  846|       |            session->opts.wanted_methods[SSH_KEX] =
  847|       |                ssh_prefix_without_duplicates(default_methods[SSH_KEX],
  848|       |                                              gssapi_algs);
  849|       |        }
  850|       |
  851|       |        gssapi_null_alg = true;
  852|       |
  853|       |        SAFE_FREE(gssapi_algs);
  854|       |    }
  855|       |#endif
  856|       |
  857|       |    /* Set the list of allowed algorithms in order of preference, if it hadn't
  858|       |     * been set yet. */
  859|  7.22k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  7.22k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (859:17): [True: 6.57k, False: 657]
  ------------------
  860|  6.57k|        if (i == SSH_HOSTKEYS) {
  ------------------
  |  Branch (860:13): [True: 657, False: 5.91k]
  ------------------
  861|       |            /* Set the hostkeys in the following order:
  862|       |             * - First: keys present in known_hosts files ordered by preference
  863|       |             * - Next: other wanted algorithms ordered by preference */
  864|    657|            client->methods[i] = ssh_client_select_hostkeys(session);
  865|    657|            if (client->methods[i] == NULL) {
  ------------------
  |  Branch (865:17): [True: 0, False: 657]
  ------------------
  866|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  867|      0|                return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  868|      0|            }
  869|    657|            if (gssapi_null_alg) {
  ------------------
  |  Branch (869:17): [True: 0, False: 657]
  ------------------
  870|      0|                hostkeys =
  871|      0|                    ssh_append_without_duplicates(client->methods[i], "null");
  872|      0|                if (hostkeys == NULL) {
  ------------------
  |  Branch (872:21): [True: 0, False: 0]
  ------------------
  873|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  874|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  875|      0|                }
  876|      0|                SAFE_FREE(client->methods[i]);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  877|      0|                client->methods[i] = hostkeys;
  878|      0|            }
  879|    657|            continue;
  880|    657|        }
  881|       |
  882|  5.91k|        wanted = session->opts.wanted_methods[i];
  883|  5.91k|        if (wanted == NULL) {
  ------------------
  |  Branch (883:13): [True: 3.28k, False: 2.62k]
  ------------------
  884|  3.28k|            if (ssh_fips_mode()) {
  ------------------
  |  |  115|  3.28k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 3.28k]
  |  |  ------------------
  ------------------
  885|      0|                wanted = fips_methods[i];
  886|  3.28k|            } else {
  887|  3.28k|                wanted = default_methods[i];
  888|  3.28k|            }
  889|  3.28k|        }
  890|  5.91k|        client->methods[i] = strdup(wanted);
  891|  5.91k|        if (client->methods[i] == NULL) {
  ------------------
  |  Branch (891:13): [True: 0, False: 5.91k]
  ------------------
  892|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  893|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  894|      0|        }
  895|  5.91k|    }
  896|       |
  897|       |    /* For rekeying, skip the extension negotiation */
  898|    657|    if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) {
  ------------------
  |  |   78|    657|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (898:9): [True: 0, False: 657]
  ------------------
  899|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  900|      0|    }
  901|       |
  902|    657|    ok = ssh_kex_append_extensions(session, client);
  903|    657|    if (ok != SSH_OK){
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (903:9): [True: 0, False: 657]
  ------------------
  904|      0|        return ok;
  905|      0|    }
  906|       |
  907|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  908|    657|}
ssh_kex_append_extensions:
  911|  1.31k|{
  912|  1.31k|    char *kex = NULL;
  913|  1.31k|    char *kex_tmp = NULL;
  914|  1.31k|    size_t kex_len, len;
  915|       |
  916|       |    /* Here we append ext-info-c and kex-strict-c-v00@openssh.com for client
  917|       |     * and kex-strict-s-v00@openssh.com for server to the list of kex algorithms
  918|       |     */
  919|  1.31k|    kex = pkex->methods[SSH_KEX];
  920|  1.31k|    len = strlen(kex);
  921|  1.31k|    if (session->server) {
  ------------------
  |  Branch (921:9): [True: 657, False: 657]
  ------------------
  922|       |        /* Comma, nul byte */
  923|    657|        kex_len = len + 1 + strlen(KEX_STRICT_SERVER) + 1;
  ------------------
  |  |  197|    657|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  924|    657|    } else {
  925|       |        /* Comma, comma, nul byte */
  926|    657|        kex_len = len + 1 + strlen(KEX_EXTENSION_CLIENT) + 1 +
  ------------------
  |  |  194|    657|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  927|    657|                  strlen(KEX_STRICT_CLIENT) + 1;
  ------------------
  |  |  196|    657|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  928|    657|    }
  929|  1.31k|    if (kex_len >= MAX_PACKET_LEN) {
  ------------------
  |  |  216|  1.31k|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (929:9): [True: 0, False: 1.31k]
  ------------------
  930|       |        /* Overflow */
  931|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  932|      0|    }
  933|  1.31k|    kex_tmp = realloc(kex, kex_len);
  934|  1.31k|    if (kex_tmp == NULL) {
  ------------------
  |  Branch (934:9): [True: 0, False: 1.31k]
  ------------------
  935|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  936|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  937|      0|    }
  938|  1.31k|    if (session->server){
  ------------------
  |  Branch (938:9): [True: 657, False: 657]
  ------------------
  939|    657|        snprintf(kex_tmp + len, kex_len - len, ",%s", KEX_STRICT_SERVER);
  ------------------
  |  |  197|    657|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  940|    657|    } else {
  941|    657|        snprintf(kex_tmp + len,
  942|    657|                 kex_len - len,
  943|    657|                 ",%s,%s",
  944|    657|                 KEX_EXTENSION_CLIENT,
  ------------------
  |  |  194|    657|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  945|    657|                 KEX_STRICT_CLIENT);
  ------------------
  |  |  196|    657|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  946|    657|    }
  947|  1.31k|    pkex->methods[SSH_KEX] = kex_tmp;
  948|  1.31k|    return SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  949|  1.31k|}
ssh_kex_select_methods:
 1082|  1.30k|{
 1083|  1.30k|    struct ssh_crypto_struct *crypto = session->next_crypto;
 1084|  1.30k|    struct ssh_kex_struct *server = &crypto->server_kex;
 1085|  1.30k|    struct ssh_kex_struct *client = &crypto->client_kex;
 1086|  1.30k|    char *ext_start = NULL;
 1087|  1.30k|    const char *aead_hmac = NULL;
 1088|  1.30k|    enum ssh_key_exchange_e kex_type;
 1089|  1.30k|    int i;
 1090|       |
 1091|       |    /* Here we should drop the extensions from the list so we avoid matching.
 1092|       |     * it. We added it to the end, so we can just truncate the string here */
 1093|  1.30k|    if (session->client) {
  ------------------
  |  Branch (1093:9): [True: 657, False: 652]
  ------------------
 1094|    657|        ext_start = strstr(client->methods[SSH_KEX], "," KEX_EXTENSION_CLIENT);
  ------------------
  |  |  194|    657|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
 1095|    657|        if (ext_start != NULL) {
  ------------------
  |  Branch (1095:13): [True: 657, False: 0]
  ------------------
 1096|    657|            ext_start[0] = '\0';
 1097|    657|        }
 1098|    657|    }
 1099|  1.30k|    if (session->server) {
  ------------------
  |  Branch (1099:9): [True: 657, False: 652]
  ------------------
 1100|    657|        ext_start = strstr(server->methods[SSH_KEX], "," KEX_STRICT_SERVER);
  ------------------
  |  |  197|    657|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
 1101|    657|        if (ext_start != NULL) {
  ------------------
  |  Branch (1101:13): [True: 657, False: 0]
  ------------------
 1102|    657|            ext_start[0] = '\0';
 1103|    657|        }
 1104|    657|    }
 1105|       |
 1106|  14.3k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  14.3k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (1106:17): [True: 13.0k, False: 1.30k]
  ------------------
 1107|  13.0k|        crypto->kex_methods[i] = ssh_find_matching(server->methods[i],
 1108|  13.0k|                                                   client->methods[i]);
 1109|       |
 1110|  13.0k|        if (i == SSH_MAC_C_S || i == SSH_MAC_S_C) {
  ------------------
  |  Branch (1110:13): [True: 1.25k, False: 11.8k]
  |  Branch (1110:33): [True: 1.31k, False: 10.5k]
  ------------------
 1111|  2.62k|            aead_hmac = ssh_find_aead_hmac(crypto->kex_methods[i - 2]);
 1112|  2.62k|            if (aead_hmac) {
  ------------------
  |  Branch (1112:17): [True: 0, False: 2.62k]
  ------------------
 1113|      0|                free(crypto->kex_methods[i]);
 1114|      0|                crypto->kex_methods[i] = strdup(aead_hmac);
 1115|      0|            }
 1116|  2.62k|        }
 1117|  13.0k|        if (crypto->kex_methods[i] == NULL && i < SSH_LANG_C_S) {
  ------------------
  |  Branch (1117:13): [True: 0, False: 13.0k]
  |  Branch (1117:47): [True: 0, False: 0]
  ------------------
 1118|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1119|      0|                          "kex error : no match for method %s: server [%s], "
 1120|      0|                          "client [%s]", ssh_kex_descriptions[i],
 1121|      0|                          server->methods[i], client->methods[i]);
 1122|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1123|  13.0k|        } else if ((i >= SSH_LANG_C_S) && (crypto->kex_methods[i] == NULL)) {
  ------------------
  |  Branch (1123:20): [True: 2.62k, False: 10.4k]
  |  Branch (1123:43): [True: 0, False: 2.62k]
  ------------------
 1124|       |            /* we can safely do that for languages */
 1125|      0|            crypto->kex_methods[i] = strdup("");
 1126|      0|        }
 1127|  13.0k|    }
 1128|       |
 1129|       |    /* We can not set this value directly as the old value is needed to revert
 1130|       |     * callbacks if we are client */
 1131|  1.30k|    kex_type = kex_select_kex_type(crypto->kex_methods[SSH_KEX]);
 1132|  1.30k|    if (session->client && session->first_kex_follows_guess_wrong) {
  ------------------
  |  Branch (1132:9): [True: 657, False: 652]
  |  Branch (1132:28): [True: 0, False: 657]
  ------------------
 1133|      0|        SSH_LOG(SSH_LOG_DEBUG, "Our guess was wrong. Restarting the KEX");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1134|       |        /* We need to remove the wrong callbacks and start kex again */
 1135|      0|        revert_kex_callbacks(session);
 1136|      0|        session->dh_handshake_state = DH_STATE_INIT;
 1137|      0|        session->first_kex_follows_guess_wrong = false;
 1138|      0|    }
 1139|  1.30k|    crypto->kex_type = kex_type;
 1140|       |
 1141|  1.30k|    SSH_LOG(SSH_LOG_DEBUG, "Negotiated %s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
  ------------------
  |  |  281|  1.30k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1142|  1.30k|            session->next_crypto->kex_methods[SSH_KEX],
 1143|  1.30k|            session->next_crypto->kex_methods[SSH_HOSTKEYS],
 1144|  1.30k|            session->next_crypto->kex_methods[SSH_CRYPT_C_S],
 1145|  1.30k|            session->next_crypto->kex_methods[SSH_CRYPT_S_C],
 1146|  1.30k|            session->next_crypto->kex_methods[SSH_MAC_C_S],
 1147|  1.30k|            session->next_crypto->kex_methods[SSH_MAC_S_C],
 1148|  1.30k|            session->next_crypto->kex_methods[SSH_COMP_C_S],
 1149|  1.30k|            session->next_crypto->kex_methods[SSH_COMP_S_C],
 1150|  1.30k|            session->next_crypto->kex_methods[SSH_LANG_C_S],
 1151|  1.30k|            session->next_crypto->kex_methods[SSH_LANG_S_C]
 1152|  1.30k|    );
 1153|  1.30k|    return SSH_OK;
  ------------------
  |  |  316|  1.30k|#define SSH_OK 0     /* No error */
  ------------------
 1154|  1.30k|}
ssh_send_kex:
 1159|  1.31k|{
 1160|  1.31k|    struct ssh_kex_struct *kex = (session->server ?
  ------------------
  |  Branch (1160:35): [True: 657, False: 657]
  ------------------
 1161|    657|        &session->next_crypto->server_kex :
 1162|  1.31k|        &session->next_crypto->client_kex);
 1163|  1.31k|    ssh_string str = NULL;
 1164|  1.31k|    int i;
 1165|  1.31k|    int rc;
 1166|  1.31k|    int first_kex_packet_follows = 0;
 1167|       |
 1168|       |    /* Only client can initiate the handshake methods we implement. If we
 1169|       |     * already received the peer mechanisms, there is no point in guessing */
 1170|  1.31k|    if (session->client &&
  ------------------
  |  Branch (1170:9): [True: 657, False: 657]
  ------------------
 1171|    657|        session->session_state != SSH_SESSION_STATE_KEXINIT_RECEIVED &&
  ------------------
  |  Branch (1171:9): [True: 657, False: 0]
  ------------------
 1172|    657|        session->send_first_kex_follows) {
  ------------------
  |  Branch (1172:9): [True: 0, False: 657]
  ------------------
 1173|      0|        first_kex_packet_follows = 1;
 1174|      0|    }
 1175|       |
 1176|  1.31k|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|  1.31k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1177|  1.31k|            "Sending KEXINIT packet, first_kex_packet_follows = %d",
 1178|  1.31k|            first_kex_packet_follows);
 1179|       |
 1180|  1.31k|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|  1.31k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.31k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.31k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.31k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.31k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1181|  1.31k|                         "bP",
 1182|  1.31k|                         SSH2_MSG_KEXINIT,
 1183|  1.31k|                         (size_t)16,
 1184|  1.31k|                         kex->cookie); /* cookie */
 1185|  1.31k|    if (rc != SSH_OK)
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1185:9): [True: 0, False: 1.31k]
  ------------------
 1186|      0|        goto error;
 1187|  1.31k|    if (ssh_hashbufout_add_cookie(session) < 0) {
  ------------------
  |  Branch (1187:9): [True: 0, False: 1.31k]
  ------------------
 1188|      0|        goto error;
 1189|      0|    }
 1190|       |
 1191|  1.31k|    ssh_list_kex(kex);
 1192|       |
 1193|  14.3k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  14.3k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (1193:17): [True: 13.0k, False: 1.31k]
  ------------------
 1194|  13.0k|        str = ssh_string_from_char(kex->methods[i]);
 1195|  13.0k|        if (str == NULL) {
  ------------------
  |  Branch (1195:13): [True: 0, False: 13.0k]
  ------------------
 1196|      0|            goto error;
 1197|      0|        }
 1198|       |
 1199|  13.0k|        rc = ssh_buffer_add_ssh_string(session->out_hashbuf, str);
 1200|  13.0k|        if (rc < 0) {
  ------------------
  |  Branch (1200:13): [True: 0, False: 13.0k]
  ------------------
 1201|      0|            goto error;
 1202|      0|        }
 1203|  13.0k|        rc = ssh_buffer_add_ssh_string(session->out_buffer, str);
 1204|  13.0k|        if (rc < 0) {
  ------------------
  |  Branch (1204:13): [True: 0, False: 13.0k]
  ------------------
 1205|      0|            goto error;
 1206|      0|        }
 1207|  13.0k|        SSH_STRING_FREE(str);
  ------------------
  |  |  910|  13.0k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 13.0k, False: 2]
  |  |  |  Branch (910:69): [Folded, False: 13.0k]
  |  |  ------------------
  ------------------
 1208|  13.0k|        str = NULL;
 1209|  13.0k|    }
 1210|       |
 1211|  1.31k|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|  1.31k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.31k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.31k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.31k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.31k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1212|  1.31k|                         "bd",
 1213|  1.31k|                         first_kex_packet_follows,
 1214|  1.31k|                         0);
 1215|  1.31k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1215:9): [True: 0, False: 1.31k]
  ------------------
 1216|      0|        goto error;
 1217|      0|    }
 1218|       |
 1219|       |    /* Prepare also the first_kex_packet_follows and reserved to 0 */
 1220|  1.31k|    rc = ssh_buffer_add_u8(session->out_hashbuf, first_kex_packet_follows);
 1221|  1.31k|    if (rc < 0) {
  ------------------
  |  Branch (1221:9): [True: 0, False: 1.31k]
  ------------------
 1222|      0|        goto error;
 1223|      0|    }
 1224|  1.31k|    rc = ssh_buffer_add_u32(session->out_hashbuf, 0);
 1225|  1.31k|    if (rc < 0) {
  ------------------
  |  Branch (1225:9): [True: 0, False: 1.31k]
  ------------------
 1226|      0|        goto error;
 1227|      0|    }
 1228|       |
 1229|  1.31k|    rc = ssh_packet_send(session);
 1230|  1.31k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1230:9): [True: 0, False: 1.31k]
  ------------------
 1231|      0|        return -1;
 1232|      0|    }
 1233|       |
 1234|  1.31k|    session->flags |= SSH_SESSION_FLAG_KEXINIT_SENT;
  ------------------
  |  |   86|  1.31k|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
 1235|  1.31k|    SSH_LOG(SSH_LOG_PACKET, "SSH_MSG_KEXINIT sent");
  ------------------
  |  |  281|  1.31k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1236|       |
 1237|       |    /* If we indicated that we are sending the guessed key exchange packet,
 1238|       |     * do it now. The packet is simple, but we need to do some preparations */
 1239|  1.31k|    if (first_kex_packet_follows == 1) {
  ------------------
  |  Branch (1239:9): [True: 0, False: 1.31k]
  ------------------
 1240|      0|        char *list = kex->methods[SSH_KEX];
 1241|      0|        const char *colon = strchr(list, ',');
 1242|      0|        size_t kex_name_len = colon ? (size_t)(colon - list) : strlen(list);
  ------------------
  |  Branch (1242:31): [True: 0, False: 0]
  ------------------
 1243|      0|        char *kex_name = calloc(kex_name_len + 1, 1);
 1244|      0|        if (kex_name == NULL) {
  ------------------
  |  Branch (1244:13): [True: 0, False: 0]
  ------------------
 1245|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1246|      0|            goto error;
 1247|      0|        }
 1248|      0|        snprintf(kex_name, kex_name_len + 1, "%.*s", (int)kex_name_len, list);
 1249|      0|        SSH_LOG(SSH_LOG_TRACE, "Sending the first kex packet for %s", kex_name);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1250|       |
 1251|      0|        session->next_crypto->kex_type = kex_select_kex_type(kex_name);
 1252|      0|        free(kex_name);
 1253|       |
 1254|       |        /* run the first step of the DH handshake */
 1255|      0|        session->dh_handshake_state = DH_STATE_INIT;
 1256|      0|        if (dh_handshake(session) == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1256:13): [True: 0, False: 0]
  ------------------
 1257|      0|            goto error;
 1258|      0|        }
 1259|      0|    }
 1260|  1.31k|    return 0;
 1261|       |
 1262|      0|error:
 1263|      0|    ssh_buffer_reinit(session->out_buffer);
 1264|      0|    ssh_buffer_reinit(session->out_hashbuf);
 1265|      0|    SSH_STRING_FREE(str);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1266|       |
 1267|      0|    return -1;
 1268|  1.31k|}
ssh_keep_known_algos:
 1324|  5.90k|{
 1325|  5.90k|    if (algo > SSH_LANG_S_C) {
  ------------------
  |  Branch (1325:9): [True: 0, False: 5.90k]
  ------------------
 1326|      0|        return NULL;
 1327|      0|    }
 1328|       |
 1329|  5.90k|    return ssh_find_all_matching(supported_methods[algo], list);
 1330|  5.90k|}
ssh_make_sessionid:
 1459|  1.31k|{
 1460|  1.31k|    ssh_string num = NULL;
 1461|  1.31k|    ssh_buffer server_hash = NULL;
 1462|  1.31k|    ssh_buffer client_hash = NULL;
 1463|  1.31k|    ssh_buffer buf = NULL;
 1464|  1.31k|    ssh_string server_pubkey_blob = NULL;
 1465|  1.31k|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
 1466|  1.31k|    const_bignum client_pubkey, server_pubkey;
 1467|       |#else
 1468|       |    bignum client_pubkey = NULL, server_pubkey = NULL;
 1469|       |#endif /* OPENSSL_VERSION_NUMBER */
 1470|  1.31k|#ifdef WITH_GEX
 1471|  1.31k|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
 1472|  1.31k|    const_bignum modulus, generator;
 1473|       |#else
 1474|       |    bignum modulus = NULL, generator = NULL;
 1475|       |#endif /* OPENSSL_VERSION_NUMBER */
 1476|  1.31k|#endif /* WITH_GEX */
 1477|  1.31k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1478|       |
 1479|  1.31k|    buf = ssh_buffer_new();
 1480|  1.31k|    if (buf == NULL) {
  ------------------
  |  Branch (1480:9): [True: 0, False: 1.31k]
  ------------------
 1481|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1482|      0|        return rc;
 1483|      0|    }
 1484|       |
 1485|  1.31k|    rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|  1.31k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.31k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.31k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.31k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.31k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1486|  1.31k|                         "ss",
 1487|  1.31k|                         session->clientbanner,
 1488|  1.31k|                         session->serverbanner);
 1489|  1.31k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1489:9): [True: 0, False: 1.31k]
  ------------------
 1490|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1491|      0|                      SSH_FATAL,
 1492|      0|                      "Failed to pack client and server banner");
 1493|      0|        goto error;
 1494|      0|    }
 1495|       |
 1496|  1.31k|    if (session->client) {
  ------------------
  |  Branch (1496:9): [True: 657, False: 657]
  ------------------
 1497|    657|        server_hash = session->in_hashbuf;
 1498|    657|        client_hash = session->out_hashbuf;
 1499|    657|    } else {
 1500|    657|        server_hash = session->out_hashbuf;
 1501|    657|        client_hash = session->in_hashbuf;
 1502|    657|    }
 1503|       |
 1504|  1.31k|    rc = ssh_dh_get_next_server_publickey_blob(session, &server_pubkey_blob);
 1505|  1.31k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1505:9): [True: 0, False: 1.31k]
  ------------------
 1506|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1507|      0|                      SSH_FATAL,
 1508|      0|                      "Failed to get next server pubkey blob");
 1509|      0|        goto error;
 1510|      0|    }
 1511|       |
 1512|  1.31k|    if (server_pubkey_blob == NULL) {
  ------------------
  |  Branch (1512:9): [True: 0, False: 1.31k]
  ------------------
 1513|      0|        if ((session->server && ssh_kex_is_gss(session->next_crypto)) ||
  ------------------
  |  Branch (1513:14): [True: 0, False: 0]
  |  Branch (1513:33): [True: 0, False: 0]
  ------------------
 1514|      0|            session->opts.gssapi_key_exchange) {
  ------------------
  |  Branch (1514:13): [True: 0, False: 0]
  ------------------
 1515|      0|            server_pubkey_blob = ssh_string_new(0);
 1516|      0|            if (server_pubkey_blob == NULL) {
  ------------------
  |  Branch (1516:17): [True: 0, False: 0]
  ------------------
 1517|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1518|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1519|      0|                goto error;
 1520|      0|            }
 1521|      0|        }
 1522|      0|    }
 1523|       |
 1524|  1.31k|    rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|  1.31k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.31k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.31k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.31k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.31k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1525|  1.31k|                         "dPdPS",
 1526|  1.31k|                         ssh_buffer_get_len(client_hash),
 1527|  1.31k|                         (size_t)ssh_buffer_get_len(client_hash),
 1528|  1.31k|                         ssh_buffer_get(client_hash),
 1529|  1.31k|                         ssh_buffer_get_len(server_hash),
 1530|  1.31k|                         (size_t)ssh_buffer_get_len(server_hash),
 1531|  1.31k|                         ssh_buffer_get(server_hash),
 1532|  1.31k|                         server_pubkey_blob);
 1533|  1.31k|    SSH_STRING_FREE(server_pubkey_blob);
  ------------------
  |  |  910|  1.31k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 1.31k, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 1534|  1.31k|    if (rc != SSH_OK){
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1534:9): [True: 0, False: 1.31k]
  ------------------
 1535|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1536|      0|                      SSH_FATAL,
 1537|      0|                      "Failed to pack hashes and pubkey blob");
 1538|      0|        goto error;
 1539|      0|    }
 1540|       |
 1541|  1.31k|    switch(session->next_crypto->kex_type) {
 1542|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1542:5): [True: 0, False: 1.31k]
  ------------------
 1543|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1543:5): [True: 0, False: 1.31k]
  ------------------
 1544|      0|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1544:5): [True: 0, False: 1.31k]
  ------------------
 1545|      0|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1545:5): [True: 0, False: 1.31k]
  ------------------
 1546|      0|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1546:5): [True: 0, False: 1.31k]
  ------------------
 1547|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1547:5): [True: 0, False: 1.31k]
  ------------------
 1548|      0|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1548:5): [True: 0, False: 1.31k]
  ------------------
 1549|      0|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1550|      0|                                     DH_CLIENT_KEYPAIR, NULL, &client_pubkey);
  ------------------
  |  |   30|      0|#define DH_CLIENT_KEYPAIR 0
  ------------------
 1551|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1551:13): [True: 0, False: 0]
  ------------------
 1552|      0|            goto error;
 1553|      0|        }
 1554|      0|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1555|      0|                                     DH_SERVER_KEYPAIR, NULL, &server_pubkey);
  ------------------
  |  |   31|      0|#define DH_SERVER_KEYPAIR 1
  ------------------
 1556|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1556:13): [True: 0, False: 0]
  ------------------
 1557|      0|            goto error;
 1558|      0|        }
 1559|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1560|      0|                             "BB",
 1561|      0|                             client_pubkey,
 1562|      0|                             server_pubkey);
 1563|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1563:13): [True: 0, False: 0]
  ------------------
 1564|      0|            ssh_set_error(session, SSH_FATAL, "Failed to pack DH pubkeys");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1565|      0|            goto error;
 1566|      0|        }
 1567|       |#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
 1568|       |        bignum_safe_free(client_pubkey);
 1569|       |        bignum_safe_free(server_pubkey);
 1570|       |#endif /* OPENSSL_VERSION_NUMBER */
 1571|      0|        break;
 1572|      0|#ifdef WITH_GEX
 1573|      0|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (1573:5): [True: 0, False: 1.31k]
  ------------------
 1574|      0|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1574:5): [True: 0, False: 1.31k]
  ------------------
 1575|      0|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1576|      0|                                     DH_CLIENT_KEYPAIR, NULL, &client_pubkey);
  ------------------
  |  |   30|      0|#define DH_CLIENT_KEYPAIR 0
  ------------------
 1577|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1577:13): [True: 0, False: 0]
  ------------------
 1578|      0|            goto error;
 1579|      0|        }
 1580|      0|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1581|      0|                                     DH_SERVER_KEYPAIR, NULL, &server_pubkey);
  ------------------
  |  |   31|      0|#define DH_SERVER_KEYPAIR 1
  ------------------
 1582|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1582:13): [True: 0, False: 0]
  ------------------
 1583|      0|            goto error;
 1584|      0|        }
 1585|      0|        rc = ssh_dh_get_parameters(session->next_crypto->dh_ctx,
 1586|      0|                                   &modulus, &generator);
 1587|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1587:13): [True: 0, False: 0]
  ------------------
 1588|      0|            goto error;
 1589|      0|        }
 1590|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1591|      0|                    "dddBBBB",
 1592|      0|                    session->next_crypto->dh_pmin,
 1593|      0|                    session->next_crypto->dh_pn,
 1594|      0|                    session->next_crypto->dh_pmax,
 1595|      0|                    modulus,
 1596|      0|                    generator,
 1597|      0|                    client_pubkey,
 1598|      0|                    server_pubkey);
 1599|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1599:13): [True: 0, False: 0]
  ------------------
 1600|      0|            ssh_set_error(session, SSH_FATAL, "Failed to pack DH GEX params");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1601|      0|            goto error;
 1602|      0|        }
 1603|       |#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
 1604|       |        bignum_safe_free(modulus);
 1605|       |        bignum_safe_free(generator);
 1606|       |#endif /* OPENSSL_VERSION_NUMBER */
 1607|      0|        break;
 1608|      0|#endif /* WITH_GEX */
 1609|      0|#ifdef HAVE_ECDH
 1610|      0|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (1610:5): [True: 0, False: 1.31k]
  ------------------
 1611|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1611:5): [True: 0, False: 1.31k]
  ------------------
 1612|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1612:5): [True: 0, False: 1.31k]
  ------------------
 1613|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1613:5): [True: 0, False: 1.31k]
  ------------------
 1614|      0|        if (session->next_crypto->ecdh_client_pubkey == NULL ||
  ------------------
  |  Branch (1614:13): [True: 0, False: 0]
  ------------------
 1615|      0|            session->next_crypto->ecdh_server_pubkey == NULL) {
  ------------------
  |  Branch (1615:13): [True: 0, False: 0]
  ------------------
 1616|      0|            SSH_LOG(SSH_LOG_TRACE, "ECDH parameter missing");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1617|      0|            goto error;
 1618|      0|        }
 1619|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1620|      0|                             "SS",
 1621|      0|                             session->next_crypto->ecdh_client_pubkey,
 1622|      0|                             session->next_crypto->ecdh_server_pubkey);
 1623|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1623:13): [True: 0, False: 0]
  ------------------
 1624|      0|            ssh_set_error(session, SSH_FATAL, "Failed to pack ECDH pubkeys");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1625|      0|            goto error;
 1626|      0|        }
 1627|      0|        break;
 1628|      0|#endif /* HAVE_ECDH */
 1629|      0|#ifdef HAVE_CURVE25519
 1630|      0|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1630:5): [True: 0, False: 1.31k]
  ------------------
 1631|      0|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1631:5): [True: 0, False: 1.31k]
  ------------------
 1632|      0|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1632:5): [True: 0, False: 1.31k]
  ------------------
 1633|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1634|      0|                             "dPdP",
 1635|      0|                             CURVE25519_PUBKEY_SIZE,
 1636|      0|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1637|      0|                             session->next_crypto->curve25519_client_pubkey,
 1638|      0|                             CURVE25519_PUBKEY_SIZE,
 1639|      0|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1640|      0|                             session->next_crypto->curve25519_server_pubkey);
 1641|       |
 1642|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1642:13): [True: 0, False: 0]
  ------------------
 1643|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1644|      0|                          SSH_FATAL,
 1645|      0|                          "Failed to pack Curve25519 pubkeys");
 1646|      0|            goto error;
 1647|      0|        }
 1648|      0|        break;
 1649|      0|#endif /* HAVE_CURVE25519 */
 1650|      0|#ifdef HAVE_SNTRUP761
 1651|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1651:5): [True: 0, False: 1.31k]
  ------------------
 1652|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1652:5): [True: 0, False: 1.31k]
  ------------------
 1653|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1654|      0|                             "dPPdPP",
 1655|      0|                             SNTRUP761_PUBLICKEY_SIZE + CURVE25519_PUBKEY_SIZE,
 1656|      0|                             (size_t)SNTRUP761_PUBLICKEY_SIZE,
 1657|      0|                             session->next_crypto->sntrup761_client_pubkey,
 1658|      0|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1659|      0|                             session->next_crypto->curve25519_client_pubkey,
 1660|      0|                             SNTRUP761_CIPHERTEXT_SIZE + CURVE25519_PUBKEY_SIZE,
 1661|      0|                             (size_t)SNTRUP761_CIPHERTEXT_SIZE,
 1662|      0|                             session->next_crypto->sntrup761_ciphertext,
 1663|      0|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1664|      0|                             session->next_crypto->curve25519_server_pubkey);
 1665|       |
 1666|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1666:13): [True: 0, False: 0]
  ------------------
 1667|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1668|      0|                          SSH_FATAL,
 1669|      0|                          "Failed to pack SNTRU Prime params");
 1670|      0|            goto error;
 1671|      0|        }
 1672|      0|        break;
 1673|      0|#endif /* HAVE_SNTRUP761 */
 1674|  1.31k|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1674:5): [True: 1.31k, False: 0]
  ------------------
 1675|  1.31k|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1675:5): [True: 0, False: 1.31k]
  ------------------
 1676|       |#ifdef HAVE_MLKEM1024
 1677|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1678|       |#endif
 1679|  1.31k|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|  1.31k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.31k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.31k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.31k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.31k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1680|  1.31k|                             "SS",
 1681|  1.31k|                             session->next_crypto->hybrid_client_init,
 1682|  1.31k|                             session->next_crypto->hybrid_server_reply);
 1683|  1.31k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1683:13): [True: 0, False: 1.31k]
  ------------------
 1684|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1685|      0|                          SSH_FATAL,
 1686|      0|                          "Failed to pack ML-KEM individual components");
 1687|      0|            goto error;
 1688|      0|        }
 1689|  1.31k|        break;
 1690|  1.31k|    default:
  ------------------
  |  Branch (1690:5): [True: 0, False: 1.31k]
  ------------------
 1691|       |        /* Handle unsupported kex types - this should not happen in normal operation */
 1692|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1693|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX algorithm");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1694|      0|        goto error;
 1695|  1.31k|    }
 1696|  1.31k|    switch (session->next_crypto->kex_type) {
 1697|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1697:5): [True: 0, False: 1.31k]
  ------------------
 1698|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1698:5): [True: 0, False: 1.31k]
  ------------------
 1699|  1.31k|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1699:5): [True: 1.31k, False: 0]
  ------------------
 1700|  1.31k|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1700:5): [True: 0, False: 1.31k]
  ------------------
 1701|       |#ifdef HAVE_MLKEM1024
 1702|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1703|       |#endif
 1704|  1.31k|        rc = ssh_buffer_pack(buf, "S", session->next_crypto->hybrid_shared_secret);
  ------------------
  |  |   50|  1.31k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.31k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.31k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.31k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.31k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.31k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1705|  1.31k|        break;
 1706|      0|    default:
  ------------------
  |  Branch (1706:5): [True: 0, False: 1.31k]
  ------------------
 1707|      0|        rc = ssh_buffer_pack(buf, "B", session->next_crypto->shared_secret);
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1708|      0|        break;
 1709|  1.31k|    }
 1710|  1.31k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1710:9): [True: 0, False: 1.31k]
  ------------------
 1711|      0|        ssh_set_error(session, SSH_FATAL, "Failed to pack shared secret");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1712|      0|        goto error;
 1713|      0|    }
 1714|       |
 1715|       |#ifdef DEBUG_CRYPTO
 1716|       |    ssh_log_hexdump("hash buffer", ssh_buffer_get(buf), ssh_buffer_get_len(buf));
 1717|       |#endif
 1718|       |
 1719|       |    /* Set rc for the following switch statement in case we goto error. */
 1720|  1.31k|    rc = SSH_ERROR;
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1721|  1.31k|    switch (session->next_crypto->kex_type) {
 1722|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1722:5): [True: 0, False: 1.31k]
  ------------------
 1723|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1723:5): [True: 0, False: 1.31k]
  ------------------
 1724|      0|#ifdef WITH_GEX
 1725|      0|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (1725:5): [True: 0, False: 1.31k]
  ------------------
 1726|      0|#endif /* WITH_GEX */
 1727|      0|        session->next_crypto->digest_len = SHA_DIGEST_LENGTH;
 1728|      0|        session->next_crypto->digest_type = SSH_KDF_SHA1;
 1729|      0|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1730|      0|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1730:13): [True: 0, False: 0]
  ------------------
 1731|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1732|      0|            goto error;
 1733|      0|        }
 1734|      0|        sha1(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
 1735|      0|                                   session->next_crypto->secret_hash);
 1736|      0|        break;
 1737|      0|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1737:5): [True: 0, False: 1.31k]
  ------------------
 1738|      0|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1738:5): [True: 0, False: 1.31k]
  ------------------
 1739|      0|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (1739:5): [True: 0, False: 1.31k]
  ------------------
 1740|      0|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1740:5): [True: 0, False: 1.31k]
  ------------------
 1741|      0|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1741:5): [True: 0, False: 1.31k]
  ------------------
 1742|  1.31k|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1742:5): [True: 1.31k, False: 0]
  ------------------
 1743|  1.31k|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1743:5): [True: 0, False: 1.31k]
  ------------------
 1744|  1.31k|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1744:5): [True: 0, False: 1.31k]
  ------------------
 1745|  1.31k|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1745:5): [True: 0, False: 1.31k]
  ------------------
 1746|  1.31k|#ifdef WITH_GEX
 1747|  1.31k|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1747:5): [True: 0, False: 1.31k]
  ------------------
 1748|  1.31k|#endif /* WITH_GEX */
 1749|  1.31k|        session->next_crypto->digest_len = SHA256_DIGEST_LENGTH;
 1750|  1.31k|        session->next_crypto->digest_type = SSH_KDF_SHA256;
 1751|  1.31k|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1752|  1.31k|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1752:13): [True: 0, False: 1.31k]
  ------------------
 1753|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1754|      0|            goto error;
 1755|      0|        }
 1756|  1.31k|        sha256(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
 1757|  1.31k|                                     session->next_crypto->secret_hash);
 1758|  1.31k|        break;
 1759|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1759:5): [True: 0, False: 1.31k]
  ------------------
 1760|       |#ifdef HAVE_MLKEM1024
 1761|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1762|       |#endif
 1763|      0|        session->next_crypto->digest_len = SHA384_DIGEST_LENGTH;
 1764|      0|        session->next_crypto->digest_type = SSH_KDF_SHA384;
 1765|      0|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1766|      0|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1766:13): [True: 0, False: 0]
  ------------------
 1767|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1768|      0|            goto error;
 1769|      0|        }
 1770|      0|        sha384(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
 1771|      0|                                     session->next_crypto->secret_hash);
 1772|      0|        break;
 1773|      0|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1773:5): [True: 0, False: 1.31k]
  ------------------
 1774|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1774:5): [True: 0, False: 1.31k]
  ------------------
 1775|      0|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1775:5): [True: 0, False: 1.31k]
  ------------------
 1776|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1776:5): [True: 0, False: 1.31k]
  ------------------
 1777|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1777:5): [True: 0, False: 1.31k]
  ------------------
 1778|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1778:5): [True: 0, False: 1.31k]
  ------------------
 1779|      0|        session->next_crypto->digest_len = SHA512_DIGEST_LENGTH;
 1780|      0|        session->next_crypto->digest_type = SSH_KDF_SHA512;
 1781|      0|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1782|      0|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1782:13): [True: 0, False: 0]
  ------------------
 1783|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1784|      0|            goto error;
 1785|      0|        }
 1786|      0|        sha512(ssh_buffer_get(buf),
 1787|      0|               ssh_buffer_get_len(buf),
 1788|      0|               session->next_crypto->secret_hash);
 1789|      0|        break;
 1790|      0|    default:
  ------------------
  |  Branch (1790:5): [True: 0, False: 1.31k]
  ------------------
 1791|       |        /* Handle unsupported kex types - this should not happen in normal operation */
 1792|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX algorithm for hash computation");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1793|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1794|      0|        goto error;
 1795|  1.31k|    }
 1796|       |
 1797|       |    /* During the first kex, secret hash and session ID are equal. However, after
 1798|       |     * a key re-exchange, a new secret hash is calculated. This hash will not replace
 1799|       |     * but complement existing session id.
 1800|       |     */
 1801|  1.31k|    if (!session->next_crypto->session_id) {
  ------------------
  |  Branch (1801:9): [True: 1.31k, False: 0]
  ------------------
 1802|  1.31k|        session->next_crypto->session_id = malloc(session->next_crypto->digest_len);
 1803|  1.31k|        if (session->next_crypto->session_id == NULL) {
  ------------------
  |  Branch (1803:13): [True: 0, False: 1.31k]
  ------------------
 1804|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1805|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1806|      0|            goto error;
 1807|      0|        }
 1808|  1.31k|        memcpy(session->next_crypto->session_id, session->next_crypto->secret_hash,
 1809|  1.31k|                session->next_crypto->digest_len);
 1810|       |	/* Initial length is the same as secret hash */
 1811|  1.31k|	session->next_crypto->session_id_len = session->next_crypto->digest_len;
 1812|  1.31k|    }
 1813|       |#ifdef DEBUG_CRYPTO
 1814|       |    SSH_LOG(SSH_LOG_DEBUG, "Session hash: \n");
 1815|       |    ssh_log_hexdump("secret hash", session->next_crypto->secret_hash, session->next_crypto->digest_len);
 1816|       |    ssh_log_hexdump("session id", session->next_crypto->session_id, session->next_crypto->session_id_len);
 1817|       |#endif /* DEBUG_CRYPTO */
 1818|       |
 1819|  1.31k|    rc = SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
 1820|  1.31k|error:
 1821|  1.31k|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|  1.31k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 1.31k, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 1822|  1.31k|    SSH_BUFFER_FREE(client_hash);
  ------------------
  |  |  951|  1.31k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 1.31k, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 1823|  1.31k|    SSH_BUFFER_FREE(server_hash);
  ------------------
  |  |  951|  1.31k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 1.31k, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 1824|       |
 1825|  1.31k|    session->in_hashbuf = NULL;
 1826|  1.31k|    session->out_hashbuf = NULL;
 1827|       |
 1828|  1.31k|    SSH_STRING_FREE(num);
  ------------------
  |  |  910|  1.31k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 1.31k]
  |  |  |  Branch (910:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 1829|       |#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
 1830|       |    bignum_safe_free(client_pubkey);
 1831|       |    bignum_safe_free(server_pubkey);
 1832|       |#endif /* OPENSSL_VERSION_NUMBER */
 1833|       |
 1834|  1.31k|    return rc;
 1835|  1.31k|}
ssh_hashbufout_add_cookie:
 1838|  1.31k|{
 1839|  1.31k|    int rc;
 1840|       |
 1841|  1.31k|    session->out_hashbuf = ssh_buffer_new();
 1842|  1.31k|    if (session->out_hashbuf == NULL) {
  ------------------
  |  Branch (1842:9): [True: 0, False: 1.31k]
  ------------------
 1843|      0|        return -1;
 1844|      0|    }
 1845|       |
 1846|  1.31k|    rc = ssh_buffer_allocate_size(session->out_hashbuf,
 1847|  1.31k|            sizeof(uint8_t) + 16);
 1848|  1.31k|    if (rc < 0) {
  ------------------
  |  Branch (1848:9): [True: 0, False: 1.31k]
  ------------------
 1849|      0|        ssh_buffer_reinit(session->out_hashbuf);
 1850|      0|        return -1;
 1851|      0|    }
 1852|       |
 1853|  1.31k|    if (ssh_buffer_add_u8(session->out_hashbuf, 20) < 0) {
  ------------------
  |  Branch (1853:9): [True: 0, False: 1.31k]
  ------------------
 1854|      0|        ssh_buffer_reinit(session->out_hashbuf);
 1855|      0|        return -1;
 1856|      0|    }
 1857|       |
 1858|  1.31k|    if (session->server) {
  ------------------
  |  Branch (1858:9): [True: 657, False: 656]
  ------------------
 1859|    657|        if (ssh_buffer_add_data(session->out_hashbuf,
  ------------------
  |  Branch (1859:13): [True: 0, False: 657]
  ------------------
 1860|    657|                    session->next_crypto->server_kex.cookie, 16) < 0) {
 1861|      0|            ssh_buffer_reinit(session->out_hashbuf);
 1862|      0|            return -1;
 1863|      0|        }
 1864|    657|    } else {
 1865|    656|        if (ssh_buffer_add_data(session->out_hashbuf,
  ------------------
  |  Branch (1865:13): [True: 0, False: 656]
  ------------------
 1866|    656|                    session->next_crypto->client_kex.cookie, 16) < 0) {
 1867|      0|            ssh_buffer_reinit(session->out_hashbuf);
 1868|      0|            return -1;
 1869|      0|        }
 1870|    656|    }
 1871|       |
 1872|  1.31k|    return 0;
 1873|  1.31k|}
ssh_hashbufin_add_cookie:
 1876|  1.30k|{
 1877|  1.30k|    int rc;
 1878|       |
 1879|  1.30k|    session->in_hashbuf = ssh_buffer_new();
 1880|  1.30k|    if (session->in_hashbuf == NULL) {
  ------------------
  |  Branch (1880:9): [True: 0, False: 1.30k]
  ------------------
 1881|      0|        return -1;
 1882|      0|    }
 1883|       |
 1884|  1.30k|    rc = ssh_buffer_allocate_size(session->in_hashbuf,
 1885|  1.30k|            sizeof(uint8_t) + 20 + 16);
 1886|  1.30k|    if (rc < 0) {
  ------------------
  |  Branch (1886:9): [True: 0, False: 1.30k]
  ------------------
 1887|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1888|      0|        return -1;
 1889|      0|    }
 1890|       |
 1891|  1.30k|    if (ssh_buffer_add_u8(session->in_hashbuf, 20) < 0) {
  ------------------
  |  Branch (1891:9): [True: 0, False: 1.30k]
  ------------------
 1892|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1893|      0|        return -1;
 1894|      0|    }
 1895|  1.30k|    if (ssh_buffer_add_data(session->in_hashbuf,cookie, 16) < 0) {
  ------------------
  |  Branch (1895:9): [True: 0, False: 1.30k]
  ------------------
 1896|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1897|      0|        return -1;
 1898|      0|    }
 1899|       |
 1900|  1.30k|    return 0;
 1901|  1.30k|}
ssh_generate_session_keys:
 1904|  1.31k|{
 1905|  1.31k|    ssh_string k_string = NULL;
 1906|  1.31k|    struct ssh_crypto_struct *crypto = session->next_crypto;
 1907|  1.31k|    unsigned char *key = NULL;
 1908|  1.31k|    unsigned char *IV_cli_to_srv = NULL;
 1909|  1.31k|    unsigned char *IV_srv_to_cli = NULL;
 1910|  1.31k|    unsigned char *enckey_cli_to_srv = NULL;
 1911|  1.31k|    unsigned char *enckey_srv_to_cli = NULL;
 1912|  1.31k|    unsigned char *intkey_cli_to_srv = NULL;
 1913|  1.31k|    unsigned char *intkey_srv_to_cli = NULL;
 1914|  1.31k|    size_t key_len = 0;
 1915|  1.31k|    size_t IV_len = 0;
 1916|  1.31k|    size_t enckey_cli_to_srv_len = 0;
 1917|  1.31k|    size_t enckey_srv_to_cli_len = 0;
 1918|  1.31k|    size_t intkey_cli_to_srv_len = 0;
 1919|  1.31k|    size_t intkey_srv_to_cli_len = 0;
 1920|  1.31k|    int rc = -1;
 1921|       |
 1922|  1.31k|    switch (session->next_crypto->kex_type) {
 1923|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1923:5): [True: 0, False: 1.31k]
  ------------------
 1924|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1924:5): [True: 0, False: 1.31k]
  ------------------
 1925|  1.31k|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1925:5): [True: 1.31k, False: 0]
  ------------------
 1926|  1.31k|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1926:5): [True: 0, False: 1.31k]
  ------------------
 1927|       |#ifdef HAVE_MLKEM1024
 1928|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1929|       |#endif
 1930|  1.31k|        k_string = ssh_string_copy(crypto->hybrid_shared_secret);
 1931|  1.31k|        break;
 1932|      0|    default:
  ------------------
  |  Branch (1932:5): [True: 0, False: 1.31k]
  ------------------
 1933|      0|        k_string = ssh_make_bignum_string(crypto->shared_secret);
 1934|      0|        break;
 1935|  1.31k|    }
 1936|  1.31k|    if (k_string == NULL) {
  ------------------
  |  Branch (1936:9): [True: 0, False: 1.31k]
  ------------------
 1937|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1938|      0|        goto error;
 1939|      0|    }
 1940|       |    /* See RFC4251 Section 5 for the definition of mpint which is the
 1941|       |     * encoding we need to use for key in the SSH KDF */
 1942|  1.31k|    key = (unsigned char *)k_string;
 1943|  1.31k|    key_len = ssh_string_len(k_string) + 4;
 1944|       |
 1945|  1.31k|    IV_len = crypto->digest_len;
 1946|  1.31k|    if (session->client) {
  ------------------
  |  Branch (1946:9): [True: 657, False: 657]
  ------------------
 1947|    657|        enckey_cli_to_srv_len = crypto->out_cipher->keysize / 8;
 1948|    657|        enckey_srv_to_cli_len = crypto->in_cipher->keysize / 8;
 1949|    657|        intkey_cli_to_srv_len = hmac_digest_len(crypto->out_hmac);
 1950|    657|        intkey_srv_to_cli_len = hmac_digest_len(crypto->in_hmac);
 1951|    657|    } else {
 1952|    657|        enckey_cli_to_srv_len = crypto->in_cipher->keysize / 8;
 1953|    657|        enckey_srv_to_cli_len = crypto->out_cipher->keysize / 8;
 1954|    657|        intkey_cli_to_srv_len = hmac_digest_len(crypto->in_hmac);
 1955|    657|        intkey_srv_to_cli_len = hmac_digest_len(crypto->out_hmac);
 1956|    657|    }
 1957|       |
 1958|  1.31k|    IV_cli_to_srv = malloc(IV_len);
 1959|  1.31k|    IV_srv_to_cli = malloc(IV_len);
 1960|  1.31k|    enckey_cli_to_srv = malloc(enckey_cli_to_srv_len);
 1961|  1.31k|    enckey_srv_to_cli = malloc(enckey_srv_to_cli_len);
 1962|  1.31k|    intkey_cli_to_srv = malloc(intkey_cli_to_srv_len);
 1963|  1.31k|    intkey_srv_to_cli = malloc(intkey_srv_to_cli_len);
 1964|  1.31k|    if (IV_cli_to_srv == NULL || IV_srv_to_cli == NULL ||
  ------------------
  |  Branch (1964:9): [True: 0, False: 1.31k]
  |  Branch (1964:34): [True: 0, False: 1.31k]
  ------------------
 1965|  1.31k|        enckey_cli_to_srv == NULL || enckey_srv_to_cli == NULL ||
  ------------------
  |  Branch (1965:9): [True: 0, False: 1.31k]
  |  Branch (1965:38): [True: 0, False: 1.31k]
  ------------------
 1966|  1.31k|        intkey_cli_to_srv == NULL || intkey_srv_to_cli == NULL) {
  ------------------
  |  Branch (1966:9): [True: 0, False: 1.31k]
  |  Branch (1966:38): [True: 0, False: 1.31k]
  ------------------
 1967|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1968|      0|        goto error;
 1969|      0|    }
 1970|       |
 1971|       |    /* IV */
 1972|  1.31k|    rc = ssh_kdf(crypto, key, key_len, 'A', IV_cli_to_srv, IV_len);
 1973|  1.31k|    if (rc < 0) {
  ------------------
  |  Branch (1973:9): [True: 0, False: 1.31k]
  ------------------
 1974|      0|        goto error;
 1975|      0|    }
 1976|  1.31k|    rc = ssh_kdf(crypto, key, key_len, 'B', IV_srv_to_cli, IV_len);
 1977|  1.31k|    if (rc < 0) {
  ------------------
  |  Branch (1977:9): [True: 0, False: 1.31k]
  ------------------
 1978|      0|        goto error;
 1979|      0|    }
 1980|       |    /* Encryption Key */
 1981|  1.31k|    rc = ssh_kdf(crypto, key, key_len, 'C', enckey_cli_to_srv,
 1982|  1.31k|                 enckey_cli_to_srv_len);
 1983|  1.31k|    if (rc < 0) {
  ------------------
  |  Branch (1983:9): [True: 0, False: 1.31k]
  ------------------
 1984|      0|        goto error;
 1985|      0|    }
 1986|  1.31k|    rc = ssh_kdf(crypto, key, key_len, 'D', enckey_srv_to_cli,
 1987|  1.31k|                 enckey_srv_to_cli_len);
 1988|  1.31k|    if (rc < 0) {
  ------------------
  |  Branch (1988:9): [True: 0, False: 1.31k]
  ------------------
 1989|      0|        goto error;
 1990|      0|    }
 1991|       |    /* Integrity Key */
 1992|  1.31k|    rc = ssh_kdf(crypto, key, key_len, 'E', intkey_cli_to_srv,
 1993|  1.31k|                 intkey_cli_to_srv_len);
 1994|  1.31k|    if (rc < 0) {
  ------------------
  |  Branch (1994:9): [True: 0, False: 1.31k]
  ------------------
 1995|      0|        goto error;
 1996|      0|    }
 1997|  1.31k|    rc = ssh_kdf(crypto, key, key_len, 'F', intkey_srv_to_cli,
 1998|  1.31k|                 intkey_srv_to_cli_len);
 1999|  1.31k|    if (rc < 0) {
  ------------------
  |  Branch (1999:9): [True: 0, False: 1.31k]
  ------------------
 2000|      0|        goto error;
 2001|      0|    }
 2002|       |
 2003|  1.31k|    if (session->client) {
  ------------------
  |  Branch (2003:9): [True: 657, False: 657]
  ------------------
 2004|    657|        crypto->encryptIV = IV_cli_to_srv;
 2005|    657|        crypto->decryptIV = IV_srv_to_cli;
 2006|    657|        crypto->encryptkey = enckey_cli_to_srv;
 2007|    657|        crypto->decryptkey = enckey_srv_to_cli;
 2008|    657|        crypto->encryptMAC = intkey_cli_to_srv;
 2009|    657|        crypto->decryptMAC = intkey_srv_to_cli;
 2010|    657|    } else {
 2011|    657|        crypto->encryptIV = IV_srv_to_cli;
 2012|    657|        crypto->decryptIV = IV_cli_to_srv;
 2013|    657|        crypto->encryptkey = enckey_srv_to_cli;
 2014|    657|        crypto->decryptkey = enckey_cli_to_srv;
 2015|    657|        crypto->encryptMAC = intkey_srv_to_cli;
 2016|    657|        crypto->decryptMAC = intkey_cli_to_srv;
 2017|    657|    }
 2018|       |
 2019|       |#ifdef DEBUG_CRYPTO
 2020|       |    ssh_log_hexdump("Client to Server IV", IV_cli_to_srv, IV_len);
 2021|       |    ssh_log_hexdump("Server to Client IV", IV_srv_to_cli, IV_len);
 2022|       |    ssh_log_hexdump("Client to Server Encryption Key", enckey_cli_to_srv,
 2023|       |                   enckey_cli_to_srv_len);
 2024|       |    ssh_log_hexdump("Server to Client Encryption Key", enckey_srv_to_cli,
 2025|       |                   enckey_srv_to_cli_len);
 2026|       |    ssh_log_hexdump("Client to Server Integrity Key", intkey_cli_to_srv,
 2027|       |                   intkey_cli_to_srv_len);
 2028|       |    ssh_log_hexdump("Server to Client Integrity Key", intkey_srv_to_cli,
 2029|       |                   intkey_srv_to_cli_len);
 2030|       |#endif /* DEBUG_CRYPTO */
 2031|       |
 2032|  1.31k|    rc = 0;
 2033|  1.31k|error:
 2034|  1.31k|    ssh_string_burn(k_string);
 2035|  1.31k|    SSH_STRING_FREE(k_string);
  ------------------
  |  |  910|  1.31k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 1.31k, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 2036|  1.31k|    if (rc != 0) {
  ------------------
  |  Branch (2036:9): [True: 0, False: 1.31k]
  ------------------
 2037|      0|        free(IV_cli_to_srv);
 2038|      0|        free(IV_srv_to_cli);
 2039|      0|        free(enckey_cli_to_srv);
 2040|      0|        free(enckey_srv_to_cli);
 2041|      0|        free(intkey_cli_to_srv);
 2042|      0|        free(intkey_srv_to_cli);
 2043|      0|    }
 2044|       |
 2045|  1.31k|    return rc;
 2046|  1.31k|}
kex.c:ssh_find_aead_hmac:
  952|  2.62k|{
  953|  2.62k|    if (cipher == NULL) {
  ------------------
  |  Branch (953:9): [True: 0, False: 2.62k]
  ------------------
  954|      0|        return NULL;
  955|  2.62k|    } else if (strcmp(cipher, "chacha20-poly1305@openssh.com") == 0) {
  ------------------
  |  Branch (955:16): [True: 0, False: 2.62k]
  ------------------
  956|      0|        return "aead-poly1305";
  957|  2.62k|    } else if (strcmp(cipher, "aes256-gcm@openssh.com") == 0) {
  ------------------
  |  Branch (957:16): [True: 0, False: 2.62k]
  ------------------
  958|      0|        return "aead-gcm";
  959|  2.62k|    } else if (strcmp(cipher, "aes128-gcm@openssh.com") == 0) {
  ------------------
  |  Branch (959:16): [True: 0, False: 2.62k]
  ------------------
  960|      0|        return "aead-gcm";
  961|      0|    }
  962|  2.62k|    return NULL;
  963|  2.62k|}
kex.c:kex_select_kex_type:
  967|  1.31k|{
  968|  1.31k|    if (strcmp(kex, "diffie-hellman-group1-sha1") == 0) {
  ------------------
  |  Branch (968:9): [True: 0, False: 1.31k]
  ------------------
  969|      0|        return SSH_KEX_DH_GROUP1_SHA1;
  970|  1.31k|    } else if (strncmp(kex, "gss-group14-sha256-", 19) == 0) {
  ------------------
  |  Branch (970:16): [True: 0, False: 1.31k]
  ------------------
  971|      0|        return SSH_GSS_KEX_DH_GROUP14_SHA256;
  972|  1.31k|    } else if (strncmp(kex, "gss-group16-sha512-", 19) == 0) {
  ------------------
  |  Branch (972:16): [True: 0, False: 1.31k]
  ------------------
  973|      0|        return SSH_GSS_KEX_DH_GROUP16_SHA512;
  974|  1.31k|    } else if (strncmp(kex, "gss-nistp256-sha256-", 20) == 0) {
  ------------------
  |  Branch (974:16): [True: 0, False: 1.31k]
  ------------------
  975|      0|        return SSH_GSS_KEX_ECDH_NISTP256_SHA256;
  976|  1.31k|    } else if (strncmp(kex, "gss-curve25519-sha256-", 22) == 0) {
  ------------------
  |  Branch (976:16): [True: 0, False: 1.31k]
  ------------------
  977|      0|        return SSH_GSS_KEX_CURVE25519_SHA256;
  978|  1.31k|    } else if (strcmp(kex, "diffie-hellman-group14-sha1") == 0) {
  ------------------
  |  Branch (978:16): [True: 0, False: 1.31k]
  ------------------
  979|      0|        return SSH_KEX_DH_GROUP14_SHA1;
  980|  1.31k|    } else if (strcmp(kex, "diffie-hellman-group14-sha256") == 0) {
  ------------------
  |  Branch (980:16): [True: 0, False: 1.31k]
  ------------------
  981|      0|        return SSH_KEX_DH_GROUP14_SHA256;
  982|  1.31k|    } else if (strcmp(kex, "diffie-hellman-group16-sha512") == 0) {
  ------------------
  |  Branch (982:16): [True: 0, False: 1.31k]
  ------------------
  983|      0|        return SSH_KEX_DH_GROUP16_SHA512;
  984|  1.31k|    } else if (strcmp(kex, "diffie-hellman-group18-sha512") == 0) {
  ------------------
  |  Branch (984:16): [True: 0, False: 1.31k]
  ------------------
  985|      0|        return SSH_KEX_DH_GROUP18_SHA512;
  986|      0|#ifdef WITH_GEX
  987|  1.31k|    } else if (strcmp(kex, "diffie-hellman-group-exchange-sha1") == 0) {
  ------------------
  |  Branch (987:16): [True: 0, False: 1.31k]
  ------------------
  988|      0|        return SSH_KEX_DH_GEX_SHA1;
  989|  1.31k|    } else if (strcmp(kex, "diffie-hellman-group-exchange-sha256") == 0) {
  ------------------
  |  Branch (989:16): [True: 0, False: 1.31k]
  ------------------
  990|      0|        return SSH_KEX_DH_GEX_SHA256;
  991|      0|#endif /* WITH_GEX */
  992|  1.31k|    } else if (strcmp(kex, "ecdh-sha2-nistp256") == 0) {
  ------------------
  |  Branch (992:16): [True: 0, False: 1.31k]
  ------------------
  993|      0|        return SSH_KEX_ECDH_SHA2_NISTP256;
  994|  1.31k|    } else if (strcmp(kex, "ecdh-sha2-nistp384") == 0) {
  ------------------
  |  Branch (994:16): [True: 0, False: 1.31k]
  ------------------
  995|      0|        return SSH_KEX_ECDH_SHA2_NISTP384;
  996|  1.31k|    } else if (strcmp(kex, "ecdh-sha2-nistp521") == 0) {
  ------------------
  |  Branch (996:16): [True: 0, False: 1.31k]
  ------------------
  997|      0|        return SSH_KEX_ECDH_SHA2_NISTP521;
  998|  1.31k|    } else if (strcmp(kex, "curve25519-sha256@libssh.org") == 0) {
  ------------------
  |  Branch (998:16): [True: 0, False: 1.31k]
  ------------------
  999|      0|        return SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG;
 1000|  1.31k|    } else if (strcmp(kex, "curve25519-sha256") == 0) {
  ------------------
  |  Branch (1000:16): [True: 0, False: 1.31k]
  ------------------
 1001|      0|        return SSH_KEX_CURVE25519_SHA256;
 1002|  1.31k|    } else if (strcmp(kex, "sntrup761x25519-sha512@openssh.com") == 0) {
  ------------------
  |  Branch (1002:16): [True: 0, False: 1.31k]
  ------------------
 1003|      0|        return SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM;
 1004|  1.31k|    } else if (strcmp(kex, "sntrup761x25519-sha512") == 0) {
  ------------------
  |  Branch (1004:16): [True: 0, False: 1.31k]
  ------------------
 1005|      0|        return SSH_KEX_SNTRUP761X25519_SHA512;
 1006|  1.31k|    } else if (strcmp(kex, "mlkem768x25519-sha256") == 0) {
  ------------------
  |  Branch (1006:16): [True: 1.31k, False: 0]
  ------------------
 1007|  1.31k|        return SSH_KEX_MLKEM768X25519_SHA256;
 1008|  1.31k|    } else if (strcmp(kex, "mlkem768nistp256-sha256") == 0) {
  ------------------
  |  Branch (1008:16): [True: 0, False: 0]
  ------------------
 1009|      0|        return SSH_KEX_MLKEM768NISTP256_SHA256;
 1010|       |#ifdef HAVE_MLKEM1024
 1011|       |    } else if (strcmp(kex, "mlkem1024nistp384-sha384") == 0) {
 1012|       |        return SSH_KEX_MLKEM1024NISTP384_SHA384;
 1013|       |#endif
 1014|      0|    }
 1015|       |    /* should not happen. We should be getting only valid names at this stage */
 1016|      0|    return 0;
 1017|  1.31k|}

ssh_known_hosts_get_algorithms_names:
  565|    657|{
  566|    657|    char methods_buffer[256 + 1] = {0};
  567|    657|    struct ssh_list *entry_list = NULL;
  568|    657|    struct ssh_iterator *it = NULL;
  569|    657|    char *host_port = NULL;
  570|    657|    size_t count;
  571|    657|    bool needcomma = false;
  572|    657|    char *names = NULL;
  573|       |
  574|    657|    int rc;
  575|       |
  576|    657|    if (session->opts.knownhosts == NULL ||
  ------------------
  |  Branch (576:9): [True: 0, False: 657]
  ------------------
  577|    657|        session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (577:9): [True: 0, False: 657]
  ------------------
  578|      0|        if (ssh_options_apply(session) < 0) {
  ------------------
  |  Branch (578:13): [True: 0, False: 0]
  ------------------
  579|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  580|      0|                          SSH_REQUEST_DENIED,
  581|      0|                          "Can't find a known_hosts file");
  582|       |
  583|      0|            return NULL;
  584|      0|        }
  585|      0|    }
  586|       |
  587|    657|    host_port = ssh_session_get_host_port(session);
  588|    657|    if (host_port == NULL) {
  ------------------
  |  Branch (588:9): [True: 0, False: 657]
  ------------------
  589|      0|        return NULL;
  590|      0|    }
  591|       |
  592|    657|    rc = ssh_known_hosts_read_entries(host_port,
  593|    657|                                      session->opts.knownhosts,
  594|    657|                                      &entry_list);
  595|    657|    if (rc != 0) {
  ------------------
  |  Branch (595:9): [True: 0, False: 657]
  ------------------
  596|      0|        SAFE_FREE(host_port);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  597|      0|        ssh_knownhosts_entries_free(entry_list);
  598|      0|        return NULL;
  599|      0|    }
  600|       |
  601|    657|    rc = ssh_known_hosts_read_entries(host_port,
  602|    657|                                      session->opts.global_knownhosts,
  603|    657|                                      &entry_list);
  604|    657|    SAFE_FREE(host_port);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  605|    657|    if (rc != 0) {
  ------------------
  |  Branch (605:9): [True: 0, False: 657]
  ------------------
  606|      0|        ssh_knownhosts_entries_free(entry_list);
  607|      0|        return NULL;
  608|      0|    }
  609|       |
  610|    657|    if (entry_list == NULL) {
  ------------------
  |  Branch (610:9): [True: 657, False: 0]
  ------------------
  611|    657|        return NULL;
  612|    657|    }
  613|       |
  614|      0|    count = ssh_list_count(entry_list);
  615|      0|    if (count == 0) {
  ------------------
  |  Branch (615:9): [True: 0, False: 0]
  ------------------
  616|      0|        ssh_list_free(entry_list);
  617|      0|        return NULL;
  618|      0|    }
  619|       |
  620|      0|    for (it = ssh_list_get_iterator(entry_list);
  621|      0|         it != NULL;
  ------------------
  |  Branch (621:10): [True: 0, False: 0]
  ------------------
  622|      0|         it = ssh_list_get_iterator(entry_list))
  623|      0|    {
  624|      0|        struct ssh_knownhosts_entry *entry = NULL;
  625|      0|        const char *algo = NULL;
  626|       |
  627|      0|        entry = ssh_iterator_value(struct ssh_knownhosts_entry *, it);
  ------------------
  |  |  114|      0|  ((type)((iterator)->data))
  ------------------
  628|      0|        algo = ssh_known_host_sigs_from_hostkey_type(entry->publickey->type);
  629|      0|        if (algo == NULL) {
  ------------------
  |  Branch (629:13): [True: 0, False: 0]
  ------------------
  630|      0|            ssh_knownhosts_entry_free(entry);
  631|      0|            ssh_list_remove(entry_list, it);
  632|      0|            continue;
  633|      0|        }
  634|       |
  635|      0|        if (needcomma) {
  ------------------
  |  Branch (635:13): [True: 0, False: 0]
  ------------------
  636|      0|            strlcat(methods_buffer, ",", sizeof(methods_buffer));
  637|      0|        }
  638|       |
  639|      0|        strlcat(methods_buffer, algo, sizeof(methods_buffer));
  640|      0|        needcomma = true;
  641|       |
  642|      0|        ssh_knownhosts_entry_free(entry);
  643|      0|        ssh_list_remove(entry_list, it);
  644|      0|    }
  645|       |
  646|      0|    ssh_list_free(entry_list);
  647|       |
  648|      0|    names = ssh_remove_duplicates(methods_buffer);
  649|       |
  650|      0|    return names;
  651|      0|}
knownhosts.c:ssh_session_get_host_port:
  330|    657|{
  331|    657|    char *host_port = NULL;
  332|    657|    char *host = NULL;
  333|       |
  334|    657|    if (session->opts.host == NULL) {
  ------------------
  |  Branch (334:9): [True: 0, False: 657]
  ------------------
  335|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  336|      0|                      SSH_FATAL,
  337|      0|                      "Can't verify server in known hosts if the host we "
  338|      0|                      "should connect to has not been set");
  339|       |
  340|      0|        return NULL;
  341|      0|    }
  342|       |
  343|    657|    host = ssh_lowercase(session->opts.host);
  344|    657|    if (host == NULL) {
  ------------------
  |  Branch (344:9): [True: 0, False: 657]
  ------------------
  345|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  346|      0|        return NULL;
  347|      0|    }
  348|       |
  349|    657|    if (session->opts.port == 0 || session->opts.port == 22) {
  ------------------
  |  Branch (349:9): [True: 0, False: 657]
  |  Branch (349:36): [True: 657, False: 0]
  ------------------
  350|    657|        host_port = host;
  351|    657|    } else {
  352|      0|        host_port = ssh_hostport(host, session->opts.port);
  353|      0|        SAFE_FREE(host);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  354|      0|        if (host_port == NULL) {
  ------------------
  |  Branch (354:13): [True: 0, False: 0]
  ------------------
  355|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  356|      0|            return NULL;
  357|      0|        }
  358|      0|    }
  359|       |
  360|    657|    return host_port;
  361|    657|}
knownhosts.c:ssh_known_hosts_read_entries:
  239|  1.31k|{
  240|  1.31k|    char line[MAX_LINE_SIZE];
  241|  1.31k|    size_t lineno = 0;
  242|  1.31k|    size_t len = 0;
  243|  1.31k|    FILE *fp = NULL;
  244|  1.31k|    int rc;
  245|       |
  246|  1.31k|    fp = ssh_strict_fopen(filename, SSH_MAX_CONFIG_FILE_SIZE);
  ------------------
  |  |  528|  1.31k|#define SSH_MAX_CONFIG_FILE_SIZE 16 * 1024 * 1024
  ------------------
  247|  1.31k|    if (fp == NULL) {
  ------------------
  |  Branch (247:9): [True: 1.31k, False: 0]
  ------------------
  248|  1.31k|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  283|  1.31k|    do {                                                            \
  |  |  284|  1.31k|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|  1.31k|        _ssh_log(priority,                                          \
  |  |  286|  1.31k|                 __func__,                                          \
  |  |  287|  1.31k|                 __VA_ARGS__,                                       \
  |  |  288|  1.31k|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|  1.31k|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|  1.31k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  249|  1.31k|                         errno,
  250|  1.31k|                         "Failed to open the known_hosts file '%s': %s",
  251|  1.31k|                         filename);
  252|       |        /* The missing file is not an error here */
  253|  1.31k|        return SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  254|  1.31k|    }
  255|       |
  256|      0|    if (*entries == NULL) {
  ------------------
  |  Branch (256:9): [True: 0, False: 0]
  ------------------
  257|      0|        *entries = ssh_list_new();
  258|      0|        if (*entries == NULL) {
  ------------------
  |  Branch (258:13): [True: 0, False: 0]
  ------------------
  259|      0|            fclose(fp);
  260|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  261|      0|        }
  262|      0|    }
  263|       |
  264|      0|    for (rc = known_hosts_read_line(fp, line, sizeof(line), &len, &lineno);
  265|      0|         rc == 0;
  ------------------
  |  Branch (265:10): [True: 0, False: 0]
  ------------------
  266|      0|         rc = known_hosts_read_line(fp, line, sizeof(line), &len, &lineno)) {
  267|      0|        struct ssh_knownhosts_entry *entry = NULL;
  268|      0|        struct ssh_iterator *it = NULL;
  269|      0|        char *p = NULL;
  270|       |
  271|      0|        if (line[len] != '\n') {
  ------------------
  |  Branch (271:13): [True: 0, False: 0]
  ------------------
  272|      0|            len = strcspn(line, "\n");
  273|      0|        }
  274|      0|        line[len] = '\0';
  275|       |
  276|       |        /* Skip leading spaces */
  277|      0|        for (p = line; isspace((int)p[0]); p++);
  ------------------
  |  Branch (277:24): [True: 0, False: 0]
  ------------------
  278|       |
  279|       |        /* Skip comments and empty lines */
  280|      0|        if (p[0] == '\0' || p[0] == '#') {
  ------------------
  |  Branch (280:13): [True: 0, False: 0]
  |  Branch (280:29): [True: 0, False: 0]
  ------------------
  281|      0|            continue;
  282|      0|        }
  283|       |
  284|       |        /* Skip lines starting with markers (@cert-authority, @revoked):
  285|       |         * we do not completely support them anyway */
  286|      0|        if (p[0] == '@') {
  ------------------
  |  Branch (286:13): [True: 0, False: 0]
  ------------------
  287|      0|            continue;
  288|      0|        }
  289|       |
  290|      0|        rc = ssh_known_hosts_parse_line(match,
  291|      0|                                        line,
  292|      0|                                        &entry);
  293|      0|        if (rc == SSH_AGAIN) {
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (293:13): [True: 0, False: 0]
  ------------------
  294|      0|            continue;
  295|      0|        } else if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (295:20): [True: 0, False: 0]
  ------------------
  296|      0|            goto error;
  297|      0|        }
  298|       |
  299|       |        /* Check for duplicates */
  300|      0|        for (it = ssh_list_get_iterator(*entries);
  301|      0|             it != NULL;
  ------------------
  |  Branch (301:14): [True: 0, False: 0]
  ------------------
  302|      0|             it = it->next) {
  303|      0|            struct ssh_knownhosts_entry *entry2 = NULL;
  304|      0|            int cmp;
  305|      0|            entry2 = ssh_iterator_value(struct ssh_knownhosts_entry *, it);
  ------------------
  |  |  114|      0|  ((type)((iterator)->data))
  ------------------
  306|      0|            cmp = ssh_known_hosts_entries_compare(entry, entry2);
  307|      0|            if (cmp == 0) {
  ------------------
  |  Branch (307:17): [True: 0, False: 0]
  ------------------
  308|      0|                ssh_knownhosts_entry_free(entry);
  309|      0|                entry = NULL;
  310|      0|                break;
  311|      0|            }
  312|      0|        }
  313|      0|        if (entry != NULL) {
  ------------------
  |  Branch (313:13): [True: 0, False: 0]
  ------------------
  314|      0|            rc = ssh_list_append(*entries, entry);
  315|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (315:17): [True: 0, False: 0]
  ------------------
  316|      0|                ssh_knownhosts_entry_free(entry);
  317|      0|                goto error;
  318|      0|            }
  319|      0|        }
  320|      0|    }
  321|       |
  322|      0|    fclose(fp);
  323|      0|    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  324|      0|error:
  325|      0|    fclose(fp);
  326|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  327|      0|}

ssh_reseed:
   94|    657|void ssh_reseed(void){
   95|    657|#ifndef _WIN32
   96|    657|    struct timeval tv;
   97|       |    gettimeofday(&tv, NULL);
   98|    657|    RAND_add(&tv, sizeof(tv), 0.0);
   99|    657|#endif
  100|    657|}
ssh_kdf:
  337|  7.88k|{
  338|  7.88k|    return sshkdf_derive_key(crypto, key, key_len,
  339|  7.88k|                             key_type, output, requested_len);
  340|  7.88k|}
hmac_init:
  344|  12.5k|{
  345|  12.5k|    HMACCTX ctx = NULL;
  346|  12.5k|    EVP_PKEY *pkey = NULL;
  347|  12.5k|    int rc = -1;
  348|       |
  349|  12.5k|    ctx = EVP_MD_CTX_new();
  350|  12.5k|    if (ctx == NULL) {
  ------------------
  |  Branch (350:9): [True: 0, False: 12.5k]
  ------------------
  351|      0|        return NULL;
  352|      0|    }
  353|       |
  354|  12.5k|    pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, key, (int)len);
  355|  12.5k|    if (pkey == NULL) {
  ------------------
  |  Branch (355:9): [True: 0, False: 12.5k]
  ------------------
  356|      0|        goto error;
  357|      0|    }
  358|       |
  359|  12.5k|    switch (type) {
  360|  9.65k|    case SSH_HMAC_SHA1:
  ------------------
  |  Branch (360:5): [True: 9.65k, False: 2.94k]
  ------------------
  361|  9.65k|        rc = EVP_DigestSignInit(ctx, NULL, EVP_sha1(), NULL, pkey);
  362|  9.65k|        break;
  363|  2.95k|    case SSH_HMAC_SHA256:
  ------------------
  |  Branch (363:5): [True: 2.95k, False: 9.64k]
  ------------------
  364|  2.95k|        rc = EVP_DigestSignInit(ctx, NULL, EVP_sha256(), NULL, pkey);
  365|  2.95k|        break;
  366|      0|    case SSH_HMAC_SHA512:
  ------------------
  |  Branch (366:5): [True: 0, False: 12.5k]
  ------------------
  367|      0|        rc = EVP_DigestSignInit(ctx, NULL, EVP_sha512(), NULL, pkey);
  368|      0|        break;
  369|      0|    case SSH_HMAC_MD5:
  ------------------
  |  Branch (369:5): [True: 0, False: 12.5k]
  ------------------
  370|      0|        rc = EVP_DigestSignInit(ctx, NULL, EVP_md5(), NULL, pkey);
  371|      0|        break;
  372|      0|    default:
  ------------------
  |  Branch (372:5): [True: 0, False: 12.5k]
  ------------------
  373|      0|        rc = -1;
  374|      0|        break;
  375|  12.5k|    }
  376|       |
  377|  12.5k|    EVP_PKEY_free(pkey);
  378|  12.5k|    if (rc != 1) {
  ------------------
  |  Branch (378:9): [True: 0, False: 12.5k]
  ------------------
  379|      0|        goto error;
  380|      0|    }
  381|  12.5k|    return ctx;
  382|       |
  383|      0|error:
  384|      0|    EVP_MD_CTX_free(ctx);
  385|       |    return NULL;
  386|  12.5k|}
hmac_update:
  389|  25.1k|{
  390|       |    return EVP_DigestSignUpdate(ctx, data, len);
  391|  25.1k|}
hmac_final:
  394|  12.5k|{
  395|  12.5k|    size_t res = *len;
  396|  12.5k|    int rc;
  397|  12.5k|    rc = EVP_DigestSignFinal(ctx, hashmacbuf, &res);
  398|  12.5k|    EVP_MD_CTX_free(ctx);
  399|  12.5k|    if (rc == 1) {
  ------------------
  |  Branch (399:9): [True: 12.5k, False: 2]
  ------------------
  400|  12.5k|        *len = res;
  401|  12.5k|    }
  402|       |
  403|  12.5k|    return rc;
  404|  12.5k|}
ssh_get_ciphertab:
 1382|  4.59k|{
 1383|  4.59k|    return ssh_ciphertab;
 1384|  4.59k|}
ssh_crypto_init:
 1391|      2|{
 1392|       |#ifndef HAVE_OPENSSL_EVP_CHACHA20
 1393|       |    size_t i;
 1394|       |#endif
 1395|       |
 1396|      2|    if (libcrypto_initialized) {
  ------------------
  |  Branch (1396:9): [True: 0, False: 2]
  ------------------
 1397|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1398|      0|    }
 1399|      2|    if (OpenSSL_version_num() != OPENSSL_VERSION_NUMBER) {
  ------------------
  |  Branch (1399:9): [True: 0, False: 2]
  ------------------
 1400|      0|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1401|      0|                "libssh compiled with %s "
 1402|      0|                "headers, currently running with %s.",
 1403|      0|                OPENSSL_VERSION_TEXT,
 1404|      0|                OpenSSL_version(OpenSSL_version_num()));
 1405|      0|    }
 1406|       |#ifdef CAN_DISABLE_AESNI
 1407|       |    /*
 1408|       |     * disable AES-NI when running within Valgrind, because they generate
 1409|       |     * too many "uninitialized memory access" false positives
 1410|       |     */
 1411|       |    if (RUNNING_ON_VALGRIND) {
 1412|       |        SSH_LOG(SSH_LOG_INFO, "Running within Valgrind, disabling AES-NI");
 1413|       |        /* Bit #57 denotes AES-NI instruction set extension */
 1414|       |        OPENSSL_ia32cap &= ~(1LL << 57);
 1415|       |    }
 1416|       |#endif /* CAN_DISABLE_AESNI */
 1417|       |
 1418|       |#ifndef HAVE_OPENSSL_EVP_CHACHA20
 1419|       |    for (i = 0; ssh_ciphertab[i].name != NULL; i++) {
 1420|       |        int cmp;
 1421|       |
 1422|       |        cmp = strcmp(ssh_ciphertab[i].name, "chacha20-poly1305@openssh.com");
 1423|       |        if (cmp == 0) {
 1424|       |            memcpy(&ssh_ciphertab[i],
 1425|       |                   ssh_get_chacha20poly1305_cipher(),
 1426|       |                   sizeof(struct ssh_cipher_struct));
 1427|       |            break;
 1428|       |        }
 1429|       |    }
 1430|       |#endif /* HAVE_OPENSSL_EVP_CHACHA20 */
 1431|       |
 1432|      2|    libcrypto_initialized = 1;
 1433|       |
 1434|      2|    return SSH_OK;
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
 1435|      2|}
libcrypto.c:evp_cipher_set_encrypt_key:
  459|  1.13k|{
  460|  1.13k|    int rc;
  461|       |
  462|  1.13k|    evp_cipher_init(cipher);
  463|       |
  464|  1.13k|    rc = EVP_EncryptInit_ex(cipher->ctx, cipher->cipher, NULL, key, IV);
  465|  1.13k|    if (rc != 1){
  ------------------
  |  Branch (465:9): [True: 0, False: 1.13k]
  ------------------
  466|      0|        SSH_LOG(SSH_LOG_TRACE, "EVP_EncryptInit_ex failed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  467|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  468|      0|    }
  469|       |
  470|       |    /* For AES-GCM we need to set IV in specific way */
  471|  1.13k|    if (cipher->ciphertype == SSH_AEAD_AES128_GCM ||
  ------------------
  |  Branch (471:9): [True: 0, False: 1.13k]
  ------------------
  472|  1.13k|        cipher->ciphertype == SSH_AEAD_AES256_GCM) {
  ------------------
  |  Branch (472:9): [True: 0, False: 1.13k]
  ------------------
  473|      0|        rc = EVP_CIPHER_CTX_ctrl(cipher->ctx,
  474|      0|                                 EVP_CTRL_GCM_SET_IV_FIXED,
  475|      0|                                 -1,
  476|      0|                                 (uint8_t *)IV);
  477|      0|        if (rc != 1) {
  ------------------
  |  Branch (477:13): [True: 0, False: 0]
  ------------------
  478|      0|            SSH_LOG(SSH_LOG_TRACE, "EVP_CTRL_GCM_SET_IV_FIXED failed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  479|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  480|      0|        }
  481|      0|    }
  482|       |
  483|  1.13k|    EVP_CIPHER_CTX_set_padding(cipher->ctx, 0);
  484|       |
  485|  1.13k|    return SSH_OK;
  ------------------
  |  |  316|  1.13k|#define SSH_OK 0     /* No error */
  ------------------
  486|  1.13k|}
libcrypto.c:evp_cipher_init:
  407|  2.26k|{
  408|  2.26k|    if (cipher->ctx == NULL) {
  ------------------
  |  Branch (408:9): [True: 2.26k, False: 0]
  ------------------
  409|  2.26k|        cipher->ctx = EVP_CIPHER_CTX_new();
  410|  2.26k|    } else {
  411|      0|        EVP_CIPHER_CTX_reset(cipher->ctx);
  412|      0|    }
  413|       |
  414|  2.26k|    switch(cipher->ciphertype){
  ------------------
  |  Branch (414:12): [True: 2.26k, False: 0]
  ------------------
  415|  1.80k|    case SSH_AES128_CBC:
  ------------------
  |  Branch (415:5): [True: 1.80k, False: 464]
  ------------------
  416|  1.80k|        cipher->cipher = EVP_aes_128_cbc();
  417|  1.80k|        break;
  418|      0|    case SSH_AES192_CBC:
  ------------------
  |  Branch (418:5): [True: 0, False: 2.26k]
  ------------------
  419|      0|        cipher->cipher = EVP_aes_192_cbc();
  420|      0|        break;
  421|      0|    case SSH_AES256_CBC:
  ------------------
  |  Branch (421:5): [True: 0, False: 2.26k]
  ------------------
  422|      0|        cipher->cipher = EVP_aes_256_cbc();
  423|      0|        break;
  424|    164|    case SSH_AES128_CTR:
  ------------------
  |  Branch (424:5): [True: 164, False: 2.10k]
  ------------------
  425|    164|        cipher->cipher = EVP_aes_128_ctr();
  426|    164|        break;
  427|      0|    case SSH_AES192_CTR:
  ------------------
  |  Branch (427:5): [True: 0, False: 2.26k]
  ------------------
  428|      0|        cipher->cipher = EVP_aes_192_ctr();
  429|      0|        break;
  430|    300|    case SSH_AES256_CTR:
  ------------------
  |  Branch (430:5): [True: 300, False: 1.96k]
  ------------------
  431|    300|        cipher->cipher = EVP_aes_256_ctr();
  432|    300|        break;
  433|      0|    case SSH_AEAD_AES128_GCM:
  ------------------
  |  Branch (433:5): [True: 0, False: 2.26k]
  ------------------
  434|      0|        cipher->cipher = EVP_aes_128_gcm();
  435|      0|        break;
  436|      0|    case SSH_AEAD_AES256_GCM:
  ------------------
  |  Branch (436:5): [True: 0, False: 2.26k]
  ------------------
  437|      0|        cipher->cipher = EVP_aes_256_gcm();
  438|      0|        break;
  439|      0|    case SSH_3DES_CBC:
  ------------------
  |  Branch (439:5): [True: 0, False: 2.26k]
  ------------------
  440|      0|        cipher->cipher = EVP_des_ede3_cbc();
  441|      0|        break;
  442|       |#ifdef HAVE_BLOWFISH
  443|       |    case SSH_BLOWFISH_CBC:
  444|       |        cipher->cipher = EVP_bf_cbc();
  445|       |        break;
  446|       |        /* ciphers not using EVP */
  447|       |#endif /* HAVE_BLOWFISH */
  448|      0|    case SSH_AEAD_CHACHA20_POLY1305:
  ------------------
  |  Branch (448:5): [True: 0, False: 2.26k]
  ------------------
  449|      0|        SSH_LOG(SSH_LOG_TRACE, "The ChaCha cipher cannot be handled here");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  450|      0|        break;
  451|      0|    case SSH_NO_CIPHER:
  ------------------
  |  Branch (451:5): [True: 0, False: 2.26k]
  ------------------
  452|      0|        SSH_LOG(SSH_LOG_TRACE, "No valid ciphertype found");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  453|      0|        break;
  454|  2.26k|    }
  455|  2.26k|}
libcrypto.c:evp_cipher_set_decrypt_key:
  489|  1.13k|            void *key, void *IV) {
  490|  1.13k|    int rc;
  491|       |
  492|  1.13k|    evp_cipher_init(cipher);
  493|       |
  494|  1.13k|    rc = EVP_DecryptInit_ex(cipher->ctx, cipher->cipher, NULL, key, IV);
  495|  1.13k|    if (rc != 1){
  ------------------
  |  Branch (495:9): [True: 0, False: 1.13k]
  ------------------
  496|      0|        SSH_LOG(SSH_LOG_TRACE, "EVP_DecryptInit_ex failed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  497|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  498|      0|    }
  499|       |
  500|       |    /* For AES-GCM we need to set IV in specific way */
  501|  1.13k|    if (cipher->ciphertype == SSH_AEAD_AES128_GCM ||
  ------------------
  |  Branch (501:9): [True: 0, False: 1.13k]
  ------------------
  502|  1.13k|        cipher->ciphertype == SSH_AEAD_AES256_GCM) {
  ------------------
  |  Branch (502:9): [True: 0, False: 1.13k]
  ------------------
  503|      0|        rc = EVP_CIPHER_CTX_ctrl(cipher->ctx,
  504|      0|                                 EVP_CTRL_GCM_SET_IV_FIXED,
  505|      0|                                 -1,
  506|      0|                                 (uint8_t *)IV);
  507|      0|        if (rc != 1) {
  ------------------
  |  Branch (507:13): [True: 0, False: 0]
  ------------------
  508|      0|            SSH_LOG(SSH_LOG_TRACE, "EVP_CTRL_GCM_SET_IV_FIXED failed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  509|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  510|      0|        }
  511|      0|    }
  512|       |
  513|  1.13k|    EVP_CIPHER_CTX_set_padding(cipher->ctx, 0);
  514|       |
  515|  1.13k|    return SSH_OK;
  ------------------
  |  |  316|  1.13k|#define SSH_OK 0     /* No error */
  ------------------
  516|  1.13k|}
libcrypto.c:evp_cipher_encrypt:
  523|  7.92k|{
  524|  7.92k|    int outlen = 0;
  525|  7.92k|    int rc = 0;
  526|       |
  527|  7.92k|    rc = EVP_EncryptUpdate(cipher->ctx,
  528|  7.92k|                           (unsigned char *)out,
  529|  7.92k|                           &outlen,
  530|  7.92k|                           (unsigned char *)in,
  531|  7.92k|                           (int)len);
  532|  7.92k|    if (rc != 1){
  ------------------
  |  Branch (532:9): [True: 0, False: 7.92k]
  ------------------
  533|      0|        SSH_LOG(SSH_LOG_TRACE, "EVP_EncryptUpdate failed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  534|      0|        return;
  535|      0|    }
  536|  7.92k|    if (outlen != (int)len){
  ------------------
  |  Branch (536:9): [True: 0, False: 7.92k]
  ------------------
  537|      0|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  538|      0|                "EVP_EncryptUpdate: output size %d for %zu in",
  539|      0|                outlen,
  540|      0|                len);
  541|      0|        return;
  542|      0|    }
  543|  7.92k|}
libcrypto.c:evp_cipher_decrypt:
  549|  10.7k|{
  550|  10.7k|    int outlen = 0;
  551|  10.7k|    int rc = 0;
  552|       |
  553|  10.7k|    rc = EVP_DecryptUpdate(cipher->ctx,
  554|  10.7k|                           (unsigned char *)out,
  555|  10.7k|                           &outlen,
  556|  10.7k|                           (unsigned char *)in,
  557|  10.7k|                           (int)len);
  558|  10.7k|    if (rc != 1){
  ------------------
  |  Branch (558:9): [True: 0, False: 10.7k]
  ------------------
  559|      0|        SSH_LOG(SSH_LOG_TRACE, "EVP_DecryptUpdate failed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  560|      0|        return;
  561|      0|    }
  562|  10.7k|    if (outlen != (int)len){
  ------------------
  |  Branch (562:9): [True: 0, False: 10.7k]
  ------------------
  563|      0|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  564|      0|                "EVP_DecryptUpdate: output size %d for %zu in",
  565|      0|                outlen,
  566|      0|                len);
  567|      0|        return;
  568|      0|    }
  569|  10.7k|}
libcrypto.c:evp_cipher_cleanup:
  571|  2.26k|static void evp_cipher_cleanup(struct ssh_cipher_struct *cipher) {
  572|  2.26k|    if (cipher->ctx != NULL) {
  ------------------
  |  Branch (572:9): [True: 2.26k, False: 0]
  ------------------
  573|  2.26k|        EVP_CIPHER_CTX_free(cipher->ctx);
  574|  2.26k|    }
  575|  2.26k|}
libcrypto.c:none_crypt:
 1217|  3.27k|{
 1218|  3.27k|    memcpy(out, in, len);
 1219|  3.27k|}

_ssh_log:
  168|   229k|{
  169|   229k|    va_list va;
  170|       |
  171|   229k|    if (verbosity <= ssh_get_log_level()) {
  ------------------
  |  Branch (171:9): [True: 0, False: 229k]
  ------------------
  172|      0|        va_start(va, format);
  173|      0|        ssh_vlog(verbosity, function, format, &va);
  174|       |        va_end(va);
  175|      0|    }
  176|   229k|}
ssh_get_log_level:
  252|   231k|int ssh_get_log_level(void) {
  253|   231k|  return ssh_log_level;
  254|   231k|}
ssh_get_log_callback:
  275|  1.31k|ssh_logging_callback ssh_get_log_callback(void) {
  276|  1.31k|  return ssh_log_cb;
  277|  1.31k|}

match_group:
  589|  4.58k|{
  590|  4.58k|    const char *a = NULL;
  591|  4.58k|    const char *z = NULL;
  592|       |
  593|  4.58k|    if (group == NULL || object == NULL) {
  ------------------
  |  Branch (593:9): [True: 18.4E, False: 4.58k]
  |  Branch (593:26): [True: 0, False: 4.58k]
  ------------------
  594|      0|        return 0;
  595|      0|    }
  596|       |
  597|  4.58k|    z = group;
  598|  53.9k|    do {
  599|  53.9k|        a = strchr(z, ',');
  600|  53.9k|        if (a == NULL) {
  ------------------
  |  Branch (600:13): [True: 2.62k, False: 51.3k]
  ------------------
  601|  2.62k|            if (strcmp(z, object) == 0) {
  ------------------
  |  Branch (601:17): [True: 2.62k, False: 1]
  ------------------
  602|  2.62k|                return 1;
  603|  2.62k|            }
  604|      1|            return 0;
  605|  51.3k|        } else {
  606|  51.3k|            if (strncmp(z, object, a - z) == 0) {
  ------------------
  |  Branch (606:17): [True: 1.97k, False: 49.3k]
  ------------------
  607|  1.97k|                return 1;
  608|  1.97k|            }
  609|  51.3k|        }
  610|  49.3k|        z = a + 1;
  611|  49.3k|    } while (1);
  ------------------
  |  Branch (611:14): [True: 49.3k, Folded]
  ------------------
  612|       |
  613|       |    /* not reached */
  614|  18.4E|    return 0;
  615|  4.58k|}

sha256_init:
   97|  10.5k|{
   98|  10.5k|    int rc;
   99|  10.5k|    SHA256CTX c = EVP_MD_CTX_new();
  100|  10.5k|    if (c == NULL) {
  ------------------
  |  Branch (100:9): [True: 0, False: 10.5k]
  ------------------
  101|      0|        return NULL;
  102|      0|    }
  103|  10.5k|    rc = EVP_DigestInit_ex(c, EVP_sha256(), NULL);
  104|  10.5k|    if (rc == 0) {
  ------------------
  |  Branch (104:9): [True: 0, False: 10.5k]
  ------------------
  105|      0|        EVP_MD_CTX_free(c);
  106|       |        c = NULL;
  107|      0|    }
  108|  10.5k|    return c;
  109|  10.5k|}
sha256_update:
  119|  34.1k|{
  120|  34.1k|    int rc = EVP_DigestUpdate(c, data, len);
  121|  34.1k|    if (rc != 1) {
  ------------------
  |  Branch (121:9): [True: 0, False: 34.1k]
  ------------------
  122|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  123|      0|    }
  124|  34.1k|    return SSH_OK;
  ------------------
  |  |  316|  34.1k|#define SSH_OK 0     /* No error */
  ------------------
  125|  34.1k|}
sha256_final:
  129|  10.5k|{
  130|  10.5k|    unsigned int mdlen = 0;
  131|  10.5k|    int rc = EVP_DigestFinal(c, md, &mdlen);
  132|       |
  133|  10.5k|    EVP_MD_CTX_free(c);
  134|  10.5k|    if (rc != 1) {
  ------------------
  |  Branch (134:9): [True: 0, False: 10.5k]
  ------------------
  135|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  136|      0|    }
  137|  10.5k|    return SSH_OK;
  ------------------
  |  |  316|  10.5k|#define SSH_OK 0     /* No error */
  ------------------
  138|  10.5k|}
sha256:
  142|  2.62k|{
  143|  2.62k|    SHA256CTX c = sha256_init();
  144|  2.62k|    int rc;
  145|       |
  146|  2.62k|    if (c == NULL) {
  ------------------
  |  Branch (146:9): [True: 0, False: 2.62k]
  ------------------
  147|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  148|      0|    }
  149|  2.62k|    rc = sha256_update(c, digest, len);
  150|  2.62k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  2.62k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (150:9): [True: 0, False: 2.62k]
  ------------------
  151|      0|        EVP_MD_CTX_free(c);
  152|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  153|      0|    }
  154|  2.62k|    return sha256_final(hash, c);
  155|  2.62k|}

ssh_message_free:
  676|  2.62k|void ssh_message_free(ssh_message msg){
  677|  2.62k|  if (msg == NULL) {
  ------------------
  |  Branch (677:7): [True: 0, False: 2.62k]
  ------------------
  678|      0|    return;
  679|      0|  }
  680|       |
  681|  2.62k|  switch(msg->type) {
  ------------------
  |  Branch (681:10): [True: 2.62k, False: 0]
  ------------------
  682|    657|    case SSH_REQUEST_AUTH:
  ------------------
  |  Branch (682:5): [True: 657, False: 1.97k]
  ------------------
  683|    657|      SAFE_FREE(msg->auth_request.username);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  684|    657|      SAFE_FREE(msg->auth_request.sigtype);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  685|    657|      if (msg->auth_request.password) {
  ------------------
  |  Branch (685:11): [True: 0, False: 657]
  ------------------
  686|      0|          ssh_burn(msg->auth_request.password,
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  687|      0|                   strlen(msg->auth_request.password));
  688|      0|          SAFE_FREE(msg->auth_request.password);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  689|      0|      }
  690|    657|      ssh_key_free(msg->auth_request.pubkey);
  691|    657|      ssh_key_free(msg->auth_request.server_pubkey);
  692|    657|      break;
  693|    657|    case SSH_REQUEST_CHANNEL_OPEN:
  ------------------
  |  Branch (693:5): [True: 657, False: 1.97k]
  ------------------
  694|    657|      SAFE_FREE(msg->channel_request_open.originator);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  695|    657|      SAFE_FREE(msg->channel_request_open.destination);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  696|    657|      break;
  697|    657|    case SSH_REQUEST_CHANNEL:
  ------------------
  |  Branch (697:5): [True: 657, False: 1.97k]
  ------------------
  698|    657|      SAFE_FREE(msg->channel_request.TERM);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  699|    657|      SAFE_FREE(msg->channel_request.modes);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  700|    657|      SAFE_FREE(msg->channel_request.var_name);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  701|    657|      SAFE_FREE(msg->channel_request.var_value);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  702|    657|      SAFE_FREE(msg->channel_request.command);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  703|    657|      SAFE_FREE(msg->channel_request.subsystem);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  704|    657|      switch (msg->channel_request.type) {
  ------------------
  |  Branch (704:15): [True: 657, False: 0]
  ------------------
  705|    657|      case SSH_CHANNEL_REQUEST_EXEC:
  ------------------
  |  Branch (705:7): [True: 657, False: 0]
  ------------------
  706|    657|          SAFE_FREE(msg->channel_request.command);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  707|    657|          break;
  708|      0|      case SSH_CHANNEL_REQUEST_ENV:
  ------------------
  |  Branch (708:7): [True: 0, False: 657]
  ------------------
  709|      0|          SAFE_FREE(msg->channel_request.var_name);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  710|      0|          SAFE_FREE(msg->channel_request.var_value);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  711|      0|          break;
  712|      0|      case SSH_CHANNEL_REQUEST_PTY:
  ------------------
  |  Branch (712:7): [True: 0, False: 657]
  ------------------
  713|      0|          SAFE_FREE(msg->channel_request.TERM);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  714|      0|          break;
  715|      0|      case SSH_CHANNEL_REQUEST_SUBSYSTEM:
  ------------------
  |  Branch (715:7): [True: 0, False: 657]
  ------------------
  716|      0|          SAFE_FREE(msg->channel_request.subsystem);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  717|      0|          break;
  718|      0|      case SSH_CHANNEL_REQUEST_X11:
  ------------------
  |  Branch (718:7): [True: 0, False: 657]
  ------------------
  719|      0|          SAFE_FREE(msg->channel_request.x11_auth_protocol);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  720|      0|          SAFE_FREE(msg->channel_request.x11_auth_cookie);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  721|      0|          break;
  722|    657|      }
  723|    657|      break;
  724|    657|    case SSH_REQUEST_SERVICE:
  ------------------
  |  Branch (724:5): [True: 657, False: 1.97k]
  ------------------
  725|    657|      SAFE_FREE(msg->service_request.service);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  726|    657|      break;
  727|      0|    case SSH_REQUEST_GLOBAL:
  ------------------
  |  Branch (727:5): [True: 0, False: 2.62k]
  ------------------
  728|      0|      SAFE_FREE(msg->global_request.bind_address);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  729|      0|      break;
  730|  2.62k|  }
  731|  2.62k|  ZERO_STRUCTP(msg);
  ------------------
  |  |  379|  2.62k|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (379:34): [True: 2.62k, False: 0]
  |  |  |  Branch (379:85): [Folded, False: 2.62k]
  |  |  ------------------
  ------------------
  732|       |  SAFE_FREE(msg);
  ------------------
  |  |  373|  2.62k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.62k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.62k]
  |  |  ------------------
  ------------------
  733|  2.62k|}
ssh_packet_service_request:
  738|    657|{
  739|    657|    char *service_c = NULL;
  740|    657|    ssh_message msg = NULL;
  741|    657|    int rc;
  742|       |
  743|    657|    (void)type;
  744|    657|    (void)user;
  745|       |
  746|    657|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|    657|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  747|    657|                           "s",
  748|    657|                           &service_c);
  749|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (749:9): [True: 0, False: 657]
  ------------------
  750|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  751|      0|                      SSH_FATAL,
  752|      0|                      "Invalid SSH_MSG_SERVICE_REQUEST packet");
  753|      0|        goto error;
  754|      0|    }
  755|       |
  756|    657|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  757|    657|            "Received a SERVICE_REQUEST for service %s",
  758|    657|            service_c);
  759|       |
  760|    657|    msg = ssh_message_new(session);
  761|    657|    if (msg == NULL) {
  ------------------
  |  Branch (761:9): [True: 0, False: 657]
  ------------------
  762|      0|        SAFE_FREE(service_c);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  763|      0|        goto error;
  764|      0|    }
  765|       |
  766|    657|    msg->type = SSH_REQUEST_SERVICE;
  767|    657|    msg->service_request.service = service_c;
  768|       |
  769|    657|    ssh_message_queue(session, msg);
  770|    657|error:
  771|       |
  772|    657|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
  773|    657|}
ssh_packet_userauth_request:
  855|    657|{
  856|    657|    ssh_message msg = NULL;
  857|    657|    ssh_signature sig = NULL;
  858|    657|    char *service = NULL;
  859|    657|    char *method = NULL;
  860|    657|    int cmp;
  861|    657|    int rc;
  862|       |
  863|    657|    (void)user;
  864|    657|    (void)type;
  865|       |
  866|    657|    msg = ssh_message_new(session);
  867|    657|    if (msg == NULL) {
  ------------------
  |  Branch (867:9): [True: 0, False: 657]
  ------------------
  868|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  869|      0|        goto error;
  870|      0|    }
  871|    657|    msg->type = SSH_REQUEST_AUTH;
  872|    657|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|    657|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  873|    657|                           "sss",
  874|    657|                           &msg->auth_request.username,
  875|    657|                           &service,
  876|    657|                           &method);
  877|       |
  878|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (878:9): [True: 0, False: 657]
  ------------------
  879|      0|        goto error;
  880|      0|    }
  881|       |
  882|    657|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  883|    657|            "Auth request for service %s, method %s for user '%s'",
  884|    657|            service,
  885|    657|            method,
  886|    657|            msg->auth_request.username);
  887|       |
  888|    657|    cmp = strcmp(service, "ssh-connection");
  889|    657|    if (cmp != 0) {
  ------------------
  |  Branch (889:9): [True: 0, False: 657]
  ------------------
  890|      0|        SSH_LOG(SSH_LOG_TRACE, "Invalid service request: %s", service);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  891|      0|        goto end;
  892|      0|    }
  893|       |
  894|    657|    if (strcmp(method, "none") == 0) {
  ------------------
  |  Branch (894:9): [True: 657, False: 0]
  ------------------
  895|    657|        msg->auth_request.method = SSH_AUTH_METHOD_NONE;
  ------------------
  |  |  156|    657|#define SSH_AUTH_METHOD_NONE         0x0001u
  ------------------
  896|    657|        goto end;
  897|    657|    }
  898|       |
  899|      0|    if (strcmp(method, "password") == 0) {
  ------------------
  |  Branch (899:9): [True: 0, False: 0]
  ------------------
  900|      0|        uint8_t tmp;
  901|       |
  902|      0|        msg->auth_request.method = SSH_AUTH_METHOD_PASSWORD;
  ------------------
  |  |  157|      0|#define SSH_AUTH_METHOD_PASSWORD     0x0002u
  ------------------
  903|      0|        rc = ssh_buffer_unpack(packet, "bs", &tmp, &msg->auth_request.password);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  904|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (904:13): [True: 0, False: 0]
  ------------------
  905|      0|            goto error;
  906|      0|        }
  907|      0|        goto end;
  908|      0|    }
  909|       |
  910|      0|    if (strcmp(method, "keyboard-interactive") == 0) {
  ------------------
  |  Branch (910:9): [True: 0, False: 0]
  ------------------
  911|      0|        ssh_string lang = NULL;
  912|      0|        ssh_string submethods = NULL;
  913|       |
  914|      0|        msg->auth_request.method = SSH_AUTH_METHOD_INTERACTIVE;
  ------------------
  |  |  160|      0|#define SSH_AUTH_METHOD_INTERACTIVE  0x0010u
  ------------------
  915|      0|        lang = ssh_buffer_get_ssh_string(packet);
  916|      0|        if (lang == NULL) {
  ------------------
  |  Branch (916:13): [True: 0, False: 0]
  ------------------
  917|      0|            goto error;
  918|      0|        }
  919|       |        /* from the RFC 4256
  920|       |         * 3.1.  Initial Exchange
  921|       |         * "The language tag is deprecated and SHOULD be the empty string."
  922|       |         */
  923|      0|        SSH_STRING_FREE(lang);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  924|       |
  925|      0|        submethods = ssh_buffer_get_ssh_string(packet);
  926|      0|        if (submethods == NULL) {
  ------------------
  |  Branch (926:13): [True: 0, False: 0]
  ------------------
  927|      0|            goto error;
  928|      0|        }
  929|       |        /* from the RFC 4256
  930|       |         * 3.1.  Initial Exchange
  931|       |         * "One possible implementation strategy of the submethods field on the
  932|       |         *  server is that, unless the user may use multiple different
  933|       |         *  submethods, the server ignores this field."
  934|       |         */
  935|      0|        SSH_STRING_FREE(submethods);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  936|       |
  937|      0|        goto end;
  938|      0|    }
  939|       |
  940|      0|    if (strcmp(method, "publickey") == 0 ||
  ------------------
  |  Branch (940:9): [True: 0, False: 0]
  ------------------
  941|      0|        strcmp(method, "publickey-hostbound-v00@openssh.com") == 0) {
  ------------------
  |  Branch (941:9): [True: 0, False: 0]
  ------------------
  942|      0|        ssh_string algo = NULL;
  943|      0|        ssh_string pubkey_blob = NULL;
  944|      0|        ssh_string server_pubkey_blob = NULL;
  945|      0|        uint8_t has_sign;
  946|       |
  947|      0|        msg->auth_request.method = SSH_AUTH_METHOD_PUBLICKEY;
  ------------------
  |  |  158|      0|#define SSH_AUTH_METHOD_PUBLICKEY    0x0004u
  ------------------
  948|       |
  949|      0|        rc = ssh_buffer_unpack(packet, "bSS", &has_sign, &algo, &pubkey_blob);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  950|       |
  951|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (951:13): [True: 0, False: 0]
  ------------------
  952|      0|            goto error;
  953|      0|        }
  954|       |
  955|      0|        cmp = strcmp(method, "publickey-hostbound-v00@openssh.com");
  956|      0|        if (cmp == 0) {
  ------------------
  |  Branch (956:13): [True: 0, False: 0]
  ------------------
  957|      0|            server_pubkey_blob = ssh_buffer_get_ssh_string(packet);
  958|      0|            if (server_pubkey_blob == NULL) {
  ------------------
  |  Branch (958:17): [True: 0, False: 0]
  ------------------
  959|      0|                SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  960|      0|                SSH_STRING_FREE(algo);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  961|      0|                goto error;
  962|      0|            }
  963|       |
  964|      0|            rc = ssh_pki_import_pubkey_blob(server_pubkey_blob,
  965|      0|                                            &msg->auth_request.server_pubkey);
  966|      0|            SSH_STRING_FREE(server_pubkey_blob);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  967|       |
  968|      0|            if (rc < 0) {
  ------------------
  |  Branch (968:17): [True: 0, False: 0]
  ------------------
  969|      0|                SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  970|      0|                SSH_STRING_FREE(algo);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  971|      0|                goto error;
  972|      0|            }
  973|      0|        }
  974|       |
  975|      0|        rc = ssh_pki_import_pubkey_blob(pubkey_blob, &msg->auth_request.pubkey);
  976|      0|        SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  977|      0|        pubkey_blob = NULL;
  978|      0|        if (rc < 0) {
  ------------------
  |  Branch (978:13): [True: 0, False: 0]
  ------------------
  979|      0|            SSH_STRING_FREE(algo);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  980|      0|            algo = NULL;
  981|      0|            goto error;
  982|      0|        }
  983|      0|        msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_NONE;
  984|      0|        msg->auth_request.sigtype = strdup(ssh_string_get_char(algo));
  985|      0|        if (msg->auth_request.sigtype == NULL) {
  ------------------
  |  Branch (985:13): [True: 0, False: 0]
  ------------------
  986|      0|            msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_ERROR;
  987|      0|            SSH_STRING_FREE(algo);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  988|      0|            algo = NULL;
  989|      0|            goto error;
  990|      0|        }
  991|       |
  992|       |        // has a valid signature ?
  993|      0|        if (has_sign) {
  ------------------
  |  Branch (993:13): [True: 0, False: 0]
  ------------------
  994|      0|            ssh_string sig_blob = NULL;
  995|      0|            ssh_buffer digest = NULL;
  996|       |
  997|      0|            sig_blob = ssh_buffer_get_ssh_string(packet);
  998|      0|            if (sig_blob == NULL) {
  ------------------
  |  Branch (998:17): [True: 0, False: 0]
  ------------------
  999|      0|                SSH_LOG(SSH_LOG_PACKET, "Invalid signature packet from peer");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1000|      0|                msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_ERROR;
 1001|      0|                SSH_STRING_FREE(algo);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1002|      0|                algo = NULL;
 1003|      0|                goto error;
 1004|      0|            }
 1005|       |
 1006|      0|            digest = ssh_msg_userauth_build_digest(session,
 1007|      0|                                                   msg,
 1008|      0|                                                   service,
 1009|      0|                                                   algo,
 1010|      0|                                                   method);
 1011|      0|            SSH_STRING_FREE(algo);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1012|      0|            algo = NULL;
 1013|      0|            if (digest == NULL) {
  ------------------
  |  Branch (1013:17): [True: 0, False: 0]
  ------------------
 1014|      0|                SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1015|      0|                SSH_LOG(SSH_LOG_PACKET, "Failed to get digest");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1016|      0|                msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_WRONG;
 1017|      0|                goto error;
 1018|      0|            }
 1019|       |
 1020|      0|            rc = ssh_pki_import_signature_blob(sig_blob,
 1021|      0|                                               msg->auth_request.pubkey,
 1022|      0|                                               &sig);
 1023|      0|            if (rc == SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1023:17): [True: 0, False: 0]
  ------------------
 1024|       |                /* Check if the signature from client matches server preferences
 1025|       |                 */
 1026|      0|                if (session->opts.pubkey_accepted_types) {
  ------------------
  |  Branch (1026:21): [True: 0, False: 0]
  ------------------
 1027|      0|                    cmp = match_group(session->opts.pubkey_accepted_types,
 1028|      0|                                      sig->type_c);
 1029|      0|                    if (cmp != 1) {
  ------------------
  |  Branch (1029:25): [True: 0, False: 0]
  ------------------
 1030|      0|                        ssh_set_error(
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1031|      0|                            session,
 1032|      0|                            SSH_FATAL,
 1033|      0|                            "Public key from client (%s) doesn't match server "
 1034|      0|                            "preference (%s)",
 1035|      0|                            sig->type_c,
 1036|      0|                            session->opts.pubkey_accepted_types);
 1037|      0|                        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1038|      0|                    }
 1039|      0|                }
 1040|       |
 1041|      0|                if (rc == SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1041:21): [True: 0, False: 0]
  ------------------
 1042|      0|                    rc = ssh_pki_signature_verify(session,
 1043|      0|                                                  sig,
 1044|      0|                                                  msg->auth_request.pubkey,
 1045|      0|                                                  ssh_buffer_get(digest),
 1046|      0|                                                  ssh_buffer_get_len(digest));
 1047|      0|                }
 1048|      0|            }
 1049|      0|            SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1050|      0|            SSH_BUFFER_FREE(digest);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1051|      0|            ssh_signature_free(sig);
 1052|      0|            if (rc < 0) {
  ------------------
  |  Branch (1052:17): [True: 0, False: 0]
  ------------------
 1053|      0|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1054|      0|                        "Received an invalid signature from peer");
 1055|      0|                msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_WRONG;
 1056|      0|                goto error;
 1057|      0|            }
 1058|       |
 1059|      0|            SSH_LOG(SSH_LOG_PACKET, "Valid signature received");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1060|       |
 1061|      0|            cmp = strcmp(method, "publickey-hostbound-v00@openssh.com");
 1062|      0|            if (cmp == 0) {
  ------------------
  |  Branch (1062:17): [True: 0, False: 0]
  ------------------
 1063|      0|                ssh_key server_key = NULL;
 1064|       |
 1065|      0|                if (msg->auth_request.server_pubkey == NULL) {
  ------------------
  |  Branch (1065:21): [True: 0, False: 0]
  ------------------
 1066|      0|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1067|      0|                            "Server public key not provided by client");
 1068|      0|                    msg->auth_request.signature_state =
 1069|      0|                        SSH_PUBLICKEY_STATE_WRONG;
 1070|      0|                    goto error;
 1071|      0|                }
 1072|       |
 1073|      0|                rc = ssh_get_server_publickey(session, &server_key);
 1074|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1074:21): [True: 0, False: 0]
  ------------------
 1075|      0|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1076|      0|                            "Failed to get server public key for hostbound "
 1077|      0|                            "verification");
 1078|      0|                    msg->auth_request.signature_state =
 1079|      0|                        SSH_PUBLICKEY_STATE_ERROR;
 1080|      0|                    ssh_key_free(server_key);
 1081|      0|                    goto error;
 1082|      0|                }
 1083|       |
 1084|      0|                if (ssh_key_cmp(server_key,
  ------------------
  |  Branch (1084:21): [True: 0, False: 0]
  ------------------
 1085|      0|                                msg->auth_request.server_pubkey,
 1086|      0|                                SSH_KEY_CMP_PUBLIC) != 0) {
 1087|      0|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1088|      0|                            "Server public key doesn't match the one provided "
 1089|      0|                            "by client");
 1090|      0|                    msg->auth_request.signature_state =
 1091|      0|                        SSH_PUBLICKEY_STATE_WRONG;
 1092|      0|                    ssh_key_free(server_key);
 1093|      0|                    goto error;
 1094|      0|                }
 1095|      0|                ssh_key_free(server_key);
 1096|      0|            }
 1097|       |
 1098|      0|            msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_VALID;
 1099|      0|        }
 1100|       |
 1101|      0|        SAFE_FREE(method);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1102|      0|        SSH_STRING_FREE(algo);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1103|      0|        goto end;
 1104|      0|    }
 1105|       |#ifdef WITH_GSSAPI
 1106|       |    if (strcmp(method, "gssapi-with-mic") == 0) {
 1107|       |        uint32_t n_oid;
 1108|       |        ssh_string *oids = NULL;
 1109|       |        ssh_string oid = NULL;
 1110|       |        char *hexa = NULL;
 1111|       |        int i;
 1112|       |        ssh_buffer_get_u32(packet, &n_oid);
 1113|       |        n_oid = ntohl(n_oid);
 1114|       |        if (n_oid > 100) {
 1115|       |            ssh_set_error(
 1116|       |                session,
 1117|       |                SSH_FATAL,
 1118|       |                "USERAUTH_REQUEST: gssapi-with-mic OID count too big (%d)",
 1119|       |                n_oid);
 1120|       |            goto error;
 1121|       |        }
 1122|       |        SSH_LOG(SSH_LOG_PACKET, "gssapi: %d OIDs", n_oid);
 1123|       |        oids = calloc(n_oid, sizeof(ssh_string));
 1124|       |        if (oids == NULL) {
 1125|       |            ssh_set_error_oom(session);
 1126|       |            goto error;
 1127|       |        }
 1128|       |        for (i = 0; i < (int)n_oid; ++i) {
 1129|       |            oid = ssh_buffer_get_ssh_string(packet);
 1130|       |            if (oid == NULL) {
 1131|       |                for (i = i - 1; i >= 0; --i) {
 1132|       |                    SAFE_FREE(oids[i]);
 1133|       |                }
 1134|       |                SAFE_FREE(oids);
 1135|       |                ssh_set_error(session,
 1136|       |                              SSH_LOG_PACKET,
 1137|       |                              "USERAUTH_REQUEST: gssapi-with-mic missing OID");
 1138|       |                goto error;
 1139|       |            }
 1140|       |            oids[i] = oid;
 1141|       |            if (session->common.log_verbosity >= SSH_LOG_PACKET) {
 1142|       |                hexa = ssh_get_hexa(ssh_string_data(oid), ssh_string_len(oid));
 1143|       |                SSH_LOG(SSH_LOG_PACKET, "gssapi: OID %d: %s", i, hexa);
 1144|       |                SAFE_FREE(hexa);
 1145|       |            }
 1146|       |        }
 1147|       |        ssh_gssapi_handle_userauth(session,
 1148|       |                                   msg->auth_request.username,
 1149|       |                                   n_oid,
 1150|       |                                   oids);
 1151|       |
 1152|       |        for (i = 0; i < (int)n_oid; ++i) {
 1153|       |            SAFE_FREE(oids[i]);
 1154|       |        }
 1155|       |        SAFE_FREE(oids);
 1156|       |        /* bypass the message queue thing */
 1157|       |        SAFE_FREE(service);
 1158|       |        SAFE_FREE(method);
 1159|       |        SSH_MESSAGE_FREE(msg);
 1160|       |
 1161|       |        return SSH_PACKET_USED;
 1162|       |    }
 1163|       |    if (strcmp(method, "gssapi-keyex") == 0) {
 1164|       |        gss_buffer_desc received_mic = GSS_C_EMPTY_BUFFER;
 1165|       |        gss_buffer_desc mic_buf = GSS_C_EMPTY_BUFFER;
 1166|       |        ssh_string mic_token_string = NULL;
 1167|       |        OM_uint32 maj_stat, min_stat;
 1168|       |        ssh_buffer buf = NULL;
 1169|       |
 1170|       |        if (!ssh_kex_is_gss(session->current_crypto)) {
 1171|       |            ssh_set_error(session,
 1172|       |                          SSH_FATAL,
 1173|       |                          "Attempt to authenticate with gssapi-keyex without "
 1174|       |                          "doing GSSAPI Key Exchange.");
 1175|       |            ssh_auth_reply_default(session, 0);
 1176|       |            goto error;
 1177|       |        }
 1178|       |
 1179|       |        if (session->gssapi == NULL || session->gssapi->ctx == NULL) {
 1180|       |            ssh_set_error(session, SSH_FATAL, "GSSAPI context not initialized");
 1181|       |            ssh_auth_reply_default(session, 0);
 1182|       |            goto error;
 1183|       |        }
 1184|       |
 1185|       |        rc = ssh_buffer_unpack(packet, "S", &mic_token_string);
 1186|       |        if (rc != SSH_OK) {
 1187|       |            ssh_auth_reply_default(session, 0);
 1188|       |            goto error;
 1189|       |        }
 1190|       |        received_mic.length = ssh_string_len(mic_token_string);
 1191|       |        received_mic.value = ssh_string_data(mic_token_string);
 1192|       |
 1193|       |        SAFE_FREE(session->gssapi->user);
 1194|       |        session->gssapi->user = strdup(msg->auth_request.username);
 1195|       |        buf = ssh_gssapi_build_mic(session, "gssapi-keyex");
 1196|       |        if (buf == NULL) {
 1197|       |            ssh_set_error_oom(session);
 1198|       |            SSH_STRING_FREE(mic_token_string);
 1199|       |            ssh_auth_reply_default(session, 0);
 1200|       |            goto error;
 1201|       |        }
 1202|       |
 1203|       |        mic_buf.length = ssh_buffer_get_len(buf);
 1204|       |        mic_buf.value = ssh_buffer_get(buf);
 1205|       |
 1206|       |        maj_stat = gss_verify_mic(&min_stat,
 1207|       |                                  session->gssapi->ctx,
 1208|       |                                  &mic_buf,
 1209|       |                                  &received_mic,
 1210|       |                                  NULL);
 1211|       |        if (maj_stat != GSS_S_COMPLETE) {
 1212|       |            ssh_set_error(session,
 1213|       |                          SSH_FATAL,
 1214|       |                          "Failed to verify MIC for gssapi-keyex auth");
 1215|       |            SSH_BUFFER_FREE(buf);
 1216|       |            SSH_STRING_FREE(mic_token_string);
 1217|       |            ssh_auth_reply_default(session, 0);
 1218|       |            goto error;
 1219|       |        }
 1220|       |
 1221|       |        ssh_auth_reply_success(session, 0);
 1222|       |
 1223|       |        /* bypass the message queue thing */
 1224|       |        SAFE_FREE(service);
 1225|       |        SAFE_FREE(method);
 1226|       |        SSH_BUFFER_FREE(buf);
 1227|       |        SSH_MESSAGE_FREE(msg);
 1228|       |        SSH_STRING_FREE(mic_token_string);
 1229|       |
 1230|       |        return SSH_PACKET_USED;
 1231|       |    }
 1232|       |#endif
 1233|       |
 1234|      0|    msg->auth_request.method = SSH_AUTH_METHOD_UNKNOWN;
  ------------------
  |  |  155|      0|#define SSH_AUTH_METHOD_UNKNOWN      0x0000u
  ------------------
 1235|      0|    SAFE_FREE(method);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1236|      0|    goto end;
 1237|      0|error:
 1238|      0|    SAFE_FREE(service);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1239|      0|    SAFE_FREE(method);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1240|       |
 1241|      0|    SSH_MESSAGE_FREE(msg);
  ------------------
  |  |  714|      0|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (714:14): [True: 0, False: 0]
  |  |  |  Branch (714:72): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1242|       |
 1243|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
 1244|    657|end:
 1245|    657|    SAFE_FREE(service);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
 1246|    657|    SAFE_FREE(method);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
 1247|       |
 1248|    657|    ssh_message_queue(session, msg);
 1249|       |
 1250|    657|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
 1251|      0|}
ssh_packet_channel_open:
 1391|    657|{
 1392|    657|    ssh_message msg = NULL;
 1393|    657|    char *type_c = NULL;
 1394|    657|    uint32_t originator_port, destination_port;
 1395|    657|    int rc;
 1396|       |
 1397|    657|    (void)type;
 1398|    657|    (void)user;
 1399|       |
 1400|    657|    msg = ssh_message_new(session);
 1401|    657|    if (msg == NULL) {
  ------------------
  |  Branch (1401:9): [True: 0, False: 657]
  ------------------
 1402|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1403|      0|        goto error;
 1404|      0|    }
 1405|       |
 1406|    657|    msg->type = SSH_REQUEST_CHANNEL_OPEN;
 1407|    657|    rc = ssh_buffer_unpack(packet, "s", &type_c);
  ------------------
  |  |   60|    657|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1408|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1408:9): [True: 0, False: 657]
  ------------------
 1409|      0|        goto error;
 1410|      0|    }
 1411|       |
 1412|    657|    SSH_LOG(SSH_LOG_PACKET, "Clients wants to open a %s channel", type_c);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1413|       |
 1414|    657|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|    657|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1415|    657|                           "ddd",
 1416|    657|                           &msg->channel_request_open.sender,
 1417|    657|                           &msg->channel_request_open.window,
 1418|    657|                           &msg->channel_request_open.packet_size);
 1419|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1419:9): [True: 0, False: 657]
  ------------------
 1420|      0|        goto error;
 1421|      0|    }
 1422|       |
 1423|    657|    if (msg->channel_request_open.packet_size == 0) {
  ------------------
  |  Branch (1423:9): [True: 0, False: 657]
  ------------------
 1424|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1425|      0|                      SSH_FATAL,
 1426|      0|                      "Invalid maximum packet size 0 in SSH2_MSG_CHANNEL_OPEN");
 1427|      0|        goto error;
 1428|      0|    }
 1429|       |
 1430|    657|    if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1430:9): [True: 0, False: 657]
  ------------------
 1431|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1432|      0|                      SSH_FATAL,
 1433|      0|                      "Invalid state when receiving channel open request "
 1434|      0|                      "(must be authenticated)");
 1435|      0|        goto error;
 1436|      0|    }
 1437|       |
 1438|    657|    if (strcmp(type_c, "session") == 0) {
  ------------------
  |  Branch (1438:9): [True: 657, False: 0]
  ------------------
 1439|    657|        if (session->flags & SSH_SESSION_FLAG_NO_MORE_SESSIONS) {
  ------------------
  |  |   81|    657|#define SSH_SESSION_FLAG_NO_MORE_SESSIONS 0x0004
  ------------------
  |  Branch (1439:13): [True: 0, False: 657]
  ------------------
 1440|      0|            ssh_session_set_disconnect_message(session,
 1441|      0|                                               "No more sessions allowed!");
 1442|      0|            ssh_set_error(session, SSH_FATAL, "No more sessions allowed!");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1443|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
 1444|      0|            ssh_send_disconnect(session);
 1445|      0|            goto error;
 1446|      0|        }
 1447|       |
 1448|    657|        msg->channel_request_open.type = SSH_CHANNEL_SESSION;
 1449|    657|        SAFE_FREE(type_c);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
 1450|    657|        goto end;
 1451|    657|    }
 1452|       |
 1453|      0|    if (strcmp(type_c, "direct-tcpip") == 0) {
  ------------------
  |  Branch (1453:9): [True: 0, False: 0]
  ------------------
 1454|      0|        rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1455|      0|                               "sdsd",
 1456|      0|                               &msg->channel_request_open.destination,
 1457|      0|                               &destination_port,
 1458|      0|                               &msg->channel_request_open.originator,
 1459|      0|                               &originator_port);
 1460|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1460:13): [True: 0, False: 0]
  ------------------
 1461|      0|            goto error;
 1462|      0|        }
 1463|       |
 1464|      0|        msg->channel_request_open.destination_port = (uint16_t)destination_port;
 1465|      0|        msg->channel_request_open.originator_port = (uint16_t)originator_port;
 1466|      0|        msg->channel_request_open.type = SSH_CHANNEL_DIRECT_TCPIP;
 1467|      0|        goto end;
 1468|      0|    }
 1469|       |
 1470|      0|    if (strcmp(type_c, "forwarded-tcpip") == 0) {
  ------------------
  |  Branch (1470:9): [True: 0, False: 0]
  ------------------
 1471|      0|        rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1472|      0|                               "sdsd",
 1473|      0|                               &msg->channel_request_open.destination,
 1474|      0|                               &destination_port,
 1475|      0|                               &msg->channel_request_open.originator,
 1476|      0|                               &originator_port);
 1477|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1477:13): [True: 0, False: 0]
  ------------------
 1478|      0|            goto error;
 1479|      0|        }
 1480|      0|        msg->channel_request_open.destination_port = (uint16_t)destination_port;
 1481|      0|        msg->channel_request_open.originator_port = (uint16_t)originator_port;
 1482|      0|        msg->channel_request_open.type = SSH_CHANNEL_FORWARDED_TCPIP;
 1483|      0|        goto end;
 1484|      0|    }
 1485|       |
 1486|      0|    if (strcmp(type_c, "x11") == 0) {
  ------------------
  |  Branch (1486:9): [True: 0, False: 0]
  ------------------
 1487|      0|        rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1488|      0|                               "sd",
 1489|      0|                               &msg->channel_request_open.originator,
 1490|      0|                               &originator_port);
 1491|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1491:13): [True: 0, False: 0]
  ------------------
 1492|      0|            goto error;
 1493|      0|        }
 1494|      0|        msg->channel_request_open.originator_port = (uint16_t)originator_port;
 1495|      0|        msg->channel_request_open.type = SSH_CHANNEL_X11;
 1496|      0|        goto end;
 1497|      0|    }
 1498|       |
 1499|      0|    if (strcmp(type_c, "auth-agent") == 0 ||
  ------------------
  |  Branch (1499:9): [True: 0, False: 0]
  ------------------
 1500|      0|        strcmp(type_c, "auth-agent@openssh.com") == 0) {
  ------------------
  |  Branch (1500:9): [True: 0, False: 0]
  ------------------
 1501|      0|        msg->channel_request_open.type = SSH_CHANNEL_AUTH_AGENT;
 1502|      0|        goto end;
 1503|      0|    }
 1504|       |
 1505|      0|    msg->channel_request_open.type = SSH_CHANNEL_UNKNOWN;
 1506|      0|    goto end;
 1507|       |
 1508|      0|error:
 1509|      0|    SSH_MESSAGE_FREE(msg);
  ------------------
  |  |  714|      0|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (714:14): [True: 0, False: 0]
  |  |  |  Branch (714:72): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1510|       |
 1511|    657|end:
 1512|    657|    SAFE_FREE(type_c);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
 1513|    657|    if (msg != NULL)
  ------------------
  |  Branch (1513:9): [True: 657, False: 0]
  ------------------
 1514|    657|        ssh_message_queue(session, msg);
 1515|       |
 1516|    657|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
 1517|      0|}
ssh_message_channel_request_open_reply_accept_channel:
 1532|    657|{
 1533|    657|    ssh_session session = NULL;
 1534|    657|    int rc;
 1535|       |
 1536|    657|    if (msg == NULL) {
  ------------------
  |  Branch (1536:9): [True: 0, False: 657]
  ------------------
 1537|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1538|      0|    }
 1539|       |
 1540|    657|    session = msg->session;
 1541|       |
 1542|    657|    chan->local_channel = ssh_channel_new_id(session);
 1543|    657|    chan->local_maxpacket = 35000;
 1544|    657|    chan->local_window = 32000;
 1545|    657|    chan->remote_channel = msg->channel_request_open.sender;
 1546|    657|    chan->remote_maxpacket = msg->channel_request_open.packet_size;
 1547|    657|    chan->remote_window = msg->channel_request_open.window;
 1548|    657|    chan->state = SSH_CHANNEL_STATE_OPEN;
 1549|    657|    chan->flags &= ~SSH_CHANNEL_FLAG_NOT_BOUND;
  ------------------
  |  |   64|    657|#define SSH_CHANNEL_FLAG_NOT_BOUND 0x0008
  ------------------
 1550|       |
 1551|    657|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    657|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1552|    657|                         "bdddd",
 1553|    657|                         SSH2_MSG_CHANNEL_OPEN_CONFIRMATION,
 1554|    657|                         chan->remote_channel,
 1555|    657|                         chan->local_channel,
 1556|    657|                         chan->local_window,
 1557|    657|                         chan->local_maxpacket);
 1558|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1558:9): [True: 0, False: 657]
  ------------------
 1559|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1560|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1561|      0|    }
 1562|       |
 1563|    657|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1564|    657|            "Accepting a channel request_open for chan %" PRIu32,
 1565|    657|            chan->remote_channel);
 1566|       |
 1567|    657|    rc = ssh_packet_send(session);
 1568|       |
 1569|    657|    return rc;
 1570|    657|}
ssh_message_handle_channel_request:
 1629|    657|{
 1630|    657|    ssh_message msg = NULL;
 1631|    657|    int rc;
 1632|       |
 1633|    657|    msg = ssh_message_new(session);
 1634|    657|    if (msg == NULL) {
  ------------------
  |  Branch (1634:9): [True: 0, False: 657]
  ------------------
 1635|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1636|      0|        goto error;
 1637|      0|    }
 1638|       |
 1639|    657|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1640|    657|            "Received a %s channel_request for channel (%" PRIu32 ":%" PRIu32
 1641|    657|            ") (want_reply=%hhu)",
 1642|    657|            request,
 1643|    657|            channel->local_channel,
 1644|    657|            channel->remote_channel,
 1645|    657|            want_reply);
 1646|       |
 1647|    657|    msg->type = SSH_REQUEST_CHANNEL;
 1648|    657|    msg->channel_request.channel = channel;
 1649|    657|    msg->channel_request.want_reply = want_reply;
 1650|       |
 1651|    657|    if (strcmp(request, "pty-req") == 0) {
  ------------------
  |  Branch (1651:9): [True: 0, False: 657]
  ------------------
 1652|      0|        rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1653|      0|                               "sddddS",
 1654|      0|                               &msg->channel_request.TERM,
 1655|      0|                               &msg->channel_request.width,
 1656|      0|                               &msg->channel_request.height,
 1657|      0|                               &msg->channel_request.pxwidth,
 1658|      0|                               &msg->channel_request.pxheight,
 1659|      0|                               &msg->channel_request.modes);
 1660|       |
 1661|      0|        msg->channel_request.type = SSH_CHANNEL_REQUEST_PTY;
 1662|       |
 1663|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1663:13): [True: 0, False: 0]
  ------------------
 1664|      0|            goto error;
 1665|      0|        }
 1666|      0|        goto end;
 1667|      0|    }
 1668|       |
 1669|    657|    if (strcmp(request, "window-change") == 0) {
  ------------------
  |  Branch (1669:9): [True: 0, False: 657]
  ------------------
 1670|      0|        msg->channel_request.type = SSH_CHANNEL_REQUEST_WINDOW_CHANGE;
 1671|      0|        rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1672|      0|                               "dddd",
 1673|      0|                               &msg->channel_request.width,
 1674|      0|                               &msg->channel_request.height,
 1675|      0|                               &msg->channel_request.pxwidth,
 1676|      0|                               &msg->channel_request.pxheight);
 1677|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1677:13): [True: 0, False: 0]
  ------------------
 1678|      0|            goto error;
 1679|      0|        }
 1680|      0|        goto end;
 1681|      0|    }
 1682|       |
 1683|    657|    if (strcmp(request, "subsystem") == 0) {
  ------------------
  |  Branch (1683:9): [True: 0, False: 657]
  ------------------
 1684|      0|        rc = ssh_buffer_unpack(packet, "s", &msg->channel_request.subsystem);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1685|      0|        msg->channel_request.type = SSH_CHANNEL_REQUEST_SUBSYSTEM;
 1686|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1686:13): [True: 0, False: 0]
  ------------------
 1687|      0|            goto error;
 1688|      0|        }
 1689|      0|        goto end;
 1690|      0|    }
 1691|       |
 1692|    657|    if (strcmp(request, "shell") == 0) {
  ------------------
  |  Branch (1692:9): [True: 0, False: 657]
  ------------------
 1693|      0|        msg->channel_request.type = SSH_CHANNEL_REQUEST_SHELL;
 1694|      0|        goto end;
 1695|      0|    }
 1696|       |
 1697|    657|    if (strcmp(request, "exec") == 0) {
  ------------------
  |  Branch (1697:9): [True: 657, False: 0]
  ------------------
 1698|    657|        rc = ssh_buffer_unpack(packet, "s", &msg->channel_request.command);
  ------------------
  |  |   60|    657|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1699|    657|        msg->channel_request.type = SSH_CHANNEL_REQUEST_EXEC;
 1700|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1700:13): [True: 0, False: 657]
  ------------------
 1701|      0|            goto error;
 1702|      0|        }
 1703|    657|        goto end;
 1704|    657|    }
 1705|       |
 1706|      0|    if (strcmp(request, "env") == 0) {
  ------------------
  |  Branch (1706:9): [True: 0, False: 0]
  ------------------
 1707|      0|        rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1708|      0|                               "ss",
 1709|      0|                               &msg->channel_request.var_name,
 1710|      0|                               &msg->channel_request.var_value);
 1711|      0|        msg->channel_request.type = SSH_CHANNEL_REQUEST_ENV;
 1712|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1712:13): [True: 0, False: 0]
  ------------------
 1713|      0|            goto error;
 1714|      0|        }
 1715|      0|        goto end;
 1716|      0|    }
 1717|       |
 1718|      0|    if (strcmp(request, "x11-req") == 0) {
  ------------------
  |  Branch (1718:9): [True: 0, False: 0]
  ------------------
 1719|      0|        rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1720|      0|                               "bssd",
 1721|      0|                               &msg->channel_request.x11_single_connection,
 1722|      0|                               &msg->channel_request.x11_auth_protocol,
 1723|      0|                               &msg->channel_request.x11_auth_cookie,
 1724|      0|                               &msg->channel_request.x11_screen_number);
 1725|       |
 1726|      0|        msg->channel_request.type = SSH_CHANNEL_REQUEST_X11;
 1727|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1727:13): [True: 0, False: 0]
  ------------------
 1728|      0|            goto error;
 1729|      0|        }
 1730|       |
 1731|      0|        goto end;
 1732|      0|    }
 1733|       |
 1734|      0|    msg->channel_request.type = SSH_CHANNEL_REQUEST_UNKNOWN;
 1735|    657|end:
 1736|    657|    ssh_message_queue(session, msg);
 1737|       |
 1738|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
 1739|      0|error:
 1740|      0|    SSH_MESSAGE_FREE(msg);
  ------------------
  |  |  714|      0|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (714:14): [True: 0, False: 0]
  |  |  |  Branch (714:72): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1741|       |
 1742|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1743|      0|}
ssh_message_channel_request_reply_success:
 1754|    657|{
 1755|    657|    uint32_t channel;
 1756|    657|    int rc;
 1757|       |
 1758|    657|    if (msg == NULL) {
  ------------------
  |  Branch (1758:9): [True: 0, False: 657]
  ------------------
 1759|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1760|      0|    }
 1761|       |
 1762|    657|    if (msg->channel_request.want_reply) {
  ------------------
  |  Branch (1762:9): [True: 657, False: 0]
  ------------------
 1763|    657|        channel = msg->channel_request.channel->remote_channel;
 1764|       |
 1765|    657|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1766|    657|                "Sending a channel_request success to channel %" PRIu32,
 1767|    657|                channel);
 1768|       |
 1769|    657|        rc = ssh_buffer_pack(msg->session->out_buffer,
  ------------------
  |  |   50|    657|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1770|    657|                             "bd",
 1771|    657|                             SSH2_MSG_CHANNEL_SUCCESS,
 1772|    657|                             channel);
 1773|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1773:13): [True: 0, False: 657]
  ------------------
 1774|      0|            ssh_set_error_oom(msg->session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1775|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1776|      0|        }
 1777|       |
 1778|    657|        return ssh_packet_send(msg->session);
 1779|    657|    }
 1780|       |
 1781|      0|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1782|      0|            "The client doesn't want to know the request succeeded");
 1783|       |
 1784|      0|    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1785|    657|}
messages.c:ssh_message_new:
   67|  2.62k|{
   68|  2.62k|    ssh_message msg = calloc(1, sizeof(struct ssh_message_struct));
   69|  2.62k|    if (msg == NULL) {
  ------------------
  |  Branch (69:9): [True: 0, False: 2.62k]
  ------------------
   70|      0|        return NULL;
   71|      0|    }
   72|  2.62k|    msg->session = session;
   73|       |
   74|       |    /* Set states explicitly */
   75|  2.62k|    msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_NONE;
   76|       |
   77|  2.62k|    return msg;
   78|  2.62k|}
messages.c:ssh_message_queue:
  498|  2.62k|{
  499|  2.62k|#ifdef WITH_SERVER
  500|  2.62k|    int ret;
  501|  2.62k|#endif
  502|       |
  503|  2.62k|    if (message == NULL) {
  ------------------
  |  Branch (503:9): [True: 0, False: 2.62k]
  ------------------
  504|      0|        return;
  505|      0|    }
  506|       |
  507|  2.62k|#ifdef WITH_SERVER
  508|       |    /* probably not the best place to execute server callbacks, but still better
  509|       |     * than nothing.
  510|       |     */
  511|  2.62k|    ret = ssh_execute_server_callbacks(session, message);
  512|  2.62k|    if (ret == SSH_OK) {
  ------------------
  |  |  316|  2.62k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (512:9): [True: 1.97k, False: 657]
  ------------------
  513|  1.97k|        SSH_MESSAGE_FREE(message);
  ------------------
  |  |  714|  1.97k|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (714:14): [True: 1.97k, False: 0]
  |  |  |  Branch (714:72): [Folded, False: 1.97k]
  |  |  ------------------
  ------------------
  514|  1.97k|        return;
  515|  1.97k|    }
  516|    657|#endif /* WITH_SERVER */
  517|       |
  518|    657|    if (session->ssh_message_callback != NULL) {
  ------------------
  |  Branch (518:9): [True: 0, False: 657]
  ------------------
  519|       |        /* This will transfer the message, do not free. */
  520|      0|        ssh_execute_message_callback(session, message);
  521|      0|        return;
  522|      0|    }
  523|       |
  524|    657|    if (session->server_callbacks != NULL) {
  ------------------
  |  Branch (524:9): [True: 657, False: 0]
  ------------------
  525|       |        /* if we have server callbacks, but nothing was executed, it means we are
  526|       |         * in non-synchronous mode, and we just don't care about the message we
  527|       |         * received. Just send a default response. Do not queue it.
  528|       |         */
  529|    657|        ssh_message_reply_default(message);
  530|    657|        SSH_MESSAGE_FREE(message);
  ------------------
  |  |  714|    657|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (714:14): [True: 657, False: 0]
  |  |  |  Branch (714:72): [Folded, False: 657]
  |  |  ------------------
  ------------------
  531|    657|        return;
  532|    657|    }
  533|       |
  534|      0|    if (session->ssh_message_list == NULL) {
  ------------------
  |  Branch (534:9): [True: 0, False: 0]
  ------------------
  535|      0|        session->ssh_message_list = ssh_list_new();
  536|      0|        if (session->ssh_message_list == NULL) {
  ------------------
  |  Branch (536:13): [True: 0, False: 0]
  ------------------
  537|       |            /*
  538|       |             * If the message list couldn't be allocated, the message can't be
  539|       |             * enqueued
  540|       |             */
  541|      0|            ssh_message_reply_default(message);
  542|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  543|      0|            SSH_MESSAGE_FREE(message);
  ------------------
  |  |  714|      0|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (714:14): [True: 0, False: 0]
  |  |  |  Branch (714:72): [Folded, False: 0]
  |  |  ------------------
  ------------------
  544|      0|            return;
  545|      0|        }
  546|      0|    }
  547|       |
  548|       |    /* This will transfer the message, do not free. */
  549|      0|    ssh_list_append(session->ssh_message_list, message);
  550|      0|    return;
  551|      0|}
messages.c:ssh_execute_server_callbacks:
  448|  2.62k|static int ssh_execute_server_callbacks(ssh_session session, ssh_message msg){
  449|  2.62k|    int rc = SSH_AGAIN;
  ------------------
  |  |  318|  2.62k|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  450|       |
  451|  2.62k|    if (session->server_callbacks != NULL){
  ------------------
  |  Branch (451:9): [True: 2.62k, False: 0]
  ------------------
  452|  2.62k|        rc = ssh_execute_server_request(session, msg);
  453|  2.62k|    } else if (session->common.callbacks != NULL) {
  ------------------
  |  Branch (453:16): [True: 0, False: 0]
  ------------------
  454|       |        /* This one is in fact a client callback... */
  455|      0|        rc = ssh_execute_client_request(session, msg);
  456|      0|    }
  457|       |
  458|  2.62k|    return rc;
  459|  2.62k|}
messages.c:ssh_execute_server_request:
  138|  2.62k|{
  139|  2.62k|    ssh_channel channel = NULL;
  140|  2.62k|    int rc;
  141|       |
  142|  2.62k|    switch(msg->type) {
  ------------------
  |  Branch (142:12): [True: 2.62k, False: 0]
  ------------------
  143|    657|        case SSH_REQUEST_AUTH:
  ------------------
  |  Branch (143:9): [True: 657, False: 1.97k]
  ------------------
  144|    657|            if (msg->auth_request.method == SSH_AUTH_METHOD_PASSWORD &&
  ------------------
  |  |  157|  1.31k|#define SSH_AUTH_METHOD_PASSWORD     0x0002u
  ------------------
  |  Branch (144:17): [True: 0, False: 657]
  ------------------
  145|      0|                ssh_callbacks_exists(session->server_callbacks, auth_password_function)) {
  ------------------
  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  ------------------
  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  ------------------
  |  |  550|      0|  )
  ------------------
  146|      0|                rc = session->server_callbacks->auth_password_function(session,
  147|      0|                        msg->auth_request.username, msg->auth_request.password,
  148|      0|                        session->server_callbacks->userdata);
  149|      0|                if (rc == SSH_AUTH_SUCCESS || rc == SSH_AUTH_PARTIAL) {
  ------------------
  |  Branch (149:21): [True: 0, False: 0]
  |  Branch (149:47): [True: 0, False: 0]
  ------------------
  150|      0|                    ssh_message_auth_reply_success(msg, rc == SSH_AUTH_PARTIAL);
  151|      0|                } else {
  152|      0|                    ssh_message_reply_default(msg);
  153|      0|                }
  154|       |
  155|      0|                return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  156|    657|            } else if(msg->auth_request.method == SSH_AUTH_METHOD_PUBLICKEY &&
  ------------------
  |  |  158|  1.31k|#define SSH_AUTH_METHOD_PUBLICKEY    0x0004u
  ------------------
  |  Branch (156:23): [True: 0, False: 657]
  ------------------
  157|      0|                      ssh_callbacks_exists(session->server_callbacks, auth_pubkey_function)) {
  ------------------
  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  ------------------
  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  ------------------
  |  |  550|      0|  )
  ------------------
  158|      0|               rc = session->server_callbacks->auth_pubkey_function(session,
  159|      0|                       msg->auth_request.username, msg->auth_request.pubkey,
  160|      0|                       msg->auth_request.signature_state,
  161|      0|                       session->server_callbacks->userdata);
  162|      0|               if (msg->auth_request.signature_state != SSH_PUBLICKEY_STATE_NONE) {
  ------------------
  |  Branch (162:20): [True: 0, False: 0]
  ------------------
  163|      0|                 if (rc == SSH_AUTH_SUCCESS || rc == SSH_AUTH_PARTIAL) {
  ------------------
  |  Branch (163:22): [True: 0, False: 0]
  |  Branch (163:48): [True: 0, False: 0]
  ------------------
  164|      0|                   ssh_message_auth_reply_success(msg, rc == SSH_AUTH_PARTIAL);
  165|      0|                 } else {
  166|      0|                   ssh_message_reply_default(msg);
  167|      0|                 }
  168|      0|               } else {
  169|      0|                 if (rc == SSH_AUTH_SUCCESS) {
  ------------------
  |  Branch (169:22): [True: 0, False: 0]
  ------------------
  170|      0|                   ssh_message_auth_reply_pk_ok_simple(msg);
  171|      0|                 } else {
  172|      0|                   ssh_message_reply_default(msg);
  173|      0|                 }
  174|      0|               }
  175|       |
  176|      0|               return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  177|    657|            } else if (msg->auth_request.method == SSH_AUTH_METHOD_NONE &&
  ------------------
  |  |  156|  1.31k|#define SSH_AUTH_METHOD_NONE         0x0001u
  ------------------
  |  Branch (177:24): [True: 657, False: 0]
  ------------------
  178|    657|                       ssh_callbacks_exists(session->server_callbacks, auth_none_function)) {
  ------------------
  |  |  547|    657|#define ssh_callbacks_exists(p,c) (\
  |  |  548|    657|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (548:3): [True: 657, False: 0]
  |  |  |  Branch (548:18): [True: 657, False: 0]
  |  |  ------------------
  |  |  549|    657|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 657, False: 0]
  |  |  ------------------
  |  |  550|    657|  )
  ------------------
  179|    657|                rc = session->server_callbacks->auth_none_function(session,
  180|    657|                    msg->auth_request.username, session->server_callbacks->userdata);
  181|    657|                if (rc == SSH_AUTH_SUCCESS || rc == SSH_AUTH_PARTIAL){
  ------------------
  |  Branch (181:21): [True: 657, False: 0]
  |  Branch (181:47): [True: 0, False: 0]
  ------------------
  182|    657|                    ssh_message_auth_reply_success(msg, rc == SSH_AUTH_PARTIAL);
  183|    657|                } else {
  184|      0|                    ssh_message_reply_default(msg);
  185|      0|                }
  186|       |
  187|    657|                return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  188|    657|            } else if (msg->auth_request.method == SSH_AUTH_METHOD_INTERACTIVE &&
  ------------------
  |  |  160|      0|#define SSH_AUTH_METHOD_INTERACTIVE  0x0010u
  ------------------
  |  Branch (188:24): [True: 0, False: 0]
  ------------------
  189|      0|                       ssh_callbacks_exists(session->server_callbacks, auth_kbdint_function)) {
  ------------------
  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  ------------------
  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  ------------------
  |  |  550|      0|  )
  ------------------
  190|      0|                rc = session->server_callbacks->auth_kbdint_function(msg,
  191|      0|                                                                     session,
  192|      0|                                                                     session->server_callbacks->userdata);
  193|      0|                if (rc == SSH_AUTH_SUCCESS || rc == SSH_AUTH_PARTIAL) {
  ------------------
  |  Branch (193:21): [True: 0, False: 0]
  |  Branch (193:47): [True: 0, False: 0]
  ------------------
  194|      0|                    ssh_message_auth_reply_success(msg, rc == SSH_AUTH_PARTIAL);
  195|      0|                } else if (rc == SSH_AUTH_INFO) {
  ------------------
  |  Branch (195:28): [True: 0, False: 0]
  ------------------
  196|      0|                    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  197|      0|                } else {
  198|      0|                    ssh_message_reply_default(msg);
  199|      0|                }
  200|      0|                return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  201|      0|            }
  202|      0|            break;
  203|    657|        case SSH_REQUEST_CHANNEL_OPEN:
  ------------------
  |  Branch (203:9): [True: 657, False: 1.97k]
  ------------------
  204|    657|            if (msg->channel_request_open.type == SSH_CHANNEL_SESSION &&
  ------------------
  |  Branch (204:17): [True: 657, False: 0]
  ------------------
  205|    657|                ssh_callbacks_exists(session->server_callbacks, channel_open_request_session_function)) {
  ------------------
  |  |  547|    657|#define ssh_callbacks_exists(p,c) (\
  |  |  548|    657|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (548:3): [True: 657, False: 0]
  |  |  |  Branch (548:18): [True: 657, False: 0]
  |  |  ------------------
  |  |  549|    657|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 657, False: 0]
  |  |  ------------------
  |  |  550|    657|  )
  ------------------
  206|    657|                channel = session->server_callbacks->channel_open_request_session_function(session,
  207|    657|                        session->server_callbacks->userdata);
  208|    657|                if (channel != NULL) {
  ------------------
  |  Branch (208:21): [True: 657, False: 0]
  ------------------
  209|    657|                    rc = ssh_message_channel_request_open_reply_accept_channel(msg, channel);
  210|    657|                    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (210:25): [True: 0, False: 657]
  ------------------
  211|      0|                        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  212|      0|                                "Failed to send reply for accepting a channel "
  213|      0|                                "open");
  214|      0|                    }
  215|    657|                    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  216|    657|                } else {
  217|      0|                    ssh_message_reply_default(msg);
  218|      0|                }
  219|       |
  220|      0|                return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  221|    657|#define CB channel_open_request_direct_tcpip_function
  222|    657|            } else if (msg->channel_request_open.type == SSH_CHANNEL_DIRECT_TCPIP &&
  ------------------
  |  Branch (222:24): [True: 0, False: 0]
  ------------------
  223|      0|                       ssh_callbacks_exists(session->server_callbacks, CB)) {
  ------------------
  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  ------------------
  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  ------------------
  |  |  550|      0|  )
  ------------------
  224|      0|                struct ssh_channel_request_open *rq = &msg->channel_request_open;
  225|      0|                channel = session->server_callbacks->CB(session,
  ------------------
  |  |  221|      0|#define CB channel_open_request_direct_tcpip_function
  ------------------
  226|      0|                                                        rq->destination,
  227|      0|                                                        rq->destination_port,
  228|      0|                                                        rq->originator,
  229|      0|                                                        rq->originator_port,
  230|      0|                                                        session->server_callbacks->userdata);
  231|      0|#undef CB
  232|      0|                if (channel != NULL) {
  ------------------
  |  Branch (232:21): [True: 0, False: 0]
  ------------------
  233|      0|                    rc = ssh_message_channel_request_open_reply_accept_channel(
  234|      0|                        msg,
  235|      0|                        channel);
  236|      0|                    if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (236:25): [True: 0, False: 0]
  ------------------
  237|      0|                        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  238|      0|                                "Failed to send reply for accepting a channel "
  239|      0|                                "open");
  240|      0|                    }
  241|      0|                    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  242|      0|                } else {
  243|      0|                    ssh_message_reply_default(msg);
  244|      0|                }
  245|       |
  246|      0|                return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  247|      0|            }
  248|       |
  249|      0|            break;
  250|    657|        case SSH_REQUEST_CHANNEL:
  ------------------
  |  Branch (250:9): [True: 657, False: 1.97k]
  ------------------
  251|    657|            channel = msg->channel_request.channel;
  252|       |
  253|    657|            if (msg->channel_request.type == SSH_CHANNEL_REQUEST_PTY){
  ------------------
  |  Branch (253:17): [True: 0, False: 657]
  ------------------
  254|      0|                ssh_callbacks_iterate(channel->callbacks,
  ------------------
  |  |  598|      0|    do {                                                              \
  |  |  599|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  600|      0|        _cb_type _cb;                                                 \
  |  |  601|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (601:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  602|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  603|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  ------------------
  255|      0|                                      ssh_channel_callbacks,
  256|      0|                                      channel_pty_request_function) {
  257|      0|                    rc = ssh_callbacks_iterate_exec(channel_pty_request_function,
  ------------------
  |  |  612|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  258|      0|                                                    session,
  259|      0|                                                    channel,
  260|      0|                                                    msg->channel_request.TERM,
  261|      0|                                                    msg->channel_request.width,
  262|      0|                                                    msg->channel_request.height,
  263|      0|                                                    msg->channel_request.pxwidth,
  264|      0|                                                    msg->channel_request.pxheight);
  265|      0|                    if (rc == 0) {
  ------------------
  |  Branch (265:25): [True: 0, False: 0]
  ------------------
  266|      0|                        ssh_message_channel_request_reply_success(msg);
  267|      0|                    } else {
  268|      0|                        ssh_message_reply_default(msg);
  269|      0|                    }
  270|      0|                    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  271|      0|                }
  272|      0|                ssh_callbacks_iterate_end();
  ------------------
  |  |  618|      0|        }                           \
  |  |  619|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (619:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  273|    657|            } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_SHELL){
  ------------------
  |  Branch (273:24): [True: 0, False: 657]
  ------------------
  274|      0|                ssh_callbacks_iterate(channel->callbacks,
  ------------------
  |  |  598|      0|    do {                                                              \
  |  |  599|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  600|      0|        _cb_type _cb;                                                 \
  |  |  601|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (601:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  602|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  603|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  ------------------
  275|      0|                                      ssh_channel_callbacks,
  276|      0|                                      channel_shell_request_function) {
  277|      0|                    rc = ssh_callbacks_iterate_exec(channel_shell_request_function,
  ------------------
  |  |  612|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  278|      0|                                                    session,
  279|      0|                                                    channel);
  280|      0|                    if (rc == 0) {
  ------------------
  |  Branch (280:25): [True: 0, False: 0]
  ------------------
  281|      0|                        ssh_message_channel_request_reply_success(msg);
  282|      0|                    } else {
  283|      0|                        ssh_message_reply_default(msg);
  284|      0|                    }
  285|      0|                    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  286|      0|                }
  287|      0|                ssh_callbacks_iterate_end();
  ------------------
  |  |  618|      0|        }                           \
  |  |  619|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (619:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  288|    657|            } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_X11){
  ------------------
  |  Branch (288:24): [True: 0, False: 657]
  ------------------
  289|      0|                ssh_callbacks_iterate(channel->callbacks,
  ------------------
  |  |  598|      0|    do {                                                              \
  |  |  599|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  600|      0|        _cb_type _cb;                                                 \
  |  |  601|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (601:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  602|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  603|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  ------------------
  290|      0|                                      ssh_channel_callbacks,
  291|      0|                                      channel_x11_req_function) {
  292|      0|                    ssh_callbacks_iterate_exec(channel_x11_req_function,
  ------------------
  |  |  612|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  293|      0|                                               session,
  294|      0|                                               channel,
  295|      0|                                               msg->channel_request.x11_single_connection,
  296|      0|                                               msg->channel_request.x11_auth_protocol,
  297|      0|                                               msg->channel_request.x11_auth_cookie,
  298|      0|                                               msg->channel_request.x11_screen_number);
  299|      0|                    ssh_message_channel_request_reply_success(msg);
  300|      0|                    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  301|      0|                }
  302|      0|                ssh_callbacks_iterate_end();
  ------------------
  |  |  618|      0|        }                           \
  |  |  619|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (619:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  303|    657|            } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_WINDOW_CHANGE){
  ------------------
  |  Branch (303:24): [True: 0, False: 657]
  ------------------
  304|      0|                ssh_callbacks_iterate(channel->callbacks,
  ------------------
  |  |  598|      0|    do {                                                              \
  |  |  599|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  600|      0|        _cb_type _cb;                                                 \
  |  |  601|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (601:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  602|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  603|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  ------------------
  305|      0|                                      ssh_channel_callbacks,
  306|      0|                                      channel_pty_window_change_function) {
  307|      0|                    rc = ssh_callbacks_iterate_exec(channel_pty_window_change_function,
  ------------------
  |  |  612|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  308|      0|                                                    session,
  309|      0|                                                    channel,
  310|      0|                                                    msg->channel_request.width,
  311|      0|                                                    msg->channel_request.height,
  312|      0|                                                    msg->channel_request.pxwidth,
  313|      0|                                                    msg->channel_request.pxheight);
  314|      0|                    if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (314:25): [True: 0, False: 0]
  ------------------
  315|      0|                        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  316|      0|                                "Failed to iterate callbacks for window change");
  317|      0|                    }
  318|      0|                    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  319|      0|                }
  320|      0|                ssh_callbacks_iterate_end();
  ------------------
  |  |  618|      0|        }                           \
  |  |  619|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (619:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  321|    657|            } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_EXEC){
  ------------------
  |  Branch (321:24): [True: 657, False: 0]
  ------------------
  322|  1.31k|                ssh_callbacks_iterate(channel->callbacks,
  ------------------
  |  |  598|    657|    do {                                                              \
  |  |  599|    657|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  600|    657|        _cb_type _cb;                                                 \
  |  |  601|    657|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (601:16): [True: 657, False: 0]
  |  |  ------------------
  |  |  602|    657|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  114|    657|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  603|    657|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  547|    657|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|    657|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 657, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 657, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|    657|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 657, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|    657|  )
  |  |  ------------------
  ------------------
  323|  1.31k|                                      ssh_channel_callbacks,
  324|  1.31k|                                      channel_exec_request_function) {
  325|    657|                    rc = ssh_callbacks_iterate_exec(channel_exec_request_function,
  ------------------
  |  |  612|    657|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  326|    657|                                                    session,
  327|    657|                                                    channel,
  328|    657|                                                    msg->channel_request.command);
  329|    657|                    if (rc == 0) {
  ------------------
  |  Branch (329:25): [True: 657, False: 0]
  ------------------
  330|    657|                        ssh_message_channel_request_reply_success(msg);
  331|    657|                    } else {
  332|      0|                        ssh_message_reply_default(msg);
  333|      0|                    }
  334|       |
  335|    657|                    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  336|    657|                }
  337|  1.31k|                ssh_callbacks_iterate_end();
  ------------------
  |  |  618|    657|        }                           \
  |  |  619|    657|    } while(0)
  |  |  ------------------
  |  |  |  Branch (619:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  338|    657|            } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_ENV){
  ------------------
  |  Branch (338:24): [True: 0, False: 0]
  ------------------
  339|      0|                ssh_callbacks_iterate(channel->callbacks,
  ------------------
  |  |  598|      0|    do {                                                              \
  |  |  599|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  600|      0|        _cb_type _cb;                                                 \
  |  |  601|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (601:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  602|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  603|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  ------------------
  340|      0|                                      ssh_channel_callbacks,
  341|      0|                                      channel_env_request_function) {
  342|      0|                    rc = ssh_callbacks_iterate_exec(channel_env_request_function,
  ------------------
  |  |  612|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  343|      0|                                                    session,
  344|      0|                                                    channel,
  345|      0|                                                    msg->channel_request.var_name,
  346|      0|                                                    msg->channel_request.var_value);
  347|      0|                    if (rc == 0) {
  ------------------
  |  Branch (347:25): [True: 0, False: 0]
  ------------------
  348|      0|                        ssh_message_channel_request_reply_success(msg);
  349|      0|                    } else {
  350|      0|                        ssh_message_reply_default(msg);
  351|      0|                    }
  352|      0|                    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  353|      0|                }
  354|      0|                ssh_callbacks_iterate_end();
  ------------------
  |  |  618|      0|        }                           \
  |  |  619|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (619:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  355|      0|            } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_SUBSYSTEM){
  ------------------
  |  Branch (355:24): [True: 0, False: 0]
  ------------------
  356|      0|                ssh_callbacks_iterate(channel->callbacks,
  ------------------
  |  |  598|      0|    do {                                                              \
  |  |  599|      0|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  600|      0|        _cb_type _cb;                                                 \
  |  |  601|      0|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (601:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  602|      0|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  603|      0|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  ------------------
  357|      0|                                      ssh_channel_callbacks,
  358|      0|                                      channel_subsystem_request_function) {
  359|      0|                    rc = ssh_callbacks_iterate_exec(channel_subsystem_request_function,
  ------------------
  |  |  612|      0|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  360|      0|                                                    session,
  361|      0|                                                    channel,
  362|      0|                                                    msg->channel_request.subsystem);
  363|      0|                    if (rc == 0) {
  ------------------
  |  Branch (363:25): [True: 0, False: 0]
  ------------------
  364|      0|                        ssh_message_channel_request_reply_success(msg);
  365|      0|                    } else {
  366|      0|                        ssh_message_reply_default(msg);
  367|      0|                    }
  368|       |
  369|      0|                    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  370|      0|                }
  371|      0|                ssh_callbacks_iterate_end();
  ------------------
  |  |  618|      0|        }                           \
  |  |  619|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (619:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  372|      0|            }
  373|      0|            break;
  374|    657|        case SSH_REQUEST_SERVICE:
  ------------------
  |  Branch (374:9): [True: 657, False: 1.97k]
  ------------------
  375|    657|            if (ssh_callbacks_exists(session->server_callbacks, service_request_function)) {
  ------------------
  |  |  547|    657|#define ssh_callbacks_exists(p,c) (\
  |  |  548|    657|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (548:3): [True: 657, False: 0]
  |  |  |  Branch (548:18): [True: 657, False: 0]
  |  |  ------------------
  |  |  549|    657|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 0, False: 657]
  |  |  ------------------
  |  |  550|    657|  )
  ------------------
  376|      0|                rc = session->server_callbacks->service_request_function(session,
  377|      0|                        msg->service_request.service, session->server_callbacks->userdata);
  378|      0|                if (rc == 0) {
  ------------------
  |  Branch (378:21): [True: 0, False: 0]
  ------------------
  379|      0|                    ssh_message_reply_default(msg);
  380|      0|                } else {
  381|      0|                    ssh_send_disconnect(session);
  382|      0|                }
  383|       |
  384|      0|                return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  385|      0|            }
  386|       |
  387|    657|            return SSH_AGAIN;
  ------------------
  |  |  318|    657|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  388|      0|        case SSH_REQUEST_GLOBAL:
  ------------------
  |  Branch (388:9): [True: 0, False: 2.62k]
  ------------------
  389|      0|            break;
  390|  2.62k|    }
  391|       |
  392|      0|    return SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  393|  2.62k|}

ssh_is_ipaddr_v4:
  430|  2.62k|{
  431|  2.62k|    int rc = -1;
  432|  2.62k|    struct in_addr dest;
  433|       |
  434|  2.62k|    rc = inet_pton(AF_INET, str, &dest);
  435|  2.62k|    if (rc > 0) {
  ------------------
  |  Branch (435:9): [True: 0, False: 2.62k]
  ------------------
  436|      0|        return 1;
  437|      0|    }
  438|       |
  439|  2.62k|    return 0;
  440|  2.62k|}
ssh_is_ipaddr:
  450|  2.62k|{
  451|  2.62k|    int rc = -1;
  452|  2.62k|    char *s = strdup(str);
  453|       |
  454|  2.62k|    if (s == NULL) {
  ------------------
  |  Branch (454:9): [True: 0, False: 2.62k]
  ------------------
  455|      0|        return -1;
  456|      0|    }
  457|  2.62k|    if (strchr(s, ':')) {
  ------------------
  |  Branch (457:9): [True: 0, False: 2.62k]
  ------------------
  458|      0|        struct in6_addr dest6;
  459|      0|        char *network_interface = strchr(s, '%');
  460|       |
  461|       |        /* link-local (IP:v6:addr%ifname). */
  462|      0|        if (network_interface != NULL) {
  ------------------
  |  Branch (462:13): [True: 0, False: 0]
  ------------------
  463|      0|            rc = if_nametoindex(network_interface + 1);
  464|      0|            if (rc == 0) {
  ------------------
  |  Branch (464:17): [True: 0, False: 0]
  ------------------
  465|      0|                free(s);
  466|      0|                return 0;
  467|      0|            }
  468|      0|            *network_interface = '\0';
  469|      0|        }
  470|      0|        rc = inet_pton(AF_INET6, s, &dest6);
  471|      0|        if (rc > 0) {
  ------------------
  |  Branch (471:13): [True: 0, False: 0]
  ------------------
  472|      0|            free(s);
  473|      0|            return 1;
  474|      0|        }
  475|      0|    }
  476|       |
  477|  2.62k|    free(s);
  478|  2.62k|    return ssh_is_ipaddr_v4(str);
  479|  2.62k|}
ssh_get_user_home_dir:
  495|  3.28k|{
  496|  3.28k|    char *szPath = NULL;
  497|       |
  498|       |    /* If used previously, reuse cached value */
  499|  3.28k|    if (session != NULL && session->opts.homedir != NULL) {
  ------------------
  |  Branch (499:9): [True: 2.62k, False: 657]
  |  Branch (499:28): [True: 1.97k, False: 657]
  ------------------
  500|  1.97k|        return strdup(session->opts.homedir);
  501|  1.97k|    }
  502|       |
  503|  1.31k|    szPath = ssh_get_user_home_dir_internal();
  504|  1.31k|    if (szPath == NULL) {
  ------------------
  |  Branch (504:9): [True: 0, False: 1.31k]
  ------------------
  505|      0|        return NULL;
  506|      0|    }
  507|       |
  508|  1.31k|    if (session != NULL) {
  ------------------
  |  Branch (508:9): [True: 657, False: 657]
  ------------------
  509|       |        /* cache it:
  510|       |         * failure is not fatal -- at worst we will just not cache it */
  511|    657|        session->opts.homedir = strdup(szPath);
  512|    657|    }
  513|       |
  514|  1.31k|    return szPath;
  515|  1.31k|}
ssh_lowercase:
  526|  1.31k|{
  527|  1.31k|    char *new = NULL, *p = NULL;
  528|       |
  529|  1.31k|    if (str == NULL) {
  ------------------
  |  Branch (529:9): [True: 0, False: 1.31k]
  ------------------
  530|      0|        return NULL;
  531|      0|    }
  532|       |
  533|  1.31k|    new = strdup(str);
  534|  1.31k|    if (new == NULL) {
  ------------------
  |  Branch (534:9): [True: 0, False: 1.31k]
  ------------------
  535|      0|        return NULL;
  536|      0|    }
  537|       |
  538|  13.1k|    for (p = new; *p; p++) {
  ------------------
  |  Branch (538:19): [True: 11.8k, False: 1.31k]
  ------------------
  539|  11.8k|        *p = tolower(*p);
  ------------------
  |  Branch (539:14): [True: 0, False: 0]
  |  Branch (539:14): [True: 0, False: 0]
  |  Branch (539:14): [Folded, False: 11.8k]
  ------------------
  540|  11.8k|    }
  541|       |
  542|  1.31k|    return new;
  543|  1.31k|}
ssh_list_new:
  865|  13.1k|{
  866|  13.1k|    struct ssh_list *ret = malloc(sizeof(struct ssh_list));
  867|  13.1k|    if (ret == NULL) {
  ------------------
  |  Branch (867:9): [True: 0, False: 13.1k]
  ------------------
  868|      0|        return NULL;
  869|      0|    }
  870|  13.1k|    ret->root = ret->end = NULL;
  871|  13.1k|    return ret;
  872|  13.1k|}
ssh_list_free:
  882|  13.1k|{
  883|  13.1k|    struct ssh_iterator *ptr = NULL, *next = NULL;
  884|  13.1k|    if (!list)
  ------------------
  |  Branch (884:9): [True: 0, False: 13.1k]
  ------------------
  885|      0|        return;
  886|  13.1k|    ptr = list->root;
  887|  15.7k|    while (ptr) {
  ------------------
  |  Branch (887:12): [True: 2.62k, False: 13.1k]
  ------------------
  888|  2.62k|        next = ptr->next;
  889|  2.62k|        SAFE_FREE(ptr);
  ------------------
  |  |  373|  2.62k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.62k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.62k]
  |  |  ------------------
  ------------------
  890|  2.62k|        ptr = next;
  891|  2.62k|    }
  892|       |    SAFE_FREE(list);
  ------------------
  |  |  373|  13.1k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 13.1k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 13.1k]
  |  |  ------------------
  ------------------
  893|  13.1k|}
ssh_list_get_iterator:
  903|  35.0k|{
  904|  35.0k|    if (!list)
  ------------------
  |  Branch (904:9): [True: 9.53k, False: 25.5k]
  ------------------
  905|  9.53k|        return NULL;
  906|  25.5k|    return list->root;
  907|  35.0k|}
ssh_list_find:
  918|  2.62k|{
  919|  2.62k|    struct ssh_iterator *it = NULL;
  920|       |
  921|  3.94k|    for (it = ssh_list_get_iterator(list); it != NULL ; it = it->next)
  ------------------
  |  Branch (921:44): [True: 3.94k, False: 0]
  ------------------
  922|  3.94k|        if (it->data == value)
  ------------------
  |  Branch (922:13): [True: 2.62k, False: 1.31k]
  ------------------
  923|  2.62k|            return it;
  924|      0|    return NULL;
  925|  2.62k|}
ssh_list_append:
  969|  9.19k|{
  970|  9.19k|  struct ssh_iterator *iterator = NULL;
  971|       |
  972|  9.19k|  if (list == NULL) {
  ------------------
  |  Branch (972:7): [True: 0, False: 9.19k]
  ------------------
  973|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  974|      0|  }
  975|       |
  976|  9.19k|  iterator = ssh_iterator_new(data);
  977|  9.19k|  if (iterator == NULL) {
  ------------------
  |  Branch (977:7): [True: 0, False: 9.19k]
  ------------------
  978|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  979|      0|  }
  980|       |
  981|  9.19k|  if(!list->end){
  ------------------
  |  Branch (981:6): [True: 3.94k, False: 5.25k]
  ------------------
  982|       |    /* list is empty */
  983|  3.94k|    list->root=list->end=iterator;
  984|  5.25k|  } else {
  985|       |    /* put it on end of list */
  986|  5.25k|    list->end->next=iterator;
  987|  5.25k|    list->end=iterator;
  988|  5.25k|  }
  989|  9.19k|  return SSH_OK;
  ------------------
  |  |  316|  9.19k|#define SSH_OK 0     /* No error */
  ------------------
  990|  9.19k|}
ssh_list_prepend:
 1001|  1.97k|{
 1002|  1.97k|  struct ssh_iterator *it = NULL;
 1003|       |
 1004|  1.97k|  if (list == NULL) {
  ------------------
  |  Branch (1004:7): [True: 0, False: 1.97k]
  ------------------
 1005|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1006|      0|  }
 1007|       |
 1008|  1.97k|  it = ssh_iterator_new(data);
 1009|  1.97k|  if (it == NULL) {
  ------------------
  |  Branch (1009:7): [True: 0, False: 1.97k]
  ------------------
 1010|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1011|      0|  }
 1012|       |
 1013|  1.97k|  if (list->end == NULL) {
  ------------------
  |  Branch (1013:7): [True: 1.97k, False: 1]
  ------------------
 1014|       |    /* list is empty */
 1015|  1.97k|    list->root = list->end = it;
 1016|  1.97k|  } else {
 1017|       |    /* set as new root */
 1018|      1|    it->next = list->root;
 1019|      1|    list->root = it;
 1020|      1|  }
 1021|       |
 1022|  1.97k|  return SSH_OK;
  ------------------
  |  |  316|  1.97k|#define SSH_OK 0     /* No error */
  ------------------
 1023|  1.97k|}
ssh_list_remove:
 1032|  3.28k|{
 1033|  3.28k|    struct ssh_iterator *ptr = NULL, *prev = NULL;
 1034|       |
 1035|  3.28k|    if (list == NULL) {
  ------------------
  |  Branch (1035:9): [True: 0, False: 3.28k]
  ------------------
 1036|      0|        return;
 1037|      0|    }
 1038|       |
 1039|  3.28k|    prev = NULL;
 1040|  3.28k|    ptr = list->root;
 1041|  4.60k|    while (ptr && ptr != iterator) {
  ------------------
  |  Branch (1041:12): [True: 3.94k, False: 657]
  |  Branch (1041:19): [True: 1.31k, False: 2.62k]
  ------------------
 1042|  1.31k|        prev = ptr;
 1043|  1.31k|        ptr = ptr->next;
 1044|  1.31k|    }
 1045|  3.28k|    if (!ptr) {
  ------------------
  |  Branch (1045:9): [True: 657, False: 2.62k]
  ------------------
 1046|       |        /* we did not find the element */
 1047|    657|        return;
 1048|    657|    }
 1049|       |    /* unlink it */
 1050|  2.62k|    if (prev)
  ------------------
  |  Branch (1050:9): [True: 1.31k, False: 1.31k]
  ------------------
 1051|  1.31k|        prev->next = ptr->next;
 1052|       |    /* if iterator was the head */
 1053|  2.62k|    if (list->root == iterator)
  ------------------
  |  Branch (1053:9): [True: 1.31k, False: 1.31k]
  ------------------
 1054|  1.31k|        list->root = iterator->next;
 1055|       |    /* if iterator was the tail */
 1056|  2.62k|    if (list->end == iterator)
  ------------------
  |  Branch (1056:9): [True: 2.62k, False: 1]
  ------------------
 1057|  2.62k|        list->end = prev;
 1058|       |    SAFE_FREE(iterator);
  ------------------
  |  |  373|  2.62k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.62k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.62k]
  |  |  ------------------
  ------------------
 1059|  2.62k|}
_ssh_list_pop_head:
 1073|  15.1k|{
 1074|  15.1k|  struct ssh_iterator *iterator = NULL;
 1075|  15.1k|  const void *data = NULL;
 1076|       |
 1077|  15.1k|  if (list == NULL) {
  ------------------
  |  Branch (1077:7): [True: 0, False: 15.1k]
  ------------------
 1078|      0|      return NULL;
 1079|      0|  }
 1080|       |
 1081|  15.1k|  iterator = list->root;
 1082|  15.1k|  if (iterator == NULL) {
  ------------------
  |  Branch (1082:7): [True: 9.19k, False: 5.91k]
  ------------------
 1083|  9.19k|      return NULL;
 1084|  9.19k|  }
 1085|  5.91k|  data=iterator->data;
 1086|  5.91k|  list->root=iterator->next;
 1087|  5.91k|  if(list->end==iterator)
  ------------------
  |  Branch (1087:6): [True: 1.97k, False: 3.94k]
  ------------------
 1088|  1.97k|    list->end=NULL;
 1089|       |  SAFE_FREE(iterator);
  ------------------
  |  |  373|  5.91k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 5.91k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 5.91k]
  |  |  ------------------
  ------------------
 1090|  5.91k|  return data;
 1091|  15.1k|}
ssh_path_expand_tilde:
 1309|  3.28k|{
 1310|  3.28k|    char *h = NULL, *r = NULL;
 1311|  3.28k|    const char *p = NULL;
 1312|  3.28k|    size_t ld;
 1313|  3.28k|    size_t lh = 0;
 1314|       |
 1315|  3.28k|    if (d[0] != '~') {
  ------------------
  |  Branch (1315:9): [True: 2.62k, False: 657]
  ------------------
 1316|  2.62k|        return strdup(d);
 1317|  2.62k|    }
 1318|    657|    d++;
 1319|       |
 1320|       |    /* handle ~user/path */
 1321|    657|    p = strchr(d, '/');
 1322|    657|    if (p != NULL && p > d) {
  ------------------
  |  Branch (1322:9): [True: 657, False: 0]
  |  Branch (1322:22): [True: 0, False: 657]
  ------------------
 1323|       |#ifdef _WIN32
 1324|       |        return strdup(d);
 1325|       |#else
 1326|      0|        struct passwd *pw = NULL;
 1327|      0|        size_t s = p - d;
 1328|      0|        char u[128];
 1329|       |
 1330|      0|        if (s >= sizeof(u)) {
  ------------------
  |  Branch (1330:13): [True: 0, False: 0]
  ------------------
 1331|      0|            return NULL;
 1332|      0|        }
 1333|      0|        memcpy(u, d, s);
 1334|      0|        u[s] = '\0';
 1335|      0|        pw = getpwnam(u);
 1336|      0|        if (pw == NULL) {
  ------------------
  |  Branch (1336:13): [True: 0, False: 0]
  ------------------
 1337|      0|            return NULL;
 1338|      0|        }
 1339|      0|        ld = strlen(p);
 1340|      0|        h = strdup(pw->pw_dir);
 1341|      0|#endif
 1342|    657|    } else {
 1343|    657|        ld = strlen(d);
 1344|    657|        p = (char *) d;
 1345|    657|        h = ssh_get_user_home_dir(NULL);
 1346|    657|    }
 1347|    657|    if (h == NULL) {
  ------------------
  |  Branch (1347:9): [True: 0, False: 657]
  ------------------
 1348|      0|        return NULL;
 1349|      0|    }
 1350|    657|    lh = strlen(h);
 1351|       |
 1352|    657|    r = malloc(ld + lh + 1);
 1353|    657|    if (r == NULL) {
  ------------------
  |  Branch (1353:9): [True: 0, False: 657]
  ------------------
 1354|      0|        SAFE_FREE(h);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1355|      0|        return NULL;
 1356|      0|    }
 1357|       |
 1358|    657|    if (lh > 0) {
  ------------------
  |  Branch (1358:9): [True: 657, False: 0]
  ------------------
 1359|    657|        memcpy(r, h, lh);
 1360|    657|    }
 1361|    657|    SAFE_FREE(h);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
 1362|    657|    memcpy(r + lh, p, ld + 1);
 1363|       |
 1364|    657|    return r;
 1365|    657|}
ssh_path_expand_escape:
 1699|  2.62k|{
 1700|       |    return ssh_path_expand_internal(session, s, false);
 1701|  2.62k|}
ssh_analyze_banner:
 1734|  1.31k|{
 1735|  1.31k|    const char *banner = NULL;
 1736|  1.31k|    const char *openssh = NULL;
 1737|  1.31k|    const char *ios = NULL;
 1738|       |
 1739|  1.31k|    if (server) {
  ------------------
  |  Branch (1739:9): [True: 657, False: 657]
  ------------------
 1740|    657|        banner = session->clientbanner;
 1741|    657|    } else {
 1742|    657|        banner = session->serverbanner;
 1743|    657|    }
 1744|       |
 1745|  1.31k|    if (banner == NULL) {
  ------------------
  |  Branch (1745:9): [True: 0, False: 1.31k]
  ------------------
 1746|      0|        ssh_set_error(session, SSH_FATAL, "Invalid banner");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1747|      0|        return -1;
 1748|      0|    }
 1749|       |
 1750|       |    /*
 1751|       |     * Typical banners e.g. are:
 1752|       |     *
 1753|       |     * SSH-1.5-openSSH_5.4
 1754|       |     * SSH-1.99-openSSH_3.0
 1755|       |     *
 1756|       |     * SSH-2.0-something
 1757|       |     * 012345678901234567890
 1758|       |     */
 1759|  1.31k|    if (strlen(banner) < 6 ||
  ------------------
  |  Branch (1759:9): [True: 0, False: 1.31k]
  ------------------
 1760|  1.31k|        strncmp(banner, "SSH-", 4) != 0) {
  ------------------
  |  Branch (1760:9): [True: 0, False: 1.31k]
  ------------------
 1761|      0|          ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1762|      0|          return -1;
 1763|      0|    }
 1764|       |
 1765|  1.31k|    SSH_LOG(SSH_LOG_DEBUG, "Analyzing banner: %s", banner);
  ------------------
  |  |  281|  1.31k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1766|       |
 1767|  1.31k|    switch (banner[4]) {
 1768|  1.31k|        case '2':
  ------------------
  |  Branch (1768:9): [True: 1.31k, False: 0]
  ------------------
 1769|  1.31k|            break;
 1770|      0|        case '1':
  ------------------
  |  Branch (1770:9): [True: 0, False: 1.31k]
  ------------------
 1771|      0|            if (strlen(banner) > 6) {
  ------------------
  |  Branch (1771:17): [True: 0, False: 0]
  ------------------
 1772|      0|                if (banner[6] == '9') {
  ------------------
  |  Branch (1772:21): [True: 0, False: 0]
  ------------------
 1773|      0|                    break;
 1774|      0|                }
 1775|      0|            }
 1776|      0|            FALL_THROUGH;
  ------------------
  |  |  494|      0|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1777|      0|        default:
  ------------------
  |  Branch (1777:9): [True: 0, False: 1.31k]
  ------------------
 1778|      0|            ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1779|      0|            return -1;
 1780|  1.31k|    }
 1781|       |
 1782|       |    /* Make a best-effort to extract OpenSSH version numbers. */
 1783|  1.31k|    openssh = strstr(banner, "OpenSSH");
 1784|  1.31k|    if (openssh != NULL) {
  ------------------
  |  Branch (1784:9): [True: 0, False: 1.31k]
  ------------------
 1785|      0|        char *tmp = NULL;
 1786|      0|        unsigned long int major = 0UL;
 1787|      0|        unsigned long int minor = 0UL;
 1788|      0|        int off = 0;
 1789|       |
 1790|       |        /*
 1791|       |         * The banner is typical:
 1792|       |         * OpenSSH_5.4
 1793|       |         * 012345678901234567890
 1794|       |         */
 1795|      0|        if (strlen(openssh) > 9) {
  ------------------
  |  Branch (1795:13): [True: 0, False: 0]
  ------------------
 1796|      0|            errno = 0;
 1797|      0|            major = strtoul(openssh + 8, &tmp, 10);
 1798|      0|            if ((tmp == (openssh + 8)) ||
  ------------------
  |  Branch (1798:17): [True: 0, False: 0]
  ------------------
 1799|      0|                ((errno == ERANGE) && (major == ULONG_MAX)) ||
  ------------------
  |  Branch (1799:18): [True: 0, False: 0]
  |  Branch (1799:39): [True: 0, False: 0]
  ------------------
 1800|      0|                ((errno != 0) && (major == 0)) ||
  ------------------
  |  Branch (1800:18): [True: 0, False: 0]
  |  Branch (1800:34): [True: 0, False: 0]
  ------------------
 1801|      0|                ((major < 1) || (major > 100))) {
  ------------------
  |  Branch (1801:18): [True: 0, False: 0]
  |  Branch (1801:33): [True: 0, False: 0]
  ------------------
 1802|       |                /* invalid major */
 1803|      0|                errno = 0;
 1804|      0|                goto done;
 1805|      0|            }
 1806|       |
 1807|      0|            errno = 0;
 1808|      0|            off = major >= 10 ? 11 : 10;
  ------------------
  |  Branch (1808:19): [True: 0, False: 0]
  ------------------
 1809|      0|            minor = strtoul(openssh + off, &tmp, 10);
 1810|      0|            if ((tmp == (openssh + off)) ||
  ------------------
  |  Branch (1810:17): [True: 0, False: 0]
  ------------------
 1811|      0|                ((errno == ERANGE) && (major == ULONG_MAX)) ||
  ------------------
  |  Branch (1811:18): [True: 0, False: 0]
  |  Branch (1811:39): [True: 0, False: 0]
  ------------------
 1812|      0|                ((errno != 0) && (major == 0)) ||
  ------------------
  |  Branch (1812:18): [True: 0, False: 0]
  |  Branch (1812:34): [True: 0, False: 0]
  ------------------
 1813|      0|                (minor > 100)) {
  ------------------
  |  Branch (1813:17): [True: 0, False: 0]
  ------------------
 1814|       |                /* invalid minor */
 1815|      0|                errno = 0;
 1816|      0|                goto done;
 1817|      0|            }
 1818|       |
 1819|      0|            session->openssh = SSH_VERSION_INT(((int) major), ((int) minor), 0);
  ------------------
  |  |   25|      0|#define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
  ------------------
 1820|       |
 1821|      0|            SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1822|      0|                    "We are talking to an OpenSSH %s version: %lu.%lu (%x)",
 1823|      0|                    server ? "client" : "server",
 1824|      0|                    major, minor, session->openssh);
 1825|      0|        }
 1826|      0|    }
 1827|       |    /* Cisco devices have odd scp implementation which breaks */
 1828|  1.31k|    ios = strstr(banner, "Cisco");
 1829|  1.31k|    if (ios != NULL) {
  ------------------
  |  Branch (1829:9): [True: 0, False: 1.31k]
  ------------------
 1830|      0|        session->flags |= SSH_SESSION_FLAG_SCP_QUOTING_BROKEN;
  ------------------
  |  |   95|      0|#define SSH_SESSION_FLAG_SCP_QUOTING_BROKEN 0x0040
  ------------------
 1831|      0|    }
 1832|       |
 1833|  1.31k|done:
 1834|  1.31k|    return 0;
 1835|  1.31k|}
ssh_timestamp_init:
 1850|  95.0k|{
 1851|  95.0k|#ifdef HAVE_CLOCK_GETTIME
 1852|  95.0k|  struct timespec tp;
 1853|  95.0k|  clock_gettime(CLOCK, &tp);
  ------------------
  |  | 1839|  95.0k|#define CLOCK CLOCK_MONOTONIC
  ------------------
 1854|  95.0k|  ts->useconds = tp.tv_nsec / 1000;
 1855|       |#else
 1856|       |  struct timeval tp;
 1857|       |  gettimeofday(&tp, NULL);
 1858|       |  ts->useconds = tp.tv_usec;
 1859|       |#endif
 1860|  95.0k|  ts->seconds = tp.tv_sec;
 1861|  95.0k|}
ssh_make_milliseconds:
 1898|  11.9k|{
 1899|  11.9k|    unsigned long res;
 1900|       |
 1901|  11.9k|    if (sec == (unsigned long)SSH_TIMEOUT_INFINITE) {
  ------------------
  |  |   99|  11.9k|#define SSH_TIMEOUT_INFINITE -1
  ------------------
  |  Branch (1901:9): [True: 0, False: 11.9k]
  ------------------
 1902|      0|        return SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|      0|#define SSH_TIMEOUT_INFINITE -1
  ------------------
 1903|      0|    }
 1904|  11.9k|    if (sec > (unsigned long)INT_MAX / 1000) {
  ------------------
  |  Branch (1904:9): [True: 0, False: 11.9k]
  ------------------
 1905|      0|        return INT_MAX;
 1906|      0|    }
 1907|       |
 1908|  11.9k|    res = usec / 1000;
 1909|  11.9k|    res += (sec * 1000);
 1910|  11.9k|    if (res == 0) {
  ------------------
  |  Branch (1910:9): [True: 0, False: 11.9k]
  ------------------
 1911|      0|        res = 10 * 1000; /* use a reasonable default value in case
 1912|       |                          * SSH_OPTIONS_TIMEOUT is not set in options. */
 1913|      0|    }
 1914|       |
 1915|  11.9k|    if (res > INT_MAX) {
  ------------------
  |  Branch (1915:9): [True: 0, False: 11.9k]
  ------------------
 1916|      0|        return INT_MAX;
 1917|  11.9k|    } else {
 1918|  11.9k|        return (int)res;
 1919|  11.9k|    }
 1920|  11.9k|}
ssh_timeout_elapsed:
 1933|  17.8k|{
 1934|  17.8k|    struct ssh_timestamp now;
 1935|       |
 1936|  17.8k|    switch(timeout) {
 1937|      0|        case -2: /*
  ------------------
  |  Branch (1937:9): [True: 0, False: 17.8k]
  ------------------
 1938|       |                  * -2 means user-defined timeout as available in
 1939|       |                  * session->timeout, session->timeout_usec.
 1940|       |                  */
 1941|      0|            SSH_LOG(SSH_LOG_DEBUG, "ssh_timeout_elapsed called with -2. this needs to "
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1942|      0|                            "be fixed. please set a breakpoint on misc.c:%d and "
 1943|      0|                            "fix the caller\n", __LINE__);
 1944|      0|            return 0;
 1945|      0|        case -1: /* -1 means infinite timeout */
  ------------------
  |  Branch (1945:9): [True: 0, False: 17.8k]
  ------------------
 1946|      0|            return 0;
 1947|      0|        case 0: /* 0 means no timeout */
  ------------------
  |  Branch (1947:9): [True: 0, False: 17.8k]
  ------------------
 1948|      0|            return 1;
 1949|  17.8k|        default:
  ------------------
  |  Branch (1949:9): [True: 17.8k, False: 0]
  ------------------
 1950|  17.8k|            break;
 1951|  17.8k|    }
 1952|       |
 1953|  17.8k|    ssh_timestamp_init(&now);
 1954|       |
 1955|  17.8k|    return (ssh_timestamp_difference(ts,&now) >= timeout);
 1956|  17.8k|}
ssh_timeout_update:
 1966|  41.5k|{
 1967|  41.5k|  struct ssh_timestamp now;
 1968|  41.5k|  int ms, ret;
 1969|  41.5k|  if (timeout <= 0) {
  ------------------
  |  Branch (1969:7): [True: 0, False: 41.5k]
  ------------------
 1970|      0|      return timeout;
 1971|      0|  }
 1972|  41.5k|  ssh_timestamp_init(&now);
 1973|  41.5k|  ms = ssh_timestamp_difference(ts,&now);
 1974|  41.5k|  if(ms < 0)
  ------------------
  |  Branch (1974:6): [True: 0, False: 41.5k]
  ------------------
 1975|      0|    ms = 0;
 1976|  41.5k|  ret = timeout - ms;
 1977|  18.4E|  return ret >= 0 ? ret: 0;
  ------------------
  |  Branch (1977:10): [True: 41.5k, False: 18.4E]
  ------------------
 1978|  41.5k|}
ssh_quote_file_name:
 2078|    657|{
 2079|    657|    const char *src = NULL;
 2080|    657|    char *dst = NULL;
 2081|    657|    size_t required_buf_len;
 2082|       |
 2083|    657|    enum ssh_quote_state_e state = NO_QUOTE;
 2084|       |
 2085|    657|    if (file_name == NULL || buf == NULL || buf_len == 0) {
  ------------------
  |  Branch (2085:9): [True: 0, False: 657]
  |  Branch (2085:30): [True: 0, False: 657]
  |  Branch (2085:45): [True: 0, False: 657]
  ------------------
 2086|      0|        SSH_LOG(SSH_LOG_TRACE, "Invalid parameter");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2087|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2088|      0|    }
 2089|       |
 2090|       |    /* Only allow file names smaller than 32kb. */
 2091|    657|    if (strlen(file_name) > 32 * 1024) {
  ------------------
  |  Branch (2091:9): [True: 0, False: 657]
  ------------------
 2092|      0|        SSH_LOG(SSH_LOG_TRACE, "File name too long");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2093|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2094|      0|    }
 2095|       |
 2096|       |    /* Paranoia check */
 2097|    657|    required_buf_len = (size_t)3 * strlen(file_name) + 1;
 2098|    657|    if (required_buf_len > buf_len) {
  ------------------
  |  Branch (2098:9): [True: 0, False: 657]
  ------------------
 2099|      0|        SSH_LOG(SSH_LOG_TRACE, "Buffer too small");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2100|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2101|      0|    }
 2102|       |
 2103|    657|    src = file_name;
 2104|    657|    dst = buf;
 2105|       |
 2106|  6.57k|    while ((*src != '\0')) {
  ------------------
  |  Branch (2106:12): [True: 5.91k, False: 657]
  ------------------
 2107|  5.91k|        switch (*src) {
 2108|       |
 2109|       |        /* The '\'' char is double quoted */
 2110|       |
 2111|      0|        case '\'':
  ------------------
  |  Branch (2111:9): [True: 0, False: 5.91k]
  ------------------
 2112|      0|            switch (state) {
 2113|      0|            case NO_QUOTE:
  ------------------
  |  Branch (2113:13): [True: 0, False: 0]
  ------------------
 2114|       |                /* Start a new double quoted string. The '\'' char will be
 2115|       |                 * copied to the beginning of it at the end of the loop. */
 2116|      0|                *dst++ = '"';
 2117|      0|                break;
 2118|      0|            case SINGLE_QUOTE:
  ------------------
  |  Branch (2118:13): [True: 0, False: 0]
  ------------------
 2119|       |                /* Close the current single quoted string and start a new double
 2120|       |                 * quoted string. The '\'' char will be copied to the beginning
 2121|       |                 * of it at the end of the loop. */
 2122|      0|                *dst++ = '\'';
 2123|      0|                *dst++ = '"';
 2124|      0|                break;
 2125|      0|            case DOUBLE_QUOTE:
  ------------------
  |  Branch (2125:13): [True: 0, False: 0]
  ------------------
 2126|       |                /* If already in the double quoted string, keep copying the
 2127|       |                 * sequence of chars. */
 2128|      0|                break;
 2129|      0|            default:
  ------------------
  |  Branch (2129:13): [True: 0, False: 0]
  ------------------
 2130|       |                /* Should never be reached */
 2131|      0|                goto error;
 2132|      0|            }
 2133|       |
 2134|       |            /* When the '\'' char is found, the resulting state will be
 2135|       |             * DOUBLE_QUOTE in any case*/
 2136|      0|            state = DOUBLE_QUOTE;
 2137|      0|            break;
 2138|       |
 2139|       |        /* The '!' char is replaced by unquoted "\!" */
 2140|       |
 2141|      0|        case '!':
  ------------------
  |  Branch (2141:9): [True: 0, False: 5.91k]
  ------------------
 2142|      0|            switch (state) {
 2143|      0|            case NO_QUOTE:
  ------------------
  |  Branch (2143:13): [True: 0, False: 0]
  ------------------
 2144|       |                /* The '!' char is interpreted in some shells (e.g. CSH) even
 2145|       |                 * when is quoted with single quotes.  Replace it with unquoted
 2146|       |                 * "\!" which is correctly interpreted as the '!' character. */
 2147|      0|                *dst++ = '\\';
 2148|      0|                break;
 2149|      0|            case SINGLE_QUOTE:
  ------------------
  |  Branch (2149:13): [True: 0, False: 0]
  ------------------
 2150|       |                /* Close the currently quoted string and replace '!' for unquoted
 2151|       |                 * "\!" */
 2152|      0|                *dst++ = '\'';
 2153|      0|                *dst++ = '\\';
 2154|      0|                break;
 2155|      0|            case DOUBLE_QUOTE:
  ------------------
  |  Branch (2155:13): [True: 0, False: 0]
  ------------------
 2156|       |                /* Close currently quoted string and replace  "!" for unquoted
 2157|       |                 * "\!" */
 2158|      0|                *dst++ = '"';
 2159|      0|                *dst++ = '\\';
 2160|      0|                break;
 2161|      0|            default:
  ------------------
  |  Branch (2161:13): [True: 0, False: 0]
  ------------------
 2162|       |                /* Should never be reached */
 2163|      0|                goto error;
 2164|      0|            }
 2165|       |
 2166|       |            /* When the '!' char is found, the resulting state will be NO_QUOTE
 2167|       |             * in any case*/
 2168|      0|            state = NO_QUOTE;
 2169|      0|            break;
 2170|       |
 2171|       |        /* Ordinary chars are single quoted */
 2172|       |
 2173|  5.91k|        default:
  ------------------
  |  Branch (2173:9): [True: 5.91k, False: 0]
  ------------------
 2174|  5.91k|            switch (state) {
 2175|    657|            case NO_QUOTE:
  ------------------
  |  Branch (2175:13): [True: 657, False: 5.25k]
  ------------------
 2176|       |                /* Start a new single quoted string */
 2177|    657|                *dst++ = '\'';
 2178|    657|                break;
 2179|  5.25k|            case SINGLE_QUOTE:
  ------------------
  |  Branch (2179:13): [True: 5.25k, False: 657]
  ------------------
 2180|       |                /* If already in the single quoted string, keep copying the
 2181|       |                 * sequence of chars. */
 2182|  5.25k|                break;
 2183|      0|            case DOUBLE_QUOTE:
  ------------------
  |  Branch (2183:13): [True: 0, False: 5.91k]
  ------------------
 2184|       |                /* Close current double quoted string and start a new single
 2185|       |                 * quoted string. */
 2186|      0|                *dst++ = '"';
 2187|      0|                *dst++ = '\'';
 2188|      0|                break;
 2189|      0|            default:
  ------------------
  |  Branch (2189:13): [True: 0, False: 5.91k]
  ------------------
 2190|       |                /* Should never be reached */
 2191|      0|                goto error;
 2192|  5.91k|            }
 2193|       |
 2194|       |            /* When an ordinary char is found, the resulting state will be
 2195|       |             * SINGLE_QUOTE in any case*/
 2196|  5.91k|            state = SINGLE_QUOTE;
 2197|  5.91k|            break;
 2198|  5.91k|        }
 2199|       |
 2200|       |        /* Copy the current char to output */
 2201|  5.91k|        *dst++ = *src++;
 2202|  5.91k|    }
 2203|       |
 2204|       |    /* Close the quoted string when necessary */
 2205|       |
 2206|    657|    switch (state) {
 2207|      0|    case NO_QUOTE:
  ------------------
  |  Branch (2207:5): [True: 0, False: 657]
  ------------------
 2208|       |        /* No open string */
 2209|      0|        break;
 2210|    657|    case SINGLE_QUOTE:
  ------------------
  |  Branch (2210:5): [True: 657, False: 0]
  ------------------
 2211|       |        /* Close current single quoted string */
 2212|    657|        *dst++ = '\'';
 2213|    657|        break;
 2214|      0|    case DOUBLE_QUOTE:
  ------------------
  |  Branch (2214:5): [True: 0, False: 657]
  ------------------
 2215|       |        /* Close current double quoted string */
 2216|      0|        *dst++ = '"';
 2217|      0|        break;
 2218|      0|    default:
  ------------------
  |  Branch (2218:5): [True: 0, False: 657]
  ------------------
 2219|       |        /* Should never be reached */
 2220|      0|        goto error;
 2221|    657|    }
 2222|       |
 2223|       |    /* Put the string terminator */
 2224|    657|    *dst = '\0';
 2225|       |
 2226|    657|    return (int)(dst - buf);
 2227|       |
 2228|      0|error:
 2229|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2230|    657|}
ssh_strerror:
 2396|  3.28k|{
 2397|       |#if ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE)
 2398|       |    /* GNU extension on Linux */
 2399|       |    return strerror_r(err_num, buf, buflen);
 2400|       |#else
 2401|  3.28k|    int rv;
 2402|       |
 2403|       |#if defined(_WIN32)
 2404|       |    rv = strerror_s(buf, buflen, err_num);
 2405|       |#else
 2406|       |    /* POSIX version available for example on FreeBSD or in musl libc */
 2407|  3.28k|    rv = strerror_r(err_num, buf, buflen);
 2408|  3.28k|#endif /* _WIN32 */
 2409|       |
 2410|       |    /* make sure the buffer is initialized and terminated with NULL */
 2411|  3.28k|    if (-rv == ERANGE) {
  ------------------
  |  Branch (2411:9): [True: 0, False: 3.28k]
  ------------------
 2412|      0|        buf[0] = '\0';
 2413|      0|    }
 2414|  3.28k|    return buf;
 2415|  3.28k|#endif /* ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE) */
 2416|  3.28k|}
ssh_check_hostname_syntax:
 2547|    657|{
 2548|    657|    char *it = NULL, *s = NULL, *buf = NULL;
 2549|    657|    size_t it_len;
 2550|    657|    char c;
 2551|       |
 2552|    657|    if (hostname == NULL || strlen(hostname) == 0) {
  ------------------
  |  Branch (2552:9): [True: 0, False: 657]
  |  Branch (2552:29): [True: 0, False: 657]
  ------------------
 2553|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2554|      0|    }
 2555|       |
 2556|       |    /* strtok_r writes into the string, keep the input clean */
 2557|    657|    s = strdup(hostname);
 2558|    657|    if (s == NULL) {
  ------------------
  |  Branch (2558:9): [True: 0, False: 657]
  ------------------
 2559|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2560|      0|    }
 2561|       |
 2562|    657|    it = strtok_r(s, ".", &buf);
 2563|       |    /* if the token has 0 length */
 2564|    657|    if (it == NULL) {
  ------------------
  |  Branch (2564:9): [True: 0, False: 657]
  ------------------
 2565|      0|        free(s);
 2566|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2567|      0|    }
 2568|    657|    do {
 2569|    657|        it_len = strlen(it);
 2570|    657|        if (it_len > ARPA_DOMAIN_MAX_LEN ||
  ------------------
  |  |  100|  1.31k|#define ARPA_DOMAIN_MAX_LEN 63
  ------------------
  |  Branch (2570:13): [True: 0, False: 657]
  ------------------
 2571|       |            /* the first char must be a letter, but some virtual urls start
 2572|       |             * with a number */
 2573|    657|            isalnum(it[0]) == 0 ||
  ------------------
  |  Branch (2573:13): [True: 0, False: 657]
  ------------------
 2574|    657|            isalnum(it[it_len - 1]) == 0) {
  ------------------
  |  Branch (2574:13): [True: 0, False: 657]
  ------------------
 2575|      0|            free(s);
 2576|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2577|      0|        }
 2578|  6.57k|        while (*it != '\0') {
  ------------------
  |  Branch (2578:16): [True: 5.91k, False: 657]
  ------------------
 2579|  5.91k|            c = *it;
 2580|       |            /* the "." is allowed too, but tokenization removes it from the
 2581|       |             * string */
 2582|  5.91k|            if (isalnum(c) == 0 && c != '-') {
  ------------------
  |  Branch (2582:17): [True: 0, False: 5.91k]
  |  Branch (2582:36): [True: 0, False: 0]
  ------------------
 2583|      0|                free(s);
 2584|      0|                return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2585|      0|            }
 2586|  5.91k|            it++;
 2587|  5.91k|        }
 2588|    657|    } while ((it = strtok_r(NULL, ".", &buf)) != NULL);
  ------------------
  |  Branch (2588:14): [True: 0, False: 657]
  ------------------
 2589|       |
 2590|    657|    free(s);
 2591|       |
 2592|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
 2593|    657|}
ssh_check_username_syntax:
 2606|    657|{
 2607|    657|    size_t username_len;
 2608|       |
 2609|    657|    if (username == NULL || *username == '-') {
  ------------------
  |  Branch (2609:9): [True: 0, False: 657]
  |  Branch (2609:29): [True: 0, False: 657]
  ------------------
 2610|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2611|      0|    }
 2612|       |
 2613|    657|    username_len = strlen(username);
 2614|    657|    if (username_len == 0 || username[username_len - 1] == '\\' ||
  ------------------
  |  Branch (2614:9): [True: 0, False: 657]
  |  Branch (2614:30): [True: 0, False: 657]
  ------------------
 2615|    657|        strpbrk(username, "'`\";&<>|(){}") != NULL) {
  ------------------
  |  Branch (2615:9): [True: 0, False: 657]
  ------------------
 2616|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2617|      0|    }
 2618|  3.28k|    for (size_t i = 0; i < username_len; i++) {
  ------------------
  |  Branch (2618:24): [True: 2.62k, False: 657]
  ------------------
 2619|  2.62k|        if (isspace(username[i]) != 0 && username[i + 1] == '-') {
  ------------------
  |  Branch (2619:13): [True: 0, False: 2.62k]
  |  Branch (2619:42): [True: 0, False: 0]
  ------------------
 2620|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2621|      0|        }
 2622|  2.62k|    }
 2623|       |
 2624|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
 2625|    657|}
ssh_proxyjumps_free:
 2637|  1.31k|{
 2638|  1.31k|    struct ssh_jump_info_struct *jump = NULL;
 2639|       |
 2640|  1.31k|    for (jump =
 2641|  1.31k|             ssh_list_pop_head(struct ssh_jump_info_struct *, proxy_jump_list);
  ------------------
  |  |  122|  1.31k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2642|  1.31k|         jump != NULL;
  ------------------
  |  Branch (2642:10): [True: 0, False: 1.31k]
  ------------------
 2643|  1.31k|         jump = ssh_list_pop_head(struct ssh_jump_info_struct *,
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2644|  1.31k|                                  proxy_jump_list)) {
 2645|      0|        SAFE_FREE(jump->hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2646|      0|        SAFE_FREE(jump->username);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2647|       |        SAFE_FREE(jump);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2648|      0|    }
 2649|  1.31k|}
ssh_strict_fopen:
 2683|  1.31k|{
 2684|  1.31k|    FILE *f = NULL;
 2685|  1.31k|    struct stat sb;
 2686|  1.31k|    int r, fd;
 2687|       |
 2688|       |    /* open first to avoid TOCTOU */
 2689|  1.31k|    fd = open(filename, O_RDONLY);
 2690|  1.31k|    if (fd == -1) {
  ------------------
  |  Branch (2690:9): [True: 1.31k, False: 0]
  ------------------
 2691|  1.31k|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  283|  1.31k|    do {                                                            \
  |  |  284|  1.31k|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|  1.31k|        _ssh_log(priority,                                          \
  |  |  286|  1.31k|                 __func__,                                          \
  |  |  287|  1.31k|                 __VA_ARGS__,                                       \
  |  |  288|  1.31k|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|  1.31k|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|  1.31k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 2692|  1.31k|                         errno,
 2693|  1.31k|                         "Failed to open a file %s for reading: %s",
 2694|  1.31k|                         filename);
 2695|  1.31k|        return NULL;
 2696|  1.31k|    }
 2697|       |
 2698|       |    /* Check the file is sensible for a configuration file */
 2699|      0|    r = fstat(fd, &sb);
 2700|      0|    if (r != 0) {
  ------------------
  |  Branch (2700:9): [True: 0, False: 0]
  ------------------
 2701|      0|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    do {                                                            \
  |  |  284|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|      0|        _ssh_log(priority,                                          \
  |  |  286|      0|                 __func__,                                          \
  |  |  287|      0|                 __VA_ARGS__,                                       \
  |  |  288|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2702|      0|                         errno,
 2703|      0|                         "Failed to stat %s: %s",
 2704|      0|                         filename);
 2705|      0|        close(fd);
 2706|      0|        return NULL;
 2707|      0|    }
 2708|      0|    if ((sb.st_mode & S_IFMT) != S_IFREG) {
  ------------------
  |  Branch (2708:9): [True: 0, False: 0]
  ------------------
 2709|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2710|      0|                "The file %s is not a regular file: skipping",
 2711|      0|                filename);
 2712|      0|        close(fd);
 2713|      0|        return NULL;
 2714|      0|    }
 2715|       |
 2716|      0|    if ((size_t)sb.st_size > max_file_size) {
  ------------------
  |  Branch (2716:9): [True: 0, False: 0]
  ------------------
 2717|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2718|      0|                "The file %s is too large (%jd MB > %zu MB): skipping",
 2719|      0|                filename,
 2720|      0|                (intmax_t)sb.st_size / 1024 / 1024,
 2721|      0|                max_file_size / 1024 / 1024);
 2722|      0|        close(fd);
 2723|      0|        return NULL;
 2724|      0|    }
 2725|       |
 2726|      0|    f = fdopen(fd, "r");
 2727|      0|    if (f == NULL) {
  ------------------
  |  Branch (2727:9): [True: 0, False: 0]
  ------------------
 2728|      0|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    do {                                                            \
  |  |  284|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|      0|        _ssh_log(priority,                                          \
  |  |  286|      0|                 __func__,                                          \
  |  |  287|      0|                 __VA_ARGS__,                                       \
  |  |  288|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2729|      0|                         errno,
 2730|      0|                         "Failed to open a file %s for reading: %s",
 2731|      0|                         filename);
 2732|      0|        close(fd);
 2733|      0|        return NULL;
 2734|      0|    }
 2735|       |
 2736|       |    /* the flcose() will close also the underlying fd */
 2737|      0|    return f;
 2738|      0|}
strlcpy:
 2749|  2.62k|{
 2750|  2.62k|    size_t len = strlen(src);
 2751|       |
 2752|  2.62k|    if (size != 0) {
  ------------------
  |  Branch (2752:9): [True: 2.62k, False: 0]
  ------------------
 2753|  2.62k|        size_t copy_len = (len >= size) ? size - 1 : len;
  ------------------
  |  Branch (2753:27): [True: 0, False: 2.62k]
  ------------------
 2754|       |
 2755|  2.62k|        memcpy(dst, src, copy_len);
 2756|  2.62k|        dst[copy_len] = '\0';
 2757|  2.62k|    }
 2758|       |
 2759|  2.62k|    return len;
 2760|  2.62k|}
ssh_normalize_loose_ip:
 2797|  1.31k|{
 2798|  1.31k|    struct in_addr addr;
 2799|  1.31k|    char buf[INET_ADDRSTRLEN];
 2800|  1.31k|    const char *p = NULL;
 2801|  1.31k|    int rc;
 2802|  1.31k|    int is_ip;
 2803|       |#ifdef _WIN32
 2804|       |    unsigned long ip;
 2805|       |    int is_broadcast;
 2806|       |#endif
 2807|       |
 2808|  1.31k|    if (host == NULL || result == NULL) {
  ------------------
  |  Branch (2808:9): [True: 0, False: 1.31k]
  |  Branch (2808:25): [True: 0, False: 1.31k]
  ------------------
 2809|      0|        return -1;
 2810|      0|    }
 2811|       |
 2812|       |    /* We don't want to normalize stricter IP checks already handled by valid
 2813|       |     * IPv4/IPv6 */
 2814|  1.31k|    is_ip = ssh_is_ipaddr(host);
 2815|  1.31k|    if (is_ip) {
  ------------------
  |  Branch (2815:9): [True: 0, False: 1.31k]
  ------------------
 2816|      0|        return 1; /* not a loose IP — already a strict address */
 2817|      0|    }
 2818|       |
 2819|       |#ifdef _WIN32
 2820|       |    ip = inet_addr(host);
 2821|       |    is_broadcast = strcmp(host, "255.255.255.255");
 2822|       |    if (ip == INADDR_NONE && is_broadcast != 0) {
 2823|       |        return 1; /* not a loose IP */
 2824|       |    }
 2825|       |    addr.S_un.S_addr = ip;
 2826|       |#else
 2827|  1.31k|    rc = inet_aton(host, &addr);
 2828|  1.31k|    if (rc == 0) {
  ------------------
  |  Branch (2828:9): [True: 1.31k, False: 0]
  ------------------
 2829|  1.31k|        return 1; /* not a loose IP */
 2830|  1.31k|    }
 2831|      0|#endif
 2832|       |
 2833|      0|    p = inet_ntop(AF_INET, &addr, buf, sizeof(buf));
 2834|      0|    if (p == NULL) {
  ------------------
  |  Branch (2834:9): [True: 0, False: 0]
  ------------------
 2835|      0|        return -1;
 2836|      0|    }
 2837|       |
 2838|      0|    *result = strdup(p);
 2839|      0|    if (*result == NULL) {
  ------------------
  |  Branch (2839:9): [True: 0, False: 0]
  ------------------
 2840|      0|        return -1;
 2841|      0|    }
 2842|       |
 2843|      0|    return 0;
 2844|      0|}
misc.c:ssh_get_user_home_dir_internal:
  329|  1.31k|{
  330|  1.31k|    char *szPath = NULL;
  331|  1.31k|    struct passwd pwd;
  332|  1.31k|    struct passwd *pwdbuf = NULL;
  333|  1.31k|    char buf[NSS_BUFLEN_PASSWD] = {0};
  334|  1.31k|    int rc;
  335|       |
  336|  1.31k|    rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
  337|  1.31k|    if (rc != 0 || pwdbuf == NULL ) {
  ------------------
  |  Branch (337:9): [True: 0, False: 1.31k]
  |  Branch (337:20): [True: 0, False: 1.31k]
  ------------------
  338|      0|        szPath = getenv("HOME");
  339|      0|        if (szPath == NULL) {
  ------------------
  |  Branch (339:13): [True: 0, False: 0]
  ------------------
  340|      0|            return NULL;
  341|      0|        }
  342|      0|        snprintf(buf, sizeof(buf), "%s", szPath);
  343|      0|        return strdup(buf);
  344|      0|    }
  345|       |
  346|  1.31k|    szPath = strdup(pwd.pw_dir);
  347|       |
  348|  1.31k|    return szPath;
  349|  1.31k|}
misc.c:ssh_iterator_new:
  947|  11.1k|{
  948|  11.1k|    struct ssh_iterator *iterator = malloc(sizeof(struct ssh_iterator));
  949|       |
  950|  11.1k|    if (iterator == NULL) {
  ------------------
  |  Branch (950:9): [True: 0, False: 11.1k]
  ------------------
  951|      0|        return NULL;
  952|      0|    }
  953|  11.1k|    iterator->next = NULL;
  954|  11.1k|    iterator->data = data;
  955|  11.1k|    return iterator;
  956|  11.1k|}
misc.c:ssh_path_expand_internal:
 1478|  2.62k|{
 1479|  2.62k|    char *buf = NULL;
 1480|  2.62k|    char *r = NULL;
 1481|  2.62k|    char *x = NULL;
 1482|  2.62k|    const char *p = NULL;
 1483|  2.62k|    size_t i, l;
 1484|       |
 1485|  2.62k|    r = ssh_path_expand_tilde(s);
 1486|  2.62k|    if (r == NULL) {
  ------------------
  |  Branch (1486:9): [True: 0, False: 2.62k]
  ------------------
 1487|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1488|      0|        return NULL;
 1489|      0|    }
 1490|       |
 1491|  2.62k|    if (strlen(r) > MAX_BUF_SIZE) {
  ------------------
  |  |  230|  2.62k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1491:9): [True: 0, False: 2.62k]
  ------------------
 1492|      0|        ssh_set_error(session, SSH_FATAL, "string to expand too long");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1493|      0|        free(r);
 1494|      0|        return NULL;
 1495|      0|    }
 1496|       |
 1497|  2.62k|    buf = malloc(MAX_BUF_SIZE);
  ------------------
  |  |  230|  2.62k|#define MAX_BUF_SIZE 4096
  ------------------
 1498|  2.62k|    if (buf == NULL) {
  ------------------
  |  Branch (1498:9): [True: 0, False: 2.62k]
  ------------------
 1499|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1500|      0|        free(r);
 1501|      0|        return NULL;
 1502|      0|    }
 1503|       |
 1504|  2.62k|    p = r;
 1505|  2.62k|    buf[0] = '\0';
 1506|       |
 1507|  44.0k|    for (i = 0; *p != '\0'; p++) {
  ------------------
  |  Branch (1507:17): [True: 41.3k, False: 2.62k]
  ------------------
 1508|  41.3k|        if (*p != '%') {
  ------------------
  |  Branch (1508:13): [True: 38.7k, False: 2.62k]
  ------------------
 1509|  38.7k|            buf[i] = hostname_lenient ? tolower((unsigned char)*p) : *p;
  ------------------
  |  Branch (1509:22): [True: 0, False: 38.7k]
  |  Branch (1509:41): [True: 0, False: 0]
  |  Branch (1509:41): [True: 0, False: 0]
  |  Branch (1509:41): [Folded, False: 0]
  ------------------
 1510|  38.7k|            i++;
 1511|  38.7k|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|  38.7k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1511:17): [True: 0, False: 38.7k]
  ------------------
 1512|      0|                free(buf);
 1513|      0|                free(r);
 1514|      0|                return NULL;
 1515|      0|            }
 1516|  38.7k|            buf[i] = '\0';
 1517|  38.7k|            continue;
 1518|  38.7k|        }
 1519|       |
 1520|  2.62k|        p++;
 1521|  2.62k|        if (*p == '\0') {
  ------------------
  |  Branch (1521:13): [True: 0, False: 2.62k]
  ------------------
 1522|       |            /* HostName expansion rejects trailing '%' to match the parse-time
 1523|       |             * scan. Keep the general expansion path unchanged, where a
 1524|       |             * trailing '%' is truncated.
 1525|       |             */
 1526|      0|            if (hostname_lenient) {
  ------------------
  |  Branch (1526:17): [True: 0, False: 0]
  ------------------
 1527|      0|                ssh_set_error(session, SSH_FATAL, "Incomplete Hostname token");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1528|      0|                free(buf);
 1529|      0|                free(r);
 1530|      0|                return NULL;
 1531|      0|            }
 1532|      0|            break;
 1533|      0|        }
 1534|       |
 1535|  2.62k|        if (hostname_lenient && *p != '%' && *p != 'h') {
  ------------------
  |  Branch (1535:13): [True: 0, False: 2.62k]
  |  Branch (1535:33): [True: 0, False: 0]
  |  Branch (1535:46): [True: 0, False: 0]
  ------------------
 1536|      0|            buf[i] = '%';
 1537|      0|            i++;
 1538|      0|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|      0|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1538:17): [True: 0, False: 0]
  ------------------
 1539|      0|                ssh_set_error(session, SSH_FATAL, "String too long");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1540|      0|                free(buf);
 1541|      0|                free(r);
 1542|      0|                return NULL;
 1543|      0|            }
 1544|      0|            buf[i] = *p;
 1545|      0|            i++;
 1546|      0|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|      0|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1546:17): [True: 0, False: 0]
  ------------------
 1547|      0|                ssh_set_error(session, SSH_FATAL, "String too long");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1548|      0|                free(buf);
 1549|      0|                free(r);
 1550|      0|                return NULL;
 1551|      0|            }
 1552|      0|            buf[i] = '\0';
 1553|      0|            continue;
 1554|      0|        }
 1555|       |
 1556|  2.62k|        switch (*p) {
 1557|      0|        case '%':
  ------------------
  |  Branch (1557:9): [True: 0, False: 2.62k]
  ------------------
 1558|      0|            buf[i] = '%';
 1559|      0|            i++;
 1560|      0|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|      0|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1560:17): [True: 0, False: 0]
  ------------------
 1561|      0|                free(buf);
 1562|      0|                free(r);
 1563|      0|                return NULL;
 1564|      0|            }
 1565|      0|            buf[i] = '\0';
 1566|      0|            continue;
 1567|  2.62k|        case 'd':
  ------------------
  |  Branch (1567:9): [True: 2.62k, False: 0]
  ------------------
 1568|  2.62k|            x = ssh_get_user_home_dir(session);
 1569|  2.62k|            if (x == NULL) {
  ------------------
  |  Branch (1569:17): [True: 0, False: 2.62k]
  ------------------
 1570|      0|                ssh_set_error(session, SSH_FATAL, "Cannot expand homedir");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1571|      0|                free(buf);
 1572|      0|                free(r);
 1573|      0|                return NULL;
 1574|      0|            }
 1575|  2.62k|            break;
 1576|  2.62k|        case 'u':
  ------------------
  |  Branch (1576:9): [True: 0, False: 2.62k]
  ------------------
 1577|      0|            x = ssh_get_local_username();
 1578|      0|            break;
 1579|      0|        case 'l':
  ------------------
  |  Branch (1579:9): [True: 0, False: 2.62k]
  ------------------
 1580|      0|            x = ssh_get_local_hostname();
 1581|      0|            break;
 1582|      0|        case 'h':
  ------------------
  |  Branch (1582:9): [True: 0, False: 2.62k]
  ------------------
 1583|      0|            if (session->opts.host) {
  ------------------
  |  Branch (1583:17): [True: 0, False: 0]
  ------------------
 1584|      0|                x = hostname_lenient ? ssh_lowercase(session->opts.host)
  ------------------
  |  Branch (1584:21): [True: 0, False: 0]
  ------------------
 1585|      0|                                     : strdup(session->opts.host);
 1586|      0|            } else if (session->opts.originalhost) {
  ------------------
  |  Branch (1586:24): [True: 0, False: 0]
  ------------------
 1587|      0|                x = hostname_lenient ? ssh_lowercase(session->opts.originalhost)
  ------------------
  |  Branch (1587:21): [True: 0, False: 0]
  ------------------
 1588|      0|                                     : strdup(session->opts.originalhost);
 1589|      0|            } else {
 1590|      0|                ssh_set_error(session, SSH_FATAL, "Cannot expand host");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1591|      0|                free(buf);
 1592|      0|                free(r);
 1593|      0|                return NULL;
 1594|      0|            }
 1595|      0|            break;
 1596|      0|        case 'n':
  ------------------
  |  Branch (1596:9): [True: 0, False: 2.62k]
  ------------------
 1597|      0|            if (session->opts.originalhost) {
  ------------------
  |  Branch (1597:17): [True: 0, False: 0]
  ------------------
 1598|      0|                x = strdup(session->opts.originalhost);
 1599|      0|            } else {
 1600|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1601|      0|                              SSH_FATAL,
 1602|      0|                              "Cannot expand original host");
 1603|      0|                free(buf);
 1604|      0|                free(r);
 1605|      0|                return NULL;
 1606|      0|            }
 1607|      0|            break;
 1608|      0|        case 'r':
  ------------------
  |  Branch (1608:9): [True: 0, False: 2.62k]
  ------------------
 1609|      0|            if (session->opts.username) {
  ------------------
  |  Branch (1609:17): [True: 0, False: 0]
  ------------------
 1610|      0|                x = strdup(session->opts.username);
 1611|      0|            } else {
 1612|      0|                ssh_set_error(session, SSH_FATAL, "Cannot expand username");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1613|      0|                free(buf);
 1614|      0|                free(r);
 1615|      0|                return NULL;
 1616|      0|            }
 1617|      0|            break;
 1618|      0|        case 'p': {
  ------------------
  |  Branch (1618:9): [True: 0, False: 2.62k]
  ------------------
 1619|      0|            char tmp[6];
 1620|      0|            unsigned int port;
 1621|       |
 1622|      0|            ssh_options_get_port(session, &port);
 1623|      0|            snprintf(tmp, sizeof(tmp), "%u", port);
 1624|      0|            x = strdup(tmp);
 1625|      0|            break;
 1626|      0|        }
 1627|      0|        case 'j':
  ------------------
  |  Branch (1627:9): [True: 0, False: 2.62k]
  ------------------
 1628|      0|            if (session->opts.proxy_jumps_str != NULL) {
  ------------------
  |  Branch (1628:17): [True: 0, False: 0]
  ------------------
 1629|      0|                x = strdup(session->opts.proxy_jumps_str);
 1630|      0|            } else {
 1631|      0|                x = strdup("");
 1632|      0|            }
 1633|      0|            break;
 1634|      0|        case 'C':
  ------------------
  |  Branch (1634:9): [True: 0, False: 2.62k]
  ------------------
 1635|      0|            x = get_connection_hash(session);
 1636|      0|            break;
 1637|      0|        default:
  ------------------
  |  Branch (1637:9): [True: 0, False: 2.62k]
  ------------------
 1638|      0|            ssh_set_error(session, SSH_FATAL, "Wrong escape sequence detected");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1639|      0|            free(buf);
 1640|      0|            free(r);
 1641|      0|            return NULL;
 1642|  2.62k|        }
 1643|       |
 1644|  2.62k|        if (x == NULL) {
  ------------------
  |  Branch (1644:13): [True: 0, False: 2.62k]
  ------------------
 1645|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1646|      0|            free(buf);
 1647|      0|            free(r);
 1648|      0|            return NULL;
 1649|      0|        }
 1650|       |
 1651|  2.62k|        i += strlen(x);
 1652|  2.62k|        if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|  2.62k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1652:13): [True: 0, False: 2.62k]
  ------------------
 1653|      0|            ssh_set_error(session, SSH_FATAL, "String too long");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1654|      0|            free(buf);
 1655|      0|            free(x);
 1656|      0|            free(r);
 1657|      0|            return NULL;
 1658|      0|        }
 1659|  2.62k|        l = strlen(buf);
 1660|  2.62k|        strlcpy(buf + l, x, MAX_BUF_SIZE - l);
  ------------------
  |  |  230|  2.62k|#define MAX_BUF_SIZE 4096
  ------------------
 1661|  2.62k|        buf[i] = '\0';
 1662|  2.62k|        SAFE_FREE(x);
  ------------------
  |  |  373|  2.62k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.62k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.62k]
  |  |  ------------------
  ------------------
 1663|  2.62k|    }
 1664|       |
 1665|  2.62k|    free(r);
 1666|       |
 1667|       |    /* strip the unused space by realloc */
 1668|  2.62k|    x = realloc(buf, strlen(buf) + 1);
 1669|  2.62k|    if (x == NULL) {
  ------------------
  |  Branch (1669:9): [True: 0, False: 2.62k]
  ------------------
 1670|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1671|      0|        free(buf);
 1672|      0|    }
 1673|  2.62k|    return x;
 1674|  2.62k|}
misc.c:ssh_timestamp_difference:
 1875|  59.3k|{
 1876|  59.3k|    long seconds, usecs, msecs;
 1877|  59.3k|    seconds = new->seconds - old->seconds;
 1878|  59.3k|    usecs = new->useconds - old->useconds;
 1879|  59.3k|    if (usecs < 0){
  ------------------
  |  Branch (1879:9): [True: 40, False: 59.3k]
  ------------------
 1880|     40|        seconds--;
 1881|     40|        usecs += 1000000;
 1882|     40|    }
 1883|  59.3k|    msecs = seconds * 1000 + usecs/1000;
 1884|  59.3k|    return msecs;
 1885|  59.3k|}

kex_type_to_mlkem_info:
   28|  3.28k|{
   29|  3.28k|    switch (kex_type) {
   30|  3.28k|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (30:5): [True: 3.28k, False: 0]
  ------------------
   31|  3.28k|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (31:5): [True: 0, False: 3.28k]
  ------------------
   32|  3.28k|        return &MLKEM768_INFO;
   33|       |#ifdef HAVE_MLKEM1024
   34|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
   35|       |        return &MLKEM1024_INFO;
   36|       |#endif
   37|      0|    default:
  ------------------
  |  Branch (37:5): [True: 0, False: 3.28k]
  ------------------
   38|       |        return NULL;
   39|  3.28k|    }
   40|  3.28k|}

ssh_mlkem_init:
   41|    657|{
   42|    657|    int ret = SSH_ERROR;
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   43|    657|    struct ssh_crypto_struct *crypto = session->next_crypto;
   44|    657|    const struct mlkem_type_info *mlkem_info = NULL;
   45|    657|    unsigned char rnd[LIBCRUX_ML_KEM_KEY_PAIR_PRNG_LEN];
   46|    657|    struct libcrux_mlkem768_keypair keypair;
   47|    657|    int err;
   48|       |
   49|    657|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
   50|    657|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (50:9): [True: 0, False: 657]
  ------------------
   51|      0|        SSH_LOG(SSH_LOG_WARNING, "Unknown ML-KEM type");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   52|      0|        goto cleanup;
   53|      0|    }
   54|       |
   55|    657|    err = ssh_get_random(rnd, sizeof(rnd), 0);
   56|    657|    if (err != 1) {
  ------------------
  |  Branch (56:9): [True: 0, False: 657]
  ------------------
   57|      0|        SSH_LOG(SSH_LOG_WARNING,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   58|      0|                "Failed to generate random data for ML-KEM keygen");
   59|      0|        goto cleanup;
   60|      0|    }
   61|       |
   62|    657|    keypair = libcrux_ml_kem_mlkem768_portable_generate_key_pair(rnd);
   63|       |
   64|    657|    if (ssh_string_len(crypto->mlkem_client_pubkey) < mlkem_info->pubkey_size) {
  ------------------
  |  Branch (64:9): [True: 657, False: 0]
  ------------------
   65|    657|        SSH_STRING_FREE(crypto->mlkem_client_pubkey);
  ------------------
  |  |  910|    657|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 657]
  |  |  |  Branch (910:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
   66|    657|    }
   67|    657|    if (crypto->mlkem_client_pubkey == NULL) {
  ------------------
  |  Branch (67:9): [True: 657, False: 0]
  ------------------
   68|    657|        crypto->mlkem_client_pubkey = ssh_string_new(mlkem_info->pubkey_size);
   69|    657|        if (crypto->mlkem_client_pubkey == NULL) {
  ------------------
  |  Branch (69:13): [True: 0, False: 657]
  ------------------
   70|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
   71|      0|            goto cleanup;
   72|      0|        }
   73|    657|    }
   74|    657|    err = ssh_string_fill(crypto->mlkem_client_pubkey,
   75|    657|                          keypair.pk.value,
   76|    657|                          mlkem_info->pubkey_size);
   77|    657|    if (err) {
  ------------------
  |  Branch (77:9): [True: 0, False: 657]
  ------------------
   78|      0|        SSH_LOG(SSH_LOG_WARNING,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   79|      0|                "Failed to fill the string with client pubkey");
   80|      0|        goto cleanup;
   81|      0|    }
   82|       |
   83|    657|    if (crypto->mlkem_privkey == NULL) {
  ------------------
  |  Branch (83:9): [True: 657, False: 0]
  ------------------
   84|    657|        crypto->mlkem_privkey = malloc(mlkem_info->privkey_size);
   85|    657|        if (crypto->mlkem_privkey == NULL) {
  ------------------
  |  Branch (85:13): [True: 0, False: 657]
  ------------------
   86|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
   87|      0|            goto cleanup;
   88|      0|        }
   89|    657|    }
   90|    657|    memcpy(crypto->mlkem_privkey, keypair.sk.value, mlkem_info->privkey_size);
   91|    657|    crypto->mlkem_privkey_len = mlkem_info->privkey_size;
   92|       |
   93|    657|    ret = SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
   94|       |
   95|    657|cleanup:
   96|    657|    ssh_burn(&keypair, sizeof(keypair));
  ------------------
  |  |  388|    657|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
   97|    657|    ssh_burn(rnd, sizeof(rnd));
  ------------------
  |  |  388|    657|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
   98|    657|    return ret;
   99|    657|}
ssh_mlkem_encapsulate:
  103|    657|{
  104|    657|    int ret = SSH_ERROR;
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  105|    657|    const struct mlkem_type_info *mlkem_info = NULL;
  106|    657|    struct ssh_crypto_struct *crypto = session->next_crypto;
  107|    657|    const unsigned char *pubkey_data = NULL;
  108|    657|    ssh_string pubkey = crypto->mlkem_client_pubkey;
  109|    657|    struct libcrux_mlkem768_enc_result enc;
  110|    657|    struct libcrux_mlkem768_pk mlkem_pub = {0};
  111|    657|    unsigned char rnd[LIBCRUX_ML_KEM_ENC_PRNG_LEN];
  112|    657|    int err;
  113|       |
  114|    657|    if (pubkey == NULL) {
  ------------------
  |  Branch (114:9): [True: 0, False: 657]
  ------------------
  115|      0|        SSH_LOG(SSH_LOG_WARNING, "Missing pubkey in session");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  116|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  117|      0|    }
  118|       |
  119|    657|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
  120|    657|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (120:9): [True: 0, False: 657]
  ------------------
  121|      0|        SSH_LOG(SSH_LOG_WARNING, "Unknown ML-KEM type");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  122|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  123|      0|    }
  124|       |
  125|    657|    pubkey_data = ssh_string_data(pubkey);
  126|    657|    memcpy(mlkem_pub.value, pubkey_data, mlkem_info->pubkey_size);
  127|    657|    err = libcrux_ml_kem_mlkem768_portable_validate_public_key(&mlkem_pub);
  128|    657|    if (err == 0) {
  ------------------
  |  Branch (128:9): [True: 0, False: 657]
  ------------------
  129|      0|        SSH_LOG(SSH_LOG_WARNING, "Invalid public key");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  130|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  131|      0|    }
  132|       |
  133|    657|    err = ssh_get_random(rnd, sizeof(rnd), 0);
  134|    657|    if (err != 1) {
  ------------------
  |  Branch (134:9): [True: 0, False: 657]
  ------------------
  135|      0|        SSH_LOG(SSH_LOG_WARNING,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  136|      0|                "Failed to generate random data for ML-KEM keygen");
  137|      0|        goto cleanup;
  138|      0|    }
  139|       |
  140|    657|    enc = libcrux_ml_kem_mlkem768_portable_encapsulate(&mlkem_pub, rnd);
  141|       |
  142|    657|    if (ssh_string_len(crypto->mlkem_ciphertext) < mlkem_info->ciphertext_size) {
  ------------------
  |  Branch (142:9): [True: 657, False: 0]
  ------------------
  143|    657|        SSH_STRING_FREE(crypto->mlkem_ciphertext);
  ------------------
  |  |  910|    657|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 657]
  |  |  |  Branch (910:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
  144|    657|    }
  145|    657|    if (crypto->mlkem_ciphertext == NULL) {
  ------------------
  |  Branch (145:9): [True: 657, False: 0]
  ------------------
  146|    657|        crypto->mlkem_ciphertext = ssh_string_new(mlkem_info->ciphertext_size);
  147|    657|        if (crypto->mlkem_ciphertext == NULL) {
  ------------------
  |  Branch (147:13): [True: 0, False: 657]
  ------------------
  148|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  149|      0|            goto cleanup;
  150|      0|        }
  151|    657|    }
  152|    657|    err = ssh_string_fill(crypto->mlkem_ciphertext,
  153|    657|                          enc.fst.value,
  154|    657|                          sizeof(enc.fst.value));
  155|    657|    if (err != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (155:9): [True: 0, False: 657]
  ------------------
  156|      0|        SSH_LOG(SSH_LOG_WARNING, "Failed to fill the string with ciphertext");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  157|      0|        goto cleanup;
  158|      0|    }
  159|    657|    memcpy(shared_secret, enc.snd, sizeof(enc.snd));
  160|       |
  161|    657|    ret = SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  162|       |
  163|    657|cleanup:
  164|    657|    ssh_burn(rnd, sizeof(rnd));
  ------------------
  |  |  388|    657|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  165|    657|    ssh_burn(&enc, sizeof(enc));
  ------------------
  |  |  388|    657|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  166|    657|    return ret;
  167|    657|}
ssh_mlkem_decapsulate:
  171|    657|{
  172|    657|    const struct mlkem_type_info *mlkem_info = NULL;
  173|    657|    struct ssh_crypto_struct *crypto = session->next_crypto;
  174|    657|    ssh_string ciphertext = NULL;
  175|    657|    unsigned char *ciphertext_data = NULL;
  176|    657|    struct libcrux_mlkem768_sk mlkem_priv = {0};
  177|    657|    struct libcrux_mlkem768_ciphertext mlkem_ciphertext = {0};
  178|       |
  179|    657|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
  180|    657|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (180:9): [True: 0, False: 657]
  ------------------
  181|      0|        SSH_LOG(SSH_LOG_WARNING, "Unknown ML-KEM type");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  182|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  183|      0|    }
  184|       |
  185|    657|    ciphertext = crypto->mlkem_ciphertext;
  186|    657|    if (ciphertext == NULL) {
  ------------------
  |  Branch (186:9): [True: 0, False: 657]
  ------------------
  187|      0|        SSH_LOG(SSH_LOG_WARNING, "Missing ciphertext in session");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  188|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  189|      0|    }
  190|       |
  191|    657|    ciphertext_data = ssh_string_data(ciphertext);
  192|    657|    memcpy(mlkem_ciphertext.value,
  193|    657|           ciphertext_data,
  194|    657|           sizeof(mlkem_ciphertext.value));
  195|       |
  196|    657|    memcpy(mlkem_priv.value, crypto->mlkem_privkey, crypto->mlkem_privkey_len);
  197|       |
  198|    657|    libcrux_ml_kem_mlkem768_portable_decapsulate(&mlkem_priv,
  199|    657|                                                 &mlkem_ciphertext,
  200|    657|                                                 shared_secret);
  201|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  202|    657|}

ssh_options_set_algo:
  337|  5.90k|{
  338|       |    /* When the list start with +,-,^ the filtration of unknown algorithms
  339|       |     * gets handled inside the helper functions, otherwise the list is taken
  340|       |     * as it is. */
  341|  5.90k|    char *p = (char *)list;
  342|       |
  343|  5.90k|    if (algo < SSH_COMP_C_S) {
  ------------------
  |  Branch (343:9): [True: 5.90k, False: 0]
  ------------------
  344|  5.90k|        if (list[0] == '+') {
  ------------------
  |  Branch (344:13): [True: 0, False: 5.90k]
  ------------------
  345|      0|            p = ssh_add_to_default_algos(algo, list+1);
  346|  5.90k|        } else if (list[0] == '-') {
  ------------------
  |  Branch (346:20): [True: 0, False: 5.90k]
  ------------------
  347|      0|            p = ssh_remove_from_default_algos(algo, list+1);
  348|  5.90k|        } else if (list[0] == '^') {
  ------------------
  |  Branch (348:20): [True: 0, False: 5.90k]
  ------------------
  349|      0|            p = ssh_prefix_default_algos(algo, list+1);
  350|      0|        }
  351|  5.90k|    }
  352|       |
  353|  5.90k|    if (p == list) {
  ------------------
  |  Branch (353:9): [True: 5.90k, False: 0]
  ------------------
  354|  5.90k|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|  5.90k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 5.90k]
  |  |  ------------------
  ------------------
  355|      0|            p = ssh_keep_fips_algos(algo, list);
  356|  5.90k|        } else {
  357|  5.90k|            p = ssh_keep_known_algos(algo, list);
  358|  5.90k|        }
  359|  5.90k|    }
  360|       |
  361|  5.90k|    if (p == NULL) {
  ------------------
  |  Branch (361:9): [True: 0, False: 5.90k]
  ------------------
  362|      0|        ssh_set_error(session, SSH_REQUEST_DENIED,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  363|      0|                "Setting method: no allowed algorithm for method \"%s\" (%s)",
  364|      0|                ssh_kex_get_description(algo), list);
  365|      0|        return -1;
  366|      0|    }
  367|       |
  368|  5.90k|    SAFE_FREE(*place);
  ------------------
  |  |  373|  5.90k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 5.90k]
  |  |  |  Branch (373:71): [Folded, False: 5.90k]
  |  |  ------------------
  ------------------
  369|  5.90k|    *place = p;
  370|       |
  371|  5.90k|    return 0;
  372|  5.90k|}
ssh_options_set:
  799|  7.22k|{
  800|  7.22k|    const char *v = NULL;
  801|  7.22k|    char *p = NULL, *q = NULL;
  802|  7.22k|    long int i;
  803|  7.22k|    unsigned int u;
  804|  7.22k|    int rc;
  805|  7.22k|    char **wanted_methods = session->opts.wanted_methods;
  806|  7.22k|    struct ssh_jump_callbacks_struct *j = NULL;
  807|       |
  808|  7.22k|    if (session == NULL) {
  ------------------
  |  Branch (808:9): [True: 0, False: 7.22k]
  ------------------
  809|      0|        return -1;
  810|      0|    }
  811|       |
  812|  7.22k|    switch (type) {
  813|    657|        case SSH_OPTIONS_HOST:
  ------------------
  |  Branch (813:9): [True: 657, False: 6.57k]
  ------------------
  814|    657|            v = value;
  815|    657|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (815:17): [True: 0, False: 657]
  |  Branch (815:30): [True: 0, False: 657]
  ------------------
  816|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  817|      0|                return -1;
  818|    657|            } else {
  819|    657|                char *username = NULL, *hostname = NULL;
  820|    657|                char *strict_hostname = NULL;
  821|    657|                char *normalized = NULL;
  822|       |
  823|       |                /* Non-strict parse: reject shell metacharacters */
  824|    657|                rc = ssh_config_parse_uri(value,
  825|    657|                                          &username,
  826|    657|                                          &hostname,
  827|    657|                                          NULL,
  828|    657|                                          true,
  829|    657|                                          false);
  830|    657|                if (rc != SSH_OK || hostname == NULL) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (830:21): [True: 0, False: 657]
  |  Branch (830:37): [True: 0, False: 657]
  ------------------
  831|      0|                    SAFE_FREE(username);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  832|      0|                    SAFE_FREE(hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  833|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  834|      0|                    return -1;
  835|      0|                }
  836|       |
  837|       |                /* Non-strict passed: set username and originalhost */
  838|    657|                if (username != NULL) {
  ------------------
  |  Branch (838:21): [True: 0, False: 657]
  ------------------
  839|      0|                    SAFE_FREE(session->opts.username);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  840|      0|                    session->opts.username = username;
  841|      0|                }
  842|    657|                if (!session->opts.config_hostname_only) {
  ------------------
  |  Branch (842:21): [True: 657, False: 0]
  ------------------
  843|    657|                    SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  844|    657|                    SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  845|    657|                    session->opts.originalhost = hostname;
  846|    657|                } else {
  847|      0|                    SAFE_FREE(hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  848|      0|                }
  849|       |
  850|       |                /* Strict parse: set host only if valid hostname or IP */
  851|    657|                rc = ssh_normalize_loose_ip(value, &normalized);
  852|    657|                if (rc == -1) {
  ------------------
  |  Branch (852:21): [True: 0, False: 657]
  ------------------
  853|       |                    /* Error */
  854|      0|                    SAFE_FREE(username);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  855|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  856|      0|                    return -1;
  857|      0|                }
  858|    657|                rc = ssh_config_parse_uri(
  859|    657|                    (normalized != NULL) ? normalized : value,
  ------------------
  |  Branch (859:21): [True: 0, False: 657]
  ------------------
  860|    657|                    NULL,
  861|    657|                    &strict_hostname,
  862|    657|                    NULL,
  863|    657|                    true,
  864|    657|                    true);
  865|    657|                SAFE_FREE(normalized);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  866|       |
  867|    657|                if (rc != SSH_OK || strict_hostname == NULL) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (867:21): [True: 0, False: 657]
  |  Branch (867:37): [True: 0, False: 657]
  ------------------
  868|      0|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  869|      0|                    SAFE_FREE(strict_hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  870|      0|                    if (session->opts.config_hostname_only) {
  ------------------
  |  Branch (870:25): [True: 0, False: 0]
  ------------------
  871|       |                        /* Config path: Hostname must be valid */
  872|      0|                        ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  873|      0|                        return -1;
  874|      0|                    }
  875|    657|                } else {
  876|    657|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  877|    657|                    session->opts.host = strict_hostname;
  878|    657|                }
  879|    657|            }
  880|    657|            break;
  881|    657|        case SSH_OPTIONS_PORT:
  ------------------
  |  Branch (881:9): [True: 0, False: 7.22k]
  ------------------
  882|      0|            if (value == NULL) {
  ------------------
  |  Branch (882:17): [True: 0, False: 0]
  ------------------
  883|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  884|      0|                return -1;
  885|      0|            } else {
  886|      0|                int *x = (int *) value;
  887|      0|                if (*x <= 0 || *x > 65535) {
  ------------------
  |  Branch (887:21): [True: 0, False: 0]
  |  Branch (887:32): [True: 0, False: 0]
  ------------------
  888|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  889|      0|                    return -1;
  890|      0|                }
  891|       |
  892|      0|                session->opts.port = *x;
  893|      0|            }
  894|      0|            break;
  895|      0|        case SSH_OPTIONS_PORT_STR:
  ------------------
  |  Branch (895:9): [True: 0, False: 7.22k]
  ------------------
  896|      0|            v = value;
  897|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (897:17): [True: 0, False: 0]
  |  Branch (897:30): [True: 0, False: 0]
  ------------------
  898|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  899|      0|                return -1;
  900|      0|            } else {
  901|      0|                q = strdup(v);
  902|      0|                if (q == NULL) {
  ------------------
  |  Branch (902:21): [True: 0, False: 0]
  ------------------
  903|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  904|      0|                    return -1;
  905|      0|                }
  906|      0|                i = strtol(q, &p, 10);
  907|      0|                if (q == p || *p != '\0') {
  ------------------
  |  Branch (907:21): [True: 0, False: 0]
  |  Branch (907:31): [True: 0, False: 0]
  ------------------
  908|      0|                    SSH_LOG(SSH_LOG_DEBUG, "No port number was parsed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  909|      0|                    SAFE_FREE(q);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  910|      0|                    return -1;
  911|      0|                }
  912|      0|                SAFE_FREE(q);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  913|      0|                if (i <= 0 || i > 65535) {
  ------------------
  |  Branch (913:21): [True: 0, False: 0]
  |  Branch (913:31): [True: 0, False: 0]
  ------------------
  914|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  915|      0|                    return -1;
  916|      0|                }
  917|       |
  918|      0|                session->opts.port = i;
  919|      0|            }
  920|      0|            break;
  921|    657|        case SSH_OPTIONS_FD:
  ------------------
  |  Branch (921:9): [True: 657, False: 6.57k]
  ------------------
  922|    657|            if (value == NULL) {
  ------------------
  |  Branch (922:17): [True: 0, False: 657]
  ------------------
  923|      0|                session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  924|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  925|      0|                return -1;
  926|    657|            } else {
  927|    657|                socket_t *x = (socket_t *) value;
  928|    657|                if (*x < 0) {
  ------------------
  |  Branch (928:21): [True: 0, False: 657]
  ------------------
  929|      0|                    session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  930|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  931|      0|                    return -1;
  932|      0|                }
  933|       |
  934|    657|                session->opts.fd = *x & 0xffff;
  935|    657|            }
  936|    657|            break;
  937|    657|        case SSH_OPTIONS_BINDADDR:
  ------------------
  |  Branch (937:9): [True: 0, False: 7.22k]
  ------------------
  938|      0|            v = value;
  939|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (939:17): [True: 0, False: 0]
  |  Branch (939:30): [True: 0, False: 0]
  ------------------
  940|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  941|      0|                return -1;
  942|      0|            }
  943|       |
  944|      0|            q = strdup(v);
  945|      0|            if (q == NULL) {
  ------------------
  |  Branch (945:17): [True: 0, False: 0]
  ------------------
  946|      0|                return -1;
  947|      0|            }
  948|      0|            SAFE_FREE(session->opts.bindaddr);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  949|      0|            session->opts.bindaddr = q;
  950|      0|            break;
  951|    657|        case SSH_OPTIONS_USER:
  ------------------
  |  Branch (951:9): [True: 657, False: 6.57k]
  ------------------
  952|    657|            v = value;
  953|    657|            SAFE_FREE(session->opts.username);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  954|    657|            if (v == NULL) {
  ------------------
  |  Branch (954:17): [True: 0, False: 657]
  ------------------
  955|      0|                q = ssh_get_local_username();
  956|      0|                if (q == NULL) {
  ------------------
  |  Branch (956:21): [True: 0, False: 0]
  ------------------
  957|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  958|      0|                    return -1;
  959|      0|                }
  960|      0|                session->opts.username = q;
  961|    657|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (961:24): [True: 0, False: 657]
  ------------------
  962|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  963|      0|                return -1;
  964|    657|            } else { /* username provided */
  965|    657|                session->opts.username = strdup(value);
  966|    657|                if (session->opts.username == NULL) {
  ------------------
  |  Branch (966:21): [True: 0, False: 657]
  ------------------
  967|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  968|      0|                    return -1;
  969|      0|                }
  970|    657|                rc = ssh_check_username_syntax(session->opts.username);
  971|    657|                if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (971:21): [True: 0, False: 657]
  ------------------
  972|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  973|      0|                    return -1;
  974|      0|                }
  975|    657|            }
  976|    657|            break;
  977|    657|        case SSH_OPTIONS_SSH_DIR:
  ------------------
  |  Branch (977:9): [True: 657, False: 6.57k]
  ------------------
  978|    657|            v = value;
  979|    657|            SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  980|    657|            if (v == NULL) {
  ------------------
  |  Branch (980:17): [True: 657, False: 0]
  ------------------
  981|    657|                session->opts.sshdir = ssh_path_expand_tilde("~/.ssh");
  982|    657|                if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (982:21): [True: 0, False: 657]
  ------------------
  983|      0|                    return -1;
  984|      0|                }
  985|    657|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (985:24): [True: 0, False: 0]
  ------------------
  986|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  987|      0|                return -1;
  988|      0|            } else {
  989|      0|                session->opts.sshdir = ssh_path_expand_tilde(v);
  990|      0|                if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (990:21): [True: 0, False: 0]
  ------------------
  991|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  992|      0|                    return -1;
  993|      0|                }
  994|      0|            }
  995|    657|            break;
  996|    657|        case SSH_OPTIONS_IDENTITY:
  ------------------
  |  Branch (996:9): [True: 0, False: 7.22k]
  ------------------
  997|      0|        case SSH_OPTIONS_ADD_IDENTITY:
  ------------------
  |  Branch (997:9): [True: 0, False: 7.22k]
  ------------------
  998|      0|            v = value;
  999|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (999:17): [True: 0, False: 0]
  |  Branch (999:30): [True: 0, False: 0]
  ------------------
 1000|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1001|      0|                return -1;
 1002|      0|            }
 1003|      0|            q = strdup(v);
 1004|      0|            if (q == NULL) {
  ------------------
  |  Branch (1004:17): [True: 0, False: 0]
  ------------------
 1005|      0|                return -1;
 1006|      0|            }
 1007|      0|            if (session->opts.exp_flags & SSH_OPT_EXP_FLAG_IDENTITY) {
  ------------------
  |  |  118|      0|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
  |  Branch (1007:17): [True: 0, False: 0]
  ------------------
 1008|      0|                rc = ssh_list_append(session->opts.identity_non_exp, q);
 1009|      0|            } else {
 1010|      0|                rc = ssh_list_prepend(session->opts.identity_non_exp, q);
 1011|      0|            }
 1012|      0|            if (rc < 0) {
  ------------------
  |  Branch (1012:17): [True: 0, False: 0]
  ------------------
 1013|      0|                free(q);
 1014|      0|                return -1;
 1015|      0|            }
 1016|      0|            break;
 1017|      0|        case SSH_OPTIONS_CERTIFICATE:
  ------------------
  |  Branch (1017:9): [True: 0, False: 7.22k]
  ------------------
 1018|      0|            v = value;
 1019|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1019:17): [True: 0, False: 0]
  |  Branch (1019:30): [True: 0, False: 0]
  ------------------
 1020|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1021|      0|                return -1;
 1022|      0|            }
 1023|      0|            q = strdup(v);
 1024|      0|            if (q == NULL) {
  ------------------
  |  Branch (1024:17): [True: 0, False: 0]
  ------------------
 1025|      0|                return -1;
 1026|      0|            }
 1027|      0|            rc = ssh_list_append(session->opts.certificate_non_exp, q);
 1028|      0|            if (rc < 0) {
  ------------------
  |  Branch (1028:17): [True: 0, False: 0]
  ------------------
 1029|      0|                free(q);
 1030|      0|                return -1;
 1031|      0|            }
 1032|      0|            break;
 1033|      0|        case SSH_OPTIONS_KNOWNHOSTS:
  ------------------
  |  Branch (1033:9): [True: 0, False: 7.22k]
  ------------------
 1034|      0|            v = value;
 1035|      0|            SAFE_FREE(session->opts.knownhosts);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1036|      0|            if (v == NULL) {
  ------------------
  |  Branch (1036:17): [True: 0, False: 0]
  ------------------
 1037|       |                /* The default value will be set by the ssh_options_apply() */
 1038|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1038:24): [True: 0, False: 0]
  ------------------
 1039|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1040|      0|                return -1;
 1041|      0|            } else {
 1042|      0|                session->opts.knownhosts = strdup(v);
 1043|      0|                if (session->opts.knownhosts == NULL) {
  ------------------
  |  Branch (1043:21): [True: 0, False: 0]
  ------------------
 1044|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1045|      0|                    return -1;
 1046|      0|                }
 1047|      0|                session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_KNOWNHOSTS;
  ------------------
  |  |  115|      0|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
 1048|      0|            }
 1049|      0|            break;
 1050|      0|        case SSH_OPTIONS_GLOBAL_KNOWNHOSTS:
  ------------------
  |  Branch (1050:9): [True: 0, False: 7.22k]
  ------------------
 1051|      0|            v = value;
 1052|      0|            SAFE_FREE(session->opts.global_knownhosts);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1053|      0|            if (v == NULL) {
  ------------------
  |  Branch (1053:17): [True: 0, False: 0]
  ------------------
 1054|      0|                session->opts.global_knownhosts =
 1055|      0|                    strdup(GLOBAL_CONF_DIR "/ssh_known_hosts");
  ------------------
  |  |   13|      0|#define GLOBAL_CONF_DIR "/etc/ssh"
  ------------------
 1056|      0|                if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (1056:21): [True: 0, False: 0]
  ------------------
 1057|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1058|      0|                    return -1;
 1059|      0|                }
 1060|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1060:24): [True: 0, False: 0]
  ------------------
 1061|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1062|      0|                return -1;
 1063|      0|            } else {
 1064|      0|                session->opts.global_knownhosts = strdup(v);
 1065|      0|                if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (1065:21): [True: 0, False: 0]
  ------------------
 1066|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1067|      0|                    return -1;
 1068|      0|                }
 1069|      0|                session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS;
  ------------------
  |  |  116|      0|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
 1070|      0|            }
 1071|      0|            break;
 1072|  1.31k|        case SSH_OPTIONS_TIMEOUT:
  ------------------
  |  Branch (1072:9): [True: 1.31k, False: 5.91k]
  ------------------
 1073|  1.31k|            if (value == NULL) {
  ------------------
  |  Branch (1073:17): [True: 0, False: 1.31k]
  ------------------
 1074|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1075|      0|                return -1;
 1076|  1.31k|            } else {
 1077|  1.31k|                long *x = (long *) value;
 1078|  1.31k|                if (*x < 0) {
  ------------------
  |  Branch (1078:21): [True: 0, False: 1.31k]
  ------------------
 1079|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1080|      0|                    return -1;
 1081|      0|                }
 1082|       |
 1083|  1.31k|                session->opts.timeout = *x & 0xffffffffU;
 1084|  1.31k|            }
 1085|  1.31k|            break;
 1086|  1.31k|        case SSH_OPTIONS_TIMEOUT_USEC:
  ------------------
  |  Branch (1086:9): [True: 0, False: 7.22k]
  ------------------
 1087|      0|            if (value == NULL) {
  ------------------
  |  Branch (1087:17): [True: 0, False: 0]
  ------------------
 1088|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1089|      0|                return -1;
 1090|      0|            } else {
 1091|      0|                long *x = (long *) value;
 1092|      0|                if (*x < 0) {
  ------------------
  |  Branch (1092:21): [True: 0, False: 0]
  ------------------
 1093|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1094|      0|                    return -1;
 1095|      0|                }
 1096|       |
 1097|      0|                session->opts.timeout_usec = *x & 0xffffffffU;
 1098|      0|            }
 1099|      0|            break;
 1100|      0|        case SSH_OPTIONS_SSH1:
  ------------------
  |  Branch (1100:9): [True: 0, False: 7.22k]
  ------------------
 1101|      0|            break;
 1102|      0|        case SSH_OPTIONS_SSH2:
  ------------------
  |  Branch (1102:9): [True: 0, False: 7.22k]
  ------------------
 1103|      0|            break;
 1104|      0|        case SSH_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (1104:9): [True: 0, False: 7.22k]
  ------------------
 1105|      0|            if (value == NULL) {
  ------------------
  |  Branch (1105:17): [True: 0, False: 0]
  ------------------
 1106|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1107|      0|                return -1;
 1108|      0|            } else {
 1109|      0|                int *x = (int *) value;
 1110|      0|                if (*x < 0) {
  ------------------
  |  Branch (1110:21): [True: 0, False: 0]
  ------------------
 1111|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1112|      0|                    return -1;
 1113|      0|                }
 1114|       |
 1115|      0|                session->common.log_verbosity = *x & 0xffffU;
 1116|      0|                ssh_set_log_level(*x & 0xffffU);
 1117|      0|            }
 1118|      0|            break;
 1119|      0|        case SSH_OPTIONS_LOG_VERBOSITY_STR:
  ------------------
  |  Branch (1119:9): [True: 0, False: 7.22k]
  ------------------
 1120|      0|            v = value;
 1121|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1121:17): [True: 0, False: 0]
  |  Branch (1121:30): [True: 0, False: 0]
  ------------------
 1122|      0|                session->common.log_verbosity = 0;
 1123|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1124|      0|                return -1;
 1125|      0|            } else {
 1126|      0|                q = strdup(v);
 1127|      0|                if (q == NULL) {
  ------------------
  |  Branch (1127:21): [True: 0, False: 0]
  ------------------
 1128|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1129|      0|                    return -1;
 1130|      0|                }
 1131|      0|                i = strtol(q, &p, 10);
 1132|      0|                if (q == p) {
  ------------------
  |  Branch (1132:21): [True: 0, False: 0]
  ------------------
 1133|      0|                    SSH_LOG(SSH_LOG_DEBUG, "No log verbositiy was parsed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1134|      0|                    SAFE_FREE(q);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1135|      0|                    return -1;
 1136|      0|                }
 1137|      0|                SAFE_FREE(q);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1138|      0|                if (i < 0) {
  ------------------
  |  Branch (1138:21): [True: 0, False: 0]
  ------------------
 1139|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1140|      0|                    return -1;
 1141|      0|                }
 1142|       |
 1143|      0|                session->common.log_verbosity = i & 0xffffU;
 1144|      0|                ssh_set_log_level(i & 0xffffU);
 1145|      0|            }
 1146|      0|            break;
 1147|    657|        case SSH_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (1147:9): [True: 657, False: 6.57k]
  ------------------
 1148|    657|            v = value;
 1149|    657|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1149:17): [True: 0, False: 657]
  |  Branch (1149:30): [True: 0, False: 657]
  ------------------
 1150|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1151|      0|                return -1;
 1152|    657|            } else {
 1153|    657|                rc = ssh_options_set_algo(session,
 1154|    657|                                          SSH_CRYPT_C_S,
 1155|    657|                                          v,
 1156|    657|                                          &wanted_methods[SSH_CRYPT_C_S]);
 1157|    657|                if (rc < 0)
  ------------------
  |  Branch (1157:21): [True: 0, False: 657]
  ------------------
 1158|      0|                    return -1;
 1159|    657|            }
 1160|    657|            break;
 1161|    657|        case SSH_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (1161:9): [True: 657, False: 6.57k]
  ------------------
 1162|    657|            v = value;
 1163|    657|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1163:17): [True: 0, False: 657]
  |  Branch (1163:30): [True: 0, False: 657]
  ------------------
 1164|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1165|      0|                return -1;
 1166|    657|            } else {
 1167|    657|                rc = ssh_options_set_algo(session,
 1168|    657|                                          SSH_CRYPT_S_C,
 1169|    657|                                          v,
 1170|    657|                                          &wanted_methods[SSH_CRYPT_S_C]);
 1171|    657|                if (rc < 0)
  ------------------
  |  Branch (1171:21): [True: 0, False: 657]
  ------------------
 1172|      0|                    return -1;
 1173|    657|            }
 1174|    657|            break;
 1175|    657|        case SSH_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (1175:9): [True: 0, False: 7.22k]
  ------------------
 1176|      0|            v = value;
 1177|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1177:17): [True: 0, False: 0]
  |  Branch (1177:30): [True: 0, False: 0]
  ------------------
 1178|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1179|      0|                return -1;
 1180|      0|            } else {
 1181|      0|                rc = ssh_options_set_algo(session,
 1182|      0|                                          SSH_KEX,
 1183|      0|                                          v,
 1184|      0|                                          &wanted_methods[SSH_KEX]);
 1185|      0|                if (rc < 0)
  ------------------
  |  Branch (1185:21): [True: 0, False: 0]
  ------------------
 1186|      0|                    return -1;
 1187|      0|            }
 1188|      0|            break;
 1189|      0|        case SSH_OPTIONS_HOSTKEYS:
  ------------------
  |  Branch (1189:9): [True: 0, False: 7.22k]
  ------------------
 1190|      0|            v = value;
 1191|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1191:17): [True: 0, False: 0]
  |  Branch (1191:30): [True: 0, False: 0]
  ------------------
 1192|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1193|      0|                return -1;
 1194|      0|            } else {
 1195|      0|                rc = ssh_options_set_algo(session,
 1196|      0|                                          SSH_HOSTKEYS,
 1197|      0|                                          v,
 1198|      0|                                          &wanted_methods[SSH_HOSTKEYS]);
 1199|      0|                if (rc < 0)
  ------------------
  |  Branch (1199:21): [True: 0, False: 0]
  ------------------
 1200|      0|                    return -1;
 1201|      0|            }
 1202|      0|            break;
 1203|      0|        case SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES:
  ------------------
  |  Branch (1203:9): [True: 0, False: 7.22k]
  ------------------
 1204|      0|            v = value;
 1205|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1205:17): [True: 0, False: 0]
  |  Branch (1205:30): [True: 0, False: 0]
  ------------------
 1206|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1207|      0|                return -1;
 1208|      0|            } else {
 1209|      0|                rc = ssh_options_set_algo(session,
 1210|      0|                                          SSH_HOSTKEYS,
 1211|      0|                                          v,
 1212|      0|                                          &session->opts.pubkey_accepted_types);
 1213|      0|                if (rc < 0)
  ------------------
  |  Branch (1213:21): [True: 0, False: 0]
  ------------------
 1214|      0|                    return -1;
 1215|      0|            }
 1216|      0|            break;
 1217|    657|        case SSH_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (1217:9): [True: 657, False: 6.57k]
  ------------------
 1218|    657|            v = value;
 1219|    657|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1219:17): [True: 0, False: 657]
  |  Branch (1219:30): [True: 0, False: 657]
  ------------------
 1220|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1221|      0|                return -1;
 1222|    657|            } else {
 1223|    657|                rc = ssh_options_set_algo(session,
 1224|    657|                                          SSH_MAC_C_S,
 1225|    657|                                          v,
 1226|    657|                                          &wanted_methods[SSH_MAC_C_S]);
 1227|    657|                if (rc < 0)
  ------------------
  |  Branch (1227:21): [True: 0, False: 657]
  ------------------
 1228|      0|                    return -1;
 1229|    657|            }
 1230|    657|            break;
 1231|    657|         case SSH_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (1231:10): [True: 657, False: 6.57k]
  ------------------
 1232|    657|            v = value;
 1233|    657|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1233:17): [True: 0, False: 657]
  |  Branch (1233:30): [True: 0, False: 657]
  ------------------
 1234|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1235|      0|                return -1;
 1236|    657|            } else {
 1237|    657|                rc = ssh_options_set_algo(session,
 1238|    657|                                          SSH_MAC_S_C,
 1239|    657|                                          v,
 1240|    657|                                          &wanted_methods[SSH_MAC_S_C]);
 1241|    657|                if (rc < 0)
  ------------------
  |  Branch (1241:21): [True: 0, False: 657]
  ------------------
 1242|      0|                    return -1;
 1243|    657|            }
 1244|    657|            break;
 1245|    657|        case SSH_OPTIONS_COMPRESSION_C_S:
  ------------------
  |  Branch (1245:9): [True: 0, False: 7.22k]
  ------------------
 1246|      0|            v = value;
 1247|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1247:17): [True: 0, False: 0]
  |  Branch (1247:30): [True: 0, False: 0]
  ------------------
 1248|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1249|      0|                return -1;
 1250|      0|            } else {
 1251|      0|                const char *tmp = v;
 1252|      0|                if (strcasecmp(value, "yes") == 0){
  ------------------
  |  Branch (1252:21): [True: 0, False: 0]
  ------------------
 1253|      0|                    tmp = "zlib@openssh.com,none";
 1254|      0|                } else if (strcasecmp(value, "no") == 0){
  ------------------
  |  Branch (1254:28): [True: 0, False: 0]
  ------------------
 1255|      0|                    tmp = "none,zlib@openssh.com";
 1256|      0|                }
 1257|      0|                rc = ssh_options_set_algo(session,
 1258|      0|                                          SSH_COMP_C_S,
 1259|      0|                                          tmp,
 1260|      0|                                          &wanted_methods[SSH_COMP_C_S]);
 1261|      0|                if (rc < 0)
  ------------------
  |  Branch (1261:21): [True: 0, False: 0]
  ------------------
 1262|      0|                    return -1;
 1263|      0|            }
 1264|      0|            break;
 1265|      0|        case SSH_OPTIONS_COMPRESSION_S_C:
  ------------------
  |  Branch (1265:9): [True: 0, False: 7.22k]
  ------------------
 1266|      0|            v = value;
 1267|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1267:17): [True: 0, False: 0]
  |  Branch (1267:30): [True: 0, False: 0]
  ------------------
 1268|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1269|      0|                return -1;
 1270|      0|            } else {
 1271|      0|                const char *tmp = v;
 1272|      0|                if (strcasecmp(value, "yes") == 0){
  ------------------
  |  Branch (1272:21): [True: 0, False: 0]
  ------------------
 1273|      0|                    tmp = "zlib@openssh.com,none";
 1274|      0|                } else if (strcasecmp(value, "no") == 0){
  ------------------
  |  Branch (1274:28): [True: 0, False: 0]
  ------------------
 1275|      0|                    tmp = "none,zlib@openssh.com";
 1276|      0|                }
 1277|       |
 1278|      0|                rc = ssh_options_set_algo(session,
 1279|      0|                                          SSH_COMP_S_C,
 1280|      0|                                          tmp,
 1281|      0|                                          &wanted_methods[SSH_COMP_S_C]);
 1282|      0|                if (rc < 0)
  ------------------
  |  Branch (1282:21): [True: 0, False: 0]
  ------------------
 1283|      0|                    return -1;
 1284|      0|            }
 1285|      0|            break;
 1286|      0|        case SSH_OPTIONS_COMPRESSION:
  ------------------
  |  Branch (1286:9): [True: 0, False: 7.22k]
  ------------------
 1287|      0|            v = value;
 1288|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1288:17): [True: 0, False: 0]
  |  Branch (1288:30): [True: 0, False: 0]
  ------------------
 1289|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1290|      0|                return -1;
 1291|      0|            }
 1292|      0|            if(ssh_options_set(session,SSH_OPTIONS_COMPRESSION_C_S, v) < 0)
  ------------------
  |  Branch (1292:16): [True: 0, False: 0]
  ------------------
 1293|      0|                return -1;
 1294|      0|            if(ssh_options_set(session,SSH_OPTIONS_COMPRESSION_S_C, v) < 0)
  ------------------
  |  Branch (1294:16): [True: 0, False: 0]
  ------------------
 1295|      0|                return -1;
 1296|      0|            break;
 1297|      0|        case SSH_OPTIONS_COMPRESSION_LEVEL:
  ------------------
  |  Branch (1297:9): [True: 0, False: 7.22k]
  ------------------
 1298|      0|            if (value == NULL) {
  ------------------
  |  Branch (1298:17): [True: 0, False: 0]
  ------------------
 1299|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1300|      0|                return -1;
 1301|      0|            } else {
 1302|      0|                int *x = (int *)value;
 1303|      0|                if (*x < 1 || *x > 9) {
  ------------------
  |  Branch (1303:21): [True: 0, False: 0]
  |  Branch (1303:31): [True: 0, False: 0]
  ------------------
 1304|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1305|      0|                    return -1;
 1306|      0|                }
 1307|      0|                session->opts.compressionlevel = *x & 0xff;
 1308|      0|            }
 1309|      0|            break;
 1310|      0|        case SSH_OPTIONS_STRICTHOSTKEYCHECK:
  ------------------
  |  Branch (1310:9): [True: 0, False: 7.22k]
  ------------------
 1311|      0|            if (value == NULL) {
  ------------------
  |  Branch (1311:17): [True: 0, False: 0]
  ------------------
 1312|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1313|      0|                return -1;
 1314|      0|            } else {
 1315|      0|                int *x = (int *) value;
 1316|      0|                int mode = *x;
 1317|       |
 1318|      0|                switch (mode) {
 1319|      0|                case SSH_STRICT_HOSTKEY_OFF:
  ------------------
  |  Branch (1319:17): [True: 0, False: 0]
  ------------------
 1320|      0|                case SSH_STRICT_HOSTKEY_YES:
  ------------------
  |  Branch (1320:17): [True: 0, False: 0]
  ------------------
 1321|      0|                case SSH_STRICT_HOSTKEY_ASK:
  ------------------
  |  Branch (1321:17): [True: 0, False: 0]
  ------------------
 1322|      0|                case SSH_STRICT_HOSTKEY_ACCEPT_NEW:
  ------------------
  |  Branch (1322:17): [True: 0, False: 0]
  ------------------
 1323|      0|                    session->opts.StrictHostKeyChecking = mode;
 1324|      0|                    break;
 1325|      0|                default:
  ------------------
  |  Branch (1325:17): [True: 0, False: 0]
  ------------------
 1326|       |                    /* Preserve the legacy low-byte "non-zero means yes"
 1327|       |                     * normalization.
 1328|       |                     */
 1329|      0|                    session->opts.StrictHostKeyChecking =
 1330|      0|                        (mode & 0xff) > 0 ? SSH_STRICT_HOSTKEY_YES
  ------------------
  |  Branch (1330:25): [True: 0, False: 0]
  ------------------
 1331|      0|                                          : SSH_STRICT_HOSTKEY_OFF;
 1332|      0|                    break;
 1333|      0|                }
 1334|      0|            }
 1335|      0|            break;
 1336|      0|        case SSH_OPTIONS_PROXYCOMMAND:
  ------------------
  |  Branch (1336:9): [True: 0, False: 7.22k]
  ------------------
 1337|      0|            v = value;
 1338|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1338:17): [True: 0, False: 0]
  |  Branch (1338:30): [True: 0, False: 0]
  ------------------
 1339|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1340|      0|                return -1;
 1341|      0|            } else {
 1342|      0|                SAFE_FREE(session->opts.ProxyCommand);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1343|       |                /* Setting the command to 'none' disables this option. */
 1344|      0|                rc = strcasecmp(v, "none");
 1345|      0|                if (rc != 0) {
  ------------------
  |  Branch (1345:21): [True: 0, False: 0]
  ------------------
 1346|      0|                    q = strdup(v);
 1347|      0|                    if (q == NULL) {
  ------------------
  |  Branch (1347:25): [True: 0, False: 0]
  ------------------
 1348|      0|                        return -1;
 1349|      0|                    }
 1350|      0|                    session->opts.ProxyCommand = q;
 1351|      0|                    session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_PROXYCOMMAND;
  ------------------
  |  |  117|      0|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
 1352|      0|                }
 1353|      0|            }
 1354|      0|            break;
 1355|      0|        case SSH_OPTIONS_PROXYJUMP:
  ------------------
  |  Branch (1355:9): [True: 0, False: 7.22k]
  ------------------
 1356|      0|            v = value;
 1357|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1357:17): [True: 0, False: 0]
  |  Branch (1357:30): [True: 0, False: 0]
  ------------------
 1358|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1359|      0|                return -1;
 1360|      0|            } else {
 1361|      0|                rc = ssh_config_parse_proxy_jump(session, v, true);
 1362|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1362:21): [True: 0, False: 0]
  ------------------
 1363|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1364|      0|                }
 1365|      0|            }
 1366|      0|            break;
 1367|      0|        case SSH_OPTIONS_PROXYJUMP_CB_LIST_APPEND:
  ------------------
  |  Branch (1367:9): [True: 0, False: 7.22k]
  ------------------
 1368|      0|            j = (struct ssh_jump_callbacks_struct *)value;
 1369|      0|            if (j == NULL) {
  ------------------
  |  Branch (1369:17): [True: 0, False: 0]
  ------------------
 1370|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1371|      0|                return -1;
 1372|      0|            } else {
 1373|      0|                rc = ssh_list_prepend(session->opts.proxy_jumps_user_cb, j);
 1374|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1374:21): [True: 0, False: 0]
  ------------------
 1375|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1376|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1377|      0|                }
 1378|      0|            }
 1379|      0|            break;
 1380|      0|        case SSH_OPTIONS_GSSAPI_SERVER_IDENTITY:
  ------------------
  |  Branch (1380:9): [True: 0, False: 7.22k]
  ------------------
 1381|      0|            v = value;
 1382|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1382:17): [True: 0, False: 0]
  |  Branch (1382:30): [True: 0, False: 0]
  ------------------
 1383|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1384|      0|                return -1;
 1385|      0|            } else {
 1386|      0|                SAFE_FREE(session->opts.gss_server_identity);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1387|      0|                session->opts.gss_server_identity = strdup(v);
 1388|      0|                if (session->opts.gss_server_identity == NULL) {
  ------------------
  |  Branch (1388:21): [True: 0, False: 0]
  ------------------
 1389|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1390|      0|                    return -1;
 1391|      0|                }
 1392|      0|            }
 1393|      0|            break;
 1394|      0|        case SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY:
  ------------------
  |  Branch (1394:9): [True: 0, False: 7.22k]
  ------------------
 1395|      0|            v = value;
 1396|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1396:17): [True: 0, False: 0]
  |  Branch (1396:30): [True: 0, False: 0]
  ------------------
 1397|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1398|      0|                return -1;
 1399|      0|            } else {
 1400|      0|                SAFE_FREE(session->opts.gss_client_identity);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1401|      0|                session->opts.gss_client_identity = strdup(v);
 1402|      0|                if (session->opts.gss_client_identity == NULL) {
  ------------------
  |  Branch (1402:21): [True: 0, False: 0]
  ------------------
 1403|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1404|      0|                    return -1;
 1405|      0|                }
 1406|      0|            }
 1407|      0|            break;
 1408|      0|        case SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS:
  ------------------
  |  Branch (1408:9): [True: 0, False: 7.22k]
  ------------------
 1409|      0|            if (value == NULL) {
  ------------------
  |  Branch (1409:17): [True: 0, False: 0]
  ------------------
 1410|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1411|      0|                return -1;
 1412|      0|            } else {
 1413|      0|                int x = *(int *)value;
 1414|       |
 1415|      0|                session->opts.gss_delegate_creds = (x & 0xff);
 1416|      0|            }
 1417|      0|            break;
 1418|       |#ifdef WITH_GSSAPI
 1419|       |        case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE:
 1420|       |            if (value == NULL) {
 1421|       |                ssh_set_error_invalid(session);
 1422|       |                return -1;
 1423|       |            } else {
 1424|       |                bool *x = (bool *)value;
 1425|       |                session->opts.gssapi_key_exchange = *x;
 1426|       |            }
 1427|       |            break;
 1428|       |        case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE_ALGS:
 1429|       |            v = value;
 1430|       |            if (v == NULL || v[0] == '\0') {
 1431|       |                ssh_set_error_invalid(session);
 1432|       |                return -1;
 1433|       |            } else {
 1434|       |                /* Check if algorithms are supported */
 1435|       |                char *ret =
 1436|       |                    ssh_find_all_matching(GSSAPI_KEY_EXCHANGE_SUPPORTED, v);
 1437|       |                if (ret == NULL) {
 1438|       |                    ssh_set_error(session,
 1439|       |                                  SSH_FATAL,
 1440|       |                                  "GSSAPI key exchange algorithms not "
 1441|       |                                  "supported or invalid");
 1442|       |                    return -1;
 1443|       |                }
 1444|       |                SAFE_FREE(session->opts.gssapi_key_exchange_algs);
 1445|       |                session->opts.gssapi_key_exchange_algs = ret;
 1446|       |            }
 1447|       |            break;
 1448|       |#endif
 1449|      0|        case SSH_OPTIONS_PASSWORD_AUTH:
  ------------------
  |  Branch (1449:9): [True: 0, False: 7.22k]
  ------------------
 1450|      0|        case SSH_OPTIONS_PUBKEY_AUTH:
  ------------------
  |  Branch (1450:9): [True: 0, False: 7.22k]
  ------------------
 1451|      0|        case SSH_OPTIONS_KBDINT_AUTH:
  ------------------
  |  Branch (1451:9): [True: 0, False: 7.22k]
  ------------------
 1452|      0|        case SSH_OPTIONS_GSSAPI_AUTH:
  ------------------
  |  Branch (1452:9): [True: 0, False: 7.22k]
  ------------------
 1453|      0|            if (value == NULL) {
  ------------------
  |  Branch (1453:17): [True: 0, False: 0]
  ------------------
 1454|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1455|      0|                return -1;
 1456|      0|            } else {
 1457|      0|                int x = *(int *)value;
 1458|      0|                u = type == SSH_OPTIONS_PASSWORD_AUTH ?
  ------------------
  |  Branch (1458:21): [True: 0, False: 0]
  ------------------
 1459|      0|                    SSH_OPT_FLAG_PASSWORD_AUTH:
  ------------------
  |  |  109|      0|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
 1460|      0|                    type == SSH_OPTIONS_PUBKEY_AUTH ?
  ------------------
  |  Branch (1460:21): [True: 0, False: 0]
  ------------------
 1461|      0|                        SSH_OPT_FLAG_PUBKEY_AUTH:
  ------------------
  |  |  110|      0|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
 1462|      0|                        type == SSH_OPTIONS_KBDINT_AUTH ?
  ------------------
  |  Branch (1462:25): [True: 0, False: 0]
  ------------------
 1463|      0|                            SSH_OPT_FLAG_KBDINT_AUTH:
  ------------------
  |  |  111|      0|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
 1464|      0|                            SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|      0|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
 1465|      0|                if (x != 0) {
  ------------------
  |  Branch (1465:21): [True: 0, False: 0]
  ------------------
 1466|      0|                    session->opts.flags |= u;
 1467|      0|                } else {
 1468|      0|                    session->opts.flags &= ~u;
 1469|      0|                }
 1470|      0|                if (type == SSH_OPTIONS_PUBKEY_AUTH) {
  ------------------
  |  Branch (1470:21): [True: 0, False: 0]
  ------------------
 1471|       |                    /*
 1472|       |                     * Keep the legacy enabled/disabled auth flag semantics in
 1473|       |                     * sync above while also storing the selected
 1474|       |                     * PubkeyAuthentication mode here.
 1475|       |                     */
 1476|      0|                    switch (x) {
 1477|      0|                    case SSH_PUBKEY_AUTH_NO:
  ------------------
  |  Branch (1477:21): [True: 0, False: 0]
  ------------------
 1478|      0|                    case SSH_PUBKEY_AUTH_ALL:
  ------------------
  |  Branch (1478:21): [True: 0, False: 0]
  ------------------
 1479|      0|                    case SSH_PUBKEY_AUTH_UNBOUND:
  ------------------
  |  Branch (1479:21): [True: 0, False: 0]
  ------------------
 1480|      0|                    case SSH_PUBKEY_AUTH_HOST_BOUND:
  ------------------
  |  Branch (1480:21): [True: 0, False: 0]
  ------------------
 1481|      0|                        session->opts.pubkey_auth = x;
 1482|      0|                        break;
 1483|      0|                    default:
  ------------------
  |  Branch (1483:21): [True: 0, False: 0]
  ------------------
 1484|       |                        /* Preserve the legacy non-zero "yes" normalization
 1485|       |                         * here so callers passing -1 still land on
 1486|       |                         * SSH_PUBKEY_AUTH_ALL.
 1487|       |                         */
 1488|      0|                        session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
 1489|      0|                        break;
 1490|      0|                    }
 1491|      0|                }
 1492|      0|            }
 1493|      0|            break;
 1494|      0|        case SSH_OPTIONS_NODELAY:
  ------------------
  |  Branch (1494:9): [True: 0, False: 7.22k]
  ------------------
 1495|      0|            if (value == NULL) {
  ------------------
  |  Branch (1495:17): [True: 0, False: 0]
  ------------------
 1496|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1497|      0|                return -1;
 1498|      0|            } else {
 1499|      0|                int *x = (int *) value;
 1500|      0|                session->opts.nodelay = (*x & 0xff) > 0 ? 1 : 0;
  ------------------
  |  Branch (1500:41): [True: 0, False: 0]
  ------------------
 1501|      0|            }
 1502|      0|            break;
 1503|    657|        case SSH_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (1503:9): [True: 657, False: 6.57k]
  ------------------
 1504|    657|            if (value == NULL) {
  ------------------
  |  Branch (1504:17): [True: 0, False: 657]
  ------------------
 1505|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1506|      0|                return -1;
 1507|    657|            } else {
 1508|    657|                bool *x = (bool *)value;
 1509|    657|                session->opts.config_processed = !(*x);
 1510|    657|            }
 1511|    657|            break;
 1512|    657|        case SSH_OPTIONS_REKEY_DATA:
  ------------------
  |  Branch (1512:9): [True: 0, False: 7.22k]
  ------------------
 1513|      0|            if (value == NULL) {
  ------------------
  |  Branch (1513:17): [True: 0, False: 0]
  ------------------
 1514|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1515|      0|                return -1;
 1516|      0|            } else {
 1517|      0|                uint64_t *x = (uint64_t *)value;
 1518|      0|                session->opts.rekey_data = *x;
 1519|      0|            }
 1520|      0|            break;
 1521|      0|        case SSH_OPTIONS_REKEY_TIME:
  ------------------
  |  Branch (1521:9): [True: 0, False: 7.22k]
  ------------------
 1522|      0|            if (value == NULL) {
  ------------------
  |  Branch (1522:17): [True: 0, False: 0]
  ------------------
 1523|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1524|      0|                return -1;
 1525|      0|            } else {
 1526|      0|                uint32_t *x = (uint32_t *)value;
 1527|      0|                if ((*x * 1000) < *x) {
  ------------------
  |  Branch (1527:21): [True: 0, False: 0]
  ------------------
 1528|      0|                    ssh_set_error(session, SSH_REQUEST_DENIED,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1529|      0|                                  "The provided value (%" PRIu32 ") for rekey"
 1530|      0|                                  " time is too large", *x);
 1531|      0|                    return -1;
 1532|      0|                }
 1533|      0|                session->opts.rekey_time = (*x) * 1000;
 1534|      0|            }
 1535|      0|            break;
 1536|      0|        case SSH_OPTIONS_RSA_MIN_SIZE:
  ------------------
  |  Branch (1536:9): [True: 0, False: 7.22k]
  ------------------
 1537|      0|            if (value == NULL) {
  ------------------
  |  Branch (1537:17): [True: 0, False: 0]
  ------------------
 1538|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1539|      0|                return -1;
 1540|      0|            } else {
 1541|      0|                int *x = (int *)value;
 1542|       |
 1543|      0|                if (*x < 0) {
  ------------------
  |  Branch (1543:21): [True: 0, False: 0]
  ------------------
 1544|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1545|      0|                    return -1;
 1546|      0|                }
 1547|       |
 1548|       |                /* (*x == 0) is allowed as it is used to revert to default */
 1549|       |
 1550|      0|                if (*x > 0 && *x < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|      0|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (1550:21): [True: 0, False: 0]
  |  Branch (1550:31): [True: 0, False: 0]
  ------------------
 1551|      0|                    ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1552|      0|                                  SSH_REQUEST_DENIED,
 1553|      0|                                  "The provided value (%d) for minimal RSA key "
 1554|      0|                                  "size is too small. Use at least %d bits.",
 1555|      0|                                  *x,
 1556|      0|                                  RSA_MIN_KEY_SIZE);
 1557|      0|                    return -1;
 1558|      0|                }
 1559|      0|                session->opts.rsa_min_size = *x;
 1560|      0|            }
 1561|      0|            break;
 1562|      0|        case SSH_OPTIONS_IDENTITY_AGENT:
  ------------------
  |  Branch (1562:9): [True: 0, False: 7.22k]
  ------------------
 1563|      0|            v = value;
 1564|      0|            SAFE_FREE(session->opts.agent_socket);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1565|      0|            if (v == NULL) {
  ------------------
  |  Branch (1565:17): [True: 0, False: 0]
  ------------------
 1566|       |                /* The default value will be set by the ssh_options_apply() */
 1567|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1567:24): [True: 0, False: 0]
  ------------------
 1568|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1569|      0|                return -1;
 1570|      0|            } else {
 1571|      0|                session->opts.agent_socket = ssh_path_expand_tilde(v);
 1572|      0|                if (session->opts.agent_socket == NULL) {
  ------------------
  |  Branch (1572:21): [True: 0, False: 0]
  ------------------
 1573|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1574|      0|                    return -1;
 1575|      0|                }
 1576|      0|            }
 1577|      0|            break;
 1578|      0|        case SSH_OPTIONS_IDENTITIES_ONLY:
  ------------------
  |  Branch (1578:9): [True: 0, False: 7.22k]
  ------------------
 1579|      0|            if (value == NULL) {
  ------------------
  |  Branch (1579:17): [True: 0, False: 0]
  ------------------
 1580|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1581|      0|                return -1;
 1582|      0|            } else {
 1583|      0|                bool *x = (bool *)value;
 1584|      0|                session->opts.identities_only = *x;
 1585|      0|            }
 1586|      0|            break;
 1587|      0|        case SSH_OPTIONS_CONTROL_MASTER:
  ------------------
  |  Branch (1587:9): [True: 0, False: 7.22k]
  ------------------
 1588|      0|            if (value == NULL) {
  ------------------
  |  Branch (1588:17): [True: 0, False: 0]
  ------------------
 1589|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1590|      0|                return -1;
 1591|      0|            } else {
 1592|      0|                int *x = (int *) value;
 1593|      0|                if (*x < SSH_CONTROL_MASTER_NO || *x > SSH_CONTROL_MASTER_AUTOASK) {
  ------------------
  |  Branch (1593:21): [True: 0, False: 0]
  |  Branch (1593:51): [True: 0, False: 0]
  ------------------
 1594|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1595|      0|                    return -1;
 1596|      0|                }
 1597|      0|                session->opts.control_master = *x;
 1598|      0|            }
 1599|      0|            break;
 1600|      0|        case SSH_OPTIONS_CONTROL_PATH:
  ------------------
  |  Branch (1600:9): [True: 0, False: 7.22k]
  ------------------
 1601|      0|            v = value;
 1602|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1602:17): [True: 0, False: 0]
  |  Branch (1602:30): [True: 0, False: 0]
  ------------------
 1603|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1604|      0|                return -1;
 1605|      0|            } else {
 1606|      0|                SAFE_FREE(session->opts.control_path);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1607|      0|                rc = strcasecmp(v, "none");
 1608|      0|                if (rc != 0) {
  ------------------
  |  Branch (1608:21): [True: 0, False: 0]
  ------------------
 1609|      0|                    session->opts.control_path = ssh_path_expand_tilde(v);
 1610|      0|                    if (session->opts.control_path == NULL) {
  ------------------
  |  Branch (1610:25): [True: 0, False: 0]
  ------------------
 1611|      0|                        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1612|      0|                        return -1;
 1613|      0|                    }
 1614|      0|                    session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_CONTROL_PATH;
  ------------------
  |  |  119|      0|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
 1615|      0|                }
 1616|      0|            }
 1617|      0|            break;
 1618|      0|        case SSH_OPTIONS_PKI_CONTEXT:
  ------------------
  |  Branch (1618:9): [True: 0, False: 7.22k]
  ------------------
 1619|      0|            if (value == NULL) {
  ------------------
  |  Branch (1619:17): [True: 0, False: 0]
  ------------------
 1620|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1621|      0|                return -1;
 1622|      0|            }
 1623|       |
 1624|      0|            SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1044|      0|    do {                         \
  |  | 1045|      0|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1045:13): [True: 0, False: 0]
  |  |  ------------------
  |  | 1046|      0|            ssh_pki_ctx_free(x); \
  |  | 1047|      0|            x = NULL;            \
  |  | 1048|      0|        }                        \
  |  | 1049|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1049:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1625|       |
 1626|      0|            session->pki_context = ssh_pki_ctx_dup((const ssh_pki_ctx)value);
 1627|      0|            if (session->pki_context == NULL) {
  ------------------
  |  Branch (1627:17): [True: 0, False: 0]
  ------------------
 1628|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1629|      0|                return -1;
 1630|      0|            }
 1631|      0|            break;
 1632|      0|        case SSH_OPTIONS_ADDRESS_FAMILY:
  ------------------
  |  Branch (1632:9): [True: 0, False: 7.22k]
  ------------------
 1633|      0|            if (value == NULL) {
  ------------------
  |  Branch (1633:17): [True: 0, False: 0]
  ------------------
 1634|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1635|      0|                return -1;
 1636|      0|            } else {
 1637|      0|                int *x = (int *)value;
 1638|      0|                if (*x < SSH_ADDRESS_FAMILY_ANY ||
  ------------------
  |  Branch (1638:21): [True: 0, False: 0]
  ------------------
 1639|      0|                    *x > SSH_ADDRESS_FAMILY_INET6) {
  ------------------
  |  Branch (1639:21): [True: 0, False: 0]
  ------------------
 1640|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1641|      0|                    return -1;
 1642|      0|                }
 1643|      0|                session->opts.address_family = *x;
 1644|      0|            }
 1645|      0|            break;
 1646|      0|        case SSH_OPTIONS_BATCH_MODE:
  ------------------
  |  Branch (1646:9): [True: 0, False: 7.22k]
  ------------------
 1647|      0|            if (value == NULL) {
  ------------------
  |  Branch (1647:17): [True: 0, False: 0]
  ------------------
 1648|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1649|      0|                return -1;
 1650|      0|            } else {
 1651|      0|                bool *x = (bool *)value;
 1652|      0|                session->opts.batch_mode = *x;
 1653|      0|            }
 1654|      0|            break;
 1655|      0|        case SSH_OPTIONS_PREFERRED_AUTHENTICATIONS:
  ------------------
  |  Branch (1655:9): [True: 0, False: 7.22k]
  ------------------
 1656|      0|            v = value;
 1657|      0|            SAFE_FREE(session->opts.preferred_authentications);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1658|      0|            if (v != NULL) {
  ------------------
  |  Branch (1658:17): [True: 0, False: 0]
  ------------------
 1659|      0|                if (v[0] == '\0') {
  ------------------
  |  Branch (1659:21): [True: 0, False: 0]
  ------------------
 1660|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1661|      0|                    return -1;
 1662|      0|                }
 1663|      0|                session->opts.preferred_authentications = strdup(v);
 1664|      0|                if (session->opts.preferred_authentications == NULL) {
  ------------------
  |  Branch (1664:21): [True: 0, False: 0]
  ------------------
 1665|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1666|      0|                    return -1;
 1667|      0|                }
 1668|      0|            }
 1669|      0|            break;
 1670|      0|        case SSH_OPTIONS_NUMBER_OF_PASSWORD_PROMPTS:
  ------------------
  |  Branch (1670:9): [True: 0, False: 7.22k]
  ------------------
 1671|      0|            if (value == NULL) {
  ------------------
  |  Branch (1671:17): [True: 0, False: 0]
  ------------------
 1672|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1673|      0|                return -1;
 1674|      0|            } else {
 1675|      0|                int *x = (int *)value;
 1676|      0|                if (*x <= 0) {
  ------------------
  |  Branch (1676:21): [True: 0, False: 0]
  ------------------
 1677|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1678|      0|                    return -1;
 1679|      0|                }
 1680|      0|                session->opts.number_of_password_prompts = *x;
 1681|      0|            }
 1682|      0|            break;
 1683|      0|        case SSH_OPTIONS_REQUEST_TTY:
  ------------------
  |  Branch (1683:9): [True: 0, False: 7.22k]
  ------------------
 1684|      0|            if (value == NULL) {
  ------------------
  |  Branch (1684:17): [True: 0, False: 0]
  ------------------
 1685|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1686|      0|                return -1;
 1687|      0|            } else {
 1688|      0|                int *x = (int *)value;
 1689|      0|                if (*x < SSH_REQUEST_TTY_NO || *x > SSH_REQUEST_TTY_FORCE) {
  ------------------
  |  Branch (1689:21): [True: 0, False: 0]
  |  Branch (1689:48): [True: 0, False: 0]
  ------------------
 1690|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1691|      0|                    return -1;
 1692|      0|                }
 1693|      0|                session->opts.request_tty = *x;
 1694|      0|            }
 1695|      0|            break;
 1696|      0|        default:
  ------------------
  |  Branch (1696:9): [True: 0, False: 7.22k]
  ------------------
 1697|      0|            ssh_set_error(session, SSH_REQUEST_DENIED, "Unknown ssh option %d", type);
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1698|      0|            return -1;
 1699|      0|            break;
 1700|  7.22k|    }
 1701|       |
 1702|  7.22k|    return 0;
 1703|  7.22k|}
ssh_options_apply:
 2382|    657|{
 2383|    657|    char *tmp = NULL;
 2384|    657|    int rc;
 2385|       |
 2386|    657|    if (session->opts.host != NULL) {
  ------------------
  |  Branch (2386:9): [True: 657, False: 0]
  ------------------
 2387|    657|        char *normalized_host = NULL;
 2388|    657|        rc = ssh_normalize_loose_ip(session->opts.host, &normalized_host);
 2389|    657|        if (rc == -1) {
  ------------------
  |  Branch (2389:13): [True: 0, False: 657]
  ------------------
 2390|       |            /* Error (e.g. NULL input or OOM) — leave host as it is */
 2391|    657|        } else if (rc == 0) {
  ------------------
  |  Branch (2391:20): [True: 0, False: 657]
  ------------------
 2392|       |            /* Was a loose IP — use the normalized dotted-quad form */
 2393|      0|            SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2394|      0|            session->opts.host = normalized_host;
 2395|    657|        } else {
 2396|       |            /* rc == 1: not a loose IP — lowercase if it's not a strict IP */
 2397|    657|            bool is_ip = ssh_is_ipaddr(session->opts.host);
 2398|    657|            if (!is_ip) {
  ------------------
  |  Branch (2398:17): [True: 657, False: 0]
  ------------------
 2399|    657|                char *lower = ssh_lowercase(session->opts.host);
 2400|    657|                if (lower != NULL) {
  ------------------
  |  Branch (2400:21): [True: 657, False: 0]
  ------------------
 2401|    657|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
 2402|    657|                    session->opts.host = lower;
 2403|    657|                }
 2404|    657|            }
 2405|    657|        }
 2406|    657|    }
 2407|       |
 2408|    657|    if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (2408:9): [True: 657, False: 0]
  ------------------
 2409|    657|        rc = ssh_options_set(session, SSH_OPTIONS_SSH_DIR, NULL);
 2410|    657|        if (rc < 0) {
  ------------------
  |  Branch (2410:13): [True: 0, False: 657]
  ------------------
 2411|      0|            return -1;
 2412|      0|        }
 2413|    657|    }
 2414|       |
 2415|    657|    if (session->opts.username == NULL) {
  ------------------
  |  Branch (2415:9): [True: 0, False: 657]
  ------------------
 2416|      0|        rc = ssh_options_set(session, SSH_OPTIONS_USER, NULL);
 2417|      0|        if (rc < 0) {
  ------------------
  |  Branch (2417:13): [True: 0, False: 0]
  ------------------
 2418|      0|            return -1;
 2419|      0|        }
 2420|      0|    }
 2421|       |
 2422|    657|    if (session->opts.config_hostname != NULL) {
  ------------------
  |  Branch (2422:9): [True: 0, False: 657]
  ------------------
 2423|      0|        char *saved_host = NULL;
 2424|       |
 2425|      0|        tmp = ssh_path_expand_hostname(session, session->opts.config_hostname);
 2426|      0|        if (tmp == NULL) {
  ------------------
  |  Branch (2426:13): [True: 0, False: 0]
  ------------------
 2427|      0|            return -1;
 2428|      0|        }
 2429|      0|        if (session->opts.host != NULL) {
  ------------------
  |  Branch (2429:13): [True: 0, False: 0]
  ------------------
 2430|      0|            saved_host = strdup(session->opts.host);
 2431|      0|            if (saved_host == NULL) {
  ------------------
  |  Branch (2431:17): [True: 0, False: 0]
  ------------------
 2432|      0|                free(tmp);
 2433|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2434|      0|                return -1;
 2435|      0|            }
 2436|      0|        }
 2437|      0|        session->opts.config_hostname_only = true;
 2438|      0|        rc = ssh_options_set(session, SSH_OPTIONS_HOST, tmp);
 2439|      0|        session->opts.config_hostname_only = false;
 2440|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2440:13): [True: 0, False: 0]
  ------------------
 2441|       |            /* If HostName expansion leaves a literal '%', keep the current
 2442|       |             * host instead of treating the deferred HostName as fatal.
 2443|       |             */
 2444|      0|            if (strchr(tmp, '%') == NULL) {
  ------------------
  |  Branch (2444:17): [True: 0, False: 0]
  ------------------
 2445|      0|                SAFE_FREE(saved_host);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2446|      0|                free(tmp);
 2447|      0|                return -1;
 2448|      0|            }
 2449|      0|            SSH_LOG(SSH_LOG_WARN,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2450|      0|                    "HostName %s contains unknown expansion tokens and could "
 2451|      0|                    "not be applied; falling back to current host",
 2452|      0|                    tmp);
 2453|      0|            SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2454|      0|            session->opts.host = saved_host;
 2455|      0|            saved_host = NULL;
 2456|      0|        }
 2457|      0|        SAFE_FREE(saved_host);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2458|      0|        free(tmp);
 2459|      0|        SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2460|      0|    }
 2461|       |
 2462|    657|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_KNOWNHOSTS) == 0) {
  ------------------
  |  |  115|    657|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
  |  Branch (2462:9): [True: 657, False: 0]
  ------------------
 2463|    657|        if (session->opts.knownhosts == NULL) {
  ------------------
  |  Branch (2463:13): [True: 657, False: 0]
  ------------------
 2464|    657|            tmp = ssh_path_expand_escape(session, "%d/.ssh/known_hosts");
 2465|    657|        } else {
 2466|      0|            tmp = ssh_path_expand_escape(session, session->opts.knownhosts);
 2467|      0|        }
 2468|    657|        if (tmp == NULL) {
  ------------------
  |  Branch (2468:13): [True: 0, False: 657]
  ------------------
 2469|      0|            return -1;
 2470|      0|        }
 2471|    657|        free(session->opts.knownhosts);
 2472|    657|        session->opts.knownhosts = tmp;
 2473|    657|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_KNOWNHOSTS;
  ------------------
  |  |  115|    657|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
 2474|    657|    }
 2475|       |
 2476|    657|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS) == 0) {
  ------------------
  |  |  116|    657|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
  |  Branch (2476:9): [True: 657, False: 0]
  ------------------
 2477|    657|        if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (2477:13): [True: 657, False: 0]
  ------------------
 2478|    657|            tmp = strdup(GLOBAL_CONF_DIR "/ssh_known_hosts");
  ------------------
  |  |   13|    657|#define GLOBAL_CONF_DIR "/etc/ssh"
  ------------------
 2479|    657|        } else {
 2480|      0|            tmp = ssh_path_expand_escape(session,
 2481|      0|                                         session->opts.global_knownhosts);
 2482|      0|        }
 2483|    657|        if (tmp == NULL) {
  ------------------
  |  Branch (2483:13): [True: 0, False: 657]
  ------------------
 2484|      0|            return -1;
 2485|      0|        }
 2486|    657|        free(session->opts.global_knownhosts);
 2487|    657|        session->opts.global_knownhosts = tmp;
 2488|    657|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS;
  ------------------
  |  |  116|    657|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
 2489|    657|    }
 2490|       |
 2491|       |
 2492|    657|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_PROXYCOMMAND) == 0) {
  ------------------
  |  |  117|    657|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
  |  Branch (2492:9): [True: 657, False: 0]
  ------------------
 2493|    657|        if (session->opts.ProxyCommand != NULL) {
  ------------------
  |  Branch (2493:13): [True: 0, False: 657]
  ------------------
 2494|      0|            char *p = NULL;
 2495|      0|            size_t plen = strlen(session->opts.ProxyCommand) +
 2496|      0|                          5 /* strlen("exec ") */;
 2497|       |
 2498|      0|            if (strncmp(session->opts.ProxyCommand, "exec ", 5) != 0) {
  ------------------
  |  Branch (2498:17): [True: 0, False: 0]
  ------------------
 2499|      0|                p = malloc(plen + 1 /* \0 */);
 2500|      0|                if (p == NULL) {
  ------------------
  |  Branch (2500:21): [True: 0, False: 0]
  ------------------
 2501|      0|                    return -1;
 2502|      0|                }
 2503|       |
 2504|      0|                rc = snprintf(p, plen + 1, "exec %s", session->opts.ProxyCommand);
 2505|      0|                if ((size_t)rc != plen) {
  ------------------
  |  Branch (2505:21): [True: 0, False: 0]
  ------------------
 2506|      0|                    free(p);
 2507|      0|                    return -1;
 2508|      0|                }
 2509|      0|                tmp = ssh_path_expand_escape(session, p);
 2510|      0|                free(p);
 2511|      0|            } else {
 2512|      0|                tmp = ssh_path_expand_escape(session,
 2513|      0|                                             session->opts.ProxyCommand);
 2514|      0|            }
 2515|       |
 2516|      0|            if (tmp == NULL) {
  ------------------
  |  Branch (2516:17): [True: 0, False: 0]
  ------------------
 2517|      0|                return -1;
 2518|      0|            }
 2519|      0|            free(session->opts.ProxyCommand);
 2520|      0|            session->opts.ProxyCommand = tmp;
 2521|      0|            session->opts.exp_flags |= SSH_OPT_EXP_FLAG_PROXYCOMMAND;
  ------------------
  |  |  117|      0|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
 2522|      0|        }
 2523|    657|    }
 2524|       |
 2525|    657|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_CONTROL_PATH) == 0) {
  ------------------
  |  |  119|    657|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
  |  Branch (2525:9): [True: 657, False: 0]
  ------------------
 2526|    657|        if (session->opts.control_path != NULL) {
  ------------------
  |  Branch (2526:13): [True: 0, False: 657]
  ------------------
 2527|      0|            tmp = ssh_path_expand_escape(session, session->opts.control_path);
 2528|      0|            if (tmp == NULL) {
  ------------------
  |  Branch (2528:17): [True: 0, False: 0]
  ------------------
 2529|      0|                return -1;
 2530|      0|            }
 2531|      0|            free(session->opts.control_path);
 2532|      0|            session->opts.control_path = tmp;
 2533|      0|            session->opts.exp_flags |= SSH_OPT_EXP_FLAG_CONTROL_PATH;
  ------------------
  |  |  119|      0|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
 2534|      0|        }
 2535|    657|    }
 2536|       |
 2537|    657|    for (tmp = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  122|    657|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2538|  2.62k|         tmp != NULL;
  ------------------
  |  Branch (2538:10): [True: 1.97k, False: 657]
  ------------------
 2539|  1.97k|         tmp = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  122|  1.97k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2540|  1.97k|        char *id = tmp;
 2541|  1.97k|        if (strncmp(id, "pkcs11:", 6) != 0) {
  ------------------
  |  Branch (2541:13): [True: 1.97k, False: 0]
  ------------------
 2542|       |            /* PKCS#11 URIs are using percent-encoding so we can not mix
 2543|       |             * it with ssh expansion of ssh escape characters.
 2544|       |             */
 2545|  1.97k|            tmp = ssh_path_expand_escape(session, id);
 2546|  1.97k|            free(id);
 2547|  1.97k|            if (tmp == NULL) {
  ------------------
  |  Branch (2547:17): [True: 0, False: 1.97k]
  ------------------
 2548|      0|                return -1;
 2549|      0|            }
 2550|  1.97k|        }
 2551|       |
 2552|       |        /* use append to keep the order at first call and use prepend
 2553|       |         * to put anything that comes on the nth calls to the beginning */
 2554|  1.97k|        if (session->opts.exp_flags & SSH_OPT_EXP_FLAG_IDENTITY) {
  ------------------
  |  |  118|  1.97k|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
  |  Branch (2554:13): [True: 0, False: 1.97k]
  ------------------
 2555|      0|            rc = ssh_list_prepend(session->opts.identity, tmp);
 2556|  1.97k|        } else {
 2557|  1.97k|            rc = ssh_list_append(session->opts.identity, tmp);
 2558|  1.97k|        }
 2559|  1.97k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.97k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2559:13): [True: 0, False: 1.97k]
  ------------------
 2560|      0|            free(tmp);
 2561|      0|            return -1;
 2562|      0|        }
 2563|  1.97k|    }
 2564|    657|    session->opts.exp_flags |= SSH_OPT_EXP_FLAG_IDENTITY;
  ------------------
  |  |  118|    657|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
 2565|       |
 2566|    657|    for (tmp = ssh_list_pop_head(char *, session->opts.certificate_non_exp);
  ------------------
  |  |  122|    657|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2567|    657|         tmp != NULL;
  ------------------
  |  Branch (2567:10): [True: 0, False: 657]
  ------------------
 2568|    657|         tmp = ssh_list_pop_head(char *, session->opts.certificate_non_exp)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2569|      0|        char *id = tmp;
 2570|       |
 2571|      0|        tmp = ssh_path_expand_escape(session, id);
 2572|      0|        free(id);
 2573|      0|        if (tmp == NULL) {
  ------------------
  |  Branch (2573:13): [True: 0, False: 0]
  ------------------
 2574|      0|            return -1;
 2575|      0|        }
 2576|       |
 2577|      0|        rc = ssh_list_append(session->opts.certificate, tmp);
 2578|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2578:13): [True: 0, False: 0]
  ------------------
 2579|      0|            free(tmp);
 2580|      0|            return -1;
 2581|      0|        }
 2582|      0|    }
 2583|       |
 2584|       |#ifdef WITH_GSSAPI
 2585|       |    if (session->opts.gssapi_key_exchange) {
 2586|       |        rc = ssh_gssapi_check_client_config(session);
 2587|       |        if (rc != SSH_OK) {
 2588|       |            SSH_LOG(SSH_LOG_WARN, "Disabled GSSAPI key exchange");
 2589|       |            session->opts.gssapi_key_exchange = false;
 2590|       |        }
 2591|       |    }
 2592|       |#endif
 2593|       |
 2594|    657|    return 0;
 2595|    657|}
ssh_bind_options_set:
 2821|  3.94k|{
 2822|  3.94k|    bool allowed;
 2823|  3.94k|    char *p = NULL, *q = NULL;
 2824|  3.94k|    const char *v = NULL;
 2825|  3.94k|    int i, rc;
 2826|  3.94k|    char **wanted_methods = sshbind->wanted_methods;
 2827|       |
 2828|  3.94k|    if (sshbind == NULL) {
  ------------------
  |  Branch (2828:9): [True: 0, False: 3.94k]
  ------------------
 2829|      0|        return -1;
 2830|      0|    }
 2831|       |
 2832|  3.94k|    switch (type) {
 2833|      0|    case SSH_BIND_OPTIONS_RSAKEY:
  ------------------
  |  Branch (2833:5): [True: 0, False: 3.94k]
  ------------------
 2834|      0|    case SSH_BIND_OPTIONS_ECDSAKEY:
  ------------------
  |  Branch (2834:5): [True: 0, False: 3.94k]
  ------------------
 2835|       |        /* deprecated */
 2836|    657|    case SSH_BIND_OPTIONS_HOSTKEY:
  ------------------
  |  Branch (2836:5): [True: 657, False: 3.28k]
  ------------------
 2837|    657|    case SSH_BIND_OPTIONS_IMPORT_KEY:
  ------------------
  |  Branch (2837:5): [True: 0, False: 3.94k]
  ------------------
 2838|    657|    case SSH_BIND_OPTIONS_IMPORT_KEY_STR:
  ------------------
  |  Branch (2838:5): [True: 0, False: 3.94k]
  ------------------
 2839|    657|        if (value == NULL) {
  ------------------
  |  Branch (2839:13): [True: 0, False: 657]
  ------------------
 2840|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2841|      0|            return -1;
 2842|    657|        } else {
 2843|    657|            int key_type;
 2844|    657|            ssh_key *bind_key_loc = NULL;
 2845|    657|            ssh_key key = NULL;
 2846|    657|            char **bind_key_path_loc = NULL;
 2847|       |
 2848|    657|            if (type == SSH_BIND_OPTIONS_IMPORT_KEY_STR) {
  ------------------
  |  Branch (2848:17): [True: 0, False: 657]
  ------------------
 2849|      0|                const char *key_str = (const char *)value;
 2850|      0|                rc = ssh_pki_import_privkey_base64(key_str,
 2851|      0|                                                   NULL,
 2852|      0|                                                   NULL,
 2853|      0|                                                   NULL,
 2854|      0|                                                   &key);
 2855|      0|                if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (2855:21): [True: 0, False: 0]
  ------------------
 2856|      0|                    ssh_set_error(sshbind,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 2857|      0|                                  SSH_FATAL,
 2858|      0|                                  "Failed to import key from buffer");
 2859|      0|                    return -1;
 2860|      0|                }
 2861|    657|            } else if (type == SSH_BIND_OPTIONS_IMPORT_KEY) {
  ------------------
  |  Branch (2861:24): [True: 0, False: 657]
  ------------------
 2862|      0|                key = (ssh_key)value;
 2863|    657|            } else {
 2864|    657|                rc = ssh_pki_import_privkey_file(value, NULL, NULL, NULL, &key);
 2865|    657|                if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2865:21): [True: 0, False: 657]
  ------------------
 2866|      0|                    return -1;
 2867|      0|                }
 2868|    657|            }
 2869|    657|            allowed = ssh_bind_key_size_allowed(sshbind, key);
 2870|    657|            if (!allowed) {
  ------------------
  |  Branch (2870:17): [True: 0, False: 657]
  ------------------
 2871|      0|                ssh_set_error(sshbind,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 2872|      0|                              SSH_FATAL,
 2873|      0|                              "The host key size %d is too small.",
 2874|      0|                              ssh_key_size(key));
 2875|      0|                if (type != SSH_BIND_OPTIONS_IMPORT_KEY) {
  ------------------
  |  Branch (2875:21): [True: 0, False: 0]
  ------------------
 2876|      0|                    SSH_KEY_FREE(key);
  ------------------
  |  |  769|      0|    do { if ((x) != NULL) { ssh_key_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (769:14): [True: 0, False: 0]
  |  |  |  Branch (769:66): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2877|      0|                }
 2878|      0|                return -1;
 2879|      0|            }
 2880|    657|            key_type = ssh_key_type(key);
 2881|    657|            switch (key_type) {
 2882|      0|            case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2882:13): [True: 0, False: 657]
  ------------------
 2883|      0|            case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2883:13): [True: 0, False: 657]
  ------------------
 2884|      0|            case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2884:13): [True: 0, False: 657]
  ------------------
 2885|      0|#ifdef HAVE_ECC
 2886|      0|                bind_key_loc = &sshbind->ecdsa;
 2887|      0|                bind_key_path_loc = &sshbind->ecdsakey;
 2888|       |#else
 2889|       |                ssh_set_error(sshbind,
 2890|       |                              SSH_FATAL,
 2891|       |                              "ECDSA key used and libssh compiled "
 2892|       |                              "without ECDSA support");
 2893|       |#endif
 2894|      0|                break;
 2895|      0|            case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2895:13): [True: 0, False: 657]
  ------------------
 2896|      0|                bind_key_loc = &sshbind->rsa;
 2897|      0|                bind_key_path_loc = &sshbind->rsakey;
 2898|      0|                break;
 2899|    657|            case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2899:13): [True: 657, False: 0]
  ------------------
 2900|    657|                bind_key_loc = &sshbind->ed25519;
 2901|    657|                bind_key_path_loc = &sshbind->ed25519key;
 2902|    657|                break;
 2903|      0|            default:
  ------------------
  |  Branch (2903:13): [True: 0, False: 657]
  ------------------
 2904|      0|                ssh_set_error(sshbind,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 2905|    657|                              SSH_FATAL,
 2906|    657|                              "Unsupported key type %d",
 2907|    657|                              key_type);
 2908|    657|            }
 2909|    657|            if (type == SSH_BIND_OPTIONS_RSAKEY ||
  ------------------
  |  Branch (2909:17): [True: 0, False: 657]
  ------------------
 2910|    657|                type == SSH_BIND_OPTIONS_ECDSAKEY ||
  ------------------
  |  Branch (2910:17): [True: 0, False: 657]
  ------------------
 2911|    657|                type == SSH_BIND_OPTIONS_HOSTKEY) {
  ------------------
  |  Branch (2911:17): [True: 657, False: 0]
  ------------------
 2912|    657|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (2912:21): [True: 0, False: 657]
  ------------------
 2913|      0|                    ssh_key_free(key);
 2914|      0|                    return -1;
 2915|      0|                }
 2916|       |                /* Set the location of the key on disk even though we don't
 2917|       |                   need it in case some other function wants it */
 2918|    657|                rc = ssh_bind_set_key(sshbind, bind_key_path_loc, value);
 2919|    657|                if (rc < 0) {
  ------------------
  |  Branch (2919:21): [True: 0, False: 657]
  ------------------
 2920|      0|                    ssh_key_free(key);
 2921|      0|                    return -1;
 2922|      0|                }
 2923|    657|            } else if (type == SSH_BIND_OPTIONS_IMPORT_KEY_STR) {
  ------------------
  |  Branch (2923:24): [True: 0, False: 0]
  ------------------
 2924|      0|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (2924:21): [True: 0, False: 0]
  ------------------
 2925|      0|                    ssh_key_free(key);
 2926|      0|                    return -1;
 2927|      0|                }
 2928|      0|            } else {
 2929|      0|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (2929:21): [True: 0, False: 0]
  ------------------
 2930|      0|                    return -1;
 2931|      0|                }
 2932|      0|            }
 2933|    657|            ssh_key_free(*bind_key_loc);
 2934|    657|            *bind_key_loc = key;
 2935|    657|        }
 2936|    657|        break;
 2937|    657|    case SSH_BIND_OPTIONS_BINDADDR:
  ------------------
  |  Branch (2937:5): [True: 0, False: 3.94k]
  ------------------
 2938|      0|        if (value == NULL) {
  ------------------
  |  Branch (2938:13): [True: 0, False: 0]
  ------------------
 2939|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2940|      0|            return -1;
 2941|      0|        } else {
 2942|      0|            SAFE_FREE(sshbind->bindaddr);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2943|      0|            sshbind->bindaddr = strdup(value);
 2944|      0|            if (sshbind->bindaddr == NULL) {
  ------------------
  |  Branch (2944:17): [True: 0, False: 0]
  ------------------
 2945|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2946|      0|                return -1;
 2947|      0|            }
 2948|      0|        }
 2949|      0|        break;
 2950|      0|    case SSH_BIND_OPTIONS_BINDPORT:
  ------------------
  |  Branch (2950:5): [True: 0, False: 3.94k]
  ------------------
 2951|      0|        if (value == NULL) {
  ------------------
  |  Branch (2951:13): [True: 0, False: 0]
  ------------------
 2952|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2953|      0|            return -1;
 2954|      0|        } else {
 2955|      0|            int *x = (int *)value;
 2956|      0|            sshbind->bindport = *x & 0xffffU;
 2957|      0|        }
 2958|      0|        break;
 2959|      0|    case SSH_BIND_OPTIONS_BINDPORT_STR:
  ------------------
  |  Branch (2959:5): [True: 0, False: 3.94k]
  ------------------
 2960|      0|        if (value == NULL) {
  ------------------
  |  Branch (2960:13): [True: 0, False: 0]
  ------------------
 2961|      0|            sshbind->bindport = 22 & 0xffffU;
 2962|      0|        } else {
 2963|      0|            q = strdup(value);
 2964|      0|            if (q == NULL) {
  ------------------
  |  Branch (2964:17): [True: 0, False: 0]
  ------------------
 2965|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2966|      0|                return -1;
 2967|      0|            }
 2968|      0|            i = strtol(q, &p, 10);
 2969|      0|            if (q == p) {
  ------------------
  |  Branch (2969:17): [True: 0, False: 0]
  ------------------
 2970|      0|                SSH_LOG(SSH_LOG_DEBUG, "No bind port was parsed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2971|      0|                SAFE_FREE(q);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2972|      0|                return -1;
 2973|      0|            }
 2974|      0|            SAFE_FREE(q);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2975|       |
 2976|      0|            sshbind->bindport = i & 0xffffU;
 2977|      0|        }
 2978|      0|        break;
 2979|      0|    case SSH_BIND_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (2979:5): [True: 0, False: 3.94k]
  ------------------
 2980|      0|        if (value == NULL) {
  ------------------
  |  Branch (2980:13): [True: 0, False: 0]
  ------------------
 2981|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2982|      0|            return -1;
 2983|      0|        } else {
 2984|      0|            int *x = (int *)value;
 2985|      0|            ssh_set_log_level(*x & 0xffffU);
 2986|      0|        }
 2987|      0|        break;
 2988|      0|    case SSH_BIND_OPTIONS_LOG_VERBOSITY_STR:
  ------------------
  |  Branch (2988:5): [True: 0, False: 3.94k]
  ------------------
 2989|      0|        if (value == NULL) {
  ------------------
  |  Branch (2989:13): [True: 0, False: 0]
  ------------------
 2990|      0|            ssh_set_log_level(0);
 2991|      0|        } else {
 2992|      0|            q = strdup(value);
 2993|      0|            if (q == NULL) {
  ------------------
  |  Branch (2993:17): [True: 0, False: 0]
  ------------------
 2994|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2995|      0|                return -1;
 2996|      0|            }
 2997|      0|            i = strtol(q, &p, 10);
 2998|      0|            if (q == p) {
  ------------------
  |  Branch (2998:17): [True: 0, False: 0]
  ------------------
 2999|      0|                SSH_LOG(SSH_LOG_DEBUG, "No log verbositiy was parsed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3000|      0|                SAFE_FREE(q);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3001|      0|                return -1;
 3002|      0|            }
 3003|      0|            SAFE_FREE(q);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3004|       |
 3005|      0|            ssh_set_log_level(i & 0xffffU);
 3006|      0|        }
 3007|      0|        break;
 3008|      0|    case SSH_BIND_OPTIONS_BANNER:
  ------------------
  |  Branch (3008:5): [True: 0, False: 3.94k]
  ------------------
 3009|      0|        if (value == NULL) {
  ------------------
  |  Branch (3009:13): [True: 0, False: 0]
  ------------------
 3010|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3011|      0|            return -1;
 3012|      0|        } else {
 3013|      0|            SAFE_FREE(sshbind->banner);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3014|      0|            sshbind->banner = strdup(value);
 3015|      0|            if (sshbind->banner == NULL) {
  ------------------
  |  Branch (3015:17): [True: 0, False: 0]
  ------------------
 3016|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3017|      0|                return -1;
 3018|      0|            }
 3019|      0|        }
 3020|      0|        break;
 3021|    657|    case SSH_BIND_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (3021:5): [True: 657, False: 3.28k]
  ------------------
 3022|    657|        v = value;
 3023|    657|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3023:13): [True: 0, False: 657]
  |  Branch (3023:26): [True: 0, False: 657]
  ------------------
 3024|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3025|      0|            return -1;
 3026|    657|        } else {
 3027|    657|            rc = ssh_bind_set_algo(sshbind,
 3028|    657|                                   SSH_CRYPT_C_S,
 3029|    657|                                   v,
 3030|    657|                                   &wanted_methods[SSH_CRYPT_C_S]);
 3031|    657|            if (rc < 0) {
  ------------------
  |  Branch (3031:17): [True: 0, False: 657]
  ------------------
 3032|      0|                return -1;
 3033|      0|            }
 3034|    657|        }
 3035|    657|        break;
 3036|    657|    case SSH_BIND_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (3036:5): [True: 657, False: 3.28k]
  ------------------
 3037|    657|        v = value;
 3038|    657|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3038:13): [True: 0, False: 657]
  |  Branch (3038:26): [True: 0, False: 657]
  ------------------
 3039|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3040|      0|            return -1;
 3041|    657|        } else {
 3042|    657|            rc = ssh_bind_set_algo(sshbind,
 3043|    657|                                   SSH_CRYPT_S_C,
 3044|    657|                                   v,
 3045|    657|                                   &wanted_methods[SSH_CRYPT_S_C]);
 3046|    657|            if (rc < 0) {
  ------------------
  |  Branch (3046:17): [True: 0, False: 657]
  ------------------
 3047|      0|                return -1;
 3048|      0|            }
 3049|    657|        }
 3050|    657|        break;
 3051|    657|    case SSH_BIND_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (3051:5): [True: 0, False: 3.94k]
  ------------------
 3052|      0|        v = value;
 3053|      0|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3053:13): [True: 0, False: 0]
  |  Branch (3053:26): [True: 0, False: 0]
  ------------------
 3054|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3055|      0|            return -1;
 3056|      0|        } else {
 3057|      0|            rc = ssh_bind_set_algo(sshbind,
 3058|      0|                                   SSH_KEX,
 3059|      0|                                   v,
 3060|      0|                                   &wanted_methods[SSH_KEX]);
 3061|      0|            if (rc < 0) {
  ------------------
  |  Branch (3061:17): [True: 0, False: 0]
  ------------------
 3062|      0|                return -1;
 3063|      0|            }
 3064|      0|        }
 3065|      0|        break;
 3066|    657|    case SSH_BIND_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (3066:5): [True: 657, False: 3.28k]
  ------------------
 3067|    657|        v = value;
 3068|    657|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3068:13): [True: 0, False: 657]
  |  Branch (3068:26): [True: 0, False: 657]
  ------------------
 3069|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3070|      0|            return -1;
 3071|    657|        } else {
 3072|    657|            rc = ssh_bind_set_algo(sshbind,
 3073|    657|                                   SSH_MAC_C_S,
 3074|    657|                                   v,
 3075|    657|                                   &wanted_methods[SSH_MAC_C_S]);
 3076|    657|            if (rc < 0) {
  ------------------
  |  Branch (3076:17): [True: 0, False: 657]
  ------------------
 3077|      0|                return -1;
 3078|      0|            }
 3079|    657|        }
 3080|    657|        break;
 3081|    657|    case SSH_BIND_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (3081:5): [True: 657, False: 3.28k]
  ------------------
 3082|    657|        v = value;
 3083|    657|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3083:13): [True: 0, False: 657]
  |  Branch (3083:26): [True: 0, False: 657]
  ------------------
 3084|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3085|      0|            return -1;
 3086|    657|        } else {
 3087|    657|            rc = ssh_bind_set_algo(sshbind,
 3088|    657|                                   SSH_MAC_S_C,
 3089|    657|                                   v,
 3090|    657|                                   &wanted_methods[SSH_MAC_S_C]);
 3091|    657|            if (rc < 0) {
  ------------------
  |  Branch (3091:17): [True: 0, False: 657]
  ------------------
 3092|      0|                return -1;
 3093|      0|            }
 3094|    657|        }
 3095|    657|        break;
 3096|    657|    case SSH_BIND_OPTIONS_CONFIG_DIR:
  ------------------
  |  Branch (3096:5): [True: 0, False: 3.94k]
  ------------------
 3097|      0|        v = value;
 3098|      0|        SAFE_FREE(sshbind->config_dir);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3099|      0|        if (v == NULL) {
  ------------------
  |  Branch (3099:13): [True: 0, False: 0]
  ------------------
 3100|      0|            break;
 3101|      0|        } else if (v[0] == '\0') {
  ------------------
  |  Branch (3101:20): [True: 0, False: 0]
  ------------------
 3102|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3103|      0|            return -1;
 3104|      0|        } else {
 3105|      0|            sshbind->config_dir = ssh_path_expand_tilde(v);
 3106|      0|            if (sshbind->config_dir == NULL) {
  ------------------
  |  Branch (3106:17): [True: 0, False: 0]
  ------------------
 3107|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3108|      0|                return -1;
 3109|      0|            }
 3110|      0|        }
 3111|      0|        break;
 3112|      0|    case SSH_BIND_OPTIONS_PUBKEY_ACCEPTED_KEY_TYPES:
  ------------------
  |  Branch (3112:5): [True: 0, False: 3.94k]
  ------------------
 3113|      0|        v = value;
 3114|      0|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3114:13): [True: 0, False: 0]
  |  Branch (3114:26): [True: 0, False: 0]
  ------------------
 3115|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3116|      0|            return -1;
 3117|      0|        } else {
 3118|      0|            rc = ssh_bind_set_algo(sshbind,
 3119|      0|                                   SSH_HOSTKEYS,
 3120|      0|                                   v,
 3121|      0|                                   &sshbind->pubkey_accepted_key_types);
 3122|      0|            if (rc < 0) {
  ------------------
  |  Branch (3122:17): [True: 0, False: 0]
  ------------------
 3123|      0|                return -1;
 3124|      0|            }
 3125|      0|        }
 3126|      0|        break;
 3127|      0|    case SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS:
  ------------------
  |  Branch (3127:5): [True: 0, False: 3.94k]
  ------------------
 3128|      0|        v = value;
 3129|      0|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3129:13): [True: 0, False: 0]
  |  Branch (3129:26): [True: 0, False: 0]
  ------------------
 3130|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3131|      0|            return -1;
 3132|      0|        } else {
 3133|      0|            rc = ssh_bind_set_algo(sshbind,
 3134|      0|                                   SSH_HOSTKEYS,
 3135|      0|                                   v,
 3136|      0|                                   &wanted_methods[SSH_HOSTKEYS]);
 3137|      0|            if (rc < 0) {
  ------------------
  |  Branch (3137:17): [True: 0, False: 0]
  ------------------
 3138|      0|                return -1;
 3139|      0|            }
 3140|      0|        }
 3141|      0|        break;
 3142|    657|    case SSH_BIND_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (3142:5): [True: 657, False: 3.28k]
  ------------------
 3143|    657|        if (value == NULL) {
  ------------------
  |  Branch (3143:13): [True: 0, False: 657]
  ------------------
 3144|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3145|      0|            return -1;
 3146|    657|        } else {
 3147|    657|            bool *x = (bool *)value;
 3148|    657|            sshbind->config_processed = !(*x);
 3149|    657|        }
 3150|    657|        break;
 3151|    657|    case SSH_BIND_OPTIONS_MODULI:
  ------------------
  |  Branch (3151:5): [True: 0, False: 3.94k]
  ------------------
 3152|      0|        if (value == NULL) {
  ------------------
  |  Branch (3152:13): [True: 0, False: 0]
  ------------------
 3153|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3154|      0|            return -1;
 3155|      0|        } else {
 3156|      0|            SAFE_FREE(sshbind->moduli_file);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3157|      0|            sshbind->moduli_file = strdup(value);
 3158|      0|            if (sshbind->moduli_file == NULL) {
  ------------------
  |  Branch (3158:17): [True: 0, False: 0]
  ------------------
 3159|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3160|      0|                return -1;
 3161|      0|            }
 3162|      0|        }
 3163|      0|        break;
 3164|      0|    case SSH_BIND_OPTIONS_RSA_MIN_SIZE:
  ------------------
  |  Branch (3164:5): [True: 0, False: 3.94k]
  ------------------
 3165|      0|        if (value == NULL) {
  ------------------
  |  Branch (3165:13): [True: 0, False: 0]
  ------------------
 3166|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3167|      0|            return -1;
 3168|      0|        } else {
 3169|      0|            int *x = (int *)value;
 3170|       |
 3171|      0|            if (*x < 0) {
  ------------------
  |  Branch (3171:17): [True: 0, False: 0]
  ------------------
 3172|      0|                ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3173|      0|                return -1;
 3174|      0|            }
 3175|       |
 3176|       |            /* (*x == 0) is allowed as it is used to revert to default */
 3177|       |
 3178|      0|            if (*x > 0 && *x < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|      0|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (3178:17): [True: 0, False: 0]
  |  Branch (3178:27): [True: 0, False: 0]
  ------------------
 3179|      0|                ssh_set_error(sshbind,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3180|      0|                              SSH_REQUEST_DENIED,
 3181|      0|                              "The provided value (%d) for minimal RSA key "
 3182|      0|                              "size is too small. Use at least %d bits.",
 3183|      0|                              *x,
 3184|      0|                              RSA_MIN_KEY_SIZE);
 3185|      0|                return -1;
 3186|      0|            }
 3187|      0|            sshbind->rsa_min_size = *x;
 3188|      0|        }
 3189|      0|        break;
 3190|       |#ifdef WITH_GSSAPI
 3191|       |    case SSH_BIND_OPTIONS_GSSAPI_KEY_EXCHANGE:
 3192|       |        if (value == NULL) {
 3193|       |            ssh_set_error_invalid(sshbind);
 3194|       |            return -1;
 3195|       |        } else {
 3196|       |            bool *x = (bool *)value;
 3197|       |            sshbind->gssapi_key_exchange = *x;
 3198|       |        }
 3199|       |        break;
 3200|       |    case SSH_BIND_OPTIONS_GSSAPI_KEY_EXCHANGE_ALGS:
 3201|       |        if (value == NULL) {
 3202|       |            ssh_set_error_invalid(sshbind);
 3203|       |            return -1;
 3204|       |        } else {
 3205|       |            char *ret = NULL;
 3206|       |            SAFE_FREE(sshbind->gssapi_key_exchange_algs);
 3207|       |            ret = ssh_find_all_matching(GSSAPI_KEY_EXCHANGE_SUPPORTED, value);
 3208|       |            if (ret == NULL) {
 3209|       |                ssh_set_error(
 3210|       |                    sshbind,
 3211|       |                    SSH_REQUEST_DENIED,
 3212|       |                    "GSSAPI key exchange algorithms not supported or invalid");
 3213|       |                return -1;
 3214|       |            }
 3215|       |            sshbind->gssapi_key_exchange_algs = ret;
 3216|       |        }
 3217|       |        break;
 3218|       |#endif /* WITH_GSSAPI */
 3219|      0|    default:
  ------------------
  |  Branch (3219:5): [True: 0, False: 3.94k]
  ------------------
 3220|      0|        ssh_set_error(sshbind,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3221|      0|                      SSH_REQUEST_DENIED,
 3222|      0|                      "Unknown ssh option %d",
 3223|      0|                      type);
 3224|      0|        return -1;
 3225|      0|        break;
 3226|  3.94k|    }
 3227|       |
 3228|  3.94k|    return 0;
 3229|  3.94k|}
options.c:ssh_bind_key_size_allowed:
 2601|    657|{
 2602|    657|    int min_size = 0;
 2603|       |
 2604|    657|    switch (ssh_key_type(key)) {
 2605|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2605:5): [True: 0, False: 657]
  ------------------
 2606|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (2606:5): [True: 0, False: 657]
  ------------------
 2607|      0|        min_size = sshbind->rsa_min_size;
 2608|      0|        return ssh_key_size_allowed_rsa(min_size, key);
 2609|    657|    default:
  ------------------
  |  Branch (2609:5): [True: 657, False: 0]
  ------------------
 2610|       |        return true;
 2611|    657|    }
 2612|    657|}
options.c:ssh_bind_set_key:
 2620|    657|{
 2621|    657|    if (value == NULL) {
  ------------------
  |  Branch (2621:9): [True: 0, False: 657]
  ------------------
 2622|      0|        ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2623|      0|        return -1;
 2624|    657|    } else {
 2625|    657|        SAFE_FREE(*key_loc);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
 2626|    657|        *key_loc = strdup(value);
 2627|    657|        if (*key_loc == NULL) {
  ------------------
  |  Branch (2627:13): [True: 0, False: 657]
  ------------------
 2628|      0|            ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2629|      0|            return -1;
 2630|      0|        }
 2631|    657|    }
 2632|    657|    return 0;
 2633|    657|}
options.c:ssh_bind_set_algo:
 2639|  2.62k|{
 2640|       |    /* sshbind is needed only for ssh_set_error which takes void*
 2641|       |     * the typecast is only to satisfy function parameter type */
 2642|  2.62k|    return ssh_options_set_algo((ssh_session)sshbind, algo, list, place);
 2643|  2.62k|}

ssh_packet_get_current_crypto:
 1159|  91.9k|{
 1160|  91.9k|    struct ssh_crypto_struct *crypto = NULL;
 1161|       |
 1162|  91.9k|    if (session == NULL) {
  ------------------
  |  Branch (1162:9): [True: 0, False: 91.9k]
  ------------------
 1163|      0|        return NULL;
 1164|      0|    }
 1165|       |
 1166|  91.9k|    if (session->current_crypto != NULL &&
  ------------------
  |  Branch (1166:9): [True: 72.9k, False: 18.9k]
  ------------------
 1167|  72.9k|        session->current_crypto->used & direction) {
  ------------------
  |  Branch (1167:9): [True: 72.9k, False: 18.4E]
  ------------------
 1168|  72.9k|        crypto = session->current_crypto;
 1169|  72.9k|    } else if (session->next_crypto != NULL &&
  ------------------
  |  Branch (1169:16): [True: 18.9k, False: 18.4E]
  ------------------
 1170|  18.9k|               session->next_crypto->used & direction) {
  ------------------
  |  Branch (1170:16): [True: 0, False: 18.9k]
  ------------------
 1171|      0|        crypto = session->next_crypto;
 1172|  18.9k|    } else {
 1173|  18.9k|        return NULL;
 1174|  18.9k|    }
 1175|       |
 1176|  72.9k|    switch (direction) {
  ------------------
  |  Branch (1176:13): [True: 73.3k, False: 18.4E]
  ------------------
 1177|  42.5k|    case SSH_DIRECTION_IN:
  ------------------
  |  Branch (1177:5): [True: 42.5k, False: 30.4k]
  ------------------
 1178|  42.5k|        if (crypto->in_cipher != NULL) {
  ------------------
  |  Branch (1178:13): [True: 42.5k, False: 0]
  ------------------
 1179|  42.5k|            return crypto;
 1180|  42.5k|        }
 1181|      0|        break;
 1182|  19.7k|    case SSH_DIRECTION_OUT:
  ------------------
  |  Branch (1182:5): [True: 19.7k, False: 53.2k]
  ------------------
 1183|  19.7k|        if (crypto->out_cipher != NULL) {
  ------------------
  |  Branch (1183:13): [True: 19.7k, False: 0]
  ------------------
 1184|  19.7k|            return crypto;
 1185|  19.7k|        }
 1186|      0|        break;
 1187|  11.1k|    case SSH_DIRECTION_BOTH:
  ------------------
  |  Branch (1187:5): [True: 11.1k, False: 61.8k]
  ------------------
 1188|  11.1k|        if (crypto->in_cipher != NULL &&
  ------------------
  |  Branch (1188:13): [True: 11.1k, False: 1]
  ------------------
 1189|  11.1k|            crypto->out_cipher != NULL) {
  ------------------
  |  Branch (1189:13): [True: 11.1k, False: 0]
  ------------------
 1190|  11.1k|            return crypto;
 1191|  11.1k|        }
 1192|  72.9k|    }
 1193|       |
 1194|      0|    return NULL;
 1195|  72.9k|}
ssh_packet_socket_callback:
 1286|  22.8k|{
 1287|  22.8k|    ssh_session session = (ssh_session)user;
 1288|  22.8k|    uint32_t blocksize = 8;
 1289|  22.8k|    uint32_t lenfield_blocksize = 8;
 1290|  22.8k|    size_t current_macsize = 0;
 1291|  22.8k|    uint8_t *ptr = NULL;
 1292|  22.8k|    ssize_t to_be_read;
 1293|  22.8k|    int rc;
 1294|  22.8k|    uint8_t *cleartext_packet = NULL;
 1295|  22.8k|    uint8_t *packet_second_block = NULL;
 1296|  22.8k|    uint8_t *mac = NULL;
 1297|  22.8k|    size_t packet_remaining, packet_offset;
 1298|  22.8k|    uint32_t packet_len, compsize, payloadsize;
 1299|  22.8k|    uint8_t padding;
 1300|  22.8k|    size_t processed = 0; /* number of bytes processed from the callback */
 1301|  22.8k|    enum ssh_packet_filter_result_e filter_result;
 1302|  22.8k|    struct ssh_crypto_struct *crypto = NULL;
 1303|  22.8k|    bool etm = false;
 1304|  22.8k|    uint32_t etm_packet_offset = 0;
 1305|  22.8k|    bool ok;
 1306|       |
 1307|  22.8k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
 1308|  22.8k|    if (crypto != NULL) {
  ------------------
  |  Branch (1308:9): [True: 15.7k, False: 7.18k]
  ------------------
 1309|  15.7k|        current_macsize = hmac_digest_len(crypto->in_hmac);
 1310|  15.7k|        blocksize = crypto->in_cipher->blocksize;
 1311|  15.7k|        lenfield_blocksize = crypto->in_cipher->lenfield_blocksize;
 1312|  15.7k|        etm = crypto->in_hmac_etm;
 1313|  15.7k|    }
 1314|       |
 1315|  22.8k|    if (etm) {
  ------------------
  |  Branch (1315:9): [True: 0, False: 22.8k]
  ------------------
 1316|       |        /* In EtM mode packet size is unencrypted. This means
 1317|       |         * we need to use this offset and set the block size
 1318|       |         * that is part of the encrypted part to 0.
 1319|       |         */
 1320|      0|        etm_packet_offset = sizeof(uint32_t);
 1321|      0|        lenfield_blocksize = 0;
 1322|  22.8k|    } else if (lenfield_blocksize == 0) {
  ------------------
  |  Branch (1322:16): [True: 15.7k, False: 7.18k]
  ------------------
 1323|  15.7k|        lenfield_blocksize = blocksize;
 1324|  15.7k|    }
 1325|  22.8k|    if (data == NULL) {
  ------------------
  |  Branch (1325:9): [True: 0, False: 22.8k]
  ------------------
 1326|      0|        goto error;
 1327|      0|    }
 1328|       |
 1329|  22.8k|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (1329:9): [True: 0, False: 22.8k]
  ------------------
 1330|      0|        goto error;
 1331|      0|    }
 1332|       |#ifdef DEBUG_PACKET
 1333|       |    SSH_LOG(SSH_LOG_PACKET,
 1334|       |            "rcv packet cb (len=%zu, state=%s)",
 1335|       |            receivedlen,
 1336|       |            session->packet_state == PACKET_STATE_INIT ?
 1337|       |                "INIT" :
 1338|       |                session->packet_state == PACKET_STATE_SIZEREAD ?
 1339|       |                    "SIZE_READ" :
 1340|       |                    session->packet_state == PACKET_STATE_PROCESSING ?
 1341|       |                    "PROCESSING" : "unknown");
 1342|       |#endif
 1343|  22.8k|    switch (session->packet_state) {
  ------------------
  |  Branch (1343:13): [True: 22.8k, False: 20]
  ------------------
 1344|  22.3k|        case PACKET_STATE_INIT:
  ------------------
  |  Branch (1344:9): [True: 22.3k, False: 536]
  ------------------
 1345|  22.3k|            if (receivedlen < lenfield_blocksize + etm_packet_offset) {
  ------------------
  |  Branch (1345:17): [True: 11.2k, False: 11.1k]
  ------------------
 1346|       |                /*
 1347|       |                 * We didn't receive enough data to read either at least one
 1348|       |                 * block size or the unencrypted length in EtM mode.
 1349|       |                 */
 1350|       |#ifdef DEBUG_PACKET
 1351|       |                SSH_LOG(SSH_LOG_PACKET,
 1352|       |                        "Waiting for more data (%zu < %u)",
 1353|       |                        receivedlen,
 1354|       |                        lenfield_blocksize);
 1355|       |#endif
 1356|  11.2k|                return 0;
 1357|  11.2k|            }
 1358|       |
 1359|  11.1k|            session->in_packet = (struct packet_struct) {
 1360|  11.1k|                .type = 0,
 1361|  11.1k|            };
 1362|       |
 1363|  11.1k|            if (session->in_buffer) {
  ------------------
  |  Branch (1363:17): [True: 11.1k, False: 18.4E]
  ------------------
 1364|  11.1k|                rc = ssh_buffer_reinit(session->in_buffer);
 1365|  11.1k|                if (rc < 0) {
  ------------------
  |  Branch (1365:21): [True: 0, False: 11.1k]
  ------------------
 1366|      0|                    goto error;
 1367|      0|                }
 1368|  18.4E|            } else {
 1369|  18.4E|                session->in_buffer = ssh_buffer_new();
 1370|  18.4E|                if (session->in_buffer == NULL) {
  ------------------
  |  Branch (1370:21): [True: 0, False: 18.4E]
  ------------------
 1371|      0|                    goto error;
 1372|      0|                }
 1373|  18.4E|            }
 1374|       |
 1375|  11.1k|            if (!etm) {
  ------------------
  |  Branch (1375:17): [True: 11.1k, False: 18.4E]
  ------------------
 1376|  11.1k|                ptr = ssh_buffer_allocate(session->in_buffer,
 1377|  11.1k|                                          lenfield_blocksize);
 1378|  11.1k|                if (ptr == NULL) {
  ------------------
  |  Branch (1378:21): [True: 0, False: 11.1k]
  ------------------
 1379|      0|                    goto error;
 1380|      0|                }
 1381|  11.1k|                packet_len = ssh_packet_decrypt_len(session, ptr,
 1382|  11.1k|                                                    (uint8_t *)data);
 1383|  11.1k|                to_be_read = packet_len - lenfield_blocksize + sizeof(uint32_t);
 1384|  18.4E|            } else {
 1385|       |                /* Length is unencrypted in case of Encrypt-then-MAC */
 1386|  18.4E|                packet_len = PULL_BE_U32(data, 0);
  ------------------
  |  |   75|  18.4E|    ((((uint32_t)PULL_BE_U16(data, pos)) << 16) | (uint32_t)(PULL_BE_U16(data, (pos) + 2)))
  |  |  ------------------
  |  |  |  |   72|  18.4E|    ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|  18.4E|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|  18.4E|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|  18.4E|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|  18.4E|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   ((((uint32_t)PULL_BE_U16(data, pos)) << 16) | (uint32_t)(PULL_BE_U16(data, (pos) + 2)))
  |  |  ------------------
  |  |  |  |   72|  18.4E|    ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|  18.4E|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|  18.4E|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|  18.4E|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|  18.4E|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1387|  18.4E|                to_be_read = packet_len - etm_packet_offset;
 1388|  18.4E|            }
 1389|       |
 1390|  11.1k|            processed += lenfield_blocksize + etm_packet_offset;
 1391|  11.1k|            if (packet_len > MAX_PACKET_LEN) {
  ------------------
  |  |  216|  11.1k|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (1391:17): [True: 0, False: 11.1k]
  ------------------
 1392|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1393|      0|                              SSH_FATAL,
 1394|      0|                              "read_packet(): Packet len too high(%" PRIu32 " %.4" PRIx32 ")",
 1395|      0|                              packet_len, packet_len);
 1396|      0|                goto error;
 1397|      0|            }
 1398|  11.1k|            if (to_be_read < 0) {
  ------------------
  |  Branch (1398:17): [True: 0, False: 11.1k]
  ------------------
 1399|       |                /* remote sshd sends invalid sizes? */
 1400|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1401|      0|                              SSH_FATAL,
 1402|      0|                              "Given numbers of bytes left to be read < 0 (%zd)!",
 1403|      0|                              to_be_read);
 1404|      0|                goto error;
 1405|      0|            }
 1406|       |
 1407|  11.1k|            session->in_packet.len = packet_len;
 1408|  11.1k|            session->packet_state = PACKET_STATE_SIZEREAD;
 1409|  11.1k|            FALL_THROUGH;
  ------------------
  |  |  494|  11.1k|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1410|  11.6k|        case PACKET_STATE_SIZEREAD:
  ------------------
  |  Branch (1410:9): [True: 516, False: 22.3k]
  ------------------
 1411|  11.6k|            packet_len = session->in_packet.len;
 1412|  11.6k|            packet_offset = processed = lenfield_blocksize + etm_packet_offset;
 1413|  11.6k|            to_be_read = packet_len + sizeof(uint32_t) + current_macsize;
 1414|       |            /* if to_be_read is zero, the whole packet was blocksize bytes. */
 1415|  11.6k|            if (to_be_read != 0) {
  ------------------
  |  Branch (1415:17): [True: 11.6k, False: 18.4E]
  ------------------
 1416|  11.6k|                if (receivedlen < (unsigned long)to_be_read) {
  ------------------
  |  Branch (1416:21): [True: 516, False: 11.1k]
  ------------------
 1417|       |                    /* give up, not enough data in buffer */
 1418|    516|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    516|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1419|    516|                            "packet: partial packet (read len) "
 1420|    516|                            "[len=%" PRIu32 ", receivedlen=%zu, to_be_read=%zd]",
 1421|    516|                            packet_len,
 1422|    516|                            receivedlen,
 1423|    516|                            to_be_read);
 1424|    516|                    return 0;
 1425|    516|                }
 1426|       |
 1427|  11.1k|                packet_second_block = (uint8_t*)data + packet_offset;
 1428|  11.1k|                processed = to_be_read - current_macsize;
 1429|  11.1k|            }
 1430|       |
 1431|  11.1k|            if (packet_offset - sizeof(uint32_t) > (size_t)packet_len) {
  ------------------
  |  Branch (1431:17): [True: 0, False: 11.1k]
  ------------------
 1432|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1433|      0|                              SSH_FATAL,
 1434|      0|                              "Invalid packet length %" PRIu32 ", required %zu",
 1435|      0|                              packet_len,
 1436|      0|                              packet_offset + sizeof(uint32_t));
 1437|      0|                goto error;
 1438|      0|            }
 1439|       |
 1440|       |            /* remaining encrypted bytes from the packet, MAC not included */
 1441|  11.1k|            packet_remaining = packet_len - (packet_offset - sizeof(uint32_t));
 1442|  11.1k|            cleartext_packet = ssh_buffer_allocate(session->in_buffer,
 1443|  11.1k|                                                   (uint32_t)packet_remaining);
 1444|  11.1k|            if (cleartext_packet == NULL) {
  ------------------
  |  Branch (1444:17): [True: 0, False: 11.1k]
  ------------------
 1445|      0|                goto error;
 1446|      0|            }
 1447|       |
 1448|  11.1k|            if (packet_second_block != NULL) {
  ------------------
  |  Branch (1448:17): [True: 11.1k, False: 18.4E]
  ------------------
 1449|  11.1k|                if (crypto != NULL) {
  ------------------
  |  Branch (1449:21): [True: 7.22k, False: 3.93k]
  ------------------
 1450|  7.22k|                    mac = packet_second_block + packet_remaining;
 1451|       |
 1452|  7.22k|                    if (crypto->in_hmac != SSH_HMAC_NONE && etm) {
  ------------------
  |  Branch (1452:25): [True: 5.54k, False: 1.68k]
  |  Branch (1452:61): [True: 0, False: 5.54k]
  ------------------
 1453|      0|                        rc = ssh_packet_hmac_verify(session,
 1454|      0|                                                    data,
 1455|      0|                                                    processed,
 1456|      0|                                                    mac,
 1457|      0|                                                    crypto->in_hmac);
 1458|      0|                        if (rc < 0) {
  ------------------
  |  Branch (1458:29): [True: 0, False: 0]
  ------------------
 1459|      0|                            ssh_set_error(session, SSH_FATAL, "HMAC error");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1460|      0|                            goto error;
 1461|      0|                        }
 1462|      0|                    }
 1463|       |                    /*
 1464|       |                     * Decrypt the packet. In case of EtM mode, the length is
 1465|       |                     * already known as it's unencrypted. In the other case,
 1466|       |                     * lenfield_blocksize bytes already have been decrypted.
 1467|       |                     */
 1468|  7.22k|                    if (packet_remaining > 0) {
  ------------------
  |  Branch (1468:25): [True: 5.53k, False: 1.69k]
  ------------------
 1469|  5.53k|                        rc = ssh_packet_decrypt(session,
 1470|  5.53k|                                                cleartext_packet,
 1471|  5.53k|                                                (uint8_t *)data,
 1472|  5.53k|                                                packet_offset,
 1473|  5.53k|                                                processed - packet_offset);
 1474|  5.53k|                        if (rc < 0) {
  ------------------
  |  Branch (1474:29): [True: 0, False: 5.53k]
  ------------------
 1475|      0|                            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1476|      0|                                          SSH_FATAL,
 1477|      0|                                          "Decryption error");
 1478|      0|                            goto error;
 1479|      0|                        }
 1480|  5.53k|                    }
 1481|       |
 1482|  7.22k|                    if (crypto->in_hmac != SSH_HMAC_NONE && !etm) {
  ------------------
  |  Branch (1482:25): [True: 5.54k, False: 1.68k]
  |  Branch (1482:61): [True: 5.54k, False: 0]
  ------------------
 1483|  5.54k|                        ssh_buffer in = session->in_buffer;
 1484|  5.54k|                        rc = ssh_packet_hmac_verify(session,
 1485|  5.54k|                                                    ssh_buffer_get(in),
 1486|  5.54k|                                                    ssh_buffer_get_len(in),
 1487|  5.54k|                                                    mac,
 1488|  5.54k|                                                    crypto->in_hmac);
 1489|  5.54k|                        if (rc < 0) {
  ------------------
  |  Branch (1489:29): [True: 0, False: 5.54k]
  ------------------
 1490|      0|                            ssh_set_error(session, SSH_FATAL, "HMAC error");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1491|      0|                            goto error;
 1492|      0|                        }
 1493|  5.54k|                    }
 1494|  7.22k|                    processed += current_macsize;
 1495|  7.22k|                } else {
 1496|  3.93k|                    memcpy(cleartext_packet,
 1497|  3.93k|                           packet_second_block,
 1498|  3.93k|                           packet_remaining);
 1499|  3.93k|                }
 1500|  11.1k|            }
 1501|       |
 1502|  11.1k|#ifdef WITH_PCAP
 1503|  11.1k|            if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1503:17): [True: 0, False: 11.1k]
  ------------------
 1504|      0|                ssh_pcap_context_write(session->pcap_ctx,
 1505|      0|                                       SSH_PCAP_DIR_IN,
 1506|      0|                                       ssh_buffer_get(session->in_buffer),
 1507|      0|                                       ssh_buffer_get_len(session->in_buffer),
 1508|      0|                                       ssh_buffer_get_len(session->in_buffer));
 1509|      0|            }
 1510|  11.1k|#endif
 1511|       |
 1512|  11.1k|            if (!etm) {
  ------------------
  |  Branch (1512:17): [True: 11.1k, False: 18.4E]
  ------------------
 1513|       |                /* skip the size field which has been processed before */
 1514|  11.1k|                ssh_buffer_pass_bytes(session->in_buffer, sizeof(uint32_t));
 1515|  11.1k|            }
 1516|       |
 1517|  11.1k|            rc = ssh_buffer_get_u8(session->in_buffer, &padding);
 1518|  11.1k|            if (rc == 0) {
  ------------------
  |  Branch (1518:17): [True: 0, False: 11.1k]
  ------------------
 1519|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1520|      0|                              SSH_FATAL,
 1521|      0|                              "Packet too short to read padding");
 1522|      0|                goto error;
 1523|      0|            }
 1524|       |
 1525|  11.1k|            if (padding > ssh_buffer_get_len(session->in_buffer)) {
  ------------------
  |  Branch (1525:17): [True: 0, False: 11.1k]
  ------------------
 1526|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1527|      0|                              SSH_FATAL,
 1528|      0|                              "Invalid padding: %d (%" PRIu32 " left)",
 1529|      0|                              padding,
 1530|      0|                              ssh_buffer_get_len(session->in_buffer));
 1531|      0|                goto error;
 1532|      0|            }
 1533|  11.1k|            ssh_buffer_pass_bytes_end(session->in_buffer, padding);
 1534|  11.1k|            compsize = ssh_buffer_get_len(session->in_buffer);
 1535|       |
 1536|  11.1k|            if (crypto && crypto->do_compress_in &&
  ------------------
  |  Branch (1536:17): [True: 7.22k, False: 3.90k]
  |  Branch (1536:27): [True: 0, False: 7.22k]
  ------------------
 1537|      0|                ssh_buffer_get_len(session->in_buffer) > 0) {
  ------------------
  |  Branch (1537:17): [True: 0, False: 0]
  ------------------
 1538|      0|                rc = decompress_buffer(session, session->in_buffer,
 1539|      0|                                       MAX_PACKET_LEN);
  ------------------
  |  |  216|      0|#define MAX_PACKET_LEN 262144
  ------------------
 1540|      0|                if (rc < 0) {
  ------------------
  |  Branch (1540:21): [True: 0, False: 0]
  ------------------
 1541|      0|                    goto error;
 1542|      0|                }
 1543|      0|            }
 1544|  11.1k|            payloadsize = ssh_buffer_get_len(session->in_buffer);
 1545|  11.1k|            if (session->recv_seq == UINT32_MAX) {
  ------------------
  |  Branch (1545:17): [True: 0, False: 11.1k]
  ------------------
 1546|       |                /* Overflowing sequence numbers is always fishy */
 1547|      0|                if (crypto == NULL) {
  ------------------
  |  Branch (1547:21): [True: 0, False: 0]
  ------------------
 1548|       |                    /* don't allow sequence number overflow when unencrypted */
 1549|      0|                    ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1550|      0|                                  SSH_FATAL,
 1551|      0|                                  "Incoming sequence number overflow");
 1552|      0|                    goto error;
 1553|      0|                } else {
 1554|      0|                    SSH_LOG(SSH_LOG_WARNING,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1555|      0|                            "Incoming sequence number overflow");
 1556|      0|                }
 1557|      0|            }
 1558|  11.1k|            session->recv_seq++;
 1559|  11.1k|            if (crypto != NULL) {
  ------------------
  |  Branch (1559:17): [True: 7.22k, False: 3.90k]
  ------------------
 1560|  7.22k|                struct ssh_cipher_struct *cipher = NULL;
 1561|       |
 1562|  7.22k|                cipher = crypto->in_cipher;
 1563|  7.22k|                cipher->packets++;
 1564|  7.22k|                cipher->blocks += payloadsize / cipher->blocksize;
 1565|  7.22k|            }
 1566|  11.1k|            if (session->raw_counter != NULL) {
  ------------------
  |  Branch (1566:17): [True: 0, False: 11.1k]
  ------------------
 1567|      0|                session->raw_counter->in_bytes += payloadsize;
 1568|      0|                session->raw_counter->in_packets++;
 1569|      0|            }
 1570|       |
 1571|       |            /*
 1572|       |             * We don't want to rewrite a new packet while still executing the
 1573|       |             * packet callbacks
 1574|       |             */
 1575|  11.1k|            session->packet_state = PACKET_STATE_PROCESSING;
 1576|  11.1k|            ssh_packet_parse_type(session);
 1577|  11.1k|            SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  11.1k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1578|  11.1k|                    "packet: read type %hhd [len=%" PRIu32 ",padding=%hhd,"
 1579|  11.1k|                    "comp=%" PRIu32 ",payload=%" PRIu32 "]",
 1580|  11.1k|                    session->in_packet.type, packet_len, padding, compsize,
 1581|  11.1k|                    payloadsize);
 1582|  11.1k|            if (crypto == NULL) {
  ------------------
  |  Branch (1582:17): [True: 3.92k, False: 7.20k]
  ------------------
 1583|       |                /* In strict kex, only a few packets are allowed. Taint the session
 1584|       |                 * if we received packets that are normally allowed but to be
 1585|       |                 * refused if we are in strict kex when KEX is over.
 1586|       |                 */
 1587|  3.92k|                uint8_t type = session->in_packet.type;
 1588|       |
 1589|  3.92k|                if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   12|  7.84k|#define SSH2_MSG_KEXINIT	 20
  ------------------
                              if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   13|  6.54k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (1589:21): [True: 2.62k, False: 1.30k]
  |  Branch (1589:49): [True: 1.31k, False: 1.30k]
  ------------------
 1590|  1.31k|                    (type < SSH2_MSG_KEXDH_INIT ||
  ------------------
  |  |   15|  2.62k|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (1590:22): [True: 0, False: 1.31k]
  ------------------
 1591|  1.31k|                     type > SSH2_MSG_KEX_DH_GEX_REQUEST)) {
  ------------------
  |  |   26|  1.31k|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (1591:22): [True: 0, False: 1.31k]
  ------------------
 1592|      0|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|      0|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1593|      0|                }
 1594|  3.92k|            }
 1595|       |            /* Check if the packet is expected */
 1596|  11.1k|            filter_result = ssh_packet_incoming_filter(session);
 1597|       |
 1598|  11.1k|            switch (filter_result) {
  ------------------
  |  Branch (1598:21): [True: 11.1k, False: 18.4E]
  ------------------
 1599|  11.1k|            case SSH_PACKET_ALLOWED:
  ------------------
  |  Branch (1599:13): [True: 11.1k, False: 18.4E]
  ------------------
 1600|       |                /* Execute callbacks */
 1601|  11.1k|                ssh_packet_process(session, session->in_packet.type);
 1602|  11.1k|                break;
 1603|      0|            case SSH_PACKET_DENIED:
  ------------------
  |  Branch (1603:13): [True: 0, False: 11.1k]
  ------------------
 1604|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1605|      0|                              SSH_FATAL,
 1606|      0|                              "Packet filter: rejected packet (type %d)",
 1607|      0|                              session->in_packet.type);
 1608|      0|                goto error;
 1609|      0|            case SSH_PACKET_UNKNOWN:
  ------------------
  |  Branch (1609:13): [True: 0, False: 11.1k]
  ------------------
 1610|      0|                if (crypto == NULL) {
  ------------------
  |  Branch (1610:21): [True: 0, False: 0]
  ------------------
 1611|      0|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|      0|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1612|      0|                }
 1613|      0|                ssh_packet_send_unimplemented(session, session->recv_seq - 1);
 1614|      0|                break;
 1615|  11.1k|            }
 1616|       |
 1617|  11.1k|            session->packet_state = PACKET_STATE_INIT;
 1618|  11.1k|            if (processed < receivedlen) {
  ------------------
  |  Branch (1618:17): [True: 1.17k, False: 9.98k]
  ------------------
 1619|  1.17k|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  1.17k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1620|  1.17k|                        "packet: %zu bytes still remaining in socket buffer "
 1621|  1.17k|                        "after processing",
 1622|  1.17k|                        receivedlen-processed);
 1623|  1.17k|            }
 1624|       |
 1625|  11.1k|            ok = ssh_packet_need_rekey(session, 0);
 1626|  11.1k|            if (ok) {
  ------------------
  |  Branch (1626:17): [True: 0, False: 11.1k]
  ------------------
 1627|      0|                SSH_LOG(SSH_LOG_PACKET, "Incoming packet triggered rekey");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1628|      0|                rc = ssh_send_rekex(session);
 1629|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1629:21): [True: 0, False: 0]
  ------------------
 1630|      0|                    SSH_LOG(SSH_LOG_PACKET, "Rekey failed: rc = %d", rc);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1631|      0|                    goto error;
 1632|      0|                }
 1633|      0|            }
 1634|       |
 1635|  11.1k|            return processed;
 1636|      0|        case PACKET_STATE_PROCESSING:
  ------------------
  |  Branch (1636:9): [True: 0, False: 22.8k]
  ------------------
 1637|      0|            SSH_LOG(SSH_LOG_PACKET, "Nested packet processing. Delaying.");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1638|      0|            return 0;
 1639|  22.8k|    }
 1640|       |
 1641|      0|    ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1642|      0|                  SSH_FATAL,
 1643|      0|                  "Invalid state into packet_read2(): %d",
 1644|      0|                  session->packet_state);
 1645|       |
 1646|      0|error:
 1647|      0|    session->session_state = SSH_SESSION_STATE_ERROR;
 1648|      0|    SSH_LOG(SSH_LOG_PACKET, "Packet: processed %zu bytes", processed);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1649|      0|    return processed;
 1650|      0|}
ssh_packet_register_socket_callback:
 1677|  1.31k|{
 1678|  1.31k|    struct ssh_socket_callbacks_struct *callbacks = &session->socket_callbacks;
 1679|       |
 1680|  1.31k|    callbacks->data = ssh_packet_socket_callback;
 1681|       |    callbacks->connected = NULL;
 1682|  1.31k|    callbacks->controlflow = ssh_packet_socket_controlflow_callback;
 1683|  1.31k|    callbacks->userdata = session;
 1684|  1.31k|    ssh_socket_set_callbacks(s, callbacks);
 1685|  1.31k|}
ssh_packet_set_callbacks:
 1692|  2.62k|{
 1693|  2.62k|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1693:9): [True: 1.31k, False: 1.31k]
  ------------------
 1694|  1.31k|        session->packet_callbacks = ssh_list_new();
 1695|  1.31k|        if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1695:13): [True: 0, False: 1.31k]
  ------------------
 1696|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1697|      0|            return;
 1698|      0|        }
 1699|  1.31k|    }
 1700|  2.62k|    ssh_list_append(session->packet_callbacks, callbacks);
 1701|  2.62k|}
ssh_packet_remove_callbacks:
 1708|  1.31k|{
 1709|  1.31k|    struct ssh_iterator *it = NULL;
 1710|       |
 1711|  1.31k|    it = ssh_list_find(session->packet_callbacks, callbacks);
 1712|  1.31k|    if (it != NULL) {
  ------------------
  |  Branch (1712:9): [True: 1.31k, False: 0]
  ------------------
 1713|  1.31k|        ssh_list_remove(session->packet_callbacks, it);
 1714|  1.31k|    }
 1715|  1.31k|}
ssh_packet_set_default_callbacks:
 1721|  1.31k|{
 1722|  1.31k|    struct ssh_packet_callbacks_struct *c = &session->default_packet_callbacks;
 1723|       |
 1724|  1.31k|    c->start = 1;
 1725|  1.31k|    c->n_callbacks = sizeof(default_packet_handlers) / sizeof(ssh_packet_callback);
 1726|  1.31k|    c->user = session;
 1727|  1.31k|    c->callbacks = default_packet_handlers;
 1728|  1.31k|    ssh_packet_set_callbacks(session, c);
 1729|  1.31k|}
ssh_packet_process:
 1736|  11.1k|{
 1737|  11.1k|    struct ssh_iterator *i = NULL;
 1738|  11.1k|    int rc = SSH_PACKET_NOT_USED;
  ------------------
  |  |  640|  11.1k|#define SSH_PACKET_NOT_USED 2
  ------------------
 1739|  11.1k|    ssh_packet_callbacks cb;
 1740|       |
 1741|  11.1k|    SSH_LOG(SSH_LOG_PACKET, "Dispatching handler for packet type %d", type);
  ------------------
  |  |  281|  11.1k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1742|  11.1k|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1742:9): [True: 0, False: 11.1k]
  ------------------
 1743|      0|        SSH_LOG(SSH_LOG_RARE, "Packet callback is not initialized !");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1744|      0|        return;
 1745|      0|    }
 1746|       |
 1747|  11.1k|    i = ssh_list_get_iterator(session->packet_callbacks);
 1748|  12.4k|    while (i != NULL) {
  ------------------
  |  Branch (1748:12): [True: 12.4k, False: 18.4E]
  ------------------
 1749|  12.4k|        cb = ssh_iterator_value(ssh_packet_callbacks, i);
  ------------------
  |  |  114|  12.4k|  ((type)((iterator)->data))
  ------------------
 1750|  12.4k|        i = i->next;
 1751|       |
 1752|  12.4k|        if (!cb) {
  ------------------
  |  Branch (1752:13): [True: 0, False: 12.4k]
  ------------------
 1753|      0|            continue;
 1754|      0|        }
 1755|       |
 1756|  12.4k|        if (cb->start > type) {
  ------------------
  |  Branch (1756:13): [True: 0, False: 12.4k]
  ------------------
 1757|      0|            continue;
 1758|      0|        }
 1759|       |
 1760|  12.4k|        if (cb->start + cb->n_callbacks <= type) {
  ------------------
  |  Branch (1760:13): [True: 0, False: 12.4k]
  ------------------
 1761|      0|            continue;
 1762|      0|        }
 1763|       |
 1764|  12.4k|        if (cb->callbacks[type - cb->start] == NULL) {
  ------------------
  |  Branch (1764:13): [True: 657, False: 11.8k]
  ------------------
 1765|    657|            continue;
 1766|    657|        }
 1767|       |
 1768|  11.8k|        rc = cb->callbacks[type - cb->start](session, type, session->in_buffer,
 1769|  11.8k|                                             cb->user);
 1770|  11.8k|        if (rc == SSH_PACKET_USED) {
  ------------------
  |  |  637|  11.8k|#define SSH_PACKET_USED 1
  ------------------
  |  Branch (1770:13): [True: 11.1k, False: 645]
  ------------------
 1771|  11.1k|            break;
 1772|  11.1k|        }
 1773|  11.8k|    }
 1774|       |
 1775|  11.1k|    if (rc == SSH_PACKET_NOT_USED) {
  ------------------
  |  |  640|  11.1k|#define SSH_PACKET_NOT_USED 2
  ------------------
  |  Branch (1775:9): [True: 0, False: 11.1k]
  ------------------
 1776|      0|        SSH_LOG(SSH_LOG_RARE, "Couldn't do anything with packet type %d", type);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1777|      0|        rc = ssh_packet_send_unimplemented(session, session->recv_seq - 1);
 1778|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1778:13): [True: 0, False: 0]
  ------------------
 1779|      0|            SSH_LOG(SSH_LOG_RARE, "Failed to send unimplemented: %s",
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1780|      0|                    ssh_get_error(session));
 1781|      0|        }
 1782|      0|        if (session->current_crypto == NULL) {
  ------------------
  |  Branch (1782:13): [True: 0, False: 0]
  ------------------
 1783|      0|            session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|      0|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1784|      0|        }
 1785|      0|    }
 1786|  11.1k|}
ssh_packet_send_newkeys:
 1794|  1.31k|{
 1795|  1.31k|    int rc;
 1796|       |
 1797|       |    /* Send the MSG_NEWKEYS */
 1798|  1.31k|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS);
  ------------------
  |  |   13|  1.31k|#define SSH2_MSG_NEWKEYS 21
  ------------------
 1799|  1.31k|    if (rc < 0) {
  ------------------
  |  Branch (1799:9): [True: 0, False: 1.31k]
  ------------------
 1800|      0|        return rc;
 1801|      0|    }
 1802|       |
 1803|  1.31k|    rc = ssh_packet_send(session);
 1804|  1.31k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1804:9): [True: 0, False: 1.31k]
  ------------------
 1805|      0|        return rc;
 1806|      0|    }
 1807|  1.31k|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_NEWKEYS sent");
  ------------------
  |  |  281|  1.31k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1808|  1.31k|    return rc;
 1809|  1.31k|}
ssh_packet_parse_type:
 1861|  11.1k|{
 1862|  11.1k|    session->in_packet = (struct packet_struct) {
 1863|  11.1k|        .type = 0,
 1864|  11.1k|    };
 1865|       |
 1866|  11.1k|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (1866:9): [True: 0, False: 11.1k]
  ------------------
 1867|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1868|      0|    }
 1869|       |
 1870|  11.1k|    if (ssh_buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) {
  ------------------
  |  Branch (1870:9): [True: 0, False: 11.1k]
  ------------------
 1871|      0|        ssh_set_error(session, SSH_FATAL, "Packet too short to read type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1872|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1873|      0|    }
 1874|       |
 1875|  11.1k|    session->in_packet.valid = 1;
 1876|       |
 1877|  11.1k|    return SSH_OK;
  ------------------
  |  |  316|  11.1k|#define SSH_OK 0     /* No error */
  ------------------
 1878|  11.1k|}
ssh_packet_send:
 2066|  13.7k|{
 2067|  13.7k|    uint32_t payloadsize;
 2068|  13.7k|    uint8_t type, *payload;
 2069|  13.7k|    bool need_rekey, in_rekey;
 2070|  13.7k|    int rc;
 2071|       |
 2072|  13.7k|    if (session->socket == NULL || !ssh_socket_is_open(session->socket)) {
  ------------------
  |  Branch (2072:9): [True: 0, False: 13.7k]
  |  Branch (2072:36): [True: 660, False: 13.1k]
  ------------------
 2073|    660|        ssh_buffer_reinit(session->out_buffer);
 2074|    660|        return SSH_ERROR;
  ------------------
  |  |  317|    660|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2075|    660|    }
 2076|       |
 2077|  13.1k|    payloadsize = ssh_buffer_get_len(session->out_buffer);
 2078|  13.1k|    if (payloadsize < 1) {
  ------------------
  |  Branch (2078:9): [True: 0, False: 13.1k]
  ------------------
 2079|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2080|      0|    }
 2081|       |
 2082|  13.1k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 2083|  13.1k|    type = payload[0]; /* type is the first byte of the packet now */
 2084|  13.1k|    need_rekey = ssh_packet_need_rekey(session, payloadsize);
 2085|  13.1k|    in_rekey = ssh_packet_in_rekey(session);
 2086|       |
 2087|       |    /* The rekey is triggered here. After that, only the key exchange
 2088|       |     * packets can be sent, until we send our NEWKEYS.
 2089|       |     */
 2090|  13.1k|    if (need_rekey || (in_rekey && !ssh_packet_is_kex(type))) {
  ------------------
  |  Branch (2090:9): [True: 0, False: 13.1k]
  |  Branch (2090:24): [True: 0, False: 13.1k]
  |  Branch (2090:36): [True: 0, False: 0]
  ------------------
 2091|      0|        if (need_rekey) {
  ------------------
  |  Branch (2091:13): [True: 0, False: 0]
  ------------------
 2092|      0|            SSH_LOG(SSH_LOG_PACKET, "Outgoing packet triggered rekey");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2093|      0|        }
 2094|       |        /* Queue the current packet -- we will send it after the rekey */
 2095|      0|        SSH_LOG(SSH_LOG_PACKET, "Queuing packet type %d", type);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2096|      0|        rc = ssh_list_append(session->out_queue, session->out_buffer);
 2097|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2097:13): [True: 0, False: 0]
  ------------------
 2098|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2099|      0|        }
 2100|      0|        session->out_buffer = ssh_buffer_new();
 2101|      0|        if (session->out_buffer == NULL) {
  ------------------
  |  Branch (2101:13): [True: 0, False: 0]
  ------------------
 2102|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2103|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2104|      0|        }
 2105|       |
 2106|      0|        if (need_rekey) {
  ------------------
  |  Branch (2106:13): [True: 0, False: 0]
  ------------------
 2107|       |            /* Send the KEXINIT packet instead.
 2108|       |             * This recursively calls the packet_send(), but it should
 2109|       |             * not get into rekeying again.
 2110|       |             * After that we need to handle the key exchange responses
 2111|       |             * up to the point where we can send the rest of the queue.
 2112|       |             */
 2113|      0|            return ssh_send_rekex(session);
 2114|      0|        }
 2115|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2116|      0|    }
 2117|       |
 2118|       |    /* Send the packet normally */
 2119|  13.1k|    rc = packet_send2(session);
 2120|       |
 2121|       |    /* We finished the key exchange so we can try to send our queue now */
 2122|  13.1k|    if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |  316|  26.2k|#define SSH_OK 0     /* No error */
  ------------------
                  if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  13.1k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2122:9): [True: 13.1k, False: 1]
  |  Branch (2122:25): [True: 1.31k, False: 11.8k]
  ------------------
 2123|  1.31k|        struct ssh_iterator *it = NULL;
 2124|       |
 2125|  1.31k|        if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|  1.31k|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (2125:13): [True: 1.31k, False: 0]
  ------------------
 2126|       |            /* reset packet sequence number when running in strict kex mode */
 2127|  1.31k|            session->send_seq = 0;
 2128|  1.31k|        }
 2129|  1.31k|        for (it = ssh_list_get_iterator(session->out_queue);
 2130|  1.31k|             it != NULL;
  ------------------
  |  Branch (2130:14): [True: 0, False: 1.31k]
  ------------------
 2131|  1.31k|             it = ssh_list_get_iterator(session->out_queue)) {
 2132|      0|            struct ssh_buffer_struct *next_buffer = NULL;
 2133|       |
 2134|       |            /* Peek only -- do not remove from queue yet */
 2135|      0|            next_buffer = (struct ssh_buffer_struct *)it->data;
 2136|      0|            payloadsize = ssh_buffer_get_len(next_buffer);
 2137|      0|            if (ssh_packet_need_rekey(session, payloadsize)) {
  ------------------
  |  Branch (2137:17): [True: 0, False: 0]
  ------------------
 2138|       |                /* Sigh ... we still can not send this packet. Repeat. */
 2139|      0|                SSH_LOG(SSH_LOG_PACKET, "Queued packet triggered rekey");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2140|      0|                return ssh_send_rekex(session);
 2141|      0|            }
 2142|      0|            SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2143|      0|            session->out_buffer = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2144|      0|                                                    session->out_queue);
 2145|      0|            payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 2146|      0|            type = payload[0];
 2147|      0|            SSH_LOG(SSH_LOG_PACKET, "Dequeue packet type %d", type);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2148|      0|            rc = packet_send2(session);
 2149|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2149:17): [True: 0, False: 0]
  ------------------
 2150|      0|                return rc;
 2151|      0|            }
 2152|      0|        }
 2153|  1.31k|    }
 2154|       |
 2155|  13.1k|    return rc;
 2156|  13.1k|}
ssh_packet_set_newkeys:
 2271|  2.62k|{
 2272|  2.62k|    struct ssh_cipher_struct *in_cipher = NULL, *out_cipher = NULL;
 2273|  2.62k|    int rc;
 2274|       |
 2275|  2.62k|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|  10.5k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 1.31k, False: 1.31k]
  |  |  |  Branch (281:34): [True: 1.31k, False: 1.31k]
  |  |  ------------------
  ------------------
 2276|  2.62k|            "called, direction =%s%s",
 2277|  2.62k|            direction & SSH_DIRECTION_IN ? " IN " : "",
 2278|  2.62k|            direction & SSH_DIRECTION_OUT ? " OUT " : "");
 2279|       |
 2280|  2.62k|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2280:9): [True: 0, False: 2.62k]
  ------------------
 2281|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2282|      0|    }
 2283|       |
 2284|  2.62k|    session->next_crypto->used |= direction;
 2285|  2.62k|    if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2285:9): [True: 0, False: 2.62k]
  ------------------
 2286|      0|        if (session->current_crypto->used & direction) {
  ------------------
  |  Branch (2286:13): [True: 0, False: 0]
  ------------------
 2287|      0|            SSH_LOG(SSH_LOG_TRACE, "This direction isn't used anymore.");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2288|      0|        }
 2289|       |        /* Mark the current requested direction unused */
 2290|      0|        session->current_crypto->used &= ~direction;
 2291|      0|    }
 2292|       |
 2293|       |    /* Both sides switched: do the actual switch now */
 2294|  2.62k|    if (session->next_crypto->used == SSH_DIRECTION_BOTH) {
  ------------------
  |  Branch (2294:9): [True: 1.31k, False: 1.31k]
  ------------------
 2295|  1.31k|        size_t session_id_len;
 2296|       |
 2297|  1.31k|        if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2297:13): [True: 0, False: 1.31k]
  ------------------
 2298|      0|            crypto_free(session->current_crypto);
 2299|      0|            session->current_crypto = NULL;
 2300|      0|        }
 2301|       |
 2302|  1.31k|        session->current_crypto = session->next_crypto;
 2303|  1.31k|        session->current_crypto->used = SSH_DIRECTION_BOTH;
 2304|       |
 2305|       |        /* Initialize the next_crypto structure */
 2306|  1.31k|        session->next_crypto = crypto_new();
 2307|  1.31k|        if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2307:13): [True: 0, False: 1.31k]
  ------------------
 2308|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2309|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2310|      0|        }
 2311|       |
 2312|  1.31k|        session_id_len = session->current_crypto->session_id_len;
 2313|  1.31k|        session->next_crypto->session_id = malloc(session_id_len);
 2314|  1.31k|        if (session->next_crypto->session_id == NULL) {
  ------------------
  |  Branch (2314:13): [True: 0, False: 1.31k]
  ------------------
 2315|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2316|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2317|      0|        }
 2318|       |
 2319|  1.31k|        memcpy(session->next_crypto->session_id,
 2320|  1.31k|               session->current_crypto->session_id,
 2321|  1.31k|               session_id_len);
 2322|  1.31k|        session->next_crypto->session_id_len = session_id_len;
 2323|       |
 2324|  1.31k|        return SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
 2325|  1.31k|    }
 2326|       |
 2327|       |    /* Initialize common structures so the next context can be used in
 2328|       |     * either direction */
 2329|  1.31k|    if (session->client) {
  ------------------
  |  Branch (2329:9): [True: 657, False: 657]
  ------------------
 2330|       |        /* The server has this part already done */
 2331|    657|        rc = ssh_make_sessionid(session);
 2332|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2332:13): [True: 0, False: 657]
  ------------------
 2333|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2334|      0|        }
 2335|       |
 2336|       |        /*
 2337|       |         * Set the cryptographic functions for the next crypto
 2338|       |         * (it is needed for ssh_generate_session_keys for key lengths)
 2339|       |         */
 2340|    657|        rc = crypt_set_algorithms_client(session);
 2341|    657|        if (rc < 0) {
  ------------------
  |  Branch (2341:13): [True: 0, False: 657]
  ------------------
 2342|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2343|      0|        }
 2344|    657|    }
 2345|       |
 2346|  1.31k|    if (ssh_generate_session_keys(session) < 0) {
  ------------------
  |  Branch (2346:9): [True: 0, False: 1.31k]
  ------------------
 2347|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2348|      0|    }
 2349|       |
 2350|  1.31k|    in_cipher = session->next_crypto->in_cipher;
 2351|  1.31k|    out_cipher = session->next_crypto->out_cipher;
 2352|  1.31k|    if (in_cipher == NULL || out_cipher == NULL) {
  ------------------
  |  Branch (2352:9): [True: 0, False: 1.31k]
  |  Branch (2352:30): [True: 0, False: 1.31k]
  ------------------
 2353|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2354|      0|    }
 2355|       |
 2356|       |    /* Initialize rekeying states */
 2357|  1.31k|    ssh_init_rekey_state(session, out_cipher);
 2358|  1.31k|    ssh_init_rekey_state(session, in_cipher);
 2359|  1.31k|    if (session->opts.rekey_time != 0) {
  ------------------
  |  Branch (2359:9): [True: 0, False: 1.31k]
  ------------------
 2360|      0|        ssh_timestamp_init(&session->last_rekey_time);
 2361|      0|        SSH_LOG(SSH_LOG_DEBUG, "Set rekey after %" PRIu32 " seconds",
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2362|      0|                session->opts.rekey_time/1000);
 2363|      0|    }
 2364|       |
 2365|  1.31k|    if (in_cipher->set_decrypt_key) {
  ------------------
  |  Branch (2365:9): [True: 1.13k, False: 182]
  ------------------
 2366|       |        /* Initialize the encryption and decryption keys in next_crypto */
 2367|  1.13k|        rc = in_cipher->set_decrypt_key(in_cipher,
 2368|  1.13k|                                        session->next_crypto->decryptkey,
 2369|  1.13k|                                        session->next_crypto->decryptIV);
 2370|  1.13k|        if (rc < 0) {
  ------------------
  |  Branch (2370:13): [True: 0, False: 1.13k]
  ------------------
 2371|       |            /* On error, make sure it is not used */
 2372|      0|            session->next_crypto->used = 0;
 2373|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2374|      0|        }
 2375|  1.13k|    }
 2376|       |
 2377|  1.31k|    if (out_cipher->set_encrypt_key) {
  ------------------
  |  Branch (2377:9): [True: 1.13k, False: 182]
  ------------------
 2378|  1.13k|        rc = out_cipher->set_encrypt_key(out_cipher,
 2379|  1.13k|                                         session->next_crypto->encryptkey,
 2380|  1.13k|                                         session->next_crypto->encryptIV);
 2381|  1.13k|        if (rc < 0) {
  ------------------
  |  Branch (2381:13): [True: 0, False: 1.13k]
  ------------------
 2382|       |            /* On error, make sure it is not used */
 2383|      0|            session->next_crypto->used = 0;
 2384|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2385|      0|        }
 2386|  1.13k|    }
 2387|       |
 2388|  1.31k|    return SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
 2389|  1.31k|}
packet.c:ssh_packet_incoming_filter:
  143|  11.1k|{
  144|  11.1k|    enum ssh_packet_filter_result_e rc;
  145|       |
  146|       |#ifdef DEBUG_PACKET
  147|       |    SSH_LOG(SSH_LOG_PACKET, "Filtering packet type %d",
  148|       |            session->in_packet.type);
  149|       |#endif
  150|       |
  151|  11.1k|    switch(session->in_packet.type) {
  152|      0|    case SSH2_MSG_DISCONNECT:                         // 1
  ------------------
  |  |    4|      0|#define SSH2_MSG_DISCONNECT 1
  ------------------
  |  Branch (152:5): [True: 0, False: 11.1k]
  ------------------
  153|       |        /*
  154|       |         * States required:
  155|       |         * - None
  156|       |         *
  157|       |         * Transitions:
  158|       |         * - session->socket->state = SSH_SOCKET_CLOSED
  159|       |         * - session->session_state = SSH_SESSION_STATE_ERROR
  160|       |         * */
  161|       |
  162|       |        /* Always allowed */
  163|      0|        rc = SSH_PACKET_ALLOWED;
  164|      0|        break;
  165|      0|    case SSH2_MSG_IGNORE:                             // 2
  ------------------
  |  |    5|      0|#define SSH2_MSG_IGNORE	 2
  ------------------
  |  Branch (165:5): [True: 0, False: 11.1k]
  ------------------
  166|       |        /*
  167|       |         * States required:
  168|       |         * - None
  169|       |         *
  170|       |         * Transitions:
  171|       |         * - None
  172|       |         * */
  173|       |
  174|       |        /* Always allowed */
  175|      0|        rc = SSH_PACKET_ALLOWED;
  176|      0|        break;
  177|      0|    case SSH2_MSG_UNIMPLEMENTED:                      // 3
  ------------------
  |  |    6|      0|#define SSH2_MSG_UNIMPLEMENTED 3
  ------------------
  |  Branch (177:5): [True: 0, False: 11.1k]
  ------------------
  178|       |        /*
  179|       |         * States required:
  180|       |         * - None
  181|       |         *
  182|       |         * Transitions:
  183|       |         * - None
  184|       |         * */
  185|       |
  186|       |        /* Always allowed */
  187|      0|        rc = SSH_PACKET_ALLOWED;
  188|      0|        break;
  189|      0|    case SSH2_MSG_DEBUG:                              // 4
  ------------------
  |  |    7|      0|#define SSH2_MSG_DEBUG	4
  ------------------
  |  Branch (189:5): [True: 0, False: 11.1k]
  ------------------
  190|       |        /*
  191|       |         * States required:
  192|       |         * - None
  193|       |         *
  194|       |         * Transitions:
  195|       |         * - None
  196|       |         * */
  197|       |
  198|       |        /* Always allowed */
  199|      0|        rc = SSH_PACKET_ALLOWED;
  200|      0|        break;
  201|    657|    case SSH2_MSG_SERVICE_REQUEST:                    // 5
  ------------------
  |  |    8|    657|#define SSH2_MSG_SERVICE_REQUEST	5
  ------------------
  |  Branch (201:5): [True: 657, False: 10.4k]
  ------------------
  202|       |        /* Server only */
  203|       |
  204|       |        /*
  205|       |         * States required:
  206|       |         * - session->session_state == SSH_SESSION_STATE_AUTHENTICATING
  207|       |         *   or session->session_state == SSH_SESSION_STATE_AUTHENTICATED
  208|       |         * - session->dh_handshake_state == DH_STATE_FINISHED
  209|       |         *
  210|       |         * Transitions:
  211|       |         * - None
  212|       |         * */
  213|       |
  214|       |        /* If this is a client, reject the message */
  215|    657|        if (session->client) {
  ------------------
  |  Branch (215:13): [True: 0, False: 657]
  ------------------
  216|      0|            rc = SSH_PACKET_DENIED;
  217|      0|            break;
  218|      0|        }
  219|       |
  220|    657|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (220:13): [True: 0, False: 657]
  ------------------
  221|      0|            (session->session_state != SSH_SESSION_STATE_AUTHENTICATED))
  ------------------
  |  Branch (221:13): [True: 0, False: 0]
  ------------------
  222|      0|        {
  223|      0|            rc = SSH_PACKET_DENIED;
  224|      0|            break;
  225|      0|        }
  226|       |
  227|    657|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (227:13): [True: 0, False: 657]
  ------------------
  228|      0|            rc = SSH_PACKET_DENIED;
  229|      0|            break;
  230|      0|        }
  231|       |
  232|    657|        rc = SSH_PACKET_ALLOWED;
  233|    657|        break;
  234|    657|    case SSH2_MSG_SERVICE_ACCEPT:                     // 6
  ------------------
  |  |    9|    657|#define SSH2_MSG_SERVICE_ACCEPT 6
  ------------------
  |  Branch (234:5): [True: 657, False: 10.4k]
  ------------------
  235|       |        /*
  236|       |         * States required:
  237|       |         * - session->session_state == SSH_SESSION_STATE_AUTHENTICATING
  238|       |         *   or session->session_state == SSH_SESSION_STATE_AUTHENTICATED
  239|       |         * - session->dh_handshake_state == DH_STATE_FINISHED
  240|       |         * - session->auth.service_state == SSH_AUTH_SERVICE_SENT
  241|       |         *
  242|       |         * Transitions:
  243|       |         * - auth.service_state = SSH_AUTH_SERVICE_ACCEPTED
  244|       |         * */
  245|       |
  246|    657|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (246:13): [True: 0, False: 657]
  ------------------
  247|      0|            (session->session_state != SSH_SESSION_STATE_AUTHENTICATED))
  ------------------
  |  Branch (247:13): [True: 0, False: 0]
  ------------------
  248|      0|        {
  249|      0|            rc = SSH_PACKET_DENIED;
  250|      0|            break;
  251|      0|        }
  252|       |
  253|    657|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (253:13): [True: 0, False: 657]
  ------------------
  254|      0|            rc = SSH_PACKET_DENIED;
  255|      0|            break;
  256|      0|        }
  257|       |
  258|       |        /* TODO check if only auth service can be requested */
  259|    657|        if (session->auth.service_state != SSH_AUTH_SERVICE_SENT) {
  ------------------
  |  Branch (259:13): [True: 0, False: 657]
  ------------------
  260|      0|            rc = SSH_PACKET_DENIED;
  261|      0|            break;
  262|      0|        }
  263|       |
  264|    657|        rc = SSH_PACKET_ALLOWED;
  265|    657|        break;
  266|    657|    case SSH2_MSG_EXT_INFO:                           // 7
  ------------------
  |  |   10|    657|#define SSH2_MSG_EXT_INFO 7
  ------------------
  |  Branch (266:5): [True: 657, False: 10.4k]
  ------------------
  267|       |        /*
  268|       |         * States required:
  269|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  270|       |         *   or session->session_state == SSH_SESSION_STATE_AUTHENTICATED
  271|       |         *   (re-exchange)
  272|       |         * - dh_handshake_state == DH_STATE_FINISHED
  273|       |         *
  274|       |         * Transitions:
  275|       |         * - None
  276|       |         * */
  277|       |
  278|    657|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (278:13): [True: 0, False: 657]
  ------------------
  279|      0|            (session->session_state != SSH_SESSION_STATE_AUTHENTICATED))
  ------------------
  |  Branch (279:13): [True: 0, False: 0]
  ------------------
  280|      0|        {
  281|      0|            rc = SSH_PACKET_DENIED;
  282|      0|            break;
  283|      0|        }
  284|       |
  285|    657|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (285:13): [True: 0, False: 657]
  ------------------
  286|      0|            rc = SSH_PACKET_DENIED;
  287|      0|            break;
  288|      0|        }
  289|       |
  290|    657|        rc = SSH_PACKET_ALLOWED;
  291|    657|        break;
  292|  1.30k|    case SSH2_MSG_KEXINIT:                            // 20
  ------------------
  |  |   12|  1.30k|#define SSH2_MSG_KEXINIT	 20
  ------------------
  |  Branch (292:5): [True: 1.30k, False: 9.84k]
  ------------------
  293|       |        /*
  294|       |         * States required:
  295|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  296|       |         *   or session_state == SSH_SESSION_STATE_INITIAL_KEX
  297|       |         * - dh_handshake_state == DH_STATE_INIT
  298|       |         *   or dh_handshake_state == DH_STATE_INIT_SENT (re-exchange)
  299|       |         *   or dh_handshake_state == DH_STATE_REQUEST_SENT (dh-gex)
  300|       |         *   or dh_handshake_state == DH_STATE_FINISHED (re-exchange)
  301|       |         *
  302|       |         * Transitions:
  303|       |         * - session->dh_handshake_state = DH_STATE_INIT
  304|       |         * - session->session_state = SSH_SESSION_STATE_KEXINIT_RECEIVED
  305|       |         *
  306|       |         * On server:
  307|       |         * - session->session_state = SSH_SESSION_STATE_DH
  308|       |         * */
  309|       |
  310|  1.30k|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATED) &&
  ------------------
  |  Branch (310:13): [True: 1.30k, False: 18.4E]
  ------------------
  311|  1.30k|            (session->session_state != SSH_SESSION_STATE_INITIAL_KEX))
  ------------------
  |  Branch (311:13): [True: 0, False: 1.30k]
  ------------------
  312|      0|        {
  313|      0|            rc = SSH_PACKET_DENIED;
  314|      0|            break;
  315|      0|        }
  316|       |
  317|  1.30k|        if ((session->dh_handshake_state != DH_STATE_INIT) &&
  ------------------
  |  Branch (317:13): [True: 0, False: 1.30k]
  ------------------
  318|      0|            (session->dh_handshake_state != DH_STATE_INIT_SENT) &&
  ------------------
  |  Branch (318:13): [True: 0, False: 0]
  ------------------
  319|      0|            (session->dh_handshake_state != DH_STATE_REQUEST_SENT) &&
  ------------------
  |  Branch (319:13): [True: 0, False: 0]
  ------------------
  320|      0|            (session->dh_handshake_state != DH_STATE_FINISHED))
  ------------------
  |  Branch (320:13): [True: 0, False: 0]
  ------------------
  321|      0|        {
  322|      0|            rc = SSH_PACKET_DENIED;
  323|      0|            break;
  324|      0|        }
  325|       |
  326|  1.30k|        rc = SSH_PACKET_ALLOWED;
  327|  1.30k|        break;
  328|  1.30k|    case SSH2_MSG_NEWKEYS:                            // 21
  ------------------
  |  |   13|  1.30k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (328:5): [True: 1.30k, False: 9.84k]
  ------------------
  329|       |        /*
  330|       |         * States required:
  331|       |         * - session_state == SSH_SESSION_STATE_DH
  332|       |         * - dh_handshake_state == DH_STATE_NEWKEYS_SENT
  333|       |         *
  334|       |         * Transitions:
  335|       |         * - session->dh_handshake_state = DH_STATE_FINISHED
  336|       |         * - session->session_state = SSH_SESSION_STATE_AUTHENTICATING
  337|       |         * if session->flags & SSH_SESSION_FLAG_AUTHENTICATED
  338|       |         * - session->session_state = SSH_SESSION_STATE_AUTHENTICATED
  339|       |         * */
  340|       |
  341|       |        /* If DH has not been started, reject message */
  342|  1.30k|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (342:13): [True: 0, False: 1.30k]
  ------------------
  343|      0|            rc = SSH_PACKET_DENIED;
  344|      0|            break;
  345|      0|        }
  346|       |
  347|       |        /* Only allowed if dh_handshake_state is in NEWKEYS_SENT state */
  348|  1.30k|        if (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (348:13): [True: 0, False: 1.30k]
  ------------------
  349|      0|            rc = SSH_PACKET_DENIED;
  350|      0|            break;
  351|      0|        }
  352|       |
  353|  1.30k|        rc = SSH_PACKET_ALLOWED;
  354|  1.30k|        break;
  355|    657|    case SSH2_MSG_KEXDH_INIT:                         // 30
  ------------------
  |  |   15|    657|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (355:5): [True: 657, False: 10.4k]
  ------------------
  356|       |      // SSH2_MSG_KEX_ECDH_INIT:                      // 30
  357|       |      // SSH2_MSG_KEX_HYBRID_INIT:                    // 30
  358|       |      // SSH2_MSG_KEX_DH_GEX_REQUEST_OLD:             // 30
  359|       |
  360|       |        /* Server only */
  361|       |
  362|       |        /*
  363|       |         * States required:
  364|       |         * - session_state == SSH_SESSION_STATE_DH
  365|       |         * - dh_handshake_state == DH_STATE_INIT
  366|       |         *
  367|       |         * Transitions:
  368|       |         * - session->dh_handshake_state = DH_STATE_INIT_SENT
  369|       |         * then calls dh_handshake_server which triggers:
  370|       |         * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  371|       |         * */
  372|       |
  373|    657|        if (session->client) {
  ------------------
  |  Branch (373:13): [True: 0, False: 657]
  ------------------
  374|      0|            rc = SSH_PACKET_DENIED;
  375|      0|            break;
  376|      0|        }
  377|       |
  378|    657|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (378:13): [True: 0, False: 657]
  ------------------
  379|      0|            rc = SSH_PACKET_DENIED;
  380|      0|            break;
  381|      0|        }
  382|       |
  383|       |        /* Only allowed if dh_handshake_state is in initial state */
  384|    657|        if (session->dh_handshake_state != DH_STATE_INIT) {
  ------------------
  |  Branch (384:13): [True: 0, False: 657]
  ------------------
  385|      0|            rc = SSH_PACKET_DENIED;
  386|      0|            break;
  387|      0|        }
  388|       |
  389|    657|        rc = SSH_PACKET_ALLOWED;
  390|    657|        break;
  391|    657|    case SSH2_MSG_KEXDH_REPLY:                        // 31
  ------------------
  |  |   16|    657|#define SSH2_MSG_KEXDH_REPLY 31
  ------------------
  |  Branch (391:5): [True: 657, False: 10.4k]
  ------------------
  392|       |      // SSH2_MSG_KEX_ECDH_REPLY:                     // 31
  393|       |      // SSH2_MSG_KEX_HYBRID_REPLY:                   // 31
  394|       |      // SSH2_MSG_KEX_DH_GEX_GROUP:                   // 31
  395|       |
  396|       |        /* Client only */
  397|       |
  398|       |        /*
  399|       |         * States required:
  400|       |         * - session_state == SSH_SESSION_STATE_DH
  401|       |         * - dh_handshake_state == DH_STATE_INIT_SENT
  402|       |         *   or dh_handshake_state == DH_STATE_REQUEST_SENT (dh-gex)
  403|       |         *
  404|       |         * Transitions:
  405|       |         * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  406|       |         * */
  407|       |
  408|    657|        if (session->server) {
  ------------------
  |  Branch (408:13): [True: 0, False: 657]
  ------------------
  409|      0|            rc = SSH_PACKET_DENIED;
  410|      0|            break;
  411|      0|        }
  412|       |
  413|    657|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (413:13): [True: 0, False: 657]
  ------------------
  414|      0|            rc = SSH_PACKET_DENIED;
  415|      0|            break;
  416|      0|        }
  417|       |
  418|    657|        if (session->dh_handshake_state != DH_STATE_INIT_SENT &&
  ------------------
  |  Branch (418:13): [True: 0, False: 657]
  ------------------
  419|      0|            session->dh_handshake_state != DH_STATE_REQUEST_SENT) {
  ------------------
  |  Branch (419:13): [True: 0, False: 0]
  ------------------
  420|      0|            rc = SSH_PACKET_DENIED;
  421|      0|            break;
  422|      0|        }
  423|       |
  424|    657|        rc = SSH_PACKET_ALLOWED;
  425|    657|        break;
  426|      0|    case SSH2_MSG_KEX_DH_GEX_INIT:                    // 32
  ------------------
  |  |   24|      0|#define SSH2_MSG_KEX_DH_GEX_INIT 32
  ------------------
  |  Branch (426:5): [True: 0, False: 11.1k]
  ------------------
  427|       |      // SSH2_MSG_KEXGSS_COMPLETE:                    // 32
  428|      0|        if (ssh_kex_is_gss(session->next_crypto)) {
  ------------------
  |  Branch (428:13): [True: 0, False: 0]
  ------------------
  429|       |            /* SSH2_MSG_KEXGSS_COMPLETE */
  430|       |            /* Client only */
  431|       |
  432|       |            /*
  433|       |             * States required:
  434|       |             * - session_state == SSH_SESSION_STATE_DH
  435|       |             * - dh_handshake_state == DH_STATE_INIT_SENT
  436|       |             *
  437|       |             * Transitions:
  438|       |             * - session->dh_handshake_state = DH_STATE_INIT_SENT
  439|       |             * then calls ssh_packet_client_gss_kex_reply which triggers:
  440|       |             * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  441|       |             * */
  442|       |
  443|      0|            if (!session->client) {
  ------------------
  |  Branch (443:17): [True: 0, False: 0]
  ------------------
  444|      0|                rc = SSH_PACKET_DENIED;
  445|      0|                break;
  446|      0|            }
  447|       |
  448|      0|            if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (448:17): [True: 0, False: 0]
  ------------------
  449|      0|                rc = SSH_PACKET_DENIED;
  450|      0|                break;
  451|      0|            }
  452|       |
  453|      0|            if (session->dh_handshake_state != DH_STATE_INIT_SENT) {
  ------------------
  |  Branch (453:17): [True: 0, False: 0]
  ------------------
  454|      0|                rc = SSH_PACKET_DENIED;
  455|      0|                break;
  456|      0|            }
  457|      0|        } else {
  458|       |            /* SSH2_MSG_KEX_DH_GEX_INIT */
  459|       |            /* Server only */
  460|       |
  461|       |            /*
  462|       |             * States required:
  463|       |             * - session_state == SSH_SESSION_STATE_DH
  464|       |             * - dh_handshake_state == DH_STATE_GROUP_SENT
  465|       |             *
  466|       |             * Transitions:
  467|       |             * - session->dh_handshake_state = DH_STATE_GROUP_SENT
  468|       |             * then calls ssh_packet_server_dhgex_init which triggers:
  469|       |             * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  470|       |             * */
  471|       |
  472|      0|            if (session->client) {
  ------------------
  |  Branch (472:17): [True: 0, False: 0]
  ------------------
  473|      0|                rc = SSH_PACKET_DENIED;
  474|      0|                break;
  475|      0|            }
  476|       |
  477|      0|            if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (477:17): [True: 0, False: 0]
  ------------------
  478|      0|                rc = SSH_PACKET_DENIED;
  479|      0|                break;
  480|      0|            }
  481|       |
  482|       |            /* Only allowed if dh_handshake_state is in initial state */
  483|      0|            if (session->dh_handshake_state != DH_STATE_GROUP_SENT) {
  ------------------
  |  Branch (483:17): [True: 0, False: 0]
  ------------------
  484|      0|                rc = SSH_PACKET_DENIED;
  485|      0|                break;
  486|      0|            }
  487|      0|        }
  488|      0|        rc = SSH_PACKET_ALLOWED;
  489|      0|        break;
  490|      0|    case SSH2_MSG_KEX_DH_GEX_REPLY:                   // 33
  ------------------
  |  |   25|      0|#define SSH2_MSG_KEX_DH_GEX_REPLY 33
  ------------------
  |  Branch (490:5): [True: 0, False: 11.1k]
  ------------------
  491|       |
  492|       |        /* Client only */
  493|       |
  494|       |        /*
  495|       |         * States required:
  496|       |         * - session_state == SSH_SESSION_STATE_DH
  497|       |         * - dh_handshake_state == DH_STATE_INIT_SENT
  498|       |         *
  499|       |         * Transitions:
  500|       |         * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  501|       |         * */
  502|       |
  503|      0|        if (session->server) {
  ------------------
  |  Branch (503:13): [True: 0, False: 0]
  ------------------
  504|      0|            rc = SSH_PACKET_DENIED;
  505|      0|            break;
  506|      0|        }
  507|       |
  508|      0|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (508:13): [True: 0, False: 0]
  ------------------
  509|      0|            rc = SSH_PACKET_DENIED;
  510|      0|            break;
  511|      0|        }
  512|       |
  513|      0|        if (session->dh_handshake_state != DH_STATE_INIT_SENT) {
  ------------------
  |  Branch (513:13): [True: 0, False: 0]
  ------------------
  514|      0|            rc = SSH_PACKET_DENIED;
  515|      0|            break;
  516|      0|        }
  517|       |
  518|      0|        rc = SSH_PACKET_ALLOWED;
  519|      0|        break;
  520|      0|    case SSH2_MSG_KEX_DH_GEX_REQUEST:                 // 34
  ------------------
  |  |   26|      0|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (520:5): [True: 0, False: 11.1k]
  ------------------
  521|       |
  522|       |        /* Server only */
  523|       |
  524|       |        /*
  525|       |         * States required:
  526|       |         * - session_state == SSH_SESSION_STATE_DH
  527|       |         * - dh_handshake_state == DH_STATE_INIT
  528|       |         *
  529|       |         * Transitions:
  530|       |         * - session->dh_handshake_state = DH_STATE_INIT_SENT
  531|       |         * then calls ssh_packet_server_dhgex_request which triggers:
  532|       |         * - session->dh_handshake_state = DH_STATE_GROUP_SENT
  533|       |         * */
  534|       |
  535|      0|        if (session->client) {
  ------------------
  |  Branch (535:13): [True: 0, False: 0]
  ------------------
  536|      0|            rc = SSH_PACKET_DENIED;
  537|      0|            break;
  538|      0|        }
  539|       |
  540|      0|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (540:13): [True: 0, False: 0]
  ------------------
  541|      0|            rc = SSH_PACKET_DENIED;
  542|      0|            break;
  543|      0|        }
  544|       |
  545|       |        /* Only allowed if dh_handshake_state is in initial state */
  546|      0|        if (session->dh_handshake_state != DH_STATE_INIT) {
  ------------------
  |  Branch (546:13): [True: 0, False: 0]
  ------------------
  547|      0|            rc = SSH_PACKET_DENIED;
  548|      0|            break;
  549|      0|        }
  550|       |
  551|      0|        rc = SSH_PACKET_ALLOWED;
  552|      0|        break;
  553|    657|    case SSH2_MSG_USERAUTH_REQUEST:                   // 50
  ------------------
  |  |   36|    657|#define SSH2_MSG_USERAUTH_REQUEST 50
  ------------------
  |  Branch (553:5): [True: 657, False: 10.4k]
  ------------------
  554|       |        /* Server only */
  555|       |
  556|       |        /*
  557|       |         * States required:
  558|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  559|       |         * - dh_handshake_state == DH_STATE_FINISHED
  560|       |         *
  561|       |         * Transitions:
  562|       |         * - if authentication was successful:
  563|       |         *   - session_state = SSH_SESSION_STATE_AUTHENTICATED
  564|       |         * */
  565|       |
  566|       |        /* If this is a client, reject the message */
  567|    657|        if (session->client) {
  ------------------
  |  Branch (567:13): [True: 0, False: 657]
  ------------------
  568|      0|            rc = SSH_PACKET_DENIED;
  569|      0|            break;
  570|      0|        }
  571|       |
  572|    657|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (572:13): [True: 0, False: 657]
  ------------------
  573|      0|            rc = SSH_PACKET_DENIED;
  574|      0|            break;
  575|      0|        }
  576|       |
  577|    657|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (577:13): [True: 0, False: 657]
  ------------------
  578|      0|            rc = SSH_PACKET_DENIED;
  579|      0|            break;
  580|      0|        }
  581|       |
  582|    657|        rc = SSH_PACKET_ALLOWED;
  583|    657|        break;
  584|      0|    case SSH2_MSG_USERAUTH_FAILURE:                   // 51
  ------------------
  |  |   37|      0|#define SSH2_MSG_USERAUTH_FAILURE 51
  ------------------
  |  Branch (584:5): [True: 0, False: 11.1k]
  ------------------
  585|       |        /*
  586|       |         * States required:
  587|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  588|       |         * - dh_handshake_state == DH_STATE_FINISHED
  589|       |         * - session->auth.state == SSH_AUTH_STATE_KBDINT_SENT
  590|       |         *   or session->auth.state == SSH_AUTH_STATE_PUBKEY_OFFER_SENT
  591|       |         *   or session->auth.state == SSH_AUTH_STATE_PUBKEY_AUTH_SENT
  592|       |         *   or session->auth.state == SSH_AUTH_STATE_PASSWORD_AUTH_SENT
  593|       |         *   or session->auth.state == SSH_AUTH_STATE_GSSAPI_MIC_SENT
  594|       |         *
  595|       |         * Transitions:
  596|       |         * - if unpacking failed:
  597|       |         *   - session->auth.state = SSH_AUTH_ERROR
  598|       |         * - if failure was partial:
  599|       |         *   - session->auth.state = SSH_AUTH_PARTIAL
  600|       |         * - else:
  601|       |         *   - session->auth.state = SSH_AUTH_STATE_FAILED
  602|       |         * */
  603|       |
  604|       |        /* If this is a server, reject the message */
  605|      0|        if (session->server) {
  ------------------
  |  Branch (605:13): [True: 0, False: 0]
  ------------------
  606|      0|            rc = SSH_PACKET_DENIED;
  607|      0|            break;
  608|      0|        }
  609|       |
  610|      0|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (610:13): [True: 0, False: 0]
  ------------------
  611|      0|            rc = SSH_PACKET_DENIED;
  612|      0|            break;
  613|      0|        }
  614|       |
  615|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (615:13): [True: 0, False: 0]
  ------------------
  616|      0|            rc = SSH_PACKET_DENIED;
  617|      0|            break;
  618|      0|        }
  619|       |
  620|      0|        rc = SSH_PACKET_ALLOWED;
  621|      0|        break;
  622|    657|    case SSH2_MSG_USERAUTH_SUCCESS:                   // 52
  ------------------
  |  |   38|    657|#define SSH2_MSG_USERAUTH_SUCCESS 52
  ------------------
  |  Branch (622:5): [True: 657, False: 10.4k]
  ------------------
  623|       |        /*
  624|       |         * States required:
  625|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  626|       |         * - dh_handshake_state == DH_STATE_FINISHED
  627|       |         * - session->auth.state == SSH_AUTH_STATE_KBDINT_SENT
  628|       |         *   or session->auth.state == SSH_AUTH_STATE_PUBKEY_AUTH_SENT
  629|       |         *   or session->auth.state == SSH_AUTH_STATE_PASSWORD_AUTH_SENT
  630|       |         *   or session->auth.state == SSH_AUTH_STATE_GSSAPI_MIC_SENT
  631|       |         *   or session->auth.state == SSH_AUTH_STATE_GSSAPI_KEYEX_MIC_SENT
  632|       |         *   or session->auth.state == SSH_AUTH_STATE_AUTH_NONE_SENT
  633|       |         *
  634|       |         * Transitions:
  635|       |         * - session->auth.state = SSH_AUTH_STATE_SUCCESS
  636|       |         * - session->session_state = SSH_SESSION_STATE_AUTHENTICATED
  637|       |         * - session->flags |= SSH_SESSION_FLAG_AUTHENTICATED
  638|       |         * - sessions->auth.current_method = SSH_AUTH_METHOD_UNKNOWN
  639|       |         * */
  640|       |
  641|       |        /* If this is a server, reject the message */
  642|    657|        if (session->server) {
  ------------------
  |  Branch (642:13): [True: 0, False: 657]
  ------------------
  643|      0|            rc = SSH_PACKET_DENIED;
  644|      0|            break;
  645|      0|        }
  646|       |
  647|    657|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (647:13): [True: 0, False: 657]
  ------------------
  648|      0|            rc = SSH_PACKET_DENIED;
  649|      0|            break;
  650|      0|        }
  651|       |
  652|    657|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (652:13): [True: 0, False: 657]
  ------------------
  653|      0|            rc = SSH_PACKET_DENIED;
  654|      0|            break;
  655|      0|        }
  656|       |
  657|    657|        if ((session->auth.state != SSH_AUTH_STATE_KBDINT_SENT) &&
  ------------------
  |  Branch (657:13): [True: 657, False: 0]
  ------------------
  658|    657|            (session->auth.state != SSH_AUTH_STATE_PUBKEY_AUTH_SENT) &&
  ------------------
  |  Branch (658:13): [True: 657, False: 0]
  ------------------
  659|    657|            (session->auth.state != SSH_AUTH_STATE_PASSWORD_AUTH_SENT) &&
  ------------------
  |  Branch (659:13): [True: 657, False: 0]
  ------------------
  660|    657|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_MIC_SENT) &&
  ------------------
  |  Branch (660:13): [True: 657, False: 0]
  ------------------
  661|    657|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_KEYEX_MIC_SENT) &&
  ------------------
  |  Branch (661:13): [True: 657, False: 0]
  ------------------
  662|    657|            (session->auth.state != SSH_AUTH_STATE_AUTH_NONE_SENT)) {
  ------------------
  |  Branch (662:13): [True: 0, False: 657]
  ------------------
  663|      0|            rc = SSH_PACKET_DENIED;
  664|      0|            break;
  665|      0|        }
  666|       |
  667|    657|        rc = SSH_PACKET_ALLOWED;
  668|    657|        break;
  669|      0|    case SSH2_MSG_USERAUTH_BANNER:                    // 53
  ------------------
  |  |   39|      0|#define SSH2_MSG_USERAUTH_BANNER 53
  ------------------
  |  Branch (669:5): [True: 0, False: 11.1k]
  ------------------
  670|       |        /*
  671|       |         * States required:
  672|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  673|       |         *
  674|       |         * Transitions:
  675|       |         * - None
  676|       |         * */
  677|       |
  678|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (678:13): [True: 0, False: 0]
  ------------------
  679|      0|            rc = SSH_PACKET_DENIED;
  680|      0|            break;
  681|      0|        }
  682|       |
  683|      0|        rc = SSH_PACKET_ALLOWED;
  684|      0|        break;
  685|      0|    case SSH2_MSG_USERAUTH_PK_OK:                     // 60
  ------------------
  |  |   40|      0|#define SSH2_MSG_USERAUTH_PK_OK 60
  ------------------
  |  Branch (685:5): [True: 0, False: 11.1k]
  ------------------
  686|       |      // SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ:          // 60
  687|       |      // SSH2_MSG_USERAUTH_INFO_REQUEST:              // 60
  688|       |      // SSH2_MSG_USERAUTH_GSSAPI_RESPONSE:           // 60
  689|       |
  690|       |        /*
  691|       |         * States required:
  692|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  693|       |         * - session->auth.state == SSH_AUTH_STATE_KBDINT_SENT
  694|       |         *   or
  695|       |         *   session->auth.state == SSH_AUTH_STATE_GSSAPI_REQUEST_SENT
  696|       |         *   or
  697|       |         *   session->auth.state == SSH_AUTH_STATE_PUBKEY_OFFER_SENT
  698|       |         *
  699|       |         * Transitions:
  700|       |         * Depending on the current state, the message is treated
  701|       |         * differently:
  702|       |         * - session->auth.state == SSH_AUTH_STATE_KBDINT_SENT
  703|       |         *   - session->auth.state = SSH_AUTH_STATE_INFO
  704|       |         * - session->auth.state == SSH_AUTH_STATE_GSSAPI_REQUEST_SENT
  705|       |         *   - session->auth.state = SSH_AUTH_STATE_GSSAPI_TOKEN
  706|       |         * - session->auth.state == SSH_AUTH_STATE_PUBKEY_OFFER_SENT
  707|       |         *   - session->auth.state = SSH_AUTH_STATE_PK_OK
  708|       |         * */
  709|       |
  710|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (710:13): [True: 0, False: 0]
  ------------------
  711|      0|            rc = SSH_PACKET_DENIED;
  712|      0|            break;
  713|      0|        }
  714|       |
  715|      0|        if ((session->auth.state != SSH_AUTH_STATE_KBDINT_SENT) &&
  ------------------
  |  Branch (715:13): [True: 0, False: 0]
  ------------------
  716|      0|            (session->auth.state != SSH_AUTH_STATE_PUBKEY_OFFER_SENT) &&
  ------------------
  |  Branch (716:13): [True: 0, False: 0]
  ------------------
  717|      0|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_REQUEST_SENT))
  ------------------
  |  Branch (717:13): [True: 0, False: 0]
  ------------------
  718|      0|        {
  719|      0|            rc = SSH_PACKET_DENIED;
  720|      0|            break;
  721|      0|        }
  722|       |
  723|      0|        rc = SSH_PACKET_ALLOWED;
  724|      0|        break;
  725|      0|    case SSH2_MSG_USERAUTH_INFO_RESPONSE:             // 61
  ------------------
  |  |   44|      0|#define SSH2_MSG_USERAUTH_INFO_RESPONSE 61
  ------------------
  |  Branch (725:5): [True: 0, False: 11.1k]
  ------------------
  726|       |      // SSH2_MSG_USERAUTH_GSSAPI_TOKEN:              // 61
  727|       |
  728|       |        /*
  729|       |         * States required:
  730|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  731|       |         * - session_state->auth.state == SSH_SESSION_STATE_GSSAPI_TOKEN
  732|       |         *   or
  733|       |         *   session_state->auth.state == SSH_SESSION_STATE_INFO
  734|       |         *
  735|       |         * Transitions:
  736|       |         * - None
  737|       |         * */
  738|       |
  739|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (739:13): [True: 0, False: 0]
  ------------------
  740|      0|            rc = SSH_PACKET_DENIED;
  741|      0|            break;
  742|      0|        }
  743|       |
  744|      0|        if ((session->auth.state != SSH_AUTH_STATE_INFO) &&
  ------------------
  |  Branch (744:13): [True: 0, False: 0]
  ------------------
  745|      0|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_TOKEN))
  ------------------
  |  Branch (745:13): [True: 0, False: 0]
  ------------------
  746|      0|        {
  747|      0|            rc = SSH_PACKET_DENIED;
  748|      0|            break;
  749|      0|        }
  750|       |
  751|      0|        rc = SSH_PACKET_ALLOWED;
  752|      0|        break;
  753|      0|    case SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE:  // 63
  ------------------
  |  |   46|      0|#define SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE 63
  ------------------
  |  Branch (753:5): [True: 0, False: 11.1k]
  ------------------
  754|       |        /* Server only */
  755|       |        /*
  756|       |         * States required:
  757|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  758|       |         * - session->gssapi->state == SSH_GSSAPI_STATE_RCV_MIC
  759|       |         *
  760|       |         * Transitions:
  761|       |         * - None
  762|       |         */
  763|       |#ifdef WITH_GSSAPI
  764|       |        if (session->client) {
  765|       |            rc = SSH_PACKET_DENIED;
  766|       |            break;
  767|       |        }
  768|       |        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  769|       |            rc = SSH_PACKET_DENIED;
  770|       |            break;
  771|       |        }
  772|       |        if (session->gssapi == NULL) {
  773|       |            rc = SSH_PACKET_DENIED;
  774|       |            break;
  775|       |        }
  776|       |        if (session->gssapi->state != SSH_GSSAPI_STATE_RCV_MIC) {
  777|       |            rc = SSH_PACKET_DENIED;
  778|       |            break;
  779|       |        }
  780|       |        rc = SSH_PACKET_ALLOWED;
  781|       |        break;
  782|       |#else
  783|      0|        rc = SSH_PACKET_DENIED;
  784|      0|        break;
  785|      0|#endif  /* WITH_GSSAPI */
  786|      0|    case SSH2_MSG_USERAUTH_GSSAPI_ERROR:              // 64
  ------------------
  |  |   47|      0|#define SSH2_MSG_USERAUTH_GSSAPI_ERROR 64
  ------------------
  |  Branch (786:5): [True: 0, False: 11.1k]
  ------------------
  787|       |        /* Client only */
  788|       |        /*
  789|       |         * States required:
  790|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  791|       |         *
  792|       |         * Transitions:
  793|       |         * - None
  794|       |         */
  795|       |#ifdef WITH_GSSAPI
  796|       |        if (session->server) {
  797|       |            rc = SSH_PACKET_DENIED;
  798|       |            break;
  799|       |        }
  800|       |        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  801|       |            rc = SSH_PACKET_DENIED;
  802|       |            break;
  803|       |        }
  804|       |
  805|       |        rc = SSH_PACKET_ALLOWED;
  806|       |        break;
  807|       |#else
  808|      0|        rc = SSH_PACKET_DENIED;
  809|      0|        break;
  810|      0|#endif  /* WITH_GSSAPI */
  811|      0|    case SSH2_MSG_USERAUTH_GSSAPI_ERRTOK:             // 65
  ------------------
  |  |   48|      0|#define SSH2_MSG_USERAUTH_GSSAPI_ERRTOK 65
  ------------------
  |  Branch (811:5): [True: 0, False: 11.1k]
  ------------------
  812|       |        /*
  813|       |         * States required:
  814|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  815|       |         *
  816|       |         * Transitions:
  817|       |         * - None
  818|       |         */
  819|       |#ifdef WITH_GSSAPI
  820|       |        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  821|       |            rc = SSH_PACKET_DENIED;
  822|       |            break;
  823|       |        }
  824|       |
  825|       |        rc = SSH_PACKET_ALLOWED;
  826|       |        break;
  827|       |#else
  828|      0|        rc = SSH_PACKET_DENIED;
  829|      0|        break;
  830|      0|#endif  /* WITH_GSSAPI */
  831|      0|    case SSH2_MSG_USERAUTH_GSSAPI_MIC:                // 66
  ------------------
  |  |   49|      0|#define SSH2_MSG_USERAUTH_GSSAPI_MIC 66
  ------------------
  |  Branch (831:5): [True: 0, False: 11.1k]
  ------------------
  832|       |        /* Server only */
  833|       |
  834|       |        /*
  835|       |         * States required:
  836|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  837|       |         * - session->gssapi->state == SSH_GSSAPI_STATE_RCV_MIC
  838|       |         *
  839|       |         * Transitions:
  840|       |         * Depending on the result of the verification, the states are
  841|       |         * changed:
  842|       |         * - SSH_AUTH_SUCCESS:
  843|       |         *   - session->session_state = SSH_SESSION_STATE_AUTHENTICATED
  844|       |         *   - session->flags != SSH_SESSION_FLAG_AUTHENTICATED
  845|       |         * - SSH_AUTH_PARTIAL:
  846|       |         *   - None
  847|       |         * - any other case:
  848|       |         *   - None
  849|       |         * */
  850|       |#ifdef WITH_GSSAPI
  851|       |        /* If this is a client, reject the message */
  852|       |        if (session->client) {
  853|       |            rc = SSH_PACKET_DENIED;
  854|       |            break;
  855|       |        }
  856|       |
  857|       |        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  858|       |            rc = SSH_PACKET_DENIED;
  859|       |            break;
  860|       |        }
  861|       |
  862|       |        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  863|       |            rc = SSH_PACKET_DENIED;
  864|       |            break;
  865|       |        }
  866|       |
  867|       |        rc = SSH_PACKET_ALLOWED;
  868|       |        break;
  869|       |#else
  870|      0|        rc = SSH_PACKET_DENIED;
  871|      0|        break;
  872|      0|#endif  /* WITH_GSSAPI */
  873|      0|    case SSH2_MSG_GLOBAL_REQUEST:                     // 80
  ------------------
  |  |   51|      0|#define SSH2_MSG_GLOBAL_REQUEST 80
  ------------------
  |  Branch (873:5): [True: 0, False: 11.1k]
  ------------------
  874|       |        /*
  875|       |         * States required:
  876|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  877|       |         *
  878|       |         * Transitions:
  879|       |         * - None
  880|       |         * */
  881|       |
  882|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (882:13): [True: 0, False: 0]
  ------------------
  883|      0|            rc = SSH_PACKET_DENIED;
  884|      0|            break;
  885|      0|        }
  886|       |
  887|      0|        rc = SSH_PACKET_ALLOWED;
  888|      0|        break;
  889|      0|    case SSH2_MSG_REQUEST_SUCCESS:                    // 81
  ------------------
  |  |   52|      0|#define SSH2_MSG_REQUEST_SUCCESS 81
  ------------------
  |  Branch (889:5): [True: 0, False: 11.1k]
  ------------------
  890|       |        /*
  891|       |         * States required:
  892|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  893|       |         *
  894|       |         * Transitions:
  895|       |         * - From channel->request_state == SSH_CHANNEL_REQ_STATE_PENDING
  896|       |         * - To   channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED
  897|       |         *
  898|       |         * If not in a pending state, message is ignored in the callback handler.
  899|       |         * */
  900|       |
  901|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (901:13): [True: 0, False: 0]
  ------------------
  902|      0|            rc = SSH_PACKET_DENIED;
  903|      0|            break;
  904|      0|        }
  905|       |
  906|      0|        rc = SSH_PACKET_ALLOWED;
  907|      0|        break;
  908|      0|    case SSH2_MSG_REQUEST_FAILURE:                    // 82
  ------------------
  |  |   53|      0|#define SSH2_MSG_REQUEST_FAILURE 82
  ------------------
  |  Branch (908:5): [True: 0, False: 11.1k]
  ------------------
  909|       |        /*
  910|       |         * States required:
  911|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  912|       |         *
  913|       |         * Transitions:
  914|       |         * - From channel->request_state == SSH_CHANNEL_REQ_STATE_PENDING
  915|       |         * - To   channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED
  916|       |         *
  917|       |         * If not in a pending state, message is ignored in the callback handler.
  918|       |         * */
  919|       |
  920|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (920:13): [True: 0, False: 0]
  ------------------
  921|      0|            rc = SSH_PACKET_DENIED;
  922|      0|            break;
  923|      0|        }
  924|       |
  925|      0|        rc = SSH_PACKET_ALLOWED;
  926|      0|        break;
  927|    657|    case SSH2_MSG_CHANNEL_OPEN:                       // 90
  ------------------
  |  |   54|    657|#define SSH2_MSG_CHANNEL_OPEN 90
  ------------------
  |  Branch (927:5): [True: 657, False: 10.4k]
  ------------------
  928|       |        /*
  929|       |         * States required:
  930|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  931|       |         *
  932|       |         * Transitions:
  933|       |         * - None
  934|       |         * */
  935|       |
  936|    657|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (936:13): [True: 0, False: 657]
  ------------------
  937|      0|            rc = SSH_PACKET_DENIED;
  938|      0|            break;
  939|      0|        }
  940|       |
  941|    657|        rc = SSH_PACKET_ALLOWED;
  942|    657|        break;
  943|    657|    case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION:          // 91
  ------------------
  |  |   55|    657|#define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
  ------------------
  |  Branch (943:5): [True: 657, False: 10.4k]
  ------------------
  944|       |        /*
  945|       |         * States required:
  946|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  947|       |         *
  948|       |         * Transitions:
  949|       |         * - channel->state = SSH_CHANNEL_STATE_OPEN
  950|       |         * - channel->flags &= ~SSH_CHANNEL_FLAG_NOT_BOUND
  951|       |         * */
  952|       |
  953|    657|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (953:13): [True: 0, False: 657]
  ------------------
  954|      0|            rc = SSH_PACKET_DENIED;
  955|      0|            break;
  956|      0|        }
  957|       |
  958|    657|        rc = SSH_PACKET_ALLOWED;
  959|    657|        break;
  960|      0|    case SSH2_MSG_CHANNEL_OPEN_FAILURE:               // 92
  ------------------
  |  |   56|      0|#define SSH2_MSG_CHANNEL_OPEN_FAILURE 92
  ------------------
  |  Branch (960:5): [True: 0, False: 11.1k]
  ------------------
  961|       |        /*
  962|       |         * States required:
  963|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  964|       |         *
  965|       |         * Transitions:
  966|       |         * - channel->state = SSH_CHANNEL_STATE_OPEN_DENIED
  967|       |         * */
  968|       |
  969|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (969:13): [True: 0, False: 0]
  ------------------
  970|      0|            rc = SSH_PACKET_DENIED;
  971|      0|            break;
  972|      0|        }
  973|       |
  974|      0|        rc = SSH_PACKET_ALLOWED;
  975|      0|        break;
  976|      0|    case SSH2_MSG_CHANNEL_WINDOW_ADJUST:              // 93
  ------------------
  |  |   57|      0|#define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93
  ------------------
  |  Branch (976:5): [True: 0, False: 11.1k]
  ------------------
  977|       |        /*
  978|       |         * States required:
  979|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  980|       |         *
  981|       |         * Transitions:
  982|       |         * - None
  983|       |         * */
  984|       |
  985|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (985:13): [True: 0, False: 0]
  ------------------
  986|      0|            rc = SSH_PACKET_DENIED;
  987|      0|            break;
  988|      0|        }
  989|       |
  990|      0|        rc = SSH_PACKET_ALLOWED;
  991|      0|        break;
  992|    657|    case SSH2_MSG_CHANNEL_DATA:                       // 94
  ------------------
  |  |   58|    657|#define SSH2_MSG_CHANNEL_DATA 94
  ------------------
  |  Branch (992:5): [True: 657, False: 10.4k]
  ------------------
  993|       |        /*
  994|       |         * States required:
  995|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  996|       |         *
  997|       |         * Transitions:
  998|       |         * - None
  999|       |         * */
 1000|       |
 1001|    657|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1001:13): [True: 0, False: 657]
  ------------------
 1002|      0|            rc = SSH_PACKET_DENIED;
 1003|      0|            break;
 1004|      0|        }
 1005|       |
 1006|    657|        rc = SSH_PACKET_ALLOWED;
 1007|    657|        break;
 1008|      0|    case SSH2_MSG_CHANNEL_EXTENDED_DATA:              // 95
  ------------------
  |  |   59|      0|#define SSH2_MSG_CHANNEL_EXTENDED_DATA 95
  ------------------
  |  Branch (1008:5): [True: 0, False: 11.1k]
  ------------------
 1009|       |        /*
 1010|       |         * States required:
 1011|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1012|       |         *
 1013|       |         * Transitions:
 1014|       |         * - None
 1015|       |         * */
 1016|       |
 1017|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1017:13): [True: 0, False: 0]
  ------------------
 1018|      0|            rc = SSH_PACKET_DENIED;
 1019|      0|            break;
 1020|      0|        }
 1021|       |
 1022|      0|        rc = SSH_PACKET_ALLOWED;
 1023|      0|        break;
 1024|    657|    case SSH2_MSG_CHANNEL_EOF:                        // 96
  ------------------
  |  |   60|    657|#define SSH2_MSG_CHANNEL_EOF	96
  ------------------
  |  Branch (1024:5): [True: 657, False: 10.4k]
  ------------------
 1025|       |        /*
 1026|       |         * States required:
 1027|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1028|       |         *
 1029|       |         * Transitions:
 1030|       |         * - None
 1031|       |         * */
 1032|       |
 1033|    657|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1033:13): [True: 0, False: 657]
  ------------------
 1034|      0|            rc = SSH_PACKET_DENIED;
 1035|      0|            break;
 1036|      0|        }
 1037|       |
 1038|    657|        rc = SSH_PACKET_ALLOWED;
 1039|    657|        break;
 1040|    657|    case SSH2_MSG_CHANNEL_CLOSE:                      // 97
  ------------------
  |  |   61|    657|#define SSH2_MSG_CHANNEL_CLOSE 97
  ------------------
  |  Branch (1040:5): [True: 657, False: 10.4k]
  ------------------
 1041|       |        /*
 1042|       |         * States required:
 1043|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1044|       |         *
 1045|       |         * Transitions:
 1046|       |         * - channel->state = SSH_CHANNEL_STATE_CLOSED
 1047|       |         * - channel->flags |= SSH_CHANNEL_FLAG_CLOSED_REMOTE
 1048|       |         * */
 1049|       |
 1050|    657|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1050:13): [True: 0, False: 657]
  ------------------
 1051|      0|            rc = SSH_PACKET_DENIED;
 1052|      0|            break;
 1053|      0|        }
 1054|       |
 1055|    657|        rc = SSH_PACKET_ALLOWED;
 1056|    657|        break;
 1057|    657|    case SSH2_MSG_CHANNEL_REQUEST:                    // 98
  ------------------
  |  |   62|    657|#define SSH2_MSG_CHANNEL_REQUEST 98
  ------------------
  |  Branch (1057:5): [True: 657, False: 10.4k]
  ------------------
 1058|       |        /*
 1059|       |         * States required:
 1060|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1061|       |         *
 1062|       |         * Transitions:
 1063|       |         * - Depends on the request
 1064|       |         * */
 1065|       |
 1066|    657|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1066:13): [True: 0, False: 657]
  ------------------
 1067|      0|            rc = SSH_PACKET_DENIED;
 1068|      0|            break;
 1069|      0|        }
 1070|       |
 1071|    657|        rc = SSH_PACKET_ALLOWED;
 1072|    657|        break;
 1073|      1|    case SSH2_MSG_CHANNEL_SUCCESS:                    // 99
  ------------------
  |  |   63|      1|#define SSH2_MSG_CHANNEL_SUCCESS 99
  ------------------
  |  Branch (1073:5): [True: 1, False: 11.1k]
  ------------------
 1074|       |        /*
 1075|       |         * States required:
 1076|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1077|       |         *
 1078|       |         * Transitions:
 1079|       |         * - From channel->request_state == SSH_CHANNEL_REQ_STATE_PENDING
 1080|       |         * - To   channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED
 1081|       |         *
 1082|       |         * If not in a pending state, message is ignored in the callback handler.
 1083|       |         * */
 1084|       |
 1085|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1085:13): [True: 0, False: 1]
  ------------------
 1086|      0|            rc = SSH_PACKET_DENIED;
 1087|      0|            break;
 1088|      0|        }
 1089|       |
 1090|      1|        rc = SSH_PACKET_ALLOWED;
 1091|      1|        break;
 1092|      0|    case SSH2_MSG_CHANNEL_FAILURE:                    // 100
  ------------------
  |  |   64|      0|#define SSH2_MSG_CHANNEL_FAILURE 100
  ------------------
  |  Branch (1092:5): [True: 0, False: 11.1k]
  ------------------
 1093|       |        /*
 1094|       |         * States required:
 1095|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1096|       |         *
 1097|       |         * Transitions:
 1098|       |         * - From channel->request_state == SSH_CHANNEL_REQ_STATE_PENDING
 1099|       |         * - To   channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED
 1100|       |         *
 1101|       |         * If not in a pending state, message is ignored in the callback handler.
 1102|       |         * */
 1103|       |
 1104|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1104:13): [True: 0, False: 0]
  ------------------
 1105|      0|            rc = SSH_PACKET_DENIED;
 1106|      0|            break;
 1107|      0|        }
 1108|       |
 1109|      0|        rc = SSH_PACKET_ALLOWED;
 1110|      0|        break;
 1111|      0|    case SSH2_MSG_PING: // 192
  ------------------
  |  |   69|      0|#define SSH2_MSG_PING 192
  ------------------
  |  Branch (1111:5): [True: 0, False: 11.1k]
  ------------------
 1112|      0|    case SSH2_MSG_PONG: // 193
  ------------------
  |  |   70|      0|#define SSH2_MSG_PONG 193
  ------------------
  |  Branch (1112:5): [True: 0, False: 11.1k]
  ------------------
 1113|       |        /*
 1114|       |         * Transport-level ping/pong messages.
 1115|       |         *
 1116|       |         * Always allow PING and PONG messages through the filter.
 1117|       |         * State checking (auth/rekey) is handled in the packet handler itself,
 1118|       |         * following OpenSSH's approach of treating these as implicit
 1119|       |         * transport-level messages (like IGNORE and DEBUG).
 1120|       |         *
 1121|       |         * States required:
 1122|       |         * - None (always allowed)
 1123|       |         *
 1124|       |         * Transitions:
 1125|       |         * - None
 1126|       |         */
 1127|      0|        rc = SSH_PACKET_ALLOWED;
 1128|      0|        break;
 1129|      0|    default:
  ------------------
  |  Branch (1129:5): [True: 0, False: 11.1k]
  ------------------
 1130|       |        /* Unknown message, do not filter */
 1131|      0|        rc = SSH_PACKET_UNKNOWN;
 1132|      0|        goto end;
 1133|  11.1k|    }
 1134|       |
 1135|  11.1k|end:
 1136|       |#ifdef DEBUG_PACKET
 1137|       |    if (rc == SSH_PACKET_DENIED) {
 1138|       |        SSH_LOG(SSH_LOG_PACKET, "REJECTED packet type %d: ",
 1139|       |                session->in_packet.type);
 1140|       |    }
 1141|       |
 1142|       |    if (rc == SSH_PACKET_UNKNOWN) {
 1143|       |        SSH_LOG(SSH_LOG_PACKET, "UNKNOWN packet type %d",
 1144|       |                session->in_packet.type);
 1145|       |    }
 1146|       |#endif
 1147|       |
 1148|  11.1k|    return rc;
 1149|  11.1k|}
packet.c:ssh_packet_need_rekey:
 1201|  24.2k|{
 1202|  24.2k|    bool data_rekey_needed = false;
 1203|  24.2k|    struct ssh_crypto_struct *crypto = NULL;
 1204|  24.2k|    struct ssh_cipher_struct *out_cipher = NULL, *in_cipher = NULL;
 1205|  24.2k|    uint32_t next_blocks;
 1206|       |
 1207|       |    /* We can safely rekey only in authenticated state */
 1208|  24.2k|    if ((session->flags & SSH_SESSION_FLAG_AUTHENTICATED) == 0) {
  ------------------
  |  |   78|  24.2k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (1208:9): [True: 13.1k, False: 11.1k]
  ------------------
 1209|  13.1k|        return false;
 1210|  13.1k|    }
 1211|       |
 1212|       |    /* Do not rekey if the rekey/key-exchange is in progress */
 1213|  11.1k|    if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (1213:9): [True: 0, False: 11.1k]
  ------------------
 1214|      0|        return false;
 1215|      0|    }
 1216|       |
 1217|  11.1k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_BOTH);
 1218|  11.1k|    if (crypto == NULL) {
  ------------------
  |  Branch (1218:9): [True: 0, False: 11.1k]
  ------------------
 1219|      0|        return false;
 1220|      0|    }
 1221|       |
 1222|  11.1k|    out_cipher = crypto->out_cipher;
 1223|  11.1k|    in_cipher = crypto->in_cipher;
 1224|       |
 1225|       |    /* Make sure we can send at least something for very small limits */
 1226|  11.1k|    if ((out_cipher->packets == 0) && (in_cipher->packets == 0)) {
  ------------------
  |  Branch (1226:9): [True: 0, False: 11.1k]
  |  Branch (1226:39): [True: 0, False: 0]
  ------------------
 1227|      0|        return false;
 1228|      0|    }
 1229|       |
 1230|       |    /* Time based rekeying */
 1231|  11.1k|    if (session->opts.rekey_time != 0 &&
  ------------------
  |  Branch (1231:9): [True: 0, False: 11.1k]
  ------------------
 1232|      0|        ssh_timeout_elapsed(&session->last_rekey_time,
  ------------------
  |  Branch (1232:9): [True: 0, False: 0]
  ------------------
 1233|      0|                            session->opts.rekey_time)) {
 1234|      0|        return true;
 1235|      0|    }
 1236|       |
 1237|       |    /* RFC4344, Section 3.1 Recommends rekeying after 2^31 packets in either
 1238|       |     * direction to avoid possible information leakage through the MAC tag
 1239|       |     */
 1240|  11.1k|    if (out_cipher->packets > MAX_PACKETS ||
  ------------------
  |  | 1197|  22.2k|#define MAX_PACKETS    (1UL<<31)
  ------------------
  |  Branch (1240:9): [True: 6, False: 11.1k]
  ------------------
 1241|  11.1k|        in_cipher->packets > MAX_PACKETS) {
  ------------------
  |  | 1197|  11.1k|#define MAX_PACKETS    (1UL<<31)
  ------------------
  |  Branch (1241:9): [True: 0, False: 11.1k]
  ------------------
 1242|      0|        return true;
 1243|      0|    }
 1244|       |
 1245|       |    /* Data-based rekeying:
 1246|       |     *  * For outgoing packets we can still delay them
 1247|       |     *  * Incoming packets need to be processed anyway, but we can
 1248|       |     *    signalize our intention to rekey
 1249|       |     */
 1250|  11.1k|    next_blocks = payloadsize / out_cipher->blocksize;
 1251|  11.1k|    data_rekey_needed = (out_cipher->max_blocks != 0 &&
  ------------------
  |  Branch (1251:26): [True: 11.1k, False: 7]
  ------------------
 1252|  11.1k|                         out_cipher->blocks + next_blocks > out_cipher->max_blocks) ||
  ------------------
  |  Branch (1252:26): [True: 0, False: 11.1k]
  ------------------
 1253|  11.1k|                         (in_cipher->max_blocks != 0 &&
  ------------------
  |  Branch (1253:27): [True: 11.1k, False: 1]
  ------------------
 1254|  11.1k|                         in_cipher->blocks + next_blocks > in_cipher->max_blocks);
  ------------------
  |  Branch (1254:26): [True: 0, False: 11.1k]
  ------------------
 1255|       |
 1256|  11.1k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  11.1k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1257|  11.1k|            "rekey: [data_rekey_needed=%d, out_blocks=%" PRIu64 ", in_blocks=%" PRIu64 "]",
 1258|  11.1k|            data_rekey_needed,
 1259|  11.1k|            out_cipher->blocks + next_blocks,
 1260|  11.1k|            in_cipher->blocks + next_blocks);
 1261|       |
 1262|  11.1k|    return data_rekey_needed;
 1263|  11.1k|}
packet.c:ssh_packet_socket_controlflow_callback:
 1653|  7.56k|{
 1654|  7.56k|    ssh_session session = userdata;
 1655|  7.56k|    struct ssh_iterator *it = NULL;
 1656|  7.56k|    ssh_channel channel = NULL;
 1657|       |
 1658|  7.56k|    if (code == SSH_SOCKET_FLOW_WRITEWONTBLOCK) {
  ------------------
  |  |  518|  7.56k|#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
  ------------------
  |  Branch (1658:9): [True: 7.56k, False: 0]
  ------------------
 1659|  7.56k|        SSH_LOG(SSH_LOG_TRACE, "sending channel_write_wontblock callback");
  ------------------
  |  |  281|  7.56k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1660|       |
 1661|       |        /* the out pipe is empty so we can forward this to channels */
 1662|  7.56k|        it = ssh_list_get_iterator(session->channels);
 1663|  9.53k|        while (it != NULL) {
  ------------------
  |  Branch (1663:16): [True: 1.97k, False: 7.56k]
  ------------------
 1664|  1.97k|            channel = ssh_iterator_value(ssh_channel, it);
  ------------------
  |  |  114|  1.97k|  ((type)((iterator)->data))
  ------------------
 1665|       |            ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|  1.97k|    do {                                                      \
  |  |  567|  1.97k|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|  1.97k|        cbtype cb;                                            \
  |  |  569|  2.62k|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 656, False: 1.97k]
  |  |  ------------------
  |  |  570|    656|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  114|    656|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  571|    656|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  547|    656|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|    656|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 656, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 656, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|    656|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 656]
  |  |  |  |  ------------------
  |  |  |  |  550|    656|  )
  |  |  ------------------
  |  |  572|    656|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  573|    656|            i = i->next;                                      \
  |  |  574|    656|        }                                                     \
  |  |  575|  1.97k|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 1.97k]
  |  |  ------------------
  ------------------
 1666|  1.97k|                                       ssh_channel_callbacks,
 1667|  1.97k|                                       channel_write_wontblock_function,
 1668|  1.97k|                                       session,
 1669|  1.97k|                                       channel,
 1670|  1.97k|                                       channel->remote_window);
 1671|  1.97k|            it = it->next;
 1672|  1.97k|        }
 1673|  7.56k|    }
 1674|  7.56k|}
packet.c:ssh_packet_in_rekey:
 2055|  13.1k|{
 2056|       |    /* We know we are rekeying if we are authenticated and the DH
 2057|       |     * status is not finished, but we only queue packets until we've
 2058|       |     * sent our NEWKEYS.
 2059|       |     */
 2060|  13.1k|    return (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) &&
  ------------------
  |  |   78|  13.1k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (2060:12): [True: 5.91k, False: 7.22k]
  ------------------
 2061|  5.91k|           (session->dh_handshake_state != DH_STATE_FINISHED) &&
  ------------------
  |  Branch (2061:12): [True: 0, False: 5.91k]
  ------------------
 2062|      0|           (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT);
  ------------------
  |  Branch (2062:12): [True: 0, False: 0]
  ------------------
 2063|  13.1k|}
packet.c:packet_send2:
 1895|  13.1k|{
 1896|  13.1k|    unsigned int blocksize = 8;
 1897|  13.1k|    unsigned int lenfield_blocksize = 0;
 1898|  13.1k|    enum ssh_hmac_e hmac_type;
 1899|  13.1k|    uint32_t currentlen = ssh_buffer_get_len(session->out_buffer);
 1900|  13.1k|    struct ssh_crypto_struct *crypto = NULL;
 1901|  13.1k|    unsigned char *hmac = NULL;
 1902|  13.1k|    uint8_t padding_data[32] = { 0 };
 1903|  13.1k|    uint8_t padding_size;
 1904|  13.1k|    uint32_t finallen, payloadsize, compsize;
 1905|  13.1k|    uint8_t header[5] = {0};
 1906|  13.1k|    uint8_t type, *payload;
 1907|  13.1k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  13.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1908|  13.1k|    bool etm = false;
 1909|  13.1k|    int etm_packet_offset = 0;
 1910|       |
 1911|  13.1k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
 1912|  13.1k|    if (crypto) {
  ------------------
  |  Branch (1912:9): [True: 9.19k, False: 3.94k]
  ------------------
 1913|  9.19k|        blocksize = crypto->out_cipher->blocksize;
 1914|  9.19k|        lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
 1915|  9.19k|        hmac_type = crypto->out_hmac;
 1916|  9.19k|        etm = crypto->out_hmac_etm;
 1917|  9.19k|    } else {
 1918|  3.94k|        hmac_type = session->next_crypto->out_hmac;
 1919|  3.94k|    }
 1920|       |
 1921|  13.1k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 1922|  13.1k|    type = payload[0]; /* type is the first byte of the packet now */
 1923|       |
 1924|  13.1k|    payloadsize = currentlen;
 1925|  13.1k|    if (etm) {
  ------------------
  |  Branch (1925:9): [True: 0, False: 13.1k]
  ------------------
 1926|      0|        etm_packet_offset = sizeof(uint32_t);
 1927|      0|        lenfield_blocksize = 0;
 1928|      0|    }
 1929|       |
 1930|  13.1k|    if (crypto != NULL && crypto->do_compress_out &&
  ------------------
  |  Branch (1930:9): [True: 9.19k, False: 3.94k]
  |  Branch (1930:27): [True: 0, False: 9.19k]
  ------------------
 1931|      0|        ssh_buffer_get_len(session->out_buffer) > 0) {
  ------------------
  |  Branch (1931:9): [True: 0, False: 0]
  ------------------
 1932|      0|        rc = compress_buffer(session,session->out_buffer);
 1933|      0|        if (rc < 0) {
  ------------------
  |  Branch (1933:13): [True: 0, False: 0]
  ------------------
 1934|      0|            goto error;
 1935|      0|        }
 1936|      0|        currentlen = ssh_buffer_get_len(session->out_buffer);
 1937|      0|    }
 1938|  13.1k|    compsize = currentlen;
 1939|       |    /* compressed payload + packet len (4) + padding_size len (1) */
 1940|       |    /* totallen - lenfield_blocksize - etm_packet_offset must be equal to 0 (mod blocksize) */
 1941|  13.1k|    padding_size = (blocksize - ((blocksize - lenfield_blocksize - etm_packet_offset + currentlen + 5) % blocksize));
 1942|  13.1k|    if (padding_size < 4) {
  ------------------
  |  Branch (1942:9): [True: 3.78k, False: 9.35k]
  ------------------
 1943|  3.78k|        padding_size += blocksize;
 1944|  3.78k|    }
 1945|       |
 1946|  13.1k|    if (crypto != NULL) {
  ------------------
  |  Branch (1946:9): [True: 9.19k, False: 3.94k]
  ------------------
 1947|  9.19k|        int ok;
 1948|       |
 1949|  9.19k|        ok = ssh_get_random(padding_data, padding_size, 0);
 1950|  9.19k|        if (!ok) {
  ------------------
  |  Branch (1950:13): [True: 0, False: 9.19k]
  ------------------
 1951|      0|            ssh_set_error(session, SSH_FATAL, "PRNG error");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1952|      0|            goto error;
 1953|      0|        }
 1954|  9.19k|    }
 1955|       |
 1956|  13.1k|    finallen = currentlen - etm_packet_offset + padding_size + 1;
 1957|       |
 1958|  13.1k|    PUSH_BE_U32(header, 0, finallen);
  ------------------
  |  |   89|  13.1k|    (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|  13.1k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  13.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  13.1k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  13.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  13.1k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|  13.1k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  13.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  13.1k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  13.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  13.1k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1959|  13.1k|    PUSH_BE_U8(header, 4, padding_size);
  ------------------
  |  |   83|  13.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  ------------------
  |  |  |  |   31|  13.1k|    (((uint8_t *)(data))[(pos)])
  |  |  ------------------
  ------------------
 1960|       |
 1961|  13.1k|    rc = ssh_buffer_prepend_data(session->out_buffer,
 1962|  13.1k|                                 header,
 1963|  13.1k|                                 sizeof(header));
 1964|  13.1k|    if (rc < 0) {
  ------------------
  |  Branch (1964:9): [True: 0, False: 13.1k]
  ------------------
 1965|      0|        goto error;
 1966|      0|    }
 1967|       |
 1968|  13.1k|    rc = ssh_buffer_add_data(session->out_buffer, padding_data, padding_size);
 1969|  13.1k|    if (rc < 0) {
  ------------------
  |  Branch (1969:9): [True: 0, False: 13.1k]
  ------------------
 1970|      0|        goto error;
 1971|      0|    }
 1972|       |
 1973|  13.1k|#ifdef WITH_PCAP
 1974|  13.1k|    if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1974:9): [True: 0, False: 13.1k]
  ------------------
 1975|      0|        ssh_pcap_context_write(session->pcap_ctx,
 1976|      0|                               SSH_PCAP_DIR_OUT,
 1977|      0|                               ssh_buffer_get(session->out_buffer),
 1978|      0|                               ssh_buffer_get_len(session->out_buffer),
 1979|      0|                               ssh_buffer_get_len(session->out_buffer));
 1980|      0|    }
 1981|  13.1k|#endif
 1982|       |
 1983|  13.1k|    hmac = ssh_packet_encrypt(session,
 1984|  13.1k|                              ssh_buffer_get(session->out_buffer),
 1985|  13.1k|                              ssh_buffer_get_len(session->out_buffer));
 1986|       |    /* XXX This returns null before switching on crypto, with none MAC
 1987|       |     * and on various errors.
 1988|       |     * We should distinguish between these cases to avoid hiding errors. */
 1989|  13.1k|    if (hmac != NULL) {
  ------------------
  |  Branch (1989:9): [True: 9.19k, False: 3.94k]
  ------------------
 1990|  9.19k|        rc = ssh_buffer_add_data(session->out_buffer,
 1991|  9.19k|                                 hmac,
 1992|  9.19k|                                 (uint32_t)hmac_digest_len(hmac_type));
 1993|  9.19k|        if (rc < 0) {
  ------------------
  |  Branch (1993:13): [True: 0, False: 9.19k]
  ------------------
 1994|      0|            goto error;
 1995|      0|        }
 1996|  9.19k|    }
 1997|       |
 1998|  13.1k|    rc = ssh_packet_write(session);
 1999|  13.1k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  13.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1999:9): [True: 0, False: 13.1k]
  ------------------
 2000|      0|        goto error;
 2001|      0|    }
 2002|  13.1k|    session->send_seq++;
 2003|  13.1k|    if (crypto != NULL) {
  ------------------
  |  Branch (2003:9): [True: 9.19k, False: 3.94k]
  ------------------
 2004|  9.19k|        struct ssh_cipher_struct *cipher = NULL;
 2005|       |
 2006|  9.19k|        cipher = crypto->out_cipher;
 2007|  9.19k|        cipher->packets++;
 2008|  9.19k|        cipher->blocks += payloadsize / cipher->blocksize;
 2009|  9.19k|    }
 2010|  13.1k|    if (session->raw_counter != NULL) {
  ------------------
  |  Branch (2010:9): [True: 0, False: 13.1k]
  ------------------
 2011|      0|        session->raw_counter->out_bytes += payloadsize;
 2012|      0|        session->raw_counter->out_packets++;
 2013|      0|    }
 2014|       |
 2015|  13.1k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  13.1k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2016|  13.1k|            "packet: wrote [type=%u, len=%" PRIu32 ", padding_size=%hhd, comp=%" PRIu32 ", "
 2017|  13.1k|            "payload=%" PRIu32 "]",
 2018|  13.1k|            type,
 2019|  13.1k|            finallen,
 2020|  13.1k|            padding_size,
 2021|  13.1k|            compsize,
 2022|  13.1k|            payloadsize);
 2023|       |
 2024|  13.1k|    rc = ssh_buffer_reinit(session->out_buffer);
 2025|  13.1k|    if (rc < 0) {
  ------------------
  |  Branch (2025:9): [True: 0, False: 13.1k]
  ------------------
 2026|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2027|      0|        goto error;
 2028|      0|    }
 2029|       |
 2030|       |    /* We sent the NEWKEYS so any further packet needs to be encrypted
 2031|       |     * with the new keys. We can not switch both directions (need to decrypt
 2032|       |     * peer NEWKEYS) and we do not want to wait for the peer NEWKEYS
 2033|       |     * too, so we will switch only the OUT direction now.
 2034|       |     */
 2035|  13.1k|    if (type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  13.1k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2035:9): [True: 1.31k, False: 11.8k]
  ------------------
 2036|  1.31k|        rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_OUT);
 2037|  1.31k|    }
 2038|  13.1k|error:
 2039|  13.1k|    return rc; /* SSH_OK, AGAIN or ERROR */
 2040|  13.1k|}
packet.c:ssh_packet_write:
 1884|  13.1k|static int ssh_packet_write(ssh_session session) {
 1885|  13.1k|  int rc = SSH_ERROR;
  ------------------
  |  |  317|  13.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1886|       |
 1887|  13.1k|  rc=ssh_socket_write(session->socket,
 1888|  13.1k|      ssh_buffer_get(session->out_buffer),
 1889|  13.1k|      ssh_buffer_get_len(session->out_buffer));
 1890|       |
 1891|  13.1k|  return rc;
 1892|  13.1k|}
packet.c:ssh_init_rekey_state:
 2240|  2.62k|{
 2241|       |    /* Reset the counters: should be NOOP */
 2242|  2.62k|    cipher->packets = 0;
 2243|  2.62k|    cipher->blocks = 0;
 2244|       |
 2245|       |    /* Default rekey limits for ciphers as specified in RFC4344, Section 3.2 */
 2246|  2.62k|    if (cipher->blocksize >= 16) {
  ------------------
  |  Branch (2246:9): [True: 2.26k, False: 364]
  ------------------
 2247|       |        /* For larger block size (L bits) use maximum of 2**(L/4) blocks */
 2248|  2.26k|        cipher->max_blocks = (uint64_t)1 << (cipher->blocksize*2);
 2249|  2.26k|    } else {
 2250|       |        /* For smaller blocks use limit of 1 GB as recommended in RFC4253 */
 2251|    364|        cipher->max_blocks = ((uint64_t)1 << 30) / cipher->blocksize;
 2252|    364|    }
 2253|       |    /* If we have limit provided by user, use the smaller one */
 2254|  2.62k|    if (session->opts.rekey_data != 0) {
  ------------------
  |  Branch (2254:9): [True: 0, False: 2.62k]
  ------------------
 2255|      0|        cipher->max_blocks = MIN(cipher->max_blocks,
  ------------------
  |  |  365|      0|#define MIN(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (365:19): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 2256|      0|                                 session->opts.rekey_data / cipher->blocksize);
 2257|      0|    }
 2258|       |
 2259|  2.62k|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|  2.62k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2260|  2.62k|            "Set rekey after %" PRIu64 " blocks",
 2261|  2.62k|            cipher->max_blocks);
 2262|  2.62k|}

ssh_packet_newkeys:
  143|  1.30k|{
  144|  1.30k|    ssh_string sig_blob = NULL;
  145|  1.30k|    ssh_signature sig = NULL;
  146|  1.30k|    int rc;
  147|       |
  148|  1.30k|    (void)packet;
  149|  1.30k|    (void)user;
  150|  1.30k|    (void)type;
  151|       |
  152|  1.30k|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_NEWKEYS");
  ------------------
  |  |  281|  1.30k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  153|       |
  154|  1.30k|    if (session->session_state != SSH_SESSION_STATE_DH ||
  ------------------
  |  Branch (154:9): [True: 4, False: 1.30k]
  ------------------
  155|  1.30k|        session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (155:9): [True: 0, False: 1.30k]
  ------------------
  156|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  157|      0|                      SSH_FATAL,
  158|      0|                      "ssh_packet_newkeys called in wrong state : %d:%d",
  159|      0|                      session->session_state,
  160|      0|                      session->dh_handshake_state);
  161|      0|        goto error;
  162|      0|    }
  163|       |
  164|  1.30k|    if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|  1.30k|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (164:9): [True: 1.30k, False: 4]
  ------------------
  165|       |        /* reset packet sequence number when running in strict kex mode */
  166|  1.30k|        session->recv_seq = 0;
  167|       |        /* Check that we aren't tainted */
  168|  1.30k|        if (session->flags & SSH_SESSION_FLAG_KEX_TAINTED) {
  ------------------
  |  |   92|  1.30k|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
  |  Branch (168:13): [True: 0, False: 1.30k]
  ------------------
  169|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  170|      0|                          SSH_FATAL,
  171|      0|                          "Received unexpected packets in strict KEX mode.");
  172|      0|            goto error;
  173|      0|        }
  174|  1.30k|    }
  175|       |
  176|  1.30k|    if (session->server) {
  ------------------
  |  Branch (176:9): [True: 657, False: 649]
  ------------------
  177|       |        /* server things are done in server.c */
  178|    657|        session->dh_handshake_state=DH_STATE_FINISHED;
  179|    657|    } else {
  180|       |#ifdef WITH_GSSAPI
  181|       |        if (ssh_kex_is_gss(session->next_crypto)) {
  182|       |            OM_uint32 maj_stat, min_stat;
  183|       |            gss_buffer_desc mic = GSS_C_EMPTY_BUFFER, msg = GSS_C_EMPTY_BUFFER;
  184|       |
  185|       |            if (session->gssapi == NULL || session->gssapi->ctx == NULL) {
  186|       |                ssh_set_error(session, SSH_FATAL, "GSSAPI context not initialized");
  187|       |                goto error;
  188|       |            }
  189|       |
  190|       |            if (session->gssapi_key_exchange_mic == NULL) {
  191|       |                ssh_set_error(session,
  192|       |                              SSH_FATAL,
  193|       |                              "GSSAPI mic not set");
  194|       |                goto error;
  195|       |            }
  196|       |
  197|       |            mic.length = ssh_string_len(session->gssapi_key_exchange_mic);
  198|       |            mic.value = ssh_string_data(session->gssapi_key_exchange_mic);
  199|       |
  200|       |            msg.length = session->next_crypto->digest_len;
  201|       |            msg.value = session->next_crypto->secret_hash;
  202|       |
  203|       |            maj_stat = gss_verify_mic(&min_stat,
  204|       |                                      session->gssapi->ctx,
  205|       |                                      &msg,
  206|       |                                      &mic,
  207|       |                                      NULL);
  208|       |            if (maj_stat != GSS_S_COMPLETE) {
  209|       |                ssh_set_error(session,
  210|       |                              SSH_FATAL,
  211|       |                              "Failed to verify mic after GSSAPI Key Exchange");
  212|       |                goto error;
  213|       |            }
  214|       |            SSH_STRING_FREE(session->gssapi_key_exchange_mic);
  215|       |        } else
  216|       |#endif
  217|    649|        {
  218|    649|            ssh_key server_key = NULL;
  219|       |
  220|       |            /* client */
  221|       |
  222|       |            /* Verify the host's signature. FIXME do it sooner */
  223|    649|            sig_blob = session->next_crypto->dh_server_signature;
  224|    649|            session->next_crypto->dh_server_signature = NULL;
  225|       |
  226|       |            /* get the server public key */
  227|    649|            server_key = ssh_dh_get_next_server_publickey(session);
  228|    649|            if (server_key == NULL) {
  ------------------
  |  Branch (228:17): [True: 0, False: 649]
  ------------------
  229|      0|                goto error;
  230|      0|            }
  231|       |
  232|    649|            rc = ssh_pki_import_signature_blob(sig_blob, server_key, &sig);
  233|    649|            ssh_string_burn(sig_blob);
  234|    649|            SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  910|    657|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 657, False: 18.4E]
  |  |  |  Branch (910:69): [Folded, False: 649]
  |  |  ------------------
  ------------------
  235|    649|            if (rc != SSH_OK) {
  ------------------
  |  |  316|    649|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (235:17): [True: 0, False: 649]
  ------------------
  236|      0|                goto error;
  237|      0|            }
  238|       |
  239|       |            /* Check if signature from server matches user preferences */
  240|    649|            if (session->opts.wanted_methods[SSH_HOSTKEYS]) {
  ------------------
  |  Branch (240:17): [True: 0, False: 649]
  ------------------
  241|      0|                rc = match_group(session->opts.wanted_methods[SSH_HOSTKEYS],
  242|      0|                                 sig->type_c);
  243|      0|                if (rc == 0) {
  ------------------
  |  Branch (243:21): [True: 0, False: 0]
  ------------------
  244|      0|                    ssh_set_error(
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  245|      0|                        session,
  246|      0|                        SSH_FATAL,
  247|      0|                        "Public key from server (%s) doesn't match user "
  248|      0|                        "preference (%s)",
  249|      0|                        sig->type_c,
  250|      0|                        session->opts.wanted_methods[SSH_HOSTKEYS]);
  251|      0|                    goto error;
  252|      0|                }
  253|      0|            }
  254|       |
  255|    649|            rc = ssh_pki_signature_verify(session,
  256|    649|                                          sig,
  257|    649|                                          server_key,
  258|    649|                                          session->next_crypto->secret_hash,
  259|    649|                                          session->next_crypto->digest_len);
  260|    649|            SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|    649|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 649]
  |  |  ------------------
  ------------------
  261|    649|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    649|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (261:17): [True: 0, False: 649]
  ------------------
  262|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  263|      0|                              SSH_FATAL,
  264|      0|                              "Failed to verify server hostkey signature");
  265|      0|                goto error;
  266|      0|            }
  267|    649|        }
  268|    649|        SSH_LOG(SSH_LOG_DEBUG, "Signature verified and valid");
  ------------------
  |  |  281|    649|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  269|       |
  270|       |        /* When receiving this packet, we switch on the incoming crypto. */
  271|    649|        rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_IN);
  272|    649|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    649|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (272:13): [True: 0, False: 649]
  ------------------
  273|      0|            goto error;
  274|      0|        }
  275|    649|    }
  276|  1.30k|    session->dh_handshake_state = DH_STATE_FINISHED;
  277|  1.30k|    session->ssh_connection_callback(session);
  278|  1.30k|    return SSH_PACKET_USED;
  ------------------
  |  |  637|  1.30k|#define SSH_PACKET_USED 1
  ------------------
  279|       |
  280|      0|error:
  281|       |#ifdef WITH_GSSAPI
  282|       |    SSH_STRING_FREE(session->gssapi_key_exchange_mic);
  283|       |#endif
  284|      0|    SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|      0|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 0]
  |  |  ------------------
  ------------------
  285|      0|    ssh_string_burn(sig_blob);
  286|      0|    SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  287|      0|    session->session_state = SSH_SESSION_STATE_ERROR;
  288|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  289|  1.30k|}
ssh_packet_service_accept:
  297|    657|{
  298|    657|    (void)packet;
  299|    657|    (void)type;
  300|    657|    (void)user;
  301|       |
  302|    657|    session->auth.service_state = SSH_AUTH_SERVICE_ACCEPTED;
  303|    657|    SSH_LOG(SSH_LOG_PACKET, "Received SSH_MSG_SERVICE_ACCEPT");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  304|       |
  305|    657|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
  306|    657|}
ssh_packet_ext_info:
  314|    657|{
  315|    657|    int rc;
  316|    657|    uint32_t nr_extensions = 0;
  317|    657|    uint32_t i;
  318|       |
  319|    657|    (void)type;
  320|    657|    (void)user;
  321|       |
  322|    657|    SSH_LOG(SSH_LOG_PACKET, "Received SSH_MSG_EXT_INFO");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  323|       |
  324|    657|    rc = ssh_buffer_get_u32(packet, &nr_extensions);
  325|    657|    if (rc == 0) {
  ------------------
  |  Branch (325:9): [True: 0, False: 657]
  ------------------
  326|      0|        SSH_LOG(SSH_LOG_PACKET, "Failed to read number of extensions");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  327|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  328|      0|    }
  329|       |
  330|    657|    nr_extensions = ntohl(nr_extensions);
  331|    657|    if (nr_extensions > 128) {
  ------------------
  |  Branch (331:9): [True: 0, False: 657]
  ------------------
  332|      0|        SSH_LOG(SSH_LOG_PACKET, "Invalid number of extensions");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  333|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  334|      0|    }
  335|       |
  336|    657|    SSH_LOG(SSH_LOG_PACKET, "Follows %" PRIu32 " extensions", nr_extensions);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  337|       |
  338|  2.62k|    for (i = 0; i < nr_extensions; i++) {
  ------------------
  |  Branch (338:17): [True: 1.97k, False: 657]
  ------------------
  339|  1.97k|        char *name = NULL;
  340|  1.97k|        char *value = NULL;
  341|       |
  342|  1.97k|        rc = ssh_buffer_unpack(packet, "ss", &name, &value);
  ------------------
  |  |   60|  1.97k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.97k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.97k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.97k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.97k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.97k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.97k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  343|  1.97k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.97k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (343:13): [True: 0, False: 1.97k]
  ------------------
  344|      0|            SSH_LOG(SSH_LOG_PACKET, "Error reading extension name-value pair");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  345|      0|            return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  346|      0|        }
  347|       |
  348|  1.97k|        if (strcmp(name, "server-sig-algs") == 0) {
  ------------------
  |  Branch (348:13): [True: 657, False: 1.31k]
  ------------------
  349|       |            /* TODO check for NULL bytes */
  350|    657|            SSH_LOG(SSH_LOG_PACKET, "Extension: %s=<%s>", name, value);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  351|       |
  352|    657|            rc = match_group(value, "rsa-sha2-512");
  353|    657|            if (rc == 1) {
  ------------------
  |  Branch (353:17): [True: 657, False: 0]
  ------------------
  354|    657|                session->extensions |= SSH_EXT_SIG_RSA_SHA512;
  ------------------
  |  |  126|    657|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  355|    657|            }
  356|       |
  357|    657|            rc = match_group(value, "rsa-sha2-256");
  358|    657|            if (rc == 1) {
  ------------------
  |  Branch (358:17): [True: 657, False: 0]
  ------------------
  359|    657|                session->extensions |= SSH_EXT_SIG_RSA_SHA256;
  ------------------
  |  |  125|    657|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  360|    657|            }
  361|  1.31k|        } else if (strcmp(name, "publickey-hostbound@openssh.com") == 0) {
  ------------------
  |  Branch (361:20): [True: 657, False: 657]
  ------------------
  362|    657|            SSH_LOG(SSH_LOG_PACKET, "Extension: %s=<%s>", name, value);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  363|    657|            session->extensions |= SSH_EXT_PUBLICKEY_HOSTBOUND;
  ------------------
  |  |  128|    657|#define SSH_EXT_PUBLICKEY_HOSTBOUND 0x08
  ------------------
  364|    657|        } else if (strcmp(name, "ping@openssh.com") == 0) {
  ------------------
  |  Branch (364:20): [True: 657, False: 0]
  ------------------
  365|    657|            if (strcmp(value, "0") == 0) {
  ------------------
  |  Branch (365:17): [True: 657, False: 0]
  ------------------
  366|    657|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  367|    657|                        "Extension: %s=<%s> (supported)",
  368|    657|                        name,
  369|    657|                        value);
  370|    657|                session->extensions |= SSH_EXT_PING;
  ------------------
  |  |  130|    657|#define SSH_EXT_PING 0x10
  ------------------
  371|    657|            } else {
  372|      0|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  373|      0|                        "Extension: %s=<%s> (unsupported version, expected 0)",
  374|      0|                        name,
  375|      0|                        value);
  376|      0|            }
  377|    657|        } else {
  378|      0|            SSH_LOG(SSH_LOG_PACKET, "Unknown extension: %s", name);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  379|      0|        }
  380|  1.97k|        free(name);
  381|  1.97k|        free(value);
  382|  1.97k|    }
  383|       |
  384|    657|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    657|#define SSH_PACKET_USED 1
  ------------------
  385|    657|}

ssh_packet_decrypt_len:
   55|  11.1k|{
   56|  11.1k|    struct ssh_crypto_struct *crypto = NULL;
   57|  11.1k|    uint32_t decrypted;
   58|  11.1k|    int rc;
   59|       |
   60|  11.1k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
   61|  11.1k|    if (crypto != NULL) {
  ------------------
  |  Branch (61:9): [True: 7.22k, False: 3.92k]
  ------------------
   62|  7.22k|        if (crypto->in_cipher->aead_decrypt_length != NULL) {
  ------------------
  |  Branch (62:13): [True: 0, False: 7.22k]
  ------------------
   63|      0|            rc = crypto->in_cipher->aead_decrypt_length(
   64|      0|                    crypto->in_cipher, source, destination,
   65|      0|                    crypto->in_cipher->lenfield_blocksize,
   66|      0|                    session->recv_seq);
   67|  7.22k|        } else {
   68|  7.22k|            rc = ssh_packet_decrypt(
   69|  7.22k|                    session,
   70|  7.22k|                    destination,
   71|  7.22k|                    source,
   72|  7.22k|                    0,
   73|  7.22k|                    crypto->in_cipher->blocksize);
   74|  7.22k|        }
   75|  7.22k|        if (rc < 0) {
  ------------------
  |  Branch (75:13): [True: 0, False: 7.22k]
  ------------------
   76|      0|            return 0;
   77|      0|        }
   78|  7.22k|    } else {
   79|  3.92k|        memcpy(destination, source, 8);
   80|  3.92k|    }
   81|  11.1k|    memcpy(&decrypted,destination,sizeof(decrypted));
   82|       |
   83|       |    return ntohl(decrypted);
   84|  11.1k|}
ssh_packet_decrypt:
   97|  12.7k|{
   98|  12.7k|    struct ssh_crypto_struct *crypto = NULL;
   99|  12.7k|    struct ssh_cipher_struct *cipher = NULL;
  100|       |
  101|  12.7k|    if (encrypted_size <= 0) {
  ------------------
  |  Branch (101:9): [True: 0, False: 12.7k]
  ------------------
  102|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  103|      0|    }
  104|       |
  105|  12.7k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
  106|  12.7k|    if (crypto == NULL) {
  ------------------
  |  Branch (106:9): [True: 0, False: 12.7k]
  ------------------
  107|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  108|      0|    }
  109|  12.7k|    cipher = crypto->in_cipher;
  110|       |
  111|  12.7k|    if (encrypted_size % cipher->blocksize != 0) {
  ------------------
  |  Branch (111:9): [True: 0, False: 12.7k]
  ------------------
  112|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  113|      0|                      SSH_FATAL,
  114|      0|                      "Cryptographic functions must be used on multiple of "
  115|      0|                      "blocksize (received %zu)",
  116|      0|                      encrypted_size);
  117|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  118|      0|    }
  119|       |
  120|  12.7k|    if (cipher->aead_decrypt != NULL) {
  ------------------
  |  Branch (120:9): [True: 0, False: 12.7k]
  ------------------
  121|      0|        return cipher->aead_decrypt(cipher,
  122|      0|                                    source,
  123|      0|                                    destination,
  124|      0|                                    encrypted_size,
  125|      0|                                    session->recv_seq);
  126|  12.7k|    } else {
  127|  12.7k|        cipher->decrypt(cipher, source + start, destination, encrypted_size);
  128|  12.7k|    }
  129|       |
  130|  12.7k|    return 0;
  131|  12.7k|}
ssh_packet_encrypt:
  134|  13.1k|{
  135|  13.1k|  struct ssh_crypto_struct *crypto = NULL;
  136|  13.1k|  struct ssh_cipher_struct *cipher = NULL;
  137|  13.1k|  HMACCTX ctx = NULL;
  138|  13.1k|  char *out = NULL;
  139|  13.1k|  int etm_packet_offset = 0, rc;
  140|  13.1k|  unsigned int blocksize;
  141|  13.1k|  size_t finallen = DIGEST_MAX_LEN;
  ------------------
  |  |   56|  13.1k|#define DIGEST_MAX_LEN 64
  ------------------
  142|  13.1k|  uint32_t seq, lenfield_blocksize;
  143|  13.1k|  enum ssh_hmac_e type;
  144|  13.1k|  bool etm;
  145|       |
  146|  13.1k|  assert(len);
  ------------------
  |  Branch (146:3): [True: 0, False: 13.1k]
  |  Branch (146:3): [True: 13.1k, False: 0]
  ------------------
  147|       |
  148|  13.1k|  crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
  149|  13.1k|  if (crypto == NULL) {
  ------------------
  |  Branch (149:7): [True: 3.94k, False: 9.19k]
  ------------------
  150|  3.94k|      return NULL; /* nothing to do here */
  151|  3.94k|  }
  152|       |
  153|  9.19k|  blocksize = crypto->out_cipher->blocksize;
  154|  9.19k|  lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
  155|       |
  156|  9.19k|  type = crypto->out_hmac;
  157|  9.19k|  etm = crypto->out_hmac_etm;
  158|       |
  159|  9.19k|  if (etm) {
  ------------------
  |  Branch (159:7): [True: 0, False: 9.19k]
  ------------------
  160|      0|      etm_packet_offset = sizeof(uint32_t);
  161|      0|  }
  162|       |
  163|  9.19k|  if ((len - lenfield_blocksize - etm_packet_offset) % blocksize != 0) {
  ------------------
  |  Branch (163:7): [True: 0, False: 9.19k]
  ------------------
  164|      0|      ssh_set_error(session, SSH_FATAL, "Cryptographic functions must be set"
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  165|      0|                    " on at least one blocksize (received %zu)", len);
  166|      0|      return NULL;
  167|      0|  }
  168|  9.19k|  out = calloc(1, len);
  169|  9.19k|  if (out == NULL) {
  ------------------
  |  Branch (169:7): [True: 0, False: 9.19k]
  ------------------
  170|      0|    return NULL;
  171|      0|  }
  172|       |
  173|  9.19k|  seq = ntohl(session->send_seq);
  174|  9.19k|  cipher = crypto->out_cipher;
  175|       |
  176|  9.19k|  if (cipher->aead_encrypt != NULL) {
  ------------------
  |  Branch (176:7): [True: 0, False: 9.19k]
  ------------------
  177|      0|      cipher->aead_encrypt(cipher, data, out, len,
  178|      0|            crypto->hmacbuf, session->send_seq);
  179|      0|      memcpy(data, out, len);
  180|  9.19k|  } else {
  181|  9.19k|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (181:11): [True: 7.05k, False: 2.14k]
  ------------------
  182|  7.05k|          ctx = hmac_init(crypto->encryptMAC, hmac_digest_len(type), type);
  183|  7.05k|          if (ctx == NULL) {
  ------------------
  |  Branch (183:15): [True: 0, False: 7.05k]
  ------------------
  184|      0|              SAFE_FREE(out);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  185|      0|              return NULL;
  186|      0|          }
  187|       |
  188|  7.05k|          if (!etm) {
  ------------------
  |  Branch (188:15): [True: 7.05k, False: 0]
  ------------------
  189|  7.05k|              rc = hmac_update(ctx, (unsigned char *)&seq, sizeof(uint32_t));
  190|  7.05k|              if (rc != 1) {
  ------------------
  |  Branch (190:19): [True: 0, False: 7.05k]
  ------------------
  191|      0|                  SAFE_FREE(out);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  192|      0|                  return NULL;
  193|      0|              }
  194|  7.05k|              rc = hmac_update(ctx, data, len);
  195|  7.05k|              if (rc != 1) {
  ------------------
  |  Branch (195:19): [True: 0, False: 7.05k]
  ------------------
  196|      0|                  SAFE_FREE(out);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  197|      0|                  return NULL;
  198|      0|              }
  199|  7.05k|              rc = hmac_final(ctx, crypto->hmacbuf, &finallen);
  200|  7.05k|              if (rc != 1) {
  ------------------
  |  Branch (200:19): [True: 0, False: 7.05k]
  ------------------
  201|      0|                  SAFE_FREE(out);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  202|      0|                  return NULL;
  203|      0|              }
  204|  7.05k|          }
  205|  7.05k|      }
  206|       |
  207|  9.19k|      cipher->encrypt(cipher, (uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  208|  9.19k|      memcpy((uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  209|       |
  210|  9.19k|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (210:11): [True: 7.05k, False: 2.14k]
  ------------------
  211|  7.05k|          if (etm) {
  ------------------
  |  Branch (211:15): [True: 0, False: 7.05k]
  ------------------
  212|      0|              PUSH_BE_U32(data, 0, len - etm_packet_offset);
  ------------------
  |  |   89|      0|    (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|      0|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|      0|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|      0|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|      0|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|      0|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|      0|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|      0|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|      0|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|      0|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|      0|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|      0|              rc = hmac_update(ctx, (unsigned char *)&seq, sizeof(uint32_t));
  214|      0|              if (rc != 1) {
  ------------------
  |  Branch (214:19): [True: 0, False: 0]
  ------------------
  215|      0|                  SAFE_FREE(out);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  216|      0|                  return NULL;
  217|      0|              }
  218|      0|              rc = hmac_update(ctx, data, len);
  219|      0|              if (rc != 1) {
  ------------------
  |  Branch (219:19): [True: 0, False: 0]
  ------------------
  220|      0|                  SAFE_FREE(out);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  221|      0|                  return NULL;
  222|      0|              }
  223|      0|              rc = hmac_final(ctx, crypto->hmacbuf, &finallen);
  224|      0|              if (rc != 1) {
  ------------------
  |  Branch (224:19): [True: 0, False: 0]
  ------------------
  225|      0|                  SAFE_FREE(out);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  226|      0|                  return NULL;
  227|      0|              }
  228|      0|          }
  229|       |#ifdef DEBUG_CRYPTO
  230|       |          ssh_log_hexdump("mac: ", data, len);
  231|       |          if (finallen != hmac_digest_len(type)) {
  232|       |              printf("Final len is %zu\n", finallen);
  233|       |          }
  234|       |          ssh_log_hexdump("Packet hmac", crypto->hmacbuf, hmac_digest_len(type));
  235|       |#endif
  236|  7.05k|      }
  237|  9.19k|  }
  238|  9.19k|  ssh_burn(out, len);
  ------------------
  |  |  388|  9.19k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  239|  9.19k|  SAFE_FREE(out);
  ------------------
  |  |  373|  9.19k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 9.19k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 9.19k]
  |  |  ------------------
  ------------------
  240|       |
  241|  9.19k|  return crypto->hmacbuf;
  242|  9.19k|}
ssh_packet_hmac_verify:
  262|  5.54k|{
  263|  5.54k|    struct ssh_crypto_struct *crypto = NULL;
  264|  5.54k|    unsigned char hmacbuf[DIGEST_MAX_LEN] = {0};
  265|  5.54k|    HMACCTX ctx = NULL;
  266|  5.54k|    size_t hmaclen = DIGEST_MAX_LEN;
  ------------------
  |  |   56|  5.54k|#define DIGEST_MAX_LEN 64
  ------------------
  267|  5.54k|    uint32_t seq;
  268|  5.54k|    int cmp;
  269|  5.54k|    int rc;
  270|       |
  271|       |    /* AEAD types have no mac checking */
  272|  5.54k|    if (type == SSH_HMAC_AEAD_POLY1305 ||
  ------------------
  |  Branch (272:9): [True: 0, False: 5.54k]
  ------------------
  273|  5.54k|        type == SSH_HMAC_AEAD_GCM) {
  ------------------
  |  Branch (273:9): [True: 0, False: 5.54k]
  ------------------
  274|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  275|      0|    }
  276|       |
  277|  5.54k|    crypto = ssh_packet_get_current_crypto(session,
  278|  5.54k|                                           SSH_DIRECTION_IN);
  279|  5.54k|    if (crypto == NULL) {
  ------------------
  |  Branch (279:9): [True: 0, False: 5.54k]
  ------------------
  280|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  281|      0|    }
  282|       |
  283|  5.54k|    ctx = hmac_init(crypto->decryptMAC,
  284|  5.54k|                    hmac_digest_len(type),
  285|  5.54k|                    type);
  286|  5.54k|    if (ctx == NULL) {
  ------------------
  |  Branch (286:9): [True: 0, False: 5.54k]
  ------------------
  287|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  288|      0|    }
  289|       |
  290|  5.54k|    seq = htonl(session->recv_seq);
  291|       |
  292|  5.54k|    rc = hmac_update(ctx,
  293|  5.54k|                     (unsigned char *) &seq,
  294|  5.54k|                     sizeof(uint32_t));
  295|  5.54k|    if (rc != 1) {
  ------------------
  |  Branch (295:9): [True: 0, False: 5.54k]
  ------------------
  296|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  297|      0|    }
  298|  5.54k|    rc = hmac_update(ctx,
  299|  5.54k|                     data,
  300|  5.54k|                     len);
  301|  5.54k|    if (rc != 1) {
  ------------------
  |  Branch (301:9): [True: 0, False: 5.54k]
  ------------------
  302|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  303|      0|    }
  304|  5.54k|    rc = hmac_final(ctx,
  305|  5.54k|                    hmacbuf,
  306|  5.54k|                    &hmaclen);
  307|  5.54k|    if (rc != 1) {
  ------------------
  |  Branch (307:9): [True: 0, False: 5.54k]
  ------------------
  308|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  309|      0|    }
  310|       |
  311|       |#ifdef DEBUG_CRYPTO
  312|       |    ssh_log_hexdump("received mac",
  313|       |                    mac,
  314|       |                    hmaclen);
  315|       |    ssh_log_hexdump("Computed mac",
  316|       |                    hmacbuf,
  317|       |                    hmaclen);
  318|       |    ssh_log_hexdump("seq",
  319|       |                    (unsigned char *)&seq,
  320|       |                    sizeof(uint32_t));
  321|       |#endif
  322|  5.54k|    cmp = secure_memcmp(mac,
  323|  5.54k|                        hmacbuf,
  324|  5.54k|                        hmaclen);
  325|  5.54k|    if (cmp == 0) {
  ------------------
  |  Branch (325:9): [True: 5.54k, False: 0]
  ------------------
  326|  5.54k|        return SSH_OK;
  ------------------
  |  |  316|  5.54k|#define SSH_OK 0     /* No error */
  ------------------
  327|  5.54k|    }
  328|       |
  329|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  330|  5.54k|}

ssh_key_new:
  113|  3.28k|{
  114|  3.28k|    ssh_key ptr = malloc (sizeof (struct ssh_key_struct));
  115|  3.28k|    if (ptr == NULL) {
  ------------------
  |  Branch (115:9): [True: 0, False: 3.28k]
  ------------------
  116|      0|        return NULL;
  117|      0|    }
  118|  3.28k|    ZERO_STRUCTP(ptr);
  ------------------
  |  |  379|  3.28k|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (379:34): [True: 3.28k, False: 0]
  |  |  |  Branch (379:85): [Folded, False: 3.28k]
  |  |  ------------------
  ------------------
  119|  3.28k|    return ptr;
  120|  3.28k|}
pki_key_dup_common_init:
  145|  1.31k|{
  146|  1.31k|    ssh_key new = NULL;
  147|       |
  148|  1.31k|    if (key == NULL) {
  ------------------
  |  Branch (148:9): [True: 0, False: 1.31k]
  ------------------
  149|      0|        return NULL;
  150|      0|    }
  151|       |
  152|  1.31k|    new = ssh_key_new();
  153|  1.31k|    if (new == NULL) {
  ------------------
  |  Branch (153:9): [True: 0, False: 1.31k]
  ------------------
  154|      0|        return NULL;
  155|      0|    }
  156|       |
  157|  1.31k|    new->type = key->type;
  158|  1.31k|    new->type_c = key->type_c;
  159|  1.31k|    if (demote) {
  ------------------
  |  Branch (159:9): [True: 657, False: 657]
  ------------------
  160|    657|        new->flags = SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   54|    657|#define SSH_KEY_FLAG_PUBLIC  0x0001
  ------------------
  161|    657|    } else {
  162|    657|        new->flags = key->flags;
  163|    657|    }
  164|       |
  165|       |    /* Copy security key fields if present */
  166|  1.31k|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|  1.31k|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 0, False: 1.31k]
  |  |  |  Branch (153:38): [True: 0, False: 1.31k]
  |  |  ------------------
  |  |  154|  1.31k|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 1.31k]
  |  |  ------------------
  |  |  155|  1.31k|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 1.31k]
  |  |  ------------------
  ------------------
  167|      0|        new->sk_application = ssh_string_copy(key->sk_application);
  168|      0|        if (new->sk_application == NULL) {
  ------------------
  |  Branch (168:13): [True: 0, False: 0]
  ------------------
  169|      0|            goto fail;
  170|      0|        }
  171|       |
  172|      0|        if (key->sk_user_id != NULL) {
  ------------------
  |  Branch (172:13): [True: 0, False: 0]
  ------------------
  173|      0|            new->sk_user_id = ssh_string_copy(key->sk_user_id);
  174|      0|            if (new->sk_user_id == NULL) {
  ------------------
  |  Branch (174:17): [True: 0, False: 0]
  ------------------
  175|      0|                goto fail;
  176|      0|            }
  177|      0|        }
  178|       |
  179|      0|        if (!demote) {
  ------------------
  |  Branch (179:13): [True: 0, False: 0]
  ------------------
  180|      0|            new->sk_flags = key->sk_flags;
  181|       |
  182|      0|            new->sk_key_handle = ssh_string_copy(key->sk_key_handle);
  183|      0|            if (new->sk_key_handle == NULL) {
  ------------------
  |  Branch (183:17): [True: 0, False: 0]
  ------------------
  184|      0|                goto fail;
  185|      0|            }
  186|       |
  187|      0|            new->sk_reserved = ssh_string_copy(key->sk_reserved);
  188|      0|            if (new->sk_reserved == NULL) {
  ------------------
  |  Branch (188:17): [True: 0, False: 0]
  ------------------
  189|      0|                goto fail;
  190|      0|            }
  191|      0|        }
  192|      0|    }
  193|       |
  194|  1.31k|    return new;
  195|       |
  196|      0|fail:
  197|      0|    SSH_KEY_FREE(new);
  ------------------
  |  |  769|      0|    do { if ((x) != NULL) { ssh_key_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (769:14): [True: 0, False: 0]
  |  |  |  Branch (769:66): [Folded, False: 0]
  |  |  ------------------
  ------------------
  198|       |    return NULL;
  199|  1.31k|}
ssh_key_dup:
  209|    657|{
  210|    657|    if (key == NULL) {
  ------------------
  |  Branch (210:9): [True: 0, False: 657]
  ------------------
  211|      0|        return NULL;
  212|      0|    }
  213|       |
  214|    657|    return pki_key_dup(key, 0);
  215|    657|}
ssh_key_clean:
  222|  3.28k|{
  223|  3.28k|    if (key == NULL)
  ------------------
  |  Branch (223:9): [True: 0, False: 3.28k]
  ------------------
  224|      0|        return;
  225|       |
  226|  3.28k|    pki_key_clean(key);
  227|       |
  228|       |#ifndef HAVE_LIBCRYPTO
  229|       |    if (key->ed25519_privkey != NULL) {
  230|       |        ssh_burn(key->ed25519_privkey, sizeof(ed25519_privkey));
  231|       |        SAFE_FREE(key->ed25519_privkey);
  232|       |    }
  233|       |    SAFE_FREE(key->ed25519_pubkey);
  234|       |#endif /* HAVE_LIBCRYPTO */
  235|  3.28k|    if (key->cert != NULL) {
  ------------------
  |  Branch (235:9): [True: 0, False: 3.28k]
  ------------------
  236|      0|        SSH_BUFFER_FREE(key->cert);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  237|      0|    }
  238|  3.28k|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|  3.28k|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 0, False: 3.28k]
  |  |  |  Branch (153:38): [True: 0, False: 3.28k]
  |  |  ------------------
  |  |  154|  3.28k|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 3.28k]
  |  |  ------------------
  |  |  155|  3.28k|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 3.28k]
  |  |  ------------------
  ------------------
  239|      0|        ssh_string_burn(key->sk_application);
  240|      0|        ssh_string_free(key->sk_application);
  241|      0|        ssh_string_burn(key->sk_key_handle);
  242|      0|        ssh_string_free(key->sk_key_handle);
  243|      0|        ssh_string_burn(key->sk_reserved);
  244|      0|        ssh_string_free(key->sk_reserved);
  245|      0|        ssh_string_burn(key->sk_user_id);
  246|      0|        ssh_string_free(key->sk_user_id);
  247|      0|        key->sk_flags = 0;
  248|      0|    }
  249|  3.28k|    key->cert_type = SSH_KEYTYPE_UNKNOWN;
  250|  3.28k|    key->flags = SSH_KEY_FLAG_EMPTY;
  ------------------
  |  |   53|  3.28k|#define SSH_KEY_FLAG_EMPTY   0x0
  ------------------
  251|  3.28k|    key->type = SSH_KEYTYPE_UNKNOWN;
  252|  3.28k|    key->ecdsa_nid = 0;
  253|       |    key->type_c = NULL;
  254|  3.28k|}
ssh_key_free:
  261|  12.4k|{
  262|  12.4k|    if (key) {
  ------------------
  |  Branch (262:9): [True: 3.28k, False: 9.19k]
  ------------------
  263|  3.28k|        ssh_key_clean(key);
  264|       |        SAFE_FREE(key);
  ------------------
  |  |  373|  3.28k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 3.28k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 3.28k]
  |  |  ------------------
  ------------------
  265|  3.28k|    }
  266|  12.4k|}
ssh_key_type:
  280|  3.28k|{
  281|  3.28k|    if (key == NULL) {
  ------------------
  |  Branch (281:9): [True: 0, False: 3.28k]
  ------------------
  282|      0|        return SSH_KEYTYPE_UNKNOWN;
  283|      0|    }
  284|  3.28k|    return key->type;
  285|  3.28k|}
ssh_key_signature_to_char:
  367|  1.31k|{
  368|  1.31k|    switch (type) {
  369|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (369:5): [True: 0, False: 1.31k]
  ------------------
  370|      0|        switch (hash_type) {
  371|      0|        case SSH_DIGEST_SHA256:
  ------------------
  |  Branch (371:9): [True: 0, False: 0]
  ------------------
  372|      0|            return "rsa-sha2-256";
  373|      0|        case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (373:9): [True: 0, False: 0]
  ------------------
  374|      0|            return "rsa-sha2-512";
  375|      0|        case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (375:9): [True: 0, False: 0]
  ------------------
  376|      0|        case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (376:9): [True: 0, False: 0]
  ------------------
  377|      0|            return "ssh-rsa";
  378|      0|        default:
  ------------------
  |  Branch (378:9): [True: 0, False: 0]
  ------------------
  379|      0|            return NULL;
  380|      0|        }
  381|      0|        break;
  382|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (382:5): [True: 0, False: 1.31k]
  ------------------
  383|      0|        switch (hash_type) {
  384|      0|        case SSH_DIGEST_SHA256:
  ------------------
  |  Branch (384:9): [True: 0, False: 0]
  ------------------
  385|      0|            return "rsa-sha2-256-cert-v01@openssh.com";
  386|      0|        case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (386:9): [True: 0, False: 0]
  ------------------
  387|      0|            return "rsa-sha2-512-cert-v01@openssh.com";
  388|      0|        case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (388:9): [True: 0, False: 0]
  ------------------
  389|      0|        case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (389:9): [True: 0, False: 0]
  ------------------
  390|      0|            return "ssh-rsa-cert-v01@openssh.com";
  391|      0|        default:
  ------------------
  |  Branch (391:9): [True: 0, False: 0]
  ------------------
  392|      0|            return NULL;
  393|      0|        }
  394|      0|        break;
  395|  1.31k|    default:
  ------------------
  |  Branch (395:5): [True: 1.31k, False: 0]
  ------------------
  396|  1.31k|        return ssh_key_type_to_char(type);
  397|  1.31k|    }
  398|       |
  399|       |    /* We should never reach this */
  400|      0|    return NULL;
  401|  1.31k|}
ssh_key_type_to_char:
  410|  3.94k|const char *ssh_key_type_to_char(enum ssh_keytypes_e type) {
  411|  3.94k|  switch (type) {
  ------------------
  |  Branch (411:11): [True: 3.94k, False: 0]
  ------------------
  412|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (412:5): [True: 0, False: 3.94k]
  ------------------
  413|      0|      return "ssh-rsa";
  414|      0|    case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (414:5): [True: 0, False: 3.94k]
  ------------------
  415|      0|      return "ssh-ecdsa"; /* deprecated. invalid value */
  416|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (416:5): [True: 0, False: 3.94k]
  ------------------
  417|      0|      return "ecdsa-sha2-nistp256";
  418|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (418:5): [True: 0, False: 3.94k]
  ------------------
  419|      0|      return "ecdsa-sha2-nistp384";
  420|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (420:5): [True: 0, False: 3.94k]
  ------------------
  421|      0|      return "ecdsa-sha2-nistp521";
  422|  3.94k|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (422:5): [True: 3.94k, False: 0]
  ------------------
  423|  3.94k|      return "ssh-ed25519";
  424|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (424:5): [True: 0, False: 3.94k]
  ------------------
  425|      0|      return "ssh-rsa-cert-v01@openssh.com";
  426|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (426:5): [True: 0, False: 3.94k]
  ------------------
  427|      0|      return "ecdsa-sha2-nistp256-cert-v01@openssh.com";
  428|      0|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (428:5): [True: 0, False: 3.94k]
  ------------------
  429|      0|      return "ecdsa-sha2-nistp384-cert-v01@openssh.com";
  430|      0|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (430:5): [True: 0, False: 3.94k]
  ------------------
  431|      0|      return "ecdsa-sha2-nistp521-cert-v01@openssh.com";
  432|      0|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (432:5): [True: 0, False: 3.94k]
  ------------------
  433|      0|      return "ssh-ed25519-cert-v01@openssh.com";
  434|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (434:5): [True: 0, False: 3.94k]
  ------------------
  435|      0|      return "sk-ecdsa-sha2-nistp256@openssh.com";
  436|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (436:5): [True: 0, False: 3.94k]
  ------------------
  437|      0|      return "sk-ssh-ed25519@openssh.com";
  438|      0|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (438:5): [True: 0, False: 3.94k]
  ------------------
  439|      0|      return "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com";
  440|      0|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (440:5): [True: 0, False: 3.94k]
  ------------------
  441|      0|      return "sk-ssh-ed25519-cert-v01@openssh.com";
  442|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (442:5): [True: 0, False: 3.94k]
  ------------------
  443|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (443:5): [True: 0, False: 3.94k]
  ------------------
  444|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (444:5): [True: 0, False: 3.94k]
  ------------------
  445|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (445:5): [True: 0, False: 3.94k]
  ------------------
  446|      0|      return NULL;
  447|  3.94k|  }
  448|       |
  449|       |  /* We should never reach this */
  450|      0|  return NULL;
  451|  3.94k|}
ssh_key_type_and_hash_from_signature_name:
  472|  1.31k|{
  473|  1.31k|    size_t len;
  474|       |
  475|  1.31k|    if (name == NULL || type == NULL || hash_type == NULL) {
  ------------------
  |  Branch (475:9): [True: 0, False: 1.31k]
  |  Branch (475:25): [True: 0, False: 1.31k]
  |  Branch (475:41): [True: 0, False: 1.31k]
  ------------------
  476|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  477|      0|    }
  478|       |
  479|  1.31k|    len = strlen(name);
  480|       |
  481|  1.31k|    if (len == 7 && strcmp(name, "ssh-rsa") == 0) {
  ------------------
  |  Branch (481:9): [True: 0, False: 1.31k]
  |  Branch (481:21): [True: 0, False: 0]
  ------------------
  482|      0|        *type = SSH_KEYTYPE_RSA;
  483|      0|        *hash_type = SSH_DIGEST_SHA1;
  484|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  485|      0|    }
  486|       |
  487|  1.31k|    if (len == 11 && strcmp(name, "ssh-ed25519") == 0) {
  ------------------
  |  Branch (487:9): [True: 1.31k, False: 0]
  |  Branch (487:22): [True: 1.31k, False: 0]
  ------------------
  488|  1.31k|        *type = SSH_KEYTYPE_ED25519;
  489|  1.31k|        *hash_type = SSH_DIGEST_AUTO;
  490|  1.31k|        return SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  491|  1.31k|    }
  492|       |
  493|      0|    if (len == 12) {
  ------------------
  |  Branch (493:9): [True: 0, False: 0]
  ------------------
  494|      0|        if (strcmp(name, "rsa-sha2-256") == 0) {
  ------------------
  |  Branch (494:13): [True: 0, False: 0]
  ------------------
  495|      0|            *type = SSH_KEYTYPE_RSA;
  496|      0|            *hash_type = SSH_DIGEST_SHA256;
  497|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  498|      0|        }
  499|      0|        if (strcmp(name, "rsa-sha2-512") == 0) {
  ------------------
  |  Branch (499:13): [True: 0, False: 0]
  ------------------
  500|      0|            *type = SSH_KEYTYPE_RSA;
  501|      0|            *hash_type = SSH_DIGEST_SHA512;
  502|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  503|      0|        }
  504|      0|    }
  505|       |
  506|      0|    if (len == 19) {
  ------------------
  |  Branch (506:9): [True: 0, False: 0]
  ------------------
  507|      0|        if (strcmp(name, "ecdsa-sha2-nistp256") == 0) {
  ------------------
  |  Branch (507:13): [True: 0, False: 0]
  ------------------
  508|      0|            *type = SSH_KEYTYPE_ECDSA_P256;
  509|      0|            *hash_type = SSH_DIGEST_SHA256;
  510|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  511|      0|        }
  512|      0|        if (strcmp(name, "ecdsa-sha2-nistp384") == 0) {
  ------------------
  |  Branch (512:13): [True: 0, False: 0]
  ------------------
  513|      0|            *type = SSH_KEYTYPE_ECDSA_P384;
  514|      0|            *hash_type = SSH_DIGEST_SHA384;
  515|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  516|      0|        }
  517|       |
  518|      0|        if (strcmp(name, "ecdsa-sha2-nistp521") == 0) {
  ------------------
  |  Branch (518:13): [True: 0, False: 0]
  ------------------
  519|      0|            *type = SSH_KEYTYPE_ECDSA_P521;
  520|      0|            *hash_type = SSH_DIGEST_SHA512;
  521|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  522|      0|        }
  523|      0|    }
  524|       |
  525|      0|    if (len == 26 && strcmp(name, "sk-ssh-ed25519@openssh.com") == 0) {
  ------------------
  |  Branch (525:9): [True: 0, False: 0]
  |  Branch (525:22): [True: 0, False: 0]
  ------------------
  526|      0|        *type = SSH_KEYTYPE_SK_ED25519;
  527|      0|        *hash_type = SSH_DIGEST_AUTO;
  528|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  529|      0|    }
  530|       |
  531|      0|    if (len == 28 && strcmp(name, "ssh-rsa-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (531:9): [True: 0, False: 0]
  |  Branch (531:22): [True: 0, False: 0]
  ------------------
  532|      0|        *type = SSH_KEYTYPE_RSA_CERT01;
  533|      0|        *hash_type = SSH_DIGEST_SHA1;
  534|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  535|      0|    }
  536|       |
  537|      0|    if (len == 32 && strcmp(name, "ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (537:9): [True: 0, False: 0]
  |  Branch (537:22): [True: 0, False: 0]
  ------------------
  538|      0|        *type = SSH_KEYTYPE_ED25519_CERT01;
  539|      0|        *hash_type = SSH_DIGEST_AUTO;
  540|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  541|      0|    }
  542|       |
  543|      0|    if (len == 33) {
  ------------------
  |  Branch (543:9): [True: 0, False: 0]
  ------------------
  544|      0|        if (strcmp(name, "rsa-sha2-256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (544:13): [True: 0, False: 0]
  ------------------
  545|      0|            *type = SSH_KEYTYPE_RSA_CERT01;
  546|      0|            *hash_type = SSH_DIGEST_SHA256;
  547|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  548|      0|        }
  549|      0|        if (strcmp(name, "rsa-sha2-512-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (549:13): [True: 0, False: 0]
  ------------------
  550|      0|            *type = SSH_KEYTYPE_RSA_CERT01;
  551|      0|            *hash_type = SSH_DIGEST_SHA512;
  552|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  553|      0|        }
  554|      0|    }
  555|       |
  556|      0|    if (len == 34 && strcmp(name, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (556:9): [True: 0, False: 0]
  |  Branch (556:22): [True: 0, False: 0]
  ------------------
  557|      0|        *type = SSH_KEYTYPE_SK_ECDSA;
  558|      0|        *hash_type = SSH_DIGEST_SHA256;
  559|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  560|      0|    }
  561|       |
  562|      0|    if (len == 40) {
  ------------------
  |  Branch (562:9): [True: 0, False: 0]
  ------------------
  563|      0|        if (strcmp(name, "ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (563:13): [True: 0, False: 0]
  ------------------
  564|      0|            *type = SSH_KEYTYPE_ECDSA_P256_CERT01;
  565|      0|            *hash_type = SSH_DIGEST_SHA256;
  566|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  567|      0|        }
  568|      0|        if (strcmp(name, "ecdsa-sha2-nistp384-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (568:13): [True: 0, False: 0]
  ------------------
  569|      0|            *type = SSH_KEYTYPE_ECDSA_P384_CERT01;
  570|      0|            *hash_type = SSH_DIGEST_SHA384;
  571|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  572|      0|        }
  573|      0|        if (strcmp(name, "ecdsa-sha2-nistp521-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (573:13): [True: 0, False: 0]
  ------------------
  574|      0|            *type = SSH_KEYTYPE_ECDSA_P521_CERT01;
  575|      0|            *hash_type = SSH_DIGEST_SHA512;
  576|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  577|      0|        }
  578|      0|    }
  579|       |
  580|      0|    SSH_LOG(SSH_LOG_TRACE, "Unknown signature name %s", name);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  581|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  582|      0|}
ssh_key_size_allowed:
  646|  1.31k|{
  647|  1.31k|    int min_size = 0;
  648|       |
  649|  1.31k|    switch (ssh_key_type(key)) {
  650|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (650:5): [True: 0, False: 1.31k]
  ------------------
  651|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (651:5): [True: 0, False: 1.31k]
  ------------------
  652|      0|        min_size = session->opts.rsa_min_size;
  653|      0|        return ssh_key_size_allowed_rsa(min_size, key);
  654|  1.31k|    default:
  ------------------
  |  Branch (654:5): [True: 1.31k, False: 0]
  ------------------
  655|       |        return true;
  656|  1.31k|    }
  657|  1.31k|}
ssh_key_type_from_name:
  808|  1.97k|{
  809|  1.97k|    if (name == NULL) {
  ------------------
  |  Branch (809:9): [True: 0, False: 1.97k]
  ------------------
  810|      0|        return SSH_KEYTYPE_UNKNOWN;
  811|      0|    }
  812|       |
  813|  1.97k|    if (strcmp(name, "rsa") == 0) {
  ------------------
  |  Branch (813:9): [True: 0, False: 1.97k]
  ------------------
  814|      0|        return SSH_KEYTYPE_RSA;
  815|  1.97k|    } else if (strcmp(name, "ssh-rsa") == 0) {
  ------------------
  |  Branch (815:16): [True: 0, False: 1.97k]
  ------------------
  816|      0|        return SSH_KEYTYPE_RSA;
  817|  1.97k|    } else if (strcmp(name, "ssh-ecdsa") == 0
  ------------------
  |  Branch (817:16): [True: 0, False: 1.97k]
  ------------------
  818|  1.97k|            || strcmp(name, "ecdsa") == 0
  ------------------
  |  Branch (818:16): [True: 0, False: 1.97k]
  ------------------
  819|  1.97k|            || strcmp(name, "ecdsa-sha2-nistp256") == 0) {
  ------------------
  |  Branch (819:16): [True: 0, False: 1.97k]
  ------------------
  820|      0|        return SSH_KEYTYPE_ECDSA_P256;
  821|  1.97k|    } else if (strcmp(name, "ecdsa-sha2-nistp384") == 0) {
  ------------------
  |  Branch (821:16): [True: 0, False: 1.97k]
  ------------------
  822|      0|        return SSH_KEYTYPE_ECDSA_P384;
  823|  1.97k|    } else if (strcmp(name, "ecdsa-sha2-nistp521") == 0) {
  ------------------
  |  Branch (823:16): [True: 0, False: 1.97k]
  ------------------
  824|      0|        return SSH_KEYTYPE_ECDSA_P521;
  825|  1.97k|    } else if (strcmp(name, "ssh-ed25519") == 0){
  ------------------
  |  Branch (825:16): [True: 1.97k, False: 0]
  ------------------
  826|  1.97k|        return SSH_KEYTYPE_ED25519;
  827|  1.97k|    } else if (strcmp(name, "ssh-rsa-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (827:16): [True: 0, False: 0]
  ------------------
  828|      0|        return SSH_KEYTYPE_RSA_CERT01;
  829|      0|    } else if (strcmp(name, "ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (829:16): [True: 0, False: 0]
  ------------------
  830|      0|        return SSH_KEYTYPE_ECDSA_P256_CERT01;
  831|      0|    } else if (strcmp(name, "ecdsa-sha2-nistp384-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (831:16): [True: 0, False: 0]
  ------------------
  832|      0|        return SSH_KEYTYPE_ECDSA_P384_CERT01;
  833|      0|    } else if (strcmp(name, "ecdsa-sha2-nistp521-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (833:16): [True: 0, False: 0]
  ------------------
  834|      0|        return SSH_KEYTYPE_ECDSA_P521_CERT01;
  835|      0|    } else if (strcmp(name, "ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (835:16): [True: 0, False: 0]
  ------------------
  836|      0|        return SSH_KEYTYPE_ED25519_CERT01;
  837|      0|    } else if(strcmp(name, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (837:15): [True: 0, False: 0]
  ------------------
  838|      0|        return SSH_KEYTYPE_SK_ECDSA;
  839|      0|    } else if(strcmp(name, "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (839:15): [True: 0, False: 0]
  ------------------
  840|      0|        return SSH_KEYTYPE_SK_ECDSA_CERT01;
  841|      0|    } else if(strcmp(name, "sk-ssh-ed25519@openssh.com") == 0) {
  ------------------
  |  Branch (841:15): [True: 0, False: 0]
  ------------------
  842|      0|        return SSH_KEYTYPE_SK_ED25519;
  843|      0|    } else if(strcmp(name, "sk-ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (843:15): [True: 0, False: 0]
  ------------------
  844|      0|        return SSH_KEYTYPE_SK_ED25519_CERT01;
  845|      0|    }
  846|       |
  847|      0|    return SSH_KEYTYPE_UNKNOWN;
  848|  1.97k|}
ssh_key_type_plain:
  858|  1.31k|{
  859|  1.31k|    switch (type) {
  860|      0|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (860:9): [True: 0, False: 1.31k]
  ------------------
  861|      0|            return SSH_KEYTYPE_RSA;
  862|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (862:9): [True: 0, False: 1.31k]
  ------------------
  863|      0|            return SSH_KEYTYPE_ECDSA_P256;
  864|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (864:9): [True: 0, False: 1.31k]
  ------------------
  865|      0|            return SSH_KEYTYPE_ECDSA_P384;
  866|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (866:9): [True: 0, False: 1.31k]
  ------------------
  867|      0|            return SSH_KEYTYPE_ECDSA_P521;
  868|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (868:9): [True: 0, False: 1.31k]
  ------------------
  869|      0|            return SSH_KEYTYPE_ED25519;
  870|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (870:9): [True: 0, False: 1.31k]
  ------------------
  871|      0|            return SSH_KEYTYPE_SK_ECDSA;
  872|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (872:9): [True: 0, False: 1.31k]
  ------------------
  873|      0|            return SSH_KEYTYPE_SK_ED25519;
  874|  1.31k|        default:
  ------------------
  |  Branch (874:9): [True: 1.31k, False: 0]
  ------------------
  875|  1.31k|            return type;
  876|  1.31k|    }
  877|  1.31k|}
ssh_key_is_private:
  902|  2.62k|int ssh_key_is_private(const ssh_key k) {
  903|  2.62k|    if (k == NULL) {
  ------------------
  |  Branch (903:9): [True: 0, False: 2.62k]
  ------------------
  904|      0|        return 0;
  905|      0|    }
  906|       |
  907|  2.62k|    return (k->flags & SSH_KEY_FLAG_PRIVATE) == SSH_KEY_FLAG_PRIVATE;
  ------------------
  |  |   55|  2.62k|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
                  return (k->flags & SSH_KEY_FLAG_PRIVATE) == SSH_KEY_FLAG_PRIVATE;
  ------------------
  |  |   55|  2.62k|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
  908|  2.62k|}
ssh_signature_new:
  997|  1.31k|{
  998|  1.31k|    struct ssh_signature_struct *sig = NULL;
  999|       |
 1000|  1.31k|    sig = calloc(1, sizeof(struct ssh_signature_struct));
 1001|  1.31k|    if (sig == NULL) {
  ------------------
  |  Branch (1001:9): [True: 0, False: 1.31k]
  ------------------
 1002|      0|        return NULL;
 1003|      0|    }
 1004|       |
 1005|  1.31k|    return sig;
 1006|  1.31k|}
ssh_signature_free:
 1009|  1.31k|{
 1010|  1.31k|    if (sig == NULL) {
  ------------------
  |  Branch (1010:9): [True: 0, False: 1.31k]
  ------------------
 1011|      0|        return;
 1012|      0|    }
 1013|       |
 1014|  1.31k|    switch(sig->type) {
  ------------------
  |  Branch (1014:12): [True: 1.31k, False: 0]
  ------------------
 1015|      0|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1015:9): [True: 0, False: 1.31k]
  ------------------
 1016|       |#ifdef HAVE_LIBMBEDCRYPTO
 1017|       |            SAFE_FREE(sig->rsa_sig);
 1018|       |#endif /* HAVE_LIBMBEDCRYPTO */
 1019|      0|            break;
 1020|      0|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1020:9): [True: 0, False: 1.31k]
  ------------------
 1021|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1021:9): [True: 0, False: 1.31k]
  ------------------
 1022|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1022:9): [True: 0, False: 1.31k]
  ------------------
 1023|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1023:9): [True: 0, False: 1.31k]
  ------------------
 1024|       |#ifdef HAVE_GCRYPT_ECC
 1025|       |            gcry_sexp_release(sig->ecdsa_sig);
 1026|       |#elif defined HAVE_LIBMBEDCRYPTO
 1027|       |            bignum_safe_free(sig->ecdsa_sig.r);
 1028|       |            bignum_safe_free(sig->ecdsa_sig.s);
 1029|       |#endif /* HAVE_GCRYPT_ECC */
 1030|      0|            break;
 1031|  1.31k|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1031:9): [True: 1.31k, False: 0]
  ------------------
 1032|  1.31k|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1032:9): [True: 0, False: 1.31k]
  ------------------
 1033|       |#ifndef HAVE_LIBCRYPTO
 1034|       |            /* When using OpenSSL, the signature is stored in sig->raw_sig */
 1035|       |            SAFE_FREE(sig->ed25519_sig);
 1036|       |#endif /* HAVE_LIBCRYPTO */
 1037|  1.31k|            break;
 1038|      0|        case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (1038:9): [True: 0, False: 1.31k]
  ------------------
 1039|      0|        case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (1039:9): [True: 0, False: 1.31k]
  ------------------
 1040|      0|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1040:9): [True: 0, False: 1.31k]
  ------------------
 1041|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1041:9): [True: 0, False: 1.31k]
  ------------------
 1042|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1042:9): [True: 0, False: 1.31k]
  ------------------
 1043|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1043:9): [True: 0, False: 1.31k]
  ------------------
 1044|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1044:9): [True: 0, False: 1.31k]
  ------------------
 1045|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1045:9): [True: 0, False: 1.31k]
  ------------------
 1046|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1046:9): [True: 0, False: 1.31k]
  ------------------
 1047|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1047:9): [True: 0, False: 1.31k]
  ------------------
 1048|      0|        case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (1048:9): [True: 0, False: 1.31k]
  ------------------
 1049|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1049:9): [True: 0, False: 1.31k]
  ------------------
 1050|      0|            break;
 1051|  1.31k|    }
 1052|       |
 1053|       |    /* Explicitly zero the signature content before free */
 1054|  1.31k|    ssh_string_burn(sig->raw_sig);
 1055|  1.31k|    SSH_STRING_FREE(sig->raw_sig);
  ------------------
  |  |  910|  1.31k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 1.31k, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 1056|       |    SAFE_FREE(sig);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 1057|  1.31k|}
ssh_pki_import_privkey_base64:
 1082|    657|{
 1083|    657|    ssh_key key = NULL;
 1084|    657|    const char *openssh_header = NULL;
 1085|       |
 1086|    657|    if (b64_key == NULL || pkey == NULL) {
  ------------------
  |  Branch (1086:9): [True: 0, False: 657]
  |  Branch (1086:28): [True: 0, False: 657]
  ------------------
 1087|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1088|      0|    }
 1089|       |
 1090|    657|    if (b64_key == NULL || !*b64_key) {
  ------------------
  |  Branch (1090:9): [True: 0, False: 657]
  |  Branch (1090:28): [True: 0, False: 657]
  ------------------
 1091|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1092|      0|    }
 1093|       |
 1094|    657|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|  1.31k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 657]
  |  |  ------------------
  ------------------
 1095|    657|            "Trying to decode privkey passphrase=%s",
 1096|    657|            passphrase ? "true" : "false");
 1097|       |
 1098|       |    /* Test for OpenSSH key format first */
 1099|    657|    openssh_header = strstr(b64_key, OPENSSH_HEADER_BEGIN);
  ------------------
  |  |   43|    657|#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
  ------------------
 1100|    657|    if (openssh_header != NULL) {
  ------------------
  |  Branch (1100:9): [True: 657, False: 0]
  ------------------
 1101|    657|        key = ssh_pki_openssh_privkey_import(openssh_header,
 1102|    657|                                             passphrase,
 1103|    657|                                             auth_fn,
 1104|    657|                                             auth_data);
 1105|    657|    } else {
 1106|       |        /* fallback on PEM decoder */
 1107|      0|        key = pki_private_key_from_base64(b64_key,
 1108|      0|                                          passphrase,
 1109|      0|                                          auth_fn,
 1110|      0|                                          auth_data);
 1111|      0|    }
 1112|    657|    if (key == NULL) {
  ------------------
  |  Branch (1112:9): [True: 0, False: 657]
  ------------------
 1113|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1114|      0|    }
 1115|       |
 1116|    657|    *pkey = key;
 1117|       |
 1118|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
 1119|    657|}
ssh_pki_import_privkey_file:
 1266|    657|                                ssh_key *pkey) {
 1267|    657|    struct stat sb;
 1268|    657|    char *key_buf = NULL;
 1269|    657|    FILE *file = NULL;
 1270|    657|    off_t size;
 1271|    657|    int rc;
 1272|       |
 1273|    657|    if (pkey == NULL || filename == NULL || *filename == '\0') {
  ------------------
  |  Branch (1273:9): [True: 0, False: 657]
  |  Branch (1273:25): [True: 0, False: 657]
  |  Branch (1273:45): [True: 0, False: 657]
  ------------------
 1274|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1275|      0|    }
 1276|       |
 1277|       |#ifdef WITH_PKCS11_URI
 1278|       |    if (ssh_pki_is_uri(filename)) {
 1279|       |        rc = pki_uri_import(filename, pkey, SSH_KEY_PRIVATE);
 1280|       |        return rc;
 1281|       |    }
 1282|       |#endif /* WITH_PKCS11_URI */
 1283|       |
 1284|    657|    file = fopen(filename, "rb");
 1285|    657|    if (file == NULL) {
  ------------------
  |  Branch (1285:9): [True: 0, False: 657]
  ------------------
 1286|      0|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    do {                                                            \
  |  |  284|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|      0|        _ssh_log(priority,                                          \
  |  |  286|      0|                 __func__,                                          \
  |  |  287|      0|                 __VA_ARGS__,                                       \
  |  |  288|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1287|      0|                         errno,
 1288|      0|                         "Error opening %s: %s",
 1289|      0|                         filename);
 1290|      0|        return SSH_EOF;
  ------------------
  |  |  319|      0|#define SSH_EOF -127 /* We have already a eof */
  ------------------
 1291|      0|    }
 1292|       |
 1293|    657|    rc = fstat(fileno(file), &sb);
 1294|    657|    if (rc < 0) {
  ------------------
  |  Branch (1294:9): [True: 0, False: 657]
  ------------------
 1295|      0|        fclose(file);
 1296|      0|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    do {                                                            \
  |  |  284|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|      0|        _ssh_log(priority,                                          \
  |  |  286|      0|                 __func__,                                          \
  |  |  287|      0|                 __VA_ARGS__,                                       \
  |  |  288|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1297|      0|                         errno,
 1298|      0|                         "Error getting fstat of %s: %s",
 1299|      0|                         filename);
 1300|      0|        switch (errno) {
  ------------------
  |  Branch (1300:17): [True: 0, False: 0]
  ------------------
 1301|      0|            case ENOENT:
  ------------------
  |  Branch (1301:13): [True: 0, False: 0]
  ------------------
 1302|      0|            case EACCES:
  ------------------
  |  Branch (1302:13): [True: 0, False: 0]
  ------------------
 1303|      0|                return SSH_EOF;
  ------------------
  |  |  319|      0|#define SSH_EOF -127 /* We have already a eof */
  ------------------
 1304|      0|        }
 1305|       |
 1306|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1307|      0|    }
 1308|       |
 1309|    657|    if (sb.st_size > MAX_PRIVKEY_SIZE) {
  ------------------
  |  |   47|    657|#define MAX_PRIVKEY_SIZE 0x400000 /* 4M */
  ------------------
  |  Branch (1309:9): [True: 0, False: 657]
  ------------------
 1310|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1311|      0|                "Private key is bigger than 4M.");
 1312|      0|        fclose(file);
 1313|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1314|      0|    }
 1315|       |
 1316|    657|    key_buf = malloc(sb.st_size + 1);
 1317|    657|    if (key_buf == NULL) {
  ------------------
  |  Branch (1317:9): [True: 0, False: 657]
  ------------------
 1318|      0|        fclose(file);
 1319|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1320|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1321|      0|    }
 1322|       |
 1323|    657|    size = fread(key_buf, 1, sb.st_size, file);
 1324|    657|    fclose(file);
 1325|       |
 1326|    657|    if (size != sb.st_size) {
  ------------------
  |  Branch (1326:9): [True: 0, False: 657]
  ------------------
 1327|      0|        SAFE_FREE(key_buf);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1328|      0|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    do {                                                            \
  |  |  284|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|      0|        _ssh_log(priority,                                          \
  |  |  286|      0|                 __func__,                                          \
  |  |  287|      0|                 __VA_ARGS__,                                       \
  |  |  288|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1329|      0|                         errno,
 1330|      0|                         "Error reading %s: %s",
 1331|      0|                         filename);
 1332|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1333|      0|    }
 1334|    657|    key_buf[size] = 0;
 1335|       |
 1336|    657|    rc = ssh_pki_import_privkey_base64(key_buf,
 1337|    657|                                       passphrase,
 1338|    657|                                       auth_fn,
 1339|    657|                                       auth_data,
 1340|    657|                                       pkey);
 1341|       |
 1342|       |    SAFE_FREE(key_buf);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
 1343|    657|    return rc;
 1344|    657|}
pki_import_privkey_buffer:
 1537|    657|{
 1538|    657|    ssh_key key = NULL;
 1539|    657|    int rc;
 1540|       |
 1541|    657|    key = ssh_key_new();
 1542|    657|    if (key == NULL) {
  ------------------
  |  Branch (1542:9): [True: 0, False: 657]
  ------------------
 1543|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1544|      0|    }
 1545|       |
 1546|    657|    key->type = type;
 1547|    657|    key->type_c = ssh_key_type_to_char(type);
 1548|    657|    key->flags = SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   55|    657|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
                  key->flags = SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   54|    657|#define SSH_KEY_FLAG_PUBLIC  0x0001
  ------------------
 1549|       |
 1550|    657|    switch (type) {
 1551|      0|    case SSH_KEYTYPE_RSA: {
  ------------------
  |  Branch (1551:5): [True: 0, False: 657]
  ------------------
 1552|      0|        ssh_string n = NULL;
 1553|      0|        ssh_string e = NULL;
 1554|      0|        ssh_string d = NULL;
 1555|      0|        ssh_string iqmp = NULL;
 1556|      0|        ssh_string p = NULL;
 1557|      0|        ssh_string q = NULL;
 1558|       |
 1559|      0|        rc = ssh_buffer_unpack(buffer, "SSSSSS", &n, &e, &d, &iqmp, &p, &q);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1560|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1560:13): [True: 0, False: 0]
  ------------------
 1561|      0|            SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1562|      0|            goto fail;
 1563|      0|        }
 1564|       |
 1565|      0|        rc = pki_privkey_build_rsa(key, n, e, d, iqmp, p, q);
 1566|       |#ifdef DEBUG_CRYPTO
 1567|       |        ssh_log_hexdump("n", ssh_string_data(n), ssh_string_len(n));
 1568|       |        ssh_log_hexdump("e", ssh_string_data(e), ssh_string_len(e));
 1569|       |        ssh_log_hexdump("d", ssh_string_data(d), ssh_string_len(d));
 1570|       |        ssh_log_hexdump("iqmp", ssh_string_data(iqmp), ssh_string_len(iqmp));
 1571|       |        ssh_log_hexdump("p", ssh_string_data(p), ssh_string_len(p));
 1572|       |        ssh_log_hexdump("q", ssh_string_data(q), ssh_string_len(q));
 1573|       |#endif /* DEBUG_CRYPTO */
 1574|      0|        ssh_string_burn(n);
 1575|      0|        SSH_STRING_FREE(n);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1576|      0|        ssh_string_burn(e);
 1577|      0|        SSH_STRING_FREE(e);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1578|      0|        ssh_string_burn(d);
 1579|      0|        SSH_STRING_FREE(d);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1580|      0|        ssh_string_burn(iqmp);
 1581|      0|        SSH_STRING_FREE(iqmp);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1582|      0|        ssh_string_burn(p);
 1583|      0|        SSH_STRING_FREE(p);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1584|      0|        ssh_string_burn(q);
 1585|      0|        SSH_STRING_FREE(q);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1586|      0|        if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1586:13): [True: 0, False: 0]
  ------------------
 1587|      0|            SSH_LOG(SSH_LOG_TRACE, "Failed to build RSA private key");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1588|      0|            goto fail;
 1589|      0|        }
 1590|      0|        break;
 1591|      0|    }
 1592|      0|#ifdef HAVE_ECC
 1593|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1593:5): [True: 0, False: 657]
  ------------------
 1594|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1594:5): [True: 0, False: 657]
  ------------------
 1595|      0|    case SSH_KEYTYPE_ECDSA_P521: {
  ------------------
  |  Branch (1595:5): [True: 0, False: 657]
  ------------------
 1596|      0|        ssh_string e = NULL;
 1597|      0|        ssh_string exp = NULL;
 1598|      0|        ssh_string i = NULL;
 1599|      0|        int nid;
 1600|       |
 1601|      0|        rc = ssh_buffer_unpack(buffer, "SSS", &i, &e, &exp);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1602|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1602:13): [True: 0, False: 0]
  ------------------
 1603|      0|            SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1604|      0|            goto fail;
 1605|      0|        }
 1606|       |
 1607|      0|        nid = pki_key_ecdsa_nid_from_name(ssh_string_get_char(i));
 1608|      0|        SSH_STRING_FREE(i);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1609|      0|        if (nid == -1) {
  ------------------
  |  Branch (1609:13): [True: 0, False: 0]
  ------------------
 1610|      0|            ssh_string_burn(e);
 1611|      0|            SSH_STRING_FREE(e);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1612|      0|            ssh_string_burn(exp);
 1613|      0|            SSH_STRING_FREE(exp);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1614|      0|            goto fail;
 1615|      0|        }
 1616|       |
 1617|      0|        rc = pki_privkey_build_ecdsa(key, nid, e, exp);
 1618|      0|        ssh_string_burn(e);
 1619|      0|        SSH_STRING_FREE(e);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1620|      0|        ssh_string_burn(exp);
 1621|      0|        SSH_STRING_FREE(exp);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1622|      0|        if (rc < 0) {
  ------------------
  |  Branch (1622:13): [True: 0, False: 0]
  ------------------
 1623|      0|            SSH_LOG(SSH_LOG_TRACE, "Failed to build ECDSA private key");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1624|      0|            goto fail;
 1625|      0|        }
 1626|      0|        break;
 1627|      0|    }
 1628|      0|    case SSH_KEYTYPE_SK_ECDSA: {
  ------------------
  |  Branch (1628:5): [True: 0, False: 657]
  ------------------
 1629|      0|        ssh_string type_str = NULL;
 1630|      0|        ssh_string pubkey = NULL;
 1631|      0|        int nid;
 1632|       |
 1633|      0|        rc = ssh_buffer_unpack(buffer, "SS", &type_str, &pubkey);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1634|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1634:13): [True: 0, False: 0]
  ------------------
 1635|      0|            goto fail;
 1636|      0|        }
 1637|       |
 1638|      0|        rc = pki_buffer_unpack_sk_priv_data(buffer, key);
 1639|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1639:13): [True: 0, False: 0]
  ------------------
 1640|      0|            SSH_STRING_FREE(type_str);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1641|      0|            SSH_STRING_FREE(pubkey);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1642|      0|            goto fail;
 1643|      0|        }
 1644|       |
 1645|      0|        nid = pki_key_ecdsa_nid_from_name(ssh_string_get_char(type_str));
 1646|      0|        SSH_STRING_FREE(type_str);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1647|       |
 1648|      0|        if (nid == -1) {
  ------------------
  |  Branch (1648:13): [True: 0, False: 0]
  ------------------
 1649|      0|            SSH_STRING_FREE(pubkey);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1650|      0|            goto fail;
 1651|      0|        }
 1652|       |
 1653|      0|        rc = pki_pubkey_build_ecdsa(key, nid, pubkey);
 1654|      0|        SSH_STRING_FREE(pubkey);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1655|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1655:13): [True: 0, False: 0]
  ------------------
 1656|      0|            goto fail;
 1657|      0|        }
 1658|      0|        break;
 1659|      0|    }
 1660|      0|#endif /* HAVE_ECC */
 1661|    657|    case SSH_KEYTYPE_ED25519: {
  ------------------
  |  Branch (1661:5): [True: 657, False: 0]
  ------------------
 1662|    657|        ssh_string pubkey = NULL, privkey = NULL;
 1663|       |
 1664|    657|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|    657|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 657]
  |  |  ------------------
  ------------------
 1665|      0|            SSH_LOG(SSH_LOG_TRACE, "Ed25519 keys not supported in FIPS mode");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1666|      0|            goto fail;
 1667|      0|        }
 1668|       |
 1669|    657|        rc = ssh_buffer_unpack(buffer, "SS", &pubkey, &privkey);
  ------------------
  |  |   60|    657|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1670|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1670:13): [True: 0, False: 657]
  ------------------
 1671|      0|            SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1672|      0|            goto fail;
 1673|      0|        }
 1674|       |
 1675|    657|        rc = pki_privkey_build_ed25519(key, pubkey, privkey);
 1676|    657|        ssh_string_burn(privkey);
 1677|    657|        SSH_STRING_FREE(privkey);
  ------------------
  |  |  910|    657|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 657, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
 1678|    657|        SSH_STRING_FREE(pubkey);
  ------------------
  |  |  910|    657|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 657, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
 1679|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1679:13): [True: 0, False: 657]
  ------------------
 1680|      0|            SSH_LOG(SSH_LOG_TRACE, "Failed to build ed25519 key");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1681|      0|            goto fail;
 1682|      0|        }
 1683|    657|        break;
 1684|    657|    }
 1685|    657|    case SSH_KEYTYPE_SK_ED25519: {
  ------------------
  |  Branch (1685:5): [True: 0, False: 657]
  ------------------
 1686|      0|        ssh_string pubkey = NULL;
 1687|       |
 1688|      0|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|      0|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1689|      0|            SSH_LOG(SSH_LOG_TRACE, "Ed25519 keys not supported in FIPS mode");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1690|      0|            goto fail;
 1691|      0|        }
 1692|       |
 1693|      0|        rc = ssh_buffer_unpack(buffer, "S", &pubkey);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1694|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1694:13): [True: 0, False: 0]
  ------------------
 1695|      0|            goto fail;
 1696|      0|        }
 1697|       |
 1698|      0|        rc = pki_buffer_unpack_sk_priv_data(buffer, key);
 1699|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1699:13): [True: 0, False: 0]
  ------------------
 1700|      0|            SSH_STRING_FREE(pubkey);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1701|      0|            goto fail;
 1702|      0|        }
 1703|       |
 1704|      0|        rc = pki_pubkey_build_ed25519(key, pubkey);
 1705|      0|        SSH_STRING_FREE(pubkey);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1706|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1706:13): [True: 0, False: 0]
  ------------------
 1707|      0|            goto fail;
 1708|      0|        }
 1709|      0|        break;
 1710|      0|    }
 1711|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1711:5): [True: 0, False: 657]
  ------------------
 1712|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1712:5): [True: 0, False: 657]
  ------------------
 1713|      0|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1713:5): [True: 0, False: 657]
  ------------------
 1714|      0|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1714:5): [True: 0, False: 657]
  ------------------
 1715|      0|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1715:5): [True: 0, False: 657]
  ------------------
 1716|      0|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1716:5): [True: 0, False: 657]
  ------------------
 1717|      0|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1717:5): [True: 0, False: 657]
  ------------------
 1718|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1718:5): [True: 0, False: 657]
  ------------------
 1719|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1719:5): [True: 0, False: 657]
  ------------------
 1720|      0|    default:
  ------------------
  |  Branch (1720:5): [True: 0, False: 657]
  ------------------
 1721|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown private key type (%d)", type);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1722|      0|        goto fail;
 1723|    657|    }
 1724|       |
 1725|    657|    *pkey = key;
 1726|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
 1727|      0|fail:
 1728|      0|    ssh_key_free(key);
 1729|       |
 1730|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1731|    657|}
ssh_pki_import_pubkey_blob:
 2027|  1.31k|{
 2028|  1.31k|    ssh_buffer buffer = NULL;
 2029|  1.31k|    ssh_string type_s = NULL;
 2030|  1.31k|    enum ssh_keytypes_e type;
 2031|  1.31k|    int rc;
 2032|       |
 2033|  1.31k|    if (key_blob == NULL || pkey == NULL) {
  ------------------
  |  Branch (2033:9): [True: 0, False: 1.31k]
  |  Branch (2033:29): [True: 0, False: 1.31k]
  ------------------
 2034|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2035|      0|    }
 2036|       |
 2037|  1.31k|    buffer = ssh_buffer_new();
 2038|  1.31k|    if (buffer == NULL) {
  ------------------
  |  Branch (2038:9): [True: 0, False: 1.31k]
  ------------------
 2039|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2040|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2041|      0|    }
 2042|       |
 2043|  1.31k|    rc = ssh_buffer_add_data(buffer,
 2044|  1.31k|                             ssh_string_data(key_blob),
 2045|  1.31k|                             (uint32_t)ssh_string_len(key_blob));
 2046|  1.31k|    if (rc < 0) {
  ------------------
  |  Branch (2046:9): [True: 0, False: 1.31k]
  ------------------
 2047|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2048|      0|        goto fail;
 2049|      0|    }
 2050|       |
 2051|  1.31k|    type_s = ssh_buffer_get_ssh_string(buffer);
 2052|  1.31k|    if (type_s == NULL) {
  ------------------
  |  Branch (2052:9): [True: 0, False: 1.31k]
  ------------------
 2053|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2054|      0|        goto fail;
 2055|      0|    }
 2056|       |
 2057|  1.31k|    type = ssh_key_type_from_name(ssh_string_get_char(type_s));
 2058|  1.31k|    if (type == SSH_KEYTYPE_UNKNOWN) {
  ------------------
  |  Branch (2058:9): [True: 0, False: 1.31k]
  ------------------
 2059|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown key type found!");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2060|      0|        goto fail;
 2061|      0|    }
 2062|  1.31k|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  910|  1.31k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 1.31k, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 2063|       |
 2064|  1.31k|    if (is_cert_type(type)) {
  ------------------
  |  |  146|  1.31k|    ((kt) == SSH_KEYTYPE_RSA_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (146:6): [True: 0, False: 1.31k]
  |  |  ------------------
  |  |  147|  1.31k|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (147:6): [True: 0, False: 1.31k]
  |  |  ------------------
  |  |  148|  1.31k|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (148:6): [True: 0, False: 1.31k]
  |  |  ------------------
  |  |  149|  1.31k|    ((kt) >= SSH_KEYTYPE_ECDSA_P256_CERT01 &&\
  |  |  ------------------
  |  |  |  Branch (149:6): [True: 0, False: 1.31k]
  |  |  ------------------
  |  |  150|  1.31k|     (kt) <= SSH_KEYTYPE_ED25519_CERT01))
  |  |  ------------------
  |  |  |  Branch (150:6): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 2065|      0|        rc = pki_import_cert_buffer(buffer, type, pkey);
 2066|  1.31k|    } else {
 2067|  1.31k|        rc = pki_import_pubkey_buffer(buffer, type, pkey);
 2068|  1.31k|    }
 2069|       |
 2070|  1.31k|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|  1.31k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 1.31k, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 2071|       |
 2072|  1.31k|    return rc;
 2073|      0|fail:
 2074|      0|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2075|      0|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2076|       |
 2077|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2078|  1.31k|}
ssh_pki_export_privkey_to_pubkey:
 2570|    657|{
 2571|    657|    ssh_key pubkey = NULL;
 2572|       |
 2573|    657|    if (privkey == NULL || !ssh_key_is_private(privkey)) {
  ------------------
  |  Branch (2573:9): [True: 0, False: 657]
  |  Branch (2573:28): [True: 0, False: 657]
  ------------------
 2574|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2575|      0|    }
 2576|       |
 2577|    657|    pubkey = pki_key_dup(privkey, 1);
 2578|    657|    if (pubkey == NULL) {
  ------------------
  |  Branch (2578:9): [True: 0, False: 657]
  ------------------
 2579|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2580|      0|    }
 2581|       |
 2582|    657|    *pkey = pubkey;
 2583|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
 2584|    657|}
ssh_pki_export_pubkey_blob:
 2666|  2.62k|{
 2667|  2.62k|    ssh_string blob = NULL;
 2668|       |
 2669|  2.62k|    if (key == NULL) {
  ------------------
  |  Branch (2669:9): [True: 0, False: 2.62k]
  ------------------
 2670|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2671|      0|    }
 2672|       |
 2673|  2.62k|    blob = pki_key_to_blob(key, SSH_KEY_PUBLIC);
 2674|  2.62k|    if (blob == NULL) {
  ------------------
  |  Branch (2674:9): [True: 0, False: 2.62k]
  ------------------
 2675|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2676|      0|    }
 2677|       |
 2678|  2.62k|    *pblob = blob;
 2679|  2.62k|    return SSH_OK;
  ------------------
  |  |  316|  2.62k|#define SSH_OK 0     /* No error */
  ------------------
 2680|  2.62k|}
ssh_pki_export_signature_blob:
 2877|    657|{
 2878|    657|    ssh_buffer buf = NULL;
 2879|    657|    ssh_string str = NULL;
 2880|    657|    int rc;
 2881|       |
 2882|    657|    if (sig == NULL || sig_blob == NULL) {
  ------------------
  |  Branch (2882:9): [True: 0, False: 657]
  |  Branch (2882:24): [True: 0, False: 657]
  ------------------
 2883|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2884|      0|    }
 2885|       |
 2886|    657|    buf = ssh_buffer_new();
 2887|    657|    if (buf == NULL) {
  ------------------
  |  Branch (2887:9): [True: 0, False: 657]
  ------------------
 2888|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2889|      0|    }
 2890|       |
 2891|    657|    str = ssh_string_from_char(sig->type_c);
 2892|    657|    if (str == NULL) {
  ------------------
  |  Branch (2892:9): [True: 0, False: 657]
  ------------------
 2893|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2894|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2895|      0|    }
 2896|       |
 2897|    657|    rc = ssh_buffer_add_ssh_string(buf, str);
 2898|    657|    SSH_STRING_FREE(str);
  ------------------
  |  |  910|    657|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 657, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
 2899|    657|    if (rc < 0) {
  ------------------
  |  Branch (2899:9): [True: 0, False: 657]
  ------------------
 2900|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2901|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2902|      0|    }
 2903|       |
 2904|    657|    str = pki_signature_to_blob(sig);
 2905|    657|    if (str == NULL) {
  ------------------
  |  Branch (2905:9): [True: 0, False: 657]
  ------------------
 2906|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2907|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2908|      0|    }
 2909|       |
 2910|    657|    rc = ssh_buffer_add_ssh_string(buf, str);
 2911|    657|    SSH_STRING_FREE(str);
  ------------------
  |  |  910|    657|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 657, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
 2912|    657|    if (rc < 0) {
  ------------------
  |  Branch (2912:9): [True: 0, False: 657]
  ------------------
 2913|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2914|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2915|      0|    }
 2916|       |
 2917|    657|    if (is_sk_key_type(sig->type)) {
  ------------------
  |  |  153|    657|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 0, False: 657]
  |  |  |  Branch (153:38): [True: 0, False: 657]
  |  |  ------------------
  |  |  154|    657|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 657]
  |  |  ------------------
  |  |  155|    657|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 657]
  |  |  ------------------
  ------------------
 2918|       |        /* Add flags and counter for SK keys */
 2919|      0|        rc = ssh_buffer_pack(buf, "bd", sig->sk_flags, sig->sk_counter);
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 2920|      0|        if (rc < 0) {
  ------------------
  |  Branch (2920:13): [True: 0, False: 0]
  ------------------
 2921|      0|            SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2922|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2923|      0|        }
 2924|      0|    }
 2925|       |
 2926|    657|    str = ssh_string_new(ssh_buffer_get_len(buf));
 2927|    657|    if (str == NULL) {
  ------------------
  |  Branch (2927:9): [True: 0, False: 657]
  ------------------
 2928|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2929|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2930|      0|    }
 2931|       |
 2932|    657|    rc = ssh_string_fill(str, ssh_buffer_get(buf), ssh_buffer_get_len(buf));
 2933|    657|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|    657|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 657, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
 2934|    657|    if (rc < 0) {
  ------------------
  |  Branch (2934:9): [True: 0, False: 657]
  ------------------
 2935|      0|        SSH_STRING_FREE(str);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2936|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2937|      0|    }
 2938|       |
 2939|    657|    *sig_blob = str;
 2940|       |
 2941|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
 2942|    657|}
ssh_pki_import_signature_blob:
 2947|    657|{
 2948|    657|    ssh_signature sig = NULL;
 2949|    657|    enum ssh_keytypes_e type;
 2950|    657|    enum ssh_digest_e hash_type;
 2951|    657|    ssh_string algorithm = NULL, blob = NULL;
 2952|    657|    ssh_buffer buf = NULL;
 2953|    657|    const char *alg = NULL;
 2954|    657|    uint8_t flags = 0;
 2955|    657|    uint32_t counter = 0;
 2956|    657|    int rc;
 2957|       |
 2958|    657|    if (sig_blob == NULL || psig == NULL) {
  ------------------
  |  Branch (2958:9): [True: 0, False: 657]
  |  Branch (2958:29): [True: 0, False: 657]
  ------------------
 2959|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2960|      0|    }
 2961|       |
 2962|    657|    buf = ssh_buffer_new();
 2963|    657|    if (buf == NULL) {
  ------------------
  |  Branch (2963:9): [True: 0, False: 657]
  ------------------
 2964|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2965|      0|    }
 2966|       |
 2967|    657|    rc = ssh_buffer_add_data(buf,
 2968|    657|                             ssh_string_data(sig_blob),
 2969|    657|                             (uint32_t)ssh_string_len(sig_blob));
 2970|    657|    if (rc < 0) {
  ------------------
  |  Branch (2970:9): [True: 0, False: 657]
  ------------------
 2971|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2972|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2973|      0|    }
 2974|       |
 2975|    657|    algorithm = ssh_buffer_get_ssh_string(buf);
 2976|    657|    if (algorithm == NULL) {
  ------------------
  |  Branch (2976:9): [True: 0, False: 657]
  ------------------
 2977|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2978|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2979|      0|    }
 2980|       |
 2981|    657|    alg = ssh_string_get_char(algorithm);
 2982|    657|    rc = ssh_key_type_and_hash_from_signature_name(alg, &type, &hash_type);
 2983|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2983:9): [True: 0, False: 657]
  ------------------
 2984|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2985|      0|        SSH_STRING_FREE(algorithm);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2986|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2987|      0|    }
 2988|    657|    SSH_STRING_FREE(algorithm);
  ------------------
  |  |  910|    657|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 657, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
 2989|       |
 2990|    657|    blob = ssh_buffer_get_ssh_string(buf);
 2991|    657|    if (blob == NULL) {
  ------------------
  |  Branch (2991:9): [True: 0, False: 657]
  ------------------
 2992|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2993|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2994|      0|    }
 2995|       |
 2996|    657|    if (type == SSH_KEYTYPE_SK_ECDSA ||
  ------------------
  |  Branch (2996:9): [True: 0, False: 657]
  ------------------
 2997|    657|        type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (2997:9): [True: 0, False: 657]
  ------------------
 2998|      0|        rc = ssh_buffer_unpack(buf, "bd", &flags, &counter);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 2999|      0|        if (rc < 0) {
  ------------------
  |  Branch (2999:13): [True: 0, False: 0]
  ------------------
 3000|      0|            SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3001|      0|            SSH_STRING_FREE(blob);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3002|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3003|      0|        }
 3004|      0|    }
 3005|    657|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  951|    657|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 657, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
 3006|       |
 3007|    657|    sig = pki_signature_from_blob(pubkey, blob, type, hash_type);
 3008|    657|    SSH_STRING_FREE(blob);
  ------------------
  |  |  910|    657|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 657, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
 3009|    657|    if (sig == NULL) {
  ------------------
  |  Branch (3009:9): [True: 0, False: 657]
  ------------------
 3010|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3011|      0|    }
 3012|       |
 3013|       |    /* Set SK specific values */
 3014|    657|    sig->sk_flags = flags;
 3015|    657|    sig->sk_counter = counter;
 3016|       |
 3017|    657|    *psig = sig;
 3018|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
 3019|    657|}
pki_key_check_hash_compatible:
 3034|  2.62k|{
 3035|  2.62k|    if (key == NULL) {
  ------------------
  |  Branch (3035:9): [True: 0, False: 2.62k]
  ------------------
 3036|      0|        SSH_LOG(SSH_LOG_TRACE, "Null pointer provided as key to "
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3037|      0|                               "pki_key_check_hash_compatible()");
 3038|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3039|      0|    }
 3040|       |
 3041|  2.62k|    switch(key->type) {
  ------------------
  |  Branch (3041:12): [True: 2.62k, False: 0]
  ------------------
 3042|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (3042:5): [True: 0, False: 2.62k]
  ------------------
 3043|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (3043:5): [True: 0, False: 2.62k]
  ------------------
 3044|      0|        if (hash_type == SSH_DIGEST_SHA1) {
  ------------------
  |  Branch (3044:13): [True: 0, False: 0]
  ------------------
 3045|      0|            if (ssh_fips_mode()) {
  ------------------
  |  |  115|      0|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 3046|      0|                SSH_LOG(SSH_LOG_TRACE, "SHA1 is not allowed in FIPS mode");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3047|      0|                return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3048|      0|            } else {
 3049|      0|                return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 3050|      0|            }
 3051|      0|        }
 3052|       |
 3053|      0|        if (hash_type == SSH_DIGEST_SHA256 ||
  ------------------
  |  Branch (3053:13): [True: 0, False: 0]
  ------------------
 3054|      0|            hash_type == SSH_DIGEST_SHA512)
  ------------------
  |  Branch (3054:13): [True: 0, False: 0]
  ------------------
 3055|      0|        {
 3056|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 3057|      0|        }
 3058|      0|        break;
 3059|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (3059:5): [True: 0, False: 2.62k]
  ------------------
 3060|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (3060:5): [True: 0, False: 2.62k]
  ------------------
 3061|      0|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (3061:5): [True: 0, False: 2.62k]
  ------------------
 3062|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (3062:5): [True: 0, False: 2.62k]
  ------------------
 3063|      0|        if (hash_type == SSH_DIGEST_SHA256) {
  ------------------
  |  Branch (3063:13): [True: 0, False: 0]
  ------------------
 3064|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 3065|      0|        }
 3066|      0|        break;
 3067|      0|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (3067:5): [True: 0, False: 2.62k]
  ------------------
 3068|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (3068:5): [True: 0, False: 2.62k]
  ------------------
 3069|      0|        if (hash_type == SSH_DIGEST_SHA384) {
  ------------------
  |  Branch (3069:13): [True: 0, False: 0]
  ------------------
 3070|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 3071|      0|        }
 3072|      0|        break;
 3073|      0|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (3073:5): [True: 0, False: 2.62k]
  ------------------
 3074|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (3074:5): [True: 0, False: 2.62k]
  ------------------
 3075|      0|        if (hash_type == SSH_DIGEST_SHA512) {
  ------------------
  |  Branch (3075:13): [True: 0, False: 0]
  ------------------
 3076|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 3077|      0|        }
 3078|      0|        break;
 3079|      0|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (3079:5): [True: 0, False: 2.62k]
  ------------------
 3080|  2.62k|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (3080:5): [True: 2.62k, False: 0]
  ------------------
 3081|  2.62k|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (3081:5): [True: 0, False: 2.62k]
  ------------------
 3082|  2.62k|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (3082:5): [True: 0, False: 2.62k]
  ------------------
 3083|  2.62k|        if (hash_type == SSH_DIGEST_AUTO) {
  ------------------
  |  Branch (3083:13): [True: 2.62k, False: 0]
  ------------------
 3084|  2.62k|            return SSH_OK;
  ------------------
  |  |  316|  2.62k|#define SSH_OK 0     /* No error */
  ------------------
 3085|  2.62k|        }
 3086|      0|        break;
 3087|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (3087:5): [True: 0, False: 2.62k]
  ------------------
 3088|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (3088:5): [True: 0, False: 2.62k]
  ------------------
 3089|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (3089:5): [True: 0, False: 2.62k]
  ------------------
 3090|      0|    case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (3090:5): [True: 0, False: 2.62k]
  ------------------
 3091|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (3091:5): [True: 0, False: 2.62k]
  ------------------
 3092|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown key type %d", key->type);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3093|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3094|  2.62k|    }
 3095|       |
 3096|      0|    SSH_LOG(SSH_LOG_TRACE, "Key type %d incompatible with hash type  %d",
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3097|      0|            key->type, hash_type);
 3098|       |
 3099|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3100|  2.62k|}
ssh_pki_signature_verify:
 3190|    657|{
 3191|    657|    int rc;
 3192|    657|    bool allowed;
 3193|    657|    enum ssh_keytypes_e key_type;
 3194|       |
 3195|    657|    if (session == NULL || sig == NULL || key == NULL || input == NULL) {
  ------------------
  |  Branch (3195:9): [True: 0, False: 657]
  |  Branch (3195:28): [True: 0, False: 657]
  |  Branch (3195:43): [True: 0, False: 657]
  |  Branch (3195:58): [True: 0, False: 657]
  ------------------
 3196|      0|        SSH_LOG(SSH_LOG_TRACE, "Bad parameter(s) provided to %s()", __func__);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3197|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3198|      0|    }
 3199|    657|    key_type = ssh_key_type_plain(key->type);
 3200|       |
 3201|    657|    SSH_LOG(SSH_LOG_FUNCTIONS,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3202|    657|            "Going to verify a %s type signature",
 3203|    657|            sig->type_c);
 3204|       |
 3205|    657|    if (key_type != sig->type) {
  ------------------
  |  Branch (3205:9): [True: 0, False: 657]
  ------------------
 3206|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3207|      0|                "Can not verify %s signature with %s key",
 3208|      0|                sig->type_c, key->type_c);
 3209|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3210|      0|    }
 3211|       |
 3212|    657|    allowed = ssh_key_size_allowed(session, key);
 3213|    657|    if (!allowed) {
  ------------------
  |  Branch (3213:9): [True: 0, False: 657]
  ------------------
 3214|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3215|      0|                      SSH_FATAL,
 3216|      0|                      "The '%s' key of size %d is not allowed by RSA_MIN_SIZE",
 3217|      0|                      key->type_c,
 3218|      0|                      ssh_key_size(key));
 3219|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3220|      0|    }
 3221|       |
 3222|       |    /* Check if public key and hash type are compatible */
 3223|    657|    rc = pki_key_check_hash_compatible(key, sig->hash_type);
 3224|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3224:9): [True: 0, False: 657]
  ------------------
 3225|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3226|      0|    }
 3227|       |
 3228|    657|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|    657|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 0, False: 657]
  |  |  |  Branch (153:38): [True: 0, False: 657]
  |  |  ------------------
  |  |  154|    657|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 657]
  |  |  ------------------
  |  |  155|    657|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 657]
  |  |  ------------------
  ------------------
 3229|      0|        ssh_buffer sk_buffer = NULL;
 3230|       |
 3231|      0|        rc = pki_sk_signature_buffer_prepare(key,
 3232|      0|                                             sig,
 3233|      0|                                             input,
 3234|      0|                                             input_len,
 3235|      0|                                             &sk_buffer);
 3236|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3236:13): [True: 0, False: 0]
  ------------------
 3237|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3238|      0|        }
 3239|       |
 3240|      0|        rc = pki_verify_data_signature(sig,
 3241|      0|                                       key,
 3242|      0|                                       ssh_buffer_get(sk_buffer),
 3243|      0|                                       ssh_buffer_get_len(sk_buffer));
 3244|      0|        SSH_BUFFER_FREE(sk_buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3245|      0|        return rc;
 3246|      0|    }
 3247|       |
 3248|    657|    return pki_verify_data_signature(sig, key, input, input_len);
 3249|    657|}
pki_do_sign:
 3255|    657|{
 3256|    657|    int rc;
 3257|       |
 3258|    657|    if (privkey == NULL || input == NULL) {
  ------------------
  |  Branch (3258:9): [True: 0, False: 657]
  |  Branch (3258:28): [True: 0, False: 657]
  ------------------
 3259|      0|        SSH_LOG(SSH_LOG_TRACE, "Bad parameter provided to "
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3260|      0|                               "pki_do_sign()");
 3261|      0|        return NULL;
 3262|      0|    }
 3263|       |
 3264|       |    /* Check if public key and hash type are compatible */
 3265|    657|    rc = pki_key_check_hash_compatible(privkey, hash_type);
 3266|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3266:9): [True: 0, False: 657]
  ------------------
 3267|      0|        return NULL;
 3268|      0|    }
 3269|       |
 3270|    657|    return pki_sign_data(privkey, hash_type, input, input_len);
 3271|    657|}
ssh_srv_pki_do_sign_sessionid:
 4027|    657|{
 4028|    657|    struct ssh_crypto_struct *crypto = NULL;
 4029|    657|    bool allowed;
 4030|    657|    ssh_signature sig = NULL;
 4031|    657|    ssh_string sig_blob = NULL;
 4032|       |
 4033|    657|    ssh_buffer sign_input = NULL;
 4034|       |
 4035|    657|    int rc;
 4036|       |
 4037|    657|    if (session == NULL || privkey == NULL || !ssh_key_is_private(privkey)) {
  ------------------
  |  Branch (4037:9): [True: 0, False: 657]
  |  Branch (4037:28): [True: 0, False: 657]
  |  Branch (4037:47): [True: 0, False: 657]
  ------------------
 4038|      0|        return NULL;
 4039|      0|    }
 4040|       |
 4041|    657|    allowed = ssh_key_size_allowed(session, privkey);
 4042|    657|    if (!allowed) {
  ------------------
  |  Branch (4042:9): [True: 0, False: 657]
  ------------------
 4043|      0|        ssh_set_error(session, SSH_FATAL, "The hostkey size too small");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 4044|      0|        return NULL;
 4045|      0|    }
 4046|       |
 4047|    657|    crypto = session->next_crypto ? session->next_crypto :
  ------------------
  |  Branch (4047:14): [True: 657, False: 0]
  ------------------
 4048|    657|                                    session->current_crypto;
 4049|       |
 4050|    657|    if (crypto->secret_hash == NULL){
  ------------------
  |  Branch (4050:9): [True: 0, False: 657]
  ------------------
 4051|      0|        ssh_set_error(session, SSH_FATAL, "Missing secret_hash");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 4052|      0|        return NULL;
 4053|      0|    }
 4054|       |
 4055|       |    /* Fill the input */
 4056|    657|    sign_input = ssh_buffer_new();
 4057|    657|    if (sign_input == NULL) {
  ------------------
  |  Branch (4057:9): [True: 0, False: 657]
  ------------------
 4058|      0|        goto end;
 4059|      0|    }
 4060|    657|    ssh_buffer_set_secure(sign_input);
 4061|       |
 4062|    657|    rc = ssh_buffer_pack(sign_input,
  ------------------
  |  |   50|    657|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 4063|    657|                         "P",
 4064|    657|                         crypto->digest_len,
 4065|    657|                         crypto->secret_hash);
 4066|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (4066:9): [True: 0, False: 657]
  ------------------
 4067|      0|        goto end;
 4068|      0|    }
 4069|       |
 4070|       |    /* Generate the signature */
 4071|    657|    sig = pki_do_sign(privkey,
 4072|    657|                      ssh_buffer_get(sign_input),
 4073|    657|                      ssh_buffer_get_len(sign_input),
 4074|    657|                      digest);
 4075|    657|    if (sig == NULL) {
  ------------------
  |  Branch (4075:9): [True: 0, False: 657]
  ------------------
 4076|      0|        goto end;
 4077|      0|    }
 4078|       |
 4079|       |    /* Convert the signature to blob */
 4080|    657|    rc = ssh_pki_export_signature_blob(sig, &sig_blob);
 4081|    657|    if (rc < 0) {
  ------------------
  |  Branch (4081:9): [True: 0, False: 657]
  ------------------
 4082|      0|        sig_blob = NULL;
 4083|      0|    }
 4084|       |
 4085|    657|end:
 4086|    657|    ssh_signature_free(sig);
 4087|    657|    SSH_BUFFER_FREE(sign_input);
  ------------------
  |  |  951|    657|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 657, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
 4088|       |
 4089|    657|    return sig_blob;
 4090|    657|}
pki.c:pki_import_pubkey_buffer:
 1736|  1.31k|{
 1737|  1.31k|    ssh_key key = NULL;
 1738|  1.31k|    int rc;
 1739|       |
 1740|  1.31k|    key = ssh_key_new();
 1741|  1.31k|    if (key == NULL) {
  ------------------
  |  Branch (1741:9): [True: 0, False: 1.31k]
  ------------------
 1742|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1743|      0|    }
 1744|       |
 1745|  1.31k|    key->type = type;
 1746|  1.31k|    key->type_c = ssh_key_type_to_char(type);
 1747|  1.31k|    key->flags = SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   54|  1.31k|#define SSH_KEY_FLAG_PUBLIC  0x0001
  ------------------
 1748|       |
 1749|  1.31k|    switch (type) {
 1750|      0|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1750:9): [True: 0, False: 1.31k]
  ------------------
 1751|      0|            {
 1752|      0|                ssh_string e = NULL;
 1753|      0|                ssh_string n = NULL;
 1754|       |
 1755|      0|                rc = ssh_buffer_unpack(buffer, "SS", &e, &n);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1756|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1756:21): [True: 0, False: 0]
  ------------------
 1757|      0|                    SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1758|      0|                    goto fail;
 1759|      0|                }
 1760|       |
 1761|      0|                rc = pki_pubkey_build_rsa(key, e, n);
 1762|       |#ifdef DEBUG_CRYPTO
 1763|       |                ssh_log_hexdump("e", ssh_string_data(e), ssh_string_len(e));
 1764|       |                ssh_log_hexdump("n", ssh_string_data(n), ssh_string_len(n));
 1765|       |#endif /* DEBUG_CRYPTO */
 1766|      0|                ssh_string_burn(e);
 1767|      0|                SSH_STRING_FREE(e);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1768|      0|                ssh_string_burn(n);
 1769|      0|                SSH_STRING_FREE(n);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1770|      0|                if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1770:21): [True: 0, False: 0]
  ------------------
 1771|      0|                    SSH_LOG(SSH_LOG_TRACE, "Failed to build RSA public key");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1772|      0|                    goto fail;
 1773|      0|                }
 1774|      0|            }
 1775|      0|            break;
 1776|      0|#ifdef HAVE_ECC
 1777|      0|        case SSH_KEYTYPE_ECDSA: /* deprecated */
  ------------------
  |  Branch (1777:9): [True: 0, False: 1.31k]
  ------------------
 1778|      0|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1778:9): [True: 0, False: 1.31k]
  ------------------
 1779|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1779:9): [True: 0, False: 1.31k]
  ------------------
 1780|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1780:9): [True: 0, False: 1.31k]
  ------------------
 1781|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1781:9): [True: 0, False: 1.31k]
  ------------------
 1782|      0|            {
 1783|      0|                ssh_string e = NULL;
 1784|      0|                ssh_string i = NULL;
 1785|      0|                int nid;
 1786|       |
 1787|      0|                rc = ssh_buffer_unpack(buffer, "SS", &i, &e);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1788|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1788:21): [True: 0, False: 0]
  ------------------
 1789|      0|                    SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1790|      0|                    goto fail;
 1791|      0|                }
 1792|       |
 1793|      0|                nid = pki_key_ecdsa_nid_from_name(ssh_string_get_char(i));
 1794|      0|                SSH_STRING_FREE(i);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1795|      0|                if (nid == -1) {
  ------------------
  |  Branch (1795:21): [True: 0, False: 0]
  ------------------
 1796|      0|                    ssh_string_burn(e);
 1797|      0|                    SSH_STRING_FREE(e);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1798|      0|                    goto fail;
 1799|      0|                }
 1800|       |
 1801|      0|                rc = pki_pubkey_build_ecdsa(key, nid, e);
 1802|      0|                ssh_string_burn(e);
 1803|      0|                SSH_STRING_FREE(e);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1804|      0|                if (rc < 0) {
  ------------------
  |  Branch (1804:21): [True: 0, False: 0]
  ------------------
 1805|      0|                    SSH_LOG(SSH_LOG_TRACE, "Failed to build ECDSA public key");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1806|      0|                    goto fail;
 1807|      0|                }
 1808|       |
 1809|       |                /* Unpack SK specific parameters */
 1810|      0|                if (type == SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1810:21): [True: 0, False: 0]
  ------------------
 1811|      0|                    ssh_string application = ssh_buffer_get_ssh_string(buffer);
 1812|      0|                    if (application == NULL) {
  ------------------
  |  Branch (1812:25): [True: 0, False: 0]
  ------------------
 1813|      0|                        SSH_LOG(SSH_LOG_TRACE, "SK Unpack error");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1814|      0|                        goto fail;
 1815|      0|                    }
 1816|      0|                    key->sk_application = application;
 1817|      0|                    key->type_c = ssh_key_type_to_char(key->type);
 1818|      0|                }
 1819|      0|            }
 1820|      0|            break;
 1821|      0|#endif /* HAVE_ECC */
 1822|  1.31k|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1822:9): [True: 1.31k, False: 0]
  ------------------
 1823|  1.31k|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1823:9): [True: 0, False: 1.31k]
  ------------------
 1824|  1.31k|        {
 1825|  1.31k|            ssh_string pubkey = ssh_buffer_get_ssh_string(buffer);
 1826|       |
 1827|  1.31k|            if (ssh_string_len(pubkey) != ED25519_KEY_LEN) {
  ------------------
  |  |   44|  1.31k|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1827:17): [True: 0, False: 1.31k]
  ------------------
 1828|      0|                SSH_LOG(SSH_LOG_TRACE, "Invalid public key length");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1829|      0|                ssh_string_burn(pubkey);
 1830|      0|                SSH_STRING_FREE(pubkey);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1831|      0|                goto fail;
 1832|      0|            }
 1833|       |
 1834|  1.31k|            rc = pki_pubkey_build_ed25519(key, pubkey);
 1835|  1.31k|            ssh_string_burn(pubkey);
 1836|  1.31k|            SSH_STRING_FREE(pubkey);
  ------------------
  |  |  910|  1.31k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 1.31k, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
 1837|  1.31k|            if (rc < 0) {
  ------------------
  |  Branch (1837:17): [True: 0, False: 1.31k]
  ------------------
 1838|      0|                SSH_LOG(SSH_LOG_TRACE, "Failed to build ED25519 public key");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1839|      0|                goto fail;
 1840|      0|            }
 1841|       |
 1842|  1.31k|            if (type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1842:17): [True: 0, False: 1.31k]
  ------------------
 1843|      0|                ssh_string application = ssh_buffer_get_ssh_string(buffer);
 1844|      0|                if (application == NULL) {
  ------------------
  |  Branch (1844:21): [True: 0, False: 0]
  ------------------
 1845|      0|                    SSH_LOG(SSH_LOG_TRACE, "SK Unpack error");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1846|      0|                    goto fail;
 1847|      0|                }
 1848|      0|                key->sk_application = application;
 1849|      0|            }
 1850|  1.31k|        }
 1851|  1.31k|        break;
 1852|  1.31k|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1852:9): [True: 0, False: 1.31k]
  ------------------
 1853|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1853:9): [True: 0, False: 1.31k]
  ------------------
 1854|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1854:9): [True: 0, False: 1.31k]
  ------------------
 1855|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1855:9): [True: 0, False: 1.31k]
  ------------------
 1856|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1856:9): [True: 0, False: 1.31k]
  ------------------
 1857|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1857:9): [True: 0, False: 1.31k]
  ------------------
 1858|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1858:9): [True: 0, False: 1.31k]
  ------------------
 1859|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1859:9): [True: 0, False: 1.31k]
  ------------------
 1860|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1860:9): [True: 0, False: 1.31k]
  ------------------
 1861|      0|        default:
  ------------------
  |  Branch (1861:9): [True: 0, False: 1.31k]
  ------------------
 1862|      0|            SSH_LOG(SSH_LOG_TRACE, "Unknown public key type %d", type);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1863|      0|            goto fail;
 1864|  1.31k|    }
 1865|       |
 1866|  1.31k|    *pkey = key;
 1867|  1.31k|    return SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
 1868|      0|fail:
 1869|      0|    ssh_key_free(key);
 1870|       |
 1871|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1872|  1.31k|}

ssh_pki_openssh_privkey_import:
  387|    657|{
  388|       |    return ssh_pki_openssh_import(text_key, passphrase, auth_fn, auth_data, true);
  389|    657|}
pki_container_openssh.c:ssh_pki_openssh_import:
  235|    657|{
  236|    657|    const char *ptr = text_key;
  237|    657|    const char *end = NULL;
  238|    657|    char *base64 = NULL;
  239|    657|    int cmp;
  240|    657|    int rc;
  241|    657|    int i;
  242|    657|    ssh_buffer buffer = NULL, privkey_buffer = NULL;
  243|    657|    char *magic = NULL, *ciphername = NULL, *kdfname = NULL;
  244|    657|    uint32_t nkeys = 0, checkint1 = 0, checkint2 = 0xFFFF;
  245|    657|    ssh_string kdfoptions = NULL;
  246|    657|    ssh_string pubkey0 = NULL;
  247|    657|    ssh_string privkeys = NULL;
  248|    657|    ssh_string comment = NULL;
  249|    657|    ssh_key key = NULL;
  250|    657|    uint8_t padding;
  251|       |
  252|    657|    cmp = strncmp(ptr, OPENSSH_HEADER_BEGIN, strlen(OPENSSH_HEADER_BEGIN));
  ------------------
  |  |   43|    657|#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
  ------------------
                  cmp = strncmp(ptr, OPENSSH_HEADER_BEGIN, strlen(OPENSSH_HEADER_BEGIN));
  ------------------
  |  |   43|    657|#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
  ------------------
  253|    657|    if (cmp != 0) {
  ------------------
  |  Branch (253:9): [True: 0, False: 657]
  ------------------
  254|      0|        SSH_LOG(SSH_LOG_TRACE, "Not an OpenSSH private key (no header)");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  255|      0|        goto out;
  256|      0|    }
  257|    657|    ptr += strlen(OPENSSH_HEADER_BEGIN);
  ------------------
  |  |   43|    657|#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
  ------------------
  258|    657|    while(ptr[0] != '\0' && !isspace((int)ptr[0])) {
  ------------------
  |  Branch (258:11): [True: 657, False: 0]
  |  Branch (258:29): [True: 0, False: 657]
  ------------------
  259|      0|        ptr++;
  260|      0|    }
  261|    657|    end = strstr(ptr, OPENSSH_HEADER_END);
  ------------------
  |  |   44|    657|#define OPENSSH_HEADER_END "-----END OPENSSH PRIVATE KEY-----"
  ------------------
  262|    657|    if (end == NULL) {
  ------------------
  |  Branch (262:9): [True: 0, False: 657]
  ------------------
  263|      0|        SSH_LOG(SSH_LOG_TRACE, "Not an OpenSSH private key (no footer)");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  264|      0|        goto out;
  265|      0|    }
  266|    657|    base64 = malloc(end - ptr + 1);
  267|    657|    if (base64 == NULL) {
  ------------------
  |  Branch (267:9): [True: 0, False: 657]
  ------------------
  268|      0|        goto out;
  269|      0|    }
  270|   225k|    for (i = 0; ptr < end; ptr++) {
  ------------------
  |  Branch (270:17): [True: 224k, False: 657]
  ------------------
  271|   224k|        if (!isspace((int)ptr[0])) {
  ------------------
  |  Branch (271:13): [True: 220k, False: 3.94k]
  ------------------
  272|   220k|            base64[i] = ptr[0];
  273|   220k|            i++;
  274|   220k|        }
  275|   224k|    }
  276|    657|    base64[i] = '\0';
  277|    657|    buffer = base64_to_bin(base64);
  278|    657|    SAFE_FREE(base64);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  279|    657|    if (buffer == NULL) {
  ------------------
  |  Branch (279:9): [True: 0, False: 657]
  ------------------
  280|      0|        SSH_LOG(SSH_LOG_TRACE, "Not an OpenSSH private key (base64 error)");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  281|      0|        goto out;
  282|      0|    }
  283|    657|    rc = ssh_buffer_unpack(buffer, "PssSdSS",
  ------------------
  |  |   60|    657|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  284|    657|                           strlen(OPENSSH_AUTH_MAGIC) + 1,
  285|    657|                           &magic,
  286|    657|                           &ciphername,
  287|    657|                           &kdfname,
  288|    657|                           &kdfoptions,
  289|    657|                           &nkeys,
  290|    657|                           &pubkey0,
  291|    657|                           &privkeys);
  292|    657|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (292:9): [True: 0, False: 657]
  ------------------
  293|      0|        SSH_LOG(SSH_LOG_TRACE, "Not an OpenSSH private key (unpack error)");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  294|      0|        goto out;
  295|      0|    }
  296|    657|    cmp = strncmp(magic, OPENSSH_AUTH_MAGIC, strlen(OPENSSH_AUTH_MAGIC));
  ------------------
  |  |   46|    657|#define OPENSSH_AUTH_MAGIC      "openssh-key-v1"
  ------------------
                  cmp = strncmp(magic, OPENSSH_AUTH_MAGIC, strlen(OPENSSH_AUTH_MAGIC));
  ------------------
  |  |   46|    657|#define OPENSSH_AUTH_MAGIC      "openssh-key-v1"
  ------------------
  297|    657|    if (cmp != 0) {
  ------------------
  |  Branch (297:9): [True: 0, False: 657]
  ------------------
  298|      0|        SSH_LOG(SSH_LOG_TRACE, "Not an OpenSSH private key (bad magic)");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  299|      0|        goto out;
  300|      0|    }
  301|    657|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  302|    657|            "Opening OpenSSH private key: ciphername: %s, kdf: %s, nkeys: %" PRIu32,
  303|    657|            ciphername,
  304|    657|            kdfname,
  305|    657|            nkeys);
  306|    657|    if (nkeys != 1) {
  ------------------
  |  Branch (306:9): [True: 0, False: 657]
  ------------------
  307|      0|        SSH_LOG(SSH_LOG_TRACE, "Opening OpenSSH private key: only 1 key supported (%" PRIu32 " available)", nkeys);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  308|      0|        goto out;
  309|      0|    }
  310|       |
  311|       |    /* If we are interested only in public key do not progress
  312|       |     * to the key decryption later
  313|       |     */
  314|    657|    if (!private) {
  ------------------
  |  Branch (314:9): [True: 0, False: 657]
  ------------------
  315|      0|        rc = ssh_pki_import_pubkey_blob(pubkey0, &key);
  316|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (316:13): [True: 0, False: 0]
  ------------------
  317|      0|            SSH_LOG(SSH_LOG_TRACE, "Failed to import public key blob");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  318|      0|        }
  319|       |        /* in either case we clean up here */
  320|      0|        goto out;
  321|      0|    }
  322|       |
  323|    657|    rc = pki_private_key_decrypt(privkeys,
  324|    657|                                 passphrase,
  325|    657|                                 ciphername,
  326|    657|                                 kdfname,
  327|    657|                                 kdfoptions,
  328|    657|                                 auth_fn,
  329|    657|                                 auth_data);
  330|    657|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (330:9): [True: 0, False: 657]
  ------------------
  331|      0|        goto out;
  332|      0|    }
  333|       |
  334|    657|    privkey_buffer = ssh_buffer_new();
  335|    657|    if (privkey_buffer == NULL) {
  ------------------
  |  Branch (335:9): [True: 0, False: 657]
  ------------------
  336|      0|        goto out;
  337|      0|    }
  338|       |
  339|    657|    ssh_buffer_set_secure(privkey_buffer);
  340|    657|    ssh_buffer_add_data(privkey_buffer,
  341|    657|                        ssh_string_data(privkeys),
  342|    657|                        (uint32_t)ssh_string_len(privkeys));
  343|       |
  344|    657|    rc = ssh_buffer_unpack(privkey_buffer, "dd", &checkint1, &checkint2);
  ------------------
  |  |   60|    657|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  345|    657|    if (rc == SSH_ERROR || checkint1 != checkint2) {
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (345:9): [True: 0, False: 657]
  |  Branch (345:28): [True: 0, False: 657]
  ------------------
  346|      0|        SSH_LOG(SSH_LOG_TRACE, "OpenSSH private key unpack error (correct password?)");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  347|      0|        goto out;
  348|      0|    }
  349|    657|    rc = pki_openssh_import_privkey_blob(privkey_buffer, &key);
  350|    657|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (350:9): [True: 0, False: 657]
  ------------------
  351|      0|        goto out;
  352|      0|    }
  353|    657|    comment = ssh_buffer_get_ssh_string(privkey_buffer);
  354|    657|    SAFE_FREE(comment);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  355|       |    /* verify that the remaining data is correct padding */
  356|  3.94k|    for (i = 1; ssh_buffer_get_len(privkey_buffer) > 0; ++i) {
  ------------------
  |  Branch (356:17): [True: 3.28k, False: 657]
  ------------------
  357|  3.28k|        ssh_buffer_get_u8(privkey_buffer, &padding);
  358|  3.28k|        if (padding != i) {
  ------------------
  |  Branch (358:13): [True: 0, False: 3.28k]
  ------------------
  359|      0|            ssh_key_free(key);
  360|      0|            key = NULL;
  361|      0|            SSH_LOG(SSH_LOG_TRACE, "Invalid padding");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  362|      0|            goto out;
  363|      0|        }
  364|  3.28k|    }
  365|    657|out:
  366|    657|    if (buffer != NULL) {
  ------------------
  |  Branch (366:9): [True: 657, False: 0]
  ------------------
  367|    657|        SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|    657|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 657, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
  368|    657|        buffer = NULL;
  369|    657|    }
  370|    657|    if (privkey_buffer != NULL) {
  ------------------
  |  Branch (370:9): [True: 657, False: 0]
  ------------------
  371|    657|        SSH_BUFFER_FREE(privkey_buffer);
  ------------------
  |  |  951|    657|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 657, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
  372|    657|        privkey_buffer = NULL;
  373|    657|    }
  374|    657|    SAFE_FREE(magic);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  375|    657|    SAFE_FREE(ciphername);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  376|    657|    SAFE_FREE(kdfname);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  377|    657|    SAFE_FREE(kdfoptions);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  378|    657|    SAFE_FREE(pubkey0);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  379|       |    SAFE_FREE(privkeys);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  380|    657|    return key;
  381|    657|}
pki_container_openssh.c:pki_private_key_decrypt:
  108|    657|{
  109|    657|    struct ssh_cipher_struct *ciphers = ssh_get_ciphertab();
  110|    657|    struct ssh_cipher_struct cipher;
  111|    657|    uint8_t key_material[128] = {0};
  112|    657|    char passphrase_buffer[128] = {0};
  113|    657|    size_t key_material_len;
  114|    657|    ssh_buffer buffer = NULL;
  115|    657|    ssh_string salt = NULL;
  116|    657|    uint32_t rounds;
  117|    657|    int cmp;
  118|    657|    int rc;
  119|    657|    int i;
  120|       |
  121|    657|    cmp = strcmp(ciphername, "none");
  122|    657|    if (cmp == 0){
  ------------------
  |  Branch (122:9): [True: 657, False: 0]
  ------------------
  123|       |        /* no decryption required */
  124|    657|        return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  125|    657|    }
  126|       |
  127|      0|    for (i = 0; ciphers[i].name != NULL; i++) {
  ------------------
  |  Branch (127:17): [True: 0, False: 0]
  ------------------
  128|      0|        cmp = strcmp(ciphername, ciphers[i].name);
  129|      0|        if (cmp == 0){
  ------------------
  |  Branch (129:13): [True: 0, False: 0]
  ------------------
  130|      0|            memcpy(&cipher, &ciphers[i], sizeof(cipher));
  131|      0|            break;
  132|      0|        }
  133|      0|    }
  134|       |
  135|      0|    if (ciphers[i].name == NULL){
  ------------------
  |  Branch (135:9): [True: 0, False: 0]
  ------------------
  136|      0|        SSH_LOG(SSH_LOG_TRACE, "Unsupported cipher %s", ciphername);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  137|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  138|      0|    }
  139|       |
  140|      0|    cmp = strcmp(kdfname, "bcrypt");
  141|      0|    if (cmp != 0) {
  ------------------
  |  Branch (141:9): [True: 0, False: 0]
  ------------------
  142|      0|        SSH_LOG(SSH_LOG_TRACE, "Unsupported KDF %s", kdfname);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  143|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  144|      0|    }
  145|      0|    if (ssh_string_len(blob) % cipher.blocksize != 0) {
  ------------------
  |  Branch (145:9): [True: 0, False: 0]
  ------------------
  146|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  147|      0|                "Encrypted string not multiple of blocksize: %zu",
  148|      0|                ssh_string_len(blob));
  149|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  150|      0|    }
  151|       |
  152|      0|    buffer = ssh_buffer_new();
  153|      0|    if (buffer == NULL){
  ------------------
  |  Branch (153:9): [True: 0, False: 0]
  ------------------
  154|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  155|      0|    }
  156|      0|    rc = ssh_buffer_add_data(buffer,
  157|      0|                             ssh_string_data(kdfoptions),
  158|      0|                             (uint32_t)ssh_string_len(kdfoptions));
  159|      0|    if (rc != SSH_ERROR){
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (159:9): [True: 0, False: 0]
  ------------------
  160|      0|        rc = ssh_buffer_unpack(buffer, "Sd", &salt, &rounds);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  161|      0|    }
  162|      0|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  163|      0|    if (rc == SSH_ERROR){
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (163:9): [True: 0, False: 0]
  ------------------
  164|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  165|      0|    }
  166|       |
  167|       |    /* We need material for key (keysize bits / 8) and IV (blocksize)  */
  168|      0|    key_material_len =  cipher.keysize/8 + cipher.blocksize;
  169|      0|    if (key_material_len > sizeof(key_material)) {
  ------------------
  |  Branch (169:9): [True: 0, False: 0]
  ------------------
  170|      0|        SSH_LOG(SSH_LOG_TRACE, "Key material too big");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  171|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  172|      0|    }
  173|       |
  174|      0|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  175|      0|            "Decryption: %d key, %d IV, %" PRIu32 " rounds, %zu bytes salt",
  176|      0|            cipher.keysize/8,
  177|      0|            cipher.blocksize,
  178|      0|            rounds,
  179|      0|            ssh_string_len(salt));
  180|       |
  181|      0|    if (passphrase == NULL) {
  ------------------
  |  Branch (181:9): [True: 0, False: 0]
  ------------------
  182|      0|        if (auth_fn == NULL) {
  ------------------
  |  Branch (182:13): [True: 0, False: 0]
  ------------------
  183|      0|            SAFE_FREE(salt);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  184|      0|            SSH_LOG(SSH_LOG_TRACE, "No passphrase provided");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  185|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  186|      0|        }
  187|      0|        rc = auth_fn("Passphrase",
  188|      0|                     passphrase_buffer,
  189|      0|                     sizeof(passphrase_buffer),
  190|      0|                     0,
  191|      0|                     0,
  192|      0|                     auth_data);
  193|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (193:13): [True: 0, False: 0]
  ------------------
  194|      0|            SAFE_FREE(salt);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  195|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  196|      0|        }
  197|      0|        passphrase = passphrase_buffer;
  198|      0|    }
  199|       |
  200|      0|    rc = bcrypt_pbkdf(passphrase,
  201|      0|                      strlen(passphrase),
  202|      0|                      ssh_string_data(salt),
  203|      0|                      ssh_string_len(salt),
  204|      0|                      key_material,
  205|      0|                      key_material_len,
  206|      0|                      rounds);
  207|      0|    SAFE_FREE(salt);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  208|      0|    if (rc < 0){
  ------------------
  |  Branch (208:9): [True: 0, False: 0]
  ------------------
  209|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  210|      0|    }
  211|      0|    ssh_burn(passphrase_buffer, sizeof(passphrase_buffer));
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  212|       |
  213|      0|    cipher.set_decrypt_key(&cipher,
  214|      0|                           key_material,
  215|      0|                           key_material + cipher.keysize/8);
  216|      0|    cipher.decrypt(&cipher,
  217|      0|                   ssh_string_data(blob),
  218|      0|                   ssh_string_data(blob),
  219|      0|                   ssh_string_len(blob));
  220|      0|    ssh_cipher_clear(&cipher);
  221|      0|    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  222|      0|}
pki_container_openssh.c:pki_openssh_import_privkey_blob:
   60|    657|{
   61|    657|    enum ssh_keytypes_e type;
   62|    657|    char *type_s = NULL;
   63|    657|    ssh_key key = NULL;
   64|    657|    int rc;
   65|       |
   66|    657|    if (pkey == NULL) {
  ------------------
  |  Branch (66:9): [True: 0, False: 657]
  ------------------
   67|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   68|      0|    }
   69|       |
   70|    657|    rc = ssh_buffer_unpack(key_blob_buffer, "s", &type_s);
  ------------------
  |  |   60|    657|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
   71|    657|    if (rc == SSH_ERROR){
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (71:9): [True: 0, False: 657]
  ------------------
   72|      0|        SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   73|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   74|      0|    }
   75|       |
   76|    657|    type = ssh_key_type_from_name(type_s);
   77|    657|    if (type == SSH_KEYTYPE_UNKNOWN) {
  ------------------
  |  Branch (77:9): [True: 0, False: 657]
  ------------------
   78|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown key type '%s' found!", type_s);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   79|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   80|      0|    }
   81|    657|    SAFE_FREE(type_s);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
   82|       |
   83|    657|    rc = pki_import_privkey_buffer(type, key_blob_buffer, &key);
   84|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (84:9): [True: 0, False: 657]
  ------------------
   85|      0|        SSH_LOG(SSH_LOG_TRACE, "Failed to read key in OpenSSH format");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   86|      0|        goto fail;
   87|      0|    }
   88|       |
   89|    657|    *pkey = key;
   90|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
   91|      0|fail:
   92|      0|    ssh_key_free(key);
   93|       |
   94|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   95|    657|}

ssh_pki_ctx_new:
   49|  1.31k|{
   50|  1.31k|    struct ssh_pki_ctx_struct *ctx = NULL;
   51|       |
   52|  1.31k|    ctx = calloc(1, sizeof(struct ssh_pki_ctx_struct));
   53|  1.31k|    if (ctx == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 1.31k]
  ------------------
   54|      0|        return NULL;
   55|      0|    }
   56|       |
   57|       |#ifdef WITH_FIDO2
   58|       |    /* Initialize SK fields with default, if available. */
   59|       |    ctx->sk_callbacks = ssh_sk_get_default_callbacks();
   60|       |
   61|       |    /*
   62|       |     * Both OpenSSH security key enrollment and server authentication require
   63|       |     * user presence by default, so we replicate that for consistency.
   64|       |     */
   65|       |    ctx->sk_flags = SSH_SK_USER_PRESENCE_REQD;
   66|       |
   67|       |    ctx->sk_application = strdup("ssh:");
   68|       |    if (ctx->sk_application == NULL) {
   69|       |        SSH_LOG(SSH_LOG_WARN,
   70|       |                "Failed to allocate memory for default application");
   71|       |        SAFE_FREE(ctx);
   72|       |        return NULL;
   73|       |    }
   74|       |#endif /* WITH_FIDO2 */
   75|       |
   76|  1.31k|    return ctx;
   77|  1.31k|}
ssh_pki_ctx_free:
   86|  1.31k|{
   87|  1.31k|    if (context == NULL) {
  ------------------
  |  Branch (87:9): [True: 0, False: 1.31k]
  ------------------
   88|      0|        return;
   89|      0|    }
   90|       |
   91|       |#ifdef WITH_FIDO2
   92|       |    SAFE_FREE(context->sk_application);
   93|       |    SSH_BUFFER_FREE(context->sk_challenge_buffer);
   94|       |    SSH_BUFFER_FREE(context->sk_attestation_buffer);
   95|       |    SK_OPTIONS_FREE(context->sk_callbacks_options);
   96|       |#endif /* WITH_FIDO2 */
   97|       |
   98|  1.31k|    SAFE_FREE(context);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
   99|  1.31k|}

pki_key_clean:
   96|  3.28k|{
   97|  3.28k|    if (key == NULL)
  ------------------
  |  Branch (97:9): [True: 0, False: 3.28k]
  ------------------
   98|      0|        return;
   99|  3.28k|    EVP_PKEY_free(key->key);
  100|       |    key->key = NULL;
  101|  3.28k|}
pki_privkey_build_ed25519:
  418|    657|{
  419|    657|    EVP_PKEY *pkey = NULL;
  420|       |
  421|    657|    if (ssh_string_len(pubkey) != ED25519_KEY_LEN ||
  ------------------
  |  |   44|  1.31k|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (421:9): [True: 0, False: 657]
  ------------------
  422|    657|        ssh_string_len(privkey) != (2 * ED25519_KEY_LEN)) {
  ------------------
  |  |   44|    657|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (422:9): [True: 0, False: 657]
  ------------------
  423|      0|        SSH_LOG(SSH_LOG_TRACE, "Invalid ed25519 key len");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  424|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  425|      0|    }
  426|       |
  427|    657|    pkey = EVP_PKEY_new_raw_private_key(EVP_PKEY_ED25519,
  428|    657|                                        NULL,
  429|    657|                                        (const uint8_t *)ssh_string_data(privkey),
  430|    657|                                        ED25519_KEY_LEN);
  ------------------
  |  |   44|    657|#define ED25519_KEY_LEN 32
  ------------------
  431|    657|    if (pkey == NULL) {
  ------------------
  |  Branch (431:9): [True: 0, False: 657]
  ------------------
  432|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  433|      0|                "Failed to create ed25519 EVP_PKEY: %s",
  434|      0|                ERR_error_string(ERR_get_error(), NULL));
  435|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  436|      0|    }
  437|       |
  438|    657|    key->key = pkey;
  439|       |
  440|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  441|    657|}
pki_pubkey_build_ed25519:
  444|  1.31k|{
  445|  1.31k|    EVP_PKEY *pkey = NULL;
  446|       |
  447|  1.31k|    if (ssh_string_len(pubkey) != ED25519_KEY_LEN) {
  ------------------
  |  |   44|  1.31k|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (447:9): [True: 0, False: 1.31k]
  ------------------
  448|      0|        SSH_LOG(SSH_LOG_TRACE, "Invalid ed25519 key len");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  449|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  450|      0|    }
  451|       |
  452|  1.31k|    if (ssh_fips_mode()) {
  ------------------
  |  |  115|  1.31k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 1.31k]
  |  |  ------------------
  ------------------
  453|       |        /* We do not want to fail here as we know the algorithm, but we can not
  454|       |         * use it. Just store the public key here. We won't be able to use it
  455|       |         * for anything though. */
  456|      0|        key->ed25519_pubkey = malloc(ED25519_KEY_LEN);
  ------------------
  |  |   44|      0|#define ED25519_KEY_LEN 32
  ------------------
  457|      0|        if (key->ed25519_pubkey == NULL) {
  ------------------
  |  Branch (457:13): [True: 0, False: 0]
  ------------------
  458|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  459|      0|                    "Failed to allocate memory for the Ed25519 public key");
  460|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  461|      0|        }
  462|       |
  463|      0|        memcpy(key->ed25519_pubkey, ssh_string_data(pubkey), ED25519_KEY_LEN);
  ------------------
  |  |   44|      0|#define ED25519_KEY_LEN 32
  ------------------
  464|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  465|      0|    }
  466|       |
  467|  1.31k|    pkey = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519,
  468|  1.31k|                                       NULL,
  469|  1.31k|                                       (const uint8_t *)ssh_string_data(pubkey),
  470|  1.31k|                                       ED25519_KEY_LEN);
  ------------------
  |  |   44|  1.31k|#define ED25519_KEY_LEN 32
  ------------------
  471|  1.31k|    if (pkey == NULL) {
  ------------------
  |  Branch (471:9): [True: 0, False: 1.31k]
  ------------------
  472|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  473|      0|                "Failed to create ed25519 EVP_PKEY: %s",
  474|      0|                ERR_error_string(ERR_get_error(), NULL));
  475|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  476|      0|    }
  477|       |
  478|  1.31k|    key->key = pkey;
  479|       |
  480|  1.31k|    return SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  481|  1.31k|}
pki_key_dup:
  484|  1.31k|{
  485|  1.31k|    ssh_key new = NULL;
  486|  1.31k|    int rc;
  487|       |
  488|  1.31k|    new = pki_key_dup_common_init(key, demote);
  489|  1.31k|    if (new == NULL) {
  ------------------
  |  Branch (489:9): [True: 0, False: 1.31k]
  ------------------
  490|      0|        return NULL;
  491|      0|    }
  492|       |
  493|  1.31k|    switch (key->type) {
  494|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (494:5): [True: 0, False: 1.31k]
  ------------------
  495|      0|    case SSH_KEYTYPE_RSA1: {
  ------------------
  |  Branch (495:5): [True: 0, False: 1.31k]
  ------------------
  496|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  497|      0|        const BIGNUM *n = NULL, *e = NULL, *d = NULL;
  498|      0|        BIGNUM *nn, *ne, *nd;
  499|      0|        RSA *new_rsa = NULL;
  500|      0|        const RSA *key_rsa = EVP_PKEY_get0_RSA(key->key);
  501|      0|#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */
  502|       |#ifdef WITH_PKCS11_URI
  503|       |        /* Take the PKCS#11 keys as they are */
  504|       |        if (key->flags & SSH_KEY_FLAG_PKCS11_URI && !demote) {
  505|       |            rc = EVP_PKEY_up_ref(key->key);
  506|       |            if (rc != 1) {
  507|       |                goto fail;
  508|       |            }
  509|       |            new->key = key->key;
  510|       |            return new;
  511|       |        }
  512|       |#endif /* WITH_PKCS11_URI */
  513|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  514|      0|        new_rsa = RSA_new();
  515|      0|        if (new_rsa == NULL) {
  ------------------
  |  Branch (515:13): [True: 0, False: 0]
  ------------------
  516|      0|            goto fail;
  517|      0|        }
  518|       |
  519|       |        /*
  520|       |         * n    = public modulus
  521|       |         * e    = public exponent
  522|       |         * d    = private exponent
  523|       |         * p    = secret prime factor
  524|       |         * q    = secret prime factor
  525|       |         * dmp1 = d mod (p-1)
  526|       |         * dmq1 = d mod (q-1)
  527|       |         * iqmp = q^-1 mod p
  528|       |         */
  529|      0|        RSA_get0_key(key_rsa, &n, &e, &d);
  530|      0|        nn = BN_dup(n);
  531|      0|        ne = BN_dup(e);
  532|      0|        if (nn == NULL || ne == NULL) {
  ------------------
  |  Branch (532:13): [True: 0, False: 0]
  |  Branch (532:27): [True: 0, False: 0]
  ------------------
  533|      0|            RSA_free(new_rsa);
  534|      0|            BN_free(nn);
  535|      0|            BN_free(ne);
  536|      0|            goto fail;
  537|      0|        }
  538|       |
  539|       |        /* Memory management of nn and ne is transferred to RSA object */
  540|      0|        rc = RSA_set0_key(new_rsa, nn, ne, NULL);
  541|      0|        if (rc == 0) {
  ------------------
  |  Branch (541:13): [True: 0, False: 0]
  ------------------
  542|      0|            RSA_free(new_rsa);
  543|      0|            BN_free(nn);
  544|      0|            BN_free(ne);
  545|      0|            goto fail;
  546|      0|        }
  547|       |
  548|      0|        if (!demote && (key->flags & SSH_KEY_FLAG_PRIVATE)) {
  ------------------
  |  |   55|      0|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
  |  Branch (548:13): [True: 0, False: 0]
  |  Branch (548:24): [True: 0, False: 0]
  ------------------
  549|      0|            const BIGNUM *p = NULL, *q = NULL, *dmp1 = NULL,
  550|      0|              *dmq1 = NULL, *iqmp = NULL;
  551|      0|            BIGNUM *np, *nq, *ndmp1, *ndmq1, *niqmp;
  552|       |
  553|      0|            nd = BN_dup(d);
  554|      0|            if (nd == NULL) {
  ------------------
  |  Branch (554:17): [True: 0, False: 0]
  ------------------
  555|      0|                RSA_free(new_rsa);
  556|      0|                goto fail;
  557|      0|            }
  558|       |
  559|       |            /* Memory management of nd is transferred to RSA object */
  560|      0|            rc = RSA_set0_key(new_rsa, NULL, NULL, nd);
  561|      0|            if (rc == 0) {
  ------------------
  |  Branch (561:17): [True: 0, False: 0]
  ------------------
  562|      0|                RSA_free(new_rsa);
  563|      0|                goto fail;
  564|      0|            }
  565|       |
  566|       |            /* p, q, dmp1, dmq1 and iqmp may be NULL in private keys, but the
  567|       |             * RSA operations are much faster when these values are available.
  568|       |             */
  569|      0|            RSA_get0_factors(key_rsa, &p, &q);
  570|      0|            if (p != NULL && q != NULL) { /* need to set both of them */
  ------------------
  |  Branch (570:17): [True: 0, False: 0]
  |  Branch (570:30): [True: 0, False: 0]
  ------------------
  571|      0|                np = BN_dup(p);
  572|      0|                nq = BN_dup(q);
  573|      0|                if (np == NULL || nq == NULL) {
  ------------------
  |  Branch (573:21): [True: 0, False: 0]
  |  Branch (573:35): [True: 0, False: 0]
  ------------------
  574|      0|                    RSA_free(new_rsa);
  575|      0|                    BN_free(np);
  576|      0|                    BN_free(nq);
  577|      0|                    goto fail;
  578|      0|                }
  579|       |
  580|       |                /* Memory management of np and nq is transferred to RSA object */
  581|      0|                rc = RSA_set0_factors(new_rsa, np, nq);
  582|      0|                if (rc == 0) {
  ------------------
  |  Branch (582:21): [True: 0, False: 0]
  ------------------
  583|      0|                    RSA_free(new_rsa);
  584|      0|                    BN_free(np);
  585|      0|                    BN_free(nq);
  586|      0|                    goto fail;
  587|      0|                }
  588|      0|            }
  589|       |
  590|      0|            RSA_get0_crt_params(key_rsa, &dmp1, &dmq1, &iqmp);
  591|      0|            if (dmp1 != NULL || dmq1 != NULL || iqmp != NULL) {
  ------------------
  |  Branch (591:17): [True: 0, False: 0]
  |  Branch (591:33): [True: 0, False: 0]
  |  Branch (591:49): [True: 0, False: 0]
  ------------------
  592|      0|                ndmp1 = BN_dup(dmp1);
  593|      0|                ndmq1 = BN_dup(dmq1);
  594|      0|                niqmp = BN_dup(iqmp);
  595|      0|                if (ndmp1 == NULL || ndmq1 == NULL || niqmp == NULL) {
  ------------------
  |  Branch (595:21): [True: 0, False: 0]
  |  Branch (595:38): [True: 0, False: 0]
  |  Branch (595:55): [True: 0, False: 0]
  ------------------
  596|      0|                    RSA_free(new_rsa);
  597|      0|                    BN_free(ndmp1);
  598|      0|                    BN_free(ndmq1);
  599|      0|                    BN_free(niqmp);
  600|      0|                    goto fail;
  601|      0|                }
  602|       |
  603|       |                /* Memory management of ndmp1, ndmq1 and niqmp is transferred
  604|       |                 * to RSA object */
  605|      0|                rc = RSA_set0_crt_params(new_rsa, ndmp1, ndmq1, niqmp);
  606|      0|                if (rc == 0) {
  ------------------
  |  Branch (606:21): [True: 0, False: 0]
  ------------------
  607|      0|                    RSA_free(new_rsa);
  608|      0|                    BN_free(ndmp1);
  609|      0|                    BN_free(ndmq1);
  610|      0|                    BN_free(niqmp);
  611|      0|                    goto fail;
  612|      0|                }
  613|      0|            }
  614|      0|        }
  615|       |
  616|      0|        new->key = EVP_PKEY_new();
  617|      0|        if (new->key == NULL) {
  ------------------
  |  Branch (617:13): [True: 0, False: 0]
  ------------------
  618|      0|            RSA_free(new_rsa);
  619|      0|            goto fail;
  620|      0|        }
  621|       |
  622|      0|        rc = EVP_PKEY_assign_RSA(new->key, new_rsa);
  623|      0|        if (rc != 1) {
  ------------------
  |  Branch (623:13): [True: 0, False: 0]
  ------------------
  624|      0|            EVP_PKEY_free(new->key);
  625|      0|            RSA_free(new_rsa);
  626|      0|            goto fail;
  627|      0|        }
  628|       |
  629|      0|        new_rsa = NULL;
  630|       |#else
  631|       |        rc = evp_dup_rsa_pkey(key, new, demote);
  632|       |        if (rc != SSH_OK) {
  633|       |            goto fail;
  634|       |        }
  635|       |#endif /* OPENSSL_VERSION_NUMBER */
  636|      0|        break;
  637|      0|    }
  638|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (638:5): [True: 0, False: 1.31k]
  ------------------
  639|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (639:5): [True: 0, False: 1.31k]
  ------------------
  640|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (640:5): [True: 0, False: 1.31k]
  ------------------
  641|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (641:5): [True: 0, False: 1.31k]
  ------------------
  642|      0|#ifdef HAVE_OPENSSL_ECC
  643|      0|        new->ecdsa_nid = key->ecdsa_nid;
  644|       |#ifdef WITH_PKCS11_URI
  645|       |        /* Take the PKCS#11 keys as they are */
  646|       |        if (key->flags & SSH_KEY_FLAG_PKCS11_URI && !demote) {
  647|       |            rc = EVP_PKEY_up_ref(key->key);
  648|       |            if (rc != 1) {
  649|       |                goto fail;
  650|       |            }
  651|       |            new->key = key->key;
  652|       |            return new;
  653|       |        }
  654|       |#endif /* WITH_PKCS11_URI */
  655|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  656|       |        /* privkey -> pubkey */
  657|      0|        if (demote && ssh_key_is_private(key)) {
  ------------------
  |  Branch (657:13): [True: 0, False: 0]
  |  Branch (657:23): [True: 0, False: 0]
  ------------------
  658|      0|            const EC_POINT *p = NULL;
  659|      0|            EC_KEY *new_ecdsa = NULL, *old_ecdsa = NULL;
  660|      0|            int ok;
  661|       |
  662|      0|            new_ecdsa = EC_KEY_new_by_curve_name(key->ecdsa_nid);
  663|      0|            if (new_ecdsa == NULL) {
  ------------------
  |  Branch (663:17): [True: 0, False: 0]
  ------------------
  664|      0|                goto fail;
  665|      0|            }
  666|       |
  667|      0|            old_ecdsa = EVP_PKEY_get0_EC_KEY(key->key);
  668|      0|            if (old_ecdsa == NULL) {
  ------------------
  |  Branch (668:17): [True: 0, False: 0]
  ------------------
  669|      0|                EC_KEY_free(new_ecdsa);
  670|      0|                goto fail;
  671|      0|            }
  672|       |
  673|      0|            p = EC_KEY_get0_public_key(old_ecdsa);
  674|      0|            if (p == NULL) {
  ------------------
  |  Branch (674:17): [True: 0, False: 0]
  ------------------
  675|      0|                EC_KEY_free(new_ecdsa);
  676|      0|                goto fail;
  677|      0|            }
  678|       |
  679|      0|            ok = EC_KEY_set_public_key(new_ecdsa, p);
  680|      0|            if (ok != 1) {
  ------------------
  |  Branch (680:17): [True: 0, False: 0]
  ------------------
  681|      0|                EC_KEY_free(new_ecdsa);
  682|      0|                goto fail;
  683|      0|            }
  684|       |
  685|      0|            new->key = EVP_PKEY_new();
  686|      0|            if (new->key == NULL) {
  ------------------
  |  Branch (686:17): [True: 0, False: 0]
  ------------------
  687|      0|                EC_KEY_free(new_ecdsa);
  688|      0|                goto fail;
  689|      0|            }
  690|       |
  691|      0|            ok = EVP_PKEY_assign_EC_KEY(new->key, new_ecdsa);
  692|      0|            if (ok != 1) {
  ------------------
  |  Branch (692:17): [True: 0, False: 0]
  ------------------
  693|      0|                EC_KEY_free(new_ecdsa);
  694|      0|                goto fail;
  695|      0|            }
  696|      0|        } else {
  697|      0|            rc = EVP_PKEY_up_ref(key->key);
  698|      0|            if (rc != 1) {
  ------------------
  |  Branch (698:17): [True: 0, False: 0]
  ------------------
  699|      0|                goto fail;
  700|      0|            }
  701|      0|            new->key = key->key;
  702|      0|        }
  703|       |#else
  704|       |        rc = evp_dup_ecdsa_pkey(key, new, demote);
  705|       |        if (rc != SSH_OK) {
  706|       |            goto fail;
  707|       |        }
  708|       |#endif /* OPENSSL_VERSION_NUMBER */
  709|      0|        break;
  710|      0|#endif /* HAVE_OPENSSL_ECC */
  711|  1.31k|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (711:5): [True: 1.31k, False: 0]
  ------------------
  712|  1.31k|    case SSH_KEYTYPE_SK_ED25519: {
  ------------------
  |  Branch (712:5): [True: 0, False: 1.31k]
  ------------------
  713|  1.31k|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  714|       |        /* Take the PKCS#11 keys as they are */
  715|  1.31k|        if (key->flags & SSH_KEY_FLAG_PKCS11_URI && !demote) {
  ------------------
  |  |   56|  2.62k|#define SSH_KEY_FLAG_PKCS11_URI 0x0004
  ------------------
  |  Branch (715:13): [True: 0, False: 1.31k]
  |  Branch (715:53): [True: 0, False: 0]
  ------------------
  716|      0|            rc = EVP_PKEY_up_ref(key->key);
  717|      0|            if (rc != 1) {
  ------------------
  |  Branch (717:17): [True: 0, False: 0]
  ------------------
  718|      0|                goto fail;
  719|      0|            }
  720|      0|            new->key = key->key;
  721|      0|            return new;
  722|      0|        }
  723|       |
  724|  1.31k|        if (!demote && (key->flags & SSH_KEY_FLAG_PRIVATE) &&
  ------------------
  |  |   55|    657|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
  |  Branch (724:13): [True: 657, False: 657]
  |  Branch (724:24): [True: 657, False: 0]
  ------------------
  725|    657|            key->type == SSH_KEYTYPE_ED25519) {
  ------------------
  |  Branch (725:13): [True: 657, False: 0]
  ------------------
  726|    657|            rc = EVP_PKEY_up_ref(key->key);
  727|    657|            if (rc != 1) {
  ------------------
  |  Branch (727:17): [True: 0, False: 657]
  ------------------
  728|      0|                goto fail;
  729|      0|            }
  730|    657|            new->key = key->key;
  731|    657|        } else {
  732|    657|            unsigned char *ed25519_pubkey = NULL;
  733|    657|            size_t key_len = 0;
  734|       |
  735|    657|            rc = EVP_PKEY_get_raw_public_key(key->key, NULL, &key_len);
  736|    657|            if (rc != 1) {
  ------------------
  |  Branch (736:17): [True: 0, False: 657]
  ------------------
  737|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  738|      0|                        "Failed to get ed25519 raw public key length: %s",
  739|      0|                        ERR_error_string(ERR_get_error(), NULL));
  740|      0|                goto fail;
  741|      0|            }
  742|       |
  743|    657|            if (key_len != ED25519_KEY_LEN) {
  ------------------
  |  |   44|    657|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (743:17): [True: 0, False: 657]
  ------------------
  744|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  745|      0|                        "Unexpected length of public key %zu. Expected %d.",
  746|      0|                        key_len,
  747|      0|                        ED25519_KEY_LEN);
  748|      0|                goto fail;
  749|      0|            }
  750|       |
  751|    657|            ed25519_pubkey = malloc(key_len);
  752|    657|            if (ed25519_pubkey == NULL) {
  ------------------
  |  Branch (752:17): [True: 0, False: 657]
  ------------------
  753|      0|                SSH_LOG(SSH_LOG_TRACE, "Out of memory");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  754|      0|                goto fail;
  755|      0|            }
  756|       |
  757|    657|            rc = EVP_PKEY_get_raw_public_key(key->key,
  758|    657|                                             ed25519_pubkey,
  759|    657|                                             &key_len);
  760|    657|            if (rc != 1) {
  ------------------
  |  Branch (760:17): [True: 0, False: 657]
  ------------------
  761|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  762|      0|                        "Failed to get ed25519 raw public key: %s",
  763|      0|                        ERR_error_string(ERR_get_error(), NULL));
  764|      0|                free(ed25519_pubkey);
  765|      0|                goto fail;
  766|      0|            }
  767|       |
  768|    657|            new->key = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519,
  769|    657|                                                   NULL,
  770|    657|                                                   ed25519_pubkey,
  771|    657|                                                   key_len);
  772|    657|            free(ed25519_pubkey);
  773|    657|        }
  774|       |
  775|       |#else
  776|       |        rc = evp_dup_ed25519_pkey(key, new, demote);
  777|       |        if (rc != SSH_OK) {
  778|       |            goto fail;
  779|       |        }
  780|       |#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */
  781|  1.31k|        break;
  782|  1.31k|    }
  783|  1.31k|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (783:5): [True: 0, False: 1.31k]
  ------------------
  784|      0|    default:
  ------------------
  |  Branch (784:5): [True: 0, False: 1.31k]
  ------------------
  785|      0|        ssh_key_free(new);
  786|      0|        return NULL;
  787|  1.31k|    }
  788|       |
  789|  1.31k|    return new;
  790|      0|fail:
  791|      0|    ssh_key_free(new);
  792|       |    return NULL;
  793|  1.31k|}
pki_key_to_blob:
 1493|  2.62k|{
 1494|  2.62k|    ssh_buffer buffer = NULL;
 1495|  2.62k|    ssh_string type_s = NULL;
 1496|  2.62k|    ssh_string str = NULL;
 1497|  2.62k|    ssh_string e = NULL;
 1498|  2.62k|    ssh_string n = NULL;
 1499|  2.62k|    ssh_string p = NULL;
 1500|  2.62k|    ssh_string g = NULL;
 1501|  2.62k|    ssh_string q = NULL;
 1502|  2.62k|    ssh_string d = NULL;
 1503|  2.62k|    ssh_string iqmp = NULL;
 1504|  2.62k|    int rc;
 1505|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1506|       |    BIGNUM *bp = NULL, *bq = NULL, *bg = NULL, *bpub_key = NULL,
 1507|       |           *bn = NULL, *be = NULL,
 1508|       |           *bd = NULL, *biqmp = NULL;
 1509|       |    OSSL_PARAM *params = NULL;
 1510|       |#endif /* OPENSSL_VERSION_NUMBER */
 1511|  2.62k|    uint8_t *ed25519_pubkey = NULL;
 1512|  2.62k|    uint8_t *ed25519_privkey = NULL;
 1513|  2.62k|    size_t key_len = 0;
 1514|       |
 1515|  2.62k|    buffer = ssh_buffer_new();
 1516|  2.62k|    if (buffer == NULL) {
  ------------------
  |  Branch (1516:9): [True: 0, False: 2.62k]
  ------------------
 1517|      0|        return NULL;
 1518|      0|    }
 1519|       |    /* The buffer will contain sensitive information. Make sure it is erased */
 1520|  2.62k|    ssh_buffer_set_secure(buffer);
 1521|       |
 1522|  2.62k|    if (key->cert != NULL) {
  ------------------
  |  Branch (1522:9): [True: 0, False: 2.62k]
  ------------------
 1523|      0|        rc = ssh_buffer_add_buffer(buffer, key->cert);
 1524|      0|        if (rc < 0) {
  ------------------
  |  Branch (1524:13): [True: 0, False: 0]
  ------------------
 1525|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1526|      0|            return NULL;
 1527|      0|        }
 1528|      0|        goto makestring;
 1529|      0|    }
 1530|       |
 1531|  2.62k|    type_s = ssh_string_from_char(key->type_c);
 1532|  2.62k|    if (type_s == NULL) {
  ------------------
  |  Branch (1532:9): [True: 0, False: 2.62k]
  ------------------
 1533|      0|        SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1534|      0|        return NULL;
 1535|      0|    }
 1536|       |
 1537|  2.62k|    rc = ssh_buffer_add_ssh_string(buffer, type_s);
 1538|  2.62k|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  910|  2.62k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 2.62k, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 2.62k]
  |  |  ------------------
  ------------------
 1539|  2.62k|    if (rc < 0) {
  ------------------
  |  Branch (1539:9): [True: 0, False: 2.62k]
  ------------------
 1540|      0|        SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1541|      0|        return NULL;
 1542|      0|    }
 1543|       |
 1544|  2.62k|    switch (key->type) {
 1545|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1545:5): [True: 0, False: 2.62k]
  ------------------
 1546|      0|    case SSH_KEYTYPE_RSA1: {
  ------------------
  |  Branch (1546:5): [True: 0, False: 2.62k]
  ------------------
 1547|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1548|      0|        const BIGNUM *be = NULL, *bn = NULL;
 1549|      0|        const RSA *key_rsa = EVP_PKEY_get0_RSA(key->key);
 1550|      0|        RSA_get0_key(key_rsa, &bn, &be, NULL);
 1551|       |#else
 1552|       |        const OSSL_PARAM *out_param = NULL;
 1553|       |        rc = EVP_PKEY_todata(key->key, EVP_PKEY_PUBLIC_KEY, &params);
 1554|       |        if (rc != 1) {
 1555|       |            goto fail;
 1556|       |        }
 1557|       |        out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_E);
 1558|       |        if (out_param == NULL) {
 1559|       |            SSH_LOG(SSH_LOG_TRACE, "RSA: No param E has been found");
 1560|       |            goto fail;
 1561|       |        }
 1562|       |        rc = OSSL_PARAM_get_BN(out_param, &be);
 1563|       |        if (rc != 1) {
 1564|       |            goto fail;
 1565|       |        }
 1566|       |        out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_N);
 1567|       |        if (out_param == NULL) {
 1568|       |            SSH_LOG(SSH_LOG_TRACE, "RSA: No param N has been found");
 1569|       |            goto fail;
 1570|       |        }
 1571|       |        rc = OSSL_PARAM_get_BN(out_param, &bn);
 1572|       |        if (rc != 1) {
 1573|       |            goto fail;
 1574|       |        }
 1575|       |#endif /* OPENSSL_VERSION_NUMBER */
 1576|      0|        e = ssh_make_bignum_string((BIGNUM *)be);
 1577|      0|        if (e == NULL) {
  ------------------
  |  Branch (1577:13): [True: 0, False: 0]
  ------------------
 1578|      0|            goto fail;
 1579|      0|        }
 1580|       |
 1581|      0|        n = ssh_make_bignum_string((BIGNUM *)bn);
 1582|      0|        if (n == NULL) {
  ------------------
  |  Branch (1582:13): [True: 0, False: 0]
  ------------------
 1583|      0|            goto fail;
 1584|      0|        }
 1585|       |
 1586|      0|        if (type == SSH_KEY_PUBLIC) {
  ------------------
  |  Branch (1586:13): [True: 0, False: 0]
  ------------------
 1587|       |            /* The N and E parts are swapped in the public key export ! */
 1588|      0|            rc = ssh_buffer_add_ssh_string(buffer, e);
 1589|      0|            if (rc < 0) {
  ------------------
  |  Branch (1589:17): [True: 0, False: 0]
  ------------------
 1590|      0|                goto fail;
 1591|      0|            }
 1592|      0|            rc = ssh_buffer_add_ssh_string(buffer, n);
 1593|      0|            if (rc < 0) {
  ------------------
  |  Branch (1593:17): [True: 0, False: 0]
  ------------------
 1594|      0|                goto fail;
 1595|      0|            }
 1596|      0|        } else if (type == SSH_KEY_PRIVATE) {
  ------------------
  |  Branch (1596:20): [True: 0, False: 0]
  ------------------
 1597|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1598|      0|            const BIGNUM *bd, *biqmp, *bp, *bq;
 1599|      0|            RSA_get0_key(key_rsa, NULL, NULL, &bd);
 1600|      0|            RSA_get0_factors(key_rsa, &bp, &bq);
 1601|      0|            RSA_get0_crt_params(key_rsa, NULL, NULL, &biqmp);
 1602|       |#else
 1603|       |            OSSL_PARAM_free(params);
 1604|       |            rc = EVP_PKEY_todata(key->key, EVP_PKEY_KEYPAIR, &params);
 1605|       |            if (rc != 1) {
 1606|       |                goto fail;
 1607|       |            }
 1608|       |
 1609|       |            out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_D);
 1610|       |            if (out_param == NULL) {
 1611|       |                SSH_LOG(SSH_LOG_TRACE, "RSA: No param D has been found");
 1612|       |                goto fail;
 1613|       |            }
 1614|       |            rc = OSSL_PARAM_get_BN(out_param, &bd);
 1615|       |            if (rc != 1) {
 1616|       |                goto fail;
 1617|       |            }
 1618|       |
 1619|       |            out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_FACTOR1);
 1620|       |            if (out_param == NULL) {
 1621|       |                SSH_LOG(SSH_LOG_TRACE, "RSA: No param P has been found");
 1622|       |                goto fail;
 1623|       |            }
 1624|       |            rc = OSSL_PARAM_get_BN(out_param, &bp);
 1625|       |            if (rc != 1) {
 1626|       |                goto fail;
 1627|       |            }
 1628|       |
 1629|       |            out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_FACTOR2);
 1630|       |            if (out_param == NULL) {
 1631|       |                SSH_LOG(SSH_LOG_TRACE, "RSA: No param Q has been found");
 1632|       |                goto fail;
 1633|       |            }
 1634|       |            rc = OSSL_PARAM_get_BN(out_param, &bq);
 1635|       |            if (rc != 1) {
 1636|       |                goto fail;
 1637|       |            }
 1638|       |
 1639|       |            out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_COEFFICIENT1);
 1640|       |            if (out_param == NULL) {
 1641|       |                SSH_LOG(SSH_LOG_TRACE, "RSA: No param IQMP has been found");
 1642|       |                goto fail;
 1643|       |            }
 1644|       |            rc = OSSL_PARAM_get_BN(out_param, &biqmp);
 1645|       |            if (rc != 1) {
 1646|       |                goto fail;
 1647|       |            }
 1648|       |#endif /* OPENSSL_VERSION_NUMBER */
 1649|      0|            rc = ssh_buffer_add_ssh_string(buffer, n);
 1650|      0|            if (rc < 0) {
  ------------------
  |  Branch (1650:17): [True: 0, False: 0]
  ------------------
 1651|      0|                goto fail;
 1652|      0|            }
 1653|      0|            rc = ssh_buffer_add_ssh_string(buffer, e);
 1654|      0|            if (rc < 0) {
  ------------------
  |  Branch (1654:17): [True: 0, False: 0]
  ------------------
 1655|      0|                goto fail;
 1656|      0|            }
 1657|       |
 1658|      0|            d = ssh_make_bignum_string((BIGNUM *)bd);
 1659|      0|            if (d == NULL) {
  ------------------
  |  Branch (1659:17): [True: 0, False: 0]
  ------------------
 1660|      0|                goto fail;
 1661|      0|            }
 1662|       |
 1663|      0|            iqmp = ssh_make_bignum_string((BIGNUM *)biqmp);
 1664|      0|            if (iqmp == NULL) {
  ------------------
  |  Branch (1664:17): [True: 0, False: 0]
  ------------------
 1665|      0|                goto fail;
 1666|      0|            }
 1667|       |
 1668|      0|            p = ssh_make_bignum_string((BIGNUM *)bp);
 1669|      0|            if (p == NULL) {
  ------------------
  |  Branch (1669:17): [True: 0, False: 0]
  ------------------
 1670|      0|                goto fail;
 1671|      0|            }
 1672|       |
 1673|      0|            q = ssh_make_bignum_string((BIGNUM *)bq);
 1674|      0|            if (q == NULL) {
  ------------------
  |  Branch (1674:17): [True: 0, False: 0]
  ------------------
 1675|      0|                goto fail;
 1676|      0|            }
 1677|       |
 1678|      0|            rc = ssh_buffer_add_ssh_string(buffer, d);
 1679|      0|            if (rc < 0) {
  ------------------
  |  Branch (1679:17): [True: 0, False: 0]
  ------------------
 1680|      0|                goto fail;
 1681|      0|            }
 1682|      0|            rc = ssh_buffer_add_ssh_string(buffer, iqmp);
 1683|      0|            if (rc < 0) {
  ------------------
  |  Branch (1683:17): [True: 0, False: 0]
  ------------------
 1684|      0|                goto fail;
 1685|      0|            }
 1686|      0|            rc = ssh_buffer_add_ssh_string(buffer, p);
 1687|      0|            if (rc < 0) {
  ------------------
  |  Branch (1687:17): [True: 0, False: 0]
  ------------------
 1688|      0|                goto fail;
 1689|      0|            }
 1690|      0|            rc = ssh_buffer_add_ssh_string(buffer, q);
 1691|      0|            if (rc < 0) {
  ------------------
  |  Branch (1691:17): [True: 0, False: 0]
  ------------------
 1692|      0|                goto fail;
 1693|      0|            }
 1694|       |
 1695|      0|            ssh_string_burn(d);
 1696|      0|            SSH_STRING_FREE(d);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1697|      0|            ssh_string_burn(iqmp);
 1698|      0|            SSH_STRING_FREE(iqmp);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1699|      0|            ssh_string_burn(p);
 1700|      0|            SSH_STRING_FREE(p);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1701|      0|            ssh_string_burn(q);
 1702|      0|            SSH_STRING_FREE(q);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1703|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1704|       |            bignum_safe_free(bd);
 1705|       |            bignum_safe_free(biqmp);
 1706|       |            bignum_safe_free(bp);
 1707|       |            bignum_safe_free(bq);
 1708|       |#endif /* OPENSSL_VERSION_NUMBER */
 1709|      0|        }
 1710|      0|        ssh_string_burn(e);
 1711|      0|        SSH_STRING_FREE(e);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1712|      0|        ssh_string_burn(n);
 1713|      0|        SSH_STRING_FREE(n);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1714|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1715|       |        bignum_safe_free(bn);
 1716|       |        bignum_safe_free(be);
 1717|       |        OSSL_PARAM_free(params);
 1718|       |        params = NULL;
 1719|       |#endif /* OPENSSL_VERSION_NUMBER */
 1720|      0|        break;
 1721|      0|    }
 1722|  2.62k|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1722:5): [True: 2.62k, False: 0]
  ------------------
 1723|  2.62k|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1723:5): [True: 0, False: 2.62k]
  ------------------
 1724|  2.62k|        rc = EVP_PKEY_get_raw_public_key(key->key, NULL, &key_len);
 1725|  2.62k|        if (rc != 1) {
  ------------------
  |  Branch (1725:13): [True: 0, False: 2.62k]
  ------------------
 1726|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1727|      0|                    "Failed to get ed25519 raw public key length: %s",
 1728|      0|                    ERR_error_string(ERR_get_error(), NULL));
 1729|      0|            goto fail;
 1730|      0|        }
 1731|       |
 1732|  2.62k|        if (key_len != ED25519_KEY_LEN) {
  ------------------
  |  |   44|  2.62k|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1732:13): [True: 0, False: 2.62k]
  ------------------
 1733|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1734|      0|                    "Unexpected length of private key %zu. Expected %d.",
 1735|      0|                    key_len,
 1736|      0|                    ED25519_KEY_LEN);
 1737|      0|            goto fail;
 1738|      0|        }
 1739|       |
 1740|  2.62k|        ed25519_pubkey = malloc(key_len);
 1741|  2.62k|        if (ed25519_pubkey == NULL) {
  ------------------
  |  Branch (1741:13): [True: 0, False: 2.62k]
  ------------------
 1742|      0|            SSH_LOG(SSH_LOG_TRACE, "Out of memory");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1743|      0|            goto fail;
 1744|      0|        }
 1745|       |
 1746|  2.62k|        rc = EVP_PKEY_get_raw_public_key(key->key,
 1747|  2.62k|                                         (uint8_t *)ed25519_pubkey,
 1748|  2.62k|                                         &key_len);
 1749|  2.62k|        if (rc != 1) {
  ------------------
  |  Branch (1749:13): [True: 0, False: 2.62k]
  ------------------
 1750|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1751|      0|                    "Failed to get ed25519 raw public key:  %s",
 1752|      0|                    ERR_error_string(ERR_get_error(), NULL));
 1753|      0|            goto fail;
 1754|      0|        }
 1755|       |
 1756|  2.62k|        rc = ssh_buffer_pack(buffer,
  ------------------
  |  |   50|  2.62k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  2.62k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  2.62k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  2.62k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  2.62k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  2.62k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  2.62k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1757|  2.62k|                             "dP",
 1758|  2.62k|                             (uint32_t)ED25519_KEY_LEN,
 1759|  2.62k|                             (size_t)ED25519_KEY_LEN,
 1760|  2.62k|                             ed25519_pubkey);
 1761|  2.62k|        if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  2.62k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1761:13): [True: 0, False: 2.62k]
  ------------------
 1762|      0|            goto fail;
 1763|      0|        }
 1764|       |
 1765|  2.62k|        if (type == SSH_KEY_PRIVATE && key->type == SSH_KEYTYPE_ED25519) {
  ------------------
  |  Branch (1765:13): [True: 0, False: 2.62k]
  |  Branch (1765:40): [True: 0, False: 0]
  ------------------
 1766|      0|            key_len = 0;
 1767|      0|            rc = EVP_PKEY_get_raw_private_key(key->key, NULL, &key_len);
 1768|      0|            if (rc != 1) {
  ------------------
  |  Branch (1768:17): [True: 0, False: 0]
  ------------------
 1769|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1770|      0|                        "Failed to get ed25519 raw private key length: %s",
 1771|      0|                        ERR_error_string(ERR_get_error(), NULL));
 1772|      0|                goto fail;
 1773|      0|            }
 1774|       |
 1775|      0|            if (key_len != ED25519_KEY_LEN) {
  ------------------
  |  |   44|      0|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1775:17): [True: 0, False: 0]
  ------------------
 1776|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1777|      0|                        "Unexpected length of private key %zu. Expected %d.",
 1778|      0|                        key_len,
 1779|      0|                        ED25519_KEY_LEN);
 1780|      0|                goto fail;
 1781|      0|            }
 1782|       |
 1783|      0|            ed25519_privkey = malloc(key_len);
 1784|      0|            if (ed25519_privkey == NULL) {
  ------------------
  |  Branch (1784:17): [True: 0, False: 0]
  ------------------
 1785|      0|                SSH_LOG(SSH_LOG_TRACE, "Out of memory");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1786|      0|                goto fail;
 1787|      0|            }
 1788|       |
 1789|      0|            rc = EVP_PKEY_get_raw_private_key(key->key,
 1790|      0|                                              ed25519_privkey,
 1791|      0|                                              &key_len);
 1792|      0|            if (rc != 1) {
  ------------------
  |  Branch (1792:17): [True: 0, False: 0]
  ------------------
 1793|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1794|      0|                        "Failed to get ed25519 raw private key: %s",
 1795|      0|                        ERR_error_string(ERR_get_error(), NULL));
 1796|      0|                goto fail;
 1797|      0|            }
 1798|       |
 1799|      0|            rc = ssh_buffer_pack(buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1800|      0|                                 "dPP",
 1801|      0|                                 (uint32_t)(2 * ED25519_KEY_LEN),
 1802|      0|                                 (size_t)ED25519_KEY_LEN,
 1803|      0|                                 ed25519_privkey,
 1804|      0|                                 (size_t)ED25519_KEY_LEN,
 1805|      0|                                 ed25519_pubkey);
 1806|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1806:17): [True: 0, False: 0]
  ------------------
 1807|      0|                goto fail;
 1808|      0|            }
 1809|      0|            ssh_burn(ed25519_privkey, ED25519_KEY_LEN);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1810|      0|            SAFE_FREE(ed25519_privkey);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1811|  2.62k|        } else if (type == SSH_KEY_PRIVATE &&
  ------------------
  |  Branch (1811:20): [True: 0, False: 2.62k]
  ------------------
 1812|      0|                   key->type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1812:20): [True: 0, False: 0]
  ------------------
 1813|       |
 1814|      0|            rc = pki_buffer_pack_sk_priv_data(buffer, key);
 1815|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1815:17): [True: 0, False: 0]
  ------------------
 1816|      0|                goto fail;
 1817|      0|            }
 1818|  2.62k|        } else if (type == SSH_KEY_PUBLIC &&
  ------------------
  |  Branch (1818:20): [True: 2.62k, False: 0]
  ------------------
 1819|  2.62k|                   key->type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1819:20): [True: 0, False: 2.62k]
  ------------------
 1820|       |            /* public key can contain certificate sk information */
 1821|      0|            rc = ssh_buffer_add_ssh_string(buffer, key->sk_application);
 1822|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1822:17): [True: 0, False: 0]
  ------------------
 1823|      0|                goto fail;
 1824|      0|            }
 1825|      0|        }
 1826|       |
 1827|  2.62k|        SAFE_FREE(ed25519_pubkey);
  ------------------
  |  |  373|  2.62k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.62k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.62k]
  |  |  ------------------
  ------------------
 1828|  2.62k|        break;
 1829|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1829:5): [True: 0, False: 2.62k]
  ------------------
 1830|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1830:5): [True: 0, False: 2.62k]
  ------------------
 1831|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1831:5): [True: 0, False: 2.62k]
  ------------------
 1832|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1832:5): [True: 0, False: 2.62k]
  ------------------
 1833|      0|#ifdef HAVE_OPENSSL_ECC
 1834|      0|    {
 1835|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1836|       |        EC_GROUP *group = NULL;
 1837|       |        EC_POINT *point = NULL;
 1838|       |        const void *pubkey = NULL;
 1839|       |        size_t pubkey_len;
 1840|       |        OSSL_PARAM *locate_param = NULL;
 1841|       |#else
 1842|      0|        const EC_GROUP *group = NULL;
 1843|      0|        const EC_POINT *point = NULL;
 1844|      0|        const BIGNUM *exp = NULL;
 1845|      0|        EC_KEY *ec = NULL;
 1846|      0|#endif /* OPENSSL_VERSION_NUMBER */
 1847|       |
 1848|      0|        type_s = ssh_string_from_char(pki_key_ecdsa_nid_to_char(key->ecdsa_nid));
 1849|      0|        if (type_s == NULL) {
  ------------------
  |  Branch (1849:13): [True: 0, False: 0]
  ------------------
 1850|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1851|      0|            return NULL;
 1852|      0|        }
 1853|       |
 1854|      0|        rc = ssh_buffer_add_ssh_string(buffer, type_s);
 1855|      0|        SSH_STRING_FREE(type_s);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1856|      0|        if (rc < 0) {
  ------------------
  |  Branch (1856:13): [True: 0, False: 0]
  ------------------
 1857|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1858|      0|            return NULL;
 1859|      0|        }
 1860|       |
 1861|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1862|      0|        ec = EVP_PKEY_get0_EC_KEY(key->key);
 1863|      0|        if (ec == NULL) {
  ------------------
  |  Branch (1863:13): [True: 0, False: 0]
  ------------------
 1864|      0|            goto fail;
 1865|      0|        }
 1866|       |#ifdef WITH_PKCS11_URI
 1867|       |        if (ssh_key_is_private(key) && !EC_KEY_get0_public_key(ec)) {
 1868|       |            SSH_LOG(SSH_LOG_TRACE,
 1869|       |                    "It is mandatory to have separate"
 1870|       |                    " public ECDSA key objects in the PKCS #11 device."
 1871|       |                    " Unlike RSA, ECDSA public keys cannot be derived"
 1872|       |                    " from their private keys.");
 1873|       |            goto fail;
 1874|       |        }
 1875|       |#endif /* WITH_PKCS11_URI */
 1876|      0|        group = EC_KEY_get0_group(ec);
 1877|      0|        point = EC_KEY_get0_public_key(ec);
 1878|      0|        if (group == NULL || point == NULL) {
  ------------------
  |  Branch (1878:13): [True: 0, False: 0]
  |  Branch (1878:30): [True: 0, False: 0]
  ------------------
 1879|      0|            goto fail;
 1880|      0|        }
 1881|      0|        e = pki_key_make_ecpoint_string(group, point);
 1882|       |#else
 1883|       |        rc = EVP_PKEY_todata(key->key, EVP_PKEY_PUBLIC_KEY, &params);
 1884|       |        if (rc < 0) {
 1885|       |            goto fail;
 1886|       |        }
 1887|       |
 1888|       |        locate_param = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_PUB_KEY);
 1889|       |#ifdef WITH_PKCS11_URI
 1890|       |        if (ssh_key_is_private(key) && !locate_param) {
 1891|       |            SSH_LOG(SSH_LOG_TRACE,
 1892|       |                    "It is mandatory to have separate"
 1893|       |                    " public ECDSA key objects in the PKCS #11 device."
 1894|       |                    " Unlike RSA, ECDSA public keys cannot be derived"
 1895|       |                    " from their private keys.");
 1896|       |            goto fail;
 1897|       |        }
 1898|       |#endif /* WITH_PKCS11_URI */
 1899|       |
 1900|       |        rc = OSSL_PARAM_get_octet_string_ptr(locate_param, &pubkey, &pubkey_len);
 1901|       |        if (rc != 1) {
 1902|       |            goto fail;
 1903|       |        }
 1904|       |        /* Convert the data to low-level representation */
 1905|       |        group = EC_GROUP_new_by_curve_name_ex(NULL, NULL, key->ecdsa_nid);
 1906|       |        point = EC_POINT_new(group);
 1907|       |        rc = EC_POINT_oct2point(group, point, pubkey, pubkey_len, NULL);
 1908|       |        if (group == NULL || point == NULL || rc != 1) {
 1909|       |            EC_GROUP_free(group);
 1910|       |            EC_POINT_free(point);
 1911|       |            goto fail;
 1912|       |        }
 1913|       |
 1914|       |        e = pki_key_make_ecpoint_string(group, point);
 1915|       |        EC_GROUP_free(group);
 1916|       |        EC_POINT_free(point);
 1917|       |#endif /* OPENSSL_VERSION_NUMBER */
 1918|      0|        if (e == NULL) {
  ------------------
  |  Branch (1918:13): [True: 0, False: 0]
  ------------------
 1919|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1920|      0|            return NULL;
 1921|      0|        }
 1922|       |
 1923|      0|        rc = ssh_buffer_add_ssh_string(buffer, e);
 1924|      0|        if (rc < 0) {
  ------------------
  |  Branch (1924:13): [True: 0, False: 0]
  ------------------
 1925|      0|            goto fail;
 1926|      0|        }
 1927|       |
 1928|      0|        ssh_string_burn(e);
 1929|      0|        SSH_STRING_FREE(e);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1930|      0|        e = NULL;
 1931|       |
 1932|      0|        if (type == SSH_KEY_PRIVATE && key->type != SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1932:13): [True: 0, False: 0]
  |  Branch (1932:40): [True: 0, False: 0]
  ------------------
 1933|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1934|       |            OSSL_PARAM_free(params);
 1935|       |            rc = EVP_PKEY_todata(key->key, EVP_PKEY_KEYPAIR, &params);
 1936|       |            if (rc < 0) {
 1937|       |                goto fail;
 1938|       |            }
 1939|       |
 1940|       |            locate_param = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_PRIV_KEY);
 1941|       |            rc = OSSL_PARAM_get_BN(locate_param, &bd);
 1942|       |            if (rc != 1) {
 1943|       |                goto fail;
 1944|       |            }
 1945|       |            d = ssh_make_bignum_string((BIGNUM *)bd);
 1946|       |            if (d == NULL) {
 1947|       |                goto fail;
 1948|       |            }
 1949|       |            if (ssh_buffer_add_ssh_string(buffer, d) < 0) {
 1950|       |                goto fail;
 1951|       |            }
 1952|       |#else
 1953|      0|            exp = EC_KEY_get0_private_key(ec);
 1954|      0|            if (exp == NULL) {
  ------------------
  |  Branch (1954:17): [True: 0, False: 0]
  ------------------
 1955|      0|                goto fail;
 1956|      0|            }
 1957|      0|            d = ssh_make_bignum_string((BIGNUM *)exp);
 1958|      0|            if (d == NULL) {
  ------------------
  |  Branch (1958:17): [True: 0, False: 0]
  ------------------
 1959|      0|                goto fail;
 1960|      0|            }
 1961|      0|            rc = ssh_buffer_add_ssh_string(buffer, d);
 1962|      0|            if (rc < 0) {
  ------------------
  |  Branch (1962:17): [True: 0, False: 0]
  ------------------
 1963|      0|                goto fail;
 1964|      0|            }
 1965|      0|#endif /* OPENSSL_VERSION_NUMBER */
 1966|      0|            ssh_string_burn(d);
 1967|      0|            SSH_STRING_FREE(d);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1968|      0|            d = NULL;
 1969|      0|        } else if (type == SSH_KEY_PRIVATE &&
  ------------------
  |  Branch (1969:20): [True: 0, False: 0]
  ------------------
 1970|      0|                   key->type == SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1970:20): [True: 0, False: 0]
  ------------------
 1971|       |
 1972|      0|            rc = pki_buffer_pack_sk_priv_data(buffer, key);
 1973|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1973:17): [True: 0, False: 0]
  ------------------
 1974|      0|                goto fail;
 1975|      0|            }
 1976|      0|        } else if (type == SSH_KEY_PUBLIC &&
  ------------------
  |  Branch (1976:20): [True: 0, False: 0]
  ------------------
 1977|      0|                   key->type == SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1977:20): [True: 0, False: 0]
  ------------------
 1978|       |            /* public key can contain certificate sk information */
 1979|      0|            rc = ssh_buffer_add_ssh_string(buffer, key->sk_application);
 1980|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1980:17): [True: 0, False: 0]
  ------------------
 1981|      0|                goto fail;
 1982|      0|            }
 1983|      0|        }
 1984|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1985|       |        bignum_safe_free(bd);
 1986|       |        OSSL_PARAM_free(params);
 1987|       |        params = NULL;
 1988|       |#endif /* OPENSSL_VERSION_NUMBER */
 1989|      0|        break;
 1990|      0|    }
 1991|      0|#endif /* HAVE_OPENSSL_ECC */
 1992|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1992:5): [True: 0, False: 2.62k]
  ------------------
 1993|      0|    default:
  ------------------
  |  Branch (1993:5): [True: 0, False: 2.62k]
  ------------------
 1994|      0|        goto fail;
 1995|  2.62k|    }
 1996|       |
 1997|  2.62k|makestring:
 1998|  2.62k|    str = ssh_string_new(ssh_buffer_get_len(buffer));
 1999|  2.62k|    if (str == NULL) {
  ------------------
  |  Branch (1999:9): [True: 0, False: 2.62k]
  ------------------
 2000|      0|        goto fail;
 2001|      0|    }
 2002|       |
 2003|  2.62k|    rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
 2004|  2.62k|    if (rc < 0) {
  ------------------
  |  Branch (2004:9): [True: 0, False: 2.62k]
  ------------------
 2005|      0|        goto fail;
 2006|      0|    }
 2007|  2.62k|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|  2.62k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 2.62k, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 2.62k]
  |  |  ------------------
  ------------------
 2008|       |
 2009|  2.62k|    return str;
 2010|      0|fail:
 2011|      0|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2012|      0|    ssh_string_burn(str);
 2013|      0|    SSH_STRING_FREE(str);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2014|      0|    ssh_string_burn(e);
 2015|      0|    SSH_STRING_FREE(e);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2016|      0|    ssh_string_burn(p);
 2017|      0|    SSH_STRING_FREE(p);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2018|      0|    ssh_string_burn(g);
 2019|      0|    SSH_STRING_FREE(g);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2020|      0|    ssh_string_burn(q);
 2021|      0|    SSH_STRING_FREE(q);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2022|      0|    ssh_string_burn(n);
 2023|      0|    SSH_STRING_FREE(n);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2024|      0|    ssh_string_burn(d);
 2025|      0|    SSH_STRING_FREE(d);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2026|      0|    ssh_string_burn(iqmp);
 2027|      0|    SSH_STRING_FREE(iqmp);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2028|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 2029|       |    bignum_safe_free(bp);
 2030|       |    bignum_safe_free(bq);
 2031|       |    bignum_safe_free(bg);
 2032|       |    bignum_safe_free(bpub_key);
 2033|       |    bignum_safe_free(bn);
 2034|       |    bignum_safe_free(be);
 2035|       |    bignum_safe_free(bd);
 2036|       |    bignum_safe_free(biqmp);
 2037|       |    OSSL_PARAM_free(params);
 2038|       |#endif /* OPENSSL_VERSION_NUMBER */
 2039|      0|    free(ed25519_pubkey);
 2040|      0|    if (ed25519_privkey) {
  ------------------
  |  Branch (2040:9): [True: 0, False: 0]
  ------------------
 2041|      0|        ssh_burn(ed25519_privkey, ED25519_KEY_LEN);
  ------------------
  |  |  388|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 2042|      0|        free(ed25519_privkey);
 2043|      0|    }
 2044|       |
 2045|       |    return NULL;
 2046|  2.62k|}
pki_signature_to_blob:
 2136|    657|{
 2137|    657|    ssh_string sig_blob = NULL;
 2138|       |
 2139|    657|    switch(sig->type) {
 2140|      0|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2140:9): [True: 0, False: 657]
  ------------------
 2141|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2141:9): [True: 0, False: 657]
  ------------------
 2142|      0|            sig_blob = ssh_string_copy(sig->raw_sig);
 2143|      0|            break;
 2144|    657|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2144:9): [True: 657, False: 0]
  ------------------
 2145|    657|            sig_blob = pki_ed25519_signature_to_blob(sig);
 2146|    657|            break;
 2147|      0|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2147:9): [True: 0, False: 657]
  ------------------
 2148|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2148:9): [True: 0, False: 657]
  ------------------
 2149|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2149:9): [True: 0, False: 657]
  ------------------
 2150|      0|#ifdef HAVE_OPENSSL_ECC
 2151|      0|            sig_blob = pki_ecdsa_signature_to_blob(sig);
 2152|      0|            break;
 2153|      0|#endif /* HAVE_OPENSSL_ECC */
 2154|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2154:9): [True: 0, False: 657]
  ------------------
 2155|      0|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2155:9): [True: 0, False: 657]
  ------------------
 2156|       |            /* For SK keys, signature data is already in raw_sig */
 2157|      0|            sig_blob = ssh_string_copy(sig->raw_sig);
 2158|      0|            break;
 2159|      0|        default:
  ------------------
  |  Branch (2159:9): [True: 0, False: 657]
  ------------------
 2160|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2160:9): [True: 0, False: 657]
  ------------------
 2161|      0|            SSH_LOG(SSH_LOG_TRACE, "Unknown signature key type: %s", sig->type_c);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2162|      0|            return NULL;
 2163|    657|    }
 2164|       |
 2165|    657|    return sig_blob;
 2166|    657|}
pki_signature_from_blob:
 2393|    657|{
 2394|    657|    ssh_signature sig;
 2395|    657|    int rc;
 2396|       |
 2397|    657|    if (ssh_key_type_plain(pubkey->type) != type) {
  ------------------
  |  Branch (2397:9): [True: 0, False: 657]
  ------------------
 2398|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2399|      0|                "Incompatible public key provided (%d) expecting (%d)",
 2400|      0|                type,
 2401|      0|                pubkey->type);
 2402|      0|        return NULL;
 2403|      0|    }
 2404|       |
 2405|    657|    sig = ssh_signature_new();
 2406|    657|    if (sig == NULL) {
  ------------------
  |  Branch (2406:9): [True: 0, False: 657]
  ------------------
 2407|      0|        return NULL;
 2408|      0|    }
 2409|       |
 2410|    657|    sig->type = type;
 2411|    657|    sig->type_c = ssh_key_signature_to_char(type, hash_type);
 2412|    657|    sig->hash_type = hash_type;
 2413|       |
 2414|    657|    switch(type) {
 2415|      0|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2415:9): [True: 0, False: 657]
  ------------------
 2416|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2416:9): [True: 0, False: 657]
  ------------------
 2417|      0|            rc = pki_signature_from_rsa_blob(pubkey, sig_blob, sig);
 2418|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2418:17): [True: 0, False: 0]
  ------------------
 2419|      0|                goto error;
 2420|      0|            }
 2421|      0|            break;
 2422|    657|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2422:9): [True: 657, False: 0]
  ------------------
 2423|    657|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2423:9): [True: 0, False: 657]
  ------------------
 2424|    657|            rc = pki_signature_from_ed25519_blob(sig, sig_blob);
 2425|    657|            if (rc != SSH_OK){
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2425:17): [True: 0, False: 657]
  ------------------
 2426|      0|                goto error;
 2427|      0|            }
 2428|    657|            break;
 2429|    657|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2429:9): [True: 0, False: 657]
  ------------------
 2430|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2430:9): [True: 0, False: 657]
  ------------------
 2431|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2431:9): [True: 0, False: 657]
  ------------------
 2432|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2432:9): [True: 0, False: 657]
  ------------------
 2433|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2433:9): [True: 0, False: 657]
  ------------------
 2434|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2434:9): [True: 0, False: 657]
  ------------------
 2435|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2435:9): [True: 0, False: 657]
  ------------------
 2436|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2436:9): [True: 0, False: 657]
  ------------------
 2437|      0|#ifdef HAVE_OPENSSL_ECC
 2438|      0|            rc = pki_signature_from_ecdsa_blob(pubkey, sig_blob, sig);
 2439|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2439:17): [True: 0, False: 0]
  ------------------
 2440|      0|                goto error;
 2441|      0|            }
 2442|      0|            break;
 2443|      0|#endif
 2444|      0|        default:
  ------------------
  |  Branch (2444:9): [True: 0, False: 657]
  ------------------
 2445|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2445:9): [True: 0, False: 657]
  ------------------
 2446|      0|            SSH_LOG(SSH_LOG_TRACE, "Unknown signature type");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2447|      0|            goto error;
 2448|    657|    }
 2449|       |
 2450|    657|    return sig;
 2451|       |
 2452|      0|error:
 2453|      0|    ssh_signature_free(sig);
 2454|       |    return NULL;
 2455|    657|}
pki_sign_data:
 2549|    657|{
 2550|    657|    const EVP_MD *md = NULL;
 2551|    657|    EVP_MD_CTX *ctx = NULL;
 2552|    657|    EVP_PKEY *pkey = NULL;
 2553|       |
 2554|    657|    unsigned char *raw_sig_data = NULL;
 2555|    657|    size_t raw_sig_len;
 2556|       |
 2557|    657|    ssh_signature sig = NULL;
 2558|       |
 2559|    657|    int rc;
 2560|       |
 2561|    657|    if (privkey == NULL || !ssh_key_is_private(privkey) || input == NULL) {
  ------------------
  |  Branch (2561:9): [True: 0, False: 657]
  |  Branch (2561:28): [True: 0, False: 657]
  |  Branch (2561:60): [True: 0, False: 657]
  ------------------
 2562|      0|        SSH_LOG(SSH_LOG_TRACE, "Bad parameter provided to "
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2563|      0|                               "pki_sign_data()");
 2564|      0|        return NULL;
 2565|      0|    }
 2566|       |
 2567|       |    /* Check if public key and hash type are compatible */
 2568|    657|    rc = pki_key_check_hash_compatible(privkey, hash_type);
 2569|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2569:9): [True: 0, False: 657]
  ------------------
 2570|      0|        return NULL;
 2571|      0|    }
 2572|       |
 2573|       |    /* Set hash algorithm to be used */
 2574|    657|    md = pki_digest_to_md(hash_type);
 2575|    657|    if (md == NULL) {
  ------------------
  |  Branch (2575:9): [True: 657, False: 0]
  ------------------
 2576|    657|        if (hash_type != SSH_DIGEST_AUTO) {
  ------------------
  |  Branch (2576:13): [True: 0, False: 657]
  ------------------
 2577|      0|            return NULL;
 2578|      0|        }
 2579|    657|    }
 2580|       |
 2581|       |    /* Setup private key EVP_PKEY */
 2582|    657|    pkey = pki_key_to_pkey(privkey);
 2583|    657|    if (pkey == NULL) {
  ------------------
  |  Branch (2583:9): [True: 0, False: 657]
  ------------------
 2584|      0|        return NULL;
 2585|      0|    }
 2586|       |
 2587|       |    /* Allocate buffer for signature */
 2588|    657|    raw_sig_len = (size_t)EVP_PKEY_size(pkey);
 2589|    657|    raw_sig_data = (unsigned char *)malloc(raw_sig_len);
 2590|    657|    if (raw_sig_data == NULL) {
  ------------------
  |  Branch (2590:9): [True: 0, False: 657]
  ------------------
 2591|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2592|      0|        goto out;
 2593|      0|    }
 2594|       |
 2595|       |    /* Create the context */
 2596|    657|    ctx = EVP_MD_CTX_new();
 2597|    657|    if (ctx == NULL) {
  ------------------
  |  Branch (2597:9): [True: 0, False: 657]
  ------------------
 2598|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2599|      0|        goto out;
 2600|      0|    }
 2601|       |
 2602|       |    /* Sign the data */
 2603|    657|    rc = EVP_DigestSignInit(ctx, NULL, md, NULL, pkey);
 2604|    657|    if (rc != 1){
  ------------------
  |  Branch (2604:9): [True: 0, False: 657]
  ------------------
 2605|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2606|      0|                "EVP_DigestSignInit() failed: %s",
 2607|      0|                ERR_error_string(ERR_get_error(), NULL));
 2608|      0|        goto out;
 2609|      0|    }
 2610|       |
 2611|    657|    rc = EVP_DigestSign(ctx, raw_sig_data, &raw_sig_len, input, input_len);
 2612|    657|    if (rc != 1) {
  ------------------
  |  Branch (2612:9): [True: 0, False: 657]
  ------------------
 2613|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2614|      0|                "EVP_DigestSign() failed: %s",
 2615|      0|                ERR_error_string(ERR_get_error(), NULL));
 2616|      0|        goto out;
 2617|      0|    }
 2618|       |
 2619|       |#ifdef DEBUG_CRYPTO
 2620|       |        ssh_log_hexdump("Generated signature", raw_sig_data, raw_sig_len);
 2621|       |#endif
 2622|       |
 2623|       |    /* Allocate and fill output signature */
 2624|    657|    sig = ssh_signature_new();
 2625|    657|    if (sig == NULL) {
  ------------------
  |  Branch (2625:9): [True: 0, False: 657]
  ------------------
 2626|      0|        goto out;
 2627|      0|    }
 2628|       |
 2629|    657|    sig->raw_sig = ssh_string_new(raw_sig_len);
 2630|    657|    if (sig->raw_sig == NULL) {
  ------------------
  |  Branch (2630:9): [True: 0, False: 657]
  ------------------
 2631|      0|        ssh_signature_free(sig);
 2632|      0|        sig = NULL;
 2633|      0|        goto out;
 2634|      0|    }
 2635|       |
 2636|    657|    rc = ssh_string_fill(sig->raw_sig, raw_sig_data, raw_sig_len);
 2637|    657|    if (rc < 0) {
  ------------------
  |  Branch (2637:9): [True: 0, False: 657]
  ------------------
 2638|      0|        ssh_signature_free(sig);
 2639|      0|        sig = NULL;
 2640|      0|        goto out;
 2641|      0|    }
 2642|       |
 2643|    657|    sig->type = privkey->type;
 2644|    657|    sig->hash_type = hash_type;
 2645|    657|    sig->type_c = ssh_key_signature_to_char(privkey->type, hash_type);
 2646|       |
 2647|    657|out:
 2648|    657|    if (ctx != NULL) {
  ------------------
  |  Branch (2648:9): [True: 657, False: 0]
  ------------------
 2649|    657|        EVP_MD_CTX_free(ctx);
 2650|    657|    }
 2651|    657|    if (raw_sig_data != NULL) {
  ------------------
  |  Branch (2651:9): [True: 657, False: 0]
  ------------------
 2652|    657|        ssh_burn(raw_sig_data, raw_sig_len);
  ------------------
  |  |  388|    657|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 2653|    657|    }
 2654|       |    SAFE_FREE(raw_sig_data);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
 2655|    657|    EVP_PKEY_free(pkey);
 2656|    657|    return sig;
 2657|    657|}
pki_verify_data_signature:
 2676|    657|{
 2677|    657|    const EVP_MD *md = NULL;
 2678|    657|    EVP_MD_CTX *ctx = NULL;
 2679|    657|    EVP_PKEY *pkey = NULL;
 2680|       |
 2681|    657|    unsigned char *raw_sig_data = NULL;
 2682|    657|    size_t raw_sig_len;
 2683|       |
 2684|       |    /* Function return code
 2685|       |     * Do not change this variable throughout the function until the signature
 2686|       |     * is successfully verified!
 2687|       |     */
 2688|    657|    int rc = SSH_ERROR;
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2689|    657|    int ok;
 2690|       |
 2691|    657|    if (pubkey == NULL || ssh_key_is_private(pubkey) || input == NULL ||
  ------------------
  |  Branch (2691:9): [True: 0, False: 657]
  |  Branch (2691:27): [True: 0, False: 657]
  |  Branch (2691:57): [True: 0, False: 657]
  ------------------
 2692|    657|        signature == NULL || signature->raw_sig == NULL)
  ------------------
  |  Branch (2692:9): [True: 0, False: 657]
  |  Branch (2692:30): [True: 0, False: 657]
  ------------------
 2693|      0|    {
 2694|      0|        SSH_LOG(SSH_LOG_TRACE, "Bad parameter provided to "
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2695|      0|                               "pki_verify_data_signature()");
 2696|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2697|      0|    }
 2698|       |
 2699|       |    /* Check if public key and hash type are compatible */
 2700|    657|    ok = pki_key_check_hash_compatible(pubkey, signature->hash_type);
 2701|    657|    if (ok != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2701:9): [True: 0, False: 657]
  ------------------
 2702|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2703|      0|    }
 2704|       |
 2705|       |    /* Get the signature to be verified */
 2706|    657|    raw_sig_data = ssh_string_data(signature->raw_sig);
 2707|    657|    raw_sig_len = ssh_string_len(signature->raw_sig);
 2708|    657|    if (raw_sig_data == NULL) {
  ------------------
  |  Branch (2708:9): [True: 0, False: 657]
  ------------------
 2709|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2710|      0|    }
 2711|       |
 2712|       |    /* Set hash algorithm to be used */
 2713|    657|    md = pki_digest_to_md(signature->hash_type);
 2714|    657|    if (md == NULL) {
  ------------------
  |  Branch (2714:9): [True: 657, False: 0]
  ------------------
 2715|    657|        if (signature->hash_type != SSH_DIGEST_AUTO) {
  ------------------
  |  Branch (2715:13): [True: 0, False: 657]
  ------------------
 2716|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2717|      0|        }
 2718|    657|    }
 2719|       |
 2720|       |    /* Setup public key EVP_PKEY */
 2721|    657|    pkey = pki_key_to_pkey(pubkey);
 2722|    657|    if (pkey == NULL) {
  ------------------
  |  Branch (2722:9): [True: 0, False: 657]
  ------------------
 2723|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2724|      0|    }
 2725|       |
 2726|       |    /* Create the context */
 2727|    657|    ctx = EVP_MD_CTX_new();
 2728|    657|    if (ctx == NULL) {
  ------------------
  |  Branch (2728:9): [True: 0, False: 657]
  ------------------
 2729|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2730|      0|                "Failed to create EVP_MD_CTX: %s",
 2731|      0|                ERR_error_string(ERR_get_error(), NULL));
 2732|      0|        goto out;
 2733|      0|    }
 2734|       |
 2735|       |    /* Verify the signature */
 2736|    657|    ok = EVP_DigestVerifyInit(ctx, NULL, md, NULL, pkey);
 2737|    657|    if (ok != 1){
  ------------------
  |  Branch (2737:9): [True: 0, False: 657]
  ------------------
 2738|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2739|      0|                "EVP_DigestVerifyInit() failed: %s",
 2740|      0|                ERR_error_string(ERR_get_error(), NULL));
 2741|      0|        goto out;
 2742|      0|    }
 2743|       |
 2744|    657|    ok = EVP_DigestVerify(ctx, raw_sig_data, raw_sig_len, input, input_len);
 2745|    657|    if (ok != 1) {
  ------------------
  |  Branch (2745:9): [True: 0, False: 657]
  ------------------
 2746|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2747|      0|                "Signature invalid: %s",
 2748|      0|                ERR_error_string(ERR_get_error(), NULL));
 2749|      0|        goto out;
 2750|      0|    }
 2751|       |
 2752|    657|    SSH_LOG(SSH_LOG_TRACE, "Signature valid");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2753|    657|    rc = SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
 2754|       |
 2755|    657|out:
 2756|    657|    EVP_MD_CTX_free(ctx);
 2757|    657|    EVP_PKEY_free(pkey);
 2758|    657|    return rc;
 2759|    657|}
pki_crypto.c:pki_digest_to_md:
 2458|  1.31k|{
 2459|  1.31k|    const EVP_MD *md = NULL;
 2460|       |
 2461|  1.31k|    switch (hash_type) {
 2462|      0|    case SSH_DIGEST_SHA256:
  ------------------
  |  Branch (2462:5): [True: 0, False: 1.31k]
  ------------------
 2463|      0|        md = EVP_sha256();
 2464|      0|        break;
 2465|      0|    case SSH_DIGEST_SHA384:
  ------------------
  |  Branch (2465:5): [True: 0, False: 1.31k]
  ------------------
 2466|      0|        md = EVP_sha384();
 2467|      0|        break;
 2468|      0|    case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (2468:5): [True: 0, False: 1.31k]
  ------------------
 2469|      0|        md = EVP_sha512();
 2470|      0|        break;
 2471|      0|    case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (2471:5): [True: 0, False: 1.31k]
  ------------------
 2472|      0|        md = EVP_sha1();
 2473|      0|        break;
 2474|  1.31k|    case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (2474:5): [True: 1.31k, False: 0]
  ------------------
 2475|  1.31k|        md = NULL;
 2476|  1.31k|        break;
 2477|      0|    default:
  ------------------
  |  Branch (2477:5): [True: 0, False: 1.31k]
  ------------------
 2478|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown hash algorithm for type: %d",
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2479|      0|                hash_type);
 2480|      0|        return NULL;
 2481|  1.31k|    }
 2482|       |
 2483|  1.31k|    return md;
 2484|  1.31k|}
pki_crypto.c:pki_key_to_pkey:
 2487|  1.31k|{
 2488|  1.31k|    EVP_PKEY *pkey = NULL;
 2489|  1.31k|    int rc = 0;
 2490|       |
 2491|  1.31k|    switch (key->type) {
 2492|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2492:5): [True: 0, False: 1.31k]
  ------------------
 2493|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2493:5): [True: 0, False: 1.31k]
  ------------------
 2494|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (2494:5): [True: 0, False: 1.31k]
  ------------------
 2495|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2495:5): [True: 0, False: 1.31k]
  ------------------
 2496|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2496:5): [True: 0, False: 1.31k]
  ------------------
 2497|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2497:5): [True: 0, False: 1.31k]
  ------------------
 2498|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2498:5): [True: 0, False: 1.31k]
  ------------------
 2499|      0|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2499:5): [True: 0, False: 1.31k]
  ------------------
 2500|      0|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2500:5): [True: 0, False: 1.31k]
  ------------------
 2501|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2501:5): [True: 0, False: 1.31k]
  ------------------
 2502|      0|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2502:5): [True: 0, False: 1.31k]
  ------------------
 2503|  1.31k|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2503:5): [True: 1.31k, False: 0]
  ------------------
 2504|  1.31k|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (2504:5): [True: 0, False: 1.31k]
  ------------------
 2505|  1.31k|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2505:5): [True: 0, False: 1.31k]
  ------------------
 2506|  1.31k|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (2506:5): [True: 0, False: 1.31k]
  ------------------
 2507|  1.31k|        if (key->key == NULL) {
  ------------------
  |  Branch (2507:13): [True: 0, False: 1.31k]
  ------------------
 2508|      0|            SSH_LOG(SSH_LOG_TRACE, "NULL key->key");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2509|      0|            goto error;
 2510|      0|        }
 2511|  1.31k|        rc = EVP_PKEY_up_ref(key->key);
 2512|  1.31k|        if (rc != 1) {
  ------------------
  |  Branch (2512:13): [True: 0, False: 1.31k]
  ------------------
 2513|      0|            SSH_LOG(SSH_LOG_TRACE, "Failed to reference EVP_PKEY");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2514|      0|            return NULL;
 2515|      0|        }
 2516|  1.31k|        pkey = key->key;
 2517|  1.31k|        break;
 2518|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2518:5): [True: 0, False: 1.31k]
  ------------------
 2519|      0|    default:
  ------------------
  |  Branch (2519:5): [True: 0, False: 1.31k]
  ------------------
 2520|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown private key algorithm for type: %d",
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2521|      0|                key->type);
 2522|      0|        goto error;
 2523|  1.31k|    }
 2524|       |
 2525|  1.31k|    return pkey;
 2526|       |
 2527|      0|error:
 2528|      0|    EVP_PKEY_free(pkey);
 2529|       |    return NULL;
 2530|  1.31k|}

pki_ed25519_signature_to_blob:
   40|    657|{
   41|    657|    ssh_string sig_blob = NULL;
   42|    657|    int rc;
   43|       |
   44|    657|#ifdef HAVE_LIBCRYPTO
   45|       |    /* When using the OpenSSL implementation, the signature is stored in raw_sig
   46|       |     * which is shared by all algorithms.*/
   47|    657|    if (sig->raw_sig == NULL) {
  ------------------
  |  Branch (47:9): [True: 0, False: 657]
  ------------------
   48|      0|        return NULL;
   49|      0|    }
   50|       |#else
   51|       |    /* When using the internal implementation, the signature is stored in an
   52|       |     * algorithm specific field. */
   53|       |    if (sig->ed25519_sig == NULL) {
   54|       |        return NULL;
   55|       |    }
   56|       |#endif
   57|       |
   58|    657|    sig_blob = ssh_string_new(ED25519_SIG_LEN);
  ------------------
  |  |   39|    657|#define ED25519_SIG_LEN 64
  ------------------
   59|    657|    if (sig_blob == NULL) {
  ------------------
  |  Branch (59:9): [True: 0, False: 657]
  ------------------
   60|      0|        return NULL;
   61|      0|    }
   62|       |
   63|    657|#ifdef HAVE_LIBCRYPTO
   64|    657|    rc = ssh_string_fill(sig_blob, ssh_string_data(sig->raw_sig),
   65|    657|                         ssh_string_len(sig->raw_sig));
   66|       |#else
   67|       |    rc = ssh_string_fill(sig_blob, sig->ed25519_sig, ED25519_SIG_LEN);
   68|       |#endif
   69|    657|    if (rc < 0) {
  ------------------
  |  Branch (69:9): [True: 0, False: 657]
  ------------------
   70|      0|        SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  910|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 0, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
   71|      0|        return NULL;
   72|      0|    }
   73|       |
   74|    657|    return sig_blob;
   75|    657|}
pki_signature_from_ed25519_blob:
   89|    657|{
   90|    657|    size_t len;
   91|       |
   92|    657|    len = ssh_string_len(sig_blob);
   93|    657|    if (len != ED25519_SIG_LEN){
  ------------------
  |  |   39|    657|#define ED25519_SIG_LEN 64
  ------------------
  |  Branch (93:9): [True: 0, False: 657]
  ------------------
   94|      0|        SSH_LOG(SSH_LOG_TRACE, "Invalid ssh-ed25519 signature len: %zu", len);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   95|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   96|      0|    }
   97|       |
   98|    657|#ifdef HAVE_LIBCRYPTO
   99|    657|    sig->raw_sig = ssh_string_copy(sig_blob);
  100|       |#else
  101|       |    sig->ed25519_sig = malloc(ED25519_SIG_LEN);
  102|       |    if (sig->ed25519_sig == NULL){
  103|       |        return SSH_ERROR;
  104|       |    }
  105|       |    memcpy(sig->ed25519_sig, ssh_string_data(sig_blob), ED25519_SIG_LEN);
  106|       |#endif
  107|       |
  108|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  109|    657|}

ssh_poll_init:
   91|      2|{
   92|      2|    return;
   93|      2|}
ssh_poll:
  115|  23.7k|{
  116|  23.7k|    return poll((struct pollfd *)fds, nfds, timeout);
  117|  23.7k|}
ssh_poll_new:
  396|  1.31k|{
  397|  1.31k|    ssh_poll_handle p = NULL;
  398|       |
  399|  1.31k|    p = malloc(sizeof(struct ssh_poll_handle_struct));
  400|  1.31k|    if (p == NULL) {
  ------------------
  |  Branch (400:9): [True: 0, False: 1.31k]
  ------------------
  401|      0|        return NULL;
  402|      0|    }
  403|  1.31k|    ZERO_STRUCTP(p);
  ------------------
  |  |  379|  1.31k|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (379:34): [True: 1.31k, False: 0]
  |  |  |  Branch (379:85): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  404|       |
  405|  1.31k|    p->x.fd = fd;
  406|  1.31k|    p->events = events;
  407|  1.31k|    p->cb = cb;
  408|  1.31k|    p->cb_data = userdata;
  409|       |
  410|  1.31k|    return p;
  411|  1.31k|}
ssh_poll_free:
  420|  1.31k|{
  421|  1.31k|    if (p->ctx != NULL) {
  ------------------
  |  Branch (421:9): [True: 1.31k, False: 0]
  ------------------
  422|  1.31k|        ssh_poll_ctx_remove(p->ctx, p);
  423|  1.31k|        p->ctx = NULL;
  424|  1.31k|    }
  425|       |    SAFE_FREE(p);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  426|  1.31k|}
ssh_poll_get_ctx:
  436|  18.4k|{
  437|  18.4k|    return p->ctx;
  438|  18.4k|}
ssh_poll_get_events:
  448|  48.6k|{
  449|  48.6k|    return p->events;
  450|  48.6k|}
ssh_poll_set_events:
  461|  51.2k|{
  462|  51.2k|    p->events = events;
  463|  51.2k|    if (p->ctx != NULL) {
  ------------------
  |  Branch (463:9): [True: 47.2k, False: 3.94k]
  ------------------
  464|  47.2k|        if (!ssh_poll_is_locked(p)) {
  ------------------
  |  Branch (464:13): [True: 19.1k, False: 28.1k]
  ------------------
  465|  19.1k|            p->ctx->pollfds[p->x.idx].events = events;
  466|  28.1k|        } else if (!(p->ctx->pollfds[p->x.idx].events & POLLOUT)) {
  ------------------
  |  Branch (466:20): [True: 22.4k, False: 5.67k]
  ------------------
  467|       |            /* if locked, allow only setting POLLOUT to prevent recursive
  468|       |             * callbacks */
  469|       |            p->ctx->pollfds[p->x.idx].events = events & POLLOUT;
  470|  22.4k|        }
  471|  47.2k|    }
  472|  51.2k|}
ssh_poll_add_events:
  498|  37.3k|{
  499|  37.3k|    ssh_poll_set_events(p, ssh_poll_get_events(p) | events);
  500|  37.3k|}
ssh_poll_remove_events:
  510|  11.3k|{
  511|  11.3k|    ssh_poll_set_events(p, ssh_poll_get_events(p) & ~events);
  512|  11.3k|}
ssh_poll_ctx_new:
  560|  1.97k|{
  561|  1.97k|    ssh_poll_ctx ctx;
  562|       |
  563|  1.97k|    ctx = malloc(sizeof(struct ssh_poll_ctx_struct));
  564|  1.97k|    if (ctx == NULL) {
  ------------------
  |  Branch (564:9): [True: 0, False: 1.97k]
  ------------------
  565|      0|        return NULL;
  566|      0|    }
  567|  1.97k|    ZERO_STRUCTP(ctx);
  ------------------
  |  |  379|  1.97k|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (379:34): [True: 1.97k, False: 0]
  |  |  |  Branch (379:85): [Folded, False: 1.97k]
  |  |  ------------------
  ------------------
  568|       |
  569|  1.97k|    if (chunk_size == 0) {
  ------------------
  |  Branch (569:9): [True: 0, False: 1.97k]
  ------------------
  570|      0|        chunk_size = SSH_POLL_CTX_CHUNK;
  ------------------
  |  |   43|      0|#define SSH_POLL_CTX_CHUNK			5
  ------------------
  571|      0|    }
  572|       |
  573|  1.97k|    ctx->chunk_size = chunk_size;
  574|       |
  575|  1.97k|    return ctx;
  576|  1.97k|}
ssh_poll_ctx_free:
  584|  1.97k|{
  585|  1.97k|    if (ctx->polls_allocated > 0) {
  ------------------
  |  Branch (585:9): [True: 1.97k, False: 0]
  ------------------
  586|  1.97k|        while (ctx->polls_used > 0) {
  ------------------
  |  Branch (586:16): [True: 0, False: 1.97k]
  ------------------
  587|      0|            ssh_poll_handle p = ctx->pollptrs[0];
  588|       |            /*
  589|       |             * The free function calls ssh_poll_ctx_remove() and decrements
  590|       |             * ctx->polls_used
  591|       |             */
  592|      0|            ssh_poll_free(p);
  593|      0|        }
  594|       |
  595|  1.97k|        SAFE_FREE(ctx->pollptrs);
  ------------------
  |  |  373|  1.97k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.97k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.97k]
  |  |  ------------------
  ------------------
  596|  1.97k|        SAFE_FREE(ctx->pollfds);
  ------------------
  |  |  373|  1.97k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.97k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.97k]
  |  |  ------------------
  ------------------
  597|  1.97k|    }
  598|       |
  599|       |    SAFE_FREE(ctx);
  ------------------
  |  |  373|  1.97k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.97k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.97k]
  |  |  ------------------
  ------------------
  600|  1.97k|}
ssh_poll_ctx_add:
  647|  2.62k|{
  648|  2.62k|    socket_t fd;
  649|       |
  650|  2.62k|    if (p->ctx != NULL) {
  ------------------
  |  Branch (650:9): [True: 0, False: 2.62k]
  ------------------
  651|       |        /* already attached to a context */
  652|      0|        return -1;
  653|      0|    }
  654|       |
  655|  2.62k|    if (ctx->polls_used == ctx->polls_allocated &&
  ------------------
  |  Branch (655:9): [True: 1.97k, False: 657]
  ------------------
  656|  1.97k|        ssh_poll_ctx_resize(ctx, ctx->polls_allocated + ctx->chunk_size) < 0) {
  ------------------
  |  Branch (656:9): [True: 0, False: 1.97k]
  ------------------
  657|      0|        return -1;
  658|      0|    }
  659|       |
  660|  2.62k|    fd = p->x.fd;
  661|  2.62k|    p->x.idx = ctx->polls_used++;
  662|  2.62k|    ctx->pollptrs[p->x.idx] = p;
  663|  2.62k|    ctx->pollfds[p->x.idx].fd = fd;
  664|  2.62k|    ctx->pollfds[p->x.idx].events = p->events;
  665|  2.62k|    ctx->pollfds[p->x.idx].revents = 0;
  666|  2.62k|    p->ctx = ctx;
  667|       |
  668|  2.62k|    return 0;
  669|  2.62k|}
ssh_poll_ctx_remove:
  697|  2.62k|{
  698|  2.62k|    size_t i;
  699|       |
  700|  2.62k|    i = p->x.idx;
  701|  2.62k|    p->x.fd = ctx->pollfds[i].fd;
  702|  2.62k|    p->ctx = NULL;
  703|       |
  704|  2.62k|    ctx->polls_used--;
  705|       |
  706|       |    /* fill the empty poll slot with the last one */
  707|  2.62k|    if (ctx->polls_used > 0 && ctx->polls_used != i) {
  ------------------
  |  Branch (707:9): [True: 0, False: 2.62k]
  |  Branch (707:32): [True: 0, False: 0]
  ------------------
  708|      0|        ctx->pollfds[i] = ctx->pollfds[ctx->polls_used];
  709|      0|        ctx->pollptrs[i] = ctx->pollptrs[ctx->polls_used];
  710|      0|        ctx->pollptrs[i]->x.idx = i;
  711|      0|    }
  712|       |
  713|       |    /* this will always leave at least chunk_size polls allocated */
  714|  2.62k|    if (ctx->polls_allocated - ctx->polls_used > ctx->chunk_size) {
  ------------------
  |  Branch (714:9): [True: 0, False: 2.62k]
  ------------------
  715|      0|        ssh_poll_ctx_resize(ctx, ctx->polls_allocated - ctx->chunk_size);
  716|      0|    }
  717|  2.62k|}
ssh_poll_is_locked:
  726|  72.2k|{
  727|  72.2k|    if (p == NULL) {
  ------------------
  |  Branch (727:9): [True: 0, False: 72.2k]
  ------------------
  728|      0|        return false;
  729|      0|    }
  730|  72.2k|    return p->lock_cnt > 0;
  731|  72.2k|}
ssh_poll_ctx_dopoll:
  750|  23.7k|{
  751|  23.7k|    int rc;
  752|  23.7k|    size_t i, used;
  753|  23.7k|    ssh_poll_handle p = NULL;
  754|  23.7k|    socket_t fd;
  755|  23.7k|    int revents;
  756|  23.7k|    struct ssh_timestamp ts;
  757|       |
  758|  23.7k|    if (ctx->polls_used == 0) {
  ------------------
  |  Branch (758:9): [True: 0, False: 23.7k]
  ------------------
  759|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  760|      0|    }
  761|       |
  762|       |    /* Allow only POLLOUT events on locked sockets as that means we are called
  763|       |     * recursively and we only want process the POLLOUT events here to flush
  764|       |     * output buffer */
  765|  47.4k|    for (i = 0; i < ctx->polls_used; i++) {
  ------------------
  |  Branch (765:17): [True: 23.7k, False: 23.7k]
  ------------------
  766|       |        /* The lock allows only POLLOUT events: drop the rest */
  767|  23.7k|        if (ssh_poll_is_locked(ctx->pollptrs[i])) {
  ------------------
  |  Branch (767:13): [True: 1.31k, False: 22.4k]
  ------------------
  768|  1.31k|            ctx->pollfds[i].events &= POLLOUT;
  769|  1.31k|        }
  770|  23.7k|    }
  771|  23.7k|    ssh_timestamp_init(&ts);
  772|  23.7k|    do {
  773|  23.7k|        int tm = ssh_timeout_update(&ts, timeout);
  774|  23.7k|        rc = ssh_poll(ctx->pollfds, ctx->polls_used, tm);
  775|  23.7k|    } while (rc == -1 && errno == EINTR);
  ------------------
  |  Branch (775:14): [True: 0, False: 23.7k]
  |  Branch (775:26): [True: 0, False: 0]
  ------------------
  776|       |
  777|  23.7k|    if (rc < 0) {
  ------------------
  |  Branch (777:9): [True: 0, False: 23.7k]
  ------------------
  778|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  779|      0|    }
  780|  23.7k|    if (rc == 0) {
  ------------------
  |  Branch (780:9): [True: 0, False: 23.7k]
  ------------------
  781|      0|        return SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  782|      0|    }
  783|       |
  784|  23.7k|    used = ctx->polls_used;
  785|  46.7k|    for (i = 0; i < used && rc > 0; ) {
  ------------------
  |  Branch (785:17): [True: 23.6k, False: 23.0k]
  |  Branch (785:29): [True: 23.6k, False: 0]
  ------------------
  786|  23.6k|        revents = ctx->pollfds[i].revents;
  787|       |        /* Do not pass any other events except for POLLOUT to callback when
  788|       |         * called recursively more than 2 times. On s390x the poll will be
  789|       |         * spammed with POLLHUP events causing infinite recursion when the user
  790|       |         * callback issues some write/flush/poll calls. */
  791|  23.6k|        if (ctx->pollptrs[i]->lock_cnt > 2) {
  ------------------
  |  Branch (791:13): [True: 0, False: 23.6k]
  ------------------
  792|      0|            revents &= POLLOUT;
  793|      0|        }
  794|  23.6k|        if (revents == 0) {
  ------------------
  |  Branch (794:13): [True: 0, False: 23.6k]
  ------------------
  795|      0|            i++;
  796|  23.6k|        } else {
  797|  23.6k|            int ret;
  798|       |
  799|  23.6k|            p = ctx->pollptrs[i];
  800|  23.6k|            fd = ctx->pollfds[i].fd;
  801|       |            /* avoid having any event caught during callback */
  802|  23.6k|            ctx->pollfds[i].events = 0;
  803|  23.6k|            p->lock_cnt++;
  804|  23.6k|            if (p->cb && (ret = p->cb(p, fd, revents, p->cb_data)) < 0) {
  ------------------
  |  Branch (804:17): [True: 23.6k, False: 13]
  |  Branch (804:26): [True: 656, False: 23.0k]
  ------------------
  805|    656|                if (ret == -2) {
  ------------------
  |  Branch (805:21): [True: 656, False: 0]
  ------------------
  806|    656|                    return -1;
  807|    656|                }
  808|       |                /* the poll was removed, reload the used counter and start again
  809|       |                 */
  810|      0|                used = ctx->polls_used;
  811|      0|                i = 0;
  812|  23.0k|            } else {
  813|  23.0k|                ctx->pollfds[i].revents = 0;
  814|  23.0k|                ctx->pollfds[i].events = p->events;
  815|  23.0k|                p->lock_cnt--;
  816|  23.0k|                i++;
  817|  23.0k|            }
  818|       |
  819|  23.0k|            rc--;
  820|  23.0k|        }
  821|  23.6k|    }
  822|       |
  823|  23.0k|    return rc;
  824|  23.7k|}
ssh_poll_get_default_ctx:
  834|  1.31k|{
  835|  1.31k|    if (session->default_poll_ctx != NULL) {
  ------------------
  |  Branch (835:9): [True: 0, False: 1.31k]
  ------------------
  836|      0|        return session->default_poll_ctx;
  837|      0|    }
  838|       |    /* 2 is enough for the default one */
  839|  1.31k|    session->default_poll_ctx = ssh_poll_ctx_new(2);
  840|  1.31k|    return session->default_poll_ctx;
  841|  1.31k|}
ssh_event_new:
  866|    657|{
  867|    657|    ssh_event event;
  868|       |
  869|    657|    event = malloc(sizeof(struct ssh_event_struct));
  870|    657|    if (event == NULL) {
  ------------------
  |  Branch (870:9): [True: 0, False: 657]
  ------------------
  871|      0|        return NULL;
  872|      0|    }
  873|    657|    ZERO_STRUCTP(event);
  ------------------
  |  |  379|    657|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (379:34): [True: 657, False: 0]
  |  |  |  Branch (379:85): [Folded, False: 657]
  |  |  ------------------
  ------------------
  874|       |
  875|    657|    event->ctx = ssh_poll_ctx_new(2);
  876|    657|    if (event->ctx == NULL) {
  ------------------
  |  Branch (876:9): [True: 0, False: 657]
  ------------------
  877|      0|        free(event);
  878|      0|        return NULL;
  879|      0|    }
  880|       |
  881|    657|#ifdef WITH_SERVER
  882|    657|    event->sessions = ssh_list_new();
  883|    657|    if (event->sessions == NULL) {
  ------------------
  |  Branch (883:9): [True: 0, False: 657]
  ------------------
  884|      0|        ssh_poll_ctx_free(event->ctx);
  885|      0|        free(event);
  886|      0|        return NULL;
  887|      0|    }
  888|    657|#endif
  889|       |
  890|    657|    return event;
  891|    657|}
ssh_event_add_session:
 1000|    657|{
 1001|    657|    ssh_poll_handle p = NULL;
 1002|    657|#ifdef WITH_SERVER
 1003|    657|    struct ssh_iterator *iterator = NULL;
 1004|    657|#endif
 1005|    657|    int rc;
 1006|       |
 1007|    657|    if (event == NULL || event->ctx == NULL || session == NULL) {
  ------------------
  |  Branch (1007:9): [True: 0, False: 657]
  |  Branch (1007:26): [True: 0, False: 657]
  |  Branch (1007:48): [True: 0, False: 657]
  ------------------
 1008|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1009|      0|    }
 1010|    657|    if (session->default_poll_ctx == NULL) {
  ------------------
  |  Branch (1010:9): [True: 0, False: 657]
  ------------------
 1011|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1012|      0|    }
 1013|  1.31k|    while (session->default_poll_ctx->polls_used > 0) {
  ------------------
  |  Branch (1013:12): [True: 657, False: 657]
  ------------------
 1014|    657|        p = session->default_poll_ctx->pollptrs[0];
 1015|       |        /*
 1016|       |         * ssh_poll_ctx_remove() decrements
 1017|       |         * session->default_poll_ctx->polls_used
 1018|       |         */
 1019|    657|        ssh_poll_ctx_remove(session->default_poll_ctx, p);
 1020|    657|        rc = ssh_poll_ctx_add(event->ctx, p);
 1021|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1021:13): [True: 0, False: 657]
  ------------------
 1022|      0|            return rc;
 1023|      0|        }
 1024|       |        /* associate the pollhandler with a session so we can put it back
 1025|       |         * at ssh_event_free()
 1026|       |         */
 1027|    657|        p->session = session;
 1028|    657|    }
 1029|    657|#ifdef WITH_SERVER
 1030|    657|    iterator = ssh_list_get_iterator(event->sessions);
 1031|    657|    while (iterator != NULL) {
  ------------------
  |  Branch (1031:12): [True: 0, False: 657]
  ------------------
 1032|      0|        if ((ssh_session)iterator->data == session) {
  ------------------
  |  Branch (1032:13): [True: 0, False: 0]
  ------------------
 1033|       |            /* allow only one instance of this session */
 1034|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1035|      0|        }
 1036|      0|        iterator = iterator->next;
 1037|      0|    }
 1038|    657|    if (ssh_list_append(event->sessions, session) == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1038:9): [True: 0, False: 657]
  ------------------
 1039|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1040|      0|    }
 1041|    657|#endif
 1042|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
 1043|    657|}
ssh_event_dopoll:
 1082|  5.25k|{
 1083|  5.25k|    int rc;
 1084|       |
 1085|  5.25k|    if (event == NULL || event->ctx == NULL) {
  ------------------
  |  Branch (1085:9): [True: 0, False: 5.25k]
  |  Branch (1085:26): [True: 0, False: 5.25k]
  ------------------
 1086|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1087|      0|    }
 1088|  5.25k|    rc = ssh_poll_ctx_dopoll(event->ctx, timeout);
 1089|  5.25k|    return rc;
 1090|  5.25k|}
ssh_event_free:
 1220|    657|{
 1221|    657|    size_t used, i;
 1222|    657|    ssh_poll_handle p = NULL;
 1223|       |
 1224|    657|    if (event == NULL) {
  ------------------
  |  Branch (1224:9): [True: 0, False: 657]
  ------------------
 1225|      0|        return;
 1226|      0|    }
 1227|       |
 1228|    657|    if (event->ctx != NULL) {
  ------------------
  |  Branch (1228:9): [True: 657, False: 0]
  ------------------
 1229|    657|        used = event->ctx->polls_used;
 1230|  1.31k|        for (i = 0; i < used; i++) {
  ------------------
  |  Branch (1230:21): [True: 657, False: 657]
  ------------------
 1231|    657|            p = event->ctx->pollptrs[i];
 1232|    657|            if (p->session != NULL) {
  ------------------
  |  Branch (1232:17): [True: 657, False: 0]
  ------------------
 1233|    657|                ssh_poll_ctx_remove(event->ctx, p);
 1234|    657|                ssh_poll_ctx_add(p->session->default_poll_ctx, p);
 1235|    657|                p->session = NULL;
 1236|    657|                used = 0;
 1237|    657|            }
 1238|    657|        }
 1239|       |
 1240|    657|        ssh_poll_ctx_free(event->ctx);
 1241|    657|    }
 1242|    657|#ifdef WITH_SERVER
 1243|    657|    if (event->sessions != NULL) {
  ------------------
  |  Branch (1243:9): [True: 657, False: 0]
  ------------------
 1244|    657|        ssh_list_free(event->sessions);
 1245|    657|    }
 1246|    657|#endif
 1247|    657|    free(event);
 1248|    657|}
poll.c:ssh_poll_ctx_resize:
  603|  1.97k|{
  604|  1.97k|    ssh_poll_handle *pollptrs = NULL;
  605|  1.97k|    ssh_pollfd_t *pollfds = NULL;
  606|       |
  607|  1.97k|    pollptrs = realloc(ctx->pollptrs, sizeof(ssh_poll_handle) * new_size);
  608|  1.97k|    if (pollptrs == NULL) {
  ------------------
  |  Branch (608:9): [True: 0, False: 1.97k]
  ------------------
  609|       |        /* Fail, but keep the old value to be freed later */
  610|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  611|      0|    }
  612|  1.97k|    ctx->pollptrs = pollptrs;
  613|       |
  614|  1.97k|    pollfds = realloc(ctx->pollfds, sizeof(ssh_pollfd_t) * new_size);
  615|  1.97k|    if (pollfds == NULL) {
  ------------------
  |  Branch (615:9): [True: 0, False: 1.97k]
  ------------------
  616|      0|        if (ctx->polls_allocated == 0) {
  ------------------
  |  Branch (616:13): [True: 0, False: 0]
  ------------------
  617|       |            /* This was initial allocation -- just free what we allocated above
  618|       |             * and fail */
  619|      0|            SAFE_FREE(ctx->pollptrs);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  620|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  621|      0|        }
  622|       |        /* Try to realloc the pollptrs back to the original size */
  623|      0|        pollptrs = realloc(ctx->pollptrs,
  624|      0|                           sizeof(ssh_poll_handle) * ctx->polls_allocated);
  625|      0|        if (pollptrs == NULL) {
  ------------------
  |  Branch (625:13): [True: 0, False: 0]
  ------------------
  626|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  627|      0|        }
  628|      0|        ctx->pollptrs = pollptrs;
  629|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  630|      0|    }
  631|       |
  632|  1.97k|    ctx->pollfds = pollfds;
  633|  1.97k|    ctx->polls_allocated = new_size;
  634|       |
  635|  1.97k|    return SSH_OK;
  ------------------
  |  |  316|  1.97k|#define SSH_OK 0     /* No error */
  ------------------
  636|  1.97k|}

ssh_scp_new:
   67|    658|{
   68|    658|    ssh_scp scp = NULL;
   69|       |
   70|    658|    if (session == NULL || location == NULL) {
  ------------------
  |  Branch (70:9): [True: 0, False: 658]
  |  Branch (70:28): [True: 0, False: 658]
  ------------------
   71|      0|        goto error;
   72|      0|    }
   73|       |
   74|    658|    scp = (ssh_scp)calloc(1, sizeof(struct ssh_scp_struct));
   75|    658|    if (scp == NULL) {
  ------------------
  |  Branch (75:9): [True: 0, False: 658]
  ------------------
   76|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   77|      0|                      "Error allocating memory for ssh_scp");
   78|      0|        goto error;
   79|      0|    }
   80|       |
   81|    658|    if ((mode & ~SSH_SCP_RECURSIVE) != SSH_SCP_WRITE &&
  ------------------
  |  Branch (81:9): [True: 657, False: 1]
  ------------------
   82|    657|        (mode & ~SSH_SCP_RECURSIVE) != SSH_SCP_READ)
  ------------------
  |  Branch (82:9): [True: 0, False: 657]
  ------------------
   83|      0|    {
   84|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   85|      0|                      "Invalid mode %d for ssh_scp_new()", mode);
   86|      0|        goto error;
   87|      0|    }
   88|       |
   89|    658|    if (strlen(location) > 32 * 1024) {
  ------------------
  |  Branch (89:9): [True: 0, False: 658]
  ------------------
   90|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   91|      0|                      "Location path is too long");
   92|      0|        goto error;
   93|      0|    }
   94|       |
   95|    658|    scp->location = strdup(location);
   96|    658|    if (scp->location == NULL) {
  ------------------
  |  Branch (96:9): [True: 0, False: 658]
  ------------------
   97|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   98|      0|                      "Error allocating memory for ssh_scp");
   99|      0|        goto error;
  100|      0|    }
  101|       |
  102|    658|    scp->session = session;
  103|    658|    scp->mode = mode & ~SSH_SCP_RECURSIVE;
  104|    658|    scp->recursive = (mode & SSH_SCP_RECURSIVE) != 0;
  105|    658|    scp->channel = NULL;
  106|    658|    scp->state = SSH_SCP_NEW;
  107|       |
  108|    658|    return scp;
  109|       |
  110|      0|error:
  111|      0|    ssh_scp_free(scp);
  112|       |    return NULL;
  113|    658|}
ssh_scp_init:
  127|    658|{
  128|    658|    int rc;
  129|    658|    char execbuffer[PATH_MAX] = {0};
  130|    658|    char *quoted_location = NULL;
  131|    658|    size_t quoted_location_len = 0;
  132|    658|    size_t scp_location_len;
  133|       |
  134|    658|    if (scp == NULL) {
  ------------------
  |  Branch (134:9): [True: 0, False: 658]
  ------------------
  135|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  136|      0|    }
  137|       |
  138|    658|    if (scp->state != SSH_SCP_NEW) {
  ------------------
  |  Branch (138:9): [True: 0, False: 658]
  ------------------
  139|      0|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  140|      0|                      "ssh_scp_init called under invalid state");
  141|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  142|      0|    }
  143|       |
  144|    658|    if (scp->location == NULL) {
  ------------------
  |  Branch (144:9): [True: 0, False: 658]
  ------------------
  145|      0|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  146|      0|                      "Invalid scp context: location is NULL");
  147|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  148|      0|    }
  149|       |
  150|    658|    SSH_LOG(SSH_LOG_DEBUG, "Initializing scp session %s %son location '%s'",
  ------------------
  |  |  281|  2.63k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 1, False: 657]
  |  |  |  Branch (281:34): [True: 1, False: 657]
  |  |  ------------------
  ------------------
  151|    658|            scp->mode == SSH_SCP_WRITE?"write":"read",
  152|    658|            scp->recursive ? "recursive " : "",
  153|    658|            scp->location);
  154|       |
  155|    658|    scp->channel = ssh_channel_new(scp->session);
  156|    658|    if (scp->channel == NULL) {
  ------------------
  |  Branch (156:9): [True: 0, False: 658]
  ------------------
  157|      0|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  158|      0|                      "Channel creation failed for scp");
  159|      0|        scp->state = SSH_SCP_ERROR;
  160|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  161|      0|    }
  162|       |
  163|    658|    rc = ssh_channel_open_session(scp->channel);
  164|    658|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    658|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (164:9): [True: 1, False: 657]
  ------------------
  165|      1|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  166|      1|                      "Failed to open channel for scp");
  167|      1|        scp->state = SSH_SCP_ERROR;
  168|      1|        return SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  169|      1|    }
  170|       |
  171|       |    /* In the worst case, each character would be replaced by 3 plus the string
  172|       |     * terminator '\0' */
  173|    657|    scp_location_len = strlen(scp->location);
  174|    657|    quoted_location_len = ((size_t)3 * scp_location_len) + 1;
  175|       |    /* Paranoia check */
  176|    657|    if (quoted_location_len < scp_location_len) {
  ------------------
  |  Branch (176:9): [True: 0, False: 657]
  ------------------
  177|      0|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  178|      0|                      "Buffer overflow detected");
  179|      0|        scp->state = SSH_SCP_ERROR;
  180|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  181|      0|    }
  182|       |
  183|    657|    quoted_location = (char *)calloc(1, quoted_location_len);
  184|    657|    if (quoted_location == NULL) {
  ------------------
  |  Branch (184:9): [True: 0, False: 657]
  ------------------
  185|      0|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  186|      0|                      "Failed to allocate memory for quoted location");
  187|      0|        scp->state = SSH_SCP_ERROR;
  188|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  189|      0|    }
  190|       |
  191|    657|    rc = ssh_quote_file_name(scp->location, quoted_location,
  192|    657|                             quoted_location_len);
  193|    657|    if (rc <= 0) {
  ------------------
  |  Branch (193:9): [True: 0, False: 657]
  ------------------
  194|      0|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  195|      0|                      "Failed to single quote command location");
  196|      0|        SAFE_FREE(quoted_location);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  197|      0|        scp->state = SSH_SCP_ERROR;
  198|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  199|      0|    }
  200|       |
  201|       |    /* Some servers do not handle the quoting well. Pass in the raw file
  202|       |     * location */
  203|    657|    if (scp->session->flags & SSH_SESSION_FLAG_SCP_QUOTING_BROKEN) {
  ------------------
  |  |   95|    657|#define SSH_SESSION_FLAG_SCP_QUOTING_BROKEN 0x0040
  ------------------
  |  Branch (203:9): [True: 0, False: 657]
  ------------------
  204|      0|        free(quoted_location);
  205|      0|        quoted_location = strdup(scp->location);
  206|      0|        if (quoted_location == NULL) {
  ------------------
  |  Branch (206:13): [True: 0, False: 0]
  ------------------
  207|      0|            ssh_set_error_oom(scp->session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  208|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  209|      0|        }
  210|      0|    }
  211|       |
  212|    657|    if (scp->mode == SSH_SCP_WRITE) {
  ------------------
  |  Branch (212:9): [True: 0, False: 657]
  ------------------
  213|      0|        snprintf(execbuffer, sizeof(execbuffer), "scp -t %s %s",
  214|      0|                scp->recursive ? "-r" : "", quoted_location);
  ------------------
  |  Branch (214:17): [True: 0, False: 0]
  ------------------
  215|    657|    } else {
  216|    657|        snprintf(execbuffer, sizeof(execbuffer), "scp -f %s %s",
  217|    657|                scp->recursive ? "-r" : "", quoted_location);
  ------------------
  |  Branch (217:17): [True: 0, False: 657]
  ------------------
  218|    657|    }
  219|       |
  220|    657|    SAFE_FREE(quoted_location);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  221|       |
  222|    657|    SSH_LOG(SSH_LOG_DEBUG, "Executing command: %s", execbuffer);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  223|       |
  224|    657|    rc = ssh_channel_request_exec(scp->channel, execbuffer);
  225|    657|    if (rc == SSH_ERROR){
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (225:9): [True: 656, False: 1]
  ------------------
  226|    656|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|    656|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  227|    656|                      "Failed executing command: %s", execbuffer);
  228|    656|        scp->state = SSH_SCP_ERROR;
  229|    656|        return SSH_ERROR;
  ------------------
  |  |  317|    656|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  230|    656|    }
  231|       |
  232|      1|    if (scp->mode == SSH_SCP_WRITE) {
  ------------------
  |  Branch (232:9): [True: 0, False: 1]
  ------------------
  233|      0|        rc = ssh_scp_response(scp, NULL);
  234|      0|        if (rc != 0) {
  ------------------
  |  Branch (234:13): [True: 0, False: 0]
  ------------------
  235|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  236|      0|        }
  237|      1|    } else {
  238|      1|        ssh_channel_write(scp->channel, "", 1);
  239|      1|    }
  240|       |
  241|      1|    if (scp->mode == SSH_SCP_WRITE) {
  ------------------
  |  Branch (241:9): [True: 0, False: 1]
  ------------------
  242|      0|        scp->state = SSH_SCP_WRITE_INITED;
  243|      1|    } else {
  244|      1|        scp->state = SSH_SCP_READ_INITED;
  245|      1|    }
  246|       |
  247|      1|    return SSH_OK;
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  248|      1|}
ssh_scp_close:
  262|    660|{
  263|    660|    char buffer[128] = {0};
  264|    660|    int rc;
  265|       |
  266|    660|    if (scp == NULL) {
  ------------------
  |  Branch (266:9): [True: 0, False: 660]
  ------------------
  267|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  268|      0|    }
  269|       |
  270|    660|    if (scp->channel != NULL) {
  ------------------
  |  Branch (270:9): [True: 660, False: 0]
  ------------------
  271|    660|        if (ssh_channel_send_eof(scp->channel) == SSH_ERROR) {
  ------------------
  |  |  317|    660|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (271:13): [True: 4, False: 656]
  ------------------
  272|      4|            scp->state = SSH_SCP_ERROR;
  273|      4|            return SSH_ERROR;
  ------------------
  |  |  317|      4|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  274|      4|        }
  275|       |        /* avoid situations where data are buffered and
  276|       |         * not yet stored on disk. This can happen if the close is sent
  277|       |         * before we got the EOF back
  278|       |         */
  279|    656|        while (!ssh_channel_is_eof(scp->channel)) {
  ------------------
  |  Branch (279:16): [True: 656, False: 0]
  ------------------
  280|    656|            rc = ssh_channel_read(scp->channel, buffer, sizeof(buffer), 0);
  281|    656|            if (rc == SSH_ERROR || rc == SSH_AGAIN || rc == 0) {
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
                          if (rc == SSH_ERROR || rc == SSH_AGAIN || rc == 0) {
  ------------------
  |  |  318|    656|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (281:17): [True: 656, False: 0]
  |  Branch (281:36): [True: 0, False: 0]
  |  Branch (281:55): [True: 0, False: 0]
  ------------------
  282|    656|                break;
  283|    656|            }
  284|    656|        }
  285|       |
  286|    656|        if (ssh_channel_close(scp->channel) == SSH_ERROR) {
  ------------------
  |  |  317|    656|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (286:13): [True: 0, False: 656]
  ------------------
  287|      0|            scp->state = SSH_SCP_ERROR;
  288|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  289|      0|        }
  290|       |
  291|    656|        ssh_channel_free(scp->channel);
  292|    656|        scp->channel = NULL;
  293|    656|    }
  294|       |
  295|    656|    scp->state = SSH_SCP_NEW;
  296|    656|    return SSH_OK;
  ------------------
  |  |  316|    656|#define SSH_OK 0     /* No error */
  ------------------
  297|    660|}
ssh_scp_free:
  309|    658|{
  310|    658|    if (scp == NULL) {
  ------------------
  |  Branch (310:9): [True: 0, False: 658]
  ------------------
  311|      0|        return;
  312|      0|    }
  313|       |
  314|    658|    if (scp->state != SSH_SCP_NEW) {
  ------------------
  |  Branch (314:9): [True: 2, False: 656]
  ------------------
  315|      2|        ssh_scp_close(scp);
  316|      2|    }
  317|       |
  318|    658|    if (scp->channel) {
  ------------------
  |  Branch (318:9): [True: 2, False: 656]
  ------------------
  319|      2|        ssh_channel_free(scp->channel);
  320|      2|    }
  321|       |
  322|    658|    SAFE_FREE(scp->location);
  ------------------
  |  |  373|    658|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 658, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 658]
  |  |  ------------------
  ------------------
  323|    658|    SAFE_FREE(scp->request_name);
  ------------------
  |  |  373|    658|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 658]
  |  |  |  Branch (373:71): [Folded, False: 658]
  |  |  ------------------
  ------------------
  324|    658|    SAFE_FREE(scp->warning);
  ------------------
  |  |  373|    658|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 658]
  |  |  |  Branch (373:71): [Folded, False: 658]
  |  |  ------------------
  ------------------
  325|       |    SAFE_FREE(scp);
  ------------------
  |  |  373|    658|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 658, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 658]
  |  |  ------------------
  ------------------
  326|    658|}
ssh_scp_read_string:
  760|      2|{
  761|      2|    size_t read = 0;
  762|      2|    int err = SSH_OK;
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
  763|       |
  764|      2|    if (scp == NULL) {
  ------------------
  |  Branch (764:9): [True: 0, False: 2]
  ------------------
  765|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  766|      0|    }
  767|       |
  768|  4.09k|    while (read < len - 1) {
  ------------------
  |  Branch (768:12): [True: 4.09k, False: 0]
  ------------------
  769|  4.09k|        err = ssh_channel_read(scp->channel, &buffer[read], 1, 0);
  770|  4.09k|        if (err == SSH_ERROR) {
  ------------------
  |  |  317|  4.09k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (770:13): [True: 0, False: 4.09k]
  ------------------
  771|      0|            break;
  772|      0|        }
  773|       |
  774|  4.09k|        if (err == 0) {
  ------------------
  |  Branch (774:13): [True: 1, False: 4.09k]
  ------------------
  775|      1|            ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  776|      1|                          "End of file while reading string");
  777|      1|            err = SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  778|      1|            break;
  779|      1|        }
  780|       |
  781|  4.09k|        if (err == SSH_AGAIN) {
  ------------------
  |  |  318|  4.09k|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (781:13): [True: 0, False: 4.09k]
  ------------------
  782|      0|            ssh_set_error(scp->session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  783|      0|                          SSH_FATAL,
  784|      0|                          "SCP: ssh_channel_read timeout");
  785|      0|            err = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  786|      0|            break;
  787|      0|        }
  788|       |
  789|  4.09k|        read++;
  790|  4.09k|        if (buffer[read - 1] == '\n') {
  ------------------
  |  Branch (790:13): [True: 1, False: 4.09k]
  ------------------
  791|      1|            break;
  792|      1|        }
  793|  4.09k|    }
  794|       |
  795|      2|    buffer[read] = 0;
  796|      2|    return err;
  797|      2|}
ssh_scp_pull_request:
  822|      2|{
  823|      2|    char buffer[PATH_MAX] = {0};
  824|      2|    char *mode = NULL;
  825|      2|    char *p, *tmp;
  826|      2|    uint64_t size;
  827|      2|    char *name = NULL;
  828|      2|    int rc;
  829|       |
  830|      2|    if (scp == NULL) {
  ------------------
  |  Branch (830:9): [True: 0, False: 2]
  ------------------
  831|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  832|      0|    }
  833|       |
  834|      2|    if (scp->state != SSH_SCP_READ_INITED) {
  ------------------
  |  Branch (834:9): [True: 0, False: 2]
  ------------------
  835|      0|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  836|      0|                      "ssh_scp_pull_request called under invalid state");
  837|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  838|      0|    }
  839|       |
  840|      2|    rc = ssh_scp_read_string(scp, buffer, sizeof(buffer));
  841|      2|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (841:9): [True: 1, False: 1]
  ------------------
  842|      1|        if (ssh_channel_is_eof(scp->channel)) {
  ------------------
  |  Branch (842:13): [True: 1, False: 0]
  ------------------
  843|      1|            scp->state = SSH_SCP_TERMINATED;
  844|      1|            return SSH_SCP_REQUEST_EOF;
  845|      1|        }
  846|      0|        return rc;
  847|      1|    }
  848|       |
  849|      1|    p = strchr(buffer, '\n');
  850|      1|    if (p != NULL) {
  ------------------
  |  Branch (850:9): [True: 0, False: 1]
  ------------------
  851|      0|        *p = '\0';
  852|      0|    }
  853|       |
  854|      1|    SSH_LOG(SSH_LOG_DEBUG, "Received SCP request: '%s'", buffer);
  ------------------
  |  |  281|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  855|      1|    switch(buffer[0]) {
  856|      0|    case 'C':
  ------------------
  |  Branch (856:5): [True: 0, False: 1]
  ------------------
  857|       |        /* File */
  858|      0|    case 'D':
  ------------------
  |  Branch (858:5): [True: 0, False: 1]
  ------------------
  859|       |        /* Directory */
  860|      0|        p = strchr(buffer, ' ');
  861|      0|        if (p == NULL) {
  ------------------
  |  Branch (861:13): [True: 0, False: 0]
  ------------------
  862|      0|            goto error;
  863|      0|        }
  864|      0|        *p = '\0';
  865|      0|        p++;
  866|       |        //mode = strdup(&buffer[1]);
  867|      0|        scp->request_mode = ssh_scp_integer_mode(&buffer[1]);
  868|      0|        tmp = p;
  869|      0|        p = strchr(p, ' ');
  870|      0|        if (p == NULL) {
  ------------------
  |  Branch (870:13): [True: 0, False: 0]
  ------------------
  871|      0|            goto error;
  872|      0|        }
  873|      0|        *p = 0;
  874|      0|        size = strtoull(tmp, NULL, 10);
  875|      0|        p++;
  876|      0|        name = strdup(p);
  877|       |        /* Catch invalid name:
  878|       |         *  - empty ones
  879|       |         *  - containing any forward slash -- directory traversal handled
  880|       |         *    differently
  881|       |         *  - special names "." and ".." referring to the current and parent
  882|       |         *    directories -- they are not expected either
  883|       |         */
  884|      0|        if (name == NULL || name[0] == '\0' || strchr(name, '/') ||
  ------------------
  |  Branch (884:13): [True: 0, False: 0]
  |  Branch (884:29): [True: 0, False: 0]
  |  Branch (884:48): [True: 0, False: 0]
  ------------------
  885|      0|            strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
  ------------------
  |  Branch (885:13): [True: 0, False: 0]
  |  Branch (885:39): [True: 0, False: 0]
  ------------------
  886|      0|            ssh_set_error(scp->session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (311:43): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  887|      0|                          SSH_FATAL,
  888|      0|                          "Received invalid filename: %s",
  889|      0|                          name == NULL ? "<NULL>" : name);
  890|      0|            SAFE_FREE(name);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  891|      0|            goto error;
  892|      0|        }
  893|      0|        SAFE_FREE(scp->request_name);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  894|      0|        scp->request_name = name;
  895|      0|        if (buffer[0] == 'C') {
  ------------------
  |  Branch (895:13): [True: 0, False: 0]
  ------------------
  896|      0|            scp->filelen = size;
  897|      0|            scp->request_type = SSH_SCP_REQUEST_NEWFILE;
  898|      0|        } else {
  899|      0|            scp->filelen = '0';
  900|      0|            scp->request_type = SSH_SCP_REQUEST_NEWDIR;
  901|      0|        }
  902|      0|        scp->state = SSH_SCP_READ_REQUESTED;
  903|      0|        scp->processed = 0;
  904|      0|        return scp->request_type;
  905|      0|        break;
  906|      0|    case 'E':
  ------------------
  |  Branch (906:5): [True: 0, False: 1]
  ------------------
  907|      0|        scp->request_type = SSH_SCP_REQUEST_ENDDIR;
  908|      0|        ssh_channel_write(scp->channel, "", 1);
  909|      0|        return scp->request_type;
  910|      0|    case 0x1:
  ------------------
  |  Branch (910:5): [True: 0, False: 1]
  ------------------
  911|      0|        ssh_set_error(scp->session, SSH_REQUEST_DENIED,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  912|      0|                      "SCP: Warning: %s", &buffer[1]);
  913|      0|        scp->request_type = SSH_SCP_REQUEST_WARNING;
  914|      0|        SAFE_FREE(scp->warning);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  915|      0|        scp->warning = strdup(&buffer[1]);
  916|      0|        return scp->request_type;
  917|      0|    case 0x2:
  ------------------
  |  Branch (917:5): [True: 0, False: 1]
  ------------------
  918|      0|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  919|      0|                      "SCP: Error: %s", &buffer[1]);
  920|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  921|      0|    case 'T':
  ------------------
  |  Branch (921:5): [True: 0, False: 1]
  ------------------
  922|       |        /* Timestamp */
  923|      1|    default:
  ------------------
  |  Branch (923:5): [True: 1, False: 0]
  ------------------
  924|      1|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  925|      1|                      "Unhandled message: (%d)%s", buffer[0], buffer);
  926|      1|        return SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  927|      1|    }
  928|       |
  929|       |    /* a parsing error occurred */
  930|      0|error:
  931|      0|    SAFE_FREE(name);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  932|      0|    SAFE_FREE(mode);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  933|      0|    ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  934|      0|                  "Parsing error while parsing message: %s", buffer);
  935|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  936|      1|}
ssh_scp_deny_request:
  952|      1|{
  953|      1|    char *buffer = NULL;
  954|      1|    size_t len;
  955|      1|    int rc;
  956|       |
  957|      1|    if (scp == NULL) {
  ------------------
  |  Branch (957:9): [True: 0, False: 1]
  ------------------
  958|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  959|      0|    }
  960|       |
  961|      1|    if (scp->state != SSH_SCP_READ_REQUESTED) {
  ------------------
  |  Branch (961:9): [True: 1, False: 0]
  ------------------
  962|      1|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  963|      1|                      "ssh_scp_deny_request called under invalid state");
  964|      1|        return SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  965|      1|    }
  966|       |
  967|      0|    len = strlen(reason) + 3;
  968|      0|    buffer = malloc(len);
  969|      0|    if (buffer == NULL) {
  ------------------
  |  Branch (969:9): [True: 0, False: 0]
  ------------------
  970|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  971|      0|    }
  972|       |
  973|      0|    snprintf(buffer, len, "%c%s\n", 2, reason);
  974|      0|    rc = ssh_channel_write(scp->channel, buffer, len - 1);
  975|      0|    free(buffer);
  976|      0|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (976:9): [True: 0, False: 0]
  ------------------
  977|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  978|      0|    }
  979|       |
  980|      0|    else {
  981|      0|        scp->state = SSH_SCP_READ_INITED;
  982|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  983|      0|    }
  984|      0|}
ssh_scp_accept_request:
  998|      1|{
  999|      1|    char buffer[] = {0x00};
 1000|      1|    int rc;
 1001|      1|    if (scp == NULL) {
  ------------------
  |  Branch (1001:9): [True: 0, False: 1]
  ------------------
 1002|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1003|      0|    }
 1004|       |
 1005|      1|    if (scp->state != SSH_SCP_READ_REQUESTED) {
  ------------------
  |  Branch (1005:9): [True: 1, False: 0]
  ------------------
 1006|      1|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1007|      1|                      "ssh_scp_deny_request called under invalid state");
 1008|      1|        return SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1009|      1|    }
 1010|       |
 1011|      0|    rc = ssh_channel_write(scp->channel, buffer, 1);
 1012|      0|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1012:9): [True: 0, False: 0]
  ------------------
 1013|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1014|      0|    }
 1015|       |
 1016|      0|    if (scp->request_type == SSH_SCP_REQUEST_NEWFILE) {
  ------------------
  |  Branch (1016:9): [True: 0, False: 0]
  ------------------
 1017|      0|        scp->state = SSH_SCP_READ_READING;
 1018|      0|    } else {
 1019|      0|        scp->state = SSH_SCP_READ_INITED;
 1020|      0|    }
 1021|       |
 1022|      0|    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1023|      0|}
ssh_scp_read:
 1040|      1|{
 1041|      1|    int rc;
 1042|      1|    int code;
 1043|       |
 1044|      1|    if (scp == NULL) {
  ------------------
  |  Branch (1044:9): [True: 0, False: 1]
  ------------------
 1045|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1046|      0|    }
 1047|       |
 1048|      1|    if (scp->state == SSH_SCP_READ_REQUESTED &&
  ------------------
  |  Branch (1048:9): [True: 0, False: 1]
  ------------------
 1049|      0|        scp->request_type == SSH_SCP_REQUEST_NEWFILE)
  ------------------
  |  Branch (1049:9): [True: 0, False: 0]
  ------------------
 1050|      0|    {
 1051|      0|        rc = ssh_scp_accept_request(scp);
 1052|      0|        if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1052:13): [True: 0, False: 0]
  ------------------
 1053|      0|            return rc;
 1054|      0|        }
 1055|      0|    }
 1056|       |
 1057|      1|    if (scp->state != SSH_SCP_READ_READING) {
  ------------------
  |  Branch (1057:9): [True: 1, False: 0]
  ------------------
 1058|      1|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1059|      1|                      "ssh_scp_read called under invalid state");
 1060|      1|        return SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1061|      1|    }
 1062|       |
 1063|      0|    if (scp->processed + size > scp->filelen) {
  ------------------
  |  Branch (1063:9): [True: 0, False: 0]
  ------------------
 1064|      0|        size = (size_t) (scp->filelen - scp->processed);
 1065|      0|    }
 1066|       |
 1067|      0|    if (size > 65536) {
  ------------------
  |  Branch (1067:9): [True: 0, False: 0]
  ------------------
 1068|      0|        size = 65536; /* avoid too large reads */
 1069|      0|    }
 1070|       |
 1071|      0|    rc = ssh_channel_read(scp->channel, buffer, size, 0);
 1072|      0|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1072:9): [True: 0, False: 0]
  ------------------
 1073|      0|        scp->state = SSH_SCP_ERROR;
 1074|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1075|      0|    }
 1076|      0|    if (rc == SSH_AGAIN) {
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (1076:9): [True: 0, False: 0]
  ------------------
 1077|      0|        ssh_set_error(scp->session, SSH_FATAL, "SCP: ssh_channel_read timeout");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1078|      0|        scp->state = SSH_SCP_ERROR;
 1079|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1080|      0|    }
 1081|      0|    scp->processed += rc;
 1082|       |
 1083|       |    /* Check if we arrived at end of file */
 1084|      0|    if (scp->processed == scp->filelen) {
  ------------------
  |  Branch (1084:9): [True: 0, False: 0]
  ------------------
 1085|      0|        scp->processed = scp->filelen = 0;
 1086|      0|        ssh_channel_write(scp->channel, "", 1);
 1087|      0|        code = ssh_scp_response(scp, NULL);
 1088|      0|        if (code == 0) {
  ------------------
  |  Branch (1088:13): [True: 0, False: 0]
  ------------------
 1089|      0|            scp->state = SSH_SCP_READ_INITED;
 1090|      0|            return rc;
 1091|      0|        }
 1092|      0|        if (code == 1) {
  ------------------
  |  Branch (1092:13): [True: 0, False: 0]
  ------------------
 1093|      0|            scp->state = SSH_SCP_READ_INITED;
 1094|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1095|      0|        }
 1096|      0|        scp->state = SSH_SCP_ERROR;
 1097|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1098|      0|    }
 1099|       |
 1100|      0|    return rc;
 1101|      0|}
ssh_scp_request_get_filename:
 1113|      1|{
 1114|      1|    if (scp == NULL) {
  ------------------
  |  Branch (1114:9): [True: 0, False: 1]
  ------------------
 1115|      0|        return NULL;
 1116|      0|    }
 1117|       |
 1118|      1|    return scp->request_name;
 1119|      1|}
ssh_scp_request_get_permissions:
 1130|      1|{
 1131|      1|    if (scp == NULL) {
  ------------------
  |  Branch (1131:9): [True: 0, False: 1]
  ------------------
 1132|      0|        return -1;
 1133|      0|    }
 1134|       |
 1135|      1|    return scp->request_mode;
 1136|      1|}
ssh_scp_request_get_size:
 1149|      1|{
 1150|      1|    if (scp == NULL) {
  ------------------
  |  Branch (1150:9): [True: 0, False: 1]
  ------------------
 1151|      0|        return 0;
 1152|      0|    }
 1153|      1|    return (size_t)scp->filelen;
 1154|      1|}
ssh_scp_request_get_size64:
 1164|      1|{
 1165|      1|    if (scp == NULL) {
  ------------------
  |  Branch (1165:9): [True: 0, False: 1]
  ------------------
 1166|      0|        return 0;
 1167|      0|    }
 1168|      1|    return scp->filelen;
 1169|      1|}
ssh_scp_request_get_warning:
 1214|      1|{
 1215|      1|    if (scp == NULL) {
  ------------------
  |  Branch (1215:9): [True: 0, False: 1]
  ------------------
 1216|      0|        return NULL;
 1217|      0|    }
 1218|       |
 1219|      1|    return scp->warning;
 1220|      1|}

server_set_kex:
   93|  1.31k|{
   94|  1.31k|    struct ssh_kex_struct *server = &session->next_crypto->server_kex;
   95|  1.31k|    int i, j, rc;
   96|  1.31k|    const char *wanted = NULL, *allowed = NULL;
   97|  1.31k|    char *kept = NULL;
   98|  1.31k|    char hostkeys[128] = {0};
   99|  1.31k|    enum ssh_keytypes_e keytype;
  100|  1.31k|    size_t len;
  101|  1.31k|    int ok;
  102|       |#ifdef WITH_GSSAPI
  103|       |    char *gssapi_algs = NULL;
  104|       |#endif /* WITH_GSSAPI */
  105|       |
  106|       |    /* Skip if already set, for example for the rekey or when we do the guessing
  107|       |     * it could have been already used to make some protocol decisions. */
  108|  1.31k|    if (server->methods[0] != NULL) {
  ------------------
  |  Branch (108:9): [True: 657, False: 657]
  ------------------
  109|    657|        return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  110|    657|    }
  111|       |
  112|    657|    ok = ssh_get_random(server->cookie, 16, 0);
  113|    657|    if (!ok) {
  ------------------
  |  Branch (113:9): [True: 0, False: 657]
  ------------------
  114|      0|        ssh_set_error(session, SSH_FATAL, "PRNG error");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  115|      0|        return -1;
  116|      0|    }
  117|       |
  118|    657|    if (session->srv.ed25519_key != NULL) {
  ------------------
  |  Branch (118:9): [True: 657, False: 0]
  ------------------
  119|    657|        snprintf(hostkeys,
  120|    657|                 sizeof(hostkeys),
  121|    657|                 "%s",
  122|    657|                 ssh_key_type_to_char(ssh_key_type(session->srv.ed25519_key)));
  123|    657|    }
  124|    657|#ifdef HAVE_ECC
  125|    657|    if (session->srv.ecdsa_key != NULL) {
  ------------------
  |  Branch (125:9): [True: 0, False: 657]
  ------------------
  126|      0|        len = strlen(hostkeys);
  127|      0|        snprintf(hostkeys + len, sizeof(hostkeys) - len,
  128|      0|                 ",%s", session->srv.ecdsa_key->type_c);
  129|      0|    }
  130|    657|#endif
  131|    657|    if (session->srv.rsa_key != NULL) {
  ------------------
  |  Branch (131:9): [True: 0, False: 657]
  ------------------
  132|       |        /* We support also the SHA2 variants */
  133|      0|        len = strlen(hostkeys);
  134|      0|        snprintf(hostkeys + len, sizeof(hostkeys) - len,
  135|      0|                 ",rsa-sha2-512,rsa-sha2-256");
  136|       |
  137|      0|        len = strlen(hostkeys);
  138|      0|        keytype = ssh_key_type(session->srv.rsa_key);
  139|       |
  140|      0|        snprintf(hostkeys + len, sizeof(hostkeys) - len,
  141|      0|                 ",%s", ssh_key_type_to_char(keytype));
  142|      0|    }
  143|       |
  144|    657|    if (session->opts.wanted_methods[SSH_HOSTKEYS]) {
  ------------------
  |  Branch (144:9): [True: 0, False: 657]
  ------------------
  145|      0|        allowed = session->opts.wanted_methods[SSH_HOSTKEYS];
  146|    657|    } else {
  147|    657|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|    657|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 657]
  |  |  ------------------
  ------------------
  148|      0|            allowed = ssh_kex_get_fips_methods(SSH_HOSTKEYS);
  149|    657|        } else {
  150|    657|            allowed = ssh_kex_get_default_methods(SSH_HOSTKEYS);
  151|    657|        }
  152|    657|    }
  153|       |
  154|    657|    if (strlen(hostkeys) != 0) {
  ------------------
  |  Branch (154:9): [True: 657, False: 0]
  ------------------
  155|       |        /* It is expected for the list of allowed hostkeys to be ordered by
  156|       |         * preference */
  157|    657|        kept =
  158|    657|            ssh_find_all_matching(hostkeys[0] == ',' ? hostkeys + 1 : hostkeys,
  ------------------
  |  Branch (158:35): [True: 0, False: 657]
  ------------------
  159|    657|                                  allowed);
  160|    657|        if (kept == NULL) {
  ------------------
  |  Branch (160:13): [True: 0, False: 657]
  ------------------
  161|       |            /* Nothing was allowed */
  162|      0|            return -1;
  163|      0|        }
  164|       |
  165|    657|        rc = ssh_options_set_algo(session,
  166|    657|                                  SSH_HOSTKEYS,
  167|    657|                                  kept,
  168|    657|                                  &session->opts.wanted_methods[SSH_HOSTKEYS]);
  169|    657|        SAFE_FREE(kept);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  170|    657|        if (rc < 0) {
  ------------------
  |  Branch (170:13): [True: 0, False: 657]
  ------------------
  171|      0|            return -1;
  172|      0|        }
  173|    657|    }
  174|       |#ifdef WITH_GSSAPI
  175|       |    if (session->opts.gssapi_key_exchange) {
  176|       |        ok = ssh_gssapi_init(session);
  177|       |        if (ok != SSH_OK) {
  178|       |            ssh_set_error_oom(session);
  179|       |            return SSH_ERROR;
  180|       |        }
  181|       |
  182|       |        gssapi_algs = ssh_gssapi_kex_mechs(session);
  183|       |        if (gssapi_algs == NULL) {
  184|       |            return SSH_ERROR;
  185|       |        }
  186|       |        ssh_gssapi_free(session);
  187|       |
  188|       |        /* Prefix the default algorithms with gsskex algs */
  189|       |        session->opts.wanted_methods[SSH_KEX] =
  190|       |            ssh_prefix_without_duplicates(ssh_kex_get_default_methods(SSH_KEX),
  191|       |                                          gssapi_algs);
  192|       |
  193|       |        if (strlen(hostkeys) == 0) {
  194|       |            session->opts.wanted_methods[SSH_HOSTKEYS] = strdup("null");
  195|       |        }
  196|       |
  197|       |        SAFE_FREE(gssapi_algs);
  198|       |    }
  199|       |#endif /* WITH_GSSAPI */
  200|       |
  201|  7.22k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  7.22k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (201:17): [True: 6.57k, False: 657]
  ------------------
  202|  6.57k|        wanted = session->opts.wanted_methods[i];
  203|  6.57k|        if (wanted == NULL) {
  ------------------
  |  Branch (203:13): [True: 3.28k, False: 3.28k]
  ------------------
  204|  3.28k|            if (ssh_fips_mode()) {
  ------------------
  |  |  115|  3.28k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 3.28k]
  |  |  ------------------
  ------------------
  205|      0|                wanted = ssh_kex_get_fips_methods(i);
  206|  3.28k|            } else {
  207|  3.28k|                wanted = ssh_kex_get_default_methods(i);
  208|  3.28k|            }
  209|  3.28k|        }
  210|  6.57k|        if (wanted == NULL) {
  ------------------
  |  Branch (210:13): [True: 0, False: 6.57k]
  ------------------
  211|      0|            for (j = 0; j < i; j++) {
  ------------------
  |  Branch (211:25): [True: 0, False: 0]
  ------------------
  212|      0|                SAFE_FREE(server->methods[j]);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  213|      0|            }
  214|      0|            return -1;
  215|      0|        }
  216|       |
  217|  6.57k|        server->methods[i] = strdup(wanted);
  218|  6.57k|        if (server->methods[i] == NULL) {
  ------------------
  |  Branch (218:13): [True: 0, False: 6.57k]
  ------------------
  219|      0|            for (j = 0; j < i; j++) {
  ------------------
  |  Branch (219:25): [True: 0, False: 0]
  ------------------
  220|      0|                SAFE_FREE(server->methods[j]);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  221|      0|            }
  222|      0|            return -1;
  223|      0|        }
  224|  6.57k|    }
  225|       |
  226|       |    /* Do not append the extensions during rekey */
  227|    657|    if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) {
  ------------------
  |  |   78|    657|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (227:9): [True: 0, False: 657]
  ------------------
  228|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  229|      0|    }
  230|       |
  231|    657|    rc = ssh_kex_append_extensions(session, server);
  232|    657|    return rc;
  233|    657|}
ssh_packet_kexdh_init:
  310|    657|SSH_PACKET_CALLBACK(ssh_packet_kexdh_init){
  311|    657|  (void)packet;
  312|    657|  (void)type;
  313|    657|  (void)user;
  314|       |
  315|    657|  SSH_LOG(SSH_LOG_PACKET,"Received SSH_MSG_KEXDH_INIT");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  316|    657|  if(session->dh_handshake_state != DH_STATE_INIT){
  ------------------
  |  Branch (316:6): [True: 0, False: 657]
  ------------------
  317|      0|    SSH_LOG(SSH_LOG_RARE,"Invalid state for SSH_MSG_KEXDH_INIT");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  318|      0|    session->session_state = SSH_SESSION_STATE_ERROR;
  319|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  320|      0|  }
  321|       |
  322|       |  /* If first_kex_packet_follows guess was wrong, ignore this message. */
  323|    657|  if (session->first_kex_follows_guess_wrong != 0) {
  ------------------
  |  Branch (323:7): [True: 0, False: 657]
  ------------------
  324|      0|    SSH_LOG(SSH_LOG_RARE, "first_kex_packet_follows guess was wrong, "
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  325|      0|                          "ignoring first SSH_MSG_KEXDH_INIT message");
  326|      0|    session->first_kex_follows_guess_wrong = 0;
  327|       |
  328|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  329|      0|  }
  330|    657|  SSH_LOG(SSH_LOG_DEBUG, "Calling next KEXDH handler");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  331|    657|  return SSH_PACKET_NOT_USED;
  ------------------
  |  |  640|    657|#define SSH_PACKET_NOT_USED 2
  ------------------
  332|    657|}
ssh_get_key_params:
  354|    657|{
  355|    657|    ssh_key pubkey = NULL;
  356|    657|    ssh_string pubkey_blob = NULL;
  357|    657|    int rc;
  358|       |
  359|    657|    switch(session->srv.hostkey) {
  360|      0|      case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (360:7): [True: 0, False: 657]
  ------------------
  361|      0|        *privkey = session->srv.rsa_key;
  362|      0|        break;
  363|      0|      case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (363:7): [True: 0, False: 657]
  ------------------
  364|      0|      case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (364:7): [True: 0, False: 657]
  ------------------
  365|      0|      case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (365:7): [True: 0, False: 657]
  ------------------
  366|      0|        *privkey = session->srv.ecdsa_key;
  367|      0|        break;
  368|    657|      case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (368:7): [True: 657, False: 0]
  ------------------
  369|    657|        *privkey = session->srv.ed25519_key;
  370|    657|        break;
  371|      0|      case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (371:7): [True: 0, False: 657]
  ------------------
  372|      0|      case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (372:7): [True: 0, False: 657]
  ------------------
  373|      0|      default:
  ------------------
  |  Branch (373:7): [True: 0, False: 657]
  ------------------
  374|      0|        *privkey = NULL;
  375|    657|    }
  376|       |
  377|    657|    *digest = session->srv.hostkey_digest;
  378|    657|    rc = ssh_pki_export_privkey_to_pubkey(*privkey, &pubkey);
  379|    657|    if (rc < 0) {
  ------------------
  |  Branch (379:9): [True: 0, False: 657]
  ------------------
  380|      0|      ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  381|      0|          "Could not get the public key from the private key");
  382|       |
  383|      0|      return -1;
  384|      0|    }
  385|       |
  386|    657|    rc = ssh_pki_export_pubkey_blob(pubkey, &pubkey_blob);
  387|    657|    ssh_key_free(pubkey);
  388|    657|    if (rc < 0) {
  ------------------
  |  Branch (388:9): [True: 0, False: 657]
  ------------------
  389|      0|      ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  390|      0|      return -1;
  391|      0|    }
  392|       |
  393|    657|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  394|    657|    SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  910|    657|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (910:14): [True: 657, False: 0]
  |  |  |  Branch (910:69): [Folded, False: 657]
  |  |  ------------------
  ------------------
  395|    657|    if (rc != 0) {
  ------------------
  |  Branch (395:9): [True: 0, False: 657]
  ------------------
  396|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  397|      0|                      SSH_FATAL,
  398|      0|                      "Could not import server public key");
  399|      0|        return -1;
  400|      0|    }
  401|       |
  402|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  403|    657|}
ssh_set_auth_methods:
  613|    657|{
  614|       |    /* accept only methods in range */
  615|    657|    session->auth.supported_methods = (uint32_t)auth_methods & 0x3fU;
  616|    657|}
ssh_handle_key_exchange:
  645|    657|{
  646|    657|    int rc;
  647|       |
  648|    657|    if (session->session_state != SSH_SESSION_STATE_NONE) {
  ------------------
  |  Branch (648:9): [True: 0, False: 657]
  ------------------
  649|      0|        goto pending;
  650|      0|    }
  651|       |
  652|    657|    rc = ssh_send_banner(session, 1);
  653|    657|    if (rc < 0) {
  ------------------
  |  Branch (653:9): [True: 0, False: 657]
  ------------------
  654|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  655|      0|    }
  656|       |
  657|    657|    session->alive = 1;
  658|       |
  659|    657|    session->ssh_connection_callback = ssh_server_connection_callback;
  660|    657|    session->session_state = SSH_SESSION_STATE_SOCKET_CONNECTED;
  661|    657|    ssh_socket_set_callbacks(session->socket,&session->socket_callbacks);
  662|    657|    session->socket_callbacks.data = callback_receive_banner;
  663|    657|    session->socket_callbacks.exception = ssh_socket_exception_callback;
  664|    657|    session->socket_callbacks.userdata = session;
  665|       |
  666|    657|    rc = server_set_kex(session);
  667|    657|    if (rc < 0) {
  ------------------
  |  Branch (667:9): [True: 0, False: 657]
  ------------------
  668|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  669|      0|    }
  670|    657|pending:
  671|    657|    rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_USER,
  ------------------
  |  |  101|    657|#define SSH_TIMEOUT_USER -2
  ------------------
  672|    657|                                        ssh_server_kex_termination,session);
  673|    657|    SSH_LOG(SSH_LOG_PACKET, "ssh_handle_key_exchange: current state : %d",
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  674|    657|            session->session_state);
  675|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (675:9): [True: 0, False: 657]
  ------------------
  676|      0|        return rc;
  677|      0|    }
  678|    657|    if (session->session_state == SSH_SESSION_STATE_ERROR ||
  ------------------
  |  Branch (678:9): [True: 0, False: 657]
  ------------------
  679|    657|        session->session_state == SSH_SESSION_STATE_DISCONNECTED) {
  ------------------
  |  Branch (679:9): [True: 0, False: 657]
  ------------------
  680|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  681|      0|    }
  682|       |
  683|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  684|    657|}
ssh_message_service_reply_success:
  834|    657|{
  835|    657|    ssh_session session = NULL;
  836|    657|    int rc;
  837|       |
  838|    657|    if (msg == NULL) {
  ------------------
  |  Branch (838:9): [True: 0, False: 657]
  ------------------
  839|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  840|      0|    }
  841|    657|    session = msg->session;
  842|       |
  843|    657|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  844|    657|            "Sending a SERVICE_ACCEPT for service %s", msg->service_request.service);
  845|       |
  846|    657|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    657|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  847|    657|                         "bs",
  848|    657|                         SSH2_MSG_SERVICE_ACCEPT,
  849|    657|                         msg->service_request.service);
  850|    657|    if (rc != SSH_OK){
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (850:9): [True: 0, False: 657]
  ------------------
  851|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  852|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  853|      0|    }
  854|    657|    rc = ssh_packet_send(msg->session);
  855|    657|    return rc;
  856|    657|}
ssh_message_reply_default:
  933|    657|int ssh_message_reply_default(ssh_message msg) {
  934|    657|  if (msg == NULL) {
  ------------------
  |  Branch (934:7): [True: 0, False: 657]
  ------------------
  935|      0|    return -1;
  936|      0|  }
  937|       |
  938|    657|  switch(msg->type) {
  939|      0|    case SSH_REQUEST_AUTH:
  ------------------
  |  Branch (939:5): [True: 0, False: 657]
  ------------------
  940|      0|      return ssh_auth_reply_default(msg->session, 0);
  941|      0|    case SSH_REQUEST_CHANNEL_OPEN:
  ------------------
  |  Branch (941:5): [True: 0, False: 657]
  ------------------
  942|      0|      return ssh_message_channel_request_open_reply_default(msg);
  943|      0|    case SSH_REQUEST_CHANNEL:
  ------------------
  |  Branch (943:5): [True: 0, False: 657]
  ------------------
  944|      0|      return ssh_message_channel_request_reply_default(msg);
  945|    657|    case SSH_REQUEST_SERVICE:
  ------------------
  |  Branch (945:5): [True: 657, False: 0]
  ------------------
  946|    657|      return ssh_message_service_request_reply_default(msg);
  947|      0|    case SSH_REQUEST_GLOBAL:
  ------------------
  |  Branch (947:5): [True: 0, False: 657]
  ------------------
  948|      0|      return ssh_message_global_request_reply_default(msg);
  949|      0|    default:
  ------------------
  |  Branch (949:5): [True: 0, False: 657]
  ------------------
  950|      0|      SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  951|      0|          "Don't know what to default reply to %d type",
  952|      0|          msg->type);
  953|      0|      break;
  954|    657|  }
  955|       |
  956|      0|  return -1;
  957|    657|}
ssh_auth_reply_success:
 1192|    657|{
 1193|    657|    struct ssh_crypto_struct *crypto = NULL;
 1194|    657|    int r;
 1195|       |
 1196|    657|    if (session == NULL) {
  ------------------
  |  Branch (1196:9): [True: 0, False: 657]
  ------------------
 1197|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1198|      0|    }
 1199|       |
 1200|    657|    if (partial) {
  ------------------
  |  Branch (1200:9): [True: 0, False: 657]
  ------------------
 1201|      0|        return ssh_auth_reply_default(session, partial);
 1202|      0|    }
 1203|       |
 1204|    657|    r = ssh_buffer_add_u8(session->out_buffer,SSH2_MSG_USERAUTH_SUCCESS);
  ------------------
  |  |   38|    657|#define SSH2_MSG_USERAUTH_SUCCESS 52
  ------------------
 1205|    657|    if (r < 0) {
  ------------------
  |  Branch (1205:9): [True: 0, False: 657]
  ------------------
 1206|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1207|      0|    }
 1208|       |
 1209|    657|    r = ssh_packet_send(session);
 1210|       |
 1211|       |    /*
 1212|       |     * Consider the session as having been authenticated only after sending
 1213|       |     * the `USERAUTH_SUCCESS` message.  Setting these flags after
 1214|       |     * ssh_packet_send ensures that a rekey is not triggered prematurely,
 1215|       |     * causing the message to be queued.
 1216|       |     */
 1217|    657|    session->session_state = SSH_SESSION_STATE_AUTHENTICATED;
 1218|    657|    session->flags |= SSH_SESSION_FLAG_AUTHENTICATED;
  ------------------
  |  |   78|    657|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
 1219|       |
 1220|    657|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
 1221|    657|    if (crypto != NULL && crypto->delayed_compress_out) {
  ------------------
  |  Branch (1221:9): [True: 657, False: 0]
  |  Branch (1221:27): [True: 0, False: 657]
  ------------------
 1222|      0|        SSH_LOG(SSH_LOG_DEBUG, "Enabling delayed compression OUT");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1223|      0|        crypto->do_compress_out = 1;
 1224|      0|    }
 1225|       |
 1226|    657|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
 1227|    657|    if (crypto != NULL && crypto->delayed_compress_in) {
  ------------------
  |  Branch (1227:9): [True: 657, False: 0]
  |  Branch (1227:27): [True: 0, False: 657]
  ------------------
 1228|      0|        SSH_LOG(SSH_LOG_DEBUG, "Enabling delayed compression IN");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1229|      0|        crypto->do_compress_in = 1;
 1230|      0|    }
 1231|    657|    return r;
 1232|    657|}
ssh_message_auth_reply_success:
 1246|    657|int ssh_message_auth_reply_success(ssh_message msg, int partial) {
 1247|    657|	if(msg == NULL)
  ------------------
  |  Branch (1247:5): [True: 0, False: 657]
  ------------------
 1248|      0|		return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1249|    657|	return ssh_auth_reply_success(msg->session, partial);
 1250|    657|}
server.c:ssh_server_connection_callback:
  412|  1.97k|{
  413|  1.97k|    int rc;
  414|       |
  415|  1.97k|    switch (session->session_state) {
  416|      0|    case SSH_SESSION_STATE_NONE:
  ------------------
  |  Branch (416:5): [True: 0, False: 1.97k]
  ------------------
  417|      0|    case SSH_SESSION_STATE_CONNECTING:
  ------------------
  |  Branch (417:5): [True: 0, False: 1.97k]
  ------------------
  418|      0|    case SSH_SESSION_STATE_SOCKET_CONNECTED:
  ------------------
  |  Branch (418:5): [True: 0, False: 1.97k]
  ------------------
  419|      0|        break;
  420|    657|    case SSH_SESSION_STATE_BANNER_RECEIVED:
  ------------------
  |  Branch (420:5): [True: 657, False: 1.31k]
  ------------------
  421|    657|        if (session->clientbanner == NULL) {
  ------------------
  |  Branch (421:13): [True: 0, False: 657]
  ------------------
  422|      0|            goto error;
  423|      0|        }
  424|    657|        set_status(session, 0.4f);
  ------------------
  |  |   65|    657|#define set_status(session, status) do {\
  |  |   66|    657|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 657]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    657|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    657|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 657]
  |  |  ------------------
  ------------------
  425|    657|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  426|    657|                "SSH client banner: %s", session->clientbanner);
  427|       |
  428|       |        /* Here we analyze the different protocols the server allows. */
  429|    657|        rc = ssh_analyze_banner(session, 1);
  430|    657|        if (rc < 0) {
  ------------------
  |  Branch (430:13): [True: 0, False: 657]
  ------------------
  431|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  432|      0|                    "No version of SSH protocol usable (banner: %s)",
  433|      0|                    session->clientbanner);
  434|      0|            goto error;
  435|      0|        }
  436|       |
  437|       |        /* from now, the packet layer is handling incoming packets */
  438|    657|        ssh_packet_register_socket_callback(session, session->socket);
  439|       |
  440|    657|        ssh_packet_set_default_callbacks(session);
  441|    657|        set_status(session, 0.5f);
  ------------------
  |  |   65|    657|#define set_status(session, status) do {\
  |  |   66|    657|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 657]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    657|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    657|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 657]
  |  |  ------------------
  ------------------
  442|    657|        session->session_state = SSH_SESSION_STATE_INITIAL_KEX;
  443|    657|        rc = ssh_send_kex(session);
  444|    657|        if (rc < 0) {
  ------------------
  |  Branch (444:13): [True: 0, False: 657]
  ------------------
  445|      0|            goto error;
  446|      0|        }
  447|    657|        break;
  448|    657|    case SSH_SESSION_STATE_INITIAL_KEX:
  ------------------
  |  Branch (448:5): [True: 0, False: 1.97k]
  ------------------
  449|       |        /* TODO: This state should disappear in favor of get_key handle */
  450|      0|        break;
  451|    657|    case SSH_SESSION_STATE_KEXINIT_RECEIVED:
  ------------------
  |  Branch (451:5): [True: 657, False: 1.31k]
  ------------------
  452|    657|        set_status(session, 0.6f);
  ------------------
  |  |   65|    657|#define set_status(session, status) do {\
  |  |   66|    657|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 657]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    657|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    657|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 657]
  |  |  ------------------
  ------------------
  453|    657|        if ((session->flags & SSH_SESSION_FLAG_KEXINIT_SENT) == 0) {
  ------------------
  |  |   86|    657|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
  |  Branch (453:13): [True: 0, False: 657]
  ------------------
  454|      0|            rc = server_set_kex(session);
  455|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (455:17): [True: 0, False: 0]
  ------------------
  456|      0|                goto error;
  457|      0|            }
  458|       |            /* We are in a rekeying, so we need to send the server kex */
  459|      0|            rc = ssh_send_kex(session);
  460|      0|            if (rc < 0) {
  ------------------
  |  Branch (460:17): [True: 0, False: 0]
  ------------------
  461|      0|                goto error;
  462|      0|            }
  463|      0|        }
  464|    657|        ssh_list_kex(&session->next_crypto->client_kex); // log client kex
  465|    657|        rc = ssh_kex_select_methods(session);
  466|    657|        if (rc < 0) {
  ------------------
  |  Branch (466:13): [True: 0, False: 657]
  ------------------
  467|      0|            goto error;
  468|      0|        }
  469|    657|        rc = crypt_set_algorithms_server(session);
  470|    657|        if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (470:13): [True: 0, False: 657]
  ------------------
  471|      0|            goto error;
  472|      0|        }
  473|    657|        set_status(session, 0.8f);
  ------------------
  |  |   65|    657|#define set_status(session, status) do {\
  |  |   66|    657|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 657]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    657|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    657|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 657]
  |  |  ------------------
  ------------------
  474|    657|        session->session_state = SSH_SESSION_STATE_DH;
  475|    657|        break;
  476|    657|    case SSH_SESSION_STATE_DH:
  ------------------
  |  Branch (476:5): [True: 657, False: 1.31k]
  ------------------
  477|    657|        if (session->dh_handshake_state == DH_STATE_FINISHED) {
  ------------------
  |  Branch (477:13): [True: 657, False: 0]
  ------------------
  478|       |
  479|    657|            rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_IN);
  480|    657|            if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (480:17): [True: 0, False: 657]
  ------------------
  481|      0|                goto error;
  482|      0|            }
  483|       |
  484|       |            /*
  485|       |             * If the client supports extension negotiation, we will send
  486|       |             * our supported extensions now. This is the first message after
  487|       |             * sending NEWKEYS message and after turning on crypto.
  488|       |             */
  489|    657|            if (session->extensions & SSH_EXT_NEGOTIATION &&
  ------------------
  |  |  123|  1.31k|#define SSH_EXT_NEGOTIATION     0x01
  ------------------
  |  Branch (489:17): [True: 657, False: 0]
  ------------------
  490|    657|                session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (490:17): [True: 657, False: 0]
  ------------------
  491|       |                /*
  492|       |                 * Only send an SSH_MSG_EXT_INFO message the first time the
  493|       |                 * client undergoes NEWKEYS.  It is unexpected for this message
  494|       |                 * to be sent upon rekey, and may cause clients to log error
  495|       |                 * messages.
  496|       |                 *
  497|       |                 * The session_state can not be used for this purpose because it
  498|       |                 * is re-set to SSH_SESSION_STATE_KEXINIT_RECEIVED during rekey.
  499|       |                 * So, use the connected flag which transitions from non-zero
  500|       |                 * below.
  501|       |                 *
  502|       |                 * See also:
  503|       |                 * - https://bugzilla.mindrot.org/show_bug.cgi?id=2929
  504|       |                 */
  505|    657|                if (session->connected == 0) {
  ------------------
  |  Branch (505:21): [True: 657, False: 0]
  ------------------
  506|    657|                    ssh_server_send_extensions(session);
  507|    657|                }
  508|    657|            }
  509|       |
  510|    657|            set_status(session, 1.0f);
  ------------------
  |  |   65|    657|#define set_status(session, status) do {\
  |  |   66|    657|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 657]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    657|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    657|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 657]
  |  |  ------------------
  ------------------
  511|    657|            session->connected = 1;
  512|    657|            session->session_state = SSH_SESSION_STATE_AUTHENTICATING;
  513|    657|            if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED)
  ------------------
  |  |   78|    657|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (513:17): [True: 0, False: 657]
  ------------------
  514|      0|                session->session_state = SSH_SESSION_STATE_AUTHENTICATED;
  515|       |
  516|    657|        }
  517|    657|        break;
  518|    657|    case SSH_SESSION_STATE_AUTHENTICATING:
  ------------------
  |  Branch (518:5): [True: 0, False: 1.97k]
  ------------------
  519|      0|        break;
  520|      0|    case SSH_SESSION_STATE_ERROR:
  ------------------
  |  Branch (520:5): [True: 0, False: 1.97k]
  ------------------
  521|      0|        goto error;
  522|      0|    default:
  ------------------
  |  Branch (522:5): [True: 0, False: 1.97k]
  ------------------
  523|      0|        ssh_set_error(session, SSH_FATAL, "Invalid state %d",
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  524|  1.97k|                      session->session_state);
  525|  1.97k|    }
  526|       |
  527|  1.97k|    return;
  528|  1.97k|error:
  529|      0|    ssh_socket_close(session->socket);
  530|      0|    session->alive = 0;
  531|      0|    session->session_state = SSH_SESSION_STATE_ERROR;
  532|      0|}
server.c:ssh_server_send_extensions:
  268|    657|{
  269|    657|    int rc;
  270|    657|    const char *hostkey_algorithms = NULL;
  271|       |
  272|    657|    SSH_LOG(SSH_LOG_PACKET, "Sending SSH_MSG_EXT_INFO");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  273|       |
  274|    657|    if (session->opts.pubkey_accepted_types) {
  ------------------
  |  Branch (274:9): [True: 0, False: 657]
  ------------------
  275|      0|        hostkey_algorithms = session->opts.pubkey_accepted_types;
  276|    657|    } else {
  277|    657|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|    657|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 657]
  |  |  ------------------
  ------------------
  278|      0|            hostkey_algorithms = ssh_kex_get_fips_methods(SSH_HOSTKEYS);
  279|    657|        } else {
  280|       |            /* There are no restrictions to the accepted public keys */
  281|    657|            hostkey_algorithms = ssh_kex_get_default_methods(SSH_HOSTKEYS);
  282|    657|        }
  283|    657|    }
  284|       |
  285|    657|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    657|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    657|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    657|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    657|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    657|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    657|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  286|    657|                         "bdssssss",
  287|    657|                         SSH2_MSG_EXT_INFO,
  288|    657|                         3, /* nr. of extensions */
  289|    657|                         "server-sig-algs",
  290|    657|                         hostkey_algorithms,
  291|    657|                         "publickey-hostbound@openssh.com",
  292|    657|                         "0",
  293|    657|                         "ping@openssh.com",
  294|    657|                         "0");
  295|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (295:9): [True: 0, False: 657]
  ------------------
  296|      0|        goto error;
  297|      0|    }
  298|       |
  299|    657|    if (ssh_packet_send(session) == SSH_ERROR) {
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (299:9): [True: 0, False: 657]
  ------------------
  300|      0|        goto error;
  301|      0|    }
  302|       |
  303|    657|    return 0;
  304|      0|error:
  305|      0|    ssh_buffer_reinit(session->out_buffer);
  306|       |
  307|      0|    return -1;
  308|    657|}
server.c:callback_receive_banner:
  546|    657|{
  547|    657|    char *buffer = (char *)data;
  548|    657|    ssh_session session = (ssh_session)user;
  549|    657|    char *str = NULL;
  550|    657|    size_t i;
  551|    657|    size_t processed = 0;
  552|       |
  553|  15.1k|    for (i = 0; i < len; i++) {
  ------------------
  |  Branch (553:17): [True: 15.1k, False: 0]
  ------------------
  554|  15.1k|#ifdef WITH_PCAP
  555|  15.1k|        if (session->pcap_ctx && buffer[i] == '\n') {
  ------------------
  |  Branch (555:13): [True: 0, False: 15.1k]
  |  Branch (555:34): [True: 0, False: 0]
  ------------------
  556|      0|            ssh_pcap_context_write(session->pcap_ctx,
  557|      0|                                   SSH_PCAP_DIR_IN,
  558|      0|                                   buffer,
  559|      0|                                   (uint32_t)(i + 1),
  560|      0|                                   (uint32_t)(i + 1));
  561|      0|        }
  562|  15.1k|#endif
  563|  15.1k|        if (buffer[i] == '\r') {
  ------------------
  |  Branch (563:13): [True: 657, False: 14.4k]
  ------------------
  564|    657|            buffer[i] = '\0';
  565|    657|        }
  566|       |
  567|  15.1k|        if (buffer[i] == '\n') {
  ------------------
  |  Branch (567:13): [True: 657, False: 14.4k]
  ------------------
  568|    657|            buffer[i] = '\0';
  569|       |
  570|    657|            str = strdup(buffer);
  571|    657|            if (str == NULL) {
  ------------------
  |  Branch (571:17): [True: 0, False: 657]
  ------------------
  572|      0|                session->session_state = SSH_SESSION_STATE_ERROR;
  573|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  574|      0|                return 0;
  575|      0|            }
  576|       |            /* number of bytes read */
  577|    657|            processed = i + 1;
  578|    657|            session->clientbanner = str;
  579|    657|            session->session_state = SSH_SESSION_STATE_BANNER_RECEIVED;
  580|    657|            SSH_LOG(SSH_LOG_PACKET, "Received banner: %s", str);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  581|    657|            session->ssh_connection_callback(session);
  582|       |
  583|    657|            return processed;
  584|    657|        }
  585|       |
  586|  14.4k|        if (i > 127) {
  ------------------
  |  Branch (586:13): [True: 0, False: 14.4k]
  ------------------
  587|       |            /* Too big banner */
  588|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
  589|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  590|      0|                          "Receiving banner: too large banner");
  591|       |
  592|      0|            return 0;
  593|      0|        }
  594|  14.4k|    }
  595|       |
  596|      0|    return processed;
  597|    657|}
server.c:ssh_server_kex_termination:
  600|  6.50k|static int ssh_server_kex_termination(void *s){
  601|  6.50k|  ssh_session session = s;
  602|  6.50k|  if (session->session_state != SSH_SESSION_STATE_ERROR &&
  ------------------
  |  Branch (602:7): [True: 6.50k, False: 0]
  ------------------
  603|  6.50k|      session->session_state != SSH_SESSION_STATE_AUTHENTICATING &&
  ------------------
  |  Branch (603:7): [True: 5.85k, False: 657]
  ------------------
  604|  5.85k|      session->session_state != SSH_SESSION_STATE_AUTHENTICATED &&
  ------------------
  |  Branch (604:7): [True: 5.85k, False: 0]
  ------------------
  605|  5.85k|      session->session_state != SSH_SESSION_STATE_DISCONNECTED)
  ------------------
  |  Branch (605:7): [True: 5.85k, False: 0]
  ------------------
  606|  5.85k|    return 0;
  607|    657|  else
  608|    657|    return 1;
  609|  6.50k|}
server.c:ssh_message_service_request_reply_default:
  821|    657|static int ssh_message_service_request_reply_default(ssh_message msg) {
  822|       |  /* The only return code accepted by specifications are success or disconnect */
  823|    657|  return ssh_message_service_reply_success(msg);
  824|    657|}

ssh_new:
   65|  1.31k|{
   66|  1.31k|    ssh_session session = NULL;
   67|  1.31k|    char *id = NULL;
   68|  1.31k|    int rc;
   69|       |
   70|  1.31k|    session = calloc(1, sizeof (struct ssh_session_struct));
   71|  1.31k|    if (session == NULL) {
  ------------------
  |  Branch (71:9): [True: 0, False: 1.31k]
  ------------------
   72|      0|        return NULL;
   73|      0|    }
   74|       |
   75|  1.31k|    session->next_crypto = crypto_new();
   76|  1.31k|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (76:9): [True: 0, False: 1.31k]
  ------------------
   77|      0|        goto err;
   78|      0|    }
   79|       |
   80|  1.31k|    session->socket = ssh_socket_new(session);
   81|  1.31k|    if (session->socket == NULL) {
  ------------------
  |  Branch (81:9): [True: 0, False: 1.31k]
  ------------------
   82|      0|        goto err;
   83|      0|    }
   84|       |
   85|  1.31k|    session->out_buffer = ssh_buffer_new();
   86|  1.31k|    if (session->out_buffer == NULL) {
  ------------------
  |  Branch (86:9): [True: 0, False: 1.31k]
  ------------------
   87|      0|        goto err;
   88|      0|    }
   89|       |
   90|  1.31k|    session->in_buffer = ssh_buffer_new();
   91|  1.31k|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (91:9): [True: 0, False: 1.31k]
  ------------------
   92|      0|        goto err;
   93|      0|    }
   94|       |
   95|  1.31k|    session->out_queue = ssh_list_new();
   96|  1.31k|    if (session->out_queue == NULL) {
  ------------------
  |  Branch (96:9): [True: 0, False: 1.31k]
  ------------------
   97|      0|        goto err;
   98|      0|    }
   99|       |
  100|  1.31k|    session->alive = 0;
  101|  1.31k|    session->auth.supported_methods = 0;
  102|  1.31k|    ssh_set_blocking(session, 1);
  103|  1.31k|    session->maxchannel = FIRST_CHANNEL;
  ------------------
  |  |   48|  1.31k|#define FIRST_CHANNEL 42 // why not ? it helps to find bugs.
  ------------------
  104|  1.31k|    session->proxy_root = true;
  105|       |
  106|  1.31k|    session->agent = ssh_agent_new(session);
  107|  1.31k|    if (session->agent == NULL) {
  ------------------
  |  Branch (107:9): [True: 0, False: 1.31k]
  ------------------
  108|      0|        goto err;
  109|      0|    }
  110|       |
  111|       |    /* Initialise a default PKI context */
  112|  1.31k|    session->pki_context = ssh_pki_ctx_new();
  113|  1.31k|    if (session->pki_context == NULL) {
  ------------------
  |  Branch (113:9): [True: 0, False: 1.31k]
  ------------------
  114|      0|        goto err;
  115|      0|    }
  116|       |
  117|       |    /* OPTIONS */
  118|  1.31k|    session->opts.StrictHostKeyChecking = SSH_STRICT_HOSTKEY_ASK;
  119|  1.31k|    session->opts.port = 22;
  120|  1.31k|    session->opts.fd = -1;
  121|  1.31k|    session->opts.compressionlevel = 7;
  122|  1.31k|    session->opts.nodelay = 0;
  123|  1.31k|    session->opts.identities_only = false;
  124|  1.31k|    session->opts.batch_mode = false;
  125|  1.31k|    session->opts.control_master = SSH_CONTROL_MASTER_NO;
  126|       |
  127|  1.31k|    session->opts.flags = SSH_OPT_FLAG_PASSWORD_AUTH |
  ------------------
  |  |  109|  1.31k|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
  128|  1.31k|                          SSH_OPT_FLAG_PUBKEY_AUTH |
  ------------------
  |  |  110|  1.31k|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
  129|  1.31k|                          SSH_OPT_FLAG_KBDINT_AUTH |
  ------------------
  |  |  111|  1.31k|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
  130|  1.31k|                          SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|  1.31k|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
  131|  1.31k|    session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
  132|       |
  133|  1.31k|    session->opts.exp_flags = 0;
  134|       |
  135|  1.31k|    session->opts.identity = ssh_list_new();
  136|  1.31k|    if (session->opts.identity == NULL) {
  ------------------
  |  Branch (136:9): [True: 0, False: 1.31k]
  ------------------
  137|      0|        goto err;
  138|      0|    }
  139|  1.31k|    session->opts.identity_non_exp = ssh_list_new();
  140|  1.31k|    if (session->opts.identity_non_exp == NULL) {
  ------------------
  |  Branch (140:9): [True: 0, False: 1.31k]
  ------------------
  141|      0|        goto err;
  142|      0|    }
  143|       |
  144|  1.31k|    session->opts.certificate = ssh_list_new();
  145|  1.31k|    if (session->opts.certificate == NULL) {
  ------------------
  |  Branch (145:9): [True: 0, False: 1.31k]
  ------------------
  146|      0|        goto err;
  147|      0|    }
  148|  1.31k|    session->opts.certificate_non_exp = ssh_list_new();
  149|  1.31k|    if (session->opts.certificate_non_exp == NULL) {
  ------------------
  |  Branch (149:9): [True: 0, False: 1.31k]
  ------------------
  150|      0|        goto err;
  151|      0|    }
  152|       |    /* the default certificates are loaded automatically from the default
  153|       |     * identities later */
  154|       |
  155|  1.31k|    session->opts.proxy_jumps = ssh_list_new();
  156|  1.31k|    if (session->opts.proxy_jumps == NULL) {
  ------------------
  |  Branch (156:9): [True: 0, False: 1.31k]
  ------------------
  157|      0|        goto err;
  158|      0|    }
  159|       |
  160|  1.31k|    session->opts.proxy_jumps_user_cb = ssh_list_new();
  161|  1.31k|    if (session->opts.proxy_jumps_user_cb == NULL) {
  ------------------
  |  Branch (161:9): [True: 0, False: 1.31k]
  ------------------
  162|      0|        goto err;
  163|      0|    }
  164|       |
  165|       |#ifdef WITH_GSSAPI
  166|       |    session->opts.gssapi_key_exchange_algs =
  167|       |        strdup(GSSAPI_KEY_EXCHANGE_SUPPORTED);
  168|       |    if (session->opts.gssapi_key_exchange_algs == NULL) {
  169|       |        goto err;
  170|       |    }
  171|       |#endif /* WITH_GSSAPI */
  172|       |
  173|  1.31k|    id = strdup("%d/.ssh/id_ed25519");
  174|  1.31k|    if (id == NULL) {
  ------------------
  |  Branch (174:9): [True: 0, False: 1.31k]
  ------------------
  175|      0|        goto err;
  176|      0|    }
  177|       |
  178|  1.31k|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  179|  1.31k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (179:9): [True: 0, False: 1.31k]
  ------------------
  180|      0|        goto err;
  181|      0|    }
  182|       |
  183|  1.31k|#ifdef HAVE_ECC
  184|  1.31k|    id = strdup("%d/.ssh/id_ecdsa");
  185|  1.31k|    if (id == NULL) {
  ------------------
  |  Branch (185:9): [True: 0, False: 1.31k]
  ------------------
  186|      0|        goto err;
  187|      0|    }
  188|  1.31k|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  189|  1.31k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (189:9): [True: 0, False: 1.31k]
  ------------------
  190|      0|        goto err;
  191|      0|    }
  192|  1.31k|#endif
  193|       |
  194|  1.31k|    id = strdup("%d/.ssh/id_rsa");
  195|  1.31k|    if (id == NULL) {
  ------------------
  |  Branch (195:9): [True: 0, False: 1.31k]
  ------------------
  196|      0|        goto err;
  197|      0|    }
  198|  1.31k|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  199|  1.31k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (199:9): [True: 0, False: 1.31k]
  ------------------
  200|      0|        goto err;
  201|      0|    }
  202|       |
  203|       |#ifdef WITH_FIDO2
  204|       |    /* Add security key identities */
  205|       |    id = strdup("%d/.ssh/id_ed25519_sk");
  206|       |    if (id == NULL) {
  207|       |        goto err;
  208|       |    }
  209|       |    rc = ssh_list_append(session->opts.identity_non_exp, id);
  210|       |    if (rc == SSH_ERROR) {
  211|       |        goto err;
  212|       |    }
  213|       |
  214|       |#ifdef HAVE_ECC
  215|       |    id = strdup("%d/.ssh/id_ecdsa_sk");
  216|       |    if (id == NULL) {
  217|       |        goto err;
  218|       |    }
  219|       |    rc = ssh_list_append(session->opts.identity_non_exp, id);
  220|       |    if (rc == SSH_ERROR) {
  221|       |        goto err;
  222|       |    }
  223|       |#endif /* HAVE_ECC */
  224|       |#endif /* WITH_FIDO2 */
  225|       |
  226|       |    /* Explicitly initialize states */
  227|  1.31k|    session->session_state = SSH_SESSION_STATE_NONE;
  228|  1.31k|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  229|  1.31k|    session->packet_state = PACKET_STATE_INIT;
  230|  1.31k|    session->dh_handshake_state = DH_STATE_INIT;
  231|  1.31k|    session->global_req_state = SSH_CHANNEL_REQ_STATE_NONE;
  232|       |
  233|  1.31k|    session->auth.state = SSH_AUTH_STATE_NONE;
  234|  1.31k|    session->auth.service_state = SSH_AUTH_SERVICE_NONE;
  235|       |
  236|  1.31k|    return session;
  237|       |
  238|      0|err:
  239|      0|    free(id);
  240|      0|    ssh_free(session);
  241|       |    return NULL;
  242|  1.31k|}
ssh_free:
  253|  1.31k|{
  254|  1.31k|  int i;
  255|  1.31k|  struct ssh_iterator *it = NULL;
  256|  1.31k|  struct ssh_buffer_struct *b = NULL;
  257|       |
  258|  1.31k|  if (session == NULL) {
  ------------------
  |  Branch (258:7): [True: 0, False: 1.31k]
  ------------------
  259|      0|    return;
  260|      0|  }
  261|       |
  262|       |  /*
  263|       |   * Delete all channels
  264|       |   *
  265|       |   * This needs the first thing we clean up cause if there is still an open
  266|       |   * channel we call ssh_channel_close() first. So we need a working socket
  267|       |   * and poll context for it.
  268|       |   */
  269|  1.31k|  for (it = ssh_list_get_iterator(session->channels);
  270|  1.31k|       it != NULL;
  ------------------
  |  Branch (270:8): [True: 0, False: 1.31k]
  ------------------
  271|  1.31k|       it = ssh_list_get_iterator(session->channels)) {
  272|      0|      ssh_channel_do_free(ssh_iterator_value(ssh_channel,it));
  ------------------
  |  |  114|      0|  ((type)((iterator)->data))
  ------------------
  273|      0|      ssh_list_remove(session->channels, it);
  274|      0|  }
  275|  1.31k|  ssh_list_free(session->channels);
  276|  1.31k|  session->channels = NULL;
  277|       |
  278|  1.31k|#ifdef WITH_PCAP
  279|  1.31k|  if (session->pcap_ctx) {
  ------------------
  |  Branch (279:7): [True: 0, False: 1.31k]
  ------------------
  280|      0|      ssh_pcap_context_free(session->pcap_ctx);
  281|      0|      session->pcap_ctx = NULL;
  282|      0|  }
  283|  1.31k|#endif
  284|       |
  285|  1.31k|  ssh_socket_free(session->socket);
  286|  1.31k|  session->socket = NULL;
  287|       |
  288|  1.31k|  if (session->default_poll_ctx) {
  ------------------
  |  Branch (288:7): [True: 1.31k, False: 0]
  ------------------
  289|  1.31k|      ssh_poll_ctx_free(session->default_poll_ctx);
  290|  1.31k|  }
  291|       |
  292|  1.31k|  SSH_BUFFER_FREE(session->in_buffer);
  ------------------
  |  |  951|  1.31k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 1.31k, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  293|  1.31k|  SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  951|  1.31k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 1.31k, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  294|  1.31k|  session->in_buffer = session->out_buffer = NULL;
  295|       |
  296|  1.31k|  if (session->in_hashbuf != NULL) {
  ------------------
  |  Branch (296:7): [True: 0, False: 1.31k]
  ------------------
  297|      0|      SSH_BUFFER_FREE(session->in_hashbuf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  298|      0|  }
  299|  1.31k|  if (session->out_hashbuf != NULL) {
  ------------------
  |  Branch (299:7): [True: 0, False: 1.31k]
  ------------------
  300|      0|      SSH_BUFFER_FREE(session->out_hashbuf);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  301|      0|  }
  302|       |
  303|  1.31k|  crypto_free(session->current_crypto);
  304|  1.31k|  crypto_free(session->next_crypto);
  305|       |
  306|  1.31k|  ssh_agent_free(session->agent);
  307|       |
  308|  1.31k|  SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1044|  1.31k|    do {                         \
  |  | 1045|  1.31k|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1045:13): [True: 1.31k, False: 0]
  |  |  ------------------
  |  | 1046|  1.31k|            ssh_pki_ctx_free(x); \
  |  | 1047|  1.31k|            x = NULL;            \
  |  | 1048|  1.31k|        }                        \
  |  | 1049|  1.31k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1049:14): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  309|       |
  310|  1.31k|  ssh_key_free(session->srv.rsa_key);
  311|  1.31k|  session->srv.rsa_key = NULL;
  312|  1.31k|  ssh_key_free(session->srv.ecdsa_key);
  313|  1.31k|  session->srv.ecdsa_key = NULL;
  314|  1.31k|  ssh_key_free(session->srv.ed25519_key);
  315|  1.31k|  session->srv.ed25519_key = NULL;
  316|       |
  317|  1.31k|  if (session->ssh_message_list) {
  ------------------
  |  Branch (317:7): [True: 0, False: 1.31k]
  ------------------
  318|      0|      ssh_message msg;
  319|       |
  320|      0|      for (msg = ssh_list_pop_head(ssh_message, session->ssh_message_list);
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  321|      0|           msg != NULL;
  ------------------
  |  Branch (321:12): [True: 0, False: 0]
  ------------------
  322|      0|           msg = ssh_list_pop_head(ssh_message, session->ssh_message_list)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  323|      0|          ssh_message_free(msg);
  324|      0|      }
  325|      0|      ssh_list_free(session->ssh_message_list);
  326|      0|  }
  327|       |
  328|  1.31k|  if (session->kbdint != NULL) {
  ------------------
  |  Branch (328:7): [True: 0, False: 1.31k]
  ------------------
  329|      0|    ssh_kbdint_free(session->kbdint);
  330|      0|  }
  331|       |
  332|  1.31k|  if (session->packet_callbacks) {
  ------------------
  |  Branch (332:7): [True: 0, False: 1.31k]
  ------------------
  333|      0|    ssh_list_free(session->packet_callbacks);
  334|      0|  }
  335|       |
  336|       |#ifdef WITH_GSSAPI
  337|       |    ssh_gssapi_free(session);
  338|       |    SAFE_FREE(session->opts.gssapi_key_exchange_algs);
  339|       |#endif
  340|       |
  341|       |  /* options */
  342|  1.31k|  if (session->opts.identity) {
  ------------------
  |  Branch (342:7): [True: 1.31k, False: 0]
  ------------------
  343|  1.31k|      char *id = NULL;
  344|       |
  345|  1.31k|      for (id = ssh_list_pop_head(char *, session->opts.identity);
  ------------------
  |  |  122|  1.31k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  346|  3.28k|           id != NULL;
  ------------------
  |  Branch (346:12): [True: 1.97k, False: 1.31k]
  ------------------
  347|  1.97k|           id = ssh_list_pop_head(char *, session->opts.identity)) {
  ------------------
  |  |  122|  1.97k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  348|  1.97k|          SAFE_FREE(id);
  ------------------
  |  |  373|  1.97k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.97k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.97k]
  |  |  ------------------
  ------------------
  349|  1.97k|      }
  350|  1.31k|      ssh_list_free(session->opts.identity);
  351|  1.31k|  }
  352|       |
  353|  1.31k|  if (session->opts.identity_non_exp) {
  ------------------
  |  Branch (353:7): [True: 1.31k, False: 0]
  ------------------
  354|  1.31k|      char *id = NULL;
  355|       |
  356|  1.31k|      for (id = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  122|  1.31k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  357|  3.28k|           id != NULL;
  ------------------
  |  Branch (357:12): [True: 1.97k, False: 1.31k]
  ------------------
  358|  1.97k|           id = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  122|  1.97k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  359|  1.97k|          SAFE_FREE(id);
  ------------------
  |  |  373|  1.97k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.97k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.97k]
  |  |  ------------------
  ------------------
  360|  1.97k|      }
  361|  1.31k|      ssh_list_free(session->opts.identity_non_exp);
  362|  1.31k|  }
  363|       |
  364|  1.31k|    if (session->opts.certificate) {
  ------------------
  |  Branch (364:9): [True: 1.31k, False: 0]
  ------------------
  365|  1.31k|        char *cert = NULL;
  366|       |
  367|  1.31k|        for (cert = ssh_list_pop_head(char *, session->opts.certificate);
  ------------------
  |  |  122|  1.31k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  368|  1.31k|             cert != NULL;
  ------------------
  |  Branch (368:14): [True: 0, False: 1.31k]
  ------------------
  369|  1.31k|             cert = ssh_list_pop_head(char *, session->opts.certificate)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  370|      0|            SAFE_FREE(cert);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  371|      0|        }
  372|  1.31k|        ssh_list_free(session->opts.certificate);
  373|  1.31k|    }
  374|       |
  375|  1.31k|    if (session->opts.certificate_non_exp) {
  ------------------
  |  Branch (375:9): [True: 1.31k, False: 0]
  ------------------
  376|  1.31k|        char *cert = NULL;
  377|       |
  378|  1.31k|        for (cert = ssh_list_pop_head(char *, session->opts.certificate_non_exp);
  ------------------
  |  |  122|  1.31k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  379|  1.31k|             cert != NULL;
  ------------------
  |  Branch (379:14): [True: 0, False: 1.31k]
  ------------------
  380|  1.31k|             cert = ssh_list_pop_head(char *, session->opts.certificate_non_exp)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  381|      0|            SAFE_FREE(cert);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  382|      0|        }
  383|  1.31k|        ssh_list_free(session->opts.certificate_non_exp);
  384|  1.31k|    }
  385|       |
  386|  1.31k|    ssh_proxyjumps_free(session->opts.proxy_jumps);
  387|  1.31k|    SSH_LIST_FREE(session->opts.proxy_jumps);
  ------------------
  |  |  125|  1.31k|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (125:14): [True: 1.31k, False: 0]
  |  |  |  Branch (125:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  388|  1.31k|    SSH_LIST_FREE(session->opts.proxy_jumps_user_cb);
  ------------------
  |  |  125|  1.31k|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (125:14): [True: 1.31k, False: 0]
  |  |  |  Branch (125:69): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  389|  1.31k|    SAFE_FREE(session->opts.proxy_jumps_str);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  390|       |
  391|  1.31k|    while ((b = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  122|  1.31k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  |  Branch (391:12): [True: 0, False: 1.31k]
  ------------------
  392|  1.31k|                                  session->out_queue)) != NULL) {
  393|      0|        SSH_BUFFER_FREE(b);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  394|      0|    }
  395|  1.31k|    ssh_list_free(session->out_queue);
  396|       |
  397|  1.31k|  ssh_agent_state_free(session->agent_state);
  398|  1.31k|  session->agent_state = NULL;
  399|       |
  400|  1.31k|  SAFE_FREE(session->auth.auto_state);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  401|  1.31k|  SAFE_FREE(session->serverbanner);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  402|  1.31k|  SAFE_FREE(session->clientbanner);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  403|  1.31k|  SAFE_FREE(session->banner);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  404|  1.31k|  SAFE_FREE(session->disconnect_message);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  405|  1.31k|  SAFE_FREE(session->peer_discon_msg);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  406|       |
  407|  1.31k|  SAFE_FREE(session->opts.agent_socket);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  408|  1.31k|  SAFE_FREE(session->opts.bindaddr);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  409|  1.31k|  SAFE_FREE(session->opts.username);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  410|  1.31k|  SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  411|  1.31k|  SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  412|  1.31k|  SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  413|  1.31k|  SAFE_FREE(session->opts.tag);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  414|  1.31k|  SAFE_FREE(session->opts.homedir);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  415|  1.31k|  SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  416|  1.31k|  SAFE_FREE(session->opts.knownhosts);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  417|  1.31k|  SAFE_FREE(session->opts.global_knownhosts);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 657]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  418|  1.31k|  SAFE_FREE(session->opts.ProxyCommand);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  419|  1.31k|  SAFE_FREE(session->opts.gss_server_identity);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  420|  1.31k|  SAFE_FREE(session->opts.gss_client_identity);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  421|  1.31k|  SAFE_FREE(session->opts.pubkey_accepted_types);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  422|  1.31k|  SAFE_FREE(session->opts.control_path);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  423|  1.31k|  SAFE_FREE(session->opts.preferred_authentications);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  424|       |
  425|  14.4k|  for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  14.4k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (425:15): [True: 13.1k, False: 1.31k]
  ------------------
  426|  13.1k|      if (session->opts.wanted_methods[i]) {
  ------------------
  |  Branch (426:11): [True: 5.91k, False: 7.22k]
  ------------------
  427|  5.91k|          SAFE_FREE(session->opts.wanted_methods[i]);
  ------------------
  |  |  373|  5.91k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 5.91k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 5.91k]
  |  |  ------------------
  ------------------
  428|  5.91k|      }
  429|  13.1k|  }
  430|       |
  431|  1.31k|  SAFE_FREE(session->server_opts.custombanner);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  432|  1.31k|  SAFE_FREE(session->server_opts.moduli_file);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.31k]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  433|       |
  434|  1.31k|  _ssh_remove_legacy_log_cb();
  435|       |
  436|       |  /* burn connection, it could contain sensitive data */
  437|  1.31k|  ssh_burn(session, sizeof(struct ssh_session_struct));
  ------------------
  |  |  388|  1.31k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  438|       |  SAFE_FREE(session);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  439|  1.31k|}
ssh_session_socket_close:
  604|  1.97k|{
  605|  1.97k|    if (session->opts.fd == SSH_INVALID_SOCKET) {
  ------------------
  |  |  124|  1.97k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  |  Branch (605:9): [True: 657, False: 1.31k]
  ------------------
  606|    657|        ssh_socket_close(session->socket);
  607|    657|    }
  608|  1.97k|    session->alive = 0;
  609|  1.97k|    session->session_state = SSH_SESSION_STATE_ERROR;
  610|  1.97k|}
ssh_set_blocking:
  638|  1.31k|{
  639|  1.31k|    if (session == NULL) {
  ------------------
  |  Branch (639:9): [True: 0, False: 1.31k]
  ------------------
  640|      0|        return;
  641|      0|    }
  642|  1.31k|    session->flags &= ~SSH_SESSION_FLAG_BLOCKING;
  ------------------
  |  |   75|  1.31k|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  643|  1.31k|    session->flags |= blocking ? SSH_SESSION_FLAG_BLOCKING : 0;
  ------------------
  |  |   75|  1.31k|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (643:23): [True: 1.31k, False: 0]
  ------------------
  644|  1.31k|}
ssh_is_blocking:
  653|  12.6k|{
  654|  12.6k|    return (session->flags & SSH_SESSION_FLAG_BLOCKING) ? 1 : 0;
  ------------------
  |  |   75|  12.6k|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (654:12): [True: 12.6k, False: 0]
  ------------------
  655|  12.6k|}
ssh_blocking_flush:
  677|  3.28k|int ssh_blocking_flush(ssh_session session, int timeout){
  678|  3.28k|    int rc;
  679|  3.28k|    if (session == NULL) {
  ------------------
  |  Branch (679:9): [True: 0, False: 3.28k]
  ------------------
  680|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  681|      0|    }
  682|       |
  683|  3.28k|    rc = ssh_handle_packets_termination(session, timeout,
  684|  3.28k|            ssh_flush_termination, session);
  685|  3.28k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  3.28k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (685:9): [True: 0, False: 3.28k]
  ------------------
  686|      0|        return rc;
  687|      0|    }
  688|  3.28k|    if (!ssh_flush_termination(session)) {
  ------------------
  |  Branch (688:9): [True: 0, False: 3.28k]
  ------------------
  689|      0|        rc = SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  690|      0|    }
  691|       |
  692|  3.28k|    return rc;
  693|  3.28k|}
ssh_set_fd_towrite:
  747|    657|void ssh_set_fd_towrite(ssh_session session) {
  748|    657|  if (session == NULL) {
  ------------------
  |  Branch (748:7): [True: 0, False: 657]
  ------------------
  749|      0|    return;
  750|      0|  }
  751|       |
  752|    657|  ssh_socket_set_write_wontblock(session->socket);
  753|    657|}
ssh_handle_packets:
  790|  18.4k|{
  791|  18.4k|    ssh_poll_handle spoll = NULL;
  792|  18.4k|    ssh_poll_ctx ctx = NULL;
  793|  18.4k|    int tm = timeout;
  794|  18.4k|    int rc;
  795|       |
  796|  18.4k|    if (session == NULL || session->socket == NULL) {
  ------------------
  |  Branch (796:9): [True: 0, False: 18.4k]
  |  Branch (796:28): [True: 0, False: 18.4k]
  ------------------
  797|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  798|      0|    }
  799|       |
  800|  18.4k|    spoll = ssh_socket_get_poll_handle(session->socket);
  801|  18.4k|    if (spoll == NULL) {
  ------------------
  |  Branch (801:9): [True: 0, False: 18.4k]
  ------------------
  802|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  803|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  804|      0|    }
  805|  18.4k|    ssh_poll_add_events(spoll, POLLIN);
  806|  18.4k|    ctx = ssh_poll_get_ctx(spoll);
  807|       |
  808|  18.4k|    if (ctx == NULL) {
  ------------------
  |  Branch (808:9): [True: 1.31k, False: 17.1k]
  ------------------
  809|  1.31k|        ctx = ssh_poll_get_default_ctx(session);
  810|  1.31k|        if (ctx == NULL) {
  ------------------
  |  Branch (810:13): [True: 0, False: 1.31k]
  ------------------
  811|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  812|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  813|      0|        }
  814|  1.31k|        rc = ssh_poll_ctx_add(ctx, spoll);
  815|  1.31k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (815:13): [True: 0, False: 1.31k]
  ------------------
  816|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  817|      0|        }
  818|  1.31k|    }
  819|       |
  820|  18.4k|    if (timeout == SSH_TIMEOUT_USER) {
  ------------------
  |  |  101|  18.4k|#define SSH_TIMEOUT_USER -2
  ------------------
  |  Branch (820:9): [True: 0, False: 18.4k]
  ------------------
  821|      0|        if (ssh_is_blocking(session)) {
  ------------------
  |  Branch (821:13): [True: 0, False: 0]
  ------------------
  822|      0|            tm = ssh_make_milliseconds(session->opts.timeout,
  823|      0|                                       session->opts.timeout_usec);
  824|      0|        } else {
  825|      0|            tm = 0;
  826|      0|        }
  827|      0|    }
  828|  18.4k|    rc = ssh_poll_ctx_dopoll(ctx, tm);
  829|  18.4k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  18.4k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (829:9): [True: 656, False: 17.8k]
  ------------------
  830|    656|        session->session_state = SSH_SESSION_STATE_ERROR;
  831|    656|    }
  832|       |
  833|  18.4k|    return rc;
  834|  18.4k|}
ssh_handle_packets_termination:
  867|  11.9k|{
  868|  11.9k|    struct ssh_timestamp ts;
  869|  11.9k|    int timeout_ms = SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|  11.9k|#define SSH_TIMEOUT_INFINITE -1
  ------------------
  870|  11.9k|    int tm;
  871|  11.9k|    int ret = SSH_OK;
  ------------------
  |  |  316|  11.9k|#define SSH_OK 0     /* No error */
  ------------------
  872|       |
  873|       |    /* If a timeout has been provided, use it */
  874|  11.9k|    if (timeout >= 0) {
  ------------------
  |  Branch (874:9): [True: 657, False: 11.3k]
  ------------------
  875|    657|        timeout_ms = timeout;
  876|  11.3k|    } else {
  877|  11.3k|        if (ssh_is_blocking(session)) {
  ------------------
  |  Branch (877:13): [True: 11.3k, False: 0]
  ------------------
  878|  11.3k|            if (timeout == SSH_TIMEOUT_USER || timeout == SSH_TIMEOUT_DEFAULT) {
  ------------------
  |  |  101|  22.6k|#define SSH_TIMEOUT_USER -2
  ------------------
                          if (timeout == SSH_TIMEOUT_USER || timeout == SSH_TIMEOUT_DEFAULT) {
  ------------------
  |  |  103|  9.35k|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
  |  Branch (878:17): [True: 1.97k, False: 9.35k]
  |  Branch (878:48): [True: 9.35k, False: 0]
  ------------------
  879|  11.3k|                if (session->opts.timeout > 0 ||
  ------------------
  |  Branch (879:21): [True: 11.3k, False: 0]
  ------------------
  880|  11.3k|                    session->opts.timeout_usec > 0) {
  ------------------
  |  Branch (880:21): [True: 0, False: 0]
  ------------------
  881|  11.3k|                    timeout_ms =
  882|  11.3k|                        ssh_make_milliseconds(session->opts.timeout,
  883|  11.3k|                                              session->opts.timeout_usec);
  884|  11.3k|                }
  885|  11.3k|            }
  886|  11.3k|        } else {
  887|      0|            timeout_ms = SSH_TIMEOUT_NONBLOCKING;
  ------------------
  |  |  105|      0|#define SSH_TIMEOUT_NONBLOCKING 0
  ------------------
  888|      0|        }
  889|  11.3k|    }
  890|       |
  891|       |    /* avoid unnecessary syscall for the SSH_TIMEOUT_NONBLOCKING case */
  892|  11.9k|    if (timeout_ms != SSH_TIMEOUT_NONBLOCKING) {
  ------------------
  |  |  105|  11.9k|#define SSH_TIMEOUT_NONBLOCKING 0
  ------------------
  |  Branch (892:9): [True: 11.9k, False: 0]
  ------------------
  893|  11.9k|        ssh_timestamp_init(&ts);
  894|  11.9k|    }
  895|       |
  896|  11.9k|    tm = timeout_ms;
  897|  29.8k|    while(!fct(user)) {
  ------------------
  |  Branch (897:11): [True: 18.4k, False: 11.3k]
  ------------------
  898|  18.4k|        ret = ssh_handle_packets(session, tm);
  899|  18.4k|        if (ret == SSH_ERROR) {
  ------------------
  |  |  317|  18.4k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (899:13): [True: 656, False: 17.8k]
  ------------------
  900|    656|            break;
  901|    656|        }
  902|  17.8k|        if (ssh_timeout_elapsed(&ts, timeout_ms)) {
  ------------------
  |  Branch (902:13): [True: 0, False: 17.8k]
  ------------------
  903|      0|            ret = fct(user) ? SSH_OK : SSH_AGAIN;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
                          ret = fct(user) ? SSH_OK : SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (903:19): [True: 0, False: 0]
  ------------------
  904|      0|            break;
  905|      0|        }
  906|       |
  907|  17.8k|        tm = ssh_timeout_update(&ts, timeout_ms);
  908|  17.8k|    }
  909|       |
  910|  11.9k|    return ret;
  911|  11.9k|}
ssh_socket_exception_callback:
 1022|  1.31k|void ssh_socket_exception_callback(int code, int errno_code, void *user){
 1023|  1.31k|    ssh_session session = (ssh_session)user;
 1024|       |
 1025|  1.31k|    SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  281|  1.31k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1026|  1.31k|            "Socket exception callback: %d (%d)",
 1027|  1.31k|            code,
 1028|  1.31k|            errno_code);
 1029|  1.31k|    session->session_state = SSH_SESSION_STATE_ERROR;
 1030|  1.31k|    if (errno_code == 0 && code == SSH_SOCKET_EXCEPTION_EOF) {
  ------------------
  |  |  520|    656|#define SSH_SOCKET_EXCEPTION_EOF 	     1
  ------------------
  |  Branch (1030:9): [True: 656, False: 657]
  |  Branch (1030:28): [True: 656, False: 0]
  ------------------
 1031|    656|        ssh_set_error(session, SSH_FATAL, "Socket error: disconnected");
  ------------------
  |  |  311|    656|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1032|       |#ifdef _WIN32
 1033|       |    } else if (errno_code == WSAENETDOWN) {
 1034|       |        ssh_set_error(session, SSH_FATAL, "Socket error: network down");
 1035|       |    } else if (errno_code == WSAENETUNREACH) {
 1036|       |        ssh_set_error(session, SSH_FATAL, "Socket error: network unreachable");
 1037|       |    } else if (errno_code == WSAENETRESET) {
 1038|       |        ssh_set_error(session, SSH_FATAL, "Socket error: network reset");
 1039|       |    } else if (errno_code == WSAECONNABORTED) {
 1040|       |        ssh_set_error(session, SSH_FATAL, "Socket error: connection aborted");
 1041|       |    } else if (errno_code == WSAECONNRESET) {
 1042|       |        ssh_set_error(session,
 1043|       |                      SSH_FATAL,
 1044|       |                      "Socket error: connection reset by peer");
 1045|       |    } else if (errno_code == WSAETIMEDOUT) {
 1046|       |        ssh_set_error(session, SSH_FATAL, "Socket error: connection timed out");
 1047|       |    } else if (errno_code == WSAECONNREFUSED) {
 1048|       |        ssh_set_error(session, SSH_FATAL, "Socket error: connection refused");
 1049|       |    } else if (errno_code == WSAEHOSTUNREACH) {
 1050|       |        ssh_set_error(session, SSH_FATAL, "Socket error: host unreachable");
 1051|       |#endif
 1052|    657|    } else {
 1053|    657|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};
 1054|    657|        ssh_set_error(session,
  ------------------
  |  |  311|    657|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1055|    657|                      SSH_FATAL,
 1056|    657|                      "Socket error: %s",
 1057|    657|                      ssh_strerror(errno_code, err_msg, SSH_ERRNO_MSG_MAX));
 1058|    657|    }
 1059|       |
 1060|  1.31k|    session->ssh_connection_callback(session);
 1061|  1.31k|}
session.c:ssh_flush_termination:
  658|  7.88k|static int ssh_flush_termination(void *c){
  659|  7.88k|  ssh_session session = c;
  660|  7.88k|  if (ssh_socket_buffered_write_bytes(session->socket) == 0 ||
  ------------------
  |  Branch (660:7): [True: 3.94k, False: 3.93k]
  ------------------
  661|  3.93k|      session->session_state == SSH_SESSION_STATE_ERROR)
  ------------------
  |  Branch (661:7): [True: 2.62k, False: 1.31k]
  ------------------
  662|  6.56k|    return 1;
  663|  1.31k|  else
  664|  1.31k|    return 0;
  665|  7.88k|}

ssh_socket_init:
  132|      2|{
  133|      2|    if (sockets_initialized == 0) {
  ------------------
  |  Branch (133:9): [True: 2, False: 0]
  ------------------
  134|       |#ifdef _WIN32
  135|       |        struct WSAData wsaData;
  136|       |
  137|       |        /* Initiates use of the Winsock DLL by a process. */
  138|       |        if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) {
  139|       |            return -1;
  140|       |        }
  141|       |#endif
  142|      2|        ssh_poll_init();
  143|       |
  144|      2|        sockets_initialized = 1;
  145|      2|    }
  146|       |
  147|      2|    return 0;
  148|      2|}
ssh_socket_new:
  182|  3.28k|{
  183|  3.28k|    ssh_socket s;
  184|       |
  185|  3.28k|    s = calloc(1, sizeof(struct ssh_socket_struct));
  186|  3.28k|    if (s == NULL) {
  ------------------
  |  Branch (186:9): [True: 0, False: 3.28k]
  ------------------
  187|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  188|      0|        return NULL;
  189|      0|    }
  190|  3.28k|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|  3.28k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  191|  3.28k|    s->last_errno = -1;
  192|  3.28k|    s->fd_is_socket = 1;
  193|  3.28k|    s->session = session;
  194|  3.28k|    s->in_buffer = ssh_buffer_new();
  195|  3.28k|    if (s->in_buffer == NULL) {
  ------------------
  |  Branch (195:9): [True: 0, False: 3.28k]
  ------------------
  196|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  197|      0|        SAFE_FREE(s);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  198|      0|        return NULL;
  199|      0|    }
  200|  3.28k|    s->out_buffer=ssh_buffer_new();
  201|  3.28k|    if (s->out_buffer == NULL) {
  ------------------
  |  Branch (201:9): [True: 0, False: 3.28k]
  ------------------
  202|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  203|      0|        SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  951|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 0, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  204|      0|        SAFE_FREE(s);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  205|      0|        return NULL;
  206|      0|    }
  207|  3.28k|    s->read_wontblock = 0;
  208|  3.28k|    s->write_wontblock = 0;
  209|  3.28k|    s->data_except = 0;
  210|       |    s->poll_handle = NULL;
  211|  3.28k|    s->state=SSH_SOCKET_NONE;
  212|  3.28k|    return s;
  213|  3.28k|}
ssh_socket_reset:
  226|  1.31k|{
  227|  1.31k|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|  1.31k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  228|  1.31k|    s->last_errno = -1;
  229|  1.31k|    s->fd_is_socket = 1;
  230|  1.31k|    ssh_buffer_reinit(s->in_buffer);
  231|  1.31k|    ssh_buffer_reinit(s->out_buffer);
  232|  1.31k|    s->read_wontblock = 0;
  233|  1.31k|    s->write_wontblock = 0;
  234|  1.31k|    s->data_except = 0;
  235|  1.31k|    if (s->poll_handle != NULL) {
  ------------------
  |  Branch (235:9): [True: 656, False: 658]
  ------------------
  236|    656|        ssh_poll_free(s->poll_handle);
  237|       |        s->poll_handle = NULL;
  238|    656|    }
  239|  1.31k|    s->state=SSH_SOCKET_NONE;
  240|  1.31k|#ifndef _WIN32
  241|  1.31k|    s->proxy_pid = 0;
  242|  1.31k|#endif
  243|  1.31k|}
ssh_socket_set_callbacks:
  253|  2.62k|{
  254|  2.62k|    s->callbacks = callbacks;
  255|  2.62k|}
ssh_socket_set_connected:
  269|  1.31k|{
  270|  1.31k|    s->state = SSH_SOCKET_CONNECTED;
  271|       |    /* `POLLOUT` is the event to wait for in a non-blocking connect */
  272|  1.31k|    if (p != NULL) {
  ------------------
  |  Branch (272:9): [True: 1.31k, False: 0]
  ------------------
  273|  1.31k|        ssh_poll_set_events(p, POLLIN | POLLOUT);
  274|  1.31k|    }
  275|  1.31k|}
ssh_socket_pollcallback:
  296|  23.6k|{
  297|  23.6k|    ssh_socket s = (ssh_socket)v_s;
  298|  23.6k|    void *buffer = NULL;
  299|  23.6k|    ssize_t nread = 0;
  300|  23.6k|    int rc;
  301|  23.6k|    int err = 0;
  302|  23.6k|    socklen_t errlen = sizeof(err);
  303|       |
  304|       |    /* Do not do anything if this socket was already closed */
  305|  23.6k|    if (!ssh_socket_is_open(s)) {
  ------------------
  |  Branch (305:9): [True: 0, False: 23.6k]
  ------------------
  306|      0|        return -1;
  307|      0|    }
  308|  23.6k|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|   141k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 13.0k, False: 10.6k]
  |  |  |  Branch (281:34): [True: 13.2k, False: 10.4k]
  |  |  |  Branch (281:34): [True: 0, False: 23.6k]
  |  |  ------------------
  ------------------
  309|  23.6k|            "Poll callback on socket %d (%s%s%s), out buffer %" PRIu32, fd,
  310|  23.6k|            (revents & POLLIN) ? "POLLIN ":"",
  311|  23.6k|            (revents & POLLOUT) ? "POLLOUT ":"",
  312|  23.6k|            (revents & POLLERR) ? "POLLERR":"",
  313|  23.6k|            ssh_buffer_get_len(s->out_buffer));
  314|  23.6k|    if ((revents & POLLERR) || (revents & POLLHUP)) {
  ------------------
  |  Branch (314:9): [True: 21, False: 23.6k]
  |  Branch (314:32): [True: 745, False: 22.9k]
  ------------------
  315|       |        /* Check if we are in a connecting state */
  316|    745|        if (s->state == SSH_SOCKET_CONNECTING) {
  ------------------
  |  Branch (316:13): [True: 0, False: 745]
  ------------------
  317|      0|            s->state = SSH_SOCKET_ERROR;
  318|      0|            rc = getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&err, &errlen);
  319|      0|            if (rc < 0) {
  ------------------
  |  Branch (319:17): [True: 0, False: 0]
  ------------------
  320|      0|                err = errno;
  321|      0|            }
  322|      0|            ssh_socket_close(s);
  323|       |            /* Overwrite ssh_socket_close() error with the real socket error */
  324|      0|            s->last_errno = err;
  325|      0|            errno = err;
  326|       |
  327|      0|            if (s->callbacks != NULL && s->callbacks->connected != NULL) {
  ------------------
  |  Branch (327:17): [True: 0, False: 0]
  |  Branch (327:41): [True: 0, False: 0]
  ------------------
  328|      0|                s->callbacks->connected(SSH_SOCKET_CONNECTED_ERROR,
  ------------------
  |  |  524|      0|#define SSH_SOCKET_CONNECTED_ERROR 		2
  ------------------
  329|      0|                                        err,
  330|      0|                                        s->callbacks->userdata);
  331|      0|            }
  332|       |
  333|      0|            return -1;
  334|      0|        }
  335|       |        /* Then we are in a more standard kind of error */
  336|       |        /* force a read to get an explanation */
  337|    745|        revents |= POLLIN;
  338|    745|    }
  339|  23.6k|    if ((revents & POLLIN) && s->state == SSH_SOCKET_CONNECTED) {
  ------------------
  |  Branch (339:9): [True: 13.0k, False: 10.6k]
  |  Branch (339:31): [True: 12.4k, False: 655]
  ------------------
  340|  12.4k|        s->read_wontblock = 1;
  341|  12.4k|        buffer = ssh_buffer_allocate(s->in_buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|  12.4k|#define MAX_BUF_SIZE 4096
  ------------------
  342|  12.4k|        if (buffer) {
  ------------------
  |  Branch (342:13): [True: 12.4k, False: 1]
  ------------------
  343|  12.4k|            nread = ssh_socket_unbuffered_read(s, buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|  12.4k|#define MAX_BUF_SIZE 4096
  ------------------
  344|  12.4k|        }
  345|  12.4k|        if (nread < 0) {
  ------------------
  |  Branch (345:13): [True: 0, False: 12.4k]
  ------------------
  346|      0|            ssh_buffer_pass_bytes_end(s->in_buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|      0|#define MAX_BUF_SIZE 4096
  ------------------
  347|      0|            if (p != NULL) {
  ------------------
  |  Branch (347:17): [True: 0, False: 0]
  ------------------
  348|      0|                ssh_poll_remove_events(p, POLLIN);
  349|      0|            }
  350|       |
  351|      0|            if (s->callbacks != NULL && s->callbacks->exception != NULL) {
  ------------------
  |  Branch (351:17): [True: 0, False: 0]
  |  Branch (351:41): [True: 0, False: 0]
  ------------------
  352|      0|                s->callbacks->exception(SSH_SOCKET_EXCEPTION_ERROR,
  ------------------
  |  |  521|      0|#define SSH_SOCKET_EXCEPTION_ERROR     2
  ------------------
  353|      0|                                        s->last_errno,
  354|      0|                                        s->callbacks->userdata);
  355|      0|            }
  356|      0|            return -2;
  357|      0|        }
  358|       |
  359|       |        /* Rollback the unused space */
  360|  12.4k|        ssh_buffer_pass_bytes_end(s->in_buffer,
  361|  12.4k|                                  (uint32_t)(MAX_BUF_SIZE - nread));
  ------------------
  |  |  230|  12.4k|#define MAX_BUF_SIZE 4096
  ------------------
  362|       |
  363|  12.4k|        if (nread == 0) {
  ------------------
  |  Branch (363:13): [True: 656, False: 11.7k]
  ------------------
  364|    656|            if (p != NULL) {
  ------------------
  |  Branch (364:17): [True: 656, False: 0]
  ------------------
  365|    656|                ssh_poll_remove_events(p, POLLIN);
  366|    656|            }
  367|    656|            if (s->callbacks != NULL && s->callbacks->exception != NULL) {
  ------------------
  |  Branch (367:17): [True: 656, False: 0]
  |  Branch (367:41): [True: 656, False: 0]
  ------------------
  368|    656|                s->callbacks->exception(SSH_SOCKET_EXCEPTION_EOF,
  ------------------
  |  |  520|    656|#define SSH_SOCKET_EXCEPTION_EOF 	     1
  ------------------
  369|    656|                                        0,
  370|    656|                                        s->callbacks->userdata);
  371|    656|            }
  372|    656|            return -2;
  373|    656|        }
  374|       |
  375|  11.7k|        if (s->session->socket_counter != NULL) {
  ------------------
  |  Branch (375:13): [True: 0, False: 11.7k]
  ------------------
  376|      0|            s->session->socket_counter->in_bytes += nread;
  377|      0|        }
  378|       |
  379|       |        /* Call the callback */
  380|  11.7k|        if (s->callbacks != NULL && s->callbacks->data != NULL) {
  ------------------
  |  Branch (380:13): [True: 11.7k, False: 18.4E]
  |  Branch (380:37): [True: 11.7k, False: 0]
  ------------------
  381|  11.7k|            size_t processed;
  382|  24.2k|            do {
  383|  24.2k|                processed = s->callbacks->data(ssh_buffer_get(s->in_buffer),
  384|  24.2k|                                               ssh_buffer_get_len(s->in_buffer),
  385|  24.2k|                                               s->callbacks->userdata);
  386|  24.2k|                ssh_buffer_pass_bytes(s->in_buffer, (uint32_t)processed);
  387|  24.2k|            } while ((processed > 0) && (s->state == SSH_SOCKET_CONNECTED));
  ------------------
  |  Branch (387:22): [True: 12.4k, False: 11.7k]
  |  Branch (387:41): [True: 12.4k, False: 0]
  ------------------
  388|       |
  389|       |            /* p may have been freed, so don't use it
  390|       |             * anymore in this function */
  391|  11.7k|            p = NULL;
  392|  11.7k|        }
  393|  11.7k|    }
  394|       |#ifdef _WIN32
  395|       |    if (revents & POLLOUT || revents & POLLWRNORM) {
  396|       |#else
  397|  23.0k|    if (revents & POLLOUT) {
  ------------------
  |  Branch (397:9): [True: 13.2k, False: 9.71k]
  ------------------
  398|  13.2k|#endif
  399|  13.2k|        uint32_t len;
  400|       |
  401|       |        /* First, POLLOUT is a sign we may be connected */
  402|  13.2k|        if (s->state == SSH_SOCKET_CONNECTING) {
  ------------------
  |  Branch (402:13): [True: 657, False: 12.6k]
  ------------------
  403|    657|            SSH_LOG(SSH_LOG_PACKET, "Received POLLOUT in connecting state");
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  404|    657|            ssh_socket_set_connected(s, p);
  405|       |
  406|    657|            rc = ssh_socket_set_blocking(ssh_socket_get_fd(s));
  407|    657|            if (rc < 0) {
  ------------------
  |  Branch (407:17): [True: 0, False: 657]
  ------------------
  408|      0|                return -1;
  409|      0|            }
  410|       |
  411|    657|            if (s->callbacks != NULL && s->callbacks->connected != NULL) {
  ------------------
  |  Branch (411:17): [True: 657, False: 0]
  |  Branch (411:41): [True: 657, False: 0]
  ------------------
  412|    657|                s->callbacks->connected(SSH_SOCKET_CONNECTED_OK,
  ------------------
  |  |  523|    657|#define SSH_SOCKET_CONNECTED_OK 			1
  ------------------
  413|    657|                                        0,
  414|    657|                                        s->callbacks->userdata);
  415|    657|            }
  416|       |
  417|    657|            return 0;
  418|    657|        }
  419|       |
  420|       |        /* So, we can write data */
  421|  12.6k|        s->write_wontblock = 1;
  422|  12.6k|        if (p != NULL) {
  ------------------
  |  Branch (422:13): [True: 10.6k, False: 1.96k]
  ------------------
  423|  10.6k|            ssh_poll_remove_events(p, POLLOUT);
  424|  10.6k|        }
  425|       |
  426|       |        /* If buffered data is pending, write it */
  427|  12.6k|        len = ssh_buffer_get_len(s->out_buffer);
  428|  12.6k|        if (len > 0) {
  ------------------
  |  Branch (428:13): [True: 4.41k, False: 8.21k]
  ------------------
  429|  4.41k|            ssh_socket_nonblocking_flush(s);
  430|  8.21k|        } else if (s->callbacks != NULL && s->callbacks->controlflow != NULL) {
  ------------------
  |  Branch (430:20): [True: 8.21k, False: 0]
  |  Branch (430:44): [True: 7.56k, False: 657]
  ------------------
  431|       |            /* Otherwise advertise the upper level that write can be done */
  432|  7.56k|            SSH_LOG(SSH_LOG_TRACE, "sending control flow event");
  ------------------
  |  |  281|  7.56k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  433|  7.56k|            s->callbacks->controlflow(SSH_SOCKET_FLOW_WRITEWONTBLOCK,
  ------------------
  |  |  518|  7.56k|#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
  ------------------
  434|  7.56k|                                      s->callbacks->userdata);
  435|  7.56k|        }
  436|       |        /* TODO: Find a way to put back POLLOUT when buffering occurs */
  437|  12.6k|    }
  438|       |
  439|       |    /* Return -1 if the poll handler disappeared */
  440|  22.3k|    if (s->poll_handle == NULL) {
  ------------------
  |  Branch (440:9): [True: 0, False: 22.3k]
  ------------------
  441|      0|        return -1;
  442|      0|    }
  443|       |
  444|  22.3k|    return 0;
  445|  22.3k|}
ssh_socket_get_poll_handle:
  454|  20.4k|{
  455|  20.4k|    if (s->poll_handle) {
  ------------------
  |  Branch (455:9): [True: 19.1k, False: 1.31k]
  ------------------
  456|  19.1k|        return s->poll_handle;
  457|  19.1k|    }
  458|  1.31k|    s->poll_handle = ssh_poll_new(s->fd, 0, ssh_socket_pollcallback, s);
  459|  1.31k|    return s->poll_handle;
  460|  20.4k|}
ssh_socket_free:
  473|  3.28k|{
  474|  3.28k|    if (s == NULL) {
  ------------------
  |  Branch (474:9): [True: 0, False: 3.28k]
  ------------------
  475|      0|        return;
  476|      0|    }
  477|  3.28k|    ssh_socket_close(s);
  478|  3.28k|    SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  951|  3.28k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 3.28k, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 3.28k]
  |  |  ------------------
  ------------------
  479|  3.28k|    SSH_BUFFER_FREE(s->out_buffer);
  ------------------
  |  |  951|  3.28k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (951:14): [True: 3.28k, False: 0]
  |  |  |  Branch (951:69): [Folded, False: 3.28k]
  |  |  ------------------
  ------------------
  480|       |    SAFE_FREE(s);
  ------------------
  |  |  373|  3.28k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 3.28k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 3.28k]
  |  |  ------------------
  ------------------
  481|  3.28k|}
ssh_socket_close:
  546|  5.91k|{
  547|  5.91k|    if (ssh_socket_is_open(s)) {
  ------------------
  |  Branch (547:9): [True: 1.31k, False: 4.59k]
  ------------------
  548|       |#ifdef _WIN32
  549|       |        CLOSE_SOCKET(s->fd);
  550|       |        s->last_errno = WSAGetLastError();
  551|       |#else
  552|  1.31k|        CLOSE_SOCKET(s->fd);
  ------------------
  |  |  472|  1.31k|#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  124|  1.31k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |               #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  199|  1.31k|#define _XCLOSESOCKET close
  |  |  ------------------
  |  |               #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  124|  1.31k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |  |  Branch (472:34): [True: 1.31k, False: 0]
  |  |  |  Branch (472:116): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  553|  1.31k|        s->last_errno = errno;
  554|  1.31k|#endif
  555|  1.31k|    }
  556|       |
  557|  5.91k|    if (s->poll_handle != NULL && !ssh_poll_is_locked(s->poll_handle)) {
  ------------------
  |  Branch (557:9): [True: 1.31k, False: 4.59k]
  |  Branch (557:35): [True: 658, False: 656]
  ------------------
  558|    658|        ssh_poll_free(s->poll_handle);
  559|    658|        s->poll_handle = NULL;
  560|    658|    }
  561|       |
  562|  5.91k|    s->state = SSH_SOCKET_CLOSED;
  563|       |
  564|  5.91k|#ifndef _WIN32
  565|       |    /* If the proxy command still runs try to kill it */
  566|  5.91k|    if (s->proxy_pid != 0) {
  ------------------
  |  Branch (566:9): [True: 0, False: 5.91k]
  ------------------
  567|      0|        int status;
  568|      0|        pid_t pid = s->proxy_pid;
  569|       |
  570|      0|        s->proxy_pid = 0;
  571|      0|        kill(pid, SIGTERM);
  572|      0|        while (waitpid(pid, &status, 0) == -1) {
  ------------------
  |  Branch (572:16): [True: 0, False: 0]
  ------------------
  573|      0|            if (errno != EINTR) {
  ------------------
  |  Branch (573:17): [True: 0, False: 0]
  ------------------
  574|      0|                SSH_LOG_STRERROR(SSH_LOG_TRACE, errno, "waitpid failed: %s");
  ------------------
  |  |  283|      0|    do {                                                            \
  |  |  284|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|      0|        _ssh_log(priority,                                          \
  |  |  286|      0|                 __func__,                                          \
  |  |  287|      0|                 __VA_ARGS__,                                       \
  |  |  288|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
  575|      0|                return;
  576|      0|            }
  577|      0|        }
  578|      0|        if (!WIFEXITED(status)) {
  ------------------
  |  Branch (578:13): [True: 0, False: 0]
  ------------------
  579|      0|            SSH_LOG(SSH_LOG_TRACE, "Proxy command exited abnormally");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  580|      0|            return;
  581|      0|        }
  582|      0|        SSH_LOG(SSH_LOG_TRACE, "Proxy command returned %d", WEXITSTATUS(status));
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  583|      0|    }
  584|  5.91k|#endif
  585|  5.91k|}
ssh_socket_set_fd:
  596|  1.31k|{
  597|  1.31k|    ssh_poll_handle h = NULL;
  598|       |
  599|  1.31k|    s->fd = fd;
  600|       |
  601|  1.31k|    if (s->poll_handle) {
  ------------------
  |  Branch (601:9): [True: 0, False: 1.31k]
  ------------------
  602|      0|        ssh_poll_set_fd(s->poll_handle,fd);
  603|  1.31k|    } else {
  604|  1.31k|        s->state = SSH_SOCKET_CONNECTING;
  605|  1.31k|        h = ssh_socket_get_poll_handle(s);
  606|  1.31k|        if (h == NULL) {
  ------------------
  |  Branch (606:13): [True: 0, False: 1.31k]
  ------------------
  607|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  608|      0|        }
  609|       |
  610|       |        /* POLLOUT is the event to wait for in a nonblocking connect */
  611|  1.31k|        ssh_poll_set_events(h, POLLOUT);
  612|       |#ifdef _WIN32
  613|       |        ssh_poll_add_events(h, POLLWRNORM);
  614|       |#endif
  615|  1.31k|    }
  616|  1.31k|    return SSH_OK;
  ------------------
  |  |  316|  1.31k|#define SSH_OK 0     /* No error */
  ------------------
  617|  1.31k|}
ssh_socket_get_fd:
  629|    657|{
  630|    657|    return s->fd;
  631|    657|}
ssh_socket_is_open:
  643|  63.4k|{
  644|  63.4k|    return s->fd != SSH_INVALID_SOCKET;
  ------------------
  |  |  124|  63.4k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  645|  63.4k|}
ssh_socket_write:
  811|  14.4k|{
  812|  14.4k|    if (len > 0) {
  ------------------
  |  Branch (812:9): [True: 14.4k, False: 0]
  ------------------
  813|  14.4k|        if (ssh_buffer_add_data(s->out_buffer, buffer, len) < 0) {
  ------------------
  |  Branch (813:13): [True: 0, False: 14.4k]
  ------------------
  814|      0|            ssh_set_error_oom(s->session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  815|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  816|      0|        }
  817|  14.4k|        ssh_socket_nonblocking_flush(s);
  818|  14.4k|    }
  819|       |
  820|  14.4k|    return SSH_OK;
  ------------------
  |  |  316|  14.4k|#define SSH_OK 0     /* No error */
  ------------------
  821|  14.4k|}
ssh_socket_nonblocking_flush:
  841|  18.8k|{
  842|  18.8k|    ssh_session session = s->session;
  843|  18.8k|    uint32_t len;
  844|       |
  845|  18.8k|    if (!ssh_socket_is_open(s)) {
  ------------------
  |  Branch (845:9): [True: 0, False: 18.8k]
  ------------------
  846|      0|        session->alive = 0;
  847|      0|        if (s->callbacks && s->callbacks->exception) {
  ------------------
  |  Branch (847:13): [True: 0, False: 0]
  |  Branch (847:29): [True: 0, False: 0]
  ------------------
  848|      0|            s->callbacks->exception(SSH_SOCKET_EXCEPTION_ERROR,
  ------------------
  |  |  521|      0|#define SSH_SOCKET_EXCEPTION_ERROR     2
  ------------------
  849|      0|                                    s->last_errno,
  850|      0|                                    s->callbacks->userdata);
  851|      0|        } else {
  852|      0|            char err_msg[SSH_ERRNO_MSG_MAX] = {0};
  853|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  854|      0|                          SSH_FATAL,
  855|      0|                          "Writing packet: error on socket (or connection "
  856|      0|                          "closed): %s",
  857|      0|                          ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
  858|      0|        }
  859|       |
  860|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  861|      0|    }
  862|       |
  863|  18.8k|    len = ssh_buffer_get_len(s->out_buffer);
  864|  18.8k|    if (!s->write_wontblock && s->poll_handle && len > 0) {
  ------------------
  |  Branch (864:9): [True: 5.73k, False: 13.1k]
  |  Branch (864:32): [True: 5.73k, False: 0]
  |  Branch (864:50): [True: 5.73k, False: 0]
  ------------------
  865|       |        /* force the poll system to catch pollout events */
  866|  5.73k|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  867|       |
  868|  5.73k|        return SSH_AGAIN;
  ------------------
  |  |  318|  5.73k|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  869|  5.73k|    }
  870|       |
  871|  13.1k|    if (s->write_wontblock && len > 0) {
  ------------------
  |  Branch (871:9): [True: 13.1k, False: 0]
  |  Branch (871:31): [True: 13.1k, False: 0]
  ------------------
  872|  13.1k|        ssize_t bwritten;
  873|       |
  874|  13.1k|        bwritten = ssh_socket_unbuffered_write(s,
  875|  13.1k|                                               ssh_buffer_get(s->out_buffer),
  876|  13.1k|                                               len);
  877|  13.1k|        if (bwritten < 0) {
  ------------------
  |  Branch (877:13): [True: 657, False: 12.4k]
  ------------------
  878|    657|            session->alive = 0;
  879|    657|            ssh_socket_close(s);
  880|       |
  881|    657|            if (s->callbacks && s->callbacks->exception) {
  ------------------
  |  Branch (881:17): [True: 657, False: 0]
  |  Branch (881:33): [True: 657, False: 0]
  ------------------
  882|    657|                s->callbacks->exception(SSH_SOCKET_EXCEPTION_ERROR,
  ------------------
  |  |  521|    657|#define SSH_SOCKET_EXCEPTION_ERROR     2
  ------------------
  883|    657|                                        s->last_errno,
  884|    657|                                        s->callbacks->userdata);
  885|    657|            } else {
  886|      0|                char err_msg[SSH_ERRNO_MSG_MAX] = {0};
  887|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  888|      0|                              SSH_FATAL,
  889|      0|                              "Writing packet: error on socket (or connection "
  890|      0|                              "closed): %s",
  891|      0|                              ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
  892|      0|            }
  893|       |
  894|    657|            return SSH_ERROR;
  ------------------
  |  |  317|    657|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  895|    657|        }
  896|       |
  897|  12.4k|        ssh_buffer_pass_bytes(s->out_buffer, (uint32_t)bwritten);
  898|  12.4k|        if (s->session->socket_counter != NULL) {
  ------------------
  |  Branch (898:13): [True: 0, False: 12.4k]
  ------------------
  899|      0|            s->session->socket_counter->out_bytes += bwritten;
  900|      0|        }
  901|  12.4k|    }
  902|       |
  903|       |    /* Is there some data pending? */
  904|  12.4k|    len = ssh_buffer_get_len(s->out_buffer);
  905|  12.4k|    if (s->poll_handle && len > 0) {
  ------------------
  |  Branch (905:9): [True: 12.4k, False: 0]
  |  Branch (905:27): [True: 0, False: 12.4k]
  ------------------
  906|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  907|      0|                "did not send all the data, queuing pollout event");
  908|       |        /* force the poll system to catch pollout events */
  909|      0|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  910|       |
  911|      0|        return SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  912|      0|    }
  913|       |
  914|       |    /* all data written */
  915|  12.4k|    return SSH_OK;
  ------------------
  |  |  316|  12.4k|#define SSH_OK 0     /* No error */
  ------------------
  916|  12.4k|}
ssh_socket_set_write_wontblock:
  929|    657|{
  930|    657|    s->write_wontblock = 1;
  931|    657|}
ssh_socket_buffered_write_bytes:
 1002|  7.88k|{
 1003|  7.88k|    if (s==NULL || s->out_buffer == NULL) {
  ------------------
  |  Branch (1003:9): [True: 0, False: 7.88k]
  |  Branch (1003:20): [True: 0, False: 7.88k]
  ------------------
 1004|      0|        return 0;
 1005|      0|    }
 1006|       |
 1007|  7.88k|    return ssh_buffer_get_len(s->out_buffer);
 1008|  7.88k|}
ssh_socket_set_blocking:
 1114|    657|{
 1115|       |    return fcntl(fd, F_SETFL, 0);
 1116|    657|}
socket.c:ssh_socket_unbuffered_read:
  665|  12.4k|{
  666|  12.4k|    ssize_t rc = -1;
  667|       |
  668|  12.4k|    if (s->data_except) {
  ------------------
  |  Branch (668:9): [True: 0, False: 12.4k]
  ------------------
  669|      0|        return -1;
  670|      0|    }
  671|  12.4k|    if (s->fd_is_socket) {
  ------------------
  |  Branch (671:9): [True: 12.4k, False: 0]
  ------------------
  672|  12.4k|        rc = recv(s->fd, buffer, len, 0);
  673|  12.4k|    } else {
  674|      0|        rc = read(s->fd, buffer, len);
  675|      0|    }
  676|       |#ifdef _WIN32
  677|       |    s->last_errno = WSAGetLastError();
  678|       |#else
  679|  12.4k|    s->last_errno = errno;
  680|  12.4k|#endif
  681|  12.4k|    s->read_wontblock = 0;
  682|       |
  683|  12.4k|    if (rc < 0) {
  ------------------
  |  Branch (683:9): [True: 0, False: 12.4k]
  ------------------
  684|      0|        s->data_except = 1;
  685|  12.4k|    } else {
  686|  12.4k|        SSH_LOG(SSH_LOG_TRACE, "read %zd", rc);
  ------------------
  |  |  281|  12.4k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  687|  12.4k|    }
  688|       |
  689|  12.4k|    return rc;
  690|  12.4k|}
socket.c:ssh_socket_unbuffered_write:
  711|  13.1k|{
  712|  13.1k|    ssize_t w = -1;
  713|  13.1k|    int flags = 0;
  714|       |
  715|  13.1k|#ifdef MSG_NOSIGNAL
  716|  13.1k|    flags |= MSG_NOSIGNAL;
  717|  13.1k|#endif
  718|       |
  719|  13.1k|    if (s->data_except) {
  ------------------
  |  Branch (719:9): [True: 0, False: 13.1k]
  ------------------
  720|      0|        return -1;
  721|      0|    }
  722|       |
  723|  13.1k|    if (s->fd_is_socket) {
  ------------------
  |  Branch (723:9): [True: 13.1k, False: 0]
  ------------------
  724|  13.1k|        w = send(s->fd, buffer, len, flags);
  725|  13.1k|    } else {
  726|      0|        w = write(s->fd, buffer, len);
  727|      0|    }
  728|       |#ifdef _WIN32
  729|       |    s->last_errno = WSAGetLastError();
  730|       |#else
  731|  13.1k|    s->last_errno = errno;
  732|  13.1k|#endif
  733|  13.1k|    s->write_wontblock = 0;
  734|       |    /* Reactive the POLLOUT detector in the poll multiplexer system */
  735|  13.1k|    if (s->poll_handle) {
  ------------------
  |  Branch (735:9): [True: 13.1k, False: 0]
  ------------------
  736|  13.1k|        SSH_LOG(SSH_LOG_PACKET, "Enabling POLLOUT for socket");
  ------------------
  |  |  281|  13.1k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  737|  13.1k|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  738|  13.1k|    }
  739|  13.1k|    if (w < 0) {
  ------------------
  |  Branch (739:9): [True: 657, False: 12.4k]
  ------------------
  740|    657|        s->data_except = 1;
  741|    657|    }
  742|       |
  743|  13.1k|    SSH_LOG(SSH_LOG_TRACE, "wrote %zd", w);
  ------------------
  |  |  281|  13.1k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  744|  13.1k|    return w;
  745|  13.1k|}

ssh_string_new:
   57|  53.1k|{
   58|  53.1k|    struct ssh_string_struct *str = NULL;
   59|       |
   60|  53.1k|    if (size > STRING_SIZE_MAX) {
  ------------------
  |  |   38|  53.1k|#define STRING_SIZE_MAX 0x10000000
  ------------------
  |  Branch (60:9): [True: 0, False: 53.1k]
  ------------------
   61|      0|        errno = EINVAL;
   62|      0|        return NULL;
   63|      0|    }
   64|       |
   65|  53.1k|    str = calloc(1, sizeof(struct ssh_string_struct) + size);
   66|  53.1k|    if (str == NULL) {
  ------------------
  |  Branch (66:9): [True: 0, False: 53.1k]
  ------------------
   67|      0|        return NULL;
   68|      0|    }
   69|       |
   70|  53.1k|    str->size = htonl((uint32_t)size);
   71|       |
   72|  53.1k|    return str;
   73|  53.1k|}
ssh_string_fill:
   87|  7.22k|{
   88|  7.22k|    if ((s == NULL) || (data == NULL) || (len == 0) ||
  ------------------
  |  Branch (88:9): [True: 0, False: 7.22k]
  |  Branch (88:24): [True: 0, False: 7.22k]
  |  Branch (88:42): [True: 0, False: 7.22k]
  ------------------
   89|  7.22k|        (len > ssh_string_len(s))) {
  ------------------
  |  Branch (89:9): [True: 0, False: 7.22k]
  ------------------
   90|      0|        return -1;
   91|      0|    }
   92|       |
   93|  7.22k|    memcpy(s->data, data, len);
   94|       |
   95|  7.22k|    return 0;
   96|  7.22k|}
ssh_string_from_char:
  109|  16.3k|{
  110|  16.3k|    struct ssh_string_struct *ptr = NULL;
  111|  16.3k|    size_t len;
  112|       |
  113|  16.3k|    if (what == NULL) {
  ------------------
  |  Branch (113:9): [True: 0, False: 16.3k]
  ------------------
  114|      0|        errno = EINVAL;
  115|      0|        return NULL;
  116|      0|    }
  117|       |
  118|  16.3k|    len = strlen(what);
  119|       |
  120|  16.3k|    ptr = ssh_string_new(len);
  121|  16.3k|    if (ptr == NULL) {
  ------------------
  |  Branch (121:9): [True: 0, False: 16.3k]
  ------------------
  122|      0|        return NULL;
  123|      0|    }
  124|       |
  125|  16.3k|    memcpy(ptr->data, what, len);
  126|       |
  127|  16.3k|    return ptr;
  128|  16.3k|}
ssh_string_len:
  177|   103k|{
  178|   103k|    size_t size;
  179|       |
  180|   103k|    if (s == NULL) {
  ------------------
  |  Branch (180:9): [True: 1.31k, False: 102k]
  ------------------
  181|  1.31k|        return 0;
  182|  1.31k|    }
  183|       |
  184|   102k|    size = ntohl(s->size);
  185|   102k|    if (size > 0 && size <= STRING_SIZE_MAX) {
  ------------------
  |  |   38|  92.3k|#define STRING_SIZE_MAX 0x10000000
  ------------------
  |  Branch (185:9): [True: 92.3k, False: 10.0k]
  |  Branch (185:21): [True: 92.3k, False: 18.4E]
  ------------------
  186|  92.3k|        return size;
  187|  92.3k|    }
  188|       |
  189|  10.0k|    return 0;
  190|   102k|}
ssh_string_get_char:
  202|  1.97k|{
  203|  1.97k|    if (s == NULL) {
  ------------------
  |  Branch (203:9): [True: 0, False: 1.97k]
  ------------------
  204|      0|        return NULL;
  205|      0|    }
  206|  1.97k|    s->data[ssh_string_len(s)] = '\0';
  207|       |
  208|  1.97k|    return (const char *)s->data;
  209|  1.97k|}
ssh_string_to_char:
  223|  12.7k|{
  224|  12.7k|    size_t len;
  225|  12.7k|    char *new = NULL;
  226|       |
  227|  12.7k|    if (s == NULL) {
  ------------------
  |  Branch (227:9): [True: 0, False: 12.7k]
  ------------------
  228|      0|        return NULL;
  229|      0|    }
  230|       |
  231|  12.7k|    len = ssh_string_len(s);
  232|  12.7k|    if (len + 1 < len) {
  ------------------
  |  Branch (232:9): [True: 0, False: 12.7k]
  ------------------
  233|      0|        return NULL;
  234|      0|    }
  235|       |
  236|  12.7k|    new = malloc(len + 1);
  237|  12.7k|    if (new == NULL) {
  ------------------
  |  Branch (237:9): [True: 0, False: 12.7k]
  ------------------
  238|      0|        return NULL;
  239|      0|    }
  240|  12.7k|    memcpy(new, s->data, len);
  241|  12.7k|    new[len] = '\0';
  242|       |
  243|  12.7k|    return new;
  244|  12.7k|}
ssh_string_copy:
  265|  1.97k|{
  266|  1.97k|    struct ssh_string_struct *new = NULL;
  267|  1.97k|    size_t len;
  268|       |
  269|  1.97k|    if (s == NULL) {
  ------------------
  |  Branch (269:9): [True: 0, False: 1.97k]
  ------------------
  270|      0|        return NULL;
  271|      0|    }
  272|       |
  273|  1.97k|    len = ssh_string_len(s);
  274|       |
  275|  1.97k|    new = ssh_string_new(len);
  276|  1.97k|    if (new == NULL) {
  ------------------
  |  Branch (276:9): [True: 0, False: 1.97k]
  ------------------
  277|      0|        return NULL;
  278|      0|    }
  279|       |
  280|  1.97k|    memcpy(new->data, s->data, len);
  281|       |
  282|  1.97k|    return new;
  283|  1.97k|}
ssh_string_burn:
  341|  11.8k|{
  342|  11.8k|    if (s == NULL || s->size == 0) {
  ------------------
  |  Branch (342:9): [True: 3.94k, False: 7.88k]
  |  Branch (342:22): [True: 0, False: 7.88k]
  ------------------
  343|  3.94k|        return;
  344|  3.94k|    }
  345|       |
  346|  7.88k|    ssh_burn(s->data, ssh_string_len(s));
  ------------------
  |  |  388|  7.88k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  347|  7.88k|}
ssh_string_data:
  357|  39.9k|{
  358|  39.9k|    if (s == NULL) {
  ------------------
  |  Branch (358:9): [True: 0, False: 39.9k]
  ------------------
  359|      0|        return NULL;
  360|      0|    }
  361|       |
  362|  39.9k|    return s->data;
  363|  39.9k|}
ssh_string_free:
  371|  68.9k|{
  372|       |    SAFE_FREE(s);
  ------------------
  |  |  373|  68.9k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 50.5k, False: 18.3k]
  |  |  |  Branch (373:71): [Folded, False: 68.9k]
  |  |  ------------------
  ------------------
  373|  68.9k|}

ssh_threads_init:
   42|      2|{
   43|      2|    static int threads_initialized = 0;
   44|      2|    int rc;
   45|       |
   46|      2|    if (threads_initialized) {
  ------------------
  |  Branch (46:9): [True: 0, False: 2]
  ------------------
   47|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
   48|      0|    }
   49|       |
   50|       |    /* first initialize the user_callbacks with our default handlers if not
   51|       |     * already the case
   52|       |     */
   53|      2|    if (user_callbacks == NULL){
  ------------------
  |  Branch (53:9): [True: 2, False: 0]
  ------------------
   54|      2|        user_callbacks = ssh_threads_get_default();
   55|      2|    }
   56|       |
   57|       |    /* Then initialize the crypto libraries threading callbacks */
   58|      2|    rc = crypto_thread_init(user_callbacks);
   59|      2|    if (rc == SSH_OK) {
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (59:9): [True: 2, False: 0]
  ------------------
   60|      2|        threads_initialized = 1;
   61|      2|    }
   62|      2|    return rc;
   63|      2|}
ssh_threads_get_type:
   96|    657|{
   97|    657|    if (user_callbacks != NULL) {
  ------------------
  |  Branch (97:9): [True: 657, False: 0]
  ------------------
   98|    657|        return user_callbacks->type;
   99|    657|    }
  100|      0|    return NULL;
  101|    657|}

crypto_thread_init:
   28|      2|{
   29|      2|    (void) cb;
   30|      2|    return SSH_OK;
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
   31|      2|}

ssh_mutex_lock:
  102|    661|{
  103|    661|    int rc;
  104|       |
  105|    661|    if (mutex == NULL) {
  ------------------
  |  Branch (105:9): [True: 0, False: 661]
  ------------------
  106|      0|        exit(EINVAL);
  107|      0|    }
  108|       |
  109|    661|    rc = pthread_mutex_lock(mutex);
  110|       |
  111|    661|    if (rc) {
  ------------------
  |  Branch (111:9): [True: 0, False: 661]
  ------------------
  112|      0|        exit(rc);
  113|      0|    }
  114|    661|}
ssh_mutex_unlock:
  117|    661|{
  118|    661|    int rc;
  119|       |
  120|    661|    if (mutex == NULL) {
  ------------------
  |  Branch (120:9): [True: 0, False: 661]
  ------------------
  121|      0|        exit(EINVAL);
  122|      0|    }
  123|       |
  124|    661|    rc = pthread_mutex_unlock(mutex);
  125|       |
  126|    661|    if (rc) {
  ------------------
  |  Branch (126:9): [True: 0, False: 661]
  ------------------
  127|      0|        exit(rc);
  128|      0|    }
  129|    661|}
ssh_threads_get_default:
  132|      2|{
  133|      2|    return &ssh_threads_pthread;
  134|      2|}

ssh_tokens_free:
   43|  42.5k|{
   44|  42.5k|    int i;
   45|  42.5k|    if (tokens == NULL) {
  ------------------
  |  Branch (45:9): [True: 0, False: 42.5k]
  ------------------
   46|      0|        return;
   47|      0|    }
   48|       |
   49|  42.5k|    if (tokens->tokens != NULL) {
  ------------------
  |  Branch (49:9): [True: 42.4k, False: 26]
  ------------------
   50|   207k|        for (i = 0; tokens->tokens[i] != NULL; i++) {
  ------------------
  |  Branch (50:21): [True: 164k, False: 42.4k]
  ------------------
   51|   164k|            ssh_burn(tokens->tokens[i], strlen(tokens->tokens[i]));
  ------------------
  |  |  388|   164k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
   52|   164k|        }
   53|  42.4k|    }
   54|       |
   55|  42.5k|    SAFE_FREE(tokens->buffer);
  ------------------
  |  |  373|  42.6k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 42.6k, False: 18.4E]
  |  |  |  Branch (373:71): [Folded, False: 42.5k]
  |  |  ------------------
  ------------------
   56|  42.5k|    SAFE_FREE(tokens->tokens);
  ------------------
  |  |  373|  42.9k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 42.9k, False: 18.4E]
  |  |  |  Branch (373:71): [Folded, False: 42.5k]
  |  |  ------------------
  ------------------
   57|       |    SAFE_FREE(tokens);
  ------------------
  |  |  373|  42.8k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 42.8k, False: 18.4E]
  |  |  |  Branch (373:71): [Folded, False: 42.5k]
  |  |  ------------------
  ------------------
   58|  42.5k|}
ssh_tokenize:
   74|  42.6k|{
   75|       |
   76|  42.6k|    struct ssh_tokens_st *tokens = NULL;
   77|  42.6k|    size_t num_tokens = 1, i = 1;
   78|       |
   79|  42.6k|    char *found, *c;
   80|       |
   81|  42.6k|    if (chain == NULL) {
  ------------------
  |  Branch (81:9): [True: 0, False: 42.6k]
  ------------------
   82|      0|        return NULL;
   83|      0|    }
   84|       |
   85|  42.6k|    tokens = calloc(1, sizeof(struct ssh_tokens_st));
   86|  42.6k|    if (tokens == NULL) {
  ------------------
  |  Branch (86:9): [True: 0, False: 42.6k]
  ------------------
   87|      0|        return NULL;
   88|      0|    }
   89|       |
   90|  42.6k|    tokens->buffer = strdup(chain);
   91|  42.6k|    if (tokens->buffer == NULL) {
  ------------------
  |  Branch (91:9): [True: 0, False: 42.6k]
  ------------------
   92|      0|        goto error;
   93|      0|    }
   94|       |
   95|  42.6k|    c = tokens->buffer;
   96|   166k|    do {
   97|   166k|        found = strchr(c, separator);
   98|   166k|        if (found != NULL) {
  ------------------
  |  Branch (98:13): [True: 124k, False: 42.6k]
  ------------------
   99|   124k|            c = found + 1;
  100|   124k|            num_tokens++;
  101|   124k|        }
  102|   166k|    } while(found != NULL);
  ------------------
  |  Branch (102:13): [True: 124k, False: 42.6k]
  ------------------
  103|       |
  104|       |    /* Allocate tokens list */
  105|  42.6k|    tokens->tokens = calloc(num_tokens + 1, sizeof(char *));
  106|  42.6k|    if (tokens->tokens == NULL) {
  ------------------
  |  Branch (106:9): [True: 0, False: 42.6k]
  ------------------
  107|      0|        goto error;
  108|      0|    }
  109|       |
  110|       |    /* First token starts in the beginning of the chain */
  111|  42.6k|    tokens->tokens[0] = tokens->buffer;
  112|  42.6k|    c = tokens->buffer;
  113|       |
  114|   166k|    for (i = 1; i < num_tokens; i++) {
  ------------------
  |  Branch (114:17): [True: 123k, False: 42.6k]
  ------------------
  115|       |        /* Find next separator */
  116|   123k|        found = strchr(c, separator);
  117|   123k|        if (found == NULL) {
  ------------------
  |  Branch (117:13): [True: 0, False: 123k]
  ------------------
  118|      0|            break;
  119|      0|        }
  120|       |
  121|       |        /* Replace it with a string terminator */
  122|   123k|        *found = '\0';
  123|       |
  124|       |        /* The next token starts in the next byte */
  125|   123k|        c = found + 1;
  126|       |
  127|       |        /* If we did not reach the end of the chain yet, set the next token */
  128|   123k|        if (*c != '\0') {
  ------------------
  |  Branch (128:13): [True: 123k, False: 18.4E]
  ------------------
  129|   123k|            tokens->tokens[i] = c;
  130|  18.4E|        } else {
  131|  18.4E|            break;
  132|  18.4E|        }
  133|   123k|    }
  134|       |
  135|  42.6k|    return tokens;
  136|       |
  137|      0|error:
  138|      0|    ssh_tokens_free(tokens);
  139|       |    return NULL;
  140|  42.6k|}
ssh_find_matching:
  157|  14.2k|{
  158|  14.2k|    struct ssh_tokens_st *a_tok = NULL, *p_tok = NULL;
  159|       |
  160|  14.2k|    int i, j;
  161|  14.2k|    char *ret = NULL;
  162|       |
  163|  14.2k|    if ((available_list == NULL) || (preferred_list == NULL)) {
  ------------------
  |  Branch (163:9): [True: 18.4E, False: 14.2k]
  |  Branch (163:37): [True: 18.4E, False: 14.2k]
  ------------------
  164|      0|        return NULL;
  165|      0|    }
  166|       |
  167|  14.2k|    a_tok = ssh_tokenize(available_list, ',');
  168|  14.2k|    if (a_tok == NULL) {
  ------------------
  |  Branch (168:9): [True: 0, False: 14.2k]
  ------------------
  169|      0|        return NULL;
  170|      0|    }
  171|       |
  172|  14.2k|    p_tok = ssh_tokenize(preferred_list, ',');
  173|  14.2k|    if (p_tok == NULL) {
  ------------------
  |  Branch (173:9): [True: 0, False: 14.2k]
  ------------------
  174|      0|        goto out;
  175|      0|    }
  176|       |
  177|  15.5k|    for (i = 0; p_tok->tokens[i]; i++) {
  ------------------
  |  Branch (177:17): [True: 14.3k, False: 1.19k]
  ------------------
  178|  15.6k|        for (j = 0; a_tok->tokens[j]; j++) {
  ------------------
  |  Branch (178:21): [True: 14.3k, False: 1.27k]
  ------------------
  179|  14.3k|            if (strcmp(a_tok->tokens[j], p_tok->tokens[i]) == 0) {
  ------------------
  |  Branch (179:17): [True: 13.0k, False: 1.28k]
  ------------------
  180|  13.0k|                ret = strdup(a_tok->tokens[j]);
  181|  13.0k|                goto out;
  182|  13.0k|            }
  183|  14.3k|        }
  184|  14.3k|    }
  185|       |
  186|  14.2k|out:
  187|  14.2k|    ssh_tokens_free(a_tok);
  188|  14.2k|    ssh_tokens_free(p_tok);
  189|  14.2k|    return ret;
  190|  14.2k|}
ssh_find_all_matching:
  208|  7.21k|{
  209|  7.21k|    struct ssh_tokens_st *a_tok = NULL, *p_tok = NULL;
  210|  7.21k|    int i, j;
  211|  7.21k|    char *ret = NULL;
  212|  7.21k|    size_t max, len, pos = 0;
  213|  7.21k|    int match;
  214|       |
  215|  7.21k|    if ((available_list == NULL) || (preferred_list == NULL)) {
  ------------------
  |  Branch (215:9): [True: 0, False: 7.21k]
  |  Branch (215:37): [True: 0, False: 7.21k]
  ------------------
  216|      0|        return NULL;
  217|      0|    }
  218|       |
  219|  7.21k|    max = MAX(strlen(available_list), strlen(preferred_list));
  ------------------
  |  |  369|  7.21k|#define MAX(a,b) ((a) > (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (369:19): [True: 5.90k, False: 1.31k]
  |  |  ------------------
  ------------------
  220|       |
  221|  7.21k|    ret = calloc(1, max + 1);
  222|  7.21k|    if (ret == NULL) {
  ------------------
  |  Branch (222:9): [True: 0, False: 7.21k]
  ------------------
  223|      0|        return NULL;
  224|      0|    }
  225|       |
  226|  7.21k|    a_tok = ssh_tokenize(available_list, ',');
  227|  7.21k|    if (a_tok == NULL) {
  ------------------
  |  Branch (227:9): [True: 0, False: 7.21k]
  ------------------
  228|      0|        SAFE_FREE(ret);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  229|      0|        goto out;
  230|      0|    }
  231|       |
  232|  7.21k|    p_tok = ssh_tokenize(preferred_list, ',');
  233|  7.21k|    if (p_tok == NULL) {
  ------------------
  |  Branch (233:9): [True: 0, False: 7.21k]
  ------------------
  234|      0|        SAFE_FREE(ret);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  235|      0|        goto out;
  236|      0|    }
  237|       |
  238|  32.7k|    for (i = 0; p_tok->tokens[i] ; i++) {
  ------------------
  |  Branch (238:17): [True: 25.5k, False: 7.21k]
  ------------------
  239|   182k|        for (j = 0; a_tok->tokens[j]; j++) {
  ------------------
  |  Branch (239:21): [True: 156k, False: 25.5k]
  ------------------
  240|   156k|            match = !strcmp(a_tok->tokens[j], p_tok->tokens[i]);
  241|   156k|            if (match) {
  ------------------
  |  Branch (241:17): [True: 11.8k, False: 145k]
  ------------------
  242|  11.8k|                if (pos != 0) {
  ------------------
  |  Branch (242:21): [True: 4.59k, False: 7.22k]
  ------------------
  243|  4.59k|                    ret[pos] = ',';
  244|  4.59k|                    pos++;
  245|  4.59k|                }
  246|       |
  247|  11.8k|                len = strlen(a_tok->tokens[j]);
  248|  11.8k|                memcpy(&ret[pos], a_tok->tokens[j], len);
  249|  11.8k|                pos += len;
  250|  11.8k|                ret[pos] = '\0';
  251|  11.8k|            }
  252|   156k|        }
  253|  25.5k|    }
  254|       |
  255|  7.21k|    if (ret[0] == '\0') {
  ------------------
  |  Branch (255:9): [True: 0, False: 7.21k]
  ------------------
  256|      0|        SAFE_FREE(ret);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  257|      0|    }
  258|       |
  259|  7.22k|out:
  260|  7.22k|    ssh_tokens_free(a_tok);
  261|  7.22k|    ssh_tokens_free(p_tok);
  262|  7.22k|    return ret;
  263|  7.21k|}

ssh_get_hmactab:
   74|  1.31k|struct ssh_hmac_struct *ssh_get_hmactab(void) {
   75|  1.31k|  return ssh_hmac_tab;
   76|  1.31k|}
hmac_digest_len:
   78|  40.0k|size_t hmac_digest_len(enum ssh_hmac_e type) {
   79|  40.0k|  switch(type) {
   80|  25.7k|    case SSH_HMAC_SHA1:
  ------------------
  |  Branch (80:5): [True: 25.7k, False: 14.2k]
  ------------------
   81|  25.7k|      return SHA_DIGEST_LEN;
  ------------------
  |  |   44|  25.7k|#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
  ------------------
   82|  7.87k|    case SSH_HMAC_SHA256:
  ------------------
  |  Branch (82:5): [True: 7.87k, False: 32.1k]
  ------------------
   83|  7.87k|      return SHA256_DIGEST_LEN;
  ------------------
  |  |   45|  7.87k|#define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
  ------------------
   84|      0|    case SSH_HMAC_SHA512:
  ------------------
  |  Branch (84:5): [True: 0, False: 40.0k]
  ------------------
   85|      0|      return SHA512_DIGEST_LEN;
  ------------------
  |  |   47|      0|#define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH
  ------------------
   86|      0|    case SSH_HMAC_MD5:
  ------------------
  |  Branch (86:5): [True: 0, False: 40.0k]
  ------------------
   87|      0|      return MD5_DIGEST_LEN;
  ------------------
  |  |   51|      0|#define MD5_DIGEST_LEN MD5_DIGEST_LENGTH
  ------------------
   88|      0|    case SSH_HMAC_AEAD_POLY1305:
  ------------------
  |  Branch (88:5): [True: 0, False: 40.0k]
  ------------------
   89|      0|      return POLY1305_TAGLEN;
  ------------------
  |  |   37|      0|#define POLY1305_TAGLEN 16
  ------------------
   90|      0|    case SSH_HMAC_AEAD_GCM:
  ------------------
  |  Branch (90:5): [True: 0, False: 40.0k]
  ------------------
   91|      0|      return AES_GCM_TAGLEN;
  ------------------
  |  |   58|      0|#define AES_GCM_TAGLEN 16
  ------------------
   92|  6.37k|    default:
  ------------------
  |  Branch (92:5): [True: 6.37k, False: 33.6k]
  ------------------
   93|  6.37k|      return 0;
   94|  40.0k|  }
   95|  40.0k|}
ssh_cipher_clear:
  124|  7.88k|void ssh_cipher_clear(struct ssh_cipher_struct *cipher){
  125|       |#ifdef HAVE_LIBGCRYPT
  126|       |    unsigned int i;
  127|       |#endif
  128|       |
  129|  7.88k|    if (cipher == NULL) {
  ------------------
  |  Branch (129:9): [True: 5.25k, False: 2.62k]
  ------------------
  130|  5.25k|        return;
  131|  5.25k|    }
  132|       |
  133|       |#ifdef HAVE_LIBGCRYPT
  134|       |    if (cipher->key) {
  135|       |        for (i = 0; i < (cipher->keylen / sizeof(gcry_cipher_hd_t)); i++) {
  136|       |            gcry_cipher_close(cipher->key[i]);
  137|       |        }
  138|       |        SAFE_FREE(cipher->key);
  139|       |    }
  140|       |#endif
  141|       |
  142|  2.62k|    if (cipher->cleanup != NULL) {
  ------------------
  |  Branch (142:9): [True: 2.26k, False: 364]
  ------------------
  143|  2.26k|        cipher->cleanup(cipher);
  144|  2.26k|    }
  145|  2.62k|}
crypto_new:
  153|  3.94k|{
  154|  3.94k|    struct ssh_crypto_struct *crypto = NULL;
  155|       |
  156|  3.94k|    crypto = calloc(1, sizeof(struct ssh_crypto_struct));
  157|  3.94k|    if (crypto == NULL) {
  ------------------
  |  Branch (157:9): [True: 0, False: 3.94k]
  ------------------
  158|      0|        return NULL;
  159|      0|    }
  160|  3.94k|    return crypto;
  161|  3.94k|}
crypto_free:
  164|  5.25k|{
  165|  5.25k|    size_t i;
  166|       |
  167|  5.25k|    if (crypto == NULL) {
  ------------------
  |  Branch (167:9): [True: 1.31k, False: 3.94k]
  ------------------
  168|  1.31k|        return;
  169|  1.31k|    }
  170|       |
  171|  3.94k|    ssh_key_free(crypto->server_pubkey);
  172|       |
  173|  3.94k|    ssh_dh_cleanup(crypto);
  174|  3.94k|    bignum_safe_free(crypto->shared_secret);
  ------------------
  |  |   71|  3.94k|#define bignum_safe_free(num) do { \
  |  |   72|  3.94k|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 3.94k]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|  3.94k|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 3.94k]
  |  |  ------------------
  ------------------
  175|  3.94k|#ifdef HAVE_ECDH
  176|  3.94k|    SAFE_FREE(crypto->ecdh_client_pubkey);
  ------------------
  |  |  373|  3.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 3.94k]
  |  |  |  Branch (373:71): [Folded, False: 3.94k]
  |  |  ------------------
  ------------------
  177|  3.94k|    SAFE_FREE(crypto->ecdh_server_pubkey);
  ------------------
  |  |  373|  3.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 3.94k]
  |  |  |  Branch (373:71): [Folded, False: 3.94k]
  |  |  ------------------
  ------------------
  178|  3.94k|    if (crypto->ecdh_privkey != NULL) {
  ------------------
  |  Branch (178:9): [True: 0, False: 3.94k]
  ------------------
  179|      0|#ifdef HAVE_OPENSSL_ECC
  180|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  181|      0|        EC_KEY_free(crypto->ecdh_privkey);
  182|       |#else
  183|       |        EVP_PKEY_free(crypto->ecdh_privkey);
  184|       |#endif /* OPENSSL_VERSION_NUMBER */
  185|       |#elif defined HAVE_GCRYPT_ECC
  186|       |        gcry_sexp_release(crypto->ecdh_privkey);
  187|       |#elif defined HAVE_LIBMBEDCRYPTO
  188|       |        mbedtls_ecp_keypair_free(crypto->ecdh_privkey);
  189|       |        SAFE_FREE(crypto->ecdh_privkey);
  190|       |#endif /* HAVE_LIBGCRYPT */
  191|      0|        crypto->ecdh_privkey = NULL;
  192|      0|    }
  193|  3.94k|#endif
  194|  3.94k|#ifdef HAVE_LIBCRYPTO
  195|  3.94k|    EVP_PKEY_free(crypto->curve25519_privkey);
  196|       |#elif defined(HAVE_GCRYPT_CURVE25519)
  197|       |    gcry_sexp_release(crypto->curve25519_privkey);
  198|       |#endif
  199|  3.94k|    SAFE_FREE(crypto->dh_server_signature);
  ------------------
  |  |  373|  3.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 3.94k]
  |  |  |  Branch (373:71): [Folded, False: 3.94k]
  |  |  ------------------
  ------------------
  200|  3.94k|    if (crypto->session_id != NULL) {
  ------------------
  |  Branch (200:9): [True: 2.62k, False: 1.31k]
  ------------------
  201|  2.62k|        ssh_burn(crypto->session_id, crypto->session_id_len);
  ------------------
  |  |  388|  2.62k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  202|  2.62k|        SAFE_FREE(crypto->session_id);
  ------------------
  |  |  373|  2.62k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.62k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.62k]
  |  |  ------------------
  ------------------
  203|  2.62k|    }
  204|  3.94k|    if (crypto->secret_hash != NULL) {
  ------------------
  |  Branch (204:9): [True: 1.31k, False: 2.62k]
  ------------------
  205|  1.31k|        ssh_burn(crypto->secret_hash, crypto->digest_len);
  ------------------
  |  |  388|  1.31k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  206|  1.31k|        SAFE_FREE(crypto->secret_hash);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  207|  1.31k|    }
  208|  3.94k|    compress_cleanup(crypto);
  209|  3.94k|    SAFE_FREE(crypto->encryptIV);
  ------------------
  |  |  373|  3.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 2.62k]
  |  |  |  Branch (373:71): [Folded, False: 3.94k]
  |  |  ------------------
  ------------------
  210|  3.94k|    SAFE_FREE(crypto->decryptIV);
  ------------------
  |  |  373|  3.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 2.62k]
  |  |  |  Branch (373:71): [Folded, False: 3.94k]
  |  |  ------------------
  ------------------
  211|  3.94k|    SAFE_FREE(crypto->encryptMAC);
  ------------------
  |  |  373|  3.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 2.62k]
  |  |  |  Branch (373:71): [Folded, False: 3.94k]
  |  |  ------------------
  ------------------
  212|  3.94k|    SAFE_FREE(crypto->decryptMAC);
  ------------------
  |  |  373|  3.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 2.62k]
  |  |  |  Branch (373:71): [Folded, False: 3.94k]
  |  |  ------------------
  ------------------
  213|  3.94k|    if (crypto->encryptkey != NULL) {
  ------------------
  |  Branch (213:9): [True: 1.31k, False: 2.62k]
  ------------------
  214|  1.31k|        ssh_burn(crypto->encryptkey, crypto->out_cipher->keysize / 8);
  ------------------
  |  |  388|  1.31k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  215|  1.31k|        SAFE_FREE(crypto->encryptkey);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  216|  1.31k|    }
  217|  3.94k|    if (crypto->decryptkey != NULL) {
  ------------------
  |  Branch (217:9): [True: 1.31k, False: 2.62k]
  ------------------
  218|  1.31k|        ssh_burn(crypto->decryptkey, crypto->in_cipher->keysize / 8);
  ------------------
  |  |  388|  1.31k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  219|  1.31k|        SAFE_FREE(crypto->decryptkey);
  ------------------
  |  |  373|  1.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.31k]
  |  |  ------------------
  ------------------
  220|  1.31k|    }
  221|       |
  222|  3.94k|    cipher_free(crypto->in_cipher);
  223|  3.94k|    cipher_free(crypto->out_cipher);
  224|       |
  225|  43.3k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  43.3k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (225:17): [True: 39.4k, False: 3.94k]
  ------------------
  226|  39.4k|        SAFE_FREE(crypto->client_kex.methods[i]);
  ------------------
  |  |  373|  39.4k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 13.1k, False: 26.2k]
  |  |  |  Branch (373:71): [Folded, False: 39.4k]
  |  |  ------------------
  ------------------
  227|  39.4k|        SAFE_FREE(crypto->server_kex.methods[i]);
  ------------------
  |  |  373|  39.4k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 13.1k, False: 26.2k]
  |  |  |  Branch (373:71): [Folded, False: 39.4k]
  |  |  ------------------
  ------------------
  228|  39.4k|        SAFE_FREE(crypto->kex_methods[i]);
  ------------------
  |  |  373|  39.4k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 13.1k, False: 26.2k]
  |  |  |  Branch (373:71): [Folded, False: 39.4k]
  |  |  ------------------
  ------------------
  229|  39.4k|    }
  230|       |
  231|       |#ifdef HAVE_OPENSSL_MLKEM
  232|       |    EVP_PKEY_free(crypto->mlkem_privkey);
  233|       |#else
  234|  3.94k|    if (crypto->mlkem_privkey != NULL) {
  ------------------
  |  Branch (234:9): [True: 657, False: 3.28k]
  ------------------
  235|    657|        ssh_burn(crypto->mlkem_privkey, crypto->mlkem_privkey_len);
  ------------------
  |  |  388|    657|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  236|    657|        SAFE_FREE(crypto->mlkem_privkey);
  ------------------
  |  |  373|    657|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 657, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 657]
  |  |  ------------------
  ------------------
  237|    657|        crypto->mlkem_privkey_len = 0;
  238|    657|    }
  239|  3.94k|#endif
  240|  3.94k|    ssh_string_burn(crypto->hybrid_shared_secret);
  241|  3.94k|    ssh_string_free(crypto->mlkem_client_pubkey);
  242|  3.94k|    ssh_string_free(crypto->mlkem_ciphertext);
  243|  3.94k|    ssh_string_free(crypto->hybrid_client_init);
  244|  3.94k|    ssh_string_free(crypto->hybrid_server_reply);
  245|  3.94k|    ssh_string_free(crypto->hybrid_shared_secret);
  246|       |
  247|  3.94k|    ssh_burn(crypto, sizeof(struct ssh_crypto_struct));
  ------------------
  |  |  388|  3.94k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  248|       |
  249|       |    SAFE_FREE(crypto);
  ------------------
  |  |  373|  3.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 3.94k, False: 18.4E]
  |  |  |  Branch (373:71): [Folded, False: 3.94k]
  |  |  ------------------
  ------------------
  250|  3.94k|}
crypt_set_algorithms_client:
  429|    657|{
  430|    657|    return crypt_set_algorithms2(session);
  431|    657|}
crypt_set_algorithms_server:
  434|    657|int crypt_set_algorithms_server(ssh_session session){
  435|    657|    const char *method = NULL;
  436|    657|    uint8_t i = 0;
  437|    657|    struct ssh_cipher_struct *ssh_ciphertab=ssh_get_ciphertab();
  438|    657|    struct ssh_hmac_struct   *ssh_hmactab=ssh_get_hmactab();
  439|    657|    int cmp;
  440|    657|    int rc;
  441|       |
  442|    657|    if (session == NULL) {
  ------------------
  |  Branch (442:9): [True: 0, False: 657]
  ------------------
  443|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  444|      0|    }
  445|       |
  446|       |    /*
  447|       |     * We must scan the kex entries to find crypto algorithms and set their
  448|       |     * appropriate structure
  449|       |     */
  450|       |    /* out */
  451|    657|    method = session->next_crypto->kex_methods[SSH_CRYPT_S_C];
  452|       |
  453|  3.06k|    for (i = 0; ssh_ciphertab[i].name != NULL; i++) {
  ------------------
  |  Branch (453:17): [True: 3.06k, False: 0]
  ------------------
  454|  3.06k|        cmp = strcmp(method, ssh_ciphertab[i].name);
  455|  3.06k|        if (cmp == 0) {
  ------------------
  |  Branch (455:13): [True: 657, False: 2.41k]
  ------------------
  456|    657|          break;
  457|    657|        }
  458|  3.06k|    }
  459|       |
  460|    657|    if (ssh_ciphertab[i].name == NULL) {
  ------------------
  |  Branch (460:9): [True: 0, False: 657]
  ------------------
  461|      0|        ssh_set_error(session,SSH_FATAL,"crypt_set_algorithms_server : "
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  462|      0|                "no crypto algorithm function found for %s",method);
  463|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  464|      0|    }
  465|    657|    SSH_LOG(SSH_LOG_PACKET,"Set output algorithm %s",method);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  466|       |
  467|    657|    session->next_crypto->out_cipher = cipher_new(i);
  468|    657|    if (session->next_crypto->out_cipher == NULL) {
  ------------------
  |  Branch (468:9): [True: 0, False: 657]
  ------------------
  469|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  470|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  471|      0|    }
  472|       |
  473|    657|    if (session->next_crypto->out_cipher->aead_encrypt != NULL){
  ------------------
  |  Branch (473:9): [True: 0, False: 657]
  ------------------
  474|       |        /* this cipher has integrated MAC */
  475|      0|        if (session->next_crypto->out_cipher->ciphertype == SSH_AEAD_CHACHA20_POLY1305) {
  ------------------
  |  Branch (475:13): [True: 0, False: 0]
  ------------------
  476|      0|            method = "aead-poly1305";
  477|      0|        } else {
  478|      0|            method = "aead-gcm";
  479|      0|        }
  480|    657|    } else {
  481|       |        /* we must scan the kex entries to find hmac algorithms and set their appropriate structure */
  482|       |        /* out */
  483|    657|        method = session->next_crypto->kex_methods[SSH_MAC_S_C];
  484|    657|    }
  485|       |    /* HMAC algorithm selection */
  486|       |
  487|  2.30k|    for (i = 0; ssh_hmactab[i].name != NULL; i++) {
  ------------------
  |  Branch (487:17): [True: 2.30k, False: 0]
  ------------------
  488|  2.30k|        cmp = strcmp(method, ssh_hmactab[i].name);
  489|  2.30k|        if (cmp == 0) {
  ------------------
  |  Branch (489:13): [True: 657, False: 1.64k]
  ------------------
  490|    657|            break;
  491|    657|        }
  492|  2.30k|    }
  493|       |
  494|    657|    if (ssh_hmactab[i].name == NULL) {
  ------------------
  |  Branch (494:9): [True: 0, False: 657]
  ------------------
  495|      0|      ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  496|      0|          "crypt_set_algorithms_server: no hmac algorithm function found for %s",
  497|      0|          method);
  498|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  499|      0|    }
  500|    657|    SSH_LOG(SSH_LOG_PACKET, "Set HMAC output algorithm to %s", method);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  501|       |
  502|    657|    session->next_crypto->out_hmac = ssh_hmactab[i].hmac_type;
  503|    657|    session->next_crypto->out_hmac_etm = ssh_hmactab[i].etm;
  504|       |
  505|       |    /* in */
  506|    657|    method = session->next_crypto->kex_methods[SSH_CRYPT_C_S];
  507|       |
  508|  3.06k|    for (i = 0; ssh_ciphertab[i].name; i++) {
  ------------------
  |  Branch (508:17): [True: 3.06k, False: 0]
  ------------------
  509|  3.06k|        cmp = strcmp(method, ssh_ciphertab[i].name);
  510|  3.06k|        if (cmp == 0) {
  ------------------
  |  Branch (510:13): [True: 657, False: 2.41k]
  ------------------
  511|    657|            break;
  512|    657|        }
  513|  3.06k|    }
  514|       |
  515|    657|    if (ssh_ciphertab[i].name == NULL) {
  ------------------
  |  Branch (515:9): [True: 0, False: 657]
  ------------------
  516|      0|        ssh_set_error(session,SSH_FATAL,"Crypt_set_algorithms_server :"
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  517|      0|                "no crypto algorithm function found for %s",method);
  518|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  519|      0|    }
  520|    657|    SSH_LOG(SSH_LOG_PACKET,"Set input algorithm %s",method);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  521|       |
  522|    657|    session->next_crypto->in_cipher = cipher_new(i);
  523|    657|    if (session->next_crypto->in_cipher == NULL) {
  ------------------
  |  Branch (523:9): [True: 0, False: 657]
  ------------------
  524|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  525|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  526|      0|    }
  527|       |
  528|    657|    if (session->next_crypto->in_cipher->aead_encrypt != NULL){
  ------------------
  |  Branch (528:9): [True: 0, False: 657]
  ------------------
  529|       |        /* this cipher has integrated MAC */
  530|      0|        if (session->next_crypto->in_cipher->ciphertype == SSH_AEAD_CHACHA20_POLY1305) {
  ------------------
  |  Branch (530:13): [True: 0, False: 0]
  ------------------
  531|      0|            method = "aead-poly1305";
  532|      0|        } else {
  533|      0|            method = "aead-gcm";
  534|      0|        }
  535|    657|    } else {
  536|       |        /* we must scan the kex entries to find hmac algorithms and set their appropriate structure */
  537|    657|        method = session->next_crypto->kex_methods[SSH_MAC_C_S];
  538|    657|    }
  539|       |
  540|  2.30k|    for (i = 0; ssh_hmactab[i].name != NULL; i++) {
  ------------------
  |  Branch (540:17): [True: 2.30k, False: 0]
  ------------------
  541|  2.30k|        cmp = strcmp(method, ssh_hmactab[i].name);
  542|  2.30k|        if (cmp == 0) {
  ------------------
  |  Branch (542:13): [True: 657, False: 1.64k]
  ------------------
  543|    657|            break;
  544|    657|        }
  545|  2.30k|    }
  546|       |
  547|    657|    if (ssh_hmactab[i].name == NULL) {
  ------------------
  |  Branch (547:9): [True: 0, False: 657]
  ------------------
  548|      0|      ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  549|      0|          "crypt_set_algorithms_server: no hmac algorithm function found for %s",
  550|      0|          method);
  551|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  552|      0|    }
  553|    657|    SSH_LOG(SSH_LOG_PACKET, "Set HMAC input algorithm to %s", method);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  554|       |
  555|    657|    session->next_crypto->in_hmac = ssh_hmactab[i].hmac_type;
  556|    657|    session->next_crypto->in_hmac_etm = ssh_hmactab[i].etm;
  557|       |
  558|       |    /* compression */
  559|    657|    method = session->next_crypto->kex_methods[SSH_COMP_C_S];
  560|    657|    cmp = strcmp(method, "zlib");
  561|    657|    if (cmp == 0) {
  ------------------
  |  Branch (561:9): [True: 0, False: 657]
  ------------------
  562|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling C->S compression");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  563|      0|        compression_enable(session, SSH_DIRECTION_IN, false);
  564|      0|    }
  565|    657|    cmp = strcmp(method, "zlib@openssh.com");
  566|    657|    if (cmp == 0) {
  ------------------
  |  Branch (566:9): [True: 0, False: 657]
  ------------------
  567|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling C->S delayed compression");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  568|      0|        compression_enable(session, SSH_DIRECTION_IN, true);
  569|      0|    }
  570|       |
  571|    657|    method = session->next_crypto->kex_methods[SSH_COMP_S_C];
  572|    657|    cmp = strcmp(method, "zlib");
  573|    657|    if (cmp == 0) {
  ------------------
  |  Branch (573:9): [True: 0, False: 657]
  ------------------
  574|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling S->C compression");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  575|      0|        compression_enable(session, SSH_DIRECTION_OUT, false);
  576|      0|    }
  577|    657|    cmp = strcmp(method, "zlib@openssh.com");
  578|    657|    if (cmp == 0) {
  ------------------
  |  Branch (578:9): [True: 0, False: 657]
  ------------------
  579|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling S->C delayed compression");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  580|      0|        compression_enable(session, SSH_DIRECTION_OUT, true);
  581|      0|    }
  582|       |
  583|    657|    method = session->next_crypto->kex_methods[SSH_HOSTKEYS];
  584|       |
  585|       |    /* For GSSAPI key exchange, hostkey algorithm may be "null" */
  586|    657|    if (strcmp(method, "null") == 0) {
  ------------------
  |  Branch (586:9): [True: 0, False: 657]
  ------------------
  587|      0|        session->srv.hostkey = SSH_KEYTYPE_UNKNOWN;
  588|      0|        session->srv.hostkey_digest = SSH_DIGEST_AUTO;
  589|    657|    } else {
  590|    657|        rc = ssh_key_type_and_hash_from_signature_name(
  591|    657|            method,
  592|    657|            &session->srv.hostkey,
  593|    657|            &session->srv.hostkey_digest);
  594|    657|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (594:13): [True: 0, False: 657]
  ------------------
  595|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  596|      0|                          SSH_FATAL,
  597|      0|                          "unknown hostkey algorithm %s",
  598|      0|                          method);
  599|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  600|      0|        }
  601|    657|    }
  602|       |
  603|       |    /* setup DH key exchange type */
  604|    657|    switch (session->next_crypto->kex_type) {
  605|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (605:5): [True: 0, False: 657]
  ------------------
  606|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (606:5): [True: 0, False: 657]
  ------------------
  607|      0|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (607:5): [True: 0, False: 657]
  ------------------
  608|      0|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (608:5): [True: 0, False: 657]
  ------------------
  609|      0|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (609:5): [True: 0, False: 657]
  ------------------
  610|      0|      ssh_server_dh_init(session);
  611|      0|      break;
  612|       |#ifdef WITH_GSSAPI
  613|       |    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  614|       |    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  615|       |    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  616|       |    case SSH_GSS_KEX_CURVE25519_SHA256:
  617|       |        ssh_server_gss_kex_init(session);
  618|       |        break;
  619|       |#endif /* WITH_GSSAPI */
  620|      0|#ifdef WITH_GEX
  621|      0|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (621:5): [True: 0, False: 657]
  ------------------
  622|      0|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (622:5): [True: 0, False: 657]
  ------------------
  623|      0|      ssh_server_dhgex_init(session);
  624|      0|      break;
  625|      0|#endif /* WITH_GEX */
  626|      0|#ifdef HAVE_ECDH
  627|      0|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (627:5): [True: 0, False: 657]
  ------------------
  628|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (628:5): [True: 0, False: 657]
  ------------------
  629|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (629:5): [True: 0, False: 657]
  ------------------
  630|      0|      ssh_server_ecdh_init(session);
  631|      0|      break;
  632|      0|#endif
  633|      0|#ifdef HAVE_CURVE25519
  634|      0|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (634:5): [True: 0, False: 657]
  ------------------
  635|      0|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (635:5): [True: 0, False: 657]
  ------------------
  636|      0|        ssh_server_curve25519_init(session);
  637|      0|        break;
  638|      0|#endif
  639|      0|#ifdef HAVE_SNTRUP761
  640|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (640:5): [True: 0, False: 657]
  ------------------
  641|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (641:5): [True: 0, False: 657]
  ------------------
  642|      0|        ssh_server_sntrup761x25519_init(session);
  643|      0|        break;
  644|      0|#endif
  645|    657|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (645:5): [True: 657, False: 0]
  ------------------
  646|    657|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (646:5): [True: 0, False: 657]
  ------------------
  647|       |#ifdef HAVE_MLKEM1024
  648|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  649|       |#endif
  650|    657|        ssh_server_hybrid_mlkem_init(session);
  651|    657|        break;
  652|      0|    default:
  ------------------
  |  Branch (652:5): [True: 0, False: 657]
  ------------------
  653|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  654|      0|                      SSH_FATAL,
  655|      0|                      "crypt_set_algorithms_server: could not find init "
  656|      0|                      "handler for kex type %d",
  657|      0|                      session->next_crypto->kex_type);
  658|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  659|    657|    }
  660|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  661|    657|}
wrapper.c:cipher_free:
  147|  7.88k|static void cipher_free(struct ssh_cipher_struct *cipher) {
  148|  7.88k|  ssh_cipher_clear(cipher);
  149|       |  SAFE_FREE(cipher);
  ------------------
  |  |  373|  7.88k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.62k, False: 5.25k]
  |  |  |  Branch (373:71): [Folded, False: 7.88k]
  |  |  ------------------
  ------------------
  150|  7.88k|}
wrapper.c:crypt_set_algorithms2:
  275|    657|{
  276|    657|    const char *wanted = NULL;
  277|    657|    const char *method = NULL;
  278|    657|    struct ssh_cipher_struct *ssh_ciphertab=ssh_get_ciphertab();
  279|    657|    struct ssh_hmac_struct *ssh_hmactab=ssh_get_hmactab();
  280|    657|    uint8_t i = 0;
  281|    657|    int cmp;
  282|       |
  283|       |    /*
  284|       |     * We must scan the kex entries to find crypto algorithms and set their
  285|       |     * appropriate structure.
  286|       |     */
  287|       |
  288|       |    /* out */
  289|    657|    wanted = session->next_crypto->kex_methods[SSH_CRYPT_C_S];
  290|  3.06k|    for (i = 0; i < 64 && ssh_ciphertab[i].name != NULL; ++i) {
  ------------------
  |  Branch (290:17): [True: 3.06k, False: 0]
  |  Branch (290:27): [True: 3.06k, False: 0]
  ------------------
  291|  3.06k|        cmp = strcmp(wanted, ssh_ciphertab[i].name);
  292|  3.06k|        if (cmp == 0) {
  ------------------
  |  Branch (292:13): [True: 657, False: 2.41k]
  ------------------
  293|    657|            break;
  294|    657|        }
  295|  3.06k|    }
  296|       |
  297|    657|    if (ssh_ciphertab[i].name == NULL) {
  ------------------
  |  Branch (297:9): [True: 0, False: 657]
  ------------------
  298|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  299|      0|                "crypt_set_algorithms2: no crypto algorithm function found for %s",
  300|      0|                wanted);
  301|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  302|      0|    }
  303|    657|    SSH_LOG(SSH_LOG_PACKET, "Set output algorithm to %s", wanted);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  304|       |
  305|    657|    session->next_crypto->out_cipher = cipher_new(i);
  306|    657|    if (session->next_crypto->out_cipher == NULL) {
  ------------------
  |  Branch (306:9): [True: 0, False: 657]
  ------------------
  307|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  308|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  309|      0|    }
  310|       |
  311|    657|    if (session->next_crypto->out_cipher->aead_encrypt != NULL) {
  ------------------
  |  Branch (311:9): [True: 0, False: 657]
  ------------------
  312|       |        /* this cipher has integrated MAC */
  313|      0|        if (session->next_crypto->out_cipher->ciphertype == SSH_AEAD_CHACHA20_POLY1305) {
  ------------------
  |  Branch (313:13): [True: 0, False: 0]
  ------------------
  314|      0|            wanted = "aead-poly1305";
  315|      0|        } else {
  316|      0|            wanted = "aead-gcm";
  317|      0|        }
  318|    657|    } else {
  319|       |        /*
  320|       |         * We must scan the kex entries to find hmac algorithms and set their
  321|       |         * appropriate structure.
  322|       |         */
  323|       |
  324|       |        /* out */
  325|    657|        wanted = session->next_crypto->kex_methods[SSH_MAC_C_S];
  326|    657|    }
  327|       |
  328|  2.30k|    for (i = 0; ssh_hmactab[i].name != NULL; i++) {
  ------------------
  |  Branch (328:17): [True: 2.30k, False: 0]
  ------------------
  329|  2.30k|        cmp = strcmp(wanted, ssh_hmactab[i].name);
  330|  2.30k|        if (cmp == 0) {
  ------------------
  |  Branch (330:13): [True: 657, False: 1.64k]
  ------------------
  331|    657|            break;
  332|    657|        }
  333|  2.30k|    }
  334|       |
  335|    657|    if (ssh_hmactab[i].name == NULL) {
  ------------------
  |  Branch (335:9): [True: 0, False: 657]
  ------------------
  336|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  337|      0|                "crypt_set_algorithms2: no hmac algorithm function found for %s",
  338|      0|                wanted);
  339|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  340|      0|    }
  341|    657|    SSH_LOG(SSH_LOG_PACKET, "Set HMAC output algorithm to %s", wanted);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  342|       |
  343|    657|    session->next_crypto->out_hmac = ssh_hmactab[i].hmac_type;
  344|    657|    session->next_crypto->out_hmac_etm = ssh_hmactab[i].etm;
  345|       |
  346|       |    /* in */
  347|    657|    wanted = session->next_crypto->kex_methods[SSH_CRYPT_S_C];
  348|       |
  349|  3.06k|    for (i = 0; ssh_ciphertab[i].name != NULL; i++) {
  ------------------
  |  Branch (349:17): [True: 3.06k, False: 0]
  ------------------
  350|  3.06k|        cmp = strcmp(wanted, ssh_ciphertab[i].name);
  351|  3.06k|        if (cmp == 0) {
  ------------------
  |  Branch (351:13): [True: 657, False: 2.41k]
  ------------------
  352|    657|            break;
  353|    657|        }
  354|  3.06k|    }
  355|       |
  356|    657|    if (ssh_ciphertab[i].name == NULL) {
  ------------------
  |  Branch (356:9): [True: 0, False: 657]
  ------------------
  357|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  358|      0|                "Crypt_set_algorithms: no crypto algorithm function found for %s",
  359|      0|                wanted);
  360|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  361|      0|    }
  362|    657|    SSH_LOG(SSH_LOG_PACKET, "Set input algorithm to %s", wanted);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  363|       |
  364|    657|    session->next_crypto->in_cipher = cipher_new(i);
  365|    657|    if (session->next_crypto->in_cipher == NULL) {
  ------------------
  |  Branch (365:9): [True: 0, False: 657]
  ------------------
  366|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  367|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  368|      0|    }
  369|       |
  370|    657|    if (session->next_crypto->in_cipher->aead_encrypt != NULL){
  ------------------
  |  Branch (370:9): [True: 0, False: 657]
  ------------------
  371|       |        /* this cipher has integrated MAC */
  372|      0|        if (session->next_crypto->in_cipher->ciphertype == SSH_AEAD_CHACHA20_POLY1305) {
  ------------------
  |  Branch (372:13): [True: 0, False: 0]
  ------------------
  373|      0|            wanted = "aead-poly1305";
  374|      0|        } else {
  375|      0|            wanted = "aead-gcm";
  376|      0|        }
  377|    657|    } else {
  378|       |        /* we must scan the kex entries to find hmac algorithms and set their appropriate structure */
  379|    657|        wanted = session->next_crypto->kex_methods[SSH_MAC_S_C];
  380|    657|    }
  381|       |
  382|  2.30k|    for (i = 0; ssh_hmactab[i].name != NULL; i++) {
  ------------------
  |  Branch (382:17): [True: 2.30k, False: 0]
  ------------------
  383|  2.30k|        cmp = strcmp(wanted, ssh_hmactab[i].name);
  384|  2.30k|        if (cmp == 0) {
  ------------------
  |  Branch (384:13): [True: 657, False: 1.64k]
  ------------------
  385|    657|            break;
  386|    657|        }
  387|  2.30k|    }
  388|       |
  389|    657|    if (ssh_hmactab[i].name == NULL) {
  ------------------
  |  Branch (389:9): [True: 0, False: 657]
  ------------------
  390|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  391|      0|                "crypt_set_algorithms2: no hmac algorithm function found for %s",
  392|      0|                wanted);
  393|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  394|      0|    }
  395|    657|    SSH_LOG(SSH_LOG_PACKET, "Set HMAC input algorithm to %s", wanted);
  ------------------
  |  |  281|    657|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  396|       |
  397|    657|    session->next_crypto->in_hmac = ssh_hmactab[i].hmac_type;
  398|    657|    session->next_crypto->in_hmac_etm = ssh_hmactab[i].etm;
  399|       |
  400|       |    /* compression: client */
  401|    657|    method = session->next_crypto->kex_methods[SSH_COMP_C_S];
  402|    657|    cmp = strcmp(method, "zlib");
  403|    657|    if (cmp == 0) {
  ------------------
  |  Branch (403:9): [True: 0, False: 657]
  ------------------
  404|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling C->S compression");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  405|      0|        compression_enable(session, SSH_DIRECTION_OUT, false);
  406|      0|    }
  407|    657|    cmp = strcmp(method, "zlib@openssh.com");
  408|    657|    if (cmp == 0) {
  ------------------
  |  Branch (408:9): [True: 0, False: 657]
  ------------------
  409|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling C->S delayed compression");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  410|      0|        compression_enable(session, SSH_DIRECTION_OUT, true);
  411|      0|    }
  412|       |
  413|    657|    method = session->next_crypto->kex_methods[SSH_COMP_S_C];
  414|    657|    cmp = strcmp(method, "zlib");
  415|    657|    if (cmp == 0) {
  ------------------
  |  Branch (415:9): [True: 0, False: 657]
  ------------------
  416|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling S->C compression");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  417|      0|        compression_enable(session, SSH_DIRECTION_IN, false);
  418|      0|    }
  419|    657|    cmp = strcmp(method, "zlib@openssh.com");
  420|    657|    if (cmp == 0) {
  ------------------
  |  Branch (420:9): [True: 0, False: 657]
  ------------------
  421|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling S->C delayed compression");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  422|      0|        compression_enable(session, SSH_DIRECTION_IN, true);
  423|      0|    }
  424|       |
  425|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  426|    657|}
wrapper.c:cipher_new:
  110|  2.62k|static struct ssh_cipher_struct *cipher_new(uint8_t offset) {
  111|  2.62k|  struct ssh_cipher_struct *cipher = NULL;
  112|       |
  113|  2.62k|  cipher = malloc(sizeof(struct ssh_cipher_struct));
  114|  2.62k|  if (cipher == NULL) {
  ------------------
  |  Branch (114:7): [True: 0, False: 2.62k]
  ------------------
  115|      0|    return NULL;
  116|      0|  }
  117|       |
  118|       |  /* note the memcpy will copy the pointers : so, you shouldn't free them */
  119|  2.62k|  memcpy(cipher, &ssh_get_ciphertab()[offset], sizeof(*cipher));
  120|       |
  121|  2.62k|  return cipher;
  122|  2.62k|}

nalloc_init:
  114|      2|{
  115|      2|    if (nalloc_initialized) {
  ------------------
  |  Branch (115:9): [True: 0, False: 2]
  ------------------
  116|      0|        return;
  117|      0|    }
  118|      2|    nalloc_initialized = true;
  119|      2|    char *bitmask = getenv("NALLOC_FREQ");
  120|      2|    if (bitmask) {
  ------------------
  |  Branch (120:9): [True: 0, False: 2]
  ------------------
  121|      0|        int shift = atoi(bitmask);
  122|      0|        if (shift > 0 && shift < 31) {
  ------------------
  |  Branch (122:13): [True: 0, False: 0]
  |  Branch (122:26): [True: 0, False: 0]
  ------------------
  123|      0|            nalloc_bitmask = 1 << shift;
  124|      0|            nalloc_random_bitmask = false;
  125|      0|        } else if (shift == 0) {
  ------------------
  |  Branch (125:20): [True: 0, False: 0]
  ------------------
  126|      0|            nalloc_random_bitmask = false;
  127|      0|            nalloc_bitmask = 0;
  128|      0|        }
  129|      2|    } else if (prog == NULL || strstr(prog, "nalloc") == NULL) {
  ------------------
  |  Branch (129:16): [True: 0, False: 2]
  |  Branch (129:32): [True: 2, False: 0]
  ------------------
  130|      2|        nalloc_random_bitmask = false;
  131|      2|        nalloc_bitmask = 0;
  132|      2|        return;
  133|      2|    }
  134|       |
  135|      0|    char *verbose = getenv("NALLOC_VERBOSE");
  136|      0|    if (verbose) {
  ------------------
  |  Branch (136:9): [True: 0, False: 0]
  ------------------
  137|       |        nalloc_verbose = true;
  138|      0|    }
  139|      0|}
recv:
  289|  12.4k|{
  290|  12.4k|    if (nalloc_fail(count, "recv")) {
  ------------------
  |  Branch (290:9): [True: 0, False: 12.4k]
  ------------------
  291|      0|        errno = EIO;
  292|      0|        return -1;
  293|      0|    }
  294|  12.4k|    return nalloc_recv(fd, buf, count, flags);
  ------------------
  |  |  265|  12.4k|#define nalloc_recv(f, b, s, x) __recv(f, b, s, x)
  ------------------
  295|  12.4k|}
send:
  298|  13.1k|{
  299|  13.1k|    if (nalloc_fail(count, "send")) {
  ------------------
  |  Branch (299:9): [True: 0, False: 13.1k]
  ------------------
  300|      0|        errno = EIO;
  301|      0|        return -1;
  302|      0|    }
  303|  13.1k|    return nalloc_send(fd, buf, count, flags);
  ------------------
  |  |  266|  13.1k|#define nalloc_send(f, b, s, x) __send(f, b, s, x)
  ------------------
  304|  13.1k|}
calloc:
  307|   197k|{
  308|   197k|    if (nalloc_fail(size, "calloc")) {
  ------------------
  |  Branch (308:9): [True: 0, False: 197k]
  ------------------
  309|      0|        errno = ENOMEM;
  310|      0|        return NULL;
  311|      0|    }
  312|   197k|    return nalloc_calloc(nmemb, size);
  ------------------
  |  |  259|   197k|#define nalloc_calloc(s, n)          __libc_calloc(s, n)
  ------------------
  313|   197k|}
malloc:
  316|   690k|{
  317|   690k|    if (nalloc_fail(size, "malloc")) {
  ------------------
  |  Branch (317:9): [True: 0, False: 690k]
  ------------------
  318|      0|        errno = ENOMEM;
  319|      0|        return NULL;
  320|      0|    }
  321|   690k|    return nalloc_malloc(size);
  ------------------
  |  |  258|   690k|#define nalloc_malloc(s)             __libc_malloc(s)
  ------------------
  322|   690k|}
realloc:
  325|  59.4k|{
  326|  59.4k|    if (nalloc_fail(size, "realloc")) {
  ------------------
  |  Branch (326:9): [True: 0, False: 59.4k]
  ------------------
  327|      0|        errno = ENOMEM;
  328|      0|        return NULL;
  329|      0|    }
  330|  59.4k|    return nalloc_realloc(ptr, size);
  ------------------
  |  |  260|  59.4k|#define nalloc_realloc(p, s)         __libc_realloc(p, s)
  ------------------
  331|  59.4k|}
ssh_scp_fuzzer.c:nalloc_fail:
  194|   956k|{
  195|       |    // do not fail before thread init
  196|   956k|    if (nalloc_runs == 0) {
  ------------------
  |  Branch (196:9): [True: 956k, False: 18.4E]
  ------------------
  197|   956k|        return false;
  198|   956k|    }
  199|  18.4E|    if (__sync_fetch_and_add(&nalloc_running, 1) != 1) {
  ------------------
  |  Branch (199:9): [True: 0, False: 18.4E]
  ------------------
  200|       |        // do not fail allocations outside of fuzzer input
  201|       |        // and do not fail inside of this function
  202|      0|        __sync_fetch_and_sub(&nalloc_running, 1);
  203|      0|        return false;
  204|      0|    }
  205|  18.4E|    nalloc_random_update((uint8_t)size);
  206|  18.4E|    if (size >= 0x100) {
  ------------------
  |  Branch (206:9): [True: 0, False: 18.4E]
  ------------------
  207|      0|        nalloc_random_update((uint8_t)(size >> 8));
  208|      0|        if (size >= 0x10000) {
  ------------------
  |  Branch (208:13): [True: 0, False: 0]
  ------------------
  209|      0|            nalloc_random_update((uint8_t)(size >> 16));
  210|       |            // bigger may already fail or oom
  211|      0|        }
  212|      0|    }
  213|  18.4E|    if (((nalloc_random_state ^ nalloc_magic) & nalloc_bitmask) == 0) {
  ------------------
  |  Branch (213:9): [True: 0, False: 18.4E]
  ------------------
  214|      0|        if (nalloc_backtrace_exclude(size, op)) {
  ------------------
  |  Branch (214:13): [True: 0, False: 0]
  ------------------
  215|      0|            __sync_fetch_and_sub(&nalloc_running, 1);
  216|      0|            return false;
  217|      0|        }
  218|      0|        __sync_fetch_and_sub(&nalloc_running, 1);
  219|      0|        return true;
  220|      0|    }
  221|  18.4E|    __sync_fetch_and_sub(&nalloc_running, 1);
  222|       |    return false;
  223|  18.4E|}
ssh_scp_fuzzer.c:nalloc_start:
  151|    657|{
  152|    657|    if (nalloc_random_bitmask) {
  ------------------
  |  Branch (152:9): [True: 0, False: 657]
  ------------------
  153|      0|        if (nalloc_random_state & 0x10) {
  ------------------
  |  Branch (153:13): [True: 0, False: 0]
  ------------------
  154|      0|            nalloc_bitmask = 0xFFFFFFFF;
  155|      0|        } else {
  156|      0|            nalloc_bitmask = 1 << (5 + (nalloc_random_state & 0xF));
  157|      0|        }
  158|    657|    } else if (nalloc_bitmask == 0) {
  ------------------
  |  Branch (158:16): [True: 657, False: 0]
  ------------------
  159|       |        // nalloc disabled
  160|    657|        return 2;
  161|    657|    }
  162|      0|    nalloc_random_state = 0;
  163|      0|    for (size_t i = 0; i < size; i++) {
  ------------------
  |  Branch (163:24): [True: 0, False: 0]
  ------------------
  164|      0|        nalloc_random_update(data[i]);
  165|      0|    }
  166|      0|    if (__sync_fetch_and_add(&nalloc_running, 1)) {
  ------------------
  |  Branch (166:9): [True: 0, False: 0]
  ------------------
  167|      0|        __sync_fetch_and_sub(&nalloc_running, 1);
  168|      0|        return 0;
  169|      0|    }
  170|      0|    nalloc_runs++;
  171|      0|    return 1;
  172|      0|}
ssh_scp_fuzzer.c:nalloc_end:
  176|    657|{
  177|    657|    __sync_fetch_and_sub(&nalloc_running, 1);
  178|    657|}

LLVMFuzzerInitialize:
   41|      2|{
   42|      2|    (void)argc;
   43|      2|    nalloc_init(*argv[0]);
   44|      2|    ssh_init();
   45|      2|    atexit(_fuzz_finalize);
   46|      2|    ssh_mock_write_hostkey(SSH_MOCK_HOSTKEY_PATH);
  ------------------
  |  |   59|      2|#define SSH_MOCK_HOSTKEY_PATH "/tmp/libssh_mock_fuzz_key"
  ------------------
   47|      2|    return 0;
   48|      2|}
LLVMFuzzerTestOneInput:
  334|    720|{
  335|    720|    uint8_t wrapped[4096];
  336|    720|    size_t wrapped_size = 0;
  337|    720|    const char *cipher = NULL;
  338|    720|    const char *hmac = NULL;
  339|       |
  340|    720|    if (size < 6) {
  ------------------
  |  Branch (340:9): [True: 63, False: 657]
  ------------------
  341|     63|        return 0;
  342|     63|    }
  343|       |
  344|    720|    assert(nalloc_start(data, size) > 0);
  ------------------
  |  Branch (344:5): [True: 0, False: 657]
  |  Branch (344:5): [True: 657, False: 0]
  ------------------
  345|       |
  346|    657|    cipher = k_ciphers[data[0] % (sizeof(k_ciphers) / sizeof(k_ciphers[0]))];
  347|    657|    hmac = k_hmacs[data[1] % (sizeof(k_hmacs) / sizeof(k_hmacs[0]))];
  348|       |
  349|    657|    wrapped_size = scp_wrap(data + 2, size - 2, wrapped, sizeof(wrapped));
  350|    657|    if (wrapped_size > 0) {
  ------------------
  |  Branch (350:9): [True: 657, False: 0]
  ------------------
  351|    657|        test_scp_with_cipher(wrapped, wrapped_size, cipher, hmac);
  352|    657|    }
  353|       |
  354|    657|    nalloc_end();
  355|    657|    return 0;
  356|    657|}
ssh_scp_fuzzer.c:_fuzz_finalize:
   36|      2|{
   37|      2|    ssh_finalize();
   38|      2|}
ssh_scp_fuzzer.c:scp_wrap:
   88|    657|{
   89|    657|    uint16_t mode;
   90|    657|    uint8_t variant;
   91|    657|    uint8_t declared_size;
   92|    657|    size_t payload_sz;
   93|    657|    size_t cap_left;
   94|    657|    size_t total;
   95|    657|    int n;
   96|       |
   97|    657|    if (size < 4 || out_cap == 0) {
  ------------------
  |  Branch (97:9): [True: 0, False: 657]
  |  Branch (97:21): [True: 0, False: 657]
  ------------------
   98|      0|        return 0;
   99|      0|    }
  100|    657|    mode = ((uint16_t)data[0] << 8 | data[1]) & 07777;
  101|    657|    variant = data[2] & 0x03;
  102|    657|    declared_size = data[3];
  103|       |
  104|    657|    switch (variant) {
  105|    118|    case 0:
  ------------------
  |  Branch (105:5): [True: 118, False: 539]
  ------------------
  106|    118|        n = snprintf((char *)out,
  107|    118|                     out_cap,
  108|    118|                     "%cC%04o %u f\n",
  109|    118|                     0,
  110|    118|                     mode,
  111|    118|                     declared_size);
  112|    118|        break;
  113|     70|    case 1:
  ------------------
  |  Branch (113:5): [True: 70, False: 587]
  ------------------
  114|     70|        n = snprintf((char *)out, out_cap, "%cD%04o 0 d\n", 0, mode);
  115|     70|        break;
  116|    357|    case 2:
  ------------------
  |  Branch (116:5): [True: 357, False: 300]
  ------------------
  117|    357|        n = snprintf((char *)out, out_cap, "%cT0 0 0 0\n", 0);
  118|    357|        break;
  119|    112|    default:
  ------------------
  |  Branch (119:5): [True: 112, False: 545]
  ------------------
  120|    112|        n = snprintf((char *)out, out_cap, "%cE\n", 0);
  121|    112|        break;
  122|    657|    }
  123|    657|    if (n < 0 || (size_t)n >= out_cap) {
  ------------------
  |  Branch (123:9): [True: 0, False: 657]
  |  Branch (123:18): [True: 0, False: 657]
  ------------------
  124|      0|        return 0;
  125|      0|    }
  126|       |
  127|    657|    payload_sz = size - 4;
  128|    657|    cap_left = out_cap - (size_t)n;
  129|    657|    if (payload_sz > cap_left) {
  ------------------
  |  Branch (129:9): [True: 500, False: 157]
  ------------------
  130|    500|        payload_sz = cap_left;
  131|    500|    }
  132|    657|    memcpy(out + n, data + 4, payload_sz);
  133|    657|    total = (size_t)n + payload_sz;
  134|       |    /* Optional server final ACK; bit chosen by fuzzer to cover both paths */
  135|    657|    if (variant == 0 && (data[2] & 0x04) && total < out_cap) {
  ------------------
  |  Branch (135:9): [True: 118, False: 539]
  |  Branch (135:25): [True: 42, False: 76]
  |  Branch (135:45): [True: 12, False: 30]
  ------------------
  136|     12|        out[total++] = '\x00';
  137|     12|    }
  138|    657|    return total;
  139|    657|}
ssh_scp_fuzzer.c:test_scp_with_cipher:
  146|    657|{
  147|    657|    bool thread_started = false;
  148|    657|    int socket_fds[2] = {-1, -1};
  149|    657|    ssh_session client_session = NULL;
  150|    657|    ssh_scp scp = NULL, scp_recursive = NULL;
  151|    657|    char buf[256] = {0};
  152|    657|    pthread_t srv_thread;
  153|    657|    int rc;
  154|    657|    long timeout = 1;
  155|    657|    bool no = false;
  156|    657|    struct timeval tv = {.tv_sec = 2, .tv_usec = 0};
  157|       |
  158|       |    /* Configure mock SSH server with fuzzer data */
  159|    657|    struct ssh_mock_server_config server_config = {
  160|    657|        .protocol_data = data,
  161|    657|        .protocol_data_size = size,
  162|    657|        .exec_callback = ssh_mock_send_raw_data,
  163|    657|        .subsystem_callback = NULL,
  164|    657|        .callback_userdata = NULL,
  165|    657|        .cipher = cipher,
  166|    657|        .hmac = hmac,
  167|    657|        .server_socket = -1,
  168|    657|        .client_socket = -1,
  169|    657|        .server_ready = false,
  170|    657|        .server_error = false,
  171|    657|        .shutdown_requested = false,
  172|    657|    };
  173|       |
  174|    657|    if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds) != 0) {
  ------------------
  |  Branch (174:9): [True: 0, False: 657]
  ------------------
  175|      0|        goto cleanup;
  176|      0|    }
  177|       |
  178|       |    /* Set socket timeouts to prevent indefinite blocking */
  179|    657|    setsockopt(socket_fds[0], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
  180|    657|    setsockopt(socket_fds[0], SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
  181|    657|    setsockopt(socket_fds[1], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
  182|    657|    setsockopt(socket_fds[1], SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
  183|       |
  184|    657|    server_config.server_socket = socket_fds[0];
  185|    657|    server_config.client_socket = socket_fds[1];
  186|       |
  187|    657|    if (ssh_mock_server_start(&server_config, &srv_thread) != 0) {
  ------------------
  |  Branch (187:9): [True: 0, False: 657]
  ------------------
  188|      0|        goto cleanup;
  189|      0|    }
  190|    657|    thread_started = true;
  191|       |
  192|    657|    client_session = ssh_new();
  193|    657|    if (client_session == NULL) {
  ------------------
  |  Branch (193:9): [True: 0, False: 657]
  ------------------
  194|      0|        goto cleanup;
  195|      0|    }
  196|       |
  197|       |    /* Configure client; bail on the first failing option-set so we don't
  198|       |     * run the rest of the iteration in a partially-configured state.
  199|       |     * SSH_OPTIONS_PROCESS_CONFIG is set to false so the fuzzer doesn't read
  200|       |     * ~/.ssh/config or /etc/ssh/ssh_config — keeps results deterministic
  201|       |     * across environments. SSH_OPTIONS_TIMEOUT is 1 second. */
  202|    657|    rc = ssh_options_set(client_session, SSH_OPTIONS_FD, &socket_fds[1]);
  203|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (203:9): [True: 0, False: 657]
  ------------------
  204|      0|        goto cleanup;
  205|      0|    }
  206|    657|    rc = ssh_options_set(client_session, SSH_OPTIONS_HOST, "localhost");
  207|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (207:9): [True: 0, False: 657]
  ------------------
  208|      0|        goto cleanup;
  209|      0|    }
  210|    657|    rc = ssh_options_set(client_session, SSH_OPTIONS_USER, "fuzz");
  211|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (211:9): [True: 0, False: 657]
  ------------------
  212|      0|        goto cleanup;
  213|      0|    }
  214|    657|    rc = ssh_options_set(client_session, SSH_OPTIONS_CIPHERS_C_S, cipher);
  215|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (215:9): [True: 0, False: 657]
  ------------------
  216|      0|        goto cleanup;
  217|      0|    }
  218|    657|    rc = ssh_options_set(client_session, SSH_OPTIONS_CIPHERS_S_C, cipher);
  219|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (219:9): [True: 0, False: 657]
  ------------------
  220|      0|        goto cleanup;
  221|      0|    }
  222|    657|    rc = ssh_options_set(client_session, SSH_OPTIONS_HMAC_C_S, hmac);
  223|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (223:9): [True: 0, False: 657]
  ------------------
  224|      0|        goto cleanup;
  225|      0|    }
  226|    657|    rc = ssh_options_set(client_session, SSH_OPTIONS_HMAC_S_C, hmac);
  227|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (227:9): [True: 0, False: 657]
  ------------------
  228|      0|        goto cleanup;
  229|      0|    }
  230|    657|    rc = ssh_options_set(client_session, SSH_OPTIONS_PROCESS_CONFIG, &no);
  231|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (231:9): [True: 0, False: 657]
  ------------------
  232|      0|        goto cleanup;
  233|      0|    }
  234|    657|    rc = ssh_options_set(client_session, SSH_OPTIONS_TIMEOUT, &timeout);
  235|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (235:9): [True: 0, False: 657]
  ------------------
  236|      0|        goto cleanup;
  237|      0|    }
  238|       |
  239|    657|    if (ssh_connect(client_session) != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (239:9): [True: 0, False: 657]
  ------------------
  240|      0|        goto cleanup;
  241|      0|    }
  242|       |
  243|    657|    if (ssh_userauth_none(client_session, NULL) != SSH_AUTH_SUCCESS) {
  ------------------
  |  Branch (243:9): [True: 0, False: 657]
  ------------------
  244|      0|        goto cleanup;
  245|      0|    }
  246|       |
  247|    657|    scp = ssh_scp_new(client_session, SSH_SCP_READ, "/tmp/fuzz");
  248|    657|    if (scp == NULL) {
  ------------------
  |  Branch (248:9): [True: 0, False: 657]
  ------------------
  249|      0|        goto cleanup;
  250|      0|    }
  251|       |
  252|    657|    if (ssh_scp_init(scp) != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (252:9): [True: 656, False: 1]
  ------------------
  253|    656|        goto cleanup;
  254|    656|    }
  255|       |
  256|      1|    if (size > 0) {
  ------------------
  |  Branch (256:9): [True: 1, False: 0]
  ------------------
  257|      1|        size_t copy_size = size < sizeof(buf) ? size : sizeof(buf);
  ------------------
  |  Branch (257:28): [True: 0, False: 1]
  ------------------
  258|      1|        memcpy(buf, data, copy_size);
  259|      1|    }
  260|       |
  261|       |    /* Fuzz all SCP API functions in read mode */
  262|      1|    ssh_scp_pull_request(scp);
  263|      1|    ssh_scp_request_get_filename(scp);
  264|      1|    ssh_scp_request_get_permissions(scp);
  265|      1|    ssh_scp_request_get_size64(scp);
  266|      1|    ssh_scp_request_get_size(scp);
  267|      1|    ssh_scp_request_get_warning(scp);
  268|      1|    ssh_scp_accept_request(scp);
  269|      1|    ssh_scp_deny_request(scp, "Denied by fuzzer");
  270|      1|    ssh_scp_read(scp, buf, sizeof(buf));
  271|       |
  272|       |    /* Final fuzz of scp pull request after all the calls */
  273|      1|    ssh_scp_pull_request(scp);
  274|       |
  275|       |    /* Fuzz SCP in write/upload + recursive directory mode. */
  276|      1|    scp_recursive = ssh_scp_new(client_session,
  277|      1|                                SSH_SCP_WRITE | SSH_SCP_RECURSIVE,
  278|      1|                                "/tmp/fuzz-recursive");
  279|      1|    if (scp_recursive != NULL) {
  ------------------
  |  Branch (279:9): [True: 1, False: 0]
  ------------------
  280|      1|        if (ssh_scp_init(scp_recursive) == SSH_OK) {
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (280:13): [True: 0, False: 1]
  ------------------
  281|      0|            ssh_scp_push_directory(scp_recursive, "fuzz-dir", 0755);
  282|      0|            ssh_scp_push_file(scp_recursive, "fuzz-file", sizeof(buf), 0644);
  283|      0|            ssh_scp_write(scp_recursive, buf, sizeof(buf));
  284|      0|            ssh_scp_leave_directory(scp_recursive);
  285|      0|        }
  286|      1|    }
  287|       |
  288|    657|cleanup:
  289|       |    /* Signal server thread to exit */
  290|    657|    server_config.shutdown_requested = true;
  291|       |
  292|       |    /* Close sockets */
  293|    657|    if (socket_fds[0] >= 0)
  ------------------
  |  Branch (293:9): [True: 657, False: 0]
  ------------------
  294|    657|        close(socket_fds[0]);
  295|    657|    if (socket_fds[1] >= 0)
  ------------------
  |  Branch (295:9): [True: 657, False: 0]
  ------------------
  296|    657|        close(socket_fds[1]);
  297|       |
  298|       |    /* Cleanup client objects */
  299|    657|    if (scp_recursive != NULL) {
  ------------------
  |  Branch (299:9): [True: 1, False: 656]
  ------------------
  300|      1|        ssh_scp_close(scp_recursive);
  301|      1|        ssh_scp_free(scp_recursive);
  302|      1|    }
  303|    657|    if (scp) {
  ------------------
  |  Branch (303:9): [True: 657, False: 0]
  ------------------
  304|    657|        ssh_scp_close(scp);
  305|    657|        ssh_scp_free(scp);
  306|    657|    }
  307|    657|    if (client_session) {
  ------------------
  |  Branch (307:9): [True: 657, False: 0]
  ------------------
  308|    657|        ssh_disconnect(client_session);
  309|    657|        ssh_free(client_session);
  310|    657|    }
  311|       |
  312|       |    /* Server thread exits via shutdown_requested + 2s socket timeout */
  313|    657|    if (thread_started) {
  ------------------
  |  Branch (313:9): [True: 657, False: 0]
  ------------------
  314|    657|        pthread_join(srv_thread, NULL);
  315|    657|    }
  316|       |
  317|    657|    return 0;
  318|      1|}

ssh_mock_server_start:
  224|    657|{
  225|    657|    if (!config || !thread)
  ------------------
  |  Branch (225:9): [True: 0, False: 657]
  |  Branch (225:20): [True: 0, False: 657]
  ------------------
  226|      0|        return -1;
  227|       |
  228|    657|    config->server_ready = false;
  229|    657|    config->server_error = false;
  230|       |
  231|    657|    if (pthread_create(thread, NULL, server_thread_func, config) != 0) {
  ------------------
  |  Branch (231:9): [True: 0, False: 657]
  ------------------
  232|      0|        return -1;
  233|      0|    }
  234|       |
  235|  1.45k|    for (int i = 0; i < 50 && !config->server_ready && !config->server_error;
  ------------------
  |  Branch (235:21): [True: 1.45k, False: 0]
  |  Branch (235:31): [True: 795, False: 657]
  |  Branch (235:56): [True: 795, False: 0]
  ------------------
  236|    795|         i++) {
  237|    795|        usleep(100);
  238|    795|    }
  239|       |
  240|    657|    if (config->server_error) {
  ------------------
  |  Branch (240:9): [True: 0, False: 657]
  ------------------
  241|      0|        pthread_join(*thread, NULL);
  242|      0|        return -1;
  243|      0|    }
  244|       |
  245|    657|    return 0;
  246|    657|}
ssh_mock_send_raw_data:
  253|    657|{
  254|    657|    (void)userdata;
  255|       |
  256|    657|    ssh_channel target_channel = (ssh_channel)channel;
  257|       |
  258|       |    /* Send raw fuzzer data */
  259|    657|    if (size > 0) {
  ------------------
  |  Branch (259:9): [True: 657, False: 0]
  ------------------
  260|    657|        ssh_channel_write(target_channel, data, size);
  261|    657|    }
  262|       |
  263|       |    /* Close channel to signal completion */
  264|    657|    ssh_channel_send_eof(target_channel);
  265|    657|    ssh_channel_close(target_channel);
  266|    657|    return SSH_OK;
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  267|    657|}
ssh_mock_write_hostkey:
  271|      2|{
  272|      2|    FILE *fp = fopen(path, "wb");
  273|      2|    if (fp == NULL)
  ------------------
  |  Branch (273:9): [True: 0, False: 2]
  ------------------
  274|      0|        return -1;
  275|       |
  276|      2|    size_t len = strlen(ssh_mock_ed25519_key_pem);
  277|      2|    size_t nwritten = fwrite(ssh_mock_ed25519_key_pem, 1, len, fp);
  278|      2|    fclose(fp);
  279|       |
  280|      2|    return (nwritten == len) ? 0 : -1;
  ------------------
  |  Branch (280:12): [True: 2, False: 0]
  ------------------
  281|      2|}
ssh_server_mock.c:server_thread_func:
  122|    657|{
  123|    657|    struct ssh_mock_server_config *config =
  124|    657|        (struct ssh_mock_server_config *)arg;
  125|    657|    struct mock_session_data sdata = {0};
  126|    657|    sdata.config = config;
  127|    657|    int rc;
  128|       |
  129|    657|    struct server_resources res = {NULL, NULL, NULL};
  130|       |
  131|    657|    struct ssh_server_callbacks_struct server_cb = {
  132|    657|        .userdata = &sdata,
  133|    657|        .auth_none_function = mock_auth_none,
  134|    657|        .channel_open_request_session_function = mock_channel_open,
  135|    657|    };
  136|       |
  137|    657|    struct ssh_channel_callbacks_struct channel_cb = {
  138|    657|        .userdata = &sdata,
  139|    657|        .channel_exec_request_function = mock_channel_exec,
  140|    657|        .channel_subsystem_request_function = mock_channel_subsystem,
  141|    657|    };
  142|       |
  143|    657|    bool no = false;
  144|       |
  145|    657|    res.sshbind = ssh_bind_new();
  146|    657|    if (res.sshbind == NULL) {
  ------------------
  |  Branch (146:9): [True: 0, False: 657]
  ------------------
  147|      0|        config->server_error = true;
  148|      0|        goto cleanup;
  149|      0|    }
  150|       |
  151|    657|    res.session = ssh_new();
  152|    657|    if (res.session == NULL) {
  ------------------
  |  Branch (152:9): [True: 0, False: 657]
  ------------------
  153|      0|        config->server_error = true;
  154|      0|        goto cleanup;
  155|      0|    }
  156|       |
  157|    657|    const char *cipher = config->cipher ? config->cipher : "aes128-ctr";
  ------------------
  |  Branch (157:26): [True: 657, False: 0]
  ------------------
  158|    657|    const char *hmac = config->hmac ? config->hmac : "hmac-sha1";
  ------------------
  |  Branch (158:24): [True: 657, False: 0]
  ------------------
  159|       |
  160|    657|    ssh_bind_options_set(res.sshbind,
  161|    657|                         SSH_BIND_OPTIONS_HOSTKEY,
  162|    657|                         SSH_MOCK_HOSTKEY_PATH);
  ------------------
  |  |   59|    657|#define SSH_MOCK_HOSTKEY_PATH "/tmp/libssh_mock_fuzz_key"
  ------------------
  163|    657|    ssh_bind_options_set(res.sshbind, SSH_BIND_OPTIONS_CIPHERS_C_S, cipher);
  164|    657|    ssh_bind_options_set(res.sshbind, SSH_BIND_OPTIONS_CIPHERS_S_C, cipher);
  165|    657|    ssh_bind_options_set(res.sshbind, SSH_BIND_OPTIONS_HMAC_C_S, hmac);
  166|    657|    ssh_bind_options_set(res.sshbind, SSH_BIND_OPTIONS_HMAC_S_C, hmac);
  167|    657|    ssh_bind_options_set(res.sshbind, SSH_BIND_OPTIONS_PROCESS_CONFIG, &no);
  168|       |
  169|    657|    ssh_set_auth_methods(res.session, SSH_AUTH_METHOD_NONE);
  ------------------
  |  |  156|    657|#define SSH_AUTH_METHOD_NONE         0x0001u
  ------------------
  170|    657|    ssh_callbacks_init(&server_cb);
  ------------------
  |  |  534|    657|#define ssh_callbacks_init(p) do {\
  |  |  535|    657|	(p)->size=sizeof(*(p)); \
  |  |  536|    657|} while(0);
  |  |  ------------------
  |  |  |  Branch (536:9): [Folded, False: 657]
  |  |  ------------------
  ------------------
  171|    657|    ssh_set_server_callbacks(res.session, &server_cb);
  172|       |
  173|       |    /* Bound libssh's internal poll in ssh_handle_key_exchange */
  174|    657|    long server_timeout = 1;
  175|    657|    ssh_options_set(res.session, SSH_OPTIONS_TIMEOUT, &server_timeout);
  176|       |
  177|    657|    rc = ssh_bind_accept_fd(res.sshbind, res.session, config->server_socket);
  178|    657|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (178:9): [True: 0, False: 657]
  ------------------
  179|      0|        config->server_error = true;
  180|      0|        goto cleanup;
  181|      0|    }
  182|       |
  183|    657|    config->server_ready = true;
  184|       |
  185|    657|    res.event = ssh_event_new();
  186|    657|    if (res.event == NULL) {
  ------------------
  |  Branch (186:9): [True: 0, False: 657]
  ------------------
  187|      0|        goto cleanup;
  188|      0|    }
  189|       |
  190|    657|    if (ssh_handle_key_exchange(res.session) == SSH_OK) {
  ------------------
  |  |  316|    657|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (190:9): [True: 657, False: 0]
  ------------------
  191|    657|        ssh_event_add_session(res.event, res.session);
  192|       |
  193|  4.59k|        for (int i = 0; i < 50 && !sdata.channel && !config->shutdown_requested;
  ------------------
  |  Branch (193:25): [True: 4.59k, False: 0]
  |  Branch (193:35): [True: 3.94k, False: 657]
  |  Branch (193:53): [True: 3.94k, False: 0]
  ------------------
  194|  3.94k|             i++) {
  195|  3.94k|            ssh_event_dopoll(res.event, 1);
  196|  3.94k|        }
  197|       |
  198|    657|        if (sdata.channel) {
  ------------------
  |  Branch (198:13): [True: 657, False: 0]
  ------------------
  199|    657|            ssh_callbacks_init(&channel_cb);
  ------------------
  |  |  534|    657|#define ssh_callbacks_init(p) do {\
  |  |  535|    657|	(p)->size=sizeof(*(p)); \
  |  |  536|    657|} while(0);
  |  |  ------------------
  |  |  |  Branch (536:9): [Folded, False: 657]
  |  |  ------------------
  ------------------
  200|    657|            ssh_set_channel_callbacks(sdata.channel, &channel_cb);
  201|       |
  202|    657|            int max_iterations = 30;
  203|  1.97k|            for (int iter = 0; iter < max_iterations &&
  ------------------
  |  Branch (203:32): [True: 1.97k, False: 0]
  ------------------
  204|  1.97k|                               !ssh_channel_is_closed(sdata.channel) &&
  ------------------
  |  Branch (204:32): [True: 1.31k, False: 657]
  ------------------
  205|  1.31k|                               !ssh_channel_is_eof(sdata.channel) &&
  ------------------
  |  Branch (205:32): [True: 1.31k, False: 0]
  ------------------
  206|  1.31k|                               !config->shutdown_requested;
  ------------------
  |  Branch (206:32): [True: 1.31k, False: 0]
  ------------------
  207|  1.31k|                 iter++) {
  208|  1.31k|                if (ssh_event_dopoll(res.event, 100) == SSH_ERROR) {
  ------------------
  |  |  317|  1.31k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (208:21): [True: 0, False: 1.31k]
  ------------------
  209|      0|                    break;
  210|      0|                }
  211|  1.31k|            }
  212|    657|        }
  213|    657|    }
  214|       |
  215|    657|cleanup:
  216|    657|    cleanup_server_resources(&res);
  217|       |
  218|       |    return NULL;
  219|    657|}
ssh_server_mock.c:mock_auth_none:
   48|    657|{
   49|    657|    (void)session;
   50|    657|    (void)user;
   51|    657|    (void)userdata;
   52|    657|    return SSH_AUTH_SUCCESS;
   53|    657|}
ssh_server_mock.c:mock_channel_open:
   57|    657|{
   58|    657|    struct mock_session_data *sdata = (struct mock_session_data *)userdata;
   59|    657|    sdata->channel = ssh_channel_new(session);
   60|    657|    return sdata->channel;
   61|    657|}
ssh_server_mock.c:mock_channel_exec:
   68|    657|{
   69|    657|    struct mock_session_data *sdata = (struct mock_session_data *)userdata;
   70|    657|    (void)session;
   71|    657|    (void)command;
   72|       |
   73|    657|    if (sdata->config->exec_callback) {
  ------------------
  |  Branch (73:9): [True: 657, False: 0]
  ------------------
   74|    657|        return sdata->config->exec_callback(channel,
   75|    657|                                            sdata->config->protocol_data,
   76|    657|                                            sdata->config->protocol_data_size,
   77|    657|                                            sdata->config->callback_userdata);
   78|    657|    }
   79|      0|    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
   80|    657|}
ssh_server_mock.c:cleanup_server_resources:
  110|    657|{
  111|    657|    struct server_resources *res = (struct server_resources *)arg;
  112|    657|    ssh_event_free(res->event);
  113|    657|    if (res->session) {
  ------------------
  |  Branch (113:9): [True: 657, False: 0]
  ------------------
  114|    657|        ssh_disconnect(res->session);
  115|    657|        ssh_free(res->session);
  116|    657|    }
  117|    657|    ssh_bind_free(res->sshbind);
  118|    657|}

