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

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

base64_to_bin:
   64|    273|{
   65|    273|    ssh_buffer buffer = NULL;
   66|    273|    unsigned char block[3];
   67|    273|    char *base64 = NULL;
   68|    273|    char *ptr = NULL;
   69|    273|    size_t len;
   70|    273|    int equals;
   71|       |
   72|    273|    base64 = strdup(source);
   73|    273|    if (base64 == NULL) {
  ------------------
  |  Branch (73:9): [True: 0, False: 273]
  ------------------
   74|      0|        return NULL;
   75|      0|    }
   76|    273|    ptr = base64;
   77|       |
   78|       |    /* Get the number of equals signs, which mirrors the padding */
   79|    273|    equals = get_equals(ptr);
   80|    273|    if (equals > 2) {
  ------------------
  |  Branch (80:9): [True: 0, False: 273]
  ------------------
   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|    273|    buffer = ssh_buffer_new();
   86|    273|    if (buffer == NULL) {
  ------------------
  |  Branch (86:9): [True: 0, False: 273]
  ------------------
   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|    273|    ssh_buffer_set_secure(buffer);
   95|       |
   96|    273|    len = strlen(ptr);
   97|  22.9k|    while (len > 4) {
  ------------------
  |  Branch (97:12): [True: 22.6k, False: 273]
  ------------------
   98|  22.6k|        if (_base64_to_bin(block, ptr, 3) < 0) {
  ------------------
  |  Branch (98:13): [True: 0, False: 22.6k]
  ------------------
   99|      0|            goto error;
  100|      0|        }
  101|  22.6k|        if (ssh_buffer_add_data(buffer, block, 3) < 0) {
  ------------------
  |  Branch (101:13): [True: 0, False: 22.6k]
  ------------------
  102|      0|            goto error;
  103|      0|        }
  104|  22.6k|        len -= 4;
  105|  22.6k|        ptr += 4;
  106|  22.6k|    }
  107|       |
  108|       |    /*
  109|       |     * Depending on the number of bytes resting, there are 3 possibilities
  110|       |     * from the RFC.
  111|       |     */
  112|    273|    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: 273]
  ------------------
  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|    273|    case 2:
  ------------------
  |  Branch (136:5): [True: 273, False: 0]
  ------------------
  137|    273|        if (equals != 2) {
  ------------------
  |  Branch (137:13): [True: 0, False: 273]
  ------------------
  138|      0|            goto error;
  139|      0|        }
  140|       |
  141|    273|        if (_base64_to_bin(block, ptr, 1) < 0) {
  ------------------
  |  Branch (141:13): [True: 0, False: 273]
  ------------------
  142|      0|            goto error;
  143|      0|        }
  144|    273|        if (ssh_buffer_add_data(buffer, block, 1) < 0) {
  ------------------
  |  Branch (144:13): [True: 0, False: 273]
  ------------------
  145|      0|            goto error;
  146|      0|        }
  147|    273|        SAFE_FREE(base64);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  148|       |
  149|    273|        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: 273]
  ------------------
  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: 273]
  ------------------
  169|       |        /* 4,3,2 are the only padding size allowed */
  170|      0|        goto error;
  171|    273|    }
  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);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  176|       |    return NULL;
  177|    273|}
base64.c:_base64_to_bin:
  216|  22.9k|{
  217|  22.9k|    unsigned long block;
  218|       |
  219|  22.9k|    if (to_block4(&block, source, num) < 0) {
  ------------------
  |  Branch (219:9): [True: 0, False: 22.9k]
  ------------------
  220|      0|        return -1;
  221|      0|    }
  222|  22.9k|    dest[0] = GET_A(block);
  ------------------
  |  |   46|  22.9k|#define GET_A(n) (unsigned char) (((n) & 0xff0000) >> 16)
  ------------------
  223|  22.9k|    dest[1] = GET_B(block);
  ------------------
  |  |   47|  22.9k|#define GET_B(n) (unsigned char) (((n) & 0xff00) >> 8)
  ------------------
  224|  22.9k|    dest[2] = GET_C(block);
  ------------------
  |  |   48|  22.9k|#define GET_C(n) (unsigned char) ((n) & 0xff)
  ------------------
  225|       |
  226|  22.9k|    return 0;
  227|  22.9k|}
base64.c:to_block4:
  187|  22.9k|{
  188|  22.9k|    const char *ptr = NULL;
  189|  22.9k|    size_t i;
  190|       |
  191|  22.9k|    *block = 0;
  192|  22.9k|    if (num < 1) {
  ------------------
  |  Branch (192:9): [True: 0, False: 22.9k]
  ------------------
  193|      0|        return 0;
  194|      0|    }
  195|       |
  196|  22.9k|    BLOCK(A, 0); /* 6 bit */
  ------------------
  |  |  179|  22.9k|#define BLOCK(letter, n) do {ptr = strchr((const char *)alphabet, source[n]); \
  |  |  180|  22.9k|                             if(!ptr) return -1; \
  |  |  ------------------
  |  |  |  Branch (180:33): [True: 0, False: 22.9k]
  |  |  ------------------
  |  |  181|  22.9k|                             i = ptr - (const char *)alphabet; \
  |  |  182|  22.9k|                             SET_##letter(*block, i); \
  |  |  ------------------
  |  |  |  |   41|  22.9k|#define SET_A(n, i) do { (n) |= ((i) & 63) <<18; } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (41:59): [Folded, False: 22.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  22.9k|                         } while(0)
  |  |  ------------------
  |  |  |  Branch (183:34): [Folded, False: 22.9k]
  |  |  ------------------
  ------------------
  197|  22.9k|    BLOCK(B, 1); /* 12 bit */
  ------------------
  |  |  179|  22.9k|#define BLOCK(letter, n) do {ptr = strchr((const char *)alphabet, source[n]); \
  |  |  180|  22.9k|                             if(!ptr) return -1; \
  |  |  ------------------
  |  |  |  Branch (180:33): [True: 0, False: 22.9k]
  |  |  ------------------
  |  |  181|  22.9k|                             i = ptr - (const char *)alphabet; \
  |  |  182|  22.9k|                             SET_##letter(*block, i); \
  |  |  ------------------
  |  |  |  |   42|  22.9k|#define SET_B(n, i) do { (n) |= ((i) & 63) <<12; } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (42:59): [Folded, False: 22.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  22.9k|                         } while(0)
  |  |  ------------------
  |  |  |  Branch (183:34): [Folded, False: 22.9k]
  |  |  ------------------
  ------------------
  198|       |
  199|  22.9k|    if (num < 2) {
  ------------------
  |  Branch (199:9): [True: 273, False: 22.6k]
  ------------------
  200|    273|        return 0;
  201|    273|    }
  202|       |
  203|  22.6k|    BLOCK(C, 2); /* 18 bit */
  ------------------
  |  |  179|  22.6k|#define BLOCK(letter, n) do {ptr = strchr((const char *)alphabet, source[n]); \
  |  |  180|  22.6k|                             if(!ptr) return -1; \
  |  |  ------------------
  |  |  |  Branch (180:33): [True: 0, False: 22.6k]
  |  |  ------------------
  |  |  181|  22.6k|                             i = ptr - (const char *)alphabet; \
  |  |  182|  22.6k|                             SET_##letter(*block, i); \
  |  |  ------------------
  |  |  |  |   43|  22.6k|#define SET_C(n, i) do { (n) |= ((i) & 63) << 6; } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (43:59): [Folded, False: 22.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  22.6k|                         } while(0)
  |  |  ------------------
  |  |  |  Branch (183:34): [Folded, False: 22.6k]
  |  |  ------------------
  ------------------
  204|       |
  205|  22.6k|    if (num < 3) {
  ------------------
  |  Branch (205:9): [True: 0, False: 22.6k]
  ------------------
  206|      0|        return 0;
  207|      0|    }
  208|       |
  209|  22.6k|    BLOCK(D, 3); /* 24 bit */
  ------------------
  |  |  179|  22.6k|#define BLOCK(letter, n) do {ptr = strchr((const char *)alphabet, source[n]); \
  |  |  180|  22.6k|                             if(!ptr) return -1; \
  |  |  ------------------
  |  |  |  Branch (180:33): [True: 0, False: 22.6k]
  |  |  ------------------
  |  |  181|  22.6k|                             i = ptr - (const char *)alphabet; \
  |  |  182|  22.6k|                             SET_##letter(*block, i); \
  |  |  ------------------
  |  |  |  |   44|  22.6k|#define SET_D(n, i) do { (n) |= ((i) & 63); } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (44:54): [Folded, False: 22.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  22.6k|                         } while(0)
  |  |  ------------------
  |  |  |  Branch (183:34): [Folded, False: 22.6k]
  |  |  ------------------
  ------------------
  210|       |
  211|  22.6k|    return 0;
  212|  22.6k|}
base64.c:get_equals:
  231|    273|{
  232|    273|    char *ptr = string;
  233|    273|    int num = 0;
  234|       |
  235|    819|    while ((ptr = strchr(ptr, '=')) != NULL) {
  ------------------
  |  Branch (235:12): [True: 546, False: 273]
  ------------------
  236|    546|        num++;
  237|    546|        *ptr = '\0';
  238|    546|        ptr++;
  239|    546|    }
  240|       |
  241|    273|    return num;
  242|    273|}

ssh_bind_new:
  136|    273|{
  137|    273|    ssh_bind ptr = NULL;
  138|       |
  139|    273|    ptr = calloc(1, sizeof(struct ssh_bind_struct));
  140|    273|    if (ptr == NULL) {
  ------------------
  |  Branch (140:9): [True: 0, False: 273]
  ------------------
  141|      0|        return NULL;
  142|      0|    }
  143|    273|    ptr->bindfd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|    273|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  144|    273|    ptr->bindport = 22;
  145|    273|    ptr->common.log_verbosity = 0;
  146|       |
  147|    273|    return ptr;
  148|    273|}
ssh_bind_free:
  372|    273|void ssh_bind_free(ssh_bind sshbind){
  373|    273|  int i;
  374|       |
  375|    273|  if (sshbind == NULL) {
  ------------------
  |  Branch (375:7): [True: 0, False: 273]
  ------------------
  376|      0|    return;
  377|      0|  }
  378|       |
  379|    273|  if (sshbind->bindfd >= 0) {
  ------------------
  |  Branch (379:7): [True: 0, False: 273]
  ------------------
  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|    273|  sshbind->bindfd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|    273|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  383|       |
  384|       |  /* options */
  385|    273|  SAFE_FREE(sshbind->banner);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  386|    273|  SAFE_FREE(sshbind->moduli_file);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  387|    273|  SAFE_FREE(sshbind->bindaddr);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  388|    273|  SAFE_FREE(sshbind->config_dir);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  389|    273|  SAFE_FREE(sshbind->pubkey_accepted_key_types);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  390|       |
  391|    273|  SAFE_FREE(sshbind->rsakey);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  392|    273|  SAFE_FREE(sshbind->ecdsakey);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  393|    273|  SAFE_FREE(sshbind->ed25519key);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  394|    273|  SAFE_FREE(sshbind->gssapi_key_exchange_algs);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  395|       |
  396|    273|  ssh_key_free(sshbind->rsa);
  397|    273|  sshbind->rsa = NULL;
  398|    273|  ssh_key_free(sshbind->ecdsa);
  399|    273|  sshbind->ecdsa = NULL;
  400|    273|  ssh_key_free(sshbind->ed25519);
  401|    273|  sshbind->ed25519 = NULL;
  402|       |
  403|  3.00k|  for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.00k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (403:15): [True: 2.73k, False: 273]
  ------------------
  404|  2.73k|    if (sshbind->wanted_methods[i]) {
  ------------------
  |  Branch (404:9): [True: 1.09k, False: 1.63k]
  ------------------
  405|  1.09k|      SAFE_FREE(sshbind->wanted_methods[i]);
  ------------------
  |  |  373|  1.09k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.09k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
  406|  1.09k|    }
  407|  2.73k|  }
  408|       |
  409|       |  SAFE_FREE(sshbind);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  410|    273|}
ssh_bind_accept_fd:
  413|    273|{
  414|    273|    ssh_poll_handle handle = NULL;
  415|    273|    int i, rc;
  416|       |
  417|    273|    if (sshbind == NULL) {
  ------------------
  |  Branch (417:9): [True: 0, False: 273]
  ------------------
  418|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  419|      0|    }
  420|       |
  421|    273|    if (session == NULL){
  ------------------
  |  Branch (421:9): [True: 0, False: 273]
  ------------------
  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|    273|    session->server = 1;
  427|       |
  428|       |    /* Copy options from bind to session */
  429|  3.00k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.00k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (429:17): [True: 2.73k, False: 273]
  ------------------
  430|  2.73k|      if (sshbind->wanted_methods[i]) {
  ------------------
  |  Branch (430:11): [True: 1.09k, False: 1.63k]
  ------------------
  431|  1.09k|        session->opts.wanted_methods[i] = strdup(sshbind->wanted_methods[i]);
  432|  1.09k|        if (session->opts.wanted_methods[i] == NULL) {
  ------------------
  |  Branch (432:13): [True: 0, False: 1.09k]
  ------------------
  433|      0|          return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  434|      0|        }
  435|  1.09k|      }
  436|  2.73k|    }
  437|       |
  438|    273|    if (sshbind->bindaddr == NULL)
  ------------------
  |  Branch (438:9): [True: 273, False: 0]
  ------------------
  439|    273|      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|    273|    if (sshbind->pubkey_accepted_key_types != NULL) {
  ------------------
  |  Branch (448:9): [True: 0, False: 273]
  ------------------
  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|    273|    session->common.log_verbosity = sshbind->common.log_verbosity;
  472|    273|    session->opts.gssapi_key_exchange = sshbind->gssapi_key_exchange;
  473|       |
  474|    273|    if (sshbind->gssapi_key_exchange_algs != NULL) {
  ------------------
  |  Branch (474:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (sshbind->banner != NULL) {
  ------------------
  |  Branch (484:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (sshbind->moduli_file != NULL) {
  ------------------
  |  Branch (492:9): [True: 0, False: 273]
  ------------------
  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|    273|    session->opts.rsa_min_size = sshbind->rsa_min_size;
  501|       |
  502|    273|    ssh_socket_free(session->socket);
  503|    273|    session->socket = ssh_socket_new(session);
  504|    273|    if (session->socket == NULL) {
  ------------------
  |  Branch (504:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_socket_set_fd(session->socket, fd);
  510|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (510:9): [True: 0, False: 273]
  ------------------
  511|      0|        return rc;
  512|      0|    }
  513|    273|    handle = ssh_socket_get_poll_handle(session->socket);
  514|    273|    if (handle == NULL) {
  ------------------
  |  Branch (514:9): [True: 0, False: 273]
  ------------------
  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|    273|    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|    273|    if (sshbind->rsa == NULL &&
  ------------------
  |  Branch (525:9): [True: 273, False: 0]
  ------------------
  526|    273|        sshbind->ecdsa == NULL &&
  ------------------
  |  Branch (526:9): [True: 273, False: 0]
  ------------------
  527|    273|        sshbind->ed25519 == NULL) {
  ------------------
  |  Branch (527:9): [True: 0, False: 273]
  ------------------
  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|    273|#ifdef HAVE_ECC
  540|    273|    if (sshbind->ecdsa) {
  ------------------
  |  Branch (540:9): [True: 0, False: 273]
  ------------------
  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|    273|#endif
  548|    273|    if (sshbind->rsa) {
  ------------------
  |  Branch (548:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (sshbind->ed25519 != NULL) {
  ------------------
  |  Branch (555:9): [True: 273, False: 0]
  ------------------
  556|    273|        session->srv.ed25519_key = ssh_key_dup(sshbind->ed25519);
  557|    273|        if (session->srv.ed25519_key == NULL){
  ------------------
  |  Branch (557:13): [True: 0, False: 273]
  ------------------
  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|    273|    }
  562|       |
  563|       |    /* force PRNG to change state in case we fork after ssh_bind_accept */
  564|    273|    ssh_reseed();
  565|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  566|    273|}

ssh_buffer_new:
  126|  11.4k|{
  127|  11.4k|    struct ssh_buffer_struct *buf = NULL;
  128|  11.4k|    int rc;
  129|       |
  130|  11.4k|    buf = calloc(1, sizeof(struct ssh_buffer_struct));
  131|  11.4k|    if (buf == NULL) {
  ------------------
  |  Branch (131:9): [True: 0, False: 11.4k]
  ------------------
  132|      0|        return NULL;
  133|      0|    }
  134|       |
  135|       |    /*
  136|       |     * Always preallocate 64 bytes.
  137|       |     *
  138|       |     * -1 for realloc_buffer magic.
  139|       |     */
  140|  11.4k|    rc = ssh_buffer_allocate_size(buf, 64 - 1);
  141|  11.4k|    if (rc != 0) {
  ------------------
  |  Branch (141:9): [True: 0, False: 11.4k]
  ------------------
  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|  11.4k|    buffer_verify(buf);
  146|       |
  147|  11.4k|    return buf;
  148|  11.4k|}
ssh_buffer_free:
  156|  11.4k|{
  157|  11.4k|    if (buffer == NULL) {
  ------------------
  |  Branch (157:9): [True: 0, False: 11.4k]
  ------------------
  158|      0|        return;
  159|      0|    }
  160|  11.4k|    buffer_verify(buffer);
  161|       |
  162|  11.4k|    if (buffer->secure && buffer->allocated > 0) {
  ------------------
  |  Branch (162:9): [True: 2.45k, False: 9.00k]
  |  Branch (162:27): [True: 2.45k, False: 0]
  ------------------
  163|       |        /* burn the data */
  164|  2.45k|        ssh_burn(buffer->data, buffer->allocated);
  ------------------
  |  |  388|  2.45k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  165|  2.45k|        SAFE_FREE(buffer->data);
  ------------------
  |  |  373|  2.45k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.45k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.45k]
  |  |  ------------------
  ------------------
  166|       |
  167|  2.45k|        ssh_burn(buffer, sizeof(struct ssh_buffer_struct));
  ------------------
  |  |  388|  2.45k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  168|  9.00k|    } else {
  169|  9.00k|        SAFE_FREE(buffer->data);
  ------------------
  |  |  373|  9.00k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 9.00k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 9.00k]
  |  |  ------------------
  ------------------
  170|  9.00k|    }
  171|       |    SAFE_FREE(buffer);
  ------------------
  |  |  373|  11.4k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 11.4k, False: 2]
  |  |  |  Branch (373:71): [Folded, False: 11.4k]
  |  |  ------------------
  ------------------
  172|  11.4k|}
ssh_buffer_set_secure:
  183|  2.45k|{
  184|       |    buffer->secure = true;
  185|  2.45k|}
ssh_buffer_reinit:
  266|  12.5k|{
  267|  12.5k|    if (buffer == NULL) {
  ------------------
  |  Branch (267:9): [True: 0, False: 12.5k]
  ------------------
  268|      0|        return -1;
  269|      0|    }
  270|       |
  271|  12.5k|    buffer_verify(buffer);
  272|       |
  273|  12.5k|    if (buffer->secure && buffer->allocated > 0) {
  ------------------
  |  Branch (273:9): [True: 0, False: 12.5k]
  |  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|  12.5k|    buffer->used = 0;
  277|  12.5k|    buffer->pos = 0;
  278|       |
  279|       |    /* If the buffer is bigger then 64K, reset it to 64K */
  280|  12.5k|    if (buffer->allocated > 65536) {
  ------------------
  |  Branch (280:9): [True: 0, False: 12.5k]
  ------------------
  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|  12.5k|    buffer_verify(buffer);
  291|       |
  292|  12.5k|    return 0;
  293|  12.5k|}
ssh_buffer_add_data:
  307|  96.2k|{
  308|  96.2k|    if (buffer == NULL) {
  ------------------
  |  Branch (308:9): [True: 0, False: 96.2k]
  ------------------
  309|      0|        return -1;
  310|      0|    }
  311|       |
  312|  96.2k|    buffer_verify(buffer);
  313|       |
  314|  96.2k|    if (data == NULL) {
  ------------------
  |  Branch (314:9): [True: 0, False: 96.2k]
  ------------------
  315|      0|        return -1;
  316|      0|    }
  317|       |
  318|  96.2k|    if (buffer->used + len < len) {
  ------------------
  |  Branch (318:9): [True: 0, False: 96.2k]
  ------------------
  319|      0|        return -1;
  320|      0|    }
  321|       |
  322|  96.2k|    if (buffer->allocated < (buffer->used + len)) {
  ------------------
  |  Branch (322:9): [True: 6.37k, False: 89.9k]
  ------------------
  323|  6.37k|        if (buffer->pos > 0) {
  ------------------
  |  Branch (323:13): [True: 0, False: 6.37k]
  ------------------
  324|      0|            buffer_shift(buffer);
  325|      0|        }
  326|  6.37k|        if (realloc_buffer(buffer, buffer->used + len) < 0) {
  ------------------
  |  Branch (326:13): [True: 0, False: 6.37k]
  ------------------
  327|      0|            return -1;
  328|      0|        }
  329|  6.37k|    }
  330|       |
  331|  96.2k|    memcpy(buffer->data + buffer->used, data, len);
  332|  96.2k|    buffer->used += len;
  333|  96.2k|    buffer_verify(buffer);
  334|  96.2k|    return 0;
  335|  96.2k|}
ssh_buffer_allocate_size:
  348|  22.9k|{
  349|  22.9k|    buffer_verify(buffer);
  350|       |
  351|  22.9k|    if (buffer->allocated < len) {
  ------------------
  |  Branch (351:9): [True: 13.4k, False: 9.46k]
  ------------------
  352|  13.4k|        if (buffer->pos > 0) {
  ------------------
  |  Branch (352:13): [True: 0, False: 13.4k]
  ------------------
  353|      0|            buffer_shift(buffer);
  354|      0|        }
  355|  13.4k|        if (realloc_buffer(buffer, len) < 0) {
  ------------------
  |  Branch (355:13): [True: 0, False: 13.4k]
  ------------------
  356|      0|            return -1;
  357|      0|        }
  358|  13.4k|    }
  359|       |
  360|  22.9k|    buffer_verify(buffer);
  361|       |
  362|  22.9k|    return 0;
  363|  22.9k|}
ssh_buffer_allocate:
  378|  14.2k|{
  379|  14.2k|    void *ptr = NULL;
  380|       |
  381|  14.2k|    buffer_verify(buffer);
  382|       |
  383|  14.2k|    if (buffer->used + len < len) {
  ------------------
  |  Branch (383:9): [True: 0, False: 14.2k]
  ------------------
  384|      0|        return NULL;
  385|      0|    }
  386|       |
  387|  14.2k|    if (buffer->allocated < (buffer->used + len)) {
  ------------------
  |  Branch (387:9): [True: 1.73k, False: 12.5k]
  ------------------
  388|  1.73k|        if (buffer->pos > 0) {
  ------------------
  |  Branch (388:13): [True: 0, False: 1.73k]
  ------------------
  389|      0|            buffer_shift(buffer);
  390|      0|        }
  391|       |
  392|  1.73k|        if (realloc_buffer(buffer, buffer->used + len) < 0) {
  ------------------
  |  Branch (392:13): [True: 0, False: 1.73k]
  ------------------
  393|      0|            return NULL;
  394|      0|        }
  395|  1.73k|    }
  396|       |
  397|  14.2k|    ptr = buffer->data + buffer->used;
  398|  14.2k|    buffer->used+=len;
  399|  14.2k|    buffer_verify(buffer);
  400|       |
  401|  14.2k|    return ptr;
  402|  14.2k|}
ssh_buffer_add_ssh_string:
  418|  21.2k|{
  419|  21.2k|    size_t len;
  420|  21.2k|    int rc;
  421|       |
  422|  21.2k|    if (string == NULL) {
  ------------------
  |  Branch (422:9): [True: 0, False: 21.2k]
  ------------------
  423|      0|        return -1;
  424|      0|    }
  425|       |
  426|  21.2k|    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|  21.2k|    rc = ssh_buffer_add_data(buffer, string, (uint32_t)len);
  430|  21.2k|    if (rc < 0) {
  ------------------
  |  Branch (430:9): [True: 0, False: 21.2k]
  ------------------
  431|      0|        return -1;
  432|      0|    }
  433|       |
  434|  21.2k|    return 0;
  435|  21.2k|}
ssh_buffer_add_u32:
  449|  13.9k|{
  450|  13.9k|    int rc;
  451|       |
  452|  13.9k|    rc = ssh_buffer_add_data(buffer, &data, sizeof(data));
  453|  13.9k|    if (rc < 0) {
  ------------------
  |  Branch (453:9): [True: 0, False: 13.9k]
  ------------------
  454|      0|        return -1;
  455|      0|    }
  456|       |
  457|  13.9k|    return 0;
  458|  13.9k|}
ssh_buffer_add_u8:
  518|  8.73k|{
  519|  8.73k|    int rc;
  520|       |
  521|  8.73k|    rc = ssh_buffer_add_data(buffer, &data, sizeof(uint8_t));
  522|  8.73k|    if (rc < 0) {
  ------------------
  |  Branch (522:9): [True: 0, False: 8.73k]
  ------------------
  523|      0|        return -1;
  524|      0|    }
  525|       |
  526|  8.73k|    return 0;
  527|  8.73k|}
ssh_buffer_prepend_data:
  543|  5.46k|    uint32_t len) {
  544|  5.46k|  buffer_verify(buffer);
  545|       |
  546|  5.46k|  if(len <= buffer->pos){
  ------------------
  |  Branch (546:6): [True: 0, False: 5.46k]
  ------------------
  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|  5.46k|  if (buffer->used - buffer->pos + len < len) {
  ------------------
  |  Branch (554:7): [True: 0, False: 5.46k]
  ------------------
  555|      0|    return -1;
  556|      0|  }
  557|       |
  558|  5.46k|  if (buffer->allocated < (buffer->used - buffer->pos + len)) {
  ------------------
  |  Branch (558:7): [True: 25, False: 5.43k]
  ------------------
  559|     25|    if (realloc_buffer(buffer, buffer->used - buffer->pos + len) < 0) {
  ------------------
  |  Branch (559:9): [True: 0, False: 25]
  ------------------
  560|      0|      return -1;
  561|      0|    }
  562|     25|  }
  563|  5.46k|  memmove(buffer->data + len, buffer->data + buffer->pos, buffer->used - buffer->pos);
  564|  5.46k|  memcpy(buffer->data, data, len);
  565|  5.46k|  buffer->used += len - buffer->pos;
  566|  5.46k|  buffer->pos = 0;
  567|  5.46k|  buffer_verify(buffer);
  568|  5.46k|  return 0;
  569|  5.46k|}
ssh_buffer_get:
  607|  43.4k|void *ssh_buffer_get(struct ssh_buffer_struct *buffer){
  608|  43.4k|    return buffer->data + buffer->pos;
  609|  43.4k|}
ssh_buffer_get_len:
  620|  95.7k|uint32_t ssh_buffer_get_len(struct ssh_buffer_struct *buffer){
  621|  95.7k|  buffer_verify(buffer);
  622|  95.7k|  return buffer->used - buffer->pos;
  623|  95.7k|}
ssh_buffer_pass_bytes:
  685|  19.7k|uint32_t ssh_buffer_pass_bytes(struct ssh_buffer_struct *buffer, uint32_t len){
  686|  19.7k|    buffer_verify(buffer);
  687|       |
  688|  19.7k|    if (buffer->pos + len < len || buffer->used < buffer->pos + len) {
  ------------------
  |  Branch (688:9): [True: 0, False: 19.7k]
  |  Branch (688:36): [True: 0, False: 19.7k]
  ------------------
  689|      0|        return 0;
  690|      0|    }
  691|       |
  692|  19.7k|    buffer->pos+=len;
  693|       |    /* if the buffer is empty after having passed the whole bytes into it, we can clean it */
  694|  19.7k|    if(buffer->pos==buffer->used){
  ------------------
  |  Branch (694:8): [True: 14.5k, False: 5.22k]
  ------------------
  695|  14.5k|        buffer->pos=0;
  696|  14.5k|        buffer->used=0;
  697|  14.5k|    }
  698|  19.7k|    buffer_verify(buffer);
  699|  19.7k|    return len;
  700|  19.7k|}
ssh_buffer_pass_bytes_end:
  713|  9.65k|uint32_t ssh_buffer_pass_bytes_end(struct ssh_buffer_struct *buffer, uint32_t len){
  714|  9.65k|  buffer_verify(buffer);
  715|       |
  716|  9.65k|  if (buffer->used < len) {
  ------------------
  |  Branch (716:7): [True: 0, False: 9.65k]
  ------------------
  717|      0|      return 0;
  718|      0|  }
  719|       |
  720|  9.65k|  buffer->used-=len;
  721|  9.65k|  buffer_verify(buffer);
  722|  9.65k|  return len;
  723|  9.65k|}
ssh_buffer_get_data:
  737|  46.1k|{
  738|  46.1k|    int rc;
  739|       |
  740|       |    /*
  741|       |     * Check for a integer overflow first, then check if not enough data is in
  742|       |     * the buffer.
  743|       |     */
  744|  46.1k|    rc = ssh_buffer_validate_length(buffer, len);
  745|  46.1k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  46.1k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (745:9): [True: 0, False: 46.1k]
  ------------------
  746|      0|        return 0;
  747|      0|    }
  748|  46.1k|    memcpy(data,buffer->data+buffer->pos,len);
  749|  46.1k|    buffer->pos+=len;
  750|  46.1k|    return len;   /* no yet support for partial reads (is it really needed ?? ) */
  751|  46.1k|}
ssh_buffer_get_u8:
  765|  11.4k|uint32_t ssh_buffer_get_u8(struct ssh_buffer_struct *buffer, uint8_t *data){
  766|  11.4k|    return ssh_buffer_get_data(buffer,data,sizeof(uint8_t));
  767|  11.4k|}
ssh_buffer_get_u32:
  780|  18.5k|uint32_t ssh_buffer_get_u32(struct ssh_buffer_struct *buffer, uint32_t *data){
  781|  18.5k|    return ssh_buffer_get_data(buffer,data,sizeof(uint32_t));
  782|  18.5k|}
ssh_buffer_validate_length:
  809|  60.7k|{
  810|  60.7k|    if (buffer == NULL || buffer->pos + len < len ||
  ------------------
  |  Branch (810:9): [True: 18.4E, False: 60.7k]
  |  Branch (810:27): [True: 18.4E, False: 60.7k]
  ------------------
  811|  60.7k|        buffer->pos + len > buffer->used) {
  ------------------
  |  Branch (811:9): [True: 18.4E, False: 60.8k]
  ------------------
  812|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  813|      0|    }
  814|       |
  815|  60.7k|    return SSH_OK;
  ------------------
  |  |  316|  60.7k|#define SSH_OK 0     /* No error */
  ------------------
  816|  60.7k|}
ssh_buffer_get_ssh_string:
  829|  10.0k|{
  830|  10.0k|    uint32_t stringlen;
  831|  10.0k|    uint32_t hostlen;
  832|  10.0k|    struct ssh_string_struct *str = NULL;
  833|  10.0k|    int rc;
  834|       |
  835|  10.0k|    rc = ssh_buffer_get_u32(buffer, &stringlen);
  836|  10.0k|    if (rc == 0) {
  ------------------
  |  Branch (836:9): [True: 0, False: 10.0k]
  ------------------
  837|      0|        return NULL;
  838|      0|    }
  839|  10.0k|    hostlen = ntohl(stringlen);
  840|       |    /* verify if there is enough space in buffer to get it */
  841|  10.0k|    rc = ssh_buffer_validate_length(buffer, hostlen);
  842|  10.0k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  10.0k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (842:9): [True: 0, False: 10.0k]
  ------------------
  843|      0|      return NULL; /* it is indeed */
  844|      0|    }
  845|  10.0k|    str = ssh_string_new(hostlen);
  846|  10.0k|    if (str == NULL) {
  ------------------
  |  Branch (846:9): [True: 0, False: 10.0k]
  ------------------
  847|      0|        return NULL;
  848|      0|    }
  849|       |
  850|  10.0k|    stringlen = ssh_buffer_get_data(buffer, ssh_string_data(str), hostlen);
  851|  10.0k|    if (stringlen != hostlen) {
  ------------------
  |  Branch (851:9): [True: 0, False: 10.0k]
  ------------------
  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|  10.0k|    return str;
  858|  10.0k|}
_ssh_buffer_pack:
 1135|  10.3k|{
 1136|  10.3k|    va_list ap;
 1137|  10.3k|    int rc;
 1138|       |
 1139|  10.3k|    if (argc > 256) {
  ------------------
  |  Branch (1139:9): [True: 0, False: 10.3k]
  ------------------
 1140|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1141|      0|    }
 1142|       |
 1143|  10.3k|    va_start(ap, argc);
 1144|  10.3k|    rc = ssh_buffer_pack_allocate_va(buffer, format, argc, ap);
 1145|  10.3k|    va_end(ap);
 1146|       |
 1147|  10.3k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  10.3k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1147:9): [True: 0, False: 10.3k]
  ------------------
 1148|      0|        return rc;
 1149|      0|    }
 1150|       |
 1151|  10.3k|    va_start(ap, argc);
 1152|  10.3k|    rc = ssh_buffer_pack_va(buffer, format, argc, ap);
 1153|  10.3k|    va_end(ap);
 1154|       |
 1155|  10.3k|    return rc;
 1156|  10.3k|}
ssh_buffer_unpack_va:
 1173|  5.18k|{
 1174|  5.18k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  5.18k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1175|  5.18k|    const char *p = format, *last = NULL;
 1176|  5.18k|    union {
 1177|  5.18k|        uint8_t *byte;
 1178|  5.18k|        uint16_t *word;
 1179|  5.18k|        uint32_t *dword;
 1180|  5.18k|        uint64_t *qword;
 1181|  5.18k|        ssh_string *string;
 1182|  5.18k|        char **cstring;
 1183|  5.18k|        bignum *bignum;
 1184|  5.18k|        void **data;
 1185|  5.18k|    } o;
 1186|  5.18k|    size_t len;
 1187|  5.18k|    uint32_t rlen, max_len;
 1188|  5.18k|    ssh_string tmp_string = NULL;
 1189|  5.18k|    va_list ap_copy;
 1190|  5.18k|    size_t count;
 1191|       |
 1192|  5.18k|    max_len = ssh_buffer_get_len(buffer);
 1193|       |
 1194|       |    /* copy the argument list in case a rollback is needed */
 1195|  5.18k|    va_copy(ap_copy, ap);
 1196|       |
 1197|  5.18k|    if (argc > 256) {
  ------------------
  |  Branch (1197:9): [True: 0, False: 5.18k]
  ------------------
 1198|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1199|      0|        goto cleanup;
 1200|      0|    }
 1201|       |
 1202|  15.2k|    for (count = 0; *p != '\0'; p++, count++) {
  ------------------
  |  Branch (1202:21): [True: 10.1k, False: 5.18k]
  ------------------
 1203|       |        /* Invalid number of arguments passed */
 1204|  10.1k|        if (count > argc) {
  ------------------
  |  Branch (1204:13): [True: 0, False: 10.1k]
  ------------------
 1205|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1206|      0|            goto cleanup;
 1207|      0|        }
 1208|       |
 1209|  10.1k|        rc = SSH_ERROR;
  ------------------
  |  |  317|  10.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1210|  10.1k|        switch (*p) {
 1211|    273|        case 'b':
  ------------------
  |  Branch (1211:9): [True: 273, False: 9.82k]
  ------------------
 1212|    273|            o.byte = va_arg(ap, uint8_t *);
 1213|    273|            rlen = ssh_buffer_get_u8(buffer, o.byte);
 1214|    273|            rc = rlen==1 ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
                          rc = rlen==1 ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1214:18): [True: 273, False: 0]
  ------------------
 1215|    273|            break;
 1216|      0|        case 'w':
  ------------------
  |  Branch (1216:9): [True: 0, False: 10.1k]
  ------------------
 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|  3.82k|        case 'd':
  ------------------
  |  Branch (1224:9): [True: 3.82k, False: 6.27k]
  ------------------
 1225|  3.82k|            o.dword = va_arg(ap, uint32_t *);
 1226|  3.82k|            rlen = ssh_buffer_get_u32(buffer, o.dword);
 1227|  3.82k|            if (rlen == 4) {
  ------------------
  |  Branch (1227:17): [True: 3.82k, False: 0]
  ------------------
 1228|  3.82k|                *o.dword = ntohl(*o.dword);
 1229|  3.82k|                rc = SSH_OK;
  ------------------
  |  |  316|  3.82k|#define SSH_OK 0     /* No error */
  ------------------
 1230|  3.82k|            }
 1231|  3.82k|            break;
 1232|      0|        case 'q':
  ------------------
  |  Branch (1232:9): [True: 0, False: 10.1k]
  ------------------
 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: 10.1k]
  ------------------
 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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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|  1.36k|        case 'S':
  ------------------
  |  Branch (1252:9): [True: 1.36k, False: 8.73k]
  ------------------
 1253|  1.36k|            o.string = va_arg(ap, ssh_string *);
 1254|  1.36k|            *o.string = ssh_buffer_get_ssh_string(buffer);
 1255|  1.36k|            rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  316|  1.36k|#define SSH_OK 0     /* No error */
  ------------------
                          rc = *o.string != NULL ? SSH_OK : SSH_ERROR;
  ------------------
  |  |  317|  1.36k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1255:18): [True: 1.36k, False: 0]
  ------------------
 1256|  1.36k|            o.string = NULL;
 1257|  1.36k|            break;
 1258|  4.36k|        case 's': {
  ------------------
  |  Branch (1258:9): [True: 4.36k, False: 5.73k]
  ------------------
 1259|  4.36k|            uint32_t u32len = 0;
 1260|       |
 1261|  4.36k|            o.cstring = va_arg(ap, char **);
 1262|  4.36k|            *o.cstring = NULL;
 1263|  4.36k|            rlen = ssh_buffer_get_u32(buffer, &u32len);
 1264|  4.36k|            if (rlen != 4){
  ------------------
  |  Branch (1264:17): [True: 0, False: 4.36k]
  ------------------
 1265|      0|                break;
 1266|      0|            }
 1267|  4.36k|            u32len = ntohl(u32len);
 1268|  4.36k|            if (u32len > max_len - 1) {
  ------------------
  |  Branch (1268:17): [True: 0, False: 4.36k]
  ------------------
 1269|      0|                break;
 1270|      0|            }
 1271|       |
 1272|  4.36k|            rc = ssh_buffer_validate_length(buffer, u32len);
 1273|  4.36k|            if (rc != SSH_OK) {
  ------------------
  |  |  316|  4.36k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1273:17): [True: 0, False: 4.36k]
  ------------------
 1274|      0|                break;
 1275|      0|            }
 1276|       |
 1277|  4.36k|            *o.cstring = malloc(u32len + 1);
 1278|  4.36k|            if (*o.cstring == NULL){
  ------------------
  |  Branch (1278:17): [True: 0, False: 4.36k]
  ------------------
 1279|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1280|      0|                break;
 1281|      0|            }
 1282|  4.36k|            rlen = ssh_buffer_get_data(buffer, *o.cstring, u32len);
 1283|  4.36k|            if (rlen != u32len) {
  ------------------
  |  Branch (1283:17): [True: 0, False: 4.36k]
  ------------------
 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|  4.36k|            (*o.cstring)[u32len] = '\0';
 1289|  4.36k|            o.cstring = NULL;
 1290|  4.36k|            rc = SSH_OK;
  ------------------
  |  |  316|  4.36k|#define SSH_OK 0     /* No error */
  ------------------
 1291|  4.36k|            break;
 1292|  4.36k|        }
 1293|    273|        case 'P':
  ------------------
  |  Branch (1293:9): [True: 273, False: 9.82k]
  ------------------
 1294|    273|            len = va_arg(ap, size_t);
 1295|    273|            if (len > max_len - 1) {
  ------------------
  |  Branch (1295:17): [True: 0, False: 273]
  ------------------
 1296|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1297|      0|                break;
 1298|      0|            }
 1299|       |
 1300|    273|            rc = ssh_buffer_validate_length(buffer, len);
 1301|    273|            if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1301:17): [True: 0, False: 273]
  ------------------
 1302|      0|                break;
 1303|      0|            }
 1304|       |
 1305|    273|            o.data = va_arg(ap, void **);
 1306|    273|            count++;
 1307|       |
 1308|    273|            *o.data = malloc(len);
 1309|    273|            if(*o.data == NULL){
  ------------------
  |  Branch (1309:16): [True: 0, False: 273]
  ------------------
 1310|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1311|      0|                break;
 1312|      0|            }
 1313|    273|            rlen = ssh_buffer_get_data(buffer, *o.data, (uint32_t)len);
 1314|    273|            if (rlen != len){
  ------------------
  |  Branch (1314:17): [True: 0, False: 273]
  ------------------
 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|    273|            o.data = NULL;
 1320|    273|            rc = SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
 1321|    273|            break;
 1322|      0|        default:
  ------------------
  |  Branch (1322:9): [True: 0, False: 10.1k]
  ------------------
 1323|      0|            SSH_LOG(SSH_LOG_TRACE, "Invalid buffer format %c", *p);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1324|  10.1k|        }
 1325|  10.1k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  10.1k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1325:13): [True: 0, False: 10.1k]
  ------------------
 1326|      0|            break;
 1327|      0|        }
 1328|  10.1k|    }
 1329|       |
 1330|  5.18k|    if (argc != count) {
  ------------------
  |  Branch (1330:9): [True: 0, False: 5.18k]
  ------------------
 1331|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1332|      0|    }
 1333|       |
 1334|  5.18k|cleanup:
 1335|  5.18k|    if (rc != SSH_ERROR){
  ------------------
  |  |  317|  5.18k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1335:9): [True: 5.18k, False: 0]
  ------------------
 1336|       |        /* Check if our canary is intact, if not something really bad happened */
 1337|  5.18k|        uint32_t canary = va_arg(ap, uint32_t);
 1338|  5.18k|        if (canary != SSH_BUFFER_PACK_END){
  ------------------
  |  |   28|  5.18k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  ------------------
  |  Branch (1338:13): [True: 0, False: 5.18k]
  ------------------
 1339|      0|            abort();
 1340|      0|        }
 1341|  5.18k|    }
 1342|       |
 1343|  5.18k|    if (rc != SSH_OK){
  ------------------
  |  |  316|  5.18k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1343:9): [True: 0, False: 5.18k]
  ------------------
 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|  5.18k|    va_end(ap_copy);
 1409|       |
 1410|  5.18k|    return rc;
 1411|  5.18k|}
_ssh_buffer_unpack:
 1439|  5.18k|{
 1440|  5.18k|    va_list ap;
 1441|  5.18k|    int rc;
 1442|       |
 1443|  5.18k|    va_start(ap, argc);
 1444|  5.18k|    rc = ssh_buffer_unpack_va(buffer, format, argc, ap);
 1445|       |    va_end(ap);
 1446|  5.18k|    return rc;
 1447|  5.18k|}
buffer.c:realloc_buffer:
  188|  21.5k|{
  189|  21.5k|    uint32_t smallest = 1;
  190|  21.5k|    uint8_t *new = NULL;
  191|       |
  192|  21.5k|    buffer_verify(buffer);
  193|       |
  194|       |    /* Find the smallest power of two which is greater or equal to needed */
  195|   193k|    while(smallest <= needed) {
  ------------------
  |  Branch (195:11): [True: 171k, False: 21.5k]
  ------------------
  196|   171k|        if (smallest == 0) {
  ------------------
  |  Branch (196:13): [True: 0, False: 171k]
  ------------------
  197|      0|            return -1;
  198|      0|        }
  199|   171k|        smallest <<= 1;
  200|   171k|    }
  201|  21.5k|    needed = smallest;
  202|       |
  203|  21.5k|    if (needed > BUFFER_SIZE_MAX) {
  ------------------
  |  |   57|  21.5k|#define BUFFER_SIZE_MAX 0x10000000
  ------------------
  |  Branch (203:9): [True: 0, False: 21.5k]
  ------------------
  204|      0|        return -1;
  205|      0|    }
  206|       |
  207|  21.5k|    if (buffer->secure) {
  ------------------
  |  Branch (207:9): [True: 819, False: 20.7k]
  ------------------
  208|    819|        new = malloc(needed);
  209|    819|        if (new == NULL) {
  ------------------
  |  Branch (209:13): [True: 0, False: 819]
  ------------------
  210|      0|            return -1;
  211|      0|        }
  212|    819|        memcpy(new, buffer->data, buffer->used);
  213|    819|        ssh_burn(buffer->data, buffer->used);
  ------------------
  |  |  388|    819|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  214|    819|        SAFE_FREE(buffer->data);
  ------------------
  |  |  373|    819|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 819, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 819]
  |  |  ------------------
  ------------------
  215|  20.7k|    } else {
  216|  20.7k|        new = realloc(buffer->data, needed);
  217|  20.7k|        if (new == NULL) {
  ------------------
  |  Branch (217:13): [True: 0, False: 20.7k]
  ------------------
  218|      0|            return -1;
  219|      0|        }
  220|  20.7k|    }
  221|  21.5k|    buffer->data = new;
  222|  21.5k|    buffer->allocated = needed;
  223|       |
  224|  21.5k|    buffer_verify(buffer);
  225|  21.5k|    return 0;
  226|  21.5k|}
buffer.c:ssh_buffer_pack_allocate_va:
  880|  10.3k|{
  881|  10.3k|    const char *p = NULL;
  882|  10.3k|    ssh_string string = NULL;
  883|  10.3k|    char *cstring = NULL;
  884|  10.3k|    bignum b = NULL;
  885|  10.3k|    size_t needed_size = 0;
  886|  10.3k|    size_t len;
  887|  10.3k|    size_t count;
  888|  10.3k|    int rc = SSH_OK;
  ------------------
  |  |  316|  10.3k|#define SSH_OK 0     /* No error */
  ------------------
  889|       |
  890|  36.5k|    for (p = format, count = 0; *p != '\0'; p++, count++) {
  ------------------
  |  Branch (890:33): [True: 26.2k, False: 10.3k]
  ------------------
  891|       |        /* Invalid number of arguments passed */
  892|  26.2k|        if (count > argc) {
  ------------------
  |  Branch (892:13): [True: 0, False: 26.2k]
  ------------------
  893|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  894|      0|        }
  895|       |
  896|  26.2k|        switch(*p) {
  897|  5.46k|        case 'b':
  ------------------
  |  Branch (897:9): [True: 5.46k, False: 20.7k]
  ------------------
  898|  5.46k|            va_arg(ap, unsigned int);
  899|  5.46k|            needed_size += sizeof(uint8_t);
  900|  5.46k|            break;
  901|      0|        case 'w':
  ------------------
  |  Branch (901:9): [True: 0, False: 26.2k]
  ------------------
  902|      0|            va_arg(ap, unsigned int);
  903|      0|            needed_size += sizeof(uint16_t);
  904|      0|            break;
  905|  7.37k|        case 'd':
  ------------------
  |  Branch (905:9): [True: 7.37k, False: 18.8k]
  ------------------
  906|  7.37k|            va_arg(ap, uint32_t);
  907|  7.37k|            needed_size += sizeof(uint32_t);
  908|  7.37k|            break;
  909|      0|        case 'q':
  ------------------
  |  Branch (909:9): [True: 0, False: 26.2k]
  ------------------
  910|      0|            va_arg(ap, uint64_t);
  911|      0|            needed_size += sizeof(uint64_t);
  912|      0|            break;
  913|  2.45k|        case 'S':
  ------------------
  |  Branch (913:9): [True: 2.45k, False: 23.7k]
  ------------------
  914|  2.45k|            string = va_arg(ap, ssh_string);
  915|  2.45k|            needed_size += sizeof(uint32_t) + ssh_string_len(string);
  916|  2.45k|            string = NULL;
  917|  2.45k|            break;
  918|  5.46k|        case 's':
  ------------------
  |  Branch (918:9): [True: 5.46k, False: 20.7k]
  ------------------
  919|  5.46k|            cstring = va_arg(ap, char *);
  920|  5.46k|            needed_size += sizeof(uint32_t) + strlen(cstring);
  921|  5.46k|            cstring = NULL;
  922|  5.46k|            break;
  923|  5.46k|        case 'P':
  ------------------
  |  Branch (923:9): [True: 5.46k, False: 20.7k]
  ------------------
  924|  5.46k|            len = va_arg(ap, size_t);
  925|  5.46k|            needed_size += len;
  926|  5.46k|            va_arg(ap, void *);
  927|  5.46k|            count++; /* increase argument count */
  928|  5.46k|            break;
  929|      0|        case 'B':
  ------------------
  |  Branch (929:9): [True: 0, False: 26.2k]
  ------------------
  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: 26.2k]
  ------------------
  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: 26.2k]
  ------------------
  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|  26.2k|        }
  943|  26.2k|        if (rc != SSH_OK){
  ------------------
  |  |  316|  26.2k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (943:13): [True: 0, False: 26.2k]
  ------------------
  944|      0|            break;
  945|      0|        }
  946|  26.2k|    }
  947|       |
  948|  10.3k|    if (argc != count) {
  ------------------
  |  Branch (948:9): [True: 0, False: 10.3k]
  ------------------
  949|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  950|      0|    }
  951|       |
  952|  10.3k|    if (rc != SSH_ERROR){
  ------------------
  |  |  317|  10.3k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (952:9): [True: 10.3k, False: 1]
  ------------------
  953|       |        /*
  954|       |         * Check if our canary is intact, if not, something really bad happened.
  955|       |         */
  956|  10.3k|        uint32_t canary = va_arg(ap, uint32_t);
  957|  10.3k|        if (canary != SSH_BUFFER_PACK_END) {
  ------------------
  |  |   28|  10.3k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  ------------------
  |  Branch (957:13): [True: 0, False: 10.3k]
  ------------------
  958|      0|            abort();
  959|      0|        }
  960|  10.3k|    }
  961|       |
  962|  10.3k|    rc = ssh_buffer_allocate_size(buffer, (uint32_t)needed_size);
  963|  10.3k|    if (rc != 0) {
  ------------------
  |  Branch (963:9): [True: 0, False: 10.3k]
  ------------------
  964|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  965|      0|    }
  966|       |
  967|  10.3k|    return SSH_OK;
  ------------------
  |  |  316|  10.3k|#define SSH_OK 0     /* No error */
  ------------------
  968|  10.3k|}
buffer.c:ssh_buffer_pack_va:
  987|  10.3k|{
  988|  10.3k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  10.3k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  989|  10.3k|    const char *p = NULL;
  990|  10.3k|    union {
  991|  10.3k|        uint8_t byte;
  992|  10.3k|        uint16_t word;
  993|  10.3k|        uint32_t dword;
  994|  10.3k|        uint64_t qword;
  995|  10.3k|        ssh_string string;
  996|  10.3k|        void *data;
  997|  10.3k|    } o;
  998|  10.3k|    char *cstring = NULL;
  999|  10.3k|    bignum b;
 1000|  10.3k|    size_t len;
 1001|  10.3k|    size_t count;
 1002|       |
 1003|  10.3k|    if (argc > 256) {
  ------------------
  |  Branch (1003:9): [True: 0, False: 10.3k]
  ------------------
 1004|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1005|      0|    }
 1006|       |
 1007|  36.5k|    for (p = format, count = 0; *p != '\0'; p++, count++) {
  ------------------
  |  Branch (1007:33): [True: 26.2k, False: 10.3k]
  ------------------
 1008|       |        /* Invalid number of arguments passed */
 1009|  26.2k|        if (count > argc) {
  ------------------
  |  Branch (1009:13): [True: 0, False: 26.2k]
  ------------------
 1010|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1011|      0|        }
 1012|       |
 1013|  26.2k|        switch(*p) {
 1014|  5.46k|        case 'b':
  ------------------
  |  Branch (1014:9): [True: 5.46k, False: 20.7k]
  ------------------
 1015|  5.46k|            o.byte = (uint8_t)va_arg(ap, unsigned int);
 1016|  5.46k|            rc = ssh_buffer_add_u8(buffer, o.byte);
 1017|  5.46k|            break;
 1018|      0|        case 'w':
  ------------------
  |  Branch (1018:9): [True: 0, False: 26.2k]
  ------------------
 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|  7.37k|        case 'd':
  ------------------
  |  Branch (1023:9): [True: 7.37k, False: 18.8k]
  ------------------
 1024|  7.37k|            o.dword = va_arg(ap, uint32_t);
 1025|  7.37k|            o.dword = htonl(o.dword);
 1026|  7.37k|            rc = ssh_buffer_add_u32(buffer, o.dword);
 1027|  7.37k|            break;
 1028|      0|        case 'q':
  ------------------
  |  Branch (1028:9): [True: 0, False: 26.2k]
  ------------------
 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|  2.45k|        case 'S':
  ------------------
  |  Branch (1033:9): [True: 2.45k, False: 23.7k]
  ------------------
 1034|  2.45k|            o.string = va_arg(ap, ssh_string);
 1035|  2.45k|            rc = ssh_buffer_add_ssh_string(buffer, o.string);
 1036|  2.45k|            o.string = NULL;
 1037|  2.45k|            break;
 1038|  5.46k|        case 's':
  ------------------
  |  Branch (1038:9): [True: 5.46k, False: 20.7k]
  ------------------
 1039|  5.46k|            cstring = va_arg(ap, char *);
 1040|  5.46k|            len = strlen(cstring);
 1041|  5.46k|            if (len > UINT32_MAX) {
  ------------------
  |  Branch (1041:17): [True: 0, False: 5.46k]
  ------------------
 1042|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1043|      0|                break;
 1044|      0|            }
 1045|  5.46k|            o.dword = (uint32_t)len;
 1046|  5.46k|            rc = ssh_buffer_add_u32(buffer, htonl(o.dword));
 1047|  5.46k|            if (rc == SSH_OK){
  ------------------
  |  |  316|  5.46k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1047:17): [True: 5.46k, False: 0]
  ------------------
 1048|  5.46k|                rc = ssh_buffer_add_data(buffer, cstring, o.dword);
 1049|  5.46k|            }
 1050|  5.46k|            cstring = NULL;
 1051|  5.46k|            break;
 1052|  5.46k|        case 'P':
  ------------------
  |  Branch (1052:9): [True: 5.46k, False: 20.7k]
  ------------------
 1053|  5.46k|            len = va_arg(ap, size_t);
 1054|  5.46k|            if (len > UINT32_MAX) {
  ------------------
  |  Branch (1054:17): [True: 0, False: 5.46k]
  ------------------
 1055|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1056|      0|                break;
 1057|      0|            }
 1058|       |
 1059|  5.46k|            o.data = va_arg(ap, void *);
 1060|  5.46k|            count++; /* increase argument count */
 1061|       |
 1062|  5.46k|            rc = ssh_buffer_add_data(buffer, o.data, (uint32_t)len);
 1063|  5.46k|            o.data = NULL;
 1064|  5.46k|            break;
 1065|      0|        case 'B':
  ------------------
  |  Branch (1065:9): [True: 0, False: 26.2k]
  ------------------
 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: 26.2k]
  ------------------
 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: 26.2k]
  ------------------
 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|  26.2k|        }
 1089|  26.2k|        if (rc != SSH_OK){
  ------------------
  |  |  316|  26.2k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1089:13): [True: 0, False: 26.2k]
  ------------------
 1090|      0|            break;
 1091|      0|        }
 1092|  26.2k|    }
 1093|       |
 1094|  10.3k|    if (argc != count) {
  ------------------
  |  Branch (1094:9): [True: 0, False: 10.3k]
  ------------------
 1095|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1096|      0|    }
 1097|       |
 1098|  10.3k|    if (rc != SSH_ERROR){
  ------------------
  |  |  317|  10.3k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1098:9): [True: 10.3k, False: 0]
  ------------------
 1099|       |        /* Check if our canary is intact, if not something really bad happened */
 1100|  10.3k|        uint32_t canary = va_arg(ap, uint32_t);
 1101|  10.3k|        if (canary != SSH_BUFFER_PACK_END) {
  ------------------
  |  |   28|  10.3k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  ------------------
  |  Branch (1101:13): [True: 0, False: 10.3k]
  ------------------
 1102|      0|            abort();
 1103|      0|        }
 1104|  10.3k|    }
 1105|  10.3k|    return rc;
 1106|  10.3k|}

_ssh_remove_legacy_log_cb:
   49|    546|{
   50|    546|    if (ssh_get_log_callback() == ssh_legacy_log_callback) {
  ------------------
  |  Branch (50:9): [True: 0, False: 546]
  ------------------
   51|      0|        _ssh_reset_log_cb();
   52|       |        ssh_set_log_userdata(NULL);
   53|      0|    }
   54|    546|}
ssh_set_channel_callbacks:
  114|    273|{
  115|    273|    return ssh_add_set_channel_callbacks(channel, cb, 1);
  116|    273|}
ssh_set_server_callbacks:
  142|    273|{
  143|    273|    if (session == NULL || cb == NULL) {
  ------------------
  |  Branch (143:9): [True: 0, False: 273]
  |  Branch (143:28): [True: 0, False: 273]
  ------------------
  144|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  145|      0|    }
  146|       |
  147|    273|    if (!is_callback_valid(session, cb)) {
  ------------------
  |  |   31|    273|    (cb->size > 0 || cb->size <= 1024 * sizeof(void *))
  |  |  ------------------
  |  |  |  Branch (31:6): [True: 273, 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|    273|    };
  153|    273|    session->server_callbacks = cb;
  154|       |
  155|    273|    return 0;
  156|    273|}
callbacks.c:ssh_add_set_channel_callbacks:
   82|    273|{
   83|    273|    ssh_session session = NULL;
   84|    273|    int rc;
   85|       |
   86|    273|    if (channel == NULL || cb == NULL) {
  ------------------
  |  Branch (86:9): [True: 0, False: 273]
  |  Branch (86:28): [True: 0, False: 273]
  ------------------
   87|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   88|      0|    }
   89|    273|    session = channel->session;
   90|       |
   91|    273|    if (!is_callback_valid(session, cb)) {
  ------------------
  |  |   31|    273|    (cb->size > 0 || cb->size <= 1024 * sizeof(void *))
  |  |  ------------------
  |  |  |  Branch (31:6): [True: 273, 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|    273|    };
   97|    273|    if (channel->callbacks == NULL) {
  ------------------
  |  Branch (97:9): [True: 273, False: 0]
  ------------------
   98|    273|        channel->callbacks = ssh_list_new();
   99|    273|        if (channel->callbacks == NULL) {
  ------------------
  |  Branch (99:13): [True: 0, False: 273]
  ------------------
  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|    273|    }
  104|    273|    if (prepend) {
  ------------------
  |  Branch (104:9): [True: 273, False: 0]
  ------------------
  105|    273|        rc = ssh_list_prepend(channel->callbacks, cb);
  106|    273|    } else {
  107|      0|        rc = ssh_list_append(channel->callbacks, cb);
  108|      0|    }
  109|       |
  110|    273|    return rc;
  111|    273|}

ssh_channel_new:
   91|    546|{
   92|    546|    ssh_channel channel = NULL;
   93|       |
   94|    546|    if (session == NULL) {
  ------------------
  |  Branch (94:9): [True: 0, False: 546]
  ------------------
   95|      0|        return NULL;
   96|      0|    }
   97|       |
   98|       |    /* Check if we have an authenticated session */
   99|    546|    if (!(session->flags & SSH_SESSION_FLAG_AUTHENTICATED)) {
  ------------------
  |  |   78|    546|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (99:9): [True: 0, False: 546]
  ------------------
  100|      0|        return NULL;
  101|      0|    }
  102|       |
  103|    546|    channel = calloc(1, sizeof(struct ssh_channel_struct));
  104|    546|    if (channel == NULL) {
  ------------------
  |  Branch (104:9): [True: 0, False: 546]
  ------------------
  105|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  106|      0|        return NULL;
  107|      0|    }
  108|       |
  109|    546|    channel->stdout_buffer = ssh_buffer_new();
  110|    546|    if (channel->stdout_buffer == NULL) {
  ------------------
  |  Branch (110:9): [True: 0, False: 546]
  ------------------
  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|    546|    channel->stderr_buffer = ssh_buffer_new();
  117|    546|    if (channel->stderr_buffer == NULL) {
  ------------------
  |  Branch (117:9): [True: 0, False: 546]
  ------------------
  118|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  119|      0|        SSH_BUFFER_FREE(channel->stdout_buffer);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957: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|    546|    channel->session = session;
  125|    546|    channel->exit.code = (uint32_t)-1;
  126|    546|    channel->flags = SSH_CHANNEL_FLAG_NOT_BOUND;
  ------------------
  |  |   64|    546|#define SSH_CHANNEL_FLAG_NOT_BOUND 0x0008
  ------------------
  127|       |
  128|    546|    if (session->channels == NULL) {
  ------------------
  |  Branch (128:9): [True: 546, False: 0]
  ------------------
  129|    546|        session->channels = ssh_list_new();
  130|    546|        if (session->channels == NULL) {
  ------------------
  |  Branch (130:13): [True: 0, False: 546]
  ------------------
  131|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  132|      0|            SSH_BUFFER_FREE(channel->stdout_buffer);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  133|      0|            SSH_BUFFER_FREE(channel->stderr_buffer);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957: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|    546|    }
  138|       |
  139|    546|    ssh_list_prepend(session->channels, channel);
  140|       |
  141|       |    /* Set states explicitly */
  142|    546|    channel->state = SSH_CHANNEL_STATE_NOT_OPEN;
  143|    546|    channel->request_state = SSH_CHANNEL_REQ_STATE_NONE;
  144|       |
  145|    546|    return channel;
  146|    546|}
ssh_channel_new_id:
  158|    546|{
  159|    546|    return ++(session->maxchannel);
  160|    546|}
ssh_packet_channel_open_conf:
  170|    273|{
  171|    273|    uint32_t channelid = 0;
  172|    273|    ssh_channel channel = NULL;
  173|    273|    int rc;
  174|    273|    (void)type;
  175|    273|    (void)user;
  176|       |
  177|    273|    SSH_LOG(SSH_LOG_PACKET, "Received SSH2_MSG_CHANNEL_OPEN_CONFIRMATION");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  178|       |
  179|    273|    rc = ssh_buffer_unpack(packet, "d", &channelid);
  ------------------
  |  |   60|    273|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  180|    273|    if (rc != SSH_OK)
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (180:9): [True: 0, False: 273]
  ------------------
  181|      0|        goto error;
  182|    273|    channel = ssh_channel_from_local(session, channelid);
  183|    273|    if (channel == NULL) {
  ------------------
  |  Branch (183:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|    273|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  194|    273|                           "ddd",
  195|    273|                           &channel->remote_channel,
  196|    273|                           &channel->remote_window,
  197|    273|                           &channel->remote_maxpacket);
  198|    273|    if (rc != SSH_OK)
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (198:9): [True: 0, False: 273]
  ------------------
  199|      0|        goto error;
  200|       |
  201|    273|    if (channel->remote_maxpacket == 0) {
  ------------------
  |  Branch (201:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  209|    273|            "Received a CHANNEL_OPEN_CONFIRMATION for channel %" PRIu32
  210|    273|            ":%" PRIu32,
  211|    273|            channel->local_channel,
  212|    273|            channel->remote_channel);
  213|       |
  214|    273|    if (channel->state != SSH_CHANNEL_STATE_OPENING) {
  ------------------
  |  Branch (214:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  223|    273|            "Remote window : %" PRIu32 ", maxpacket : %" PRIu32,
  224|    273|            channel->remote_window,
  225|    273|            channel->remote_maxpacket);
  226|       |
  227|    273|    channel->state = SSH_CHANNEL_STATE_OPEN;
  228|    273|    channel->flags &= ~SSH_CHANNEL_FLAG_NOT_BOUND;
  ------------------
  |  |   64|    273|#define SSH_CHANNEL_FLAG_NOT_BOUND 0x0008
  ------------------
  229|       |
  230|    273|    ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|    273|    do {                                                      \
  |  |  567|    273|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|    273|        cbtype cb;                                            \
  |  |  569|    273|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 0, False: 273]
  |  |  ------------------
  |  |  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|    273|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 273]
  |  |  ------------------
  ------------------
  231|    273|                               ssh_channel_callbacks,
  232|    273|                               channel_open_response_function,
  233|    273|                               channel->session,
  234|    273|                               channel,
  235|    273|                               true /* is_success */);
  236|       |
  237|    273|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    273|#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|    273|}
ssh_channel_from_local:
  420|  1.36k|{
  421|  1.36k|    struct ssh_iterator *it = NULL;
  422|  1.36k|    ssh_channel channel = NULL;
  423|       |
  424|  1.36k|    for (it = ssh_list_get_iterator(session->channels); it != NULL;
  ------------------
  |  Branch (424:57): [True: 1.36k, False: 0]
  ------------------
  425|  1.36k|         it = it->next) {
  426|  1.36k|        channel = ssh_iterator_value(ssh_channel, it);
  ------------------
  |  |  114|  1.36k|  ((type)((iterator)->data))
  ------------------
  427|  1.36k|        if (channel == NULL) {
  ------------------
  |  Branch (427:13): [True: 0, False: 1.36k]
  ------------------
  428|      0|            continue;
  429|      0|        }
  430|  1.36k|        if (channel->local_channel == id) {
  ------------------
  |  Branch (430:13): [True: 1.36k, False: 0]
  ------------------
  431|  1.36k|            return channel;
  432|  1.36k|        }
  433|  1.36k|    }
  434|       |
  435|      0|    return NULL;
  436|  1.36k|}
channel_rcv_data:
  603|    273|{
  604|    273|    ssh_channel channel = NULL;
  605|    273|    ssh_string str = NULL;
  606|    273|    ssh_buffer buf = NULL;
  607|    273|    void *data = NULL;
  608|    273|    uint32_t len;
  609|    273|    int extended, is_stderr = 0;
  610|    273|    int rest;
  611|       |
  612|    273|    (void)user;
  613|       |
  614|    273|    if (type == SSH2_MSG_CHANNEL_DATA) {
  ------------------
  |  |   58|    273|#define SSH2_MSG_CHANNEL_DATA 94
  ------------------
  |  Branch (614:9): [True: 273, False: 0]
  ------------------
  615|    273|        extended = 0;
  616|    273|    } else { /* SSH_MSG_CHANNEL_EXTENDED_DATA */
  617|      0|        extended = 1;
  618|      0|    }
  619|       |
  620|    273|    channel = channel_from_msg(session, packet);
  621|    273|    if (channel == NULL) {
  ------------------
  |  Branch (621:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (extended) {
  ------------------
  |  Branch (627:9): [True: 0, False: 273]
  ------------------
  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|    273|    str = ssh_buffer_get_ssh_string(packet);
  645|    273|    if (str == NULL) {
  ------------------
  |  Branch (645:9): [True: 0, False: 273]
  ------------------
  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|    273|    len = (uint32_t)ssh_string_len(str);
  652|       |
  653|    273|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 273]
  |  |  ------------------
  ------------------
  654|    273|            "Channel receiving %" PRIu32 " bytes data%s (local win=%" PRIu32
  655|    273|            " remote win=%" PRIu32 ") on channel %" PRIu32 ":%" PRIu32,
  656|    273|            len,
  657|    273|            is_stderr ? " in stderr" : "",
  658|    273|            channel->local_window,
  659|    273|            channel->remote_window,
  660|    273|            channel->local_channel,
  661|    273|            channel->remote_channel);
  662|       |
  663|    273|    if (len > channel->local_window) {
  ------------------
  |  Branch (663:9): [True: 0, False: 273]
  ------------------
  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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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|    273|    data = ssh_string_data(str);
  677|    273|    if (channel_default_bufferize(channel, data, len, is_stderr) < 0) {
  ------------------
  |  Branch (677:9): [True: 0, False: 273]
  ------------------
  678|      0|        SSH_STRING_FREE(str);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  679|       |
  680|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  681|      0|    }
  682|       |
  683|    273|    channel->local_window -= len;
  684|       |
  685|    273|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  686|    273|            "Channel windows are now (local win=%" PRIu32 " remote win=%" PRIu32 ")",
  687|    273|            channel->local_window,
  688|    273|            channel->remote_window);
  689|       |
  690|    273|    SSH_STRING_FREE(str);
  ------------------
  |  |  915|    273|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 273, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
  691|       |
  692|    273|    if (is_stderr) {
  ------------------
  |  Branch (692:9): [True: 0, False: 273]
  ------------------
  693|      0|        buf = channel->stderr_buffer;
  694|    273|    } else {
  695|    273|        buf = channel->stdout_buffer;
  696|    273|    }
  697|       |
  698|    273|    ssh_callbacks_iterate(channel->callbacks,
  ------------------
  |  |  598|    273|    do {                                                              \
  |  |  599|    273|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  600|    273|        _cb_type _cb;                                                 \
  |  |  601|    273|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (601:16): [True: 0, False: 273]
  |  |  ------------------
  |  |  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|    273|                          ssh_channel_callbacks,
  700|    273|                          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|    273|    ssh_callbacks_iterate_end();
  ------------------
  |  |  618|      0|        }                           \
  |  |  619|    273|    } while(0)
  |  |  ------------------
  |  |  |  Branch (619:13): [Folded, False: 273]
  |  |  ------------------
  ------------------
  724|       |
  725|    273|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    273|#define SSH_PACKET_USED 1
  ------------------
  726|    273|}
channel_rcv_eof:
  729|    273|{
  730|    273|    ssh_channel channel = NULL;
  731|    273|    (void)user;
  732|    273|    (void)type;
  733|       |
  734|    273|    channel = channel_from_msg(session, packet);
  735|    273|    if (channel == NULL) {
  ------------------
  |  Branch (735:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  742|    273|            "Received eof on channel (%" PRIu32 ":%" PRIu32 ")",
  743|    273|            channel->local_channel,
  744|    273|            channel->remote_channel);
  745|       |    /* channel->remote_window = 0; */
  746|    273|    channel->remote_eof = 1;
  747|       |
  748|    273|    ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|    273|    do {                                                      \
  |  |  567|    273|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|    273|        cbtype cb;                                            \
  |  |  569|    273|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 0, False: 273]
  |  |  ------------------
  |  |  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|    273|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 273]
  |  |  ------------------
  ------------------
  749|    273|                               ssh_channel_callbacks,
  750|    273|                               channel_eof_function,
  751|    273|                               channel->session,
  752|    273|                               channel);
  753|       |
  754|    273|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    273|#define SSH_PACKET_USED 1
  ------------------
  755|    273|}
channel_rcv_close:
  775|    273|{
  776|    273|    ssh_channel channel = NULL;
  777|    273|    (void)user;
  778|    273|    (void)type;
  779|       |
  780|    273|    channel = channel_from_msg(session,packet);
  781|    273|    if (channel == NULL) {
  ------------------
  |  Branch (781:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  788|    273|        "Received close on channel (%" PRIu32 ":%" PRIu32 ")",
  789|    273|        channel->local_channel,
  790|    273|        channel->remote_channel);
  791|       |
  792|    273|    if (!ssh_channel_has_unread_data(channel)) {
  ------------------
  |  Branch (792:9): [True: 0, False: 273]
  ------------------
  793|      0|        channel->state = SSH_CHANNEL_STATE_CLOSED;
  794|    273|    } else {
  795|    273|        channel->delayed_close = 1;
  796|    273|    }
  797|       |
  798|    273|    if (channel->remote_eof == 0) {
  ------------------
  |  Branch (798:9): [True: 0, False: 273]
  ------------------
  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|    273|    channel->remote_eof = 1;
  807|       |
  808|    273|    ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|    273|    do {                                                      \
  |  |  567|    273|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|    273|        cbtype cb;                                            \
  |  |  569|    273|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 0, False: 273]
  |  |  ------------------
  |  |  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|    273|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 273]
  |  |  ------------------
  ------------------
  809|    273|                               ssh_channel_callbacks,
  810|    273|                               channel_close_function,
  811|    273|                               channel->session,
  812|    273|                               channel);
  813|       |
  814|    273|    channel->flags |= SSH_CHANNEL_FLAG_CLOSED_REMOTE;
  ------------------
  |  |   55|    273|#define SSH_CHANNEL_FLAG_CLOSED_REMOTE 0x0001
  ------------------
  815|    273|    if(channel->flags & SSH_CHANNEL_FLAG_FREED_LOCAL)
  ------------------
  |  |   61|    273|#define SSH_CHANNEL_FLAG_FREED_LOCAL 0x0004
  ------------------
  |  Branch (815:8): [True: 0, False: 273]
  ------------------
  816|      0|        ssh_channel_do_free(channel);
  817|       |
  818|    273|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    273|#define SSH_PACKET_USED 1
  ------------------
  819|    273|}
channel_rcv_request:
  822|    273|{
  823|    273|    ssh_channel channel = NULL;
  824|    273|    char *request = NULL;
  825|    273|    uint8_t want_reply;
  826|    273|    int rc;
  827|    273|    (void)user;
  828|    273|    (void)type;
  829|       |
  830|    273|    channel = channel_from_msg(session, packet);
  831|    273|    if (channel == NULL) {
  ------------------
  |  Branch (831:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_buffer_unpack(packet, "sb", &request, &want_reply);
  ------------------
  |  |   60|    273|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  837|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (837:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (strcmp(request, "exit-status") == 0) {
  ------------------
  |  Branch (842:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (strcmp(request, "signal") == 0) {
  ------------------
  |  Branch (867:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (strcmp(request, "exit-signal") == 0) {
  ------------------
  |  Branch (891:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (strcmp(request, "keepalive@openssh.com") == 0) {
  ------------------
  |  Branch (941:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (strcmp(request, "auth-agent-req") == 0 ||
  ------------------
  |  Branch (957:9): [True: 0, False: 273]
  ------------------
  958|    273|        strcmp(request, "auth-agent-req@openssh.com") == 0) {
  ------------------
  |  Branch (958:9): [True: 0, False: 273]
  ------------------
  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|    273|#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|    273|    ssh_message_handle_channel_request(session,
  997|    273|                                       channel,
  998|    273|                                       packet,
  999|    273|                                       request,
 1000|    273|                                       want_reply);
 1001|       |#else
 1002|       |    SSH_LOG(SSH_LOG_DEBUG, "Unhandled channel request %s", request);
 1003|       |#endif
 1004|       |
 1005|    273|    SAFE_FREE(request);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
 1006|       |
 1007|    273|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    273|#define SSH_PACKET_USED 1
  ------------------
 1008|    273|}
channel_default_bufferize:
 1019|    273|{
 1020|    273|    ssh_session session = NULL;
 1021|       |
 1022|    273|    if (channel == NULL) {
  ------------------
  |  Branch (1022:9): [True: 0, False: 273]
  ------------------
 1023|      0|        return -1;
 1024|      0|    }
 1025|       |
 1026|    273|    session = channel->session;
 1027|       |
 1028|    273|    if (data == NULL) {
  ------------------
  |  Branch (1028:9): [True: 0, False: 273]
  ------------------
 1029|      0|        ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1030|      0|        return -1;
 1031|      0|    }
 1032|       |
 1033|    273|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 273]
  |  |  ------------------
  ------------------
 1034|    273|            "placing %" PRIu32 " bytes into channel buffer (%s)",
 1035|    273|            len,
 1036|    273|            is_stderr ? "stderr" : "stdout");
 1037|    273|    if (!is_stderr) {
  ------------------
  |  Branch (1037:9): [True: 273, False: 0]
  ------------------
 1038|       |        /* stdout */
 1039|    273|        if (channel->stdout_buffer == NULL) {
  ------------------
  |  Branch (1039:13): [True: 0, False: 273]
  ------------------
 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|    273|        if (ssh_buffer_add_data(channel->stdout_buffer, data, len) < 0) {
  ------------------
  |  Branch (1047:13): [True: 0, False: 273]
  ------------------
 1048|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1049|      0|            SSH_BUFFER_FREE(channel->stdout_buffer);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1050|      0|            channel->stdout_buffer = NULL;
 1051|      0|            return -1;
 1052|      0|        }
 1053|    273|    } 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);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1066|      0|            channel->stderr_buffer = NULL;
 1067|      0|            return -1;
 1068|      0|        }
 1069|      0|    }
 1070|       |
 1071|    273|    return 0;
 1072|    273|}
ssh_channel_open_session:
 1090|    273|{
 1091|    273|  if (channel == NULL) {
  ------------------
  |  Branch (1091:7): [True: 0, False: 273]
  ------------------
 1092|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1093|      0|  }
 1094|       |
 1095|    273|  return channel_open(channel,
 1096|    273|                      "session",
 1097|    273|                      WINDOW_DEFAULT,
  ------------------
  |  |   67|    273|#define WINDOW_DEFAULT (64*CHANNEL_MAX_PACKET)
  |  |  ------------------
  |  |  |  |   60|    273|#define CHANNEL_MAX_PACKET 32768
  |  |  ------------------
  ------------------
 1098|    273|                      CHANNEL_MAX_PACKET,
  ------------------
  |  |   60|    273|#define CHANNEL_MAX_PACKET 32768
  ------------------
 1099|       |                      NULL);
 1100|    273|}
ssh_channel_free:
 1294|    273|{
 1295|    273|    ssh_session session = NULL;
 1296|       |
 1297|    273|    if (channel == NULL) {
  ------------------
  |  Branch (1297:9): [True: 0, False: 273]
  ------------------
 1298|      0|        return;
 1299|      0|    }
 1300|       |
 1301|    273|    session = channel->session;
 1302|    273|    if (session->alive) {
  ------------------
  |  Branch (1302:9): [True: 0, False: 273]
  ------------------
 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|    273|    channel->flags |= SSH_CHANNEL_FLAG_FREED_LOCAL;
  ------------------
  |  |   61|    273|#define SSH_CHANNEL_FLAG_FREED_LOCAL 0x0004
  ------------------
 1327|       |
 1328|    273|    if (channel->callbacks != NULL) {
  ------------------
  |  Branch (1328:9): [True: 0, False: 273]
  ------------------
 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|    273|    if ((channel->flags & SSH_CHANNEL_FLAG_CLOSED_REMOTE) ||
  ------------------
  |  |   55|    273|#define SSH_CHANNEL_FLAG_CLOSED_REMOTE 0x0001
  ------------------
  |  Branch (1338:9): [True: 273, False: 0]
  ------------------
 1339|    273|        (channel->flags & SSH_CHANNEL_FLAG_NOT_BOUND)) {
  ------------------
  |  |   64|      0|#define SSH_CHANNEL_FLAG_NOT_BOUND 0x0008
  ------------------
  |  Branch (1339:9): [True: 0, False: 0]
  ------------------
 1340|    273|        ssh_channel_do_free(channel);
 1341|    273|    }
 1342|    273|}
ssh_channel_do_free:
 1350|    546|{
 1351|    546|    struct ssh_iterator *it = NULL;
 1352|    546|    ssh_session session = channel->session;
 1353|       |
 1354|    546|    it = ssh_list_find(session->channels, channel);
 1355|    546|    if (it != NULL) {
  ------------------
  |  Branch (1355:9): [True: 546, False: 0]
  ------------------
 1356|    546|        ssh_list_remove(session->channels, it);
 1357|    546|    }
 1358|       |
 1359|    546|    SSH_BUFFER_FREE(channel->stdout_buffer);
  ------------------
  |  |  957|    546|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 546, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
 1360|    546|    SSH_BUFFER_FREE(channel->stderr_buffer);
  ------------------
  |  |  957|    546|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 546, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
 1361|       |
 1362|    546|    if (channel->callbacks != NULL) {
  ------------------
  |  Branch (1362:9): [True: 273, False: 273]
  ------------------
 1363|    273|        ssh_list_free(channel->callbacks);
 1364|    273|        channel->callbacks = NULL;
 1365|    273|    }
 1366|    546|    SAFE_FREE(channel->exit.signal);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
 1367|       |
 1368|    546|    channel->session = NULL;
 1369|       |    SAFE_FREE(channel);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
 1370|    546|}
ssh_channel_send_eof:
 1401|  1.09k|{
 1402|  1.09k|    ssh_session session = NULL;
 1403|  1.09k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  1.09k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1404|  1.09k|    int err;
 1405|       |
 1406|  1.09k|    if (channel == NULL || channel->session == NULL) {
  ------------------
  |  Branch (1406:9): [True: 0, False: 1.09k]
  |  Branch (1406:28): [True: 0, False: 1.09k]
  ------------------
 1407|      0|        return rc;
 1408|      0|    }
 1409|       |
 1410|       |    /* If the EOF has already been sent we're done here. */
 1411|  1.09k|    if (channel->local_eof != 0) {
  ------------------
  |  Branch (1411:9): [True: 546, False: 546]
  ------------------
 1412|    546|        return SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
 1413|    546|    }
 1414|       |
 1415|    546|    session = channel->session;
 1416|       |
 1417|    546|    err = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    546|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    546|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    546|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    546|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    546|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1418|    546|                          "bd",
 1419|    546|                          SSH2_MSG_CHANNEL_EOF,
 1420|    546|                          channel->remote_channel);
 1421|    546|    if (err != SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1421:9): [True: 0, False: 546]
  ------------------
 1422|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1423|      0|        goto error;
 1424|      0|    }
 1425|       |
 1426|    546|    rc = ssh_packet_send(session);
 1427|    546|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1428|    546|        "Sent a EOF on client channel (%" PRIu32 ":%" PRIu32 ")",
 1429|    546|        channel->local_channel,
 1430|    546|        channel->remote_channel);
 1431|    546|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1431:9): [True: 0, False: 546]
  ------------------
 1432|      0|        goto error;
 1433|      0|    }
 1434|       |
 1435|    546|    rc = ssh_channel_flush(channel);
 1436|    546|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1436:9): [True: 0, False: 546]
  ------------------
 1437|      0|        goto error;
 1438|      0|    }
 1439|    546|    channel->local_eof = 1;
 1440|       |
 1441|    546|    return rc;
 1442|      0|error:
 1443|      0|    ssh_buffer_reinit(session->out_buffer);
 1444|       |
 1445|      0|    return rc;
 1446|    546|}
ssh_channel_close:
 1462|    546|{
 1463|    546|    ssh_session session = NULL;
 1464|    546|    int rc = 0;
 1465|       |
 1466|    546|    if(channel == NULL) {
  ------------------
  |  Branch (1466:8): [True: 0, False: 546]
  ------------------
 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|    546|    if (channel->flags & SSH_CHANNEL_FLAG_CLOSED_LOCAL) {
  ------------------
  |  |   58|    546|#define SSH_CHANNEL_FLAG_CLOSED_LOCAL 0x0002
  ------------------
  |  Branch (1471:9): [True: 0, False: 546]
  ------------------
 1472|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1473|      0|    }
 1474|       |
 1475|    546|    session = channel->session;
 1476|       |
 1477|    546|    rc = ssh_channel_send_eof(channel);
 1478|    546|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1478:9): [True: 0, False: 546]
  ------------------
 1479|      0|        return rc;
 1480|      0|    }
 1481|       |
 1482|    546|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    546|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    546|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    546|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    546|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    546|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1483|    546|                         "bd",
 1484|    546|                         SSH2_MSG_CHANNEL_CLOSE,
 1485|    546|                         channel->remote_channel);
 1486|    546|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1486:9): [True: 0, False: 546]
  ------------------
 1487|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1488|      0|        goto error;
 1489|      0|    }
 1490|       |
 1491|    546|    rc = ssh_packet_send(session);
 1492|    546|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1493|    546|            "Sent a close on client channel (%" PRIu32 ":%" PRIu32 ")",
 1494|    546|            channel->local_channel,
 1495|    546|            channel->remote_channel);
 1496|       |
 1497|    546|    if (rc == SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1497:9): [True: 273, False: 273]
  ------------------
 1498|    273|        channel->state = SSH_CHANNEL_STATE_CLOSED;
 1499|    273|        channel->flags |= SSH_CHANNEL_FLAG_CLOSED_LOCAL;
  ------------------
  |  |   58|    273|#define SSH_CHANNEL_FLAG_CLOSED_LOCAL 0x0002
  ------------------
 1500|    273|    }
 1501|       |
 1502|    546|    rc = ssh_channel_flush(channel);
 1503|    546|    if(rc == SSH_ERROR) {
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1503:8): [True: 0, False: 546]
  ------------------
 1504|      0|        goto error;
 1505|      0|    }
 1506|       |
 1507|    546|    return rc;
 1508|      0|error:
 1509|      0|    ssh_buffer_reinit(session->out_buffer);
 1510|       |
 1511|      0|    return rc;
 1512|    546|}
ssh_channel_flush:
 1551|  1.36k|{
 1552|  1.36k|    return ssh_blocking_flush(channel->session, SSH_TIMEOUT_DEFAULT);
  ------------------
  |  |  103|  1.36k|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
 1553|  1.36k|}
ssh_channel_write:
 1744|    273|{
 1745|    273|    return channel_write_common(channel, data, len, 0);
 1746|    273|}
ssh_channel_is_closed:
 1775|    819|{
 1776|    819|    if (channel == NULL || channel->session == NULL) {
  ------------------
  |  Branch (1776:9): [True: 0, False: 819]
  |  Branch (1776:28): [True: 0, False: 819]
  ------------------
 1777|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1778|      0|    }
 1779|    819|    return (channel->state != SSH_CHANNEL_STATE_OPEN || channel->session->alive == 0);
  ------------------
  |  Branch (1779:13): [True: 273, False: 546]
  |  Branch (1779:57): [True: 0, False: 546]
  ------------------
 1780|    819|}
ssh_channel_is_eof:
 1790|    819|{
 1791|    819|    if (channel == NULL) {
  ------------------
  |  Branch (1791:9): [True: 0, False: 819]
  ------------------
 1792|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1793|      0|    }
 1794|    819|    if (ssh_channel_has_unread_data(channel)) {
  ------------------
  |  Branch (1794:9): [True: 273, False: 546]
  ------------------
 1795|    273|        return 0;
 1796|    273|    }
 1797|       |
 1798|    546|    return (channel->remote_eof != 0);
 1799|    819|}
ssh_channel_request_exec:
 2877|    273|{
 2878|    273|  ssh_buffer buffer = NULL;
 2879|    273|  int rc = SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2880|       |
 2881|    273|  if(channel == NULL) {
  ------------------
  |  Branch (2881:6): [True: 0, False: 273]
  ------------------
 2882|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2883|      0|  }
 2884|    273|  if(cmd == NULL) {
  ------------------
  |  Branch (2884:6): [True: 0, False: 273]
  ------------------
 2885|      0|      ssh_set_error_invalid(channel->session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2886|      0|      return rc;
 2887|      0|  }
 2888|       |
 2889|    273|  switch(channel->request_state){
 2890|    273|  case SSH_CHANNEL_REQ_STATE_NONE:
  ------------------
  |  Branch (2890:3): [True: 273, False: 0]
  ------------------
 2891|    273|    break;
 2892|      0|  default:
  ------------------
  |  Branch (2892:3): [True: 0, False: 273]
  ------------------
 2893|      0|    goto pending;
 2894|    273|  }
 2895|    273|  buffer = ssh_buffer_new();
 2896|    273|  if (buffer == NULL) {
  ------------------
  |  Branch (2896:7): [True: 0, False: 273]
  ------------------
 2897|      0|    ssh_set_error_oom(channel->session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2898|      0|    goto error;
 2899|      0|  }
 2900|       |
 2901|    273|  rc = ssh_buffer_pack(buffer, "s", cmd);
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 2902|       |
 2903|    273|  if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2903:7): [True: 0, False: 273]
  ------------------
 2904|      0|    ssh_set_error_oom(channel->session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2905|      0|    goto error;
 2906|      0|  }
 2907|    273|pending:
 2908|    273|  rc = channel_request(channel, "exec", buffer, 1);
 2909|    273|error:
 2910|       |  SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  957|    273|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 273, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
 2911|    273|  return rc;
 2912|    273|}
ssh_channel_read:
 3139|    273|{
 3140|    273|    return ssh_channel_read_timeout(channel,
 3141|    273|                                    dest,
 3142|    273|                                    count,
 3143|    273|                                    is_stderr,
 3144|    273|                                    SSH_TIMEOUT_DEFAULT);
  ------------------
  |  |  103|    273|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
 3145|    273|}
ssh_channel_read_timeout:
 3172|    273|{
 3173|    273|    ssh_session session = NULL;
 3174|    273|    ssh_buffer stdbuf = NULL;
 3175|    273|    uint32_t len;
 3176|    273|    struct ssh_channel_read_termination_struct ctx;
 3177|    273|    int rc;
 3178|       |
 3179|    273|    if (channel == NULL) {
  ------------------
  |  Branch (3179:9): [True: 0, False: 273]
  ------------------
 3180|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3181|      0|    }
 3182|    273|    if (dest == NULL) {
  ------------------
  |  Branch (3182:9): [True: 0, False: 273]
  ------------------
 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|    273|    session = channel->session;
 3188|    273|    stdbuf = channel->stdout_buffer;
 3189|       |
 3190|    273|    if (count == 0) {
  ------------------
  |  Branch (3190:9): [True: 0, False: 273]
  ------------------
 3191|      0|        return 0;
 3192|      0|    }
 3193|       |
 3194|    273|    if (is_stderr) {
  ------------------
  |  Branch (3194:9): [True: 0, False: 273]
  ------------------
 3195|      0|        stdbuf = channel->stderr_buffer;
 3196|      0|    }
 3197|       |
 3198|    273|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3199|    273|            "Read (%" PRIu32 ") buffered : %" PRIu32 " bytes. Window: %" PRIu32,
 3200|    273|            count,
 3201|    273|            ssh_buffer_get_len(stdbuf),
 3202|    273|            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|    273|    ctx.channel = channel;
 3208|    273|    ctx.buffer = stdbuf;
 3209|       |
 3210|    273|    if (timeout_ms < SSH_TIMEOUT_DEFAULT) {
  ------------------
  |  |  103|    273|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
  |  Branch (3210:9): [True: 0, False: 273]
  ------------------
 3211|      0|        timeout_ms = SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|      0|#define SSH_TIMEOUT_INFINITE -1
  ------------------
 3212|      0|    }
 3213|       |
 3214|    273|    rc = ssh_handle_packets_termination(session,
 3215|    273|                                        timeout_ms,
 3216|    273|                                        ssh_channel_read_termination,
 3217|    273|                                        &ctx);
 3218|    273|    if (rc == SSH_ERROR || rc == SSH_AGAIN) {
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
                  if (rc == SSH_ERROR || rc == SSH_AGAIN) {
  ------------------
  |  |  318|    273|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (3218:9): [True: 0, False: 273]
  |  Branch (3218:28): [True: 0, False: 273]
  ------------------
 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|    273|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (3226:9): [True: 273, False: 0]
  ------------------
 3227|    273|        return SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3228|    273|    }
 3229|       |    /* If the server closed the channel properly, there is nothing to do */
 3230|      0|    if (channel->remote_eof && ssh_buffer_get_len(stdbuf) == 0) {
  ------------------
  |  Branch (3230:9): [True: 0, False: 0]
  |  Branch (3230:32): [True: 0, False: 0]
  ------------------
 3231|      0|        return 0;
 3232|      0|    }
 3233|      0|    if (channel->state == SSH_CHANNEL_STATE_CLOSED) {
  ------------------
  |  Branch (3233:9): [True: 0, False: 0]
  ------------------
 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|      0|    len = ssh_buffer_get_len(stdbuf);
 3238|       |    /* Read count bytes if len is greater, everything otherwise */
 3239|      0|    len = (len > count ? count : len);
  ------------------
  |  Branch (3239:12): [True: 0, False: 0]
  ------------------
 3240|      0|    memcpy(dest, ssh_buffer_get(stdbuf), len);
 3241|      0|    ssh_buffer_pass_bytes(stdbuf, len);
 3242|      0|    if (channel->counter != NULL) {
  ------------------
  |  Branch (3242:9): [True: 0, False: 0]
  ------------------
 3243|      0|        channel->counter->in_bytes += len;
 3244|      0|    }
 3245|       |    /* Try completing the delayed_close */
 3246|      0|    if (channel->delayed_close && !ssh_channel_has_unread_data(channel)) {
  ------------------
  |  Branch (3246:9): [True: 0, False: 0]
  |  Branch (3246:35): [True: 0, False: 0]
  ------------------
 3247|      0|        channel->state = SSH_CHANNEL_STATE_CLOSED;
 3248|      0|    }
 3249|       |
 3250|      0|    rc = grow_window(session, channel);
 3251|      0|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (3251:9): [True: 0, False: 0]
  ------------------
 3252|      0|        return -1;
 3253|      0|    }
 3254|       |
 3255|      0|    return len;
 3256|      0|}
channels.c:channel_from_msg:
  518|  1.09k|{
  519|  1.09k|    ssh_channel channel = NULL;
  520|  1.09k|    uint32_t chan;
  521|  1.09k|    int rc;
  522|       |
  523|  1.09k|    rc = ssh_buffer_unpack(packet, "d", &chan);
  ------------------
  |  |   60|  1.09k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.09k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.09k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.09k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.09k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.09k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.09k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  524|  1.09k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.09k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (524:9): [True: 0, False: 1.09k]
  ------------------
  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|  1.09k|    channel = ssh_channel_from_local(session, chan);
  532|  1.09k|    if (channel == NULL) {
  ------------------
  |  Branch (532:9): [True: 0, False: 1.09k]
  ------------------
  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|  1.09k|    return channel;
  540|  1.09k|}
channels.c:ssh_channel_has_unread_data:
  758|  1.09k|{
  759|  1.09k|    if (channel == NULL) {
  ------------------
  |  Branch (759:9): [True: 0, False: 1.09k]
  ------------------
  760|      0|        return false;
  761|      0|    }
  762|       |
  763|  1.09k|    if ((channel->stdout_buffer &&
  ------------------
  |  Branch (763:10): [True: 1.09k, False: 0]
  ------------------
  764|  1.09k|         ssh_buffer_get_len(channel->stdout_buffer) > 0) ||
  ------------------
  |  Branch (764:10): [True: 546, False: 546]
  ------------------
  765|    546|        (channel->stderr_buffer &&
  ------------------
  |  Branch (765:10): [True: 546, False: 0]
  ------------------
  766|    546|         ssh_buffer_get_len(channel->stderr_buffer) > 0))
  ------------------
  |  Branch (766:10): [True: 0, False: 546]
  ------------------
  767|    546|    {
  768|    546|        return true;
  769|    546|    }
  770|       |
  771|    546|    return false;
  772|  1.09k|}
channels.c:channel_open:
  339|    273|{
  340|    273|    ssh_session session = channel->session;
  341|    273|    int err = SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  342|    273|    int rc;
  343|       |
  344|    273|    switch (channel->state) {
  345|    273|    case SSH_CHANNEL_STATE_NOT_OPEN:
  ------------------
  |  Branch (345:5): [True: 273, False: 0]
  ------------------
  346|    273|        break;
  347|      0|    case SSH_CHANNEL_STATE_OPENING:
  ------------------
  |  Branch (347:5): [True: 0, False: 273]
  ------------------
  348|      0|        goto pending;
  349|      0|    case SSH_CHANNEL_STATE_OPEN:
  ------------------
  |  Branch (349:5): [True: 0, False: 273]
  ------------------
  350|      0|    case SSH_CHANNEL_STATE_CLOSED:
  ------------------
  |  Branch (350:5): [True: 0, False: 273]
  ------------------
  351|      0|    case SSH_CHANNEL_STATE_OPEN_DENIED:
  ------------------
  |  Branch (351:5): [True: 0, False: 273]
  ------------------
  352|      0|        goto end;
  353|      0|    default:
  ------------------
  |  Branch (353:5): [True: 0, False: 273]
  ------------------
  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|    273|                      channel->state);
  356|    273|    }
  357|       |
  358|    273|    channel->local_channel = ssh_channel_new_id(session);
  359|    273|    channel->local_maxpacket = maxpacket;
  360|    273|    channel->local_window = window;
  361|       |
  362|    273|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  363|    273|            "Creating a channel %" PRIu32 " with %" PRIu32 " window and %" PRIu32 " max packet",
  364|    273|            channel->local_channel, window, maxpacket);
  365|       |
  366|    273|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  367|    273|                         "bsddd",
  368|    273|                         SSH2_MSG_CHANNEL_OPEN,
  369|    273|                         type,
  370|    273|                         channel->local_channel,
  371|    273|                         channel->local_window,
  372|    273|                         channel->local_maxpacket);
  373|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (373:9): [True: 0, False: 273]
  ------------------
  374|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  375|      0|        return err;
  376|      0|    }
  377|       |
  378|    273|    if (payload != NULL) {
  ------------------
  |  Branch (378:9): [True: 0, False: 273]
  ------------------
  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|    273|    channel->state = SSH_CHANNEL_STATE_OPENING;
  386|    273|    if (ssh_packet_send(session) == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (386:9): [True: 0, False: 273]
  ------------------
  387|      0|        return err;
  388|      0|    }
  389|       |
  390|    273|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  391|    273|            "Sent a SSH_MSG_CHANNEL_OPEN type %s for channel %" PRIu32,
  392|    273|            type, channel->local_channel);
  393|       |
  394|    273|pending:
  395|       |    /* wait until channel is opened by server */
  396|    273|    err = ssh_handle_packets_termination(session,
  397|    273|                                         SSH_TIMEOUT_DEFAULT,
  ------------------
  |  |  103|    273|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
  398|    273|                                         ssh_channel_open_termination,
  399|    273|                                         channel);
  400|       |
  401|    273|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (401:9): [True: 0, False: 273]
  ------------------
  402|      0|        err = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  403|      0|    }
  404|       |
  405|    273|end:
  406|       |    /* This needs to pass the SSH_AGAIN from the above,
  407|       |     * but needs to catch failed channel states */
  408|    273|    if (channel->state == SSH_CHANNEL_STATE_OPEN) {
  ------------------
  |  Branch (408:9): [True: 273, False: 0]
  ------------------
  409|    273|        err = SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  410|    273|    } else if (err != SSH_AGAIN) {
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (410:16): [True: 0, False: 0]
  ------------------
  411|       |        /* Messages were handled correctly, but the channel state is invalid */
  412|      0|        err = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  413|      0|    }
  414|       |
  415|    273|    return err;
  416|    273|}
channels.c:ssh_channel_open_termination:
  304|    819|{
  305|    819|  ssh_channel channel = (ssh_channel) c;
  306|    819|  if (channel->state != SSH_CHANNEL_STATE_OPENING ||
  ------------------
  |  Branch (306:7): [True: 273, False: 546]
  ------------------
  307|    546|      channel->session->session_state == SSH_SESSION_STATE_ERROR)
  ------------------
  |  Branch (307:7): [True: 0, False: 546]
  ------------------
  308|    273|    return 1;
  309|    546|  else
  310|    546|    return 0;
  311|    819|}
channels.c:channel_write_common:
 1558|    273|{
 1559|    273|    ssh_session session = NULL;
 1560|    273|    uint32_t origlen = len;
 1561|    273|    uint32_t effectivelen;
 1562|    273|    int rc;
 1563|       |
 1564|    273|    if (channel == NULL) {
  ------------------
  |  Branch (1564:9): [True: 0, False: 273]
  ------------------
 1565|      0|        return -1;
 1566|      0|    }
 1567|    273|    session = channel->session;
 1568|    273|    if (data == NULL) {
  ------------------
  |  Branch (1568:9): [True: 0, False: 273]
  ------------------
 1569|      0|        ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1570|      0|        return -1;
 1571|      0|    }
 1572|       |
 1573|    273|    if (len > INT_MAX) {
  ------------------
  |  Branch (1573:9): [True: 0, False: 273]
  ------------------
 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|    273|    if (channel->local_eof) {
  ------------------
  |  Branch (1580:9): [True: 0, False: 273]
  ------------------
 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|    273|    if (channel->state != SSH_CHANNEL_STATE_OPEN ||
  ------------------
  |  Branch (1590:9): [True: 0, False: 273]
  ------------------
 1591|    273|        channel->delayed_close != 0) {
  ------------------
  |  Branch (1591:9): [True: 0, False: 273]
  ------------------
 1592|      0|        ssh_set_error(session, SSH_REQUEST_DENIED, "Remote channel is closed");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1593|       |
 1594|      0|        return -1;
 1595|      0|    }
 1596|       |
 1597|    273|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (1597:9): [True: 0, False: 273]
  ------------------
 1598|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1599|      0|    }
 1600|       |
 1601|    273|    if (ssh_waitsession_unblocked(session) == 0) {
  ------------------
  |  Branch (1601:9): [True: 0, False: 273]
  ------------------
 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|    546|    while (len > 0) {
  ------------------
  |  Branch (1609:12): [True: 273, False: 273]
  ------------------
 1610|    273|        if (channel->remote_window < len) {
  ------------------
  |  Branch (1610:13): [True: 0, False: 273]
  ------------------
 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|    273|        } else {
 1635|    273|            effectivelen = len;
 1636|    273|        }
 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|    273|        effectivelen = MIN(effectivelen, channel->remote_maxpacket);
  ------------------
  |  |  365|    273|#define MIN(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (365:19): [True: 273, False: 0]
  |  |  ------------------
  ------------------
 1643|       |
 1644|    273|        rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    546|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  |  |  |  Branch (50:68): [True: 0, False: 273]
  |  |  ------------------
  ------------------
 1645|    273|                             "bd",
 1646|    273|                             is_stderr ? SSH2_MSG_CHANNEL_EXTENDED_DATA
 1647|    273|                                       : SSH2_MSG_CHANNEL_DATA,
 1648|    273|                             channel->remote_channel);
 1649|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1649:13): [True: 0, False: 273]
  ------------------
 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|    273|        if (is_stderr) {
  ------------------
  |  Branch (1655:13): [True: 0, False: 273]
  ------------------
 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|    273|        rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1667|    273|                             "dP",
 1668|    273|                             effectivelen,
 1669|    273|                             (size_t)effectivelen,
 1670|    273|                             data);
 1671|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1671:13): [True: 0, False: 273]
  ------------------
 1672|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1673|      0|            goto error;
 1674|      0|        }
 1675|       |
 1676|    273|        rc = ssh_packet_send(session);
 1677|    273|        if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1677:13): [True: 0, False: 273]
  ------------------
 1678|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1679|      0|        }
 1680|       |
 1681|    273|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1682|    273|                "ssh_channel_write wrote %" PRIu32 " bytes",
 1683|    273|                effectivelen);
 1684|       |
 1685|    273|        channel->remote_window -= effectivelen;
 1686|    273|        len -= effectivelen;
 1687|    273|        data = ((uint8_t *)data + effectivelen);
 1688|    273|        if (channel->counter != NULL) {
  ------------------
  |  Branch (1688:13): [True: 0, False: 273]
  ------------------
 1689|      0|            channel->counter->out_bytes += effectivelen;
 1690|      0|        }
 1691|    273|    }
 1692|       |
 1693|       |    /* it's a good idea to flush the socket now */
 1694|    273|    rc = ssh_channel_flush(channel);
 1695|    273|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1695:9): [True: 0, False: 273]
  ------------------
 1696|      0|        goto error;
 1697|      0|    }
 1698|       |
 1699|    273|out:
 1700|    273|    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|    273|}
channels.c:ssh_waitsession_unblocked:
 1530|    273|{
 1531|    273|    ssh_session session = (ssh_session)s;
 1532|    273|    switch (session->session_state){
 1533|      0|        case SSH_SESSION_STATE_DH:
  ------------------
  |  Branch (1533:9): [True: 0, False: 273]
  ------------------
 1534|      0|        case SSH_SESSION_STATE_INITIAL_KEX:
  ------------------
  |  Branch (1534:9): [True: 0, False: 273]
  ------------------
 1535|      0|        case SSH_SESSION_STATE_KEXINIT_RECEIVED:
  ------------------
  |  Branch (1535:9): [True: 0, False: 273]
  ------------------
 1536|      0|            return 0;
 1537|    273|        default:
  ------------------
  |  Branch (1537:9): [True: 273, False: 0]
  ------------------
 1538|    273|            return 1;
 1539|    273|    }
 1540|    273|}
channels.c:channel_request:
 1909|    273|{
 1910|    273|  ssh_session session = channel->session;
 1911|    273|  int rc = SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1912|    273|  int ret;
 1913|       |
 1914|    273|  switch(channel->request_state){
 1915|    273|  case SSH_CHANNEL_REQ_STATE_NONE:
  ------------------
  |  Branch (1915:3): [True: 273, False: 0]
  ------------------
 1916|    273|    break;
 1917|      0|  default:
  ------------------
  |  Branch (1917:3): [True: 0, False: 273]
  ------------------
 1918|      0|    goto pending;
 1919|    273|  }
 1920|       |
 1921|    273|  ret = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    546|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  |  |  |  Branch (50:68): [True: 0, False: 273]
  |  |  ------------------
  ------------------
 1922|    273|                        "bdsb",
 1923|    273|                        SSH2_MSG_CHANNEL_REQUEST,
 1924|    273|                        channel->remote_channel,
 1925|    273|                        request,
 1926|    273|                        reply == 0 ? 0 : 1);
 1927|    273|  if (ret != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1927:7): [True: 0, False: 273]
  ------------------
 1928|      0|    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1929|      0|    goto error;
 1930|      0|  }
 1931|       |
 1932|    273|  if (buffer != NULL) {
  ------------------
  |  Branch (1932:7): [True: 273, False: 0]
  ------------------
 1933|    273|    if (ssh_buffer_add_data(session->out_buffer, ssh_buffer_get(buffer),
  ------------------
  |  Branch (1933:9): [True: 0, False: 273]
  ------------------
 1934|    273|        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|    273|  }
 1939|    273|  channel->request_state = SSH_CHANNEL_REQ_STATE_PENDING;
 1940|    273|  if (ssh_packet_send(session) == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1940:7): [True: 0, False: 273]
  ------------------
 1941|      0|    return rc;
 1942|      0|  }
 1943|       |
 1944|    273|  SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1945|    273|          "Sent a SSH_MSG_CHANNEL_REQUEST %s on channel %" PRIu32 ":%" PRIu32,
 1946|    273|          request,
 1947|    273|          channel->local_channel,
 1948|    273|          channel->remote_channel);
 1949|    273|  if (reply == 0) {
  ------------------
  |  Branch (1949:7): [True: 0, False: 273]
  ------------------
 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|    273|pending:
 1954|    273|  rc = ssh_handle_packets_termination(session,
 1955|    273|                                      SSH_TIMEOUT_DEFAULT,
  ------------------
  |  |  103|    273|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
 1956|    273|                                      ssh_channel_request_termination,
 1957|    273|                                      channel);
 1958|       |
 1959|    273|  if(session->session_state == SSH_SESSION_STATE_ERROR || rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1959:6): [True: 273, False: 0]
  |  Branch (1959:59): [True: 0, False: 0]
  ------------------
 1960|    273|      channel->request_state = SSH_CHANNEL_REQ_STATE_ERROR;
 1961|    273|  }
 1962|       |  /* we received something */
 1963|    273|  switch (channel->request_state){
  ------------------
  |  Branch (1963:11): [True: 273, False: 0]
  ------------------
 1964|    273|    case SSH_CHANNEL_REQ_STATE_ERROR:
  ------------------
  |  Branch (1964:5): [True: 273, False: 0]
  ------------------
 1965|    273|      rc=SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1966|    273|      break;
 1967|      0|    case SSH_CHANNEL_REQ_STATE_DENIED:
  ------------------
  |  Branch (1967:5): [True: 0, False: 273]
  ------------------
 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|      0|    case SSH_CHANNEL_REQ_STATE_ACCEPTED:
  ------------------
  |  Branch (1976:5): [True: 0, False: 273]
  ------------------
 1977|      0|      SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1978|      0|              "Channel request %s success on channel %" PRIu32 ":%" PRIu32,
 1979|      0|              request,
 1980|      0|              channel->local_channel,
 1981|      0|              channel->remote_channel);
 1982|      0|      rc=SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1983|      0|      break;
 1984|      0|    case SSH_CHANNEL_REQ_STATE_PENDING:
  ------------------
  |  Branch (1984:5): [True: 0, False: 273]
  ------------------
 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: 273]
  ------------------
 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|    273|  }
 1993|    273|  channel->request_state=SSH_CHANNEL_REQ_STATE_NONE;
 1994|       |
 1995|    273|  return rc;
 1996|      0|error:
 1997|      0|  ssh_buffer_reinit(session->out_buffer);
 1998|       |
 1999|      0|  return rc;
 2000|    273|}
channels.c:ssh_channel_request_termination:
 1898|  1.22k|{
 1899|  1.22k|  ssh_channel channel = (ssh_channel)c;
 1900|  1.22k|  if(channel->request_state != SSH_CHANNEL_REQ_STATE_PENDING ||
  ------------------
  |  Branch (1900:6): [True: 0, False: 1.22k]
  ------------------
 1901|  1.22k|      channel->session->session_state == SSH_SESSION_STATE_ERROR)
  ------------------
  |  Branch (1901:7): [True: 0, False: 1.22k]
  ------------------
 1902|      0|    return 1;
 1903|  1.22k|  else
 1904|  1.22k|    return 0;
 1905|  1.22k|}
channels.c:ssh_channel_read_termination:
 3111|    273|{
 3112|    273|  struct ssh_channel_read_termination_struct *ctx = s;
 3113|    273|  if (ssh_buffer_get_len(ctx->buffer) >= 1 ||
  ------------------
  |  Branch (3113:7): [True: 273, False: 0]
  ------------------
 3114|      0|      ctx->channel->remote_eof ||
  ------------------
  |  Branch (3114:7): [True: 0, False: 0]
  ------------------
 3115|      0|      ctx->channel->session->session_state == SSH_SESSION_STATE_ERROR)
  ------------------
  |  Branch (3115:7): [True: 0, False: 0]
  ------------------
 3116|    273|    return 1;
 3117|      0|  else
 3118|      0|    return 0;
 3119|    273|}

ssh_send_banner:
  187|    546|{
  188|    546|    const char *banner = CLIENT_BANNER_SSH2;
  ------------------
  |  |  223|    546|#define CLIENT_BANNER_SSH2 "SSH-2.0-libssh_" SSH_STRINGIFY(LIBSSH_VERSION)
  |  |  ------------------
  |  |  |  |   71|    546|#define SSH_STRINGIFY(s) SSH_TOSTRING(s)
  |  |  |  |  ------------------
  |  |  |  |  |  |   72|    546|#define SSH_TOSTRING(s) #s
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|    546|    const char *terminator = "\r\n";
  190|       |    /* The maximum banner length is 255 for SSH2 */
  191|    546|    char buffer[256] = {0};
  192|    546|    size_t len;
  193|    546|    int rc = SSH_ERROR;
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  194|       |
  195|    546|    if (server == 1) {
  ------------------
  |  Branch (195:9): [True: 273, False: 273]
  ------------------
  196|    273|        if (session->server_opts.custombanner == NULL) {
  ------------------
  |  Branch (196:13): [True: 273, False: 0]
  ------------------
  197|    273|            session->serverbanner = strdup(banner);
  198|    273|            if (session->serverbanner == NULL) {
  ------------------
  |  Branch (198:17): [True: 0, False: 273]
  ------------------
  199|      0|                goto end;
  200|      0|            }
  201|    273|        } 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|    273|        snprintf(buffer,
  214|    273|                 sizeof(buffer),
  215|    273|                 "%s%s",
  216|    273|                 session->serverbanner,
  217|    273|                 terminator);
  218|    273|    } else {
  219|    273|        session->clientbanner = strdup(banner);
  220|    273|        if (session->clientbanner == NULL) {
  ------------------
  |  Branch (220:13): [True: 0, False: 273]
  ------------------
  221|      0|            goto end;
  222|      0|        }
  223|       |
  224|    273|        snprintf(buffer,
  225|    273|                 sizeof(buffer),
  226|    273|                 "%s%s",
  227|    273|                 session->clientbanner,
  228|    273|                 terminator);
  229|    273|    }
  230|       |
  231|    546|    rc = ssh_socket_write(session->socket, buffer, (uint32_t)strlen(buffer));
  232|    546|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (232:9): [True: 0, False: 546]
  ------------------
  233|      0|        goto end;
  234|      0|    }
  235|    546|#ifdef WITH_PCAP
  236|    546|    if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (236:9): [True: 0, False: 546]
  ------------------
  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|    546|#endif
  244|       |
  245|    546|    rc = SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  246|    546|end:
  247|    546|    return rc;
  248|    546|}
dh_handshake:
  258|    273|{
  259|    273|    int rc = SSH_AGAIN;
  ------------------
  |  |  318|    273|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  260|       |
  261|    273|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  262|    273|            "dh_handshake_state = %d, kex_type = %d",
  263|    273|            session->dh_handshake_state,
  264|    273|            session->next_crypto->kex_type);
  265|       |
  266|    273|    switch (session->dh_handshake_state) {
  267|    273|    case DH_STATE_INIT:
  ------------------
  |  Branch (267:5): [True: 273, False: 0]
  ------------------
  268|    273|        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: 273]
  ------------------
  278|      0|        case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (278:9): [True: 0, False: 273]
  ------------------
  279|      0|        case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (279:9): [True: 0, False: 273]
  ------------------
  280|      0|        case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (280:9): [True: 0, False: 273]
  ------------------
  281|      0|        case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (281:9): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  286|      0|        case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (286:9): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  292|      0|        case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (292:9): [True: 0, False: 273]
  ------------------
  293|      0|        case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (293:9): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  299|      0|        case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (299:9): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  305|      0|        case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (305:9): [True: 0, False: 273]
  ------------------
  306|      0|            rc = ssh_client_sntrup761x25519_init(session);
  307|      0|            break;
  308|      0|#endif
  309|    273|        case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (309:9): [True: 273, False: 0]
  ------------------
  310|    273|        case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (310:9): [True: 0, False: 273]
  ------------------
  311|       |#ifdef HAVE_MLKEM1024
  312|       |        case SSH_KEX_MLKEM1024NISTP384_SHA384:
  313|       |#endif
  314|    273|            rc = ssh_client_hybrid_mlkem_init(session);
  315|    273|            break;
  316|      0|        default:
  ------------------
  |  Branch (316:9): [True: 0, False: 273]
  ------------------
  317|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  318|    273|        }
  319|       |
  320|    273|        break;
  321|    273|    case DH_STATE_INIT_SENT:
  ------------------
  |  Branch (321:5): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  325|       |    	/* wait until ssh_packet_newkeys is called */
  326|      0|    	break;
  327|      0|    case DH_STATE_FINISHED:
  ------------------
  |  Branch (327:5): [True: 0, False: 273]
  ------------------
  328|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  329|      0|    default:
  ------------------
  |  Branch (329:5): [True: 0, False: 273]
  ------------------
  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|    273|    }
  337|       |
  338|    273|    return rc;
  339|    273|}
ssh_service_request:
  373|    273|{
  374|    273|  int rc = SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  375|       |
  376|    273|  if(session->auth.service_state != SSH_AUTH_SERVICE_NONE)
  ------------------
  |  Branch (376:6): [True: 0, False: 273]
  ------------------
  377|      0|    goto pending;
  378|       |
  379|    273|  rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  380|    273|                       "bs",
  381|    273|                       SSH2_MSG_SERVICE_REQUEST,
  382|    273|                       service);
  383|    273|  if (rc != SSH_OK){
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (383:7): [True: 0, False: 273]
  ------------------
  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|    273|  session->auth.service_state = SSH_AUTH_SERVICE_SENT;
  388|    273|  if (ssh_packet_send(session) == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (388:7): [True: 0, False: 273]
  ------------------
  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|    273|  SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  395|    273|      "Sent SSH_MSG_SERVICE_REQUEST (service %s)", service);
  396|    273|pending:
  397|    273|  rc=ssh_handle_packets_termination(session,SSH_TIMEOUT_USER,
  ------------------
  |  |  101|    273|#define SSH_TIMEOUT_USER -2
  ------------------
  398|    273|      ssh_service_request_termination, session);
  399|    273|  if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (399:7): [True: 0, False: 273]
  ------------------
  400|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  401|      0|  }
  402|    273|  switch(session->auth.service_state) {
  ------------------
  |  Branch (402:10): [True: 273, False: 0]
  ------------------
  403|      0|  case SSH_AUTH_SERVICE_DENIED:
  ------------------
  |  Branch (403:3): [True: 0, False: 273]
  ------------------
  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|    273|  case SSH_AUTH_SERVICE_ACCEPTED:
  ------------------
  |  Branch (406:3): [True: 273, False: 0]
  ------------------
  407|    273|    rc=SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  408|    273|    break;
  409|      0|  case SSH_AUTH_SERVICE_SENT:
  ------------------
  |  Branch (409:3): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  413|      0|    rc=SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  414|      0|    break;
  415|    273|  }
  416|       |
  417|    273|  return rc;
  418|    273|}
ssh_connect:
  556|    273|{
  557|    273|    int ret;
  558|       |
  559|    273|    if (!is_ssh_initialized()) {
  ------------------
  |  Branch (559:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (session == NULL) {
  ------------------
  |  Branch (566:9): [True: 0, False: 273]
  ------------------
  567|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  568|      0|    }
  569|       |
  570|    273|    switch(session->pending_call_state) {
  571|    273|    case SSH_PENDING_CALL_NONE:
  ------------------
  |  Branch (571:5): [True: 273, False: 0]
  ------------------
  572|    273|        break;
  573|      0|    case SSH_PENDING_CALL_CONNECT:
  ------------------
  |  Branch (573:5): [True: 0, False: 273]
  ------------------
  574|      0|        goto pending;
  575|      0|    default:
  ------------------
  |  Branch (575:5): [True: 0, False: 273]
  ------------------
  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|    273|    }
  581|    273|    session->alive = 0;
  582|    273|    session->client = 1;
  583|       |
  584|    273|    if (session->opts.fd == SSH_INVALID_SOCKET &&
  ------------------
  |  |  124|    546|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  |  Branch (584:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (!session->opts.config_processed) {
  ------------------
  |  Branch (592:9): [True: 0, False: 273]
  ------------------
  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|    273|    ret = ssh_options_apply(session);
  602|    273|    if (ret < 0) {
  ------------------
  |  Branch (602:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  608|    273|            "libssh %s, using threading %s",
  609|    273|            ssh_copyright(),
  610|    273|            ssh_threads_get_type());
  611|       |
  612|    273|    session->ssh_connection_callback = ssh_client_connection_callback;
  613|    273|    session->session_state = SSH_SESSION_STATE_CONNECTING;
  614|    273|    ssh_socket_set_callbacks(session->socket, &session->socket_callbacks);
  615|    273|    session->socket_callbacks.connected = socket_callback_connected;
  616|    273|    session->socket_callbacks.data = callback_receive_banner;
  617|    273|    session->socket_callbacks.exception = ssh_socket_exception_callback;
  618|    273|    session->socket_callbacks.userdata = session;
  619|       |
  620|    273|    if (session->opts.fd != SSH_INVALID_SOCKET) {
  ------------------
  |  |  124|    273|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  |  Branch (620:9): [True: 273, False: 0]
  ------------------
  621|    273|        session->session_state = SSH_SESSION_STATE_SOCKET_CONNECTED;
  622|    273|        ret = ssh_socket_set_fd(session->socket, session->opts.fd);
  623|    273|#ifndef _WIN32
  624|    273|#ifdef HAVE_PTHREAD
  625|    273|    } 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|    273|    if (ret == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (646:9): [True: 0, False: 273]
  ------------------
  647|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  648|      0|    }
  649|       |
  650|    273|    set_status(session, 0.2f);
  ------------------
  |  |   58|    273|#define set_status(session, status) do {\
  |  |   59|    273|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (59:13): [True: 0, False: 273]
  |  |  |  Branch (59:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   60|    273|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   61|    273|    } while (0)
  |  |  ------------------
  |  |  |  Branch (61:14): [Folded, False: 273]
  |  |  ------------------
  ------------------
  651|       |
  652|    273|    session->alive = 1;
  653|    273|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  654|    273|            "Socket connecting, now waiting for the callbacks to work");
  655|       |
  656|    273|pending:
  657|    273|    session->pending_call_state = SSH_PENDING_CALL_CONNECT;
  658|    273|    if(ssh_is_blocking(session)) {
  ------------------
  |  Branch (658:8): [True: 273, False: 0]
  ------------------
  659|    273|        int timeout = ssh_make_milliseconds(session->opts.timeout,
  660|    273|                                            session->opts.timeout_usec);
  661|    273|        SSH_LOG(SSH_LOG_PACKET, "Actual timeout : %d", timeout);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  662|    273|        ret = ssh_handle_packets_termination(session, timeout,
  663|    273|                                             ssh_connect_termination, session);
  664|    273|        if (session->session_state != SSH_SESSION_STATE_ERROR &&
  ------------------
  |  Branch (664:13): [True: 273, False: 0]
  ------------------
  665|    273|            (ret == SSH_ERROR || !ssh_connect_termination(session)))
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (665:14): [True: 0, False: 273]
  |  Branch (665:34): [True: 0, False: 273]
  ------------------
  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|    273|    } 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|    273|    SSH_LOG(SSH_LOG_PACKET, "current state : %d", session->session_state);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  682|    273|    if (!ssh_is_blocking(session) && !ssh_connect_termination(session)) {
  ------------------
  |  Branch (682:9): [True: 0, False: 273]
  |  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|    273|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  687|    273|    if (session->session_state == SSH_SESSION_STATE_ERROR ||
  ------------------
  |  Branch (687:9): [True: 0, False: 273]
  ------------------
  688|    273|        session->session_state == SSH_SESSION_STATE_DISCONNECTED)
  ------------------
  |  Branch (688:9): [True: 0, False: 273]
  ------------------
  689|      0|    {
  690|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  691|      0|    }
  692|       |
  693|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  694|    273|}
ssh_disconnect:
  809|    546|{
  810|    546|    struct ssh_iterator *it = NULL;
  811|    546|    int rc;
  812|       |
  813|    546|    if (session == NULL) {
  ------------------
  |  Branch (813:9): [True: 0, False: 546]
  ------------------
  814|      0|        return;
  815|      0|    }
  816|       |
  817|    546|#ifndef _WIN32
  818|    546|#ifdef HAVE_PTHREAD
  819|       |    /* Only send the disconnect to all other threads when the root session calls
  820|       |     * ssh_disconnect() */
  821|    546|    if (session->proxy_root) {
  ------------------
  |  Branch (821:9): [True: 546, False: 0]
  ------------------
  822|    546|        proxy_disconnect = 1;
  823|    546|    }
  824|    546|#endif /* HAVE_PTHREAD */
  825|    546|#endif /* _WIN32 */
  826|       |
  827|    546|    if (session->disconnect_message == NULL) {
  ------------------
  |  Branch (827:9): [True: 546, False: 0]
  ------------------
  828|    546|        session->disconnect_message = strdup("Bye Bye") ;
  829|    546|        if (session->disconnect_message == NULL) {
  ------------------
  |  Branch (829:13): [True: 0, False: 546]
  ------------------
  830|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  831|      0|            goto error;
  832|      0|        }
  833|    546|    }
  834|       |
  835|    546|    if (session->socket != NULL && ssh_socket_is_open(session->socket)) {
  ------------------
  |  Branch (835:9): [True: 546, False: 0]
  |  Branch (835:36): [True: 273, False: 273]
  ------------------
  836|    273|        rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  837|    273|                             "bdss",
  838|    273|                             SSH2_MSG_DISCONNECT,
  839|    273|                             SSH2_DISCONNECT_BY_APPLICATION,
  840|    273|                             session->disconnect_message,
  841|    273|                             ""); /* language tag */
  842|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (842:13): [True: 0, False: 273]
  ------------------
  843|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  844|      0|            goto error;
  845|      0|        }
  846|       |
  847|    273|        ssh_packet_send(session);
  848|    273|        ssh_session_socket_close(session);
  849|    273|    }
  850|       |
  851|    546|error:
  852|    546|    session->recv_seq = 0;
  853|    546|    session->send_seq = 0;
  854|    546|    session->alive = 0;
  855|    546|    if (session->socket != NULL){
  ------------------
  |  Branch (855:9): [True: 546, False: 0]
  ------------------
  856|    546|        ssh_socket_reset(session->socket);
  857|    546|    }
  858|    546|    session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|    546|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  859|    546|    session->session_state = SSH_SESSION_STATE_DISCONNECTED;
  860|    546|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  861|    546|    session->packet_state = PACKET_STATE_INIT;
  862|       |
  863|    819|    while ((it = ssh_list_get_iterator(session->channels)) != NULL) {
  ------------------
  |  Branch (863:12): [True: 273, False: 546]
  ------------------
  864|    273|        ssh_channel_do_free(ssh_iterator_value(ssh_channel, it));
  ------------------
  |  |  114|    273|  ((type)((iterator)->data))
  ------------------
  865|    273|        ssh_list_remove(session->channels, it);
  866|    273|    }
  867|    546|    if (session->current_crypto) {
  ------------------
  |  Branch (867:9): [True: 546, False: 0]
  ------------------
  868|    546|      crypto_free(session->current_crypto);
  869|    546|      session->current_crypto = NULL;
  870|    546|    }
  871|    546|    if (session->next_crypto) {
  ------------------
  |  Branch (871:9): [True: 546, False: 0]
  ------------------
  872|    546|        crypto_free(session->next_crypto);
  873|    546|        session->next_crypto = crypto_new();
  874|    546|        if (session->next_crypto == NULL) {
  ------------------
  |  Branch (874:13): [True: 0, False: 546]
  ------------------
  875|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  876|      0|        }
  877|    546|    }
  878|    546|    if (session->in_buffer) {
  ------------------
  |  Branch (878:9): [True: 546, False: 0]
  ------------------
  879|    546|        ssh_buffer_reinit(session->in_buffer);
  880|    546|    }
  881|    546|    if (session->out_buffer) {
  ------------------
  |  Branch (881:9): [True: 546, False: 0]
  ------------------
  882|    546|        ssh_buffer_reinit(session->out_buffer);
  883|    546|    }
  884|    546|    if (session->in_hashbuf) {
  ------------------
  |  Branch (884:9): [True: 0, False: 546]
  ------------------
  885|      0|        ssh_buffer_reinit(session->in_hashbuf);
  886|      0|    }
  887|    546|    if (session->out_hashbuf) {
  ------------------
  |  Branch (887:9): [True: 0, False: 546]
  ------------------
  888|      0|        ssh_buffer_reinit(session->out_hashbuf);
  889|      0|    }
  890|    546|    session->auth.supported_methods = 0;
  891|    546|    SAFE_FREE(session->serverbanner);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  892|    546|    SAFE_FREE(session->clientbanner);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  893|    546|    SAFE_FREE(session->disconnect_message);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  894|       |
  895|    546|    if (session->ssh_message_list) {
  ------------------
  |  Branch (895:9): [True: 0, False: 546]
  ------------------
  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|    546|    if (session->packet_callbacks) {
  ------------------
  |  Branch (906:9): [True: 546, False: 0]
  ------------------
  907|    546|        ssh_list_free(session->packet_callbacks);
  908|       |        session->packet_callbacks = NULL;
  909|    546|    }
  910|    546|}
ssh_copyright:
  920|    273|{
  921|    273|    return SSH_STRINGIFY(LIBSSH_VERSION) " (c) 2003-2026 "
  ------------------
  |  |   71|    273|#define SSH_STRINGIFY(s) SSH_TOSTRING(s)
  |  |  ------------------
  |  |  |  |   72|    273|#define SSH_TOSTRING(s) #s
  |  |  ------------------
  ------------------
  922|    273|           "Aris Adamantiadis, Andreas Schneider "
  923|    273|           "and libssh contributors. "
  924|    273|           "Distributed under the LGPL, please refer to COPYING "
  925|    273|           "file for information about your rights";
  926|    273|}
client.c:ssh_service_request_termination:
  342|  1.09k|{
  343|  1.09k|    ssh_session session = (ssh_session)s;
  344|       |
  345|  1.09k|    if (session->session_state == SSH_SESSION_STATE_ERROR ||
  ------------------
  |  Branch (345:9): [True: 0, False: 1.09k]
  ------------------
  346|  1.09k|        session->auth.service_state != SSH_AUTH_SERVICE_SENT)
  ------------------
  |  Branch (346:9): [True: 273, False: 819]
  ------------------
  347|    273|        return 1;
  348|    819|    else
  349|    819|        return 0;
  350|  1.09k|}
client.c:ssh_client_connection_callback:
  427|  1.63k|{
  428|  1.63k|    int rc;
  429|       |
  430|  1.63k|    SSH_LOG(SSH_LOG_DEBUG, "session_state=%d", session->session_state);
  ------------------
  |  |  281|  1.63k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  431|       |
  432|  1.63k|    switch (session->session_state) {
  433|      0|    case SSH_SESSION_STATE_NONE:
  ------------------
  |  Branch (433:5): [True: 0, False: 1.63k]
  ------------------
  434|      0|    case SSH_SESSION_STATE_CONNECTING:
  ------------------
  |  Branch (434:5): [True: 0, False: 1.63k]
  ------------------
  435|      0|        break;
  436|    273|    case SSH_SESSION_STATE_SOCKET_CONNECTED:
  ------------------
  |  Branch (436:5): [True: 273, False: 1.36k]
  ------------------
  437|    273|        ssh_set_fd_towrite(session);
  438|    273|        ssh_send_banner(session, 0);
  439|       |
  440|    273|        break;
  441|    273|    case SSH_SESSION_STATE_BANNER_RECEIVED:
  ------------------
  |  Branch (441:5): [True: 273, False: 1.36k]
  ------------------
  442|    273|        if (session->serverbanner == NULL) {
  ------------------
  |  Branch (442:13): [True: 0, False: 273]
  ------------------
  443|      0|            goto error;
  444|      0|        }
  445|    273|        set_status(session, 0.4f);
  ------------------
  |  |   58|    273|#define set_status(session, status) do {\
  |  |   59|    273|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (59:13): [True: 0, False: 273]
  |  |  |  Branch (59:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   60|    273|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   61|    273|    } while (0)
  |  |  ------------------
  |  |  |  Branch (61:14): [Folded, False: 273]
  |  |  ------------------
  ------------------
  446|    273|        SSH_LOG(SSH_LOG_DEBUG, "SSH server banner: %s", session->serverbanner);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  447|       |
  448|       |        /* Here we analyze the different protocols the server allows. */
  449|    273|        rc = ssh_analyze_banner(session, 0);
  450|    273|        if (rc < 0) {
  ------------------
  |  Branch (450:13): [True: 0, False: 273]
  ------------------
  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|    273|        ssh_packet_register_socket_callback(session, session->socket);
  458|       |
  459|    273|        ssh_packet_set_default_callbacks(session);
  460|    273|        session->session_state = SSH_SESSION_STATE_INITIAL_KEX;
  461|    273|        rc = ssh_set_client_kex(session);
  462|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (462:13): [True: 0, False: 273]
  ------------------
  463|      0|            goto error;
  464|      0|        }
  465|    273|        rc = ssh_send_kex(session);
  466|    273|        if (rc < 0) {
  ------------------
  |  Branch (466:13): [True: 0, False: 273]
  ------------------
  467|      0|            goto error;
  468|      0|        }
  469|    273|        set_status(session, 0.5f);
  ------------------
  |  |   58|    273|#define set_status(session, status) do {\
  |  |   59|    273|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (59:13): [True: 0, False: 273]
  |  |  |  Branch (59:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   60|    273|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   61|    273|    } while (0)
  |  |  ------------------
  |  |  |  Branch (61:14): [Folded, False: 273]
  |  |  ------------------
  ------------------
  470|       |
  471|    273|        break;
  472|      0|    case SSH_SESSION_STATE_INITIAL_KEX:
  ------------------
  |  Branch (472:5): [True: 0, False: 1.63k]
  ------------------
  473|       |        /* TODO: This state should disappear in favor of get_key handle */
  474|      0|        break;
  475|    273|    case SSH_SESSION_STATE_KEXINIT_RECEIVED:
  ------------------
  |  Branch (475:5): [True: 273, False: 1.36k]
  ------------------
  476|    273|        set_status(session, 0.6f);
  ------------------
  |  |   58|    273|#define set_status(session, status) do {\
  |  |   59|    273|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (59:13): [True: 0, False: 273]
  |  |  |  Branch (59:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   60|    273|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   61|    273|    } while (0)
  |  |  ------------------
  |  |  |  Branch (61:14): [Folded, False: 273]
  |  |  ------------------
  ------------------
  477|    273|        ssh_list_kex(&session->next_crypto->server_kex);
  478|    273|        if ((session->flags & SSH_SESSION_FLAG_KEXINIT_SENT) == 0) {
  ------------------
  |  |   86|    273|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
  |  Branch (478:13): [True: 0, False: 273]
  ------------------
  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|    273|        if (ssh_kex_select_methods(session) == SSH_ERROR)
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (489:13): [True: 0, False: 273]
  ------------------
  490|      0|            goto error;
  491|    273|        set_status(session, 0.8f);
  ------------------
  |  |   58|    273|#define set_status(session, status) do {\
  |  |   59|    273|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (59:13): [True: 0, False: 273]
  |  |  |  Branch (59:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   60|    273|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   61|    273|    } while (0)
  |  |  ------------------
  |  |  |  Branch (61:14): [Folded, False: 273]
  |  |  ------------------
  ------------------
  492|    273|        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|    273|        if (dh_handshake(session) == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (496:13): [True: 0, False: 273]
  ------------------
  497|      0|            goto error;
  498|      0|        }
  499|    273|        FALL_THROUGH;
  ------------------
  |  |  494|    273|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
  500|    546|    case SSH_SESSION_STATE_DH:
  ------------------
  |  Branch (500:5): [True: 273, False: 1.36k]
  ------------------
  501|    546|        if (session->dh_handshake_state == DH_STATE_FINISHED) {
  ------------------
  |  Branch (501:13): [True: 273, False: 273]
  ------------------
  502|    273|            set_status(session, 1.0f);
  ------------------
  |  |   58|    273|#define set_status(session, status) do {\
  |  |   59|    273|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (59:13): [True: 0, False: 273]
  |  |  |  Branch (59:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   60|    273|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   61|    273|    } while (0)
  |  |  ------------------
  |  |  |  Branch (61:14): [Folded, False: 273]
  |  |  ------------------
  ------------------
  503|    273|            session->connected = 1;
  504|    273|            if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) {
  ------------------
  |  |   78|    273|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (504:17): [True: 0, False: 273]
  ------------------
  505|      0|                session->session_state = SSH_SESSION_STATE_AUTHENTICATED;
  506|    273|            } else {
  507|    273|                session->session_state = SSH_SESSION_STATE_AUTHENTICATING;
  508|    273|            }
  509|    273|        }
  510|    546|        break;
  511|      0|    case SSH_SESSION_STATE_AUTHENTICATING:
  ------------------
  |  Branch (511:5): [True: 0, False: 1.63k]
  ------------------
  512|      0|        break;
  513|    546|    case SSH_SESSION_STATE_ERROR:
  ------------------
  |  Branch (513:5): [True: 546, False: 1.09k]
  ------------------
  514|    546|        goto error;
  515|      0|    default:
  ------------------
  |  Branch (515:5): [True: 0, False: 1.63k]
  ------------------
  516|      0|        ssh_set_error(session, SSH_FATAL, "Invalid state %d",
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  517|  1.63k|                      session->session_state);
  518|  1.63k|    }
  519|       |
  520|  1.09k|    return;
  521|  1.09k|error:
  522|    546|    ssh_session_socket_close(session);
  523|    546|    SSH_LOG(SSH_LOG_WARN, "%s", ssh_get_error(session));
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  524|    546|}
client.c:socket_callback_connected:
   72|    273|{
   73|    273|	ssh_session session=(ssh_session)user;
   74|       |
   75|    273|	if (session->session_state != SSH_SESSION_STATE_CONNECTING &&
  ------------------
  |  Branch (75:6): [True: 273, False: 0]
  ------------------
   76|    273|	    session->session_state != SSH_SESSION_STATE_SOCKET_CONNECTED)
  ------------------
  |  Branch (76:6): [True: 0, False: 273]
  ------------------
   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|    273|	SSH_LOG(SSH_LOG_TRACE,"Socket connection callback: %d (%d)",code, errno_code);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   85|    273|	if(code == SSH_SOCKET_CONNECTED_OK)
  ------------------
  |  |  523|    273|#define SSH_SOCKET_CONNECTED_OK 			1
  ------------------
  |  Branch (85:5): [True: 273, False: 0]
  ------------------
   86|    273|		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|    273|	session->ssh_connection_callback(session);
   94|    273|}
client.c:callback_receive_banner:
  108|    273|{
  109|    273|    char *buffer = (char *)data;
  110|    273|    ssh_session session = (ssh_session) user;
  111|    273|    char *str = NULL;
  112|    273|    uint32_t i;
  113|    273|    int ret=0;
  114|       |
  115|    273|    if (session->session_state != SSH_SESSION_STATE_SOCKET_CONNECTED) {
  ------------------
  |  Branch (115:9): [True: 0, False: 273]
  ------------------
  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|  6.27k|    for (i = 0; i < len; ++i) {
  ------------------
  |  Branch (122:17): [True: 6.27k, False: 0]
  ------------------
  123|  6.27k|#ifdef WITH_PCAP
  124|  6.27k|        if (session->pcap_ctx && buffer[i] == '\n') {
  ------------------
  |  Branch (124:13): [True: 0, False: 6.27k]
  |  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|  6.27k|#endif
  131|  6.27k|        if (buffer[i] == '\r') {
  ------------------
  |  Branch (131:13): [True: 273, False: 6.00k]
  ------------------
  132|    273|            buffer[i] = '\0';
  133|    273|        }
  134|  6.27k|        if (buffer[i] == '\n') {
  ------------------
  |  Branch (134:13): [True: 273, False: 6.00k]
  ------------------
  135|    273|            int cmp;
  136|       |
  137|    273|            buffer[i] = '\0';
  138|       |
  139|       |            /* The server MAY send other lines of data... */
  140|    273|            cmp = strncmp(buffer, "SSH-", 4);
  141|    273|            if (cmp == 0) {
  ------------------
  |  Branch (141:17): [True: 273, False: 0]
  ------------------
  142|    273|                str = strdup(buffer);
  143|    273|                if (str == NULL) {
  ------------------
  |  Branch (143:21): [True: 0, False: 273]
  ------------------
  144|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  145|      0|                }
  146|       |                /* number of bytes read */
  147|    273|                ret = i + 1;
  148|    273|                session->serverbanner = str;
  149|    273|                session->session_state = SSH_SESSION_STATE_BANNER_RECEIVED;
  150|    273|                SSH_LOG(SSH_LOG_PACKET, "Received banner: %s", str);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  151|    273|                session->ssh_connection_callback(session);
  152|       |
  153|    273|                return ret;
  154|    273|            } 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|    273|        }
  162|       |        /* According to RFC 4253 the max banner length is 255 */
  163|  6.00k|        if (i > 255) {
  ------------------
  |  Branch (163:13): [True: 0, False: 6.00k]
  ------------------
  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|  6.00k|    }
  173|       |
  174|      0|    return ret;
  175|    273|}
client.c:ssh_connect_termination:
  530|  1.99k|{
  531|  1.99k|    ssh_session session = (ssh_session)user;
  532|       |
  533|  1.99k|    switch (session->session_state) {
  534|      0|    case SSH_SESSION_STATE_ERROR:
  ------------------
  |  Branch (534:5): [True: 0, False: 1.99k]
  ------------------
  535|    546|    case SSH_SESSION_STATE_AUTHENTICATING:
  ------------------
  |  Branch (535:5): [True: 546, False: 1.44k]
  ------------------
  536|    546|    case SSH_SESSION_STATE_DISCONNECTED:
  ------------------
  |  Branch (536:5): [True: 0, False: 1.99k]
  ------------------
  537|    546|        return 1;
  538|  1.44k|    default:
  ------------------
  |  Branch (538:5): [True: 1.44k, False: 546]
  ------------------
  539|  1.44k|        return 0;
  540|  1.99k|    }
  541|  1.99k|}

ssh_config_parse_uri:
  248|    546|{
  249|    546|    const char *endp = NULL;
  250|    546|    long port_n;
  251|    546|    int rc;
  252|       |
  253|       |    /* Sanitize inputs */
  254|    546|    if (username != NULL) {
  ------------------
  |  Branch (254:9): [True: 273, False: 273]
  ------------------
  255|    273|        *username = NULL;
  256|    273|    }
  257|    546|    if (hostname != NULL) {
  ------------------
  |  Branch (257:9): [True: 546, False: 0]
  ------------------
  258|    546|        *hostname = NULL;
  259|    546|    }
  260|    546|    if (port != NULL) {
  ------------------
  |  Branch (260:9): [True: 0, False: 546]
  ------------------
  261|      0|        *port = NULL;
  262|      0|    }
  263|       |
  264|       |    /* Username part (optional) */
  265|    546|    endp = strrchr(tok, '@');
  266|    546|    if (endp != NULL) {
  ------------------
  |  Branch (266:9): [True: 0, False: 546]
  ------------------
  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|    546|    if (*tok == '[') {
  ------------------
  |  Branch (290:9): [True: 0, False: 546]
  ------------------
  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|    546|    } else if (!ignore_port) {
  ------------------
  |  Branch (297:16): [True: 0, False: 546]
  ------------------
  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|    546|    } else {
  305|       |        /* If no port is requested, expand to the end of line
  306|       |         * (to accommodate the IPv6 addresses) */
  307|    546|        endp = strchr(tok, '\0');
  308|    546|    }
  309|    546|    if (tok == endp) {
  ------------------
  |  Branch (309:9): [True: 0, False: 546]
  ------------------
  310|       |        /* Zero-length hostnames are not valid */
  311|      0|        goto error;
  312|      0|    }
  313|    546|    if (hostname != NULL) {
  ------------------
  |  Branch (313:9): [True: 546, False: 0]
  ------------------
  314|    546|        *hostname = strndup(tok, endp - tok);
  315|    546|        if (*hostname == NULL) {
  ------------------
  |  Branch (315:13): [True: 0, False: 546]
  ------------------
  316|      0|            goto error;
  317|      0|        }
  318|    546|        if (strict) {
  ------------------
  |  Branch (318:13): [True: 273, False: 273]
  ------------------
  319|       |            /* if not an ip, check syntax */
  320|    273|            rc = ssh_is_ipaddr(*hostname);
  321|    273|            if (rc == 0) {
  ------------------
  |  Branch (321:17): [True: 273, False: 0]
  ------------------
  322|    273|                rc = ssh_check_hostname_syntax(*hostname);
  323|    273|                if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (323:21): [True: 0, False: 273]
  ------------------
  324|      0|                    goto error;
  325|      0|                }
  326|    273|            }
  327|    273|        } 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|    273|            const char *c = NULL;
  332|    273|            if ((*hostname)[0] == '-') {
  ------------------
  |  Branch (332:17): [True: 0, False: 273]
  ------------------
  333|      0|                goto error;
  334|      0|            }
  335|  2.73k|            for (c = *hostname; *c != '\0'; c++) {
  ------------------
  |  Branch (335:33): [True: 2.45k, False: 273]
  ------------------
  336|  2.45k|                const char *is_meta = strchr("'`\"$\\;&<>|(){},", *c);
  337|  2.45k|                int is_space = isspace((unsigned char)*c);
  338|  2.45k|                int is_ctrl = iscntrl((unsigned char)*c);
  339|  2.45k|                if (is_meta != NULL || is_space || is_ctrl) {
  ------------------
  |  Branch (339:21): [True: 0, False: 2.45k]
  |  Branch (339:40): [True: 0, False: 2.45k]
  |  Branch (339:52): [True: 0, False: 2.45k]
  ------------------
  340|      0|                    goto error;
  341|      0|                }
  342|  2.45k|            }
  343|    273|        }
  344|    546|    }
  345|       |    /* Skip also the closing bracket */
  346|    546|    if (*endp == ']') {
  ------------------
  |  Branch (346:9): [True: 0, False: 546]
  ------------------
  347|      0|        endp++;
  348|      0|    }
  349|       |
  350|       |    /* Port (optional) */
  351|    546|    if (*endp != '\0') {
  ------------------
  |  Branch (351:9): [True: 0, False: 546]
  ------------------
  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|    546|    return SSH_OK;
  ------------------
  |  |  316|    546|#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|    546|}

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

ssh_curve25519_create_k:
   52|    546|{
   53|    546|    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|    546|    rc = curve25519_do_create_k(session, k);
   65|    546|    return rc;
   66|    546|}

ssh_curve25519_init:
   34|    546|{
   35|    546|    ssh_curve25519_pubkey *pubkey_loc = NULL;
   36|    546|    EVP_PKEY_CTX *pctx = NULL;
   37|    546|    EVP_PKEY *pkey = NULL;
   38|    546|    size_t pubkey_len = CURVE25519_PUBKEY_SIZE;
  ------------------
  |  |   40|    546|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
   39|    546|    int rc;
   40|       |
   41|    546|    if (session->server) {
  ------------------
  |  Branch (41:9): [True: 273, False: 273]
  ------------------
   42|    273|        pubkey_loc = &session->next_crypto->curve25519_server_pubkey;
   43|    273|    } else {
   44|    273|        pubkey_loc = &session->next_crypto->curve25519_client_pubkey;
   45|    273|    }
   46|       |
   47|    546|    pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_X25519, NULL);
   48|    546|    if (pctx == NULL) {
  ------------------
  |  Branch (48:9): [True: 0, False: 546]
  ------------------
   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|    546|    rc = EVP_PKEY_keygen_init(pctx);
   56|    546|    if (rc != 1) {
  ------------------
  |  Branch (56:9): [True: 0, False: 546]
  ------------------
   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|    546|    rc = EVP_PKEY_keygen(pctx, &pkey);
   65|    546|    EVP_PKEY_CTX_free(pctx);
   66|    546|    if (rc != 1) {
  ------------------
  |  Branch (66:9): [True: 0, False: 546]
  ------------------
   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|    546|    rc = EVP_PKEY_get_raw_public_key(pkey, *pubkey_loc, &pubkey_len);
   74|    546|    if (rc != 1) {
  ------------------
  |  Branch (74:9): [True: 0, False: 546]
  ------------------
   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|    546|    if (session->next_crypto->curve25519_privkey != NULL) {
  ------------------
  |  Branch (83:9): [True: 0, False: 546]
  ------------------
   84|      0|        EVP_PKEY_free(session->next_crypto->curve25519_privkey);
   85|      0|        session->next_crypto->curve25519_privkey = NULL;
   86|      0|    }
   87|       |
   88|    546|    session->next_crypto->curve25519_privkey = pkey;
   89|    546|    pkey = NULL;
   90|       |
   91|    546|    return SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
   92|    546|}
curve25519_do_create_k:
   95|    546|{
   96|    546|    ssh_curve25519_pubkey *peer_pubkey_loc = NULL;
   97|    546|    int rc, ret = SSH_ERROR;
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   98|    546|    EVP_PKEY_CTX *pctx = NULL;
   99|    546|    EVP_PKEY *pkey = NULL, *pubkey = NULL;
  100|    546|    size_t shared_key_len = CURVE25519_PUBKEY_SIZE;
  ------------------
  |  |   40|    546|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  101|       |
  102|    546|    if (session->server) {
  ------------------
  |  Branch (102:9): [True: 273, False: 273]
  ------------------
  103|    273|        peer_pubkey_loc = &session->next_crypto->curve25519_client_pubkey;
  104|    273|    } else {
  105|    273|        peer_pubkey_loc = &session->next_crypto->curve25519_server_pubkey;
  106|    273|    }
  107|       |
  108|    546|    pkey = session->next_crypto->curve25519_privkey;
  109|    546|    if (pkey == NULL) {
  ------------------
  |  Branch (109:9): [True: 0, False: 546]
  ------------------
  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|    546|    pctx = EVP_PKEY_CTX_new(pkey, NULL);
  117|    546|    if (pctx == NULL) {
  ------------------
  |  Branch (117:9): [True: 0, False: 546]
  ------------------
  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|    546|    rc = EVP_PKEY_derive_init(pctx);
  125|    546|    if (rc != 1) {
  ------------------
  |  Branch (125:9): [True: 0, False: 546]
  ------------------
  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|    546|    pubkey = EVP_PKEY_new_raw_public_key(EVP_PKEY_X25519,
  133|    546|                                         NULL,
  134|    546|                                         *peer_pubkey_loc,
  135|    546|                                         CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   40|    546|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  136|    546|    if (pubkey == NULL) {
  ------------------
  |  Branch (136:9): [True: 0, False: 546]
  ------------------
  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|    546|    rc = EVP_PKEY_derive_set_peer(pctx, pubkey);
  144|    546|    if (rc != 1) {
  ------------------
  |  Branch (144:9): [True: 0, False: 546]
  ------------------
  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|    546|    rc = EVP_PKEY_derive(pctx, k, &shared_key_len);
  152|    546|    if (rc != 1) {
  ------------------
  |  Branch (152:9): [True: 0, False: 546]
  ------------------
  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|    546|    ret = SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  159|       |
  160|    546|out:
  161|    546|    EVP_PKEY_free(pubkey);
  162|    546|    EVP_PKEY_CTX_free(pctx);
  163|    546|    return ret;
  164|    546|}

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|    546|{
  296|    546|    return ssh_pki_import_pubkey_blob(pubkey_blob,
  297|    546|                                      &session->next_crypto->server_pubkey);
  298|       |
  299|    546|}
ssh_dh_get_next_server_publickey:
  676|  1.09k|{
  677|  1.09k|    return session->next_crypto->server_pubkey;
  678|  1.09k|}
ssh_dh_get_next_server_publickey_blob:
  683|    819|{
  684|    819|    const ssh_key pubkey = ssh_dh_get_next_server_publickey(session);
  685|       |
  686|    819|    return ssh_pki_export_pubkey_blob(pubkey, pubkey_blob);
  687|    819|}

ssh_dh_cleanup:
  449|  1.63k|{
  450|  1.63k|    if (crypto->dh_ctx != NULL) {
  ------------------
  |  Branch (450:9): [True: 0, False: 1.63k]
  ------------------
  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|  1.63k|}

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

libcrux_ml_kem_mlkem768_portable_decapsulate:
 8039|    273|    libcrux_ml_kem_mlkem768_MlKem768Ciphertext *ciphertext, uint8_t ret[32U]) {
 8040|    273|  libcrux_ml_kem_ind_cca_instantiations_portable_decapsulate_35(
 8041|    273|      private_key, ciphertext, ret);
 8042|    273|}
libcrux_ml_kem_mlkem768_portable_encapsulate:
 8172|    273|    uint8_t randomness[32U]) {
 8173|    273|  return libcrux_ml_kem_ind_cca_instantiations_portable_encapsulate_cd(
 8174|    273|      public_key, randomness);
 8175|    273|}
libcrux_ml_kem_mlkem768_portable_generate_key_pair:
 8762|    273|libcrux_ml_kem_mlkem768_portable_generate_key_pair(uint8_t randomness[64U]) {
 8763|    273|  return libcrux_ml_kem_ind_cca_instantiations_portable_generate_keypair_ce(
 8764|    273|      randomness);
 8765|    273|}
libcrux_ml_kem_mlkem768_portable_validate_public_key:
 8876|    273|    libcrux_ml_kem_types_MlKemPublicKey_30 *public_key) {
 8877|    273|  return libcrux_ml_kem_ind_cca_instantiations_portable_validate_public_key_41(
 8878|    273|      public_key->value);
 8879|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_instantiations_portable_decapsulate_35:
 8026|    273|    libcrux_ml_kem_mlkem768_MlKem768Ciphertext *ciphertext, uint8_t ret[32U]) {
 8027|    273|  libcrux_ml_kem_ind_cca_decapsulate_62(private_key, ciphertext, ret);
 8028|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_decapsulate_62:
 7937|    273|    libcrux_ml_kem_mlkem768_MlKem768Ciphertext *ciphertext, uint8_t ret[32U]) {
 7938|    273|  Eurydice_slice_uint8_t_x4 uu____0 =
 7939|    273|      libcrux_ml_kem_types_unpack_private_key_b4(
 7940|    273|          Eurydice_array_to_slice((size_t)2400U, private_key->value, uint8_t));
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7941|    273|  Eurydice_slice ind_cpa_secret_key = uu____0.fst;
 7942|    273|  Eurydice_slice ind_cpa_public_key = uu____0.snd;
 7943|    273|  Eurydice_slice ind_cpa_public_key_hash = uu____0.thd;
 7944|    273|  Eurydice_slice implicit_rejection_value = uu____0.f3;
 7945|    273|  uint8_t decrypted[32U];
 7946|    273|  libcrux_ml_kem_ind_cpa_decrypt_42(ind_cpa_secret_key, ciphertext->value,
 7947|    273|                                    decrypted);
 7948|    273|  uint8_t to_hash0[64U];
 7949|    273|  libcrux_ml_kem_utils_into_padded_array_24(
 7950|    273|      Eurydice_array_to_slice((size_t)32U, decrypted, uint8_t), to_hash0);
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7951|    273|  Eurydice_slice_copy(
  ------------------
  |  |  229|    273|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 7952|    273|      Eurydice_array_to_subslice_from(
 7953|    273|          (size_t)64U, to_hash0, LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
 7954|    273|          uint8_t, size_t, uint8_t[]),
 7955|    273|      ind_cpa_public_key_hash, uint8_t);
 7956|    273|  uint8_t hashed[64U];
 7957|    273|  libcrux_ml_kem_hash_functions_portable_G_4a_e0(
 7958|    273|      Eurydice_array_to_slice((size_t)64U, to_hash0, uint8_t), hashed);
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7959|    273|  Eurydice_slice_uint8_t_x2 uu____1 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    273|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    273|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    273|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    273|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    273|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    273|  }
  ------------------
 7960|    273|      Eurydice_array_to_slice((size_t)64U, hashed, uint8_t),
 7961|    273|      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE, uint8_t,
 7962|    273|      Eurydice_slice_uint8_t_x2);
 7963|    273|  Eurydice_slice shared_secret0 = uu____1.fst;
 7964|    273|  Eurydice_slice pseudorandomness = uu____1.snd;
 7965|    273|  uint8_t to_hash[1120U];
 7966|    273|  libcrux_ml_kem_utils_into_padded_array_15(implicit_rejection_value, to_hash);
 7967|    273|  Eurydice_slice uu____2 = Eurydice_array_to_subslice_from(
  ------------------
  |  |  225|    273|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7968|    273|      (size_t)1120U, to_hash, LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE,
 7969|    273|      uint8_t, size_t, uint8_t[]);
 7970|    273|  Eurydice_slice_copy(uu____2, libcrux_ml_kem_types_as_ref_d3_80(ciphertext),
  ------------------
  |  |  229|    273|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 7971|    273|                      uint8_t);
 7972|    273|  uint8_t implicit_rejection_shared_secret0[32U];
 7973|    273|  libcrux_ml_kem_hash_functions_portable_PRF_4a_41(
 7974|    273|      Eurydice_array_to_slice((size_t)1120U, to_hash, uint8_t),
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7975|    273|      implicit_rejection_shared_secret0);
 7976|    273|  uint8_t expected_ciphertext[1088U];
 7977|    273|  libcrux_ml_kem_ind_cpa_encrypt_2a(ind_cpa_public_key, decrypted,
 7978|    273|                                    pseudorandomness, expected_ciphertext);
 7979|    273|  uint8_t implicit_rejection_shared_secret[32U];
 7980|    273|  libcrux_ml_kem_variant_kdf_39_d6(
 7981|    273|      Eurydice_array_to_slice((size_t)32U, implicit_rejection_shared_secret0,
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7982|    273|                              uint8_t),
 7983|    273|      libcrux_ml_kem_types_as_slice_a9_80(ciphertext),
 7984|    273|      implicit_rejection_shared_secret);
 7985|    273|  uint8_t shared_secret[32U];
 7986|    273|  libcrux_ml_kem_variant_kdf_39_d6(
 7987|    273|      shared_secret0, libcrux_ml_kem_types_as_slice_a9_80(ciphertext),
 7988|    273|      shared_secret);
 7989|    273|  uint8_t ret0[32U];
 7990|    273|  libcrux_ml_kem_constant_time_ops_compare_ciphertexts_select_shared_secret_in_constant_time(
 7991|    273|      libcrux_ml_kem_types_as_ref_d3_80(ciphertext),
 7992|    273|      Eurydice_array_to_slice((size_t)1088U, expected_ciphertext, uint8_t),
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7993|    273|      Eurydice_array_to_slice((size_t)32U, shared_secret, uint8_t),
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7994|    273|      Eurydice_array_to_slice((size_t)32U, implicit_rejection_shared_secret,
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7995|    273|                              uint8_t),
 7996|    273|      ret0);
 7997|    273|  memcpy(ret, ret0, (size_t)32U * sizeof(uint8_t));
 7998|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_unpack_private_key_b4:
  989|    273|libcrux_ml_kem_types_unpack_private_key_b4(Eurydice_slice private_key) {
  990|    273|  Eurydice_slice_uint8_t_x2 uu____0 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    273|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    273|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    273|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    273|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    273|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    273|  }
  ------------------
  991|    273|      private_key, (size_t)1152U, uint8_t, Eurydice_slice_uint8_t_x2);
  992|    273|  Eurydice_slice ind_cpa_secret_key = uu____0.fst;
  993|    273|  Eurydice_slice secret_key0 = uu____0.snd;
  994|    273|  Eurydice_slice_uint8_t_x2 uu____1 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    273|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    273|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    273|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    273|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    273|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    273|  }
  ------------------
  995|    273|      secret_key0, (size_t)1184U, uint8_t, Eurydice_slice_uint8_t_x2);
  996|    273|  Eurydice_slice ind_cpa_public_key = uu____1.fst;
  997|    273|  Eurydice_slice secret_key = uu____1.snd;
  998|    273|  Eurydice_slice_uint8_t_x2 uu____2 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    273|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    273|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    273|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    273|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    273|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    273|  }
  ------------------
  999|    273|      secret_key, LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE, uint8_t,
 1000|    273|      Eurydice_slice_uint8_t_x2);
 1001|    273|  Eurydice_slice ind_cpa_public_key_hash = uu____2.fst;
 1002|    273|  Eurydice_slice implicit_rejection_value = uu____2.snd;
 1003|    273|  return (
 1004|    273|      KRML_CLITERAL(Eurydice_slice_uint8_t_x4){.fst = ind_cpa_secret_key,
  ------------------
  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  ------------------
 1005|    273|                                               .snd = ind_cpa_public_key,
 1006|    273|                                               .thd = ind_cpa_public_key_hash,
 1007|    273|                                               .f3 = implicit_rejection_value});
 1008|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_decrypt_42:
 6268|    273|    Eurydice_slice secret_key, uint8_t *ciphertext, uint8_t ret[32U]) {
 6269|    273|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPrivateKeyUnpacked_a0
 6270|    273|      secret_key_unpacked;
 6271|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret0[3U];
 6272|  1.09k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6272:31): [True: 819, False: 273]
  ------------------
 6273|       |    /* original Rust expression is not an lvalue in C */
 6274|    819|    void *lvalue = (void *)0U;
 6275|    819|    ret0[i] = libcrux_ml_kem_ind_cpa_decrypt_call_mut_0b_42(&lvalue, i);
 6276|    819|  }
 6277|    273|  memcpy(
 6278|    273|      secret_key_unpacked.secret_as_ntt, ret0,
 6279|    273|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 6280|    273|  libcrux_ml_kem_ind_cpa_deserialize_vector_1b(
 6281|    273|      secret_key, secret_key_unpacked.secret_as_ntt);
 6282|    273|  uint8_t ret1[32U];
 6283|    273|  libcrux_ml_kem_ind_cpa_decrypt_unpacked_42(&secret_key_unpacked, ciphertext,
 6284|    273|                                             ret1);
 6285|    273|  memcpy(ret, ret1, (size_t)32U * sizeof(uint8_t));
 6286|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_decrypt_call_mut_0b_42:
 5348|    819|libcrux_ml_kem_ind_cpa_decrypt_call_mut_0b_42(void **_, size_t tupled_args) {
 5349|    819|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 5350|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_ZERO_d6_ea:
 5317|  25.3k|libcrux_ml_kem_polynomial_ZERO_d6_ea(void) {
 5318|  25.3k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d lit;
 5319|  25.3k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector
 5320|  25.3k|      repeat_expression[16U];
 5321|   431k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5321:31): [True: 406k, False: 25.3k]
  ------------------
 5322|   406k|    repeat_expression[i] = libcrux_ml_kem_vector_portable_ZERO_b8();
 5323|   406k|  }
 5324|  25.3k|  memcpy(lit.coefficients, repeat_expression,
 5325|  25.3k|         (size_t)16U *
 5326|  25.3k|             sizeof(libcrux_ml_kem_vector_portable_vector_type_PortableVector));
 5327|  25.3k|  return lit;
 5328|  25.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ZERO_b8:
 3836|   768k|libcrux_ml_kem_vector_portable_ZERO_b8(void) {
 3837|   768k|  return libcrux_ml_kem_vector_portable_vector_type_zero();
 3838|   768k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_vector_type_zero:
 3822|   934k|libcrux_ml_kem_vector_portable_vector_type_zero(void) {
 3823|   934k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector lit;
 3824|   934k|  int16_t ret[16U];
 3825|   934k|  int16_t buf[16U] = {0U};
 3826|   934k|  libcrux_secrets_int_public_integers_classify_27_46(buf, ret);
 3827|   934k|  memcpy(lit.elements, ret, (size_t)16U * sizeof(int16_t));
 3828|   934k|  return lit;
 3829|   934k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_46:
 1075|   934k|    int16_t self[16U], int16_t ret[16U]) {
 1076|   934k|  memcpy(ret, self, (size_t)16U * sizeof(int16_t));
 1077|   934k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_deserialize_vector_1b:
 5387|    273|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *secret_as_ntt) {
 5388|  1.09k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (5388:31): [True: 819, False: 273]
  ------------------
 5389|    819|    size_t i0 = i;
 5390|    819|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0 =
 5391|    819|        libcrux_ml_kem_serialize_deserialize_to_uncompressed_ring_element_ea(
 5392|    819|            Eurydice_slice_subslice3(
  ------------------
  |  |  195|    819|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    819|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    819|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5393|    819|                secret_key,
 5394|    819|                i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 5395|    819|                (i0 + (size_t)1U) *
 5396|    819|                    LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 5397|    819|                uint8_t *));
 5398|    819|    secret_as_ntt[i0] = uu____0;
 5399|    819|  }
 5400|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_to_uncompressed_ring_element_ea:
 5360|    819|    Eurydice_slice serialized) {
 5361|    819|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d re =
 5362|    819|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 5363|    819|  for (size_t i = (size_t)0U;
 5364|  13.9k|       i < Eurydice_slice_len(serialized, uint8_t) / (size_t)24U; i++) {
  ------------------
  |  |  173|  13.9k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5364:8): [True: 13.1k, False: 819]
  ------------------
 5365|  13.1k|    size_t i0 = i;
 5366|  13.1k|    Eurydice_slice bytes =
 5367|  13.1k|        Eurydice_slice_subslice3(serialized, i0 * (size_t)24U,
  ------------------
  |  |  195|  13.1k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  13.1k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  13.1k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5368|  13.1k|                                 i0 * (size_t)24U + (size_t)24U, uint8_t *);
 5369|  13.1k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5370|  13.1k|        libcrux_ml_kem_vector_portable_deserialize_12_b8(bytes);
 5371|  13.1k|    re.coefficients[i0] = uu____0;
 5372|  13.1k|  }
 5373|    819|  return re;
 5374|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_12_b8:
 5179|  52.4k|libcrux_ml_kem_vector_portable_deserialize_12_b8(Eurydice_slice a) {
 5180|  52.4k|  return libcrux_ml_kem_vector_portable_deserialize_12(a);
 5181|  52.4k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_12:
 5169|  52.4k|libcrux_ml_kem_vector_portable_deserialize_12(Eurydice_slice a) {
 5170|  52.4k|  return libcrux_ml_kem_vector_portable_serialize_deserialize_12(
 5171|  52.4k|      libcrux_secrets_int_classify_public_classify_ref_9b_90(a));
 5172|  52.4k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_12:
 5140|  52.4k|libcrux_ml_kem_vector_portable_serialize_deserialize_12(Eurydice_slice bytes) {
 5141|  52.4k|  int16_t_x2 v0_1 = libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5142|  52.4k|      Eurydice_slice_subslice3(bytes, (size_t)0U, (size_t)3U, uint8_t *));
  ------------------
  |  |  195|  52.4k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  52.4k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  52.4k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5143|  52.4k|  int16_t_x2 v2_3 = libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5144|  52.4k|      Eurydice_slice_subslice3(bytes, (size_t)3U, (size_t)6U, uint8_t *));
  ------------------
  |  |  195|  52.4k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  52.4k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  52.4k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5145|  52.4k|  int16_t_x2 v4_5 = libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5146|  52.4k|      Eurydice_slice_subslice3(bytes, (size_t)6U, (size_t)9U, uint8_t *));
  ------------------
  |  |  195|  52.4k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  52.4k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  52.4k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5147|  52.4k|  int16_t_x2 v6_7 = libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5148|  52.4k|      Eurydice_slice_subslice3(bytes, (size_t)9U, (size_t)12U, uint8_t *));
  ------------------
  |  |  195|  52.4k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  52.4k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  52.4k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5149|  52.4k|  int16_t_x2 v8_9 = libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5150|  52.4k|      Eurydice_slice_subslice3(bytes, (size_t)12U, (size_t)15U, uint8_t *));
  ------------------
  |  |  195|  52.4k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  52.4k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  52.4k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5151|  52.4k|  int16_t_x2 v10_11 =
 5152|  52.4k|      libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5153|  52.4k|          Eurydice_slice_subslice3(bytes, (size_t)15U, (size_t)18U, uint8_t *));
  ------------------
  |  |  195|  52.4k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  52.4k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  52.4k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5154|  52.4k|  int16_t_x2 v12_13 =
 5155|  52.4k|      libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5156|  52.4k|          Eurydice_slice_subslice3(bytes, (size_t)18U, (size_t)21U, uint8_t *));
  ------------------
  |  |  195|  52.4k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  52.4k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  52.4k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5157|  52.4k|  int16_t_x2 v14_15 =
 5158|  52.4k|      libcrux_ml_kem_vector_portable_serialize_deserialize_12_int(
 5159|  52.4k|          Eurydice_slice_subslice3(bytes, (size_t)21U, (size_t)24U, uint8_t *));
  ------------------
  |  |  195|  52.4k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  52.4k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  52.4k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5160|  52.4k|  return (
 5161|  52.4k|      KRML_CLITERAL(libcrux_ml_kem_vector_portable_vector_type_PortableVector){
  ------------------
  |  |  154|  52.4k|#define KRML_CLITERAL(type) (type)
  ------------------
 5162|  52.4k|          .elements = {v0_1.fst, v0_1.snd, v2_3.fst, v2_3.snd, v4_5.fst,
 5163|  52.4k|                       v4_5.snd, v6_7.fst, v6_7.snd, v8_9.fst, v8_9.snd,
 5164|  52.4k|                       v10_11.fst, v10_11.snd, v12_13.fst, v12_13.snd,
 5165|  52.4k|                       v14_15.fst, v14_15.snd}});
 5166|  52.4k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_12_int:
 5127|   419k|    Eurydice_slice bytes) {
 5128|   419k|  int16_t byte0 = libcrux_secrets_int_as_i16_59(
 5129|   419k|      Eurydice_slice_index(bytes, (size_t)0U, uint8_t, uint8_t *));
  ------------------
  |  |  180|   419k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5130|   419k|  int16_t byte1 = libcrux_secrets_int_as_i16_59(
 5131|   419k|      Eurydice_slice_index(bytes, (size_t)1U, uint8_t, uint8_t *));
  ------------------
  |  |  180|   419k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5132|   419k|  int16_t byte2 = libcrux_secrets_int_as_i16_59(
 5133|   419k|      Eurydice_slice_index(bytes, (size_t)2U, uint8_t, uint8_t *));
  ------------------
  |  |  180|   419k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5134|   419k|  int16_t r0 = (byte1 & (int16_t)15) << 8U | (byte0 & (int16_t)255);
 5135|   419k|  int16_t r1 = byte2 << 4U | (byte1 >> 4U & (int16_t)15);
 5136|   419k|  return (KRML_CLITERAL(int16_t_x2){.fst = r0, .snd = r1});
  ------------------
  |  |  154|   419k|#define KRML_CLITERAL(type) (type)
  ------------------
 5137|   419k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i16_59:
  535|  1.95M|static KRML_MUSTINLINE int16_t libcrux_secrets_int_as_i16_59(uint8_t self) {
  536|  1.95M|  return libcrux_secrets_int_public_integers_classify_27_39(
  537|  1.95M|      (int16_t)libcrux_secrets_int_public_integers_declassify_d8_90(self));
  538|  1.95M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_39:
  515|  63.0M|libcrux_secrets_int_public_integers_classify_27_39(int16_t self) {
  516|  63.0M|  return self;
  517|  63.0M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_90:
  528|  1.95M|libcrux_secrets_int_public_integers_declassify_d8_90(uint8_t self) {
  529|  1.95M|  return self;
  530|  1.95M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_classify_public_classify_ref_9b_90:
 1089|  78.6k|libcrux_secrets_int_classify_public_classify_ref_9b_90(Eurydice_slice self) {
 1090|  78.6k|  return self;
 1091|  78.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_decrypt_unpacked_42:
 6241|    273|    uint8_t *ciphertext, uint8_t ret[32U]) {
 6242|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d u_as_ntt[3U];
 6243|    273|  libcrux_ml_kem_ind_cpa_deserialize_then_decompress_u_6c(ciphertext, u_as_ntt);
 6244|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d v =
 6245|    273|      libcrux_ml_kem_serialize_deserialize_then_decompress_ring_element_v_89(
 6246|    273|          Eurydice_array_to_subslice_from((size_t)1088U, ciphertext,
  ------------------
  |  |  225|    273|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6247|    273|                                          (size_t)960U, uint8_t, size_t,
 6248|    273|                                          uint8_t[]));
 6249|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d message =
 6250|    273|      libcrux_ml_kem_matrix_compute_message_1b(&v, secret_key->secret_as_ntt,
 6251|    273|                                               u_as_ntt);
 6252|    273|  uint8_t ret0[32U];
 6253|    273|  libcrux_ml_kem_serialize_compress_then_serialize_message_ea(message, ret0);
 6254|    273|  memcpy(ret, ret0, (size_t)32U * sizeof(uint8_t));
 6255|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_deserialize_then_decompress_u_6c:
 5694|    273|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret[3U]) {
 5695|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d u_as_ntt[3U];
 5696|  1.09k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (5696:31): [True: 819, False: 273]
  ------------------
 5697|       |    /* original Rust expression is not an lvalue in C */
 5698|    819|    void *lvalue = (void *)0U;
 5699|    819|    u_as_ntt[i] =
 5700|    819|        libcrux_ml_kem_ind_cpa_deserialize_then_decompress_u_call_mut_35_6c(
 5701|    819|            &lvalue, i);
 5702|    819|  }
 5703|    273|  for (size_t i = (size_t)0U;
 5704|  1.09k|       i < Eurydice_slice_len(
  ------------------
  |  |  173|  1.09k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5704:8): [True: 819, False: 273]
  ------------------
 5705|  1.09k|               Eurydice_array_to_slice((size_t)1088U, ciphertext, uint8_t),
 5706|  1.09k|               uint8_t) /
 5707|  1.09k|               (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT *
  ------------------
  |  |  447|  1.09k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 5708|  1.09k|                (size_t)10U / (size_t)8U);
 5709|    819|       i++) {
 5710|    819|    size_t i0 = i;
 5711|    819|    Eurydice_slice u_bytes = Eurydice_array_to_subslice3(
  ------------------
  |  |  215|    819|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    819|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    819|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5712|    819|        ciphertext,
 5713|    819|        i0 * (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT *
 5714|    819|              (size_t)10U / (size_t)8U),
 5715|    819|        i0 * (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT *
 5716|    819|              (size_t)10U / (size_t)8U) +
 5717|    819|            LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT *
 5718|    819|                (size_t)10U / (size_t)8U,
 5719|    819|        uint8_t *);
 5720|    819|    u_as_ntt[i0] =
 5721|    819|        libcrux_ml_kem_serialize_deserialize_then_decompress_ring_element_u_0a(
 5722|    819|            u_bytes);
 5723|    819|    libcrux_ml_kem_ntt_ntt_vector_u_0a(&u_as_ntt[i0]);
 5724|    819|  }
 5725|    273|  memcpy(
 5726|    273|      ret, u_as_ntt,
 5727|    273|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 5728|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_deserialize_then_decompress_u_call_mut_35_6c:
 5419|    819|    void **_, size_t tupled_args) {
 5420|    819|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 5421|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_then_decompress_ring_element_u_0a:
 5499|    819|    Eurydice_slice serialized) {
 5500|    819|  return libcrux_ml_kem_serialize_deserialize_then_decompress_10_ea(serialized);
 5501|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_then_decompress_10_ea:
 5472|    819|    Eurydice_slice serialized) {
 5473|    819|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d re =
 5474|    819|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 5475|    819|  for (size_t i = (size_t)0U;
 5476|  13.9k|       i < Eurydice_slice_len(serialized, uint8_t) / (size_t)20U; i++) {
  ------------------
  |  |  173|  13.9k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5476:8): [True: 13.1k, False: 819]
  ------------------
 5477|  13.1k|    size_t i0 = i;
 5478|  13.1k|    Eurydice_slice bytes =
 5479|  13.1k|        Eurydice_slice_subslice3(serialized, i0 * (size_t)20U,
  ------------------
  |  |  195|  13.1k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  13.1k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  13.1k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5480|  13.1k|                                 i0 * (size_t)20U + (size_t)20U, uint8_t *);
 5481|  13.1k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 5482|  13.1k|        libcrux_ml_kem_vector_portable_deserialize_10_b8(bytes);
 5483|  13.1k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5484|  13.1k|        libcrux_ml_kem_vector_portable_decompress_ciphertext_coefficient_b8_ef(
 5485|  13.1k|            coefficient);
 5486|  13.1k|    re.coefficients[i0] = uu____0;
 5487|  13.1k|  }
 5488|    819|  return re;
 5489|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_10_b8:
 5024|  13.1k|libcrux_ml_kem_vector_portable_deserialize_10_b8(Eurydice_slice a) {
 5025|  13.1k|  return libcrux_ml_kem_vector_portable_deserialize_10(a);
 5026|  13.1k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_10:
 5014|  13.1k|libcrux_ml_kem_vector_portable_deserialize_10(Eurydice_slice a) {
 5015|  13.1k|  return libcrux_ml_kem_vector_portable_serialize_deserialize_10(
 5016|  13.1k|      libcrux_secrets_int_classify_public_classify_ref_9b_90(a));
 5017|  13.1k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_10:
 5000|  13.1k|libcrux_ml_kem_vector_portable_serialize_deserialize_10(Eurydice_slice bytes) {
 5001|  13.1k|  int16_t_x8 v0_7 = libcrux_ml_kem_vector_portable_serialize_deserialize_10_int(
 5002|  13.1k|      Eurydice_slice_subslice3(bytes, (size_t)0U, (size_t)10U, uint8_t *));
  ------------------
  |  |  195|  13.1k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  13.1k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  13.1k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5003|  13.1k|  int16_t_x8 v8_15 =
 5004|  13.1k|      libcrux_ml_kem_vector_portable_serialize_deserialize_10_int(
 5005|  13.1k|          Eurydice_slice_subslice3(bytes, (size_t)10U, (size_t)20U, uint8_t *));
  ------------------
  |  |  195|  13.1k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  13.1k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  13.1k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5006|  13.1k|  return (
 5007|  13.1k|      KRML_CLITERAL(libcrux_ml_kem_vector_portable_vector_type_PortableVector){
  ------------------
  |  |  154|  13.1k|#define KRML_CLITERAL(type) (type)
  ------------------
 5008|  13.1k|          .elements = {v0_7.fst, v0_7.snd, v0_7.thd, v0_7.f3, v0_7.f4, v0_7.f5,
 5009|  13.1k|                       v0_7.f6, v0_7.f7, v8_15.fst, v8_15.snd, v8_15.thd,
 5010|  13.1k|                       v8_15.f3, v8_15.f4, v8_15.f5, v8_15.f6, v8_15.f7}});
 5011|  13.1k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_10_int:
 4926|  26.2k|    Eurydice_slice bytes) {
 4927|  26.2k|  int16_t r0 = libcrux_secrets_int_as_i16_f5(
 4928|  26.2k|      (libcrux_secrets_int_as_i16_59(
 4929|  26.2k|           Eurydice_slice_index(bytes, (size_t)1U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4930|  26.2k|       (int16_t)3)
 4931|  26.2k|          << 8U |
 4932|  26.2k|      (libcrux_secrets_int_as_i16_59(
 4933|  26.2k|           Eurydice_slice_index(bytes, (size_t)0U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4934|  26.2k|       (int16_t)255));
 4935|  26.2k|  int16_t r1 = libcrux_secrets_int_as_i16_f5(
 4936|  26.2k|      (libcrux_secrets_int_as_i16_59(
 4937|  26.2k|           Eurydice_slice_index(bytes, (size_t)2U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4938|  26.2k|       (int16_t)15)
 4939|  26.2k|          << 6U |
 4940|  26.2k|      libcrux_secrets_int_as_i16_59(
 4941|  26.2k|          Eurydice_slice_index(bytes, (size_t)1U, uint8_t, uint8_t *)) >>
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4942|  26.2k|          2U);
 4943|  26.2k|  int16_t r2 = libcrux_secrets_int_as_i16_f5(
 4944|  26.2k|      (libcrux_secrets_int_as_i16_59(
 4945|  26.2k|           Eurydice_slice_index(bytes, (size_t)3U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4946|  26.2k|       (int16_t)63)
 4947|  26.2k|          << 4U |
 4948|  26.2k|      libcrux_secrets_int_as_i16_59(
 4949|  26.2k|          Eurydice_slice_index(bytes, (size_t)2U, uint8_t, uint8_t *)) >>
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4950|  26.2k|          4U);
 4951|  26.2k|  int16_t r3 = libcrux_secrets_int_as_i16_f5(
 4952|  26.2k|      libcrux_secrets_int_as_i16_59(
 4953|  26.2k|          Eurydice_slice_index(bytes, (size_t)4U, uint8_t, uint8_t *))
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4954|  26.2k|          << 2U |
 4955|  26.2k|      libcrux_secrets_int_as_i16_59(
 4956|  26.2k|          Eurydice_slice_index(bytes, (size_t)3U, uint8_t, uint8_t *)) >>
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4957|  26.2k|          6U);
 4958|  26.2k|  int16_t r4 = libcrux_secrets_int_as_i16_f5(
 4959|  26.2k|      (libcrux_secrets_int_as_i16_59(
 4960|  26.2k|           Eurydice_slice_index(bytes, (size_t)6U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4961|  26.2k|       (int16_t)3)
 4962|  26.2k|          << 8U |
 4963|  26.2k|      (libcrux_secrets_int_as_i16_59(
 4964|  26.2k|           Eurydice_slice_index(bytes, (size_t)5U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4965|  26.2k|       (int16_t)255));
 4966|  26.2k|  int16_t r5 = libcrux_secrets_int_as_i16_f5(
 4967|  26.2k|      (libcrux_secrets_int_as_i16_59(
 4968|  26.2k|           Eurydice_slice_index(bytes, (size_t)7U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4969|  26.2k|       (int16_t)15)
 4970|  26.2k|          << 6U |
 4971|  26.2k|      libcrux_secrets_int_as_i16_59(
 4972|  26.2k|          Eurydice_slice_index(bytes, (size_t)6U, uint8_t, uint8_t *)) >>
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4973|  26.2k|          2U);
 4974|  26.2k|  int16_t r6 = libcrux_secrets_int_as_i16_f5(
 4975|  26.2k|      (libcrux_secrets_int_as_i16_59(
 4976|  26.2k|           Eurydice_slice_index(bytes, (size_t)8U, uint8_t, uint8_t *)) &
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4977|  26.2k|       (int16_t)63)
 4978|  26.2k|          << 4U |
 4979|  26.2k|      libcrux_secrets_int_as_i16_59(
 4980|  26.2k|          Eurydice_slice_index(bytes, (size_t)7U, uint8_t, uint8_t *)) >>
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4981|  26.2k|          4U);
 4982|  26.2k|  int16_t r7 = libcrux_secrets_int_as_i16_f5(
 4983|  26.2k|      libcrux_secrets_int_as_i16_59(
 4984|  26.2k|          Eurydice_slice_index(bytes, (size_t)9U, uint8_t, uint8_t *))
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4985|  26.2k|          << 2U |
 4986|  26.2k|      libcrux_secrets_int_as_i16_59(
 4987|  26.2k|          Eurydice_slice_index(bytes, (size_t)8U, uint8_t, uint8_t *)) >>
  ------------------
  |  |  180|  26.2k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4988|  26.2k|          6U);
 4989|  26.2k|  return (KRML_CLITERAL(int16_t_x8){.fst = r0,
  ------------------
  |  |  154|  26.2k|#define KRML_CLITERAL(type) (type)
  ------------------
 4990|  26.2k|                                    .snd = r1,
 4991|  26.2k|                                    .thd = r2,
 4992|  26.2k|                                    .f3 = r3,
 4993|  26.2k|                                    .f4 = r4,
 4994|  26.2k|                                    .f5 = r5,
 4995|  26.2k|                                    .f6 = r6,
 4996|  26.2k|                                    .f7 = r7});
 4997|  26.2k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i16_f5:
  711|   768k|static KRML_MUSTINLINE int16_t libcrux_secrets_int_as_i16_f5(int16_t self) {
  712|   768k|  return libcrux_secrets_int_public_integers_classify_27_39(
  713|   768k|      libcrux_secrets_int_public_integers_declassify_d8_39(self));
  714|   768k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_39:
  494|  64.7M|libcrux_secrets_int_public_integers_declassify_d8_39(int16_t self) {
  495|  64.7M|  return self;
  496|  64.7M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_decompress_ciphertext_coefficient_b8_ef:
 5459|  13.1k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 5460|  13.1k|  return libcrux_ml_kem_vector_portable_compress_decompress_ciphertext_coefficient_ef(
 5461|  13.1k|      a);
 5462|  13.1k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_decompress_ciphertext_coefficient_ef:
 5431|  13.1k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 5432|  13.1k|  for (size_t i = (size_t)0U;
 5433|   222k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   222k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (5433:8): [True: 209k, False: 13.1k]
  ------------------
 5434|   209k|    size_t i0 = i;
 5435|   209k|    int32_t decompressed =
 5436|   209k|        libcrux_secrets_int_as_i32_f5(a.elements[i0]) *
 5437|   209k|        libcrux_secrets_int_as_i32_f5(
 5438|   209k|            libcrux_secrets_int_public_integers_classify_27_39(
 5439|   209k|                LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS));
  ------------------
  |  | 3777|   209k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 5440|   209k|    decompressed = (decompressed << 1U) + ((int32_t)1 << (uint32_t)(int32_t)10);
 5441|   209k|    decompressed = decompressed >> (uint32_t)((int32_t)10 + (int32_t)1);
 5442|   209k|    a.elements[i0] = libcrux_secrets_int_as_i16_36(decompressed);
 5443|   209k|  }
 5444|  13.1k|  return a;
 5445|  13.1k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i32_f5:
  556|  60.6M|static KRML_MUSTINLINE int32_t libcrux_secrets_int_as_i32_f5(int16_t self) {
  557|  60.6M|  return libcrux_secrets_int_public_integers_classify_27_a8(
  558|  60.6M|      (int32_t)libcrux_secrets_int_public_integers_declassify_d8_39(self));
  559|  60.6M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_a8:
  549|  70.6M|libcrux_secrets_int_public_integers_classify_27_a8(int32_t self) {
  550|  70.6M|  return self;
  551|  70.6M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i16_36:
  577|  45.2M|static KRML_MUSTINLINE int16_t libcrux_secrets_int_as_i16_36(int32_t self) {
  578|  45.2M|  return libcrux_secrets_int_public_integers_classify_27_39(
  579|  45.2M|      (int16_t)libcrux_secrets_int_public_integers_declassify_d8_a8(self));
  580|  45.2M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_a8:
  570|  45.2M|libcrux_secrets_int_public_integers_declassify_d8_a8(int32_t self) {
  571|  45.2M|  return self;
  572|  45.2M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_vector_u_0a:
 5663|    819|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 5664|    819|  size_t zeta_i = (size_t)0U;
 5665|    819|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)7U,
 5666|    819|                                            (size_t)3328U);
 5667|    819|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)6U,
 5668|    819|                                            (size_t)2U * (size_t)3328U);
 5669|    819|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)5U,
 5670|    819|                                            (size_t)3U * (size_t)3328U);
 5671|    819|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)4U,
 5672|    819|                                            (size_t)4U * (size_t)3328U);
 5673|    819|  libcrux_ml_kem_ntt_ntt_at_layer_3_ea(&zeta_i, re, (size_t)5U * (size_t)3328U);
 5674|    819|  libcrux_ml_kem_ntt_ntt_at_layer_2_ea(&zeta_i, re, (size_t)6U * (size_t)3328U);
 5675|    819|  libcrux_ml_kem_ntt_ntt_at_layer_1_ea(&zeta_i, re, (size_t)7U * (size_t)3328U);
 5676|    819|  libcrux_ml_kem_polynomial_poly_barrett_reduce_d6_ea(re);
 5677|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea:
 5538|  13.1k|    size_t layer, size_t _initial_coefficient_bound) {
 5539|  13.1k|  size_t step = (size_t)1U << (uint32_t)layer;
 5540|  71.2k|  for (size_t i0 = (size_t)0U; i0 < (size_t)128U >> (uint32_t)layer; i0++) {
  ------------------
  |  Branch (5540:32): [True: 58.1k, False: 13.1k]
  ------------------
 5541|  58.1k|    size_t round = i0;
 5542|  58.1k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5543|  58.1k|    size_t offset = round * step * (size_t)2U;
 5544|  58.1k|    size_t offset_vec = offset / (size_t)16U;
 5545|  58.1k|    size_t step_vec = step / (size_t)16U;
 5546|   162k|    for (size_t i = offset_vec; i < offset_vec + step_vec; i++) {
  ------------------
  |  Branch (5546:33): [True: 104k, False: 58.1k]
  ------------------
 5547|   104k|      size_t j = i;
 5548|   104k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2 uu____0 =
 5549|   104k|          libcrux_ml_kem_ntt_ntt_layer_int_vec_step_ea(
 5550|   104k|              re->coefficients[j], re->coefficients[j + step_vec],
 5551|   104k|              libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
 5552|   104k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector x = uu____0.fst;
 5553|   104k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector y = uu____0.snd;
 5554|   104k|      re->coefficients[j] = x;
 5555|   104k|      re->coefficients[j + step_vec] = y;
 5556|   104k|    }
 5557|  58.1k|  }
 5558|  13.1k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_layer_int_vec_step_ea:
 5519|   104k|        int16_t zeta_r) {
 5520|   104k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector t =
 5521|   104k|      libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(b,
 5522|   104k|                                                                        zeta_r);
 5523|   104k|  b = libcrux_ml_kem_vector_portable_sub_b8(a, &t);
 5524|   104k|  a = libcrux_ml_kem_vector_portable_add_b8(a, &t);
 5525|   104k|  return (KRML_CLITERAL(
  ------------------
  |  |  154|   104k|#define KRML_CLITERAL(type) (type)
  ------------------
 5526|   104k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2){.fst = a,
 5527|   104k|                                                                    .snd = b});
 5528|   104k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8:
 4077|   235k|    int16_t constant) {
 4078|   235k|  return libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_by_constant(
 4079|   235k|      vector, libcrux_secrets_int_public_integers_classify_27_39(constant));
 4080|   235k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_by_constant:
 4059|   235k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec, int16_t c) {
 4060|   235k|  for (size_t i = (size_t)0U;
 4061|  4.00M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  4.00M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (4061:8): [True: 3.77M, False: 235k]
  ------------------
 4062|  3.77M|    size_t i0 = i;
 4063|  3.77M|    vec.elements[i0] =
 4064|  3.77M|        libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer(
 4065|  3.77M|            vec.elements[i0], c);
 4066|  3.77M|  }
 4067|   235k|  return vec;
 4068|   235k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer:
 4050|  6.28M|    int16_t fe, int16_t fer) {
 4051|  6.28M|  int32_t product =
 4052|  6.28M|      libcrux_secrets_int_as_i32_f5(fe) * libcrux_secrets_int_as_i32_f5(fer);
 4053|  6.28M|  return libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(
 4054|  6.28M|      product);
 4055|  6.28M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element:
 4017|  10.0M|    int32_t value) {
 4018|  10.0M|  int32_t k =
 4019|  10.0M|      libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_as_i16_36(value)) *
 4020|  10.0M|      libcrux_secrets_int_as_i32_b8(
 4021|  10.0M|          libcrux_secrets_int_public_integers_classify_27_df(
 4022|  10.0M|              LIBCRUX_ML_KEM_VECTOR_TRAITS_INVERSE_OF_MODULUS_MOD_MONTGOMERY_R));
  ------------------
  |  | 3780|  10.0M|  (62209U)
  ------------------
 4023|  10.0M|  int32_t k_times_modulus =
 4024|  10.0M|      libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_as_i16_36(k)) *
 4025|  10.0M|      libcrux_secrets_int_as_i32_f5(
 4026|  10.0M|          libcrux_secrets_int_public_integers_classify_27_39(
 4027|  10.0M|              LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS));
  ------------------
  |  | 3777|  10.0M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 4028|  10.0M|  int16_t c = libcrux_secrets_int_as_i16_36(
 4029|  10.0M|      k_times_modulus >>
 4030|  10.0M|      (uint32_t)LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT);
  ------------------
  |  | 3997|  10.0M|#define LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT (16U)
  ------------------
 4031|  10.0M|  int16_t value_high = libcrux_secrets_int_as_i16_36(
 4032|  10.0M|      value >>
 4033|  10.0M|      (uint32_t)LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT);
  ------------------
  |  | 3997|  10.0M|#define LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT (16U)
  ------------------
 4034|  10.0M|  return value_high - c;
 4035|  10.0M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i32_b8:
  598|  10.0M|static KRML_MUSTINLINE int32_t libcrux_secrets_int_as_i32_b8(uint32_t self) {
  599|  10.0M|  return libcrux_secrets_int_public_integers_classify_27_a8(
  600|  10.0M|      (int32_t)libcrux_secrets_int_public_integers_declassify_d8_df(self));
  601|  10.0M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_df:
  591|  10.6M|libcrux_secrets_int_public_integers_declassify_d8_df(uint32_t self) {
  592|  10.6M|  return self;
  593|  10.6M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_df:
  675|  10.6M|libcrux_secrets_int_public_integers_classify_27_df(uint32_t self) {
  676|  10.6M|  return self;
  677|  10.6M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_sub_b8:
 3884|   214k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector *rhs) {
 3885|   214k|  return libcrux_ml_kem_vector_portable_arithmetic_sub(lhs, rhs);
 3886|   214k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_sub:
 3867|   222k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector *rhs) {
 3868|   222k|  for (size_t i = (size_t)0U;
 3869|  3.78M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  3.78M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3869:8): [True: 3.56M, False: 222k]
  ------------------
 3870|  3.56M|    size_t i0 = i;
 3871|  3.56M|    size_t uu____0 = i0;
 3872|  3.56M|    lhs.elements[uu____0] = lhs.elements[uu____0] - rhs->elements[i0];
 3873|  3.56M|  }
 3874|   222k|  return lhs;
 3875|   222k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_add_b8:
 3860|   423k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector *rhs) {
 3861|   423k|  return libcrux_ml_kem_vector_portable_arithmetic_add(lhs, rhs);
 3862|   423k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_add:
 3843|   502k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector *rhs) {
 3844|   502k|  for (size_t i = (size_t)0U;
 3845|  8.53M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  8.53M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3845:8): [True: 8.03M, False: 502k]
  ------------------
 3846|  8.03M|    size_t i0 = i;
 3847|  8.03M|    size_t uu____0 = i0;
 3848|  8.03M|    lhs.elements[uu____0] = lhs.elements[uu____0] + rhs->elements[i0];
 3849|  8.03M|  }
 3850|   502k|  return lhs;
 3851|   502k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_zeta:
 3766|  1.54M|static KRML_MUSTINLINE int16_t libcrux_ml_kem_polynomial_zeta(size_t i) {
 3767|  1.54M|  return libcrux_ml_kem_polynomial_ZETAS_TIMES_MONTGOMERY_R[i];
 3768|  1.54M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_3_ea:
 5568|  4.09k|    size_t _initial_coefficient_bound) {
 5569|  69.6k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5569:31): [True: 65.5k, False: 4.09k]
  ------------------
 5570|  65.5k|    size_t round = i;
 5571|  65.5k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5572|  65.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5573|  65.5k|        libcrux_ml_kem_vector_portable_ntt_layer_3_step_b8(
 5574|  65.5k|            re->coefficients[round],
 5575|  65.5k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
 5576|  65.5k|    re->coefficients[round] = uu____0;
 5577|  65.5k|  }
 5578|  4.09k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_layer_3_step_b8:
 4344|  65.5k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a, int16_t zeta) {
 4345|  65.5k|  return libcrux_ml_kem_vector_portable_ntt_ntt_layer_3_step(a, zeta);
 4346|  65.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_layer_3_step:
 4318|  65.5k|    int16_t zeta) {
 4319|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)0U,
 4320|  65.5k|                                              (size_t)8U);
 4321|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)1U,
 4322|  65.5k|                                              (size_t)9U);
 4323|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)2U,
 4324|  65.5k|                                              (size_t)10U);
 4325|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)3U,
 4326|  65.5k|                                              (size_t)11U);
 4327|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)4U,
 4328|  65.5k|                                              (size_t)12U);
 4329|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)5U,
 4330|  65.5k|                                              (size_t)13U);
 4331|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)6U,
 4332|  65.5k|                                              (size_t)14U);
 4333|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)7U,
 4334|  65.5k|                                              (size_t)15U);
 4335|  65.5k|  return vec;
 4336|  65.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_step:
 4235|  1.57M|    int16_t zeta, size_t i, size_t j) {
 4236|  1.57M|  int16_t t =
 4237|  1.57M|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer(
 4238|  1.57M|          vec->elements[j],
 4239|  1.57M|          libcrux_secrets_int_public_integers_classify_27_39(zeta));
 4240|  1.57M|  int16_t a_minus_t = vec->elements[i] - t;
 4241|  1.57M|  int16_t a_plus_t = vec->elements[i] + t;
 4242|  1.57M|  vec->elements[j] = a_minus_t;
 4243|  1.57M|  vec->elements[i] = a_plus_t;
 4244|  1.57M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_2_ea:
 5588|  4.09k|    size_t _initial_coefficient_bound) {
 5589|  69.6k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5589:31): [True: 65.5k, False: 4.09k]
  ------------------
 5590|  65.5k|    size_t round = i;
 5591|  65.5k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5592|  65.5k|    re->coefficients[round] =
 5593|  65.5k|        libcrux_ml_kem_vector_portable_ntt_layer_2_step_b8(
 5594|  65.5k|            re->coefficients[round], libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
 5595|  65.5k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)1U));
 5596|  65.5k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5597|  65.5k|  }
 5598|  4.09k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_layer_2_step_b8:
 4311|  65.5k|    int16_t zeta1) {
 4312|  65.5k|  return libcrux_ml_kem_vector_portable_ntt_ntt_layer_2_step(a, zeta0, zeta1);
 4313|  65.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_layer_2_step:
 4284|  65.5k|    int16_t zeta0, int16_t zeta1) {
 4285|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)0U,
 4286|  65.5k|                                              (size_t)4U);
 4287|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)1U,
 4288|  65.5k|                                              (size_t)5U);
 4289|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)2U,
 4290|  65.5k|                                              (size_t)6U);
 4291|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)3U,
 4292|  65.5k|                                              (size_t)7U);
 4293|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)8U,
 4294|  65.5k|                                              (size_t)12U);
 4295|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)9U,
 4296|  65.5k|                                              (size_t)13U);
 4297|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)10U,
 4298|  65.5k|                                              (size_t)14U);
 4299|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)11U,
 4300|  65.5k|                                              (size_t)15U);
 4301|  65.5k|  return vec;
 4302|  65.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_1_ea:
 5608|  4.09k|    size_t _initial_coefficient_bound) {
 5609|  69.6k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5609:31): [True: 65.5k, False: 4.09k]
  ------------------
 5610|  65.5k|    size_t round = i;
 5611|  65.5k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5612|  65.5k|    re->coefficients[round] =
 5613|  65.5k|        libcrux_ml_kem_vector_portable_ntt_layer_1_step_b8(
 5614|  65.5k|            re->coefficients[round], libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
 5615|  65.5k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)1U),
 5616|  65.5k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)2U),
 5617|  65.5k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)3U));
 5618|  65.5k|    zeta_i[0U] = zeta_i[0U] + (size_t)3U;
 5619|  65.5k|  }
 5620|  4.09k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_layer_1_step_b8:
 4276|  65.5k|    int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4277|  65.5k|  return libcrux_ml_kem_vector_portable_ntt_ntt_layer_1_step(a, zeta0, zeta1,
 4278|  65.5k|                                                             zeta2, zeta3);
 4279|  65.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_layer_1_step:
 4249|  65.5k|    int16_t zeta0, int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4250|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)0U,
 4251|  65.5k|                                              (size_t)2U);
 4252|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)1U,
 4253|  65.5k|                                              (size_t)3U);
 4254|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)4U,
 4255|  65.5k|                                              (size_t)6U);
 4256|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)5U,
 4257|  65.5k|                                              (size_t)7U);
 4258|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta2, (size_t)8U,
 4259|  65.5k|                                              (size_t)10U);
 4260|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta2, (size_t)9U,
 4261|  65.5k|                                              (size_t)11U);
 4262|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta3, (size_t)12U,
 4263|  65.5k|                                              (size_t)14U);
 4264|  65.5k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta3, (size_t)13U,
 4265|  65.5k|                                              (size_t)15U);
 4266|  65.5k|  return vec;
 4267|  65.5k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_poly_barrett_reduce_d6_ea:
 5652|  6.55k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *self) {
 5653|  6.55k|  libcrux_ml_kem_polynomial_poly_barrett_reduce_ea(self);
 5654|  6.55k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_poly_barrett_reduce_ea:
 5629|  6.55k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *myself) {
 5630|  6.55k|  for (size_t i = (size_t)0U;
 5631|   111k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|   111k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (5631:8): [True: 104k, False: 6.55k]
  ------------------
 5632|   104k|    size_t i0 = i;
 5633|   104k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5634|   104k|        libcrux_ml_kem_vector_portable_barrett_reduce_b8(
 5635|   104k|            myself->coefficients[i0]);
 5636|   104k|    myself->coefficients[i0] = uu____0;
 5637|   104k|  }
 5638|  6.55k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_barrett_reduce_b8:
 3993|   235k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vector) {
 3994|   235k|  return libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce(vector);
 3995|   235k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce:
 3975|   235k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec) {
 3976|   235k|  for (size_t i = (size_t)0U;
 3977|  4.00M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  4.00M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3977:8): [True: 3.77M, False: 235k]
  ------------------
 3978|  3.77M|    size_t i0 = i;
 3979|  3.77M|    int16_t vi =
 3980|  3.77M|        libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce_element(
 3981|  3.77M|            vec.elements[i0]);
 3982|  3.77M|    vec.elements[i0] = vi;
 3983|  3.77M|  }
 3984|   235k|  return vec;
 3985|   235k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce_element:
 3964|  4.71M|    int16_t value) {
 3965|  4.71M|  int32_t t = libcrux_secrets_int_as_i32_f5(value) *
 3966|  4.71M|                  LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_BARRETT_MULTIPLIER +
  ------------------
  |  | 3940|  4.71M|  ((int32_t)20159)
  ------------------
 3967|  4.71M|              (LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_R >> 1U);
  ------------------
  |  | 3945|  4.71M|  ((int32_t)1 << (uint32_t)LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT)
  |  |  ------------------
  |  |  |  | 3942|  4.71M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT ((int32_t)26)
  |  |  ------------------
  ------------------
 3968|  4.71M|  int16_t quotient = libcrux_secrets_int_as_i16_36(
 3969|  4.71M|      t >> (uint32_t)LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT);
  ------------------
  |  | 3942|  4.71M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT ((int32_t)26)
  ------------------
 3970|  4.71M|  return value - quotient * LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS;
  ------------------
  |  | 3777|  4.71M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 3971|  4.71M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_then_decompress_ring_element_v_89:
 5806|    273|    Eurydice_slice serialized) {
 5807|    273|  return libcrux_ml_kem_serialize_deserialize_then_decompress_4_ea(serialized);
 5808|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_then_decompress_4_ea:
 5779|    273|    Eurydice_slice serialized) {
 5780|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d re =
 5781|    273|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 5782|    273|  for (size_t i = (size_t)0U;
 5783|  4.64k|       i < Eurydice_slice_len(serialized, uint8_t) / (size_t)8U; i++) {
  ------------------
  |  |  173|  4.64k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5783:8): [True: 4.36k, False: 273]
  ------------------
 5784|  4.36k|    size_t i0 = i;
 5785|  4.36k|    Eurydice_slice bytes = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  4.36k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  4.36k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  4.36k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5786|  4.36k|        serialized, i0 * (size_t)8U, i0 * (size_t)8U + (size_t)8U, uint8_t *);
 5787|  4.36k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 5788|  4.36k|        libcrux_ml_kem_vector_portable_deserialize_4_b8(bytes);
 5789|  4.36k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5790|  4.36k|        libcrux_ml_kem_vector_portable_decompress_ciphertext_coefficient_b8_d1(
 5791|  4.36k|            coefficient);
 5792|  4.36k|    re.coefficients[i0] = uu____0;
 5793|  4.36k|  }
 5794|    273|  return re;
 5795|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_4_b8:
 4824|  4.36k|libcrux_ml_kem_vector_portable_deserialize_4_b8(Eurydice_slice a) {
 4825|  4.36k|  return libcrux_ml_kem_vector_portable_deserialize_4(a);
 4826|  4.36k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_4:
 4814|  4.36k|libcrux_ml_kem_vector_portable_deserialize_4(Eurydice_slice a) {
 4815|  4.36k|  return libcrux_ml_kem_vector_portable_serialize_deserialize_4(
 4816|  4.36k|      libcrux_secrets_int_classify_public_classify_ref_9b_90(a));
 4817|  4.36k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_4:
 4801|  4.36k|libcrux_ml_kem_vector_portable_serialize_deserialize_4(Eurydice_slice bytes) {
 4802|  4.36k|  int16_t_x8 v0_7 = libcrux_ml_kem_vector_portable_serialize_deserialize_4_int(
 4803|  4.36k|      Eurydice_slice_subslice3(bytes, (size_t)0U, (size_t)4U, uint8_t *));
  ------------------
  |  |  195|  4.36k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  4.36k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  4.36k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4804|  4.36k|  int16_t_x8 v8_15 = libcrux_ml_kem_vector_portable_serialize_deserialize_4_int(
 4805|  4.36k|      Eurydice_slice_subslice3(bytes, (size_t)4U, (size_t)8U, uint8_t *));
  ------------------
  |  |  195|  4.36k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  4.36k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  4.36k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4806|  4.36k|  return (
 4807|  4.36k|      KRML_CLITERAL(libcrux_ml_kem_vector_portable_vector_type_PortableVector){
  ------------------
  |  |  154|  4.36k|#define KRML_CLITERAL(type) (type)
  ------------------
 4808|  4.36k|          .elements = {v0_7.fst, v0_7.snd, v0_7.thd, v0_7.f3, v0_7.f4, v0_7.f5,
 4809|  4.36k|                       v0_7.f6, v0_7.f7, v8_15.fst, v8_15.snd, v8_15.thd,
 4810|  4.36k|                       v8_15.f3, v8_15.f4, v8_15.f5, v8_15.f6, v8_15.f7}});
 4811|  4.36k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_4_int:
 4761|  8.73k|    Eurydice_slice bytes) {
 4762|  8.73k|  int16_t v0 = libcrux_secrets_int_as_i16_59(
 4763|  8.73k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)0U, uint8_t, uint8_t *) &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4764|  8.73k|      15U);
 4765|  8.73k|  int16_t v1 = libcrux_secrets_int_as_i16_59(
 4766|  8.73k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)0U, uint8_t, uint8_t *) >>
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4767|  8.73k|          4U &
 4768|  8.73k|      15U);
 4769|  8.73k|  int16_t v2 = libcrux_secrets_int_as_i16_59(
 4770|  8.73k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)1U, uint8_t, uint8_t *) &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4771|  8.73k|      15U);
 4772|  8.73k|  int16_t v3 = libcrux_secrets_int_as_i16_59(
 4773|  8.73k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)1U, uint8_t, uint8_t *) >>
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4774|  8.73k|          4U &
 4775|  8.73k|      15U);
 4776|  8.73k|  int16_t v4 = libcrux_secrets_int_as_i16_59(
 4777|  8.73k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)2U, uint8_t, uint8_t *) &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4778|  8.73k|      15U);
 4779|  8.73k|  int16_t v5 = libcrux_secrets_int_as_i16_59(
 4780|  8.73k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)2U, uint8_t, uint8_t *) >>
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4781|  8.73k|          4U &
 4782|  8.73k|      15U);
 4783|  8.73k|  int16_t v6 = libcrux_secrets_int_as_i16_59(
 4784|  8.73k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)3U, uint8_t, uint8_t *) &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4785|  8.73k|      15U);
 4786|  8.73k|  int16_t v7 = libcrux_secrets_int_as_i16_59(
 4787|  8.73k|      (uint32_t)Eurydice_slice_index(bytes, (size_t)3U, uint8_t, uint8_t *) >>
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4788|  8.73k|          4U &
 4789|  8.73k|      15U);
 4790|  8.73k|  return (KRML_CLITERAL(int16_t_x8){.fst = v0,
  ------------------
  |  |  154|  8.73k|#define KRML_CLITERAL(type) (type)
  ------------------
 4791|  8.73k|                                    .snd = v1,
 4792|  8.73k|                                    .thd = v2,
 4793|  8.73k|                                    .f3 = v3,
 4794|  8.73k|                                    .f4 = v4,
 4795|  8.73k|                                    .f5 = v5,
 4796|  8.73k|                                    .f6 = v6,
 4797|  8.73k|                                    .f7 = v7});
 4798|  8.73k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_decompress_ciphertext_coefficient_b8_d1:
 5766|  4.36k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 5767|  4.36k|  return libcrux_ml_kem_vector_portable_compress_decompress_ciphertext_coefficient_d1(
 5768|  4.36k|      a);
 5769|  4.36k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_decompress_ciphertext_coefficient_d1:
 5738|  4.36k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 5739|  4.36k|  for (size_t i = (size_t)0U;
 5740|  74.2k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  74.2k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (5740:8): [True: 69.8k, False: 4.36k]
  ------------------
 5741|  69.8k|    size_t i0 = i;
 5742|  69.8k|    int32_t decompressed =
 5743|  69.8k|        libcrux_secrets_int_as_i32_f5(a.elements[i0]) *
 5744|  69.8k|        libcrux_secrets_int_as_i32_f5(
 5745|  69.8k|            libcrux_secrets_int_public_integers_classify_27_39(
 5746|  69.8k|                LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS));
  ------------------
  |  | 3777|  69.8k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 5747|  69.8k|    decompressed = (decompressed << 1U) + ((int32_t)1 << (uint32_t)(int32_t)4);
 5748|  69.8k|    decompressed = decompressed >> (uint32_t)((int32_t)4 + (int32_t)1);
 5749|  69.8k|    a.elements[i0] = libcrux_secrets_int_as_i16_36(decompressed);
 5750|  69.8k|  }
 5751|  4.36k|  return a;
 5752|  4.36k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_compute_message_1b:
 6150|    273|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *u_as_ntt) {
 6151|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d result =
 6152|    273|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 6153|  1.09k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6153:31): [True: 819, False: 273]
  ------------------
 6154|    819|    size_t i0 = i;
 6155|    819|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d product =
 6156|    819|        libcrux_ml_kem_polynomial_ntt_multiply_d6_ea(&secret_as_ntt[i0],
 6157|    819|                                                     &u_as_ntt[i0]);
 6158|    819|    libcrux_ml_kem_polynomial_add_to_ring_element_d6_1b(&result, &product);
 6159|    819|  }
 6160|    273|  libcrux_ml_kem_invert_ntt_invert_ntt_montgomery_1b(&result);
 6161|    273|  return libcrux_ml_kem_polynomial_subtract_reduce_d6_ea(v, result);
 6162|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_ntt_multiply_d6_ea:
 5901|  9.82k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *rhs) {
 5902|  9.82k|  return libcrux_ml_kem_polynomial_ntt_multiply_ea(self, rhs);
 5903|  9.82k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_ntt_multiply_ea:
 5866|  9.82k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *rhs) {
 5867|  9.82k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d out =
 5868|  9.82k|      libcrux_ml_kem_polynomial_ZERO_ea();
 5869|  9.82k|  for (size_t i = (size_t)0U;
 5870|   167k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|   167k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (5870:8): [True: 157k, False: 9.82k]
  ------------------
 5871|   157k|    size_t i0 = i;
 5872|   157k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5873|   157k|        libcrux_ml_kem_vector_portable_ntt_multiply_b8(
 5874|   157k|            &myself->coefficients[i0], &rhs->coefficients[i0],
 5875|   157k|            libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0),
 5876|   157k|            libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0 +
 5877|   157k|                                           (size_t)1U),
 5878|   157k|            libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0 +
 5879|   157k|                                           (size_t)2U),
 5880|   157k|            libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0 +
 5881|   157k|                                           (size_t)3U));
 5882|   157k|    out.coefficients[i0] = uu____0;
 5883|   157k|  }
 5884|  9.82k|  return out;
 5885|  9.82k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_ZERO_ea:
 5817|  22.6k|libcrux_ml_kem_polynomial_ZERO_ea(void) {
 5818|  22.6k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d lit;
 5819|  22.6k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector
 5820|  22.6k|      repeat_expression[16U];
 5821|   385k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5821:31): [True: 362k, False: 22.6k]
  ------------------
 5822|   362k|    repeat_expression[i] = libcrux_ml_kem_vector_portable_ZERO_b8();
 5823|   362k|  }
 5824|  22.6k|  memcpy(lit.coefficients, repeat_expression,
 5825|  22.6k|         (size_t)16U *
 5826|  22.6k|             sizeof(libcrux_ml_kem_vector_portable_vector_type_PortableVector));
 5827|  22.6k|  return lit;
 5828|  22.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_multiply_b8:
 4567|   157k|    int16_t zeta0, int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4568|   157k|  return libcrux_ml_kem_vector_portable_ntt_ntt_multiply(lhs, rhs, zeta0, zeta1,
 4569|   157k|                                                         zeta2, zeta3);
 4570|   157k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_multiply:
 4525|   157k|    int16_t zeta0, int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4526|   157k|  int16_t nzeta0 = -zeta0;
 4527|   157k|  int16_t nzeta1 = -zeta1;
 4528|   157k|  int16_t nzeta2 = -zeta2;
 4529|   157k|  int16_t nzeta3 = -zeta3;
 4530|   157k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector out =
 4531|   157k|      libcrux_ml_kem_vector_portable_vector_type_zero();
 4532|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4533|   157k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(zeta0),
 4534|   157k|      (size_t)0U, &out);
 4535|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4536|   157k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(nzeta0),
 4537|   157k|      (size_t)1U, &out);
 4538|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4539|   157k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(zeta1),
 4540|   157k|      (size_t)2U, &out);
 4541|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4542|   157k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(nzeta1),
 4543|   157k|      (size_t)3U, &out);
 4544|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4545|   157k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(zeta2),
 4546|   157k|      (size_t)4U, &out);
 4547|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4548|   157k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(nzeta2),
 4549|   157k|      (size_t)5U, &out);
 4550|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4551|   157k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(zeta3),
 4552|   157k|      (size_t)6U, &out);
 4553|   157k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4554|   157k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(nzeta3),
 4555|   157k|      (size_t)7U, &out);
 4556|   157k|  return out;
 4557|   157k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials:
 4491|  1.25M|    size_t i, libcrux_ml_kem_vector_portable_vector_type_PortableVector *out) {
 4492|  1.25M|  int16_t ai = a->elements[(size_t)2U * i];
 4493|  1.25M|  int16_t bi = b->elements[(size_t)2U * i];
 4494|  1.25M|  int16_t aj = a->elements[(size_t)2U * i + (size_t)1U];
 4495|  1.25M|  int16_t bj = b->elements[(size_t)2U * i + (size_t)1U];
 4496|  1.25M|  int32_t ai_bi =
 4497|  1.25M|      libcrux_secrets_int_as_i32_f5(ai) * libcrux_secrets_int_as_i32_f5(bi);
 4498|  1.25M|  int32_t aj_bj_ =
 4499|  1.25M|      libcrux_secrets_int_as_i32_f5(aj) * libcrux_secrets_int_as_i32_f5(bj);
 4500|  1.25M|  int16_t aj_bj =
 4501|  1.25M|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(
 4502|  1.25M|          aj_bj_);
 4503|  1.25M|  int32_t aj_bj_zeta = libcrux_secrets_int_as_i32_f5(aj_bj) *
 4504|  1.25M|                       libcrux_secrets_int_as_i32_f5(zeta);
 4505|  1.25M|  int32_t ai_bi_aj_bj = ai_bi + aj_bj_zeta;
 4506|  1.25M|  int16_t o0 =
 4507|  1.25M|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(
 4508|  1.25M|          ai_bi_aj_bj);
 4509|  1.25M|  int32_t ai_bj =
 4510|  1.25M|      libcrux_secrets_int_as_i32_f5(ai) * libcrux_secrets_int_as_i32_f5(bj);
 4511|  1.25M|  int32_t aj_bi =
 4512|  1.25M|      libcrux_secrets_int_as_i32_f5(aj) * libcrux_secrets_int_as_i32_f5(bi);
 4513|  1.25M|  int32_t ai_bj_aj_bi = ai_bj + aj_bi;
 4514|  1.25M|  int16_t o1 =
 4515|  1.25M|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(
 4516|  1.25M|          ai_bj_aj_bi);
 4517|  1.25M|  out->elements[(size_t)2U * i] = o0;
 4518|  1.25M|  out->elements[(size_t)2U * i + (size_t)1U] = o1;
 4519|  1.25M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_to_ring_element_d6_1b:
 5946|  9.82k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *rhs) {
 5947|  9.82k|  libcrux_ml_kem_polynomial_add_to_ring_element_1b(self, rhs);
 5948|  9.82k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_to_ring_element_1b:
 5917|  9.82k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *rhs) {
 5918|  9.82k|  for (size_t i = (size_t)0U;
 5919|   167k|       i < Eurydice_slice_len(
  ------------------
  |  |  173|   167k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5919:8): [True: 157k, False: 9.82k]
  ------------------
 5920|  9.82k|               Eurydice_array_to_slice(
 5921|  9.82k|                   (size_t)16U, myself->coefficients,
 5922|  9.82k|                   libcrux_ml_kem_vector_portable_vector_type_PortableVector),
 5923|  9.82k|               libcrux_ml_kem_vector_portable_vector_type_PortableVector);
 5924|   157k|       i++) {
 5925|   157k|    size_t i0 = i;
 5926|   157k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5927|   157k|        libcrux_ml_kem_vector_portable_add_b8(myself->coefficients[i0],
 5928|   157k|                                              &rhs->coefficients[i0]);
 5929|   157k|    myself->coefficients[i0] = uu____0;
 5930|   157k|  }
 5931|  9.82k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_invert_ntt_invert_ntt_montgomery_1b:
 6072|  2.45k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 6073|  2.45k|  size_t zeta_i =
 6074|  2.45k|      LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT / (size_t)2U;
  ------------------
  |  |  447|  2.45k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6075|  2.45k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_1_ea(&zeta_i, re);
 6076|  2.45k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_2_ea(&zeta_i, re);
 6077|  2.45k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_3_ea(&zeta_i, re);
 6078|  2.45k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_4_plus_ea(&zeta_i, re,
 6079|  2.45k|                                                          (size_t)4U);
 6080|  2.45k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_4_plus_ea(&zeta_i, re,
 6081|  2.45k|                                                          (size_t)5U);
 6082|  2.45k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_4_plus_ea(&zeta_i, re,
 6083|  2.45k|                                                          (size_t)6U);
 6084|  2.45k|  libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_4_plus_ea(&zeta_i, re,
 6085|  2.45k|                                                          (size_t)7U);
 6086|  2.45k|  libcrux_ml_kem_polynomial_poly_barrett_reduce_d6_ea(re);
 6087|  2.45k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_1_ea:
 5957|  2.45k|    size_t *zeta_i, libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 5958|  41.7k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5958:31): [True: 39.3k, False: 2.45k]
  ------------------
 5959|  39.3k|    size_t round = i;
 5960|  39.3k|    zeta_i[0U] = zeta_i[0U] - (size_t)1U;
 5961|  39.3k|    re->coefficients[round] =
 5962|  39.3k|        libcrux_ml_kem_vector_portable_inv_ntt_layer_1_step_b8(
 5963|  39.3k|            re->coefficients[round], libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
 5964|  39.3k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] - (size_t)1U),
 5965|  39.3k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] - (size_t)2U),
 5966|  39.3k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] - (size_t)3U));
 5967|  39.3k|    zeta_i[0U] = zeta_i[0U] - (size_t)3U;
 5968|  39.3k|  }
 5969|  2.45k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_inv_ntt_layer_1_step_b8:
 4392|  39.3k|    int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4393|  39.3k|  return libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_1_step(
 4394|  39.3k|      a, zeta0, zeta1, zeta2, zeta3);
 4395|  39.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_1_step:
 4365|  39.3k|    int16_t zeta0, int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4366|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)0U,
 4367|  39.3k|                                                  (size_t)2U);
 4368|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)1U,
 4369|  39.3k|                                                  (size_t)3U);
 4370|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)4U,
 4371|  39.3k|                                                  (size_t)6U);
 4372|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)5U,
 4373|  39.3k|                                                  (size_t)7U);
 4374|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta2, (size_t)8U,
 4375|  39.3k|                                                  (size_t)10U);
 4376|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta2, (size_t)9U,
 4377|  39.3k|                                                  (size_t)11U);
 4378|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta3, (size_t)12U,
 4379|  39.3k|                                                  (size_t)14U);
 4380|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta3, (size_t)13U,
 4381|  39.3k|                                                  (size_t)15U);
 4382|  39.3k|  return vec;
 4383|  39.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_inv_ntt_step:
 4350|   943k|    int16_t zeta, size_t i, size_t j) {
 4351|   943k|  int16_t a_minus_b = vec->elements[j] - vec->elements[i];
 4352|   943k|  int16_t a_plus_b = vec->elements[j] + vec->elements[i];
 4353|   943k|  int16_t o0 = libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce_element(
 4354|   943k|      a_plus_b);
 4355|   943k|  int16_t o1 =
 4356|   943k|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer(
 4357|   943k|          a_minus_b, libcrux_secrets_int_public_integers_classify_27_39(zeta));
 4358|   943k|  vec->elements[i] = o0;
 4359|   943k|  vec->elements[j] = o1;
 4360|   943k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_2_ea:
 5978|  2.45k|    size_t *zeta_i, libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 5979|  41.7k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5979:31): [True: 39.3k, False: 2.45k]
  ------------------
 5980|  39.3k|    size_t round = i;
 5981|  39.3k|    zeta_i[0U] = zeta_i[0U] - (size_t)1U;
 5982|  39.3k|    re->coefficients[round] =
 5983|  39.3k|        libcrux_ml_kem_vector_portable_inv_ntt_layer_2_step_b8(
 5984|  39.3k|            re->coefficients[round], libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
 5985|  39.3k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] - (size_t)1U));
 5986|  39.3k|    zeta_i[0U] = zeta_i[0U] - (size_t)1U;
 5987|  39.3k|  }
 5988|  2.45k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_inv_ntt_layer_2_step_b8:
 4427|  39.3k|    int16_t zeta1) {
 4428|  39.3k|  return libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_2_step(a, zeta0,
 4429|  39.3k|                                                                 zeta1);
 4430|  39.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_2_step:
 4400|  39.3k|    int16_t zeta0, int16_t zeta1) {
 4401|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)0U,
 4402|  39.3k|                                                  (size_t)4U);
 4403|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)1U,
 4404|  39.3k|                                                  (size_t)5U);
 4405|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)2U,
 4406|  39.3k|                                                  (size_t)6U);
 4407|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta0, (size_t)3U,
 4408|  39.3k|                                                  (size_t)7U);
 4409|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)8U,
 4410|  39.3k|                                                  (size_t)12U);
 4411|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)9U,
 4412|  39.3k|                                                  (size_t)13U);
 4413|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)10U,
 4414|  39.3k|                                                  (size_t)14U);
 4415|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta1, (size_t)11U,
 4416|  39.3k|                                                  (size_t)15U);
 4417|  39.3k|  return vec;
 4418|  39.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_3_ea:
 5997|  2.45k|    size_t *zeta_i, libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 5998|  41.7k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5998:31): [True: 39.3k, False: 2.45k]
  ------------------
 5999|  39.3k|    size_t round = i;
 6000|  39.3k|    zeta_i[0U] = zeta_i[0U] - (size_t)1U;
 6001|  39.3k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 6002|  39.3k|        libcrux_ml_kem_vector_portable_inv_ntt_layer_3_step_b8(
 6003|  39.3k|            re->coefficients[round],
 6004|  39.3k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
 6005|  39.3k|    re->coefficients[round] = uu____0;
 6006|  39.3k|  }
 6007|  2.45k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_inv_ntt_layer_3_step_b8:
 4461|  39.3k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a, int16_t zeta) {
 4462|  39.3k|  return libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_3_step(a, zeta);
 4463|  39.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_inv_ntt_layer_3_step:
 4435|  39.3k|    int16_t zeta) {
 4436|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)0U,
 4437|  39.3k|                                                  (size_t)8U);
 4438|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)1U,
 4439|  39.3k|                                                  (size_t)9U);
 4440|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)2U,
 4441|  39.3k|                                                  (size_t)10U);
 4442|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)3U,
 4443|  39.3k|                                                  (size_t)11U);
 4444|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)4U,
 4445|  39.3k|                                                  (size_t)12U);
 4446|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)5U,
 4447|  39.3k|                                                  (size_t)13U);
 4448|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)6U,
 4449|  39.3k|                                                  (size_t)14U);
 4450|  39.3k|  libcrux_ml_kem_vector_portable_ntt_inv_ntt_step(&vec, zeta, (size_t)7U,
 4451|  39.3k|                                                  (size_t)15U);
 4452|  39.3k|  return vec;
 4453|  39.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_invert_ntt_invert_ntt_at_layer_4_plus_ea:
 6041|  9.82k|    size_t layer) {
 6042|  9.82k|  size_t step = (size_t)1U << (uint32_t)layer;
 6043|  46.6k|  for (size_t i0 = (size_t)0U; i0 < (size_t)128U >> (uint32_t)layer; i0++) {
  ------------------
  |  Branch (6043:32): [True: 36.8k, False: 9.82k]
  ------------------
 6044|  36.8k|    size_t round = i0;
 6045|  36.8k|    zeta_i[0U] = zeta_i[0U] - (size_t)1U;
 6046|  36.8k|    size_t offset = round * step * (size_t)2U;
 6047|  36.8k|    size_t offset_vec =
 6048|  36.8k|        offset / LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR;
  ------------------
  |  | 3772|  36.8k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
 6049|  36.8k|    size_t step_vec =
 6050|  36.8k|        step / LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR;
  ------------------
  |  | 3772|  36.8k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
 6051|   115k|    for (size_t i = offset_vec; i < offset_vec + step_vec; i++) {
  ------------------
  |  Branch (6051:33): [True: 78.6k, False: 36.8k]
  ------------------
 6052|  78.6k|      size_t j = i;
 6053|  78.6k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2 uu____0 =
 6054|  78.6k|          libcrux_ml_kem_invert_ntt_inv_ntt_layer_int_vec_step_reduce_ea(
 6055|  78.6k|              re->coefficients[j], re->coefficients[j + step_vec],
 6056|  78.6k|              libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
 6057|  78.6k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector x = uu____0.fst;
 6058|  78.6k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector y = uu____0.snd;
 6059|  78.6k|      re->coefficients[j] = x;
 6060|  78.6k|      re->coefficients[j + step_vec] = y;
 6061|  78.6k|    }
 6062|  36.8k|  }
 6063|  9.82k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_invert_ntt_inv_ntt_layer_int_vec_step_reduce_ea:
 6020|  78.6k|        int16_t zeta_r) {
 6021|  78.6k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector a_minus_b =
 6022|  78.6k|      libcrux_ml_kem_vector_portable_sub_b8(b, &a);
 6023|  78.6k|  a = libcrux_ml_kem_vector_portable_barrett_reduce_b8(
 6024|  78.6k|      libcrux_ml_kem_vector_portable_add_b8(a, &b));
 6025|  78.6k|  b = libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(
 6026|  78.6k|      a_minus_b, zeta_r);
 6027|  78.6k|  return (KRML_CLITERAL(
  ------------------
  |  |  154|  78.6k|#define KRML_CLITERAL(type) (type)
  ------------------
 6028|  78.6k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2){.fst = a,
 6029|  78.6k|                                                                    .snd = b});
 6030|  78.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_subtract_reduce_d6_ea:
 6130|    273|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d b) {
 6131|    273|  return libcrux_ml_kem_polynomial_subtract_reduce_ea(self, b);
 6132|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_subtract_reduce_ea:
 6098|    273|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d b) {
 6099|    273|  for (size_t i = (size_t)0U;
 6100|  4.64k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  4.64k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (6100:8): [True: 4.36k, False: 273]
  ------------------
 6101|  4.36k|    size_t i0 = i;
 6102|  4.36k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 6103|  4.36k|        coefficient_normal_form =
 6104|  4.36k|            libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(
 6105|  4.36k|                b.coefficients[i0], (int16_t)1441);
 6106|  4.36k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector diff =
 6107|  4.36k|        libcrux_ml_kem_vector_portable_sub_b8(myself->coefficients[i0],
 6108|  4.36k|                                              &coefficient_normal_form);
 6109|  4.36k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector red =
 6110|  4.36k|        libcrux_ml_kem_vector_portable_barrett_reduce_b8(diff);
 6111|  4.36k|    b.coefficients[i0] = red;
 6112|  4.36k|  }
 6113|    273|  return b;
 6114|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_compress_then_serialize_message_ea:
 6184|    273|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d re, uint8_t ret[32U]) {
 6185|    273|  uint8_t serialized[32U] = {0U};
 6186|  4.64k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (6186:31): [True: 4.36k, False: 273]
  ------------------
 6187|  4.36k|    size_t i0 = i;
 6188|  4.36k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 6189|  4.36k|        libcrux_ml_kem_serialize_to_unsigned_field_modulus_ea(
 6190|  4.36k|            re.coefficients[i0]);
 6191|  4.36k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 6192|  4.36k|        coefficient_compressed =
 6193|  4.36k|            libcrux_ml_kem_vector_portable_compress_1_b8(coefficient);
 6194|  4.36k|    uint8_t bytes[2U];
 6195|  4.36k|    libcrux_ml_kem_vector_portable_serialize_1_b8(coefficient_compressed,
 6196|  4.36k|                                                  bytes);
 6197|  4.36k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  4.36k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 6198|  4.36k|        Eurydice_array_to_subslice3(serialized, (size_t)2U * i0,
 6199|  4.36k|                                    (size_t)2U * i0 + (size_t)2U, uint8_t *),
 6200|  4.36k|        Eurydice_array_to_slice((size_t)2U, bytes, uint8_t), uint8_t);
 6201|  4.36k|  }
 6202|    273|  memcpy(ret, serialized, (size_t)32U * sizeof(uint8_t));
 6203|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_to_unsigned_field_modulus_ea:
 6172|  78.6k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 6173|  78.6k|  return libcrux_ml_kem_vector_portable_to_unsigned_representative_b8(a);
 6174|  78.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_to_unsigned_representative_b8:
 4127|  78.6k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4128|  78.6k|  return libcrux_ml_kem_vector_portable_arithmetic_to_unsigned_representative(
 4129|  78.6k|      a);
 4130|  78.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_to_unsigned_representative:
 4112|  78.6k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4113|  78.6k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector t =
 4114|  78.6k|      libcrux_ml_kem_vector_portable_arithmetic_shift_right_ef(a);
 4115|  78.6k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector fm =
 4116|  78.6k|      libcrux_ml_kem_vector_portable_arithmetic_bitwise_and_with_constant(
 4117|  78.6k|          t, LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS);
  ------------------
  |  | 3777|  78.6k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 4118|  78.6k|  return libcrux_ml_kem_vector_portable_arithmetic_add(a, &fm);
 4119|  78.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_shift_right_ef:
 4101|  78.6k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec) {
 4102|  78.6k|  for (size_t i = (size_t)0U;
 4103|  1.33M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  1.33M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (4103:8): [True: 1.25M, False: 78.6k]
  ------------------
 4104|  1.25M|    size_t i0 = i;
 4105|  1.25M|    vec.elements[i0] = vec.elements[i0] >> (uint32_t)(int32_t)15;
 4106|  1.25M|  }
 4107|  78.6k|  return vec;
 4108|  78.6k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_bitwise_and_with_constant:
 4084|  87.3k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec, int16_t c) {
 4085|  87.3k|  for (size_t i = (size_t)0U;
 4086|  1.48M|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  1.48M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (4086:8): [True: 1.39M, False: 87.3k]
  ------------------
 4087|  1.39M|    size_t i0 = i;
 4088|  1.39M|    size_t uu____0 = i0;
 4089|  1.39M|    vec.elements[uu____0] = vec.elements[uu____0] & c;
 4090|  1.39M|  }
 4091|  87.3k|  return vec;
 4092|  87.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_1_b8:
 4187|  4.36k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4188|  4.36k|  return libcrux_ml_kem_vector_portable_compress_compress_1(a);
 4189|  4.36k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_compress_1:
 4170|  4.36k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4171|  4.36k|  for (size_t i = (size_t)0U;
 4172|  74.2k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  74.2k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (4172:8): [True: 69.8k, False: 4.36k]
  ------------------
 4173|  69.8k|    size_t i0 = i;
 4174|  69.8k|    a.elements[i0] = libcrux_secrets_int_as_i16_59(
 4175|  69.8k|        libcrux_ml_kem_vector_portable_compress_compress_message_coefficient(
 4176|  69.8k|            libcrux_secrets_int_as_u16_f5(a.elements[i0])));
 4177|  69.8k|  }
 4178|  4.36k|  return a;
 4179|  4.36k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_compress_message_coefficient:
 4156|  69.8k|    uint16_t fe) {
 4157|  69.8k|  int16_t shifted =
 4158|  69.8k|      libcrux_secrets_int_public_integers_classify_27_39((int16_t)1664) -
 4159|  69.8k|      libcrux_secrets_int_as_i16_ca(fe);
 4160|  69.8k|  int16_t mask = shifted >> 15U;
 4161|  69.8k|  int16_t shifted_to_positive = mask ^ shifted;
 4162|  69.8k|  int16_t shifted_positive_in_range = shifted_to_positive - (int16_t)832;
 4163|  69.8k|  int16_t r0 = shifted_positive_in_range >> 15U;
 4164|  69.8k|  int16_t r1 = r0 & (int16_t)1;
 4165|  69.8k|  return libcrux_secrets_int_as_u8_f5(r1);
 4166|  69.8k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i16_ca:
  640|  69.8k|static KRML_MUSTINLINE int16_t libcrux_secrets_int_as_i16_ca(uint16_t self) {
  641|  69.8k|  return libcrux_secrets_int_public_integers_classify_27_39(
  642|  69.8k|      (int16_t)libcrux_secrets_int_public_integers_declassify_d8_de(self));
  643|  69.8k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_de:
  633|   628k|libcrux_secrets_int_public_integers_declassify_d8_de(uint16_t self) {
  634|   628k|  return self;
  635|   628k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_u8_f5:
  501|  2.06M|static KRML_MUSTINLINE uint8_t libcrux_secrets_int_as_u8_f5(int16_t self) {
  502|  2.06M|  return libcrux_secrets_int_public_integers_classify_27_90(
  503|  2.06M|      (uint8_t)libcrux_secrets_int_public_integers_declassify_d8_39(self));
  504|  2.06M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_90:
  481|  2.06M|libcrux_secrets_int_public_integers_classify_27_90(uint8_t self) {
  482|  2.06M|  return self;
  483|  2.06M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_u16_f5:
  619|   628k|static KRML_MUSTINLINE uint16_t libcrux_secrets_int_as_u16_f5(int16_t self) {
  620|   628k|  return libcrux_secrets_int_public_integers_classify_27_de(
  621|   628k|      (uint16_t)libcrux_secrets_int_public_integers_declassify_d8_39(self));
  622|   628k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_de:
  612|   628k|libcrux_secrets_int_public_integers_classify_27_de(uint16_t self) {
  613|   628k|  return self;
  614|   628k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_1_b8:
 4612|  4.36k|    uint8_t ret[2U]) {
 4613|  4.36k|  libcrux_ml_kem_vector_portable_serialize_1(a, ret);
 4614|  4.36k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_1:
 4600|  4.36k|    uint8_t ret[2U]) {
 4601|  4.36k|  uint8_t ret0[2U];
 4602|  4.36k|  libcrux_ml_kem_vector_portable_serialize_serialize_1(a, ret0);
 4603|  4.36k|  libcrux_secrets_int_public_integers_declassify_d8_d4(ret0, ret);
 4604|  4.36k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_1:
 4575|  4.36k|    uint8_t ret[2U]) {
 4576|  4.36k|  uint8_t result0 =
 4577|  4.36k|      (((((((uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[0U]) |
 4578|  4.36k|            (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[1U]) << 1U) |
 4579|  4.36k|           (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[2U]) << 2U) |
 4580|  4.36k|          (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[3U]) << 3U) |
 4581|  4.36k|         (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[4U]) << 4U) |
 4582|  4.36k|        (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[5U]) << 5U) |
 4583|  4.36k|       (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[6U]) << 6U) |
 4584|  4.36k|      (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[7U]) << 7U;
 4585|  4.36k|  uint8_t result1 =
 4586|  4.36k|      (((((((uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[8U]) |
 4587|  4.36k|            (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[9U]) << 1U) |
 4588|  4.36k|           (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[10U]) << 2U) |
 4589|  4.36k|          (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[11U]) << 3U) |
 4590|  4.36k|         (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[12U]) << 4U) |
 4591|  4.36k|        (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[13U]) << 5U) |
 4592|  4.36k|       (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[14U]) << 6U) |
 4593|  4.36k|      (uint32_t)libcrux_secrets_int_as_u8_f5(v.elements[15U]) << 7U;
 4594|  4.36k|  ret[0U] = result0;
 4595|  4.36k|  ret[1U] = result1;
 4596|  4.36k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_d4:
 1062|  4.36k|                                                     uint8_t ret[2U]) {
 1063|  4.36k|  memcpy(ret, self, (size_t)2U * sizeof(uint8_t));
 1064|  4.36k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_into_padded_array_24:
  955|    546|    Eurydice_slice slice, uint8_t ret[64U]) {
  956|    546|  uint8_t out[64U] = {0U};
  957|    546|  uint8_t *uu____0 = out;
  958|    546|  Eurydice_slice_copy(
  ------------------
  |  |  229|    546|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
  959|    546|      Eurydice_array_to_subslice3(
  960|    546|          uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *),
  961|    546|      slice, uint8_t);
  962|    546|  memcpy(ret, out, (size_t)64U * sizeof(uint8_t));
  963|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_G_4a_e0:
 6298|    819|    Eurydice_slice input, uint8_t ret[64U]) {
 6299|    819|  libcrux_ml_kem_hash_functions_portable_G(input, ret);
 6300|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_G:
 3717|    819|    Eurydice_slice input, uint8_t ret[64U]) {
 3718|    819|  uint8_t digest[64U] = {0U};
 3719|    819|  libcrux_sha3_portable_sha512(
 3720|    819|      Eurydice_array_to_slice((size_t)64U, digest, uint8_t), input);
  ------------------
  |  |  204|    819|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    819|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    819|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    819|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3721|    819|  memcpy(ret, digest, (size_t)64U * sizeof(uint8_t));
 3722|    819|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_sha512:
 3128|    819|                                                         Eurydice_slice data) {
 3129|    819|  libcrux_sha3_generic_keccak_portable_keccak1_96(data, digest);
 3130|    819|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_keccak1_96:
 3092|    819|    Eurydice_slice data, Eurydice_slice out) {
 3093|    819|  libcrux_sha3_generic_keccak_KeccakState_17 s =
 3094|    819|      libcrux_sha3_generic_keccak_new_80_04();
 3095|    819|  size_t data_len = Eurydice_slice_len(data, uint8_t);
  ------------------
  |  |  173|    819|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3096|    819|  for (size_t i = (size_t)0U; i < data_len / (size_t)72U; i++) {
  ------------------
  |  Branch (3096:31): [True: 0, False: 819]
  ------------------
 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|    819|  size_t rem = data_len % (size_t)72U;
 3102|    819|  Eurydice_slice buf[1U] = {data};
 3103|    819|  libcrux_sha3_generic_keccak_absorb_final_80_9e(&s, buf, data_len - rem, rem);
 3104|    819|  size_t outlen = Eurydice_slice_len(out, uint8_t);
  ------------------
  |  |  173|    819|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3105|    819|  size_t blocks = outlen / (size_t)72U;
 3106|    819|  size_t last = outlen - outlen % (size_t)72U;
 3107|    819|  if (blocks == (size_t)0U) {
  ------------------
  |  Branch (3107:7): [True: 819, False: 0]
  ------------------
 3108|    819|    libcrux_sha3_simd_portable_squeeze_13_f8(&s, out, (size_t)0U, outlen);
 3109|    819|  } 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|    819|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_new_80_04:
 1449|  14.4k|libcrux_sha3_generic_keccak_new_80_04(void) {
 1450|  14.4k|  libcrux_sha3_generic_keccak_KeccakState_17 lit;
 1451|  14.4k|  uint64_t repeat_expression[25U];
 1452|   376k|  for (size_t i = (size_t)0U; i < (size_t)25U; i++) {
  ------------------
  |  Branch (1452:31): [True: 361k, False: 14.4k]
  ------------------
 1453|   361k|    repeat_expression[i] = libcrux_sha3_simd_portable_zero_d2();
 1454|   361k|  }
 1455|  14.4k|  memcpy(lit.st, repeat_expression, (size_t)25U * sizeof(uint64_t));
 1456|  14.4k|  return lit;
 1457|  14.4k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_zero_d2:
 1320|   361k|static KRML_MUSTINLINE uint64_t libcrux_sha3_simd_portable_zero_d2(void) {
 1321|   361k|  return 0ULL;
 1322|   361k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_block_f8:
 1489|    819|    uint64_t *state, Eurydice_slice blocks, size_t start) {
 1490|    819|  uint64_t state_flat[25U] = {0U};
 1491|  8.19k|  for (size_t i = (size_t)0U; i < (size_t)72U / (size_t)8U; i++) {
  ------------------
  |  Branch (1491:31): [True: 7.37k, False: 819]
  ------------------
 1492|  7.37k|    size_t i0 = i;
 1493|  7.37k|    size_t offset = start + (size_t)8U * i0;
 1494|  7.37k|    uint8_t uu____0[8U];
 1495|  7.37k|    Result_15 dst;
 1496|  7.37k|    Eurydice_slice_to_array2(
  ------------------
  |  |  277|  7.37k|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|  7.37k|                           sizeof(t_arr))
  ------------------
 1497|  7.37k|        &dst,
 1498|  7.37k|        Eurydice_slice_subslice3(blocks, offset, offset + (size_t)8U,
 1499|  7.37k|                                 uint8_t *),
 1500|  7.37k|        Eurydice_slice, uint8_t[8U], TryFromSliceError);
 1501|  7.37k|    unwrap_26_68(dst, uu____0);
 1502|  7.37k|    state_flat[i0] = core_num__u64__from_le_bytes(uu____0);
 1503|  7.37k|  }
 1504|  8.19k|  for (size_t i = (size_t)0U; i < (size_t)72U / (size_t)8U; i++) {
  ------------------
  |  Branch (1504:31): [True: 7.37k, False: 819]
  ------------------
 1505|  7.37k|    size_t i0 = i;
 1506|  7.37k|    libcrux_sha3_traits_set_ij_04(
 1507|  7.37k|        state, i0 / (size_t)5U, i0 % (size_t)5U,
 1508|  7.37k|        libcrux_sha3_traits_get_ij_04(state, i0 / (size_t)5U,
 1509|  7.37k|                                      i0 % (size_t)5U)[0U] ^
 1510|  7.37k|            state_flat[i0]);
 1511|  7.37k|  }
 1512|    819|}
libcrux_mlkem768_sha3.c:Eurydice_slice_to_array3:
  281|   585k|                                            Eurydice_slice src, size_t sz) {
  282|   585k|  *dst_tag = 0;
  283|   585k|  memcpy(dst_ok, src.ptr, sz);
  284|   585k|}
libcrux_mlkem768_sha3.c:unwrap_26_68:
 1163|   380k|static inline void unwrap_26_68(Result_15 self, uint8_t ret[8U]) {
 1164|   380k|  if (self.tag == Ok) {
  ------------------
  |  |  721|   380k|#define Ok 0
  ------------------
  |  Branch (1164:7): [True: 380k, False: 0]
  ------------------
 1165|   380k|    uint8_t f0[8U];
 1166|   380k|    memcpy(f0, self.val.case_Ok, (size_t)8U * sizeof(uint8_t));
 1167|   380k|    memcpy(ret, f0, (size_t)8U * sizeof(uint8_t));
 1168|   380k|  } 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|   380k|}
libcrux_mlkem768_sha3.c:core_num__u64__from_le_bytes:
  331|   380k|static inline uint64_t core_num__u64__from_le_bytes(uint8_t buf[8]) {
  332|   380k|  return load64_le(buf);
  333|   380k|}
libcrux_mlkem768_sha3.c:load64_le:
   61|   380k|{
   62|   380k|	return (uint64_t)(src[0]) |
   63|   380k|	    ((uint64_t)(src[1]) << 8) |
   64|   380k|	    ((uint64_t)(src[2]) << 16) |
   65|   380k|	    ((uint64_t)(src[3]) << 24) |
   66|   380k|	    ((uint64_t)(src[4]) << 32) |
   67|   380k|	    ((uint64_t)(src[5]) << 40) |
   68|   380k|	    ((uint64_t)(src[6]) << 48) |
   69|   380k|	    ((uint64_t)(src[7]) << 56);
   70|   380k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_traits_set_ij_04:
 1479|  65.0M|                                                          uint64_t value) {
 1480|  65.0M|  arr[(size_t)5U * j + i] = value;
 1481|  65.0M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_traits_get_ij_04:
 1467|   130M|                                                               size_t j) {
 1468|   130M|  return &arr[(size_t)5U * j + i];
 1469|   130M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_final_80_9e:
 3027|    819|    size_t start, size_t len) {
 3028|    819|  libcrux_sha3_simd_portable_load_last_a1_96(self, last, start, len);
 3029|    819|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3030|    819|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_a1_96:
 3009|    819|    size_t start, size_t len) {
 3010|    819|  libcrux_sha3_simd_portable_load_last_96(self->st, input[0U], start, len);
 3011|    819|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_96:
 2983|    819|    uint64_t *state, Eurydice_slice blocks, size_t start, size_t len) {
 2984|    819|  uint8_t buffer[72U] = {0U};
 2985|    819|  Eurydice_slice_copy(
  ------------------
  |  |  229|    819|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 2986|    819|      Eurydice_array_to_subslice3(buffer, (size_t)0U, len, uint8_t *),
 2987|    819|      Eurydice_slice_subslice3(blocks, start, start + len, uint8_t *), uint8_t);
 2988|    819|  buffer[len] = 6U;
 2989|    819|  size_t uu____0 = (size_t)72U - (size_t)1U;
 2990|    819|  buffer[uu____0] = (uint32_t)buffer[uu____0] | 128U;
 2991|    819|  libcrux_sha3_simd_portable_load_block_f8(
 2992|    819|      state, Eurydice_array_to_slice((size_t)72U, buffer, uint8_t), (size_t)0U);
  ------------------
  |  |  204|    819|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    819|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    819|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    819|                 end) /* x is already at an array type, no need for cast */
  ------------------
 2993|    819|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_squeeze_13_f8:
 3081|    819|    size_t start, size_t len) {
 3082|    819|  libcrux_sha3_simd_portable_store_block_f8(self->st, out, start, len);
 3083|    819|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_store_block_f8:
 3038|    819|    uint64_t *s, Eurydice_slice out, size_t start, size_t len) {
 3039|    819|  size_t octets = len / (size_t)8U;
 3040|  7.37k|  for (size_t i = (size_t)0U; i < octets; i++) {
  ------------------
  |  Branch (3040:31): [True: 6.55k, False: 819]
  ------------------
 3041|  6.55k|    size_t i0 = i;
 3042|  6.55k|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  6.55k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  6.55k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  6.55k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3043|  6.55k|        out, start + (size_t)8U * i0, start + (size_t)8U * i0 + (size_t)8U,
 3044|  6.55k|        uint8_t *);
 3045|  6.55k|    uint8_t ret[8U];
 3046|  6.55k|    core_num__u64__to_le_bytes(
 3047|  6.55k|        libcrux_sha3_traits_get_ij_04(s, i0 / (size_t)5U, i0 % (size_t)5U)[0U],
 3048|  6.55k|        ret);
 3049|  6.55k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  6.55k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3050|  6.55k|        uu____0, Eurydice_array_to_slice((size_t)8U, ret, uint8_t), uint8_t);
 3051|  6.55k|  }
 3052|    819|  size_t remaining = len % (size_t)8U;
 3053|    819|  if (remaining > (size_t)0U) {
  ------------------
  |  Branch (3053:7): [True: 0, False: 819]
  ------------------
 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|    819|}
libcrux_mlkem768_sha3.c:core_num__u64__to_le_bytes:
  327|   564k|static inline void core_num__u64__to_le_bytes(uint64_t v, uint8_t buf[8]) {
  328|   564k|  store64_le(buf, v);
  329|   564k|}
libcrux_mlkem768_sha3.c:store64_le:
   48|   564k|{
   49|   564k|	dst[0] = src & 0xff;
   50|   564k|	dst[1] = (src >> 8) & 0xff;
   51|   564k|	dst[2] = (src >> 16) & 0xff;
   52|   564k|	dst[3] = (src >> 24) & 0xff;
   53|   564k|	dst[4] = (src >> 32) & 0xff;
   54|   564k|	dst[5] = (src >> 40) & 0xff;
   55|   564k|	dst[6] = (src >> 48) & 0xff;
   56|   564k|	dst[7] = (src >> 56) & 0xff;
   57|   564k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_keccakf1600_80_04:
 2943|  35.9k|    libcrux_sha3_generic_keccak_KeccakState_17 *self) {
 2944|   898k|  for (size_t i = (size_t)0U; i < (size_t)24U; i++) {
  ------------------
  |  Branch (2944:31): [True: 862k, False: 35.9k]
  ------------------
 2945|   862k|    size_t i0 = i;
 2946|   862k|    uint64_t t[5U];
 2947|   862k|    libcrux_sha3_generic_keccak_theta_80_04(self, t);
 2948|   862k|    libcrux_sha3_generic_keccak_KeccakState_17 *uu____0 = self;
 2949|   862k|    uint64_t uu____1[5U];
 2950|   862k|    memcpy(uu____1, t, (size_t)5U * sizeof(uint64_t));
 2951|   862k|    libcrux_sha3_generic_keccak_rho_80_04(uu____0, uu____1);
 2952|   862k|    libcrux_sha3_generic_keccak_pi_80_04(self);
 2953|   862k|    libcrux_sha3_generic_keccak_chi_80_04(self);
 2954|   862k|    libcrux_sha3_generic_keccak_iota_80_04(self, i0);
 2955|   862k|  }
 2956|  35.9k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_theta_80_04:
 1557|   862k|    libcrux_sha3_generic_keccak_KeccakState_17 *self, uint64_t ret[5U]) {
 1558|   862k|  uint64_t c[5U] = {
 1559|   862k|      libcrux_sha3_simd_portable_xor5_d2(
 1560|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1561|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1562|   862k|                                              .snd = (size_t)0U}))[0U],
 1563|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1564|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1565|   862k|                                              .snd = (size_t)0U}))[0U],
 1566|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1567|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1568|   862k|                                              .snd = (size_t)0U}))[0U],
 1569|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1570|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1571|   862k|                                              .snd = (size_t)0U}))[0U],
 1572|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1573|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1574|   862k|                                              .snd = (size_t)0U}))[0U]),
 1575|   862k|      libcrux_sha3_simd_portable_xor5_d2(
 1576|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1577|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1578|   862k|                                              .snd = (size_t)1U}))[0U],
 1579|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1580|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1581|   862k|                                              .snd = (size_t)1U}))[0U],
 1582|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1583|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1584|   862k|                                              .snd = (size_t)1U}))[0U],
 1585|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1586|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1587|   862k|                                              .snd = (size_t)1U}))[0U],
 1588|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1589|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1590|   862k|                                              .snd = (size_t)1U}))[0U]),
 1591|   862k|      libcrux_sha3_simd_portable_xor5_d2(
 1592|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1593|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1594|   862k|                                              .snd = (size_t)2U}))[0U],
 1595|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1596|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1597|   862k|                                              .snd = (size_t)2U}))[0U],
 1598|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1599|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1600|   862k|                                              .snd = (size_t)2U}))[0U],
 1601|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1602|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1603|   862k|                                              .snd = (size_t)2U}))[0U],
 1604|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1605|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1606|   862k|                                              .snd = (size_t)2U}))[0U]),
 1607|   862k|      libcrux_sha3_simd_portable_xor5_d2(
 1608|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1609|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1610|   862k|                                              .snd = (size_t)3U}))[0U],
 1611|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1612|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1613|   862k|                                              .snd = (size_t)3U}))[0U],
 1614|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1615|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1616|   862k|                                              .snd = (size_t)3U}))[0U],
 1617|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1618|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1619|   862k|                                              .snd = (size_t)3U}))[0U],
 1620|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1621|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1622|   862k|                                              .snd = (size_t)3U}))[0U]),
 1623|   862k|      libcrux_sha3_simd_portable_xor5_d2(
 1624|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1625|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1626|   862k|                                              .snd = (size_t)4U}))[0U],
 1627|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1628|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1629|   862k|                                              .snd = (size_t)4U}))[0U],
 1630|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1631|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1632|   862k|                                              .snd = (size_t)4U}))[0U],
 1633|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1634|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1635|   862k|                                              .snd = (size_t)4U}))[0U],
 1636|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 1637|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 1638|   862k|                                              .snd = (size_t)4U}))[0U])};
 1639|   862k|  uint64_t uu____0 = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1640|   862k|      c[((size_t)0U + (size_t)4U) % (size_t)5U],
 1641|   862k|      c[((size_t)0U + (size_t)1U) % (size_t)5U]);
 1642|   862k|  uint64_t uu____1 = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1643|   862k|      c[((size_t)1U + (size_t)4U) % (size_t)5U],
 1644|   862k|      c[((size_t)1U + (size_t)1U) % (size_t)5U]);
 1645|   862k|  uint64_t uu____2 = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1646|   862k|      c[((size_t)2U + (size_t)4U) % (size_t)5U],
 1647|   862k|      c[((size_t)2U + (size_t)1U) % (size_t)5U]);
 1648|   862k|  uint64_t uu____3 = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1649|   862k|      c[((size_t)3U + (size_t)4U) % (size_t)5U],
 1650|   862k|      c[((size_t)3U + (size_t)1U) % (size_t)5U]);
 1651|   862k|  ret[0U] = uu____0;
 1652|   862k|  ret[1U] = uu____1;
 1653|   862k|  ret[2U] = uu____2;
 1654|   862k|  ret[3U] = uu____3;
 1655|   862k|  ret[4U] = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1656|   862k|      c[((size_t)4U + (size_t)4U) % (size_t)5U],
 1657|   862k|      c[((size_t)4U + (size_t)1U) % (size_t)5U]);
 1658|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor5_d2:
 1333|  4.31M|    uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e) {
 1334|  4.31M|  return libcrux_sha3_simd_portable__veor5q_u64(a, b, c, d, e);
 1335|  4.31M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__veor5q_u64:
 1325|  4.31M|    uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e) {
 1326|  4.31M|  return (((a ^ b) ^ c) ^ d) ^ e;
 1327|  4.31M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_index_c2_04:
 1542|   129M|    libcrux_sha3_generic_keccak_KeccakState_17 *self, size_t_x2 index) {
 1543|   129M|  return libcrux_sha3_traits_get_ij_04(self->st, index.fst, index.snd);
 1544|   129M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left1_and_xor_d2:
 1358|  4.31M|libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(uint64_t a, uint64_t b) {
 1359|  4.31M|  return libcrux_sha3_simd_portable__vrax1q_u64(a, b);
 1360|  4.31M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vrax1q_u64:
 1349|  4.31M|libcrux_sha3_simd_portable__vrax1q_u64(uint64_t a, uint64_t b) {
 1350|  4.31M|  uint64_t uu____0 = a;
 1351|  4.31M|  return uu____0 ^ libcrux_sha3_simd_portable_rotate_left_76(b);
 1352|  4.31M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_76:
 1344|  5.17M|libcrux_sha3_simd_portable_rotate_left_76(uint64_t x) {
 1345|  5.17M|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)1);
 1346|  5.17M|}
libcrux_mlkem768_sha3.c:core_num__u64__rotate_left:
  342|  25.0M|static inline uint64_t core_num__u64__rotate_left(uint64_t x0, uint32_t x1) {
  343|  25.0M|  return (x0 << x1 | x0 >> (64 - x1));
  344|  25.0M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_rho_80_04:
 2540|   862k|    libcrux_sha3_generic_keccak_KeccakState_17 *self, uint64_t t[5U]) {
 2541|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2542|   862k|      self, (size_t)0U, (size_t)0U,
 2543|   862k|      libcrux_sha3_simd_portable_xor_d2(
 2544|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2545|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2546|   862k|                                              .snd = (size_t)0U}))[0U],
 2547|   862k|          t[0U]));
 2548|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____0 = self;
 2549|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2550|   862k|      uu____0, (size_t)1U, (size_t)0U,
 2551|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_02(
 2552|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2553|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2554|   862k|                                              .snd = (size_t)0U}))[0U],
 2555|   862k|          t[0U]));
 2556|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____1 = self;
 2557|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2558|   862k|      uu____1, (size_t)2U, (size_t)0U,
 2559|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_ac(
 2560|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2561|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2562|   862k|                                              .snd = (size_t)0U}))[0U],
 2563|   862k|          t[0U]));
 2564|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____2 = self;
 2565|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2566|   862k|      uu____2, (size_t)3U, (size_t)0U,
 2567|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_020(
 2568|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2569|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2570|   862k|                                              .snd = (size_t)0U}))[0U],
 2571|   862k|          t[0U]));
 2572|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____3 = self;
 2573|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2574|   862k|      uu____3, (size_t)4U, (size_t)0U,
 2575|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_a9(
 2576|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2577|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2578|   862k|                                              .snd = (size_t)0U}))[0U],
 2579|   862k|          t[0U]));
 2580|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____4 = self;
 2581|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2582|   862k|      uu____4, (size_t)0U, (size_t)1U,
 2583|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_76(
 2584|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2585|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2586|   862k|                                              .snd = (size_t)1U}))[0U],
 2587|   862k|          t[1U]));
 2588|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____5 = self;
 2589|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2590|   862k|      uu____5, (size_t)1U, (size_t)1U,
 2591|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_58(
 2592|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2593|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2594|   862k|                                              .snd = (size_t)1U}))[0U],
 2595|   862k|          t[1U]));
 2596|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____6 = self;
 2597|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2598|   862k|      uu____6, (size_t)2U, (size_t)1U,
 2599|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_e0(
 2600|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2601|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2602|   862k|                                              .snd = (size_t)1U}))[0U],
 2603|   862k|          t[1U]));
 2604|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____7 = self;
 2605|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2606|   862k|      uu____7, (size_t)3U, (size_t)1U,
 2607|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_63(
 2608|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2609|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2610|   862k|                                              .snd = (size_t)1U}))[0U],
 2611|   862k|          t[1U]));
 2612|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____8 = self;
 2613|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2614|   862k|      uu____8, (size_t)4U, (size_t)1U,
 2615|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_6a(
 2616|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2617|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2618|   862k|                                              .snd = (size_t)1U}))[0U],
 2619|   862k|          t[1U]));
 2620|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____9 = self;
 2621|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2622|   862k|      uu____9, (size_t)0U, (size_t)2U,
 2623|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_ab(
 2624|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2625|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2626|   862k|                                              .snd = (size_t)2U}))[0U],
 2627|   862k|          t[2U]));
 2628|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____10 = self;
 2629|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2630|   862k|      uu____10, (size_t)1U, (size_t)2U,
 2631|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_5b(
 2632|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2633|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2634|   862k|                                              .snd = (size_t)2U}))[0U],
 2635|   862k|          t[2U]));
 2636|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____11 = self;
 2637|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2638|   862k|      uu____11, (size_t)2U, (size_t)2U,
 2639|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_6f(
 2640|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2641|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2642|   862k|                                              .snd = (size_t)2U}))[0U],
 2643|   862k|          t[2U]));
 2644|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____12 = self;
 2645|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2646|   862k|      uu____12, (size_t)3U, (size_t)2U,
 2647|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_62(
 2648|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2649|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2650|   862k|                                              .snd = (size_t)2U}))[0U],
 2651|   862k|          t[2U]));
 2652|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____13 = self;
 2653|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2654|   862k|      uu____13, (size_t)4U, (size_t)2U,
 2655|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_23(
 2656|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2657|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2658|   862k|                                              .snd = (size_t)2U}))[0U],
 2659|   862k|          t[2U]));
 2660|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____14 = self;
 2661|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2662|   862k|      uu____14, (size_t)0U, (size_t)3U,
 2663|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_37(
 2664|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2665|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2666|   862k|                                              .snd = (size_t)3U}))[0U],
 2667|   862k|          t[3U]));
 2668|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____15 = self;
 2669|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2670|   862k|      uu____15, (size_t)1U, (size_t)3U,
 2671|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_bb(
 2672|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2673|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2674|   862k|                                              .snd = (size_t)3U}))[0U],
 2675|   862k|          t[3U]));
 2676|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____16 = self;
 2677|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2678|   862k|      uu____16, (size_t)2U, (size_t)3U,
 2679|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_b9(
 2680|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2681|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2682|   862k|                                              .snd = (size_t)3U}))[0U],
 2683|   862k|          t[3U]));
 2684|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____17 = self;
 2685|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2686|   862k|      uu____17, (size_t)3U, (size_t)3U,
 2687|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_54(
 2688|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2689|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2690|   862k|                                              .snd = (size_t)3U}))[0U],
 2691|   862k|          t[3U]));
 2692|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____18 = self;
 2693|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2694|   862k|      uu____18, (size_t)4U, (size_t)3U,
 2695|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_4c(
 2696|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2697|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2698|   862k|                                              .snd = (size_t)3U}))[0U],
 2699|   862k|          t[3U]));
 2700|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____19 = self;
 2701|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2702|   862k|      uu____19, (size_t)0U, (size_t)4U,
 2703|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_ce(
 2704|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2705|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2706|   862k|                                              .snd = (size_t)4U}))[0U],
 2707|   862k|          t[4U]));
 2708|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____20 = self;
 2709|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2710|   862k|      uu____20, (size_t)1U, (size_t)4U,
 2711|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_77(
 2712|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2713|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2714|   862k|                                              .snd = (size_t)4U}))[0U],
 2715|   862k|          t[4U]));
 2716|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____21 = self;
 2717|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2718|   862k|      uu____21, (size_t)2U, (size_t)4U,
 2719|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_25(
 2720|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2721|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2722|   862k|                                              .snd = (size_t)4U}))[0U],
 2723|   862k|          t[4U]));
 2724|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____22 = self;
 2725|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2726|   862k|      uu____22, (size_t)3U, (size_t)4U,
 2727|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_af(
 2728|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2729|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2730|   862k|                                              .snd = (size_t)4U}))[0U],
 2731|   862k|          t[4U]));
 2732|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____23 = self;
 2733|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2734|   862k|      uu____23, (size_t)4U, (size_t)4U,
 2735|   862k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_fd(
 2736|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2737|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2738|   862k|                                              .snd = (size_t)4U}))[0U],
 2739|   862k|          t[4U]));
 2740|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_set_80_04:
 1672|  64.6M|    uint64_t v) {
 1673|  64.6M|  libcrux_sha3_traits_set_ij_04(self->st, i, j, v);
 1674|  64.6M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_d2:
 1392|   862k|                                                                  uint64_t b) {
 1393|   862k|  return a ^ b;
 1394|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_02:
 1708|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_02(uint64_t a, uint64_t b) {
 1709|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_02(a, b);
 1710|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_02:
 1694|   862k|libcrux_sha3_simd_portable__vxarq_u64_02(uint64_t a, uint64_t b) {
 1695|   862k|  return libcrux_sha3_simd_portable_rotate_left_02(a ^ b);
 1696|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_02:
 1683|   862k|libcrux_sha3_simd_portable_rotate_left_02(uint64_t x) {
 1684|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)36);
 1685|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_ac:
 1744|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_ac(uint64_t a, uint64_t b) {
 1745|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_ac(a, b);
 1746|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_ac:
 1730|   862k|libcrux_sha3_simd_portable__vxarq_u64_ac(uint64_t a, uint64_t b) {
 1731|   862k|  return libcrux_sha3_simd_portable_rotate_left_ac(a ^ b);
 1732|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_ac:
 1719|   862k|libcrux_sha3_simd_portable_rotate_left_ac(uint64_t x) {
 1720|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)3);
 1721|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_020:
 1780|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_020(uint64_t a, uint64_t b) {
 1781|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_020(a, b);
 1782|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_020:
 1766|   862k|libcrux_sha3_simd_portable__vxarq_u64_020(uint64_t a, uint64_t b) {
 1767|   862k|  return libcrux_sha3_simd_portable_rotate_left_020(a ^ b);
 1768|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_020:
 1755|   862k|libcrux_sha3_simd_portable_rotate_left_020(uint64_t x) {
 1756|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)41);
 1757|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_a9:
 1816|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_a9(uint64_t a, uint64_t b) {
 1817|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_a9(a, b);
 1818|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_a9:
 1802|   862k|libcrux_sha3_simd_portable__vxarq_u64_a9(uint64_t a, uint64_t b) {
 1803|   862k|  return libcrux_sha3_simd_portable_rotate_left_a9(a ^ b);
 1804|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_a9:
 1791|   862k|libcrux_sha3_simd_portable_rotate_left_a9(uint64_t x) {
 1792|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)18);
 1793|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_76:
 1841|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_76(uint64_t a, uint64_t b) {
 1842|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_76(a, b);
 1843|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_76:
 1827|   862k|libcrux_sha3_simd_portable__vxarq_u64_76(uint64_t a, uint64_t b) {
 1828|   862k|  return libcrux_sha3_simd_portable_rotate_left_76(a ^ b);
 1829|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_58:
 1877|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_58(uint64_t a, uint64_t b) {
 1878|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_58(a, b);
 1879|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_58:
 1863|   862k|libcrux_sha3_simd_portable__vxarq_u64_58(uint64_t a, uint64_t b) {
 1864|   862k|  return libcrux_sha3_simd_portable_rotate_left_58(a ^ b);
 1865|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_58:
 1852|   862k|libcrux_sha3_simd_portable_rotate_left_58(uint64_t x) {
 1853|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)44);
 1854|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_e0:
 1913|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_e0(uint64_t a, uint64_t b) {
 1914|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_e0(a, b);
 1915|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_e0:
 1899|   862k|libcrux_sha3_simd_portable__vxarq_u64_e0(uint64_t a, uint64_t b) {
 1900|   862k|  return libcrux_sha3_simd_portable_rotate_left_e0(a ^ b);
 1901|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_e0:
 1888|   862k|libcrux_sha3_simd_portable_rotate_left_e0(uint64_t x) {
 1889|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)10);
 1890|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_63:
 1949|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_63(uint64_t a, uint64_t b) {
 1950|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_63(a, b);
 1951|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_63:
 1935|   862k|libcrux_sha3_simd_portable__vxarq_u64_63(uint64_t a, uint64_t b) {
 1936|   862k|  return libcrux_sha3_simd_portable_rotate_left_63(a ^ b);
 1937|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_63:
 1924|   862k|libcrux_sha3_simd_portable_rotate_left_63(uint64_t x) {
 1925|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)45);
 1926|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_6a:
 1985|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_6a(uint64_t a, uint64_t b) {
 1986|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_6a(a, b);
 1987|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_6a:
 1971|   862k|libcrux_sha3_simd_portable__vxarq_u64_6a(uint64_t a, uint64_t b) {
 1972|   862k|  return libcrux_sha3_simd_portable_rotate_left_6a(a ^ b);
 1973|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_6a:
 1960|   862k|libcrux_sha3_simd_portable_rotate_left_6a(uint64_t x) {
 1961|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)2);
 1962|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_ab:
 2021|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_ab(uint64_t a, uint64_t b) {
 2022|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_ab(a, b);
 2023|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_ab:
 2007|   862k|libcrux_sha3_simd_portable__vxarq_u64_ab(uint64_t a, uint64_t b) {
 2008|   862k|  return libcrux_sha3_simd_portable_rotate_left_ab(a ^ b);
 2009|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_ab:
 1996|   862k|libcrux_sha3_simd_portable_rotate_left_ab(uint64_t x) {
 1997|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)62);
 1998|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_5b:
 2057|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_5b(uint64_t a, uint64_t b) {
 2058|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_5b(a, b);
 2059|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_5b:
 2043|   862k|libcrux_sha3_simd_portable__vxarq_u64_5b(uint64_t a, uint64_t b) {
 2044|   862k|  return libcrux_sha3_simd_portable_rotate_left_5b(a ^ b);
 2045|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_5b:
 2032|   862k|libcrux_sha3_simd_portable_rotate_left_5b(uint64_t x) {
 2033|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)6);
 2034|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_6f:
 2093|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_6f(uint64_t a, uint64_t b) {
 2094|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_6f(a, b);
 2095|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_6f:
 2079|   862k|libcrux_sha3_simd_portable__vxarq_u64_6f(uint64_t a, uint64_t b) {
 2080|   862k|  return libcrux_sha3_simd_portable_rotate_left_6f(a ^ b);
 2081|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_6f:
 2068|   862k|libcrux_sha3_simd_portable_rotate_left_6f(uint64_t x) {
 2069|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)43);
 2070|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_62:
 2129|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_62(uint64_t a, uint64_t b) {
 2130|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_62(a, b);
 2131|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_62:
 2115|   862k|libcrux_sha3_simd_portable__vxarq_u64_62(uint64_t a, uint64_t b) {
 2116|   862k|  return libcrux_sha3_simd_portable_rotate_left_62(a ^ b);
 2117|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_62:
 2104|   862k|libcrux_sha3_simd_portable_rotate_left_62(uint64_t x) {
 2105|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)15);
 2106|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_23:
 2165|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_23(uint64_t a, uint64_t b) {
 2166|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_23(a, b);
 2167|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_23:
 2151|   862k|libcrux_sha3_simd_portable__vxarq_u64_23(uint64_t a, uint64_t b) {
 2152|   862k|  return libcrux_sha3_simd_portable_rotate_left_23(a ^ b);
 2153|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_23:
 2140|   862k|libcrux_sha3_simd_portable_rotate_left_23(uint64_t x) {
 2141|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)61);
 2142|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_37:
 2201|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_37(uint64_t a, uint64_t b) {
 2202|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_37(a, b);
 2203|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_37:
 2187|   862k|libcrux_sha3_simd_portable__vxarq_u64_37(uint64_t a, uint64_t b) {
 2188|   862k|  return libcrux_sha3_simd_portable_rotate_left_37(a ^ b);
 2189|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_37:
 2176|   862k|libcrux_sha3_simd_portable_rotate_left_37(uint64_t x) {
 2177|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)28);
 2178|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_bb:
 2237|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_bb(uint64_t a, uint64_t b) {
 2238|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_bb(a, b);
 2239|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_bb:
 2223|   862k|libcrux_sha3_simd_portable__vxarq_u64_bb(uint64_t a, uint64_t b) {
 2224|   862k|  return libcrux_sha3_simd_portable_rotate_left_bb(a ^ b);
 2225|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_bb:
 2212|   862k|libcrux_sha3_simd_portable_rotate_left_bb(uint64_t x) {
 2213|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)55);
 2214|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_b9:
 2273|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_b9(uint64_t a, uint64_t b) {
 2274|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_b9(a, b);
 2275|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_b9:
 2259|   862k|libcrux_sha3_simd_portable__vxarq_u64_b9(uint64_t a, uint64_t b) {
 2260|   862k|  return libcrux_sha3_simd_portable_rotate_left_b9(a ^ b);
 2261|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_b9:
 2248|   862k|libcrux_sha3_simd_portable_rotate_left_b9(uint64_t x) {
 2249|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)25);
 2250|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_54:
 2309|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_54(uint64_t a, uint64_t b) {
 2310|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_54(a, b);
 2311|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_54:
 2295|   862k|libcrux_sha3_simd_portable__vxarq_u64_54(uint64_t a, uint64_t b) {
 2296|   862k|  return libcrux_sha3_simd_portable_rotate_left_54(a ^ b);
 2297|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_54:
 2284|   862k|libcrux_sha3_simd_portable_rotate_left_54(uint64_t x) {
 2285|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)21);
 2286|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_4c:
 2345|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_4c(uint64_t a, uint64_t b) {
 2346|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_4c(a, b);
 2347|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_4c:
 2331|   862k|libcrux_sha3_simd_portable__vxarq_u64_4c(uint64_t a, uint64_t b) {
 2332|   862k|  return libcrux_sha3_simd_portable_rotate_left_4c(a ^ b);
 2333|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_4c:
 2320|   862k|libcrux_sha3_simd_portable_rotate_left_4c(uint64_t x) {
 2321|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)56);
 2322|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_ce:
 2381|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_ce(uint64_t a, uint64_t b) {
 2382|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_ce(a, b);
 2383|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_ce:
 2367|   862k|libcrux_sha3_simd_portable__vxarq_u64_ce(uint64_t a, uint64_t b) {
 2368|   862k|  return libcrux_sha3_simd_portable_rotate_left_ce(a ^ b);
 2369|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_ce:
 2356|   862k|libcrux_sha3_simd_portable_rotate_left_ce(uint64_t x) {
 2357|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)27);
 2358|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_77:
 2417|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_77(uint64_t a, uint64_t b) {
 2418|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_77(a, b);
 2419|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_77:
 2403|   862k|libcrux_sha3_simd_portable__vxarq_u64_77(uint64_t a, uint64_t b) {
 2404|   862k|  return libcrux_sha3_simd_portable_rotate_left_77(a ^ b);
 2405|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_77:
 2392|   862k|libcrux_sha3_simd_portable_rotate_left_77(uint64_t x) {
 2393|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)20);
 2394|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_25:
 2453|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_25(uint64_t a, uint64_t b) {
 2454|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_25(a, b);
 2455|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_25:
 2439|   862k|libcrux_sha3_simd_portable__vxarq_u64_25(uint64_t a, uint64_t b) {
 2440|   862k|  return libcrux_sha3_simd_portable_rotate_left_25(a ^ b);
 2441|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_25:
 2428|   862k|libcrux_sha3_simd_portable_rotate_left_25(uint64_t x) {
 2429|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)39);
 2430|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_af:
 2489|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_af(uint64_t a, uint64_t b) {
 2490|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_af(a, b);
 2491|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_af:
 2475|   862k|libcrux_sha3_simd_portable__vxarq_u64_af(uint64_t a, uint64_t b) {
 2476|   862k|  return libcrux_sha3_simd_portable_rotate_left_af(a ^ b);
 2477|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_af:
 2464|   862k|libcrux_sha3_simd_portable_rotate_left_af(uint64_t x) {
 2465|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)8);
 2466|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_fd:
 2525|   862k|libcrux_sha3_simd_portable_xor_and_rotate_d2_fd(uint64_t a, uint64_t b) {
 2526|   862k|  return libcrux_sha3_simd_portable__vxarq_u64_fd(a, b);
 2527|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_fd:
 2511|   862k|libcrux_sha3_simd_portable__vxarq_u64_fd(uint64_t a, uint64_t b) {
 2512|   862k|  return libcrux_sha3_simd_portable_rotate_left_fd(a ^ b);
 2513|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_fd:
 2500|   862k|libcrux_sha3_simd_portable_rotate_left_fd(uint64_t x) {
 2501|   862k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)14);
 2502|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_pi_80_04:
 2753|   862k|    libcrux_sha3_generic_keccak_KeccakState_17 *self) {
 2754|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 old = self[0U];
 2755|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2756|   862k|      self, (size_t)1U, (size_t)0U,
 2757|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2758|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2759|   862k|                                          .snd = (size_t)3U}))[0U]);
 2760|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2761|   862k|      self, (size_t)2U, (size_t)0U,
 2762|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2763|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2764|   862k|                                          .snd = (size_t)1U}))[0U]);
 2765|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2766|   862k|      self, (size_t)3U, (size_t)0U,
 2767|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2768|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2769|   862k|                                          .snd = (size_t)4U}))[0U]);
 2770|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2771|   862k|      self, (size_t)4U, (size_t)0U,
 2772|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2773|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2774|   862k|                                          .snd = (size_t)2U}))[0U]);
 2775|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2776|   862k|      self, (size_t)0U, (size_t)1U,
 2777|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2778|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2779|   862k|                                          .snd = (size_t)1U}))[0U]);
 2780|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2781|   862k|      self, (size_t)1U, (size_t)1U,
 2782|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2783|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2784|   862k|                                          .snd = (size_t)4U}))[0U]);
 2785|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2786|   862k|      self, (size_t)2U, (size_t)1U,
 2787|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2788|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2789|   862k|                                          .snd = (size_t)2U}))[0U]);
 2790|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2791|   862k|      self, (size_t)3U, (size_t)1U,
 2792|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2793|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2794|   862k|                                          .snd = (size_t)0U}))[0U]);
 2795|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2796|   862k|      self, (size_t)4U, (size_t)1U,
 2797|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2798|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2799|   862k|                                          .snd = (size_t)3U}))[0U]);
 2800|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2801|   862k|      self, (size_t)0U, (size_t)2U,
 2802|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2803|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2804|   862k|                                          .snd = (size_t)2U}))[0U]);
 2805|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2806|   862k|      self, (size_t)1U, (size_t)2U,
 2807|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2808|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2809|   862k|                                          .snd = (size_t)0U}))[0U]);
 2810|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2811|   862k|      self, (size_t)2U, (size_t)2U,
 2812|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2813|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2814|   862k|                                          .snd = (size_t)3U}))[0U]);
 2815|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2816|   862k|      self, (size_t)3U, (size_t)2U,
 2817|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2818|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2819|   862k|                                          .snd = (size_t)1U}))[0U]);
 2820|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2821|   862k|      self, (size_t)4U, (size_t)2U,
 2822|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2823|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2824|   862k|                                          .snd = (size_t)4U}))[0U]);
 2825|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2826|   862k|      self, (size_t)0U, (size_t)3U,
 2827|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2828|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2829|   862k|                                          .snd = (size_t)3U}))[0U]);
 2830|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2831|   862k|      self, (size_t)1U, (size_t)3U,
 2832|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2833|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2834|   862k|                                          .snd = (size_t)1U}))[0U]);
 2835|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2836|   862k|      self, (size_t)2U, (size_t)3U,
 2837|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2838|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2839|   862k|                                          .snd = (size_t)4U}))[0U]);
 2840|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2841|   862k|      self, (size_t)3U, (size_t)3U,
 2842|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2843|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2844|   862k|                                          .snd = (size_t)2U}))[0U]);
 2845|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2846|   862k|      self, (size_t)4U, (size_t)3U,
 2847|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2848|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2849|   862k|                                          .snd = (size_t)0U}))[0U]);
 2850|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2851|   862k|      self, (size_t)0U, (size_t)4U,
 2852|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2853|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2854|   862k|                                          .snd = (size_t)4U}))[0U]);
 2855|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2856|   862k|      self, (size_t)1U, (size_t)4U,
 2857|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2858|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2859|   862k|                                          .snd = (size_t)2U}))[0U]);
 2860|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2861|   862k|      self, (size_t)2U, (size_t)4U,
 2862|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2863|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2864|   862k|                                          .snd = (size_t)0U}))[0U]);
 2865|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2866|   862k|      self, (size_t)3U, (size_t)4U,
 2867|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2868|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2869|   862k|                                          .snd = (size_t)3U}))[0U]);
 2870|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2871|   862k|      self, (size_t)4U, (size_t)4U,
 2872|   862k|      libcrux_sha3_generic_keccak_index_c2_04(
 2873|   862k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2874|   862k|                                          .snd = (size_t)1U}))[0U]);
 2875|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_chi_80_04:
 2888|   862k|    libcrux_sha3_generic_keccak_KeccakState_17 *self) {
 2889|   862k|  libcrux_sha3_generic_keccak_KeccakState_17 old = self[0U];
 2890|  5.17M|  for (size_t i0 = (size_t)0U; i0 < (size_t)5U; i0++) {
  ------------------
  |  Branch (2890:32): [True: 4.31M, False: 862k]
  ------------------
 2891|  4.31M|    size_t i1 = i0;
 2892|  25.8M|    for (size_t i = (size_t)0U; i < (size_t)5U; i++) {
  ------------------
  |  Branch (2892:33): [True: 21.5M, False: 4.31M]
  ------------------
 2893|  21.5M|      size_t j = i;
 2894|  21.5M|      libcrux_sha3_generic_keccak_set_80_04(
 2895|  21.5M|          self, i1, j,
 2896|  21.5M|          libcrux_sha3_simd_portable_and_not_xor_d2(
 2897|  21.5M|              libcrux_sha3_generic_keccak_index_c2_04(
 2898|  21.5M|                  self, (KRML_CLITERAL(size_t_x2){.fst = i1, .snd = j}))[0U],
  ------------------
  |  |  154|  21.5M|#define KRML_CLITERAL(type) (type)
  ------------------
 2899|  21.5M|              libcrux_sha3_generic_keccak_index_c2_04(
 2900|  21.5M|                  &old,
 2901|  21.5M|                  (KRML_CLITERAL(size_t_x2){
  ------------------
  |  |  154|  21.5M|#define KRML_CLITERAL(type) (type)
  ------------------
 2902|  21.5M|                      .fst = i1, .snd = (j + (size_t)2U) % (size_t)5U}))[0U],
 2903|  21.5M|              libcrux_sha3_generic_keccak_index_c2_04(
 2904|  21.5M|                  &old,
 2905|  21.5M|                  (KRML_CLITERAL(size_t_x2){
  ------------------
  |  |  154|  21.5M|#define KRML_CLITERAL(type) (type)
  ------------------
 2906|  21.5M|                      .fst = i1, .snd = (j + (size_t)1U) % (size_t)5U}))[0U]));
 2907|  21.5M|    }
 2908|  4.31M|  }
 2909|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_and_not_xor_d2:
 1371|  21.5M|libcrux_sha3_simd_portable_and_not_xor_d2(uint64_t a, uint64_t b, uint64_t c) {
 1372|  21.5M|  return libcrux_sha3_simd_portable__vbcaxq_u64(a, b, c);
 1373|  21.5M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vbcaxq_u64:
 1363|  21.5M|libcrux_sha3_simd_portable__vbcaxq_u64(uint64_t a, uint64_t b, uint64_t c) {
 1364|  21.5M|  return a ^ (b & ~c);
 1365|  21.5M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_iota_80_04:
 2922|   862k|    libcrux_sha3_generic_keccak_KeccakState_17 *self, size_t i) {
 2923|   862k|  libcrux_sha3_generic_keccak_set_80_04(
 2924|   862k|      self, (size_t)0U, (size_t)0U,
 2925|   862k|      libcrux_sha3_simd_portable_xor_constant_d2(
 2926|   862k|          libcrux_sha3_generic_keccak_index_c2_04(
 2927|   862k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   862k|#define KRML_CLITERAL(type) (type)
  ------------------
 2928|   862k|                                              .snd = (size_t)0U}))[0U],
 2929|   862k|          libcrux_sha3_generic_keccak_constants_ROUNDCONSTANTS[i]));
 2930|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_constant_d2:
 1384|   862k|libcrux_sha3_simd_portable_xor_constant_d2(uint64_t a, uint64_t c) {
 1385|   862k|  return libcrux_sha3_simd_portable__veorq_n_u64(a, c);
 1386|   862k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__veorq_n_u64:
 1376|   862k|libcrux_sha3_simd_portable__veorq_n_u64(uint64_t a, uint64_t c) {
 1377|   862k|  return a ^ c;
 1378|   862k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_into_padded_array_15:
  936|    273|    Eurydice_slice slice, uint8_t ret[1120U]) {
  937|    273|  uint8_t out[1120U] = {0U};
  938|    273|  uint8_t *uu____0 = out;
  939|    273|  Eurydice_slice_copy(
  ------------------
  |  |  229|    273|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
  940|    273|      Eurydice_array_to_subslice3(
  941|    273|          uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *),
  942|    273|      slice, uint8_t);
  943|    273|  memcpy(ret, out, (size_t)1120U * sizeof(uint8_t));
  944|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_as_ref_d3_80:
  923|    546|    libcrux_ml_kem_mlkem768_MlKem768Ciphertext *self) {
  924|    546|  return Eurydice_array_to_slice((size_t)1088U, self->value, uint8_t);
  ------------------
  |  |  204|    546|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    546|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    546|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    546|                 end) /* x is already at an array type, no need for cast */
  ------------------
  925|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRF_4a_41:
 6326|    273|    Eurydice_slice input, uint8_t ret[32U]) {
 6327|    273|  libcrux_ml_kem_hash_functions_portable_PRF_9e(input, ret);
 6328|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRF_9e:
 6308|    273|    Eurydice_slice input, uint8_t ret[32U]) {
 6309|    273|  uint8_t digest[32U] = {0U};
 6310|    273|  libcrux_sha3_portable_shake256(
 6311|    273|      Eurydice_array_to_slice((size_t)32U, digest, uint8_t), input);
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6312|    273|  memcpy(ret, digest, (size_t)32U * sizeof(uint8_t));
 6313|    273|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_shake256:
 3455|  5.73k|    Eurydice_slice digest, Eurydice_slice data) {
 3456|  5.73k|  libcrux_sha3_generic_keccak_portable_keccak1_ad0(data, digest);
 3457|  5.73k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_keccak1_ad0:
 3419|  5.73k|    Eurydice_slice data, Eurydice_slice out) {
 3420|  5.73k|  libcrux_sha3_generic_keccak_KeccakState_17 s =
 3421|  5.73k|      libcrux_sha3_generic_keccak_new_80_04();
 3422|  5.73k|  size_t data_len = Eurydice_slice_len(data, uint8_t);
  ------------------
  |  |  173|  5.73k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3423|  7.91k|  for (size_t i = (size_t)0U; i < data_len / (size_t)136U; i++) {
  ------------------
  |  Branch (3423:31): [True: 2.18k, False: 5.73k]
  ------------------
 3424|  2.18k|    size_t i0 = i;
 3425|  2.18k|    Eurydice_slice buf[1U] = {data};
 3426|  2.18k|    libcrux_sha3_generic_keccak_absorb_block_80_c60(&s, buf, i0 * (size_t)136U);
 3427|  2.18k|  }
 3428|  5.73k|  size_t rem = data_len % (size_t)136U;
 3429|  5.73k|  Eurydice_slice buf[1U] = {data};
 3430|  5.73k|  libcrux_sha3_generic_keccak_absorb_final_80_9e1(&s, buf, data_len - rem, rem);
 3431|  5.73k|  size_t outlen = Eurydice_slice_len(out, uint8_t);
  ------------------
  |  |  173|  5.73k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3432|  5.73k|  size_t blocks = outlen / (size_t)136U;
 3433|  5.73k|  size_t last = outlen - outlen % (size_t)136U;
 3434|  5.73k|  if (blocks == (size_t)0U) {
  ------------------
  |  Branch (3434:7): [True: 5.73k, False: 0]
  ------------------
 3435|  5.73k|    libcrux_sha3_simd_portable_squeeze_13_5b(&s, out, (size_t)0U, outlen);
 3436|  5.73k|  } 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|  5.73k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_block_80_c60:
 3193|  6.55k|    size_t start) {
 3194|  6.55k|  libcrux_sha3_simd_portable_load_block_a1_5b(self, blocks, start);
 3195|  6.55k|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3196|  6.55k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_block_a1_5b:
 3176|  6.55k|    size_t start) {
 3177|  6.55k|  libcrux_sha3_simd_portable_load_block_5b(self->st, input[0U], start);
 3178|  6.55k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_block_5b:
 3138|  12.8k|    uint64_t *state, Eurydice_slice blocks, size_t start) {
 3139|  12.8k|  uint64_t state_flat[25U] = {0U};
 3140|   230k|  for (size_t i = (size_t)0U; i < (size_t)136U / (size_t)8U; i++) {
  ------------------
  |  Branch (3140:31): [True: 218k, False: 12.8k]
  ------------------
 3141|   218k|    size_t i0 = i;
 3142|   218k|    size_t offset = start + (size_t)8U * i0;
 3143|   218k|    uint8_t uu____0[8U];
 3144|   218k|    Result_15 dst;
 3145|   218k|    Eurydice_slice_to_array2(
  ------------------
  |  |  277|   218k|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|   218k|                           sizeof(t_arr))
  ------------------
 3146|   218k|        &dst,
 3147|   218k|        Eurydice_slice_subslice3(blocks, offset, offset + (size_t)8U,
 3148|   218k|                                 uint8_t *),
 3149|   218k|        Eurydice_slice, uint8_t[8U], TryFromSliceError);
 3150|   218k|    unwrap_26_68(dst, uu____0);
 3151|   218k|    state_flat[i0] = core_num__u64__from_le_bytes(uu____0);
 3152|   218k|  }
 3153|   230k|  for (size_t i = (size_t)0U; i < (size_t)136U / (size_t)8U; i++) {
  ------------------
  |  Branch (3153:31): [True: 218k, False: 12.8k]
  ------------------
 3154|   218k|    size_t i0 = i;
 3155|   218k|    libcrux_sha3_traits_set_ij_04(
 3156|   218k|        state, i0 / (size_t)5U, i0 % (size_t)5U,
 3157|   218k|        libcrux_sha3_traits_get_ij_04(state, i0 / (size_t)5U,
 3158|   218k|                                      i0 % (size_t)5U)[0U] ^
 3159|   218k|            state_flat[i0]);
 3160|   218k|  }
 3161|  12.8k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_final_80_9e1:
 3407|  5.73k|    size_t start, size_t len) {
 3408|  5.73k|  libcrux_sha3_simd_portable_load_last_a1_ad0(self, last, start, len);
 3409|  5.73k|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3410|  5.73k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_a1_ad0:
 3389|  5.73k|    size_t start, size_t len) {
 3390|  5.73k|  libcrux_sha3_simd_portable_load_last_ad0(self->st, input[0U], start, len);
 3391|  5.73k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_ad0:
 3362|  5.73k|    uint64_t *state, Eurydice_slice blocks, size_t start, size_t len) {
 3363|  5.73k|  uint8_t buffer[136U] = {0U};
 3364|  5.73k|  Eurydice_slice_copy(
  ------------------
  |  |  229|  5.73k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3365|  5.73k|      Eurydice_array_to_subslice3(buffer, (size_t)0U, len, uint8_t *),
 3366|  5.73k|      Eurydice_slice_subslice3(blocks, start, start + len, uint8_t *), uint8_t);
 3367|  5.73k|  buffer[len] = 31U;
 3368|  5.73k|  size_t uu____0 = (size_t)136U - (size_t)1U;
 3369|  5.73k|  buffer[uu____0] = (uint32_t)buffer[uu____0] | 128U;
 3370|  5.73k|  libcrux_sha3_simd_portable_load_block_5b(
 3371|  5.73k|      state, Eurydice_array_to_slice((size_t)136U, buffer, uint8_t),
  ------------------
  |  |  204|  5.73k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  5.73k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  5.73k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  5.73k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3372|  5.73k|      (size_t)0U);
 3373|  5.73k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_squeeze_13_5b:
 3304|  6.27k|    size_t start, size_t len) {
 3305|  6.27k|  libcrux_sha3_simd_portable_store_block_5b(self->st, out, start, len);
 3306|  6.27k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_store_block_5b:
 3261|  6.27k|    uint64_t *s, Eurydice_slice out, size_t start, size_t len) {
 3262|  6.27k|  size_t octets = len / (size_t)8U;
 3263|  96.9k|  for (size_t i = (size_t)0U; i < octets; i++) {
  ------------------
  |  Branch (3263:31): [True: 90.6k, False: 6.27k]
  ------------------
 3264|  90.6k|    size_t i0 = i;
 3265|  90.6k|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  90.6k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  90.6k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  90.6k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3266|  90.6k|        out, start + (size_t)8U * i0, start + (size_t)8U * i0 + (size_t)8U,
 3267|  90.6k|        uint8_t *);
 3268|  90.6k|    uint8_t ret[8U];
 3269|  90.6k|    core_num__u64__to_le_bytes(
 3270|  90.6k|        libcrux_sha3_traits_get_ij_04(s, i0 / (size_t)5U, i0 % (size_t)5U)[0U],
 3271|  90.6k|        ret);
 3272|  90.6k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  90.6k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3273|  90.6k|        uu____0, Eurydice_array_to_slice((size_t)8U, ret, uint8_t), uint8_t);
 3274|  90.6k|  }
 3275|  6.27k|  size_t remaining = len % (size_t)8U;
 3276|  6.27k|  if (remaining > (size_t)0U) {
  ------------------
  |  Branch (3276:7): [True: 0, False: 6.27k]
  ------------------
 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|  6.27k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_encrypt_2a:
 7881|    546|    uint8_t ret[1088U]) {
 7882|    546|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0
 7883|    546|      unpacked_public_key =
 7884|    546|          libcrux_ml_kem_ind_cpa_build_unpacked_public_key_3f(public_key);
 7885|    546|  uint8_t ret0[1088U];
 7886|    546|  libcrux_ml_kem_ind_cpa_encrypt_unpacked_2a(&unpacked_public_key, message,
 7887|    546|                                             randomness, ret0);
 7888|    546|  memcpy(ret, ret0, (size_t)1088U * sizeof(uint8_t));
 7889|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_build_unpacked_public_key_3f:
 6924|    546|        Eurydice_slice public_key) {
 6925|    546|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0
 6926|    546|      unpacked_public_key = libcrux_ml_kem_ind_cpa_unpacked_default_8b_1b();
 6927|    546|  libcrux_ml_kem_ind_cpa_build_unpacked_public_key_mut_3f(public_key,
 6928|    546|                                                          &unpacked_public_key);
 6929|    546|  return unpacked_public_key;
 6930|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_unpacked_default_8b_1b:
 6354|    819|libcrux_ml_kem_ind_cpa_unpacked_default_8b_1b(void) {
 6355|    819|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0[3U];
 6356|  3.27k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6356:31): [True: 2.45k, False: 819]
  ------------------
 6357|  2.45k|    uu____0[i] = libcrux_ml_kem_polynomial_ZERO_d6_ea();
 6358|  2.45k|  }
 6359|    819|  uint8_t uu____1[32U] = {0U};
 6360|    819|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0 lit;
 6361|    819|  memcpy(
 6362|    819|      lit.t_as_ntt, uu____0,
 6363|    819|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 6364|    819|  memcpy(lit.seed_for_A, uu____1, (size_t)32U * sizeof(uint8_t));
 6365|    819|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d repeat_expression0[3U][3U];
 6366|  3.27k|  for (size_t i0 = (size_t)0U; i0 < (size_t)3U; i0++) {
  ------------------
  |  Branch (6366:32): [True: 2.45k, False: 819]
  ------------------
 6367|  2.45k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d repeat_expression[3U];
 6368|  9.82k|    for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6368:33): [True: 7.37k, False: 2.45k]
  ------------------
 6369|  7.37k|      repeat_expression[i] = libcrux_ml_kem_polynomial_ZERO_d6_ea();
 6370|  7.37k|    }
 6371|  2.45k|    memcpy(repeat_expression0[i0], repeat_expression,
 6372|  2.45k|           (size_t)3U *
 6373|  2.45k|               sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 6374|  2.45k|  }
 6375|    819|  memcpy(lit.A, repeat_expression0,
 6376|    819|         (size_t)3U *
 6377|    819|             sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]));
 6378|    819|  return lit;
 6379|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_build_unpacked_public_key_mut_3f:
 6899|    546|        *unpacked_public_key) {
 6900|    546|  Eurydice_slice uu____0 = Eurydice_slice_subslice_to(
  ------------------
  |  |  198|    546|  EURYDICE_SLICE((t *)s.ptr, 0, subslice_end_pos)
  |  |  ------------------
  |  |  |  |  169|    546|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    546|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6901|    546|      public_key, (size_t)1152U, uint8_t, size_t, uint8_t[]);
 6902|    546|  libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_1b(
 6903|    546|      uu____0, unpacked_public_key->t_as_ntt);
 6904|    546|  Eurydice_slice seed = Eurydice_slice_subslice_from(
  ------------------
  |  |  201|    546|  EURYDICE_SLICE((t *)s.ptr, subslice_start_pos, s.len)
  |  |  ------------------
  |  |  |  |  169|    546|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    546|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6905|    546|      public_key, (size_t)1152U, uint8_t, size_t, uint8_t[]);
 6906|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d(*uu____1)[3U] =
 6907|    546|      unpacked_public_key->A;
 6908|    546|  uint8_t ret[34U];
 6909|    546|  libcrux_ml_kem_utils_into_padded_array_b6(seed, ret);
 6910|       |  libcrux_ml_kem_matrix_sample_matrix_A_2b(uu____1, ret, false);
 6911|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_1b:
 6425|    819|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *deserialized_pk) {
 6426|    819|  for (size_t i = (size_t)0U;
 6427|  3.27k|       i < Eurydice_slice_len(public_key, uint8_t) /
  ------------------
  |  |  173|  3.27k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (6427:8): [True: 2.45k, False: 819]
  ------------------
 6428|  3.27k|               LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT;
  ------------------
  |  |  453|  3.27k|  (LIBCRUX_ML_KEM_CONSTANTS_BITS_PER_RING_ELEMENT / (size_t)8U)
  |  |  ------------------
  |  |  |  |  450|  3.27k|  (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)12U)
  |  |  |  |  ------------------
  |  |  |  |  |  |  447|  3.27k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6429|  2.45k|       i++) {
 6430|  2.45k|    size_t i0 = i;
 6431|  2.45k|    Eurydice_slice ring_element = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  2.45k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  2.45k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  2.45k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6432|  2.45k|        public_key, i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 6433|  2.45k|        i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT +
 6434|  2.45k|            LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 6435|  2.45k|        uint8_t *);
 6436|  2.45k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0 =
 6437|  2.45k|        libcrux_ml_kem_serialize_deserialize_to_reduced_ring_element_ea(
 6438|  2.45k|            ring_element);
 6439|  2.45k|    deserialized_pk[i0] = uu____0;
 6440|  2.45k|  }
 6441|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_to_reduced_ring_element_ea:
 6395|  2.45k|    Eurydice_slice serialized) {
 6396|  2.45k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d re =
 6397|  2.45k|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 6398|  2.45k|  for (size_t i = (size_t)0U;
 6399|  41.7k|       i < Eurydice_slice_len(serialized, uint8_t) / (size_t)24U; i++) {
  ------------------
  |  |  173|  41.7k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (6399:8): [True: 39.3k, False: 2.45k]
  ------------------
 6400|  39.3k|    size_t i0 = i;
 6401|  39.3k|    Eurydice_slice bytes =
 6402|  39.3k|        Eurydice_slice_subslice3(serialized, i0 * (size_t)24U,
  ------------------
  |  |  195|  39.3k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  39.3k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  39.3k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6403|  39.3k|                                 i0 * (size_t)24U + (size_t)24U, uint8_t *);
 6404|  39.3k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 6405|  39.3k|        libcrux_ml_kem_vector_portable_deserialize_12_b8(bytes);
 6406|  39.3k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 6407|  39.3k|        libcrux_ml_kem_vector_portable_cond_subtract_3329_b8(coefficient);
 6408|  39.3k|    re.coefficients[i0] = uu____0;
 6409|  39.3k|  }
 6410|  2.45k|  return re;
 6411|  2.45k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_cond_subtract_3329_b8:
 3935|  39.3k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector v) {
 3936|  39.3k|  return libcrux_ml_kem_vector_portable_arithmetic_cond_subtract_3329(v);
 3937|  39.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_cond_subtract_3329:
 3916|  39.3k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec) {
 3917|  39.3k|  for (size_t i = (size_t)0U;
 3918|   668k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   668k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3918:8): [True: 628k, False: 39.3k]
  ------------------
 3919|   628k|    size_t i0 = i;
 3920|   628k|    if (libcrux_secrets_int_public_integers_declassify_d8_39(
  ------------------
  |  Branch (3920:9): [True: 0, False: 628k]
  ------------------
 3921|   628k|            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|   628k|  }
 3926|  39.3k|  return vec;
 3927|  39.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_into_padded_array_b6:
  903|    819|    Eurydice_slice slice, uint8_t ret[34U]) {
  904|    819|  uint8_t out[34U] = {0U};
  905|    819|  uint8_t *uu____0 = out;
  906|    819|  Eurydice_slice_copy(
  ------------------
  |  |  229|    819|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
  907|    819|      Eurydice_array_to_subslice3(
  908|    819|          uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *),
  909|    819|      slice, uint8_t);
  910|    819|  memcpy(ret, out, (size_t)34U * sizeof(uint8_t));
  911|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_sample_matrix_A_2b:
 6854|    819|    uint8_t *seed, bool transpose) {
 6855|  3.27k|  for (size_t i0 = (size_t)0U; i0 < (size_t)3U; i0++) {
  ------------------
  |  Branch (6855:32): [True: 2.45k, False: 819]
  ------------------
 6856|  2.45k|    size_t i1 = i0;
 6857|  2.45k|    uint8_t seeds[3U][34U];
 6858|  9.82k|    for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6858:33): [True: 7.37k, False: 2.45k]
  ------------------
 6859|  7.37k|      core_array__core__clone__Clone_for__Array_T__N___clone(
  ------------------
  |  |  236|  7.37k|  (memcpy(dst, src, len * sizeof(elem_type)))
  ------------------
 6860|  7.37k|          (size_t)34U, seed, seeds[i], uint8_t, void *);
 6861|  7.37k|    }
 6862|  9.82k|    for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6862:33): [True: 7.37k, False: 2.45k]
  ------------------
 6863|  7.37k|      size_t j = i;
 6864|  7.37k|      seeds[j][32U] = (uint8_t)i1;
 6865|  7.37k|      seeds[j][33U] = (uint8_t)j;
 6866|  7.37k|    }
 6867|  2.45k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d sampled[3U];
 6868|  2.45k|    libcrux_ml_kem_sampling_sample_from_xof_2b(seeds, sampled);
 6869|  2.45k|    for (size_t i = (size_t)0U;
 6870|  9.82k|         i < Eurydice_slice_len(
  ------------------
  |  |  173|  9.82k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (6870:10): [True: 7.37k, False: 2.45k]
  ------------------
 6871|  2.45k|                 Eurydice_array_to_slice(
 6872|  2.45k|                     (size_t)3U, sampled,
 6873|  2.45k|                     libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 6874|  2.45k|                 libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 6875|  7.37k|         i++) {
 6876|  7.37k|      size_t j = i;
 6877|  7.37k|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d sample = sampled[j];
 6878|  7.37k|      if (transpose) {
  ------------------
  |  Branch (6878:11): [True: 2.45k, False: 4.91k]
  ------------------
 6879|  2.45k|        A_transpose[j][i1] = sample;
 6880|  4.91k|      } else {
 6881|  4.91k|        A_transpose[i1][j] = sample;
 6882|  4.91k|      }
 6883|  7.37k|    }
 6884|  2.45k|  }
 6885|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_xof_2b:
 6808|  2.45k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret[3U]) {
 6809|  2.45k|  size_t sampled_coefficients[3U] = {0U};
 6810|  2.45k|  int16_t out[3U][272U] = {{0U}};
 6811|  2.45k|  libcrux_ml_kem_hash_functions_portable_PortableHash_88 xof_state =
 6812|  2.45k|      libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_4a_e0(
 6813|  2.45k|          seeds);
 6814|  2.45k|  uint8_t randomness0[3U][504U];
 6815|  2.45k|  libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_4a_e0(
 6816|  2.45k|      &xof_state, randomness0);
 6817|  2.45k|  bool done = libcrux_ml_kem_sampling_sample_from_uniform_distribution_next_89(
 6818|  2.45k|      randomness0, sampled_coefficients, out);
 6819|  2.51k|  while (true) {
  ------------------
  |  Branch (6819:10): [True: 2.51k, Folded]
  ------------------
 6820|  2.51k|    if (done) {
  ------------------
  |  Branch (6820:9): [True: 2.45k, False: 54]
  ------------------
 6821|  2.45k|      break;
 6822|  2.45k|    } else {
 6823|     54|      uint8_t randomness[3U][168U];
 6824|     54|      libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_4a_e0(
 6825|     54|          &xof_state, randomness);
 6826|     54|      done = libcrux_ml_kem_sampling_sample_from_uniform_distribution_next_890(
 6827|     54|          randomness, sampled_coefficients, out);
 6828|     54|    }
 6829|  2.51k|  }
 6830|       |  /* Passing arrays by value in Rust generates a copy in C */
 6831|  2.45k|  int16_t copy_of_out[3U][272U];
 6832|  2.45k|  memcpy(copy_of_out, out, (size_t)3U * sizeof(int16_t[272U]));
 6833|  2.45k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret0[3U];
 6834|  9.82k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6834:31): [True: 7.37k, False: 2.45k]
  ------------------
 6835|       |    /* original Rust expression is not an lvalue in C */
 6836|  7.37k|    void *lvalue = (void *)0U;
 6837|  7.37k|    ret0[i] = libcrux_ml_kem_sampling_sample_from_xof_call_mut_e7_2b(
 6838|  7.37k|        &lvalue, copy_of_out[i]);
 6839|  7.37k|  }
 6840|  2.45k|  memcpy(
 6841|  2.45k|      ret, ret0,
 6842|  2.45k|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 6843|  2.45k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_4a_e0:
 6489|  2.45k|    uint8_t (*input)[34U]) {
 6490|  2.45k|  return libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_e0(
 6491|  2.45k|      input);
 6492|  2.45k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_e0:
 6460|  2.45k|    uint8_t (*input)[34U]) {
 6461|  2.45k|  libcrux_ml_kem_hash_functions_portable_PortableHash_88 shake128_state;
 6462|  2.45k|  libcrux_sha3_generic_keccak_KeccakState_17 repeat_expression[3U];
 6463|  9.82k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6463:31): [True: 7.37k, False: 2.45k]
  ------------------
 6464|  7.37k|    repeat_expression[i] = libcrux_sha3_portable_incremental_shake128_init();
 6465|  7.37k|  }
 6466|  2.45k|  memcpy(shake128_state.shake128_state, repeat_expression,
 6467|  2.45k|         (size_t)3U * sizeof(libcrux_sha3_generic_keccak_KeccakState_17));
 6468|  9.82k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6468:31): [True: 7.37k, False: 2.45k]
  ------------------
 6469|  7.37k|    size_t i0 = i;
 6470|  7.37k|    libcrux_sha3_portable_incremental_shake128_absorb_final(
 6471|  7.37k|        &shake128_state.shake128_state[i0],
 6472|  7.37k|        Eurydice_array_to_slice((size_t)34U, input[i0], uint8_t));
  ------------------
  |  |  204|  7.37k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  7.37k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  7.37k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  7.37k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6473|  7.37k|  }
 6474|  2.45k|  return shake128_state;
 6475|  2.45k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_incremental_shake128_init:
 3466|  7.37k|libcrux_sha3_portable_incremental_shake128_init(void) {
 3467|  7.37k|  return libcrux_sha3_generic_keccak_new_80_04();
 3468|  7.37k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_incremental_shake128_absorb_final:
 3563|  7.37k|    libcrux_sha3_generic_keccak_KeccakState_17 *s, Eurydice_slice data0) {
 3564|  7.37k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____0 = s;
 3565|  7.37k|  Eurydice_slice uu____1[1U] = {data0};
 3566|  7.37k|  libcrux_sha3_generic_keccak_absorb_final_80_9e2(
 3567|  7.37k|      uu____0, uu____1, (size_t)0U, Eurydice_slice_len(data0, uint8_t));
  ------------------
  |  |  173|  7.37k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3568|  7.37k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_final_80_9e2:
 3553|  7.37k|    size_t start, size_t len) {
 3554|  7.37k|  libcrux_sha3_simd_portable_load_last_a1_c6(self, last, start, len);
 3555|  7.37k|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3556|  7.37k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_a1_c6:
 3535|  7.37k|    size_t start, size_t len) {
 3536|  7.37k|  libcrux_sha3_simd_portable_load_last_c6(self->st, input[0U], start, len);
 3537|  7.37k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_c6:
 3508|  7.37k|    uint64_t *state, Eurydice_slice blocks, size_t start, size_t len) {
 3509|  7.37k|  uint8_t buffer[168U] = {0U};
 3510|  7.37k|  Eurydice_slice_copy(
  ------------------
  |  |  229|  7.37k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3511|  7.37k|      Eurydice_array_to_subslice3(buffer, (size_t)0U, len, uint8_t *),
 3512|  7.37k|      Eurydice_slice_subslice3(blocks, start, start + len, uint8_t *), uint8_t);
 3513|  7.37k|  buffer[len] = 31U;
 3514|  7.37k|  size_t uu____0 = (size_t)168U - (size_t)1U;
 3515|  7.37k|  buffer[uu____0] = (uint32_t)buffer[uu____0] | 128U;
 3516|  7.37k|  libcrux_sha3_simd_portable_load_block_3a(
 3517|  7.37k|      state, Eurydice_array_to_slice((size_t)168U, buffer, uint8_t),
  ------------------
  |  |  204|  7.37k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  7.37k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  7.37k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  7.37k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3518|  7.37k|      (size_t)0U);
 3519|  7.37k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_block_3a:
 3476|  7.37k|    uint64_t *state, Eurydice_slice blocks, size_t start) {
 3477|  7.37k|  uint64_t state_flat[25U] = {0U};
 3478|   162k|  for (size_t i = (size_t)0U; i < (size_t)168U / (size_t)8U; i++) {
  ------------------
  |  Branch (3478:31): [True: 154k, False: 7.37k]
  ------------------
 3479|   154k|    size_t i0 = i;
 3480|   154k|    size_t offset = start + (size_t)8U * i0;
 3481|   154k|    uint8_t uu____0[8U];
 3482|   154k|    Result_15 dst;
 3483|   154k|    Eurydice_slice_to_array2(
  ------------------
  |  |  277|   154k|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|   154k|                           sizeof(t_arr))
  ------------------
 3484|   154k|        &dst,
 3485|   154k|        Eurydice_slice_subslice3(blocks, offset, offset + (size_t)8U,
 3486|   154k|                                 uint8_t *),
 3487|   154k|        Eurydice_slice, uint8_t[8U], TryFromSliceError);
 3488|   154k|    unwrap_26_68(dst, uu____0);
 3489|   154k|    state_flat[i0] = core_num__u64__from_le_bytes(uu____0);
 3490|   154k|  }
 3491|   162k|  for (size_t i = (size_t)0U; i < (size_t)168U / (size_t)8U; i++) {
  ------------------
  |  Branch (3491:31): [True: 154k, False: 7.37k]
  ------------------
 3492|   154k|    size_t i0 = i;
 3493|   154k|    libcrux_sha3_traits_set_ij_04(
 3494|   154k|        state, i0 / (size_t)5U, i0 % (size_t)5U,
 3495|   154k|        libcrux_sha3_traits_get_ij_04(state, i0 / (size_t)5U,
 3496|   154k|                                      i0 % (size_t)5U)[0U] ^
 3497|   154k|            state_flat[i0]);
 3498|   154k|  }
 3499|  7.37k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_4a_e0:
 6527|  2.45k|    uint8_t ret[3U][504U]) {
 6528|  2.45k|  libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_e0(
 6529|  2.45k|      self, ret);
 6530|  2.45k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_e0:
 6503|  2.45k|    uint8_t ret[3U][504U]) {
 6504|  2.45k|  uint8_t out[3U][504U] = {{0U}};
 6505|  9.82k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6505:31): [True: 7.37k, False: 2.45k]
  ------------------
 6506|  7.37k|    size_t i0 = i;
 6507|  7.37k|    libcrux_sha3_portable_incremental_shake128_squeeze_first_three_blocks(
 6508|  7.37k|        &st->shake128_state[i0],
 6509|  7.37k|        Eurydice_array_to_slice((size_t)504U, out[i0], uint8_t));
  ------------------
  |  |  204|  7.37k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  7.37k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  7.37k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  7.37k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6510|  7.37k|  }
 6511|  2.45k|  memcpy(ret, out, (size_t)3U * sizeof(uint8_t[504U]));
 6512|  2.45k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_incremental_shake128_squeeze_first_three_blocks:
 3652|  7.37k|    libcrux_sha3_generic_keccak_KeccakState_17 *s, Eurydice_slice out0) {
 3653|  7.37k|  libcrux_sha3_generic_keccak_portable_squeeze_first_three_blocks_b4_3a(s,
 3654|  7.37k|                                                                        out0);
 3655|  7.37k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_squeeze_first_three_blocks_b4_3a:
 3637|  7.37k|    libcrux_sha3_generic_keccak_KeccakState_17 *self, Eurydice_slice out) {
 3638|  7.37k|  libcrux_sha3_simd_portable_squeeze_13_3a(self, out, (size_t)0U, (size_t)168U);
 3639|  7.37k|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3640|  7.37k|  libcrux_sha3_simd_portable_squeeze_13_3a(self, out, (size_t)168U,
 3641|  7.37k|                                           (size_t)168U);
 3642|  7.37k|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3643|  7.37k|  libcrux_sha3_simd_portable_squeeze_13_3a(self, out, (size_t)2U * (size_t)168U,
 3644|  7.37k|                                           (size_t)168U);
 3645|  7.37k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_squeeze_13_3a:
 3619|  22.2k|    size_t start, size_t len) {
 3620|  22.2k|  libcrux_sha3_simd_portable_store_block_3a(self->st, out, start, len);
 3621|  22.2k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_store_block_3a:
 3576|  22.2k|    uint64_t *s, Eurydice_slice out, size_t start, size_t len) {
 3577|  22.2k|  size_t octets = len / (size_t)8U;
 3578|   490k|  for (size_t i = (size_t)0U; i < octets; i++) {
  ------------------
  |  Branch (3578:31): [True: 467k, False: 22.2k]
  ------------------
 3579|   467k|    size_t i0 = i;
 3580|   467k|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|   467k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   467k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   467k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3581|   467k|        out, start + (size_t)8U * i0, start + (size_t)8U * i0 + (size_t)8U,
 3582|   467k|        uint8_t *);
 3583|   467k|    uint8_t ret[8U];
 3584|   467k|    core_num__u64__to_le_bytes(
 3585|   467k|        libcrux_sha3_traits_get_ij_04(s, i0 / (size_t)5U, i0 % (size_t)5U)[0U],
 3586|   467k|        ret);
 3587|   467k|    Eurydice_slice_copy(
  ------------------
  |  |  229|   467k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3588|   467k|        uu____0, Eurydice_array_to_slice((size_t)8U, ret, uint8_t), uint8_t);
 3589|   467k|  }
 3590|  22.2k|  size_t remaining = len % (size_t)8U;
 3591|  22.2k|  if (remaining > (size_t)0U) {
  ------------------
  |  Branch (3591:7): [True: 0, False: 22.2k]
  ------------------
 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|  22.2k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_uniform_distribution_next_89:
 6583|  2.45k|    int16_t (*out)[272U]) {
 6584|  9.82k|  for (size_t i0 = (size_t)0U; i0 < (size_t)3U; i0++) {
  ------------------
  |  Branch (6584:32): [True: 7.37k, False: 2.45k]
  ------------------
 6585|  7.37k|    size_t i1 = i0;
 6586|   162k|    for (size_t i = (size_t)0U; i < (size_t)504U / (size_t)24U; i++) {
  ------------------
  |  Branch (6586:33): [True: 154k, False: 7.37k]
  ------------------
 6587|   154k|      size_t r = i;
 6588|   154k|      if (sampled_coefficients[i1] <
  ------------------
  |  Branch (6588:11): [True: 148k, False: 6.40k]
  ------------------
 6589|   154k|          LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT) {
  ------------------
  |  |  447|   154k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6590|   148k|        size_t sampled = libcrux_ml_kem_vector_portable_rej_sample_b8(
 6591|   148k|            Eurydice_array_to_subslice3(randomness[i1], r * (size_t)24U,
  ------------------
  |  |  215|   148k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   148k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   148k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6592|   148k|                                        r * (size_t)24U + (size_t)24U,
 6593|   148k|                                        uint8_t *),
 6594|   148k|            Eurydice_array_to_subslice3(out[i1], sampled_coefficients[i1],
  ------------------
  |  |  215|   148k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   148k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   148k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6595|   148k|                                        sampled_coefficients[i1] + (size_t)16U,
 6596|   148k|                                        int16_t *));
 6597|   148k|        size_t uu____0 = i1;
 6598|   148k|        sampled_coefficients[uu____0] = sampled_coefficients[uu____0] + sampled;
 6599|   148k|      }
 6600|   154k|    }
 6601|  7.37k|  }
 6602|  2.45k|  bool done = true;
 6603|  9.82k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6603:31): [True: 7.37k, False: 2.45k]
  ------------------
 6604|  7.37k|    size_t i0 = i;
 6605|  7.37k|    if (sampled_coefficients[i0] >=
  ------------------
  |  Branch (6605:9): [True: 7.31k, False: 57]
  ------------------
 6606|  7.37k|        LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT) {
  ------------------
  |  |  447|  7.37k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6607|  7.31k|      sampled_coefficients[i0] =
 6608|  7.31k|          LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT;
  ------------------
  |  |  447|  7.31k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6609|  7.31k|    } else {
 6610|       |      done = false;
 6611|     57|    }
 6612|  7.37k|  }
 6613|  2.45k|  return done;
 6614|  2.45k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_rej_sample_b8:
 5219|   148k|    Eurydice_slice a, Eurydice_slice out) {
 5220|   148k|  return libcrux_ml_kem_vector_portable_sampling_rej_sample(a, out);
 5221|   148k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_sampling_rej_sample:
 5185|   148k|                                                   Eurydice_slice result) {
 5186|   148k|  size_t sampled = (size_t)0U;
 5187|  1.33M|  for (size_t i = (size_t)0U; i < Eurydice_slice_len(a, uint8_t) / (size_t)3U;
  ------------------
  |  |  173|  1.33M|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5187:31): [True: 1.18M, False: 148k]
  ------------------
 5188|  1.18M|       i++) {
 5189|  1.18M|    size_t i0 = i;
 5190|  1.18M|    int16_t b1 = (int16_t)Eurydice_slice_index(a, i0 * (size_t)3U + (size_t)0U,
  ------------------
  |  |  180|  1.18M|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5191|  1.18M|                                               uint8_t, uint8_t *);
 5192|  1.18M|    int16_t b2 = (int16_t)Eurydice_slice_index(a, i0 * (size_t)3U + (size_t)1U,
  ------------------
  |  |  180|  1.18M|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5193|  1.18M|                                               uint8_t, uint8_t *);
 5194|  1.18M|    int16_t b3 = (int16_t)Eurydice_slice_index(a, i0 * (size_t)3U + (size_t)2U,
  ------------------
  |  |  180|  1.18M|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5195|  1.18M|                                               uint8_t, uint8_t *);
 5196|  1.18M|    int16_t d1 = (b2 & (int16_t)15) << 8U | b1;
 5197|  1.18M|    int16_t d2 = b3 << 4U | b2 >> 4U;
 5198|  1.18M|    if (d1 < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS) {
  ------------------
  |  | 3777|  1.18M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
  |  Branch (5198:9): [True: 966k, False: 221k]
  ------------------
 5199|   966k|      if (sampled < (size_t)16U) {
  ------------------
  |  Branch (5199:11): [True: 966k, False: 0]
  ------------------
 5200|   966k|        Eurydice_slice_index(result, sampled, int16_t, int16_t *) = d1;
  ------------------
  |  |  180|   966k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5201|   966k|        sampled++;
 5202|   966k|      }
 5203|   966k|    }
 5204|  1.18M|    if (d2 < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS) {
  ------------------
  |  | 3777|  1.18M|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
  |  Branch (5204:9): [True: 965k, False: 222k]
  ------------------
 5205|   965k|      if (sampled < (size_t)16U) {
  ------------------
  |  Branch (5205:11): [True: 965k, False: 0]
  ------------------
 5206|   965k|        Eurydice_slice_index(result, sampled, int16_t, int16_t *) = d2;
  ------------------
  |  |  180|   965k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5207|   965k|        sampled++;
 5208|   965k|      }
 5209|   965k|    }
 5210|  1.18M|  }
 5211|   148k|  return sampled;
 5212|   148k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_4a_e0:
 6649|     54|    uint8_t ret[3U][168U]) {
 6650|     54|  libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_e0(self,
 6651|     54|                                                                        ret);
 6652|     54|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_e0:
 6625|     54|    uint8_t ret[3U][168U]) {
 6626|     54|  uint8_t out[3U][168U] = {{0U}};
 6627|    216|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6627:31): [True: 162, False: 54]
  ------------------
 6628|    162|    size_t i0 = i;
 6629|    162|    libcrux_sha3_portable_incremental_shake128_squeeze_next_block(
 6630|    162|        &st->shake128_state[i0],
 6631|    162|        Eurydice_array_to_slice((size_t)168U, out[i0], uint8_t));
  ------------------
  |  |  204|    162|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    162|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    162|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    162|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6632|    162|  }
 6633|     54|  memcpy(ret, out, (size_t)3U * sizeof(uint8_t[168U]));
 6634|     54|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_incremental_shake128_squeeze_next_block:
 3681|    162|    libcrux_sha3_generic_keccak_KeccakState_17 *s, Eurydice_slice out0) {
 3682|    162|  libcrux_sha3_generic_keccak_portable_squeeze_next_block_b4_3a(s, out0,
 3683|    162|                                                                (size_t)0U);
 3684|    162|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_squeeze_next_block_b4_3a:
 3671|    162|    size_t start) {
 3672|    162|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3673|    162|  libcrux_sha3_simd_portable_squeeze_13_3a(self, out, start, (size_t)168U);
 3674|    162|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_uniform_distribution_next_890:
 6705|     54|    int16_t (*out)[272U]) {
 6706|    216|  for (size_t i0 = (size_t)0U; i0 < (size_t)3U; i0++) {
  ------------------
  |  Branch (6706:32): [True: 162, False: 54]
  ------------------
 6707|    162|    size_t i1 = i0;
 6708|  1.29k|    for (size_t i = (size_t)0U; i < (size_t)168U / (size_t)24U; i++) {
  ------------------
  |  Branch (6708:33): [True: 1.13k, False: 162]
  ------------------
 6709|  1.13k|      size_t r = i;
 6710|  1.13k|      if (sampled_coefficients[i1] <
  ------------------
  |  Branch (6710:11): [True: 57, False: 1.07k]
  ------------------
 6711|  1.13k|          LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT) {
  ------------------
  |  |  447|  1.13k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6712|     57|        size_t sampled = libcrux_ml_kem_vector_portable_rej_sample_b8(
 6713|     57|            Eurydice_array_to_subslice3(randomness[i1], r * (size_t)24U,
  ------------------
  |  |  215|     57|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|     57|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|     57|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6714|     57|                                        r * (size_t)24U + (size_t)24U,
 6715|     57|                                        uint8_t *),
 6716|     57|            Eurydice_array_to_subslice3(out[i1], sampled_coefficients[i1],
  ------------------
  |  |  215|     57|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|     57|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|     57|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6717|     57|                                        sampled_coefficients[i1] + (size_t)16U,
 6718|     57|                                        int16_t *));
 6719|     57|        size_t uu____0 = i1;
 6720|     57|        sampled_coefficients[uu____0] = sampled_coefficients[uu____0] + sampled;
 6721|     57|      }
 6722|  1.13k|    }
 6723|    162|  }
 6724|     54|  bool done = true;
 6725|    216|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6725:31): [True: 162, False: 54]
  ------------------
 6726|    162|    size_t i0 = i;
 6727|    162|    if (sampled_coefficients[i0] >=
  ------------------
  |  Branch (6727:9): [True: 162, False: 0]
  ------------------
 6728|    162|        LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT) {
  ------------------
  |  |  447|    162|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6729|    162|      sampled_coefficients[i0] =
 6730|    162|          LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT;
  ------------------
  |  |  447|    162|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6731|    162|    } else {
 6732|       |      done = false;
 6733|      0|    }
 6734|    162|  }
 6735|     54|  return done;
 6736|     54|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_xof_call_mut_e7_2b:
 6792|  7.37k|    void **_, int16_t tupled_args[272U]) {
 6793|  7.37k|  int16_t s[272U];
 6794|  7.37k|  memcpy(s, tupled_args, (size_t)272U * sizeof(int16_t));
 6795|  7.37k|  return libcrux_ml_kem_polynomial_from_i16_array_d6_ea(
 6796|  7.37k|      Eurydice_array_to_subslice3(s, (size_t)0U, (size_t)256U, int16_t *));
  ------------------
  |  |  215|  7.37k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  7.37k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  7.37k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6797|  7.37k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_from_i16_array_d6_ea:
 6773|  12.8k|libcrux_ml_kem_polynomial_from_i16_array_d6_ea(Eurydice_slice a) {
 6774|  12.8k|  return libcrux_ml_kem_polynomial_from_i16_array_ea(a);
 6775|  12.8k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_from_i16_array_ea:
 6745|  12.8k|libcrux_ml_kem_polynomial_from_i16_array_ea(Eurydice_slice a) {
 6746|  12.8k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d result =
 6747|  12.8k|      libcrux_ml_kem_polynomial_ZERO_ea();
 6748|  12.8k|  for (size_t i = (size_t)0U;
 6749|   218k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|   218k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (6749:8): [True: 205k, False: 12.8k]
  ------------------
 6750|   205k|    size_t i0 = i;
 6751|   205k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 6752|   205k|        libcrux_ml_kem_vector_portable_from_i16_array_b8(
 6753|   205k|            Eurydice_slice_subslice3(a, i0 * (size_t)16U,
  ------------------
  |  |  195|   205k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   205k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   205k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6754|   205k|                                     (i0 + (size_t)1U) * (size_t)16U,
 6755|   205k|                                     int16_t *));
 6756|   205k|    result.coefficients[i0] = uu____0;
 6757|   205k|  }
 6758|  12.8k|  return result;
 6759|  12.8k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_from_i16_array_b8:
 3805|   205k|libcrux_ml_kem_vector_portable_from_i16_array_b8(Eurydice_slice array) {
 3806|   205k|  return libcrux_ml_kem_vector_portable_vector_type_from_i16_array(
 3807|   205k|      libcrux_secrets_int_classify_public_classify_ref_9b_39(array));
 3808|   205k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_vector_type_from_i16_array:
 3788|   205k|    Eurydice_slice array) {
 3789|   205k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector lit;
 3790|   205k|  int16_t ret[16U];
 3791|   205k|  Result_0a dst;
 3792|   205k|  Eurydice_slice_to_array2(
  ------------------
  |  |  277|   205k|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|   205k|                           sizeof(t_arr))
  ------------------
 3793|   205k|      &dst, Eurydice_slice_subslice3(array, (size_t)0U, (size_t)16U, int16_t *),
 3794|   205k|      Eurydice_slice, int16_t[16U], TryFromSliceError);
 3795|   205k|  unwrap_26_00(dst, ret);
 3796|   205k|  memcpy(lit.elements, ret, (size_t)16U * sizeof(int16_t));
 3797|   205k|  return lit;
 3798|   205k|}
libcrux_mlkem768_sha3.c:unwrap_26_00:
 1129|   205k|static inline void unwrap_26_00(Result_0a self, int16_t ret[16U]) {
 1130|   205k|  if (self.tag == Ok) {
  ------------------
  |  |  721|   205k|#define Ok 0
  ------------------
  |  Branch (1130:7): [True: 205k, False: 0]
  ------------------
 1131|   205k|    int16_t f0[16U];
 1132|   205k|    memcpy(f0, self.val.case_Ok, (size_t)16U * sizeof(int16_t));
 1133|   205k|    memcpy(ret, f0, (size_t)16U * sizeof(int16_t));
 1134|   205k|  } 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|   205k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_classify_public_classify_ref_9b_39:
 1103|   205k|libcrux_secrets_int_classify_public_classify_ref_9b_39(Eurydice_slice self) {
 1104|   205k|  return self;
 1105|   205k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_encrypt_unpacked_2a:
 7838|    546|    uint8_t *message, Eurydice_slice randomness, uint8_t ret[1088U]) {
 7839|    546|  uint8_t ciphertext[1088U] = {0U};
 7840|    546|  tuple_ed uu____0 = libcrux_ml_kem_ind_cpa_encrypt_c1_85(
 7841|    546|      randomness, public_key->A,
 7842|    546|      Eurydice_array_to_subslice3(ciphertext, (size_t)0U, (size_t)960U,
  ------------------
  |  |  215|    546|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    546|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    546|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7843|    546|                                  uint8_t *));
 7844|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d r_as_ntt[3U];
 7845|    546|  memcpy(
 7846|    546|      r_as_ntt, uu____0.fst,
 7847|    546|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 7848|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d error_2 = uu____0.snd;
 7849|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d *uu____1 =
 7850|    546|      public_key->t_as_ntt;
 7851|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d *uu____2 = r_as_ntt;
 7852|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d *uu____3 = &error_2;
 7853|    546|  uint8_t *uu____4 = message;
 7854|    546|  libcrux_ml_kem_ind_cpa_encrypt_c2_6c(
 7855|    546|      uu____1, uu____2, uu____3, uu____4,
 7856|    546|      Eurydice_array_to_subslice_from((size_t)1088U, ciphertext, (size_t)960U,
  ------------------
  |  |  225|    546|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|    546|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    546|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7857|    546|                                      uint8_t, size_t, uint8_t[]));
 7858|    546|  memcpy(ret, ciphertext, (size_t)1088U * sizeof(uint8_t));
 7859|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_encrypt_c1_85:
 7528|    546|    Eurydice_slice ciphertext) {
 7529|    546|  uint8_t prf_input[33U];
 7530|    546|  libcrux_ml_kem_utils_into_padded_array_c8(randomness, prf_input);
 7531|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d r_as_ntt[3U];
 7532|  2.18k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7532:31): [True: 1.63k, False: 546]
  ------------------
 7533|       |    /* original Rust expression is not an lvalue in C */
 7534|  1.63k|    void *lvalue = (void *)0U;
 7535|  1.63k|    r_as_ntt[i] = libcrux_ml_kem_ind_cpa_encrypt_c1_call_mut_f1_85(&lvalue, i);
 7536|  1.63k|  }
 7537|    546|  uint8_t domain_separator0 =
 7538|    546|      libcrux_ml_kem_ind_cpa_sample_vector_cbd_then_ntt_3b(r_as_ntt, prf_input,
 7539|    546|                                                           0U);
 7540|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d error_1[3U];
 7541|  2.18k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7541:31): [True: 1.63k, False: 546]
  ------------------
 7542|       |    /* original Rust expression is not an lvalue in C */
 7543|  1.63k|    void *lvalue = (void *)0U;
 7544|  1.63k|    error_1[i] = libcrux_ml_kem_ind_cpa_encrypt_c1_call_mut_dd_85(&lvalue, i);
 7545|  1.63k|  }
 7546|    546|  uint8_t domain_separator = libcrux_ml_kem_ind_cpa_sample_ring_element_cbd_3b(
 7547|    546|      prf_input, domain_separator0, error_1);
 7548|    546|  prf_input[32U] = domain_separator;
 7549|    546|  uint8_t prf_output[128U];
 7550|    546|  libcrux_ml_kem_hash_functions_portable_PRF_4a_410(
 7551|    546|      Eurydice_array_to_slice((size_t)33U, prf_input, uint8_t), prf_output);
  ------------------
  |  |  204|    546|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    546|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    546|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    546|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7552|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d error_2 =
 7553|    546|      libcrux_ml_kem_sampling_sample_from_binomial_distribution_a0(
 7554|    546|          Eurydice_array_to_slice((size_t)128U, prf_output, uint8_t));
  ------------------
  |  |  204|    546|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    546|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    546|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    546|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7555|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d u[3U];
 7556|    546|  libcrux_ml_kem_matrix_compute_vector_u_1b(matrix, r_as_ntt, error_1, u);
 7557|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0[3U];
 7558|    546|  memcpy(
 7559|    546|      uu____0, u,
 7560|    546|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 7561|    546|  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|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d copy_of_r_as_ntt[3U];
 7564|    546|  memcpy(
 7565|    546|      copy_of_r_as_ntt, r_as_ntt,
 7566|    546|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 7567|    546|  tuple_ed lit;
 7568|    546|  memcpy(
 7569|    546|      lit.fst, copy_of_r_as_ntt,
 7570|    546|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 7571|    546|  lit.snd = error_2;
 7572|    546|  return lit;
 7573|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_into_padded_array_c8:
  884|    819|    Eurydice_slice slice, uint8_t ret[33U]) {
  885|    819|  uint8_t out[33U] = {0U};
  886|    819|  uint8_t *uu____0 = out;
  887|    819|  Eurydice_slice_copy(
  ------------------
  |  |  229|    819|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
  888|    819|      Eurydice_array_to_subslice3(
  889|    819|          uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *),
  890|    819|      slice, uint8_t);
  891|    819|  memcpy(ret, out, (size_t)33U * sizeof(uint8_t));
  892|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_encrypt_c1_call_mut_f1_85:
 6968|  1.63k|libcrux_ml_kem_ind_cpa_encrypt_c1_call_mut_f1_85(void **_, size_t tupled_args) {
 6969|  1.63k|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 6970|  1.63k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_sample_vector_cbd_then_ntt_3b:
 7177|  1.09k|    uint8_t *prf_input, uint8_t domain_separator) {
 7178|  1.09k|  uint8_t prf_inputs[3U][33U];
 7179|  4.36k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7179:31): [True: 3.27k, False: 1.09k]
  ------------------
 7180|  3.27k|    core_array__core__clone__Clone_for__Array_T__N___clone(
  ------------------
  |  |  236|  3.27k|  (memcpy(dst, src, len * sizeof(elem_type)))
  ------------------
 7181|  3.27k|        (size_t)33U, prf_input, prf_inputs[i], uint8_t, void *);
 7182|  3.27k|  }
 7183|  1.09k|  domain_separator =
 7184|  1.09k|      libcrux_ml_kem_utils_prf_input_inc_e0(prf_inputs, domain_separator);
 7185|  1.09k|  uint8_t prf_outputs[3U][128U];
 7186|  1.09k|  libcrux_ml_kem_hash_functions_portable_PRFxN_4a_41(prf_inputs, prf_outputs);
 7187|  4.36k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7187:31): [True: 3.27k, False: 1.09k]
  ------------------
 7188|  3.27k|    size_t i0 = i;
 7189|  3.27k|    re_as_ntt[i0] =
 7190|  3.27k|        libcrux_ml_kem_sampling_sample_from_binomial_distribution_a0(
 7191|  3.27k|            Eurydice_array_to_slice((size_t)128U, prf_outputs[i0], uint8_t));
  ------------------
  |  |  204|  3.27k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  3.27k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  3.27k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  3.27k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7192|  3.27k|    libcrux_ml_kem_ntt_ntt_binomially_sampled_ring_element_ea(&re_as_ntt[i0]);
 7193|  3.27k|  }
 7194|  1.09k|  return domain_separator;
 7195|  1.09k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_prf_input_inc_e0:
  866|  1.63k|    uint8_t (*prf_inputs)[33U], uint8_t domain_separator) {
  867|  6.55k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (867:31): [True: 4.91k, False: 1.63k]
  ------------------
  868|  4.91k|    size_t i0 = i;
  869|  4.91k|    prf_inputs[i0][32U] = domain_separator;
  870|  4.91k|    domain_separator = (uint32_t)domain_separator + 1U;
  871|  4.91k|  }
  872|  1.63k|  return domain_separator;
  873|  1.63k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRFxN_4a_41:
 7001|  1.63k|    uint8_t (*input)[33U], uint8_t ret[3U][128U]) {
 7002|  1.63k|  libcrux_ml_kem_hash_functions_portable_PRFxN_41(input, ret);
 7003|  1.63k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRFxN_41:
 6979|  1.63k|    uint8_t (*input)[33U], uint8_t ret[3U][128U]) {
 6980|  1.63k|  uint8_t out[3U][128U] = {{0U}};
 6981|  6.55k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6981:31): [True: 4.91k, False: 1.63k]
  ------------------
 6982|  4.91k|    size_t i0 = i;
 6983|  4.91k|    libcrux_sha3_portable_shake256(
 6984|  4.91k|        Eurydice_array_to_slice((size_t)128U, out[i0], uint8_t),
  ------------------
  |  |  204|  4.91k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  4.91k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  4.91k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  4.91k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6985|  4.91k|        Eurydice_array_to_slice((size_t)33U, input[i0], uint8_t));
  ------------------
  |  |  204|  4.91k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  4.91k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  4.91k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  4.91k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6986|  4.91k|  }
 6987|  1.63k|  memcpy(ret, out, (size_t)3U * sizeof(uint8_t[128U]));
 6988|  1.63k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_binomially_sampled_ring_element_ea:
 7143|  3.27k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 7144|  3.27k|  libcrux_ml_kem_ntt_ntt_at_layer_7_ea(re);
 7145|  3.27k|  size_t zeta_i = (size_t)1U;
 7146|  3.27k|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)6U,
 7147|  3.27k|                                            (size_t)11207U);
 7148|  3.27k|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)5U,
 7149|  3.27k|                                            (size_t)11207U + (size_t)3328U);
 7150|  3.27k|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(
 7151|  3.27k|      &zeta_i, re, (size_t)4U, (size_t)11207U + (size_t)2U * (size_t)3328U);
 7152|  3.27k|  libcrux_ml_kem_ntt_ntt_at_layer_3_ea(
 7153|  3.27k|      &zeta_i, re, (size_t)11207U + (size_t)3U * (size_t)3328U);
 7154|  3.27k|  libcrux_ml_kem_ntt_ntt_at_layer_2_ea(
 7155|  3.27k|      &zeta_i, re, (size_t)11207U + (size_t)4U * (size_t)3328U);
 7156|  3.27k|  libcrux_ml_kem_ntt_ntt_at_layer_1_ea(
 7157|  3.27k|      &zeta_i, re, (size_t)11207U + (size_t)5U * (size_t)3328U);
 7158|  3.27k|  libcrux_ml_kem_polynomial_poly_barrett_reduce_d6_ea(re);
 7159|  3.27k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_7_ea:
 7120|  3.27k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 7121|  3.27k|  size_t step = LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT / (size_t)2U;
  ------------------
  |  | 3770|  3.27k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
 7122|  29.4k|  for (size_t i = (size_t)0U; i < step; i++) {
  ------------------
  |  Branch (7122:31): [True: 26.2k, False: 3.27k]
  ------------------
 7123|  26.2k|    size_t j = i;
 7124|  26.2k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector t =
 7125|  26.2k|        libcrux_ml_kem_vector_portable_multiply_by_constant_b8(
 7126|  26.2k|            re->coefficients[j + step], (int16_t)-1600);
 7127|  26.2k|    re->coefficients[j + step] =
 7128|  26.2k|        libcrux_ml_kem_vector_portable_sub_b8(re->coefficients[j], &t);
 7129|  26.2k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____1 =
 7130|  26.2k|        libcrux_ml_kem_vector_portable_add_b8(re->coefficients[j], &t);
 7131|  26.2k|    re->coefficients[j] = uu____1;
 7132|  26.2k|  }
 7133|  3.27k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_multiply_by_constant_b8:
 3906|  26.2k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec, int16_t c) {
 3907|  26.2k|  return libcrux_ml_kem_vector_portable_arithmetic_multiply_by_constant(vec, c);
 3908|  26.2k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_multiply_by_constant:
 3890|  26.2k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec, int16_t c) {
 3891|  26.2k|  for (size_t i = (size_t)0U;
 3892|   445k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   445k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3892:8): [True: 419k, False: 26.2k]
  ------------------
 3893|   419k|    size_t i0 = i;
 3894|   419k|    size_t uu____0 = i0;
 3895|   419k|    vec.elements[uu____0] = vec.elements[uu____0] * c;
 3896|   419k|  }
 3897|  26.2k|  return vec;
 3898|  26.2k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_encrypt_c1_call_mut_dd_85:
 7220|  1.63k|libcrux_ml_kem_ind_cpa_encrypt_c1_call_mut_dd_85(void **_, size_t tupled_args) {
 7221|  1.63k|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 7222|  1.63k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_sample_ring_element_cbd_3b:
 7239|    546|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error_1) {
 7240|    546|  uint8_t prf_inputs[3U][33U];
 7241|  2.18k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7241:31): [True: 1.63k, False: 546]
  ------------------
 7242|  1.63k|    core_array__core__clone__Clone_for__Array_T__N___clone(
  ------------------
  |  |  236|  1.63k|  (memcpy(dst, src, len * sizeof(elem_type)))
  ------------------
 7243|  1.63k|        (size_t)33U, prf_input, prf_inputs[i], uint8_t, void *);
 7244|  1.63k|  }
 7245|    546|  domain_separator =
 7246|    546|      libcrux_ml_kem_utils_prf_input_inc_e0(prf_inputs, domain_separator);
 7247|    546|  uint8_t prf_outputs[3U][128U];
 7248|    546|  libcrux_ml_kem_hash_functions_portable_PRFxN_4a_41(prf_inputs, prf_outputs);
 7249|  2.18k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7249:31): [True: 1.63k, False: 546]
  ------------------
 7250|  1.63k|    size_t i0 = i;
 7251|  1.63k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0 =
 7252|  1.63k|        libcrux_ml_kem_sampling_sample_from_binomial_distribution_a0(
 7253|  1.63k|            Eurydice_array_to_slice((size_t)128U, prf_outputs[i0], uint8_t));
  ------------------
  |  |  204|  1.63k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  1.63k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.63k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  1.63k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7254|  1.63k|    error_1[i0] = uu____0;
 7255|  1.63k|  }
 7256|    546|  return domain_separator;
 7257|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRF_4a_410:
 7283|    546|    Eurydice_slice input, uint8_t ret[128U]) {
 7284|    546|  libcrux_ml_kem_hash_functions_portable_PRF_a6(input, ret);
 7285|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRF_a6:
 7265|    546|    Eurydice_slice input, uint8_t ret[128U]) {
 7266|    546|  uint8_t digest[128U] = {0U};
 7267|    546|  libcrux_sha3_portable_shake256(
 7268|    546|      Eurydice_array_to_slice((size_t)128U, digest, uint8_t), input);
  ------------------
  |  |  204|    546|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    546|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    546|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    546|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7269|    546|  memcpy(ret, digest, (size_t)128U * sizeof(uint8_t));
 7270|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_binomial_distribution_a0:
 7108|  5.46k|    Eurydice_slice randomness) {
 7109|  5.46k|  return libcrux_ml_kem_sampling_sample_from_binomial_distribution_2_ea(
 7110|  5.46k|      randomness);
 7111|  5.46k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_binomial_distribution_2_ea:
 7062|  5.46k|    Eurydice_slice randomness) {
 7063|  5.46k|  int16_t sampled_i16s[256U] = {0U};
 7064|  5.46k|  for (size_t i0 = (size_t)0U;
 7065|   180k|       i0 < Eurydice_slice_len(randomness, uint8_t) / (size_t)4U; i0++) {
  ------------------
  |  |  173|   180k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (7065:8): [True: 174k, False: 5.46k]
  ------------------
 7066|   174k|    size_t chunk_number = i0;
 7067|   174k|    Eurydice_slice byte_chunk = Eurydice_slice_subslice3(
  ------------------
  |  |  195|   174k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|   174k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|   174k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7068|   174k|        randomness, chunk_number * (size_t)4U,
 7069|   174k|        chunk_number * (size_t)4U + (size_t)4U, uint8_t *);
 7070|   174k|    uint32_t random_bits_as_u32 =
 7071|   174k|        (((uint32_t)Eurydice_slice_index(byte_chunk, (size_t)0U, uint8_t,
  ------------------
  |  |  180|   174k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 7072|   174k|                                         uint8_t *) |
 7073|   174k|          (uint32_t)Eurydice_slice_index(byte_chunk, (size_t)1U, uint8_t,
  ------------------
  |  |  180|   174k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 7074|   174k|                                         uint8_t *)
 7075|   174k|              << 8U) |
 7076|   174k|         (uint32_t)Eurydice_slice_index(byte_chunk, (size_t)2U, uint8_t,
  ------------------
  |  |  180|   174k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 7077|   174k|                                        uint8_t *)
 7078|   174k|             << 16U) |
 7079|   174k|        (uint32_t)Eurydice_slice_index(byte_chunk, (size_t)3U, uint8_t,
  ------------------
  |  |  180|   174k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 7080|   174k|                                       uint8_t *)
 7081|   174k|            << 24U;
 7082|   174k|    uint32_t even_bits = random_bits_as_u32 & 1431655765U;
 7083|   174k|    uint32_t odd_bits = random_bits_as_u32 >> 1U & 1431655765U;
 7084|   174k|    uint32_t coin_toss_outcomes = even_bits + odd_bits;
 7085|  1.57M|    for (uint32_t i = 0U; i < 32U / 4U; i++) {
  ------------------
  |  Branch (7085:27): [True: 1.39M, False: 174k]
  ------------------
 7086|  1.39M|      uint32_t outcome_set = i;
 7087|  1.39M|      uint32_t outcome_set0 = outcome_set * 4U;
 7088|  1.39M|      int16_t outcome_1 =
 7089|  1.39M|          (int16_t)(coin_toss_outcomes >> (uint32_t)outcome_set0 & 3U);
 7090|  1.39M|      int16_t outcome_2 =
 7091|  1.39M|          (int16_t)(coin_toss_outcomes >> (uint32_t)(outcome_set0 + 2U) & 3U);
 7092|  1.39M|      size_t offset = (size_t)(outcome_set0 >> 2U);
 7093|  1.39M|      sampled_i16s[(size_t)8U * chunk_number + offset] = outcome_1 - outcome_2;
 7094|  1.39M|    }
 7095|   174k|  }
 7096|  5.46k|  return libcrux_ml_kem_polynomial_from_i16_array_d6_ea(
 7097|  5.46k|      Eurydice_array_to_slice((size_t)256U, sampled_i16s, int16_t));
  ------------------
  |  |  204|  5.46k|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|  5.46k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  5.46k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|  5.46k|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7098|  5.46k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_compute_vector_u_1b:
 7360|    546|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret[3U]) {
 7361|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d result[3U];
 7362|  2.18k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7362:31): [True: 1.63k, False: 546]
  ------------------
 7363|       |    /* original Rust expression is not an lvalue in C */
 7364|  1.63k|    void *lvalue = (void *)0U;
 7365|  1.63k|    result[i] =
 7366|  1.63k|        libcrux_ml_kem_matrix_compute_vector_u_call_mut_a8_1b(&lvalue, i);
 7367|  1.63k|  }
 7368|    546|  for (size_t i0 = (size_t)0U;
 7369|  2.18k|       i0 < Eurydice_slice_len(
  ------------------
  |  |  173|  2.18k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (7369:8): [True: 1.63k, False: 546]
  ------------------
 7370|    546|                Eurydice_array_to_slice(
 7371|    546|                    (size_t)3U, a_as_ntt,
 7372|    546|                    libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]),
 7373|    546|                libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]);
 7374|  1.63k|       i0++) {
 7375|  1.63k|    size_t i1 = i0;
 7376|  1.63k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *row = a_as_ntt[i1];
 7377|  1.63k|    for (size_t i = (size_t)0U;
 7378|  6.55k|         i < Eurydice_slice_len(
  ------------------
  |  |  173|  6.55k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (7378:10): [True: 4.91k, False: 1.63k]
  ------------------
 7379|  1.63k|                 Eurydice_array_to_slice(
 7380|  1.63k|                     (size_t)3U, row,
 7381|  1.63k|                     libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 7382|  1.63k|                 libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 7383|  4.91k|         i++) {
 7384|  4.91k|      size_t j = i;
 7385|  4.91k|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d *a_element = &row[j];
 7386|  4.91k|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d product =
 7387|  4.91k|          libcrux_ml_kem_polynomial_ntt_multiply_d6_ea(a_element, &r_as_ntt[j]);
 7388|  4.91k|      libcrux_ml_kem_polynomial_add_to_ring_element_d6_1b(&result[i1],
 7389|  4.91k|                                                          &product);
 7390|  4.91k|    }
 7391|  1.63k|    libcrux_ml_kem_invert_ntt_invert_ntt_montgomery_1b(&result[i1]);
 7392|  1.63k|    libcrux_ml_kem_polynomial_add_error_reduce_d6_ea(&result[i1], &error_1[i1]);
 7393|  1.63k|  }
 7394|    546|  memcpy(
 7395|    546|      ret, result,
 7396|    546|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 7397|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_compute_vector_u_call_mut_a8_1b:
 7301|  1.63k|                                                      size_t tupled_args) {
 7302|  1.63k|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 7303|  1.63k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_error_reduce_d6_ea:
 7343|  1.63k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error) {
 7344|  1.63k|  libcrux_ml_kem_polynomial_add_error_reduce_ea(self, error);
 7345|  1.63k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_error_reduce_ea:
 7313|  1.63k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error) {
 7314|  1.63k|  for (size_t i = (size_t)0U;
 7315|  27.8k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  27.8k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (7315:8): [True: 26.2k, False: 1.63k]
  ------------------
 7316|  26.2k|    size_t j = i;
 7317|  26.2k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 7318|  26.2k|        coefficient_normal_form =
 7319|  26.2k|            libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(
 7320|  26.2k|                myself->coefficients[j], (int16_t)1441);
 7321|  26.2k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector sum =
 7322|  26.2k|        libcrux_ml_kem_vector_portable_add_b8(coefficient_normal_form,
 7323|  26.2k|                                              &error->coefficients[j]);
 7324|  26.2k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector red =
 7325|  26.2k|        libcrux_ml_kem_vector_portable_barrett_reduce_b8(sum);
 7326|  26.2k|    myself->coefficients[j] = red;
 7327|  26.2k|  }
 7328|  1.63k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_compress_then_serialize_u_43:
 7490|    546|    Eurydice_slice out) {
 7491|    546|  for (size_t i = (size_t)0U;
 7492|  2.18k|       i < Eurydice_slice_len(
  ------------------
  |  |  173|  2.18k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (7492:8): [True: 1.63k, False: 546]
  ------------------
 7493|    546|               Eurydice_array_to_slice(
 7494|    546|                   (size_t)3U, input,
 7495|    546|                   libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 7496|    546|               libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 7497|  1.63k|       i++) {
 7498|  1.63k|    size_t i0 = i;
 7499|  1.63k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d re = input[i0];
 7500|  1.63k|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  1.63k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  1.63k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  1.63k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7501|  1.63k|        out, i0 * ((size_t)960U / (size_t)3U),
 7502|  1.63k|        (i0 + (size_t)1U) * ((size_t)960U / (size_t)3U), uint8_t *);
 7503|  1.63k|    uint8_t ret[320U];
 7504|  1.63k|    libcrux_ml_kem_serialize_compress_then_serialize_ring_element_u_fe(&re,
 7505|  1.63k|                                                                       ret);
 7506|  1.63k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  1.63k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 7507|  1.63k|        uu____0, Eurydice_array_to_slice((size_t)320U, ret, uint8_t), uint8_t);
 7508|  1.63k|  }
 7509|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_compress_then_serialize_ring_element_u_fe:
 7470|  1.63k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re, uint8_t ret[320U]) {
 7471|  1.63k|  uint8_t uu____0[320U];
 7472|  1.63k|  libcrux_ml_kem_serialize_compress_then_serialize_10_ff(re, uu____0);
 7473|  1.63k|  memcpy(ret, uu____0, (size_t)320U * sizeof(uint8_t));
 7474|  1.63k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_compress_then_serialize_10_ff:
 7442|  1.63k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re, uint8_t ret[320U]) {
 7443|  1.63k|  uint8_t serialized[320U] = {0U};
 7444|  1.63k|  for (size_t i = (size_t)0U;
 7445|  27.8k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  27.8k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (7445:8): [True: 26.2k, False: 1.63k]
  ------------------
 7446|  26.2k|    size_t i0 = i;
 7447|  26.2k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 7448|  26.2k|        libcrux_ml_kem_vector_portable_compress_b8_ef(
 7449|  26.2k|            libcrux_ml_kem_serialize_to_unsigned_field_modulus_ea(
 7450|  26.2k|                re->coefficients[i0]));
 7451|  26.2k|    uint8_t bytes[20U];
 7452|  26.2k|    libcrux_ml_kem_vector_portable_serialize_10_b8(coefficient, bytes);
 7453|  26.2k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  26.2k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 7454|  26.2k|        Eurydice_array_to_subslice3(serialized, (size_t)20U * i0,
 7455|  26.2k|                                    (size_t)20U * i0 + (size_t)20U, uint8_t *),
 7456|  26.2k|        Eurydice_array_to_slice((size_t)20U, bytes, uint8_t), uint8_t);
 7457|  26.2k|  }
 7458|  1.63k|  memcpy(ret, serialized, (size_t)320U * sizeof(uint8_t));
 7459|  1.63k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_b8_ef:
 7430|  26.2k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 7431|  26.2k|  return libcrux_ml_kem_vector_portable_compress_compress_ef(a);
 7432|  26.2k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_compress_ef:
 7406|  26.2k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 7407|  26.2k|  for (size_t i = (size_t)0U;
 7408|   445k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   445k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (7408:8): [True: 419k, False: 26.2k]
  ------------------
 7409|   419k|    size_t i0 = i;
 7410|   419k|    int16_t uu____0 = libcrux_secrets_int_as_i16_f5(
 7411|   419k|        libcrux_ml_kem_vector_portable_compress_compress_ciphertext_coefficient(
 7412|   419k|            (uint8_t)(int32_t)10,
 7413|   419k|            libcrux_secrets_int_as_u16_f5(a.elements[i0])));
 7414|   419k|    a.elements[i0] = uu____0;
 7415|   419k|  }
 7416|  26.2k|  return a;
 7417|  26.2k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_compress_ciphertext_coefficient:
 4199|   559k|    uint8_t coefficient_bits, uint16_t fe) {
 4200|   559k|  uint64_t compressed = libcrux_secrets_int_as_u64_ca(fe)
 4201|   559k|                        << (uint32_t)coefficient_bits;
 4202|   559k|  compressed = compressed + 1664ULL;
 4203|   559k|  compressed = compressed * 10321340ULL;
 4204|   559k|  compressed = compressed >> 35U;
 4205|   559k|  return libcrux_secrets_int_as_i16_b8(
 4206|   559k|      libcrux_ml_kem_vector_portable_arithmetic_get_n_least_significant_bits(
 4207|   559k|          coefficient_bits, libcrux_secrets_int_as_u32_a3(compressed)));
 4208|   559k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_u64_ca:
  661|   559k|static KRML_MUSTINLINE uint64_t libcrux_secrets_int_as_u64_ca(uint16_t self) {
  662|   559k|  return libcrux_secrets_int_public_integers_classify_27_49(
  663|   559k|      (uint64_t)libcrux_secrets_int_public_integers_declassify_d8_de(self));
  664|   559k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_49:
  654|   559k|libcrux_secrets_int_public_integers_classify_27_49(uint64_t self) {
  655|   559k|  return self;
  656|   559k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i16_b8:
  703|   559k|static KRML_MUSTINLINE int16_t libcrux_secrets_int_as_i16_b8(uint32_t self) {
  704|   559k|  return libcrux_secrets_int_public_integers_classify_27_39(
  705|   559k|      (int16_t)libcrux_secrets_int_public_integers_declassify_d8_df(self));
  706|   559k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_get_n_least_significant_bits:
 4193|   559k|    uint8_t n, uint32_t value) {
 4194|   559k|  return value & ((1U << (uint32_t)n) - 1U);
 4195|   559k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_u32_a3:
  695|   559k|static KRML_MUSTINLINE uint32_t libcrux_secrets_int_as_u32_a3(uint64_t self) {
  696|   559k|  return libcrux_secrets_int_public_integers_classify_27_df(
  697|   559k|      (uint32_t)libcrux_secrets_int_public_integers_declassify_d8_49(self));
  698|   559k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_49:
  688|   559k|libcrux_secrets_int_public_integers_declassify_d8_49(uint64_t self) {
  689|   559k|  return self;
  690|   559k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_10_b8:
 4920|  26.2k|    uint8_t ret[20U]) {
 4921|  26.2k|  libcrux_ml_kem_vector_portable_serialize_10(a, ret);
 4922|  26.2k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_10:
 4908|  26.2k|    uint8_t ret[20U]) {
 4909|  26.2k|  uint8_t ret0[20U];
 4910|  26.2k|  libcrux_ml_kem_vector_portable_serialize_serialize_10(a, ret0);
 4911|  26.2k|  libcrux_secrets_int_public_integers_declassify_d8_57(ret0, ret);
 4912|  26.2k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_10:
 4871|  26.2k|    uint8_t ret[20U]) {
 4872|  26.2k|  uint8_t_x5 r0_4 = libcrux_ml_kem_vector_portable_serialize_serialize_10_int(
 4873|  26.2k|      Eurydice_array_to_subslice3(v.elements, (size_t)0U, (size_t)4U,
  ------------------
  |  |  215|  26.2k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  26.2k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  26.2k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4874|  26.2k|                                  int16_t *));
 4875|  26.2k|  uint8_t_x5 r5_9 = libcrux_ml_kem_vector_portable_serialize_serialize_10_int(
 4876|  26.2k|      Eurydice_array_to_subslice3(v.elements, (size_t)4U, (size_t)8U,
  ------------------
  |  |  215|  26.2k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  26.2k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  26.2k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4877|  26.2k|                                  int16_t *));
 4878|  26.2k|  uint8_t_x5 r10_14 = libcrux_ml_kem_vector_portable_serialize_serialize_10_int(
 4879|  26.2k|      Eurydice_array_to_subslice3(v.elements, (size_t)8U, (size_t)12U,
  ------------------
  |  |  215|  26.2k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  26.2k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  26.2k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4880|  26.2k|                                  int16_t *));
 4881|  26.2k|  uint8_t_x5 r15_19 = libcrux_ml_kem_vector_portable_serialize_serialize_10_int(
 4882|  26.2k|      Eurydice_array_to_subslice3(v.elements, (size_t)12U, (size_t)16U,
  ------------------
  |  |  215|  26.2k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  26.2k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  26.2k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4883|  26.2k|                                  int16_t *));
 4884|  26.2k|  ret[0U] = r0_4.fst;
 4885|  26.2k|  ret[1U] = r0_4.snd;
 4886|  26.2k|  ret[2U] = r0_4.thd;
 4887|  26.2k|  ret[3U] = r0_4.f3;
 4888|  26.2k|  ret[4U] = r0_4.f4;
 4889|  26.2k|  ret[5U] = r5_9.fst;
 4890|  26.2k|  ret[6U] = r5_9.snd;
 4891|  26.2k|  ret[7U] = r5_9.thd;
 4892|  26.2k|  ret[8U] = r5_9.f3;
 4893|  26.2k|  ret[9U] = r5_9.f4;
 4894|  26.2k|  ret[10U] = r10_14.fst;
 4895|  26.2k|  ret[11U] = r10_14.snd;
 4896|  26.2k|  ret[12U] = r10_14.thd;
 4897|  26.2k|  ret[13U] = r10_14.f3;
 4898|  26.2k|  ret[14U] = r10_14.f4;
 4899|  26.2k|  ret[15U] = r15_19.fst;
 4900|  26.2k|  ret[16U] = r15_19.snd;
 4901|  26.2k|  ret[17U] = r15_19.thd;
 4902|  26.2k|  ret[18U] = r15_19.f3;
 4903|  26.2k|  ret[19U] = r15_19.f4;
 4904|  26.2k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_10_int:
 4837|   104k|libcrux_ml_kem_vector_portable_serialize_serialize_10_int(Eurydice_slice v) {
 4838|   104k|  uint8_t r0 = libcrux_secrets_int_as_u8_f5(
 4839|   104k|      Eurydice_slice_index(v, (size_t)0U, int16_t, int16_t *) & (int16_t)255);
  ------------------
  |  |  180|   104k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4840|   104k|  uint8_t r1 =
 4841|   104k|      (uint32_t)libcrux_secrets_int_as_u8_f5(
 4842|   104k|          Eurydice_slice_index(v, (size_t)1U, int16_t, int16_t *) & (int16_t)63)
  ------------------
  |  |  180|   104k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4843|   104k|          << 2U |
 4844|   104k|      (uint32_t)libcrux_secrets_int_as_u8_f5(
 4845|   104k|          Eurydice_slice_index(v, (size_t)0U, int16_t, int16_t *) >> 8U &
  ------------------
  |  |  180|   104k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4846|   104k|          (int16_t)3);
 4847|   104k|  uint8_t r2 =
 4848|   104k|      (uint32_t)libcrux_secrets_int_as_u8_f5(
 4849|   104k|          Eurydice_slice_index(v, (size_t)2U, int16_t, int16_t *) & (int16_t)15)
  ------------------
  |  |  180|   104k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4850|   104k|          << 4U |
 4851|   104k|      (uint32_t)libcrux_secrets_int_as_u8_f5(
 4852|   104k|          Eurydice_slice_index(v, (size_t)1U, int16_t, int16_t *) >> 6U &
  ------------------
  |  |  180|   104k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4853|   104k|          (int16_t)15);
 4854|   104k|  uint8_t r3 =
 4855|   104k|      (uint32_t)libcrux_secrets_int_as_u8_f5(
 4856|   104k|          Eurydice_slice_index(v, (size_t)3U, int16_t, int16_t *) & (int16_t)3)
  ------------------
  |  |  180|   104k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4857|   104k|          << 6U |
 4858|   104k|      (uint32_t)libcrux_secrets_int_as_u8_f5(
 4859|   104k|          Eurydice_slice_index(v, (size_t)2U, int16_t, int16_t *) >> 4U &
  ------------------
  |  |  180|   104k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4860|   104k|          (int16_t)63);
 4861|   104k|  uint8_t r4 = libcrux_secrets_int_as_u8_f5(
 4862|   104k|      Eurydice_slice_index(v, (size_t)3U, int16_t, int16_t *) >> 2U &
  ------------------
  |  |  180|   104k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4863|   104k|      (int16_t)255);
 4864|   104k|  return (KRML_CLITERAL(uint8_t_x5){
  ------------------
  |  |  154|   104k|#define KRML_CLITERAL(type) (type)
  ------------------
 4865|   104k|      .fst = r0, .snd = r1, .thd = r2, .f3 = r3, .f4 = r4});
 4866|   104k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_57:
 1034|  26.2k|                                                     uint8_t ret[20U]) {
 1035|  26.2k|  memcpy(ret, self, (size_t)20U * sizeof(uint8_t));
 1036|  26.2k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_encrypt_c2_6c:
 7767|    546|    uint8_t *message, Eurydice_slice ciphertext) {
 7768|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d message_as_ring_element =
 7769|    546|      libcrux_ml_kem_serialize_deserialize_then_decompress_message_ea(message);
 7770|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d v =
 7771|    546|      libcrux_ml_kem_matrix_compute_ring_element_v_1b(
 7772|    546|          t_as_ntt, r_as_ntt, error_2, &message_as_ring_element);
 7773|    546|  libcrux_ml_kem_serialize_compress_then_serialize_ring_element_v_6c(
 7774|    546|      v, ciphertext);
 7775|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_then_decompress_message_ea:
 7583|    546|    uint8_t *serialized) {
 7584|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d re =
 7585|    546|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 7586|  9.28k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (7586:31): [True: 8.73k, False: 546]
  ------------------
 7587|  8.73k|    size_t i0 = i;
 7588|  8.73k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 7589|  8.73k|        coefficient_compressed =
 7590|  8.73k|            libcrux_ml_kem_vector_portable_deserialize_1_b8(
 7591|  8.73k|                Eurydice_array_to_subslice3(serialized, (size_t)2U * i0,
  ------------------
  |  |  215|  8.73k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  8.73k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  8.73k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7592|  8.73k|                                            (size_t)2U * i0 + (size_t)2U,
 7593|  8.73k|                                            uint8_t *));
 7594|  8.73k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 7595|  8.73k|        libcrux_ml_kem_vector_portable_decompress_1_b8(coefficient_compressed);
 7596|  8.73k|    re.coefficients[i0] = uu____0;
 7597|  8.73k|  }
 7598|    546|  return re;
 7599|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_1_b8:
 4682|  8.73k|libcrux_ml_kem_vector_portable_deserialize_1_b8(Eurydice_slice a) {
 4683|  8.73k|  return libcrux_ml_kem_vector_portable_deserialize_1(a);
 4684|  8.73k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_deserialize_1:
 4672|  8.73k|libcrux_ml_kem_vector_portable_deserialize_1(Eurydice_slice a) {
 4673|  8.73k|  return libcrux_ml_kem_vector_portable_serialize_deserialize_1(
 4674|  8.73k|      libcrux_secrets_int_classify_public_classify_ref_9b_90(a));
 4675|  8.73k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_deserialize_1:
 4617|  8.73k|libcrux_ml_kem_vector_portable_serialize_deserialize_1(Eurydice_slice v) {
 4618|  8.73k|  int16_t result0 = libcrux_secrets_int_as_i16_59(
 4619|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) & 1U);
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4620|  8.73k|  int16_t result1 = libcrux_secrets_int_as_i16_59(
 4621|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 1U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4622|  8.73k|      1U);
 4623|  8.73k|  int16_t result2 = libcrux_secrets_int_as_i16_59(
 4624|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 2U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4625|  8.73k|      1U);
 4626|  8.73k|  int16_t result3 = libcrux_secrets_int_as_i16_59(
 4627|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 3U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4628|  8.73k|      1U);
 4629|  8.73k|  int16_t result4 = libcrux_secrets_int_as_i16_59(
 4630|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 4U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4631|  8.73k|      1U);
 4632|  8.73k|  int16_t result5 = libcrux_secrets_int_as_i16_59(
 4633|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 5U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4634|  8.73k|      1U);
 4635|  8.73k|  int16_t result6 = libcrux_secrets_int_as_i16_59(
 4636|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 6U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4637|  8.73k|      1U);
 4638|  8.73k|  int16_t result7 = libcrux_secrets_int_as_i16_59(
 4639|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)0U, uint8_t, uint8_t *) >> 7U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4640|  8.73k|      1U);
 4641|  8.73k|  int16_t result8 = libcrux_secrets_int_as_i16_59(
 4642|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) & 1U);
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4643|  8.73k|  int16_t result9 = libcrux_secrets_int_as_i16_59(
 4644|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 1U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4645|  8.73k|      1U);
 4646|  8.73k|  int16_t result10 = libcrux_secrets_int_as_i16_59(
 4647|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 2U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4648|  8.73k|      1U);
 4649|  8.73k|  int16_t result11 = libcrux_secrets_int_as_i16_59(
 4650|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 3U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4651|  8.73k|      1U);
 4652|  8.73k|  int16_t result12 = libcrux_secrets_int_as_i16_59(
 4653|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 4U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4654|  8.73k|      1U);
 4655|  8.73k|  int16_t result13 = libcrux_secrets_int_as_i16_59(
 4656|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 5U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4657|  8.73k|      1U);
 4658|  8.73k|  int16_t result14 = libcrux_secrets_int_as_i16_59(
 4659|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 6U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4660|  8.73k|      1U);
 4661|  8.73k|  int16_t result15 = libcrux_secrets_int_as_i16_59(
 4662|  8.73k|      (uint32_t)Eurydice_slice_index(v, (size_t)1U, uint8_t, uint8_t *) >> 7U &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4663|  8.73k|      1U);
 4664|  8.73k|  return (
 4665|  8.73k|      KRML_CLITERAL(libcrux_ml_kem_vector_portable_vector_type_PortableVector){
  ------------------
  |  |  154|  8.73k|#define KRML_CLITERAL(type) (type)
  ------------------
 4666|  8.73k|          .elements = {result0, result1, result2, result3, result4, result5,
 4667|  8.73k|                       result6, result7, result8, result9, result10, result11,
 4668|  8.73k|                       result12, result13, result14, result15}});
 4669|  8.73k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_decompress_1_b8:
 4229|  8.73k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4230|  8.73k|  return libcrux_ml_kem_vector_portable_compress_decompress_1(a);
 4231|  8.73k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_decompress_1:
 4212|  8.73k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4213|  8.73k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector z =
 4214|  8.73k|      libcrux_ml_kem_vector_portable_vector_type_zero();
 4215|  8.73k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector s =
 4216|  8.73k|      libcrux_ml_kem_vector_portable_arithmetic_sub(z, &a);
 4217|  8.73k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector res =
 4218|  8.73k|      libcrux_ml_kem_vector_portable_arithmetic_bitwise_and_with_constant(
 4219|  8.73k|          s, (int16_t)1665);
 4220|  8.73k|  return res;
 4221|  8.73k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_compute_ring_element_v_1b:
 7665|    546|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *message) {
 7666|    546|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d result =
 7667|    546|      libcrux_ml_kem_polynomial_ZERO_d6_ea();
 7668|  2.18k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7668:31): [True: 1.63k, False: 546]
  ------------------
 7669|  1.63k|    size_t i0 = i;
 7670|  1.63k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d product =
 7671|  1.63k|        libcrux_ml_kem_polynomial_ntt_multiply_d6_ea(&t_as_ntt[i0],
 7672|  1.63k|                                                     &r_as_ntt[i0]);
 7673|  1.63k|    libcrux_ml_kem_polynomial_add_to_ring_element_d6_1b(&result, &product);
 7674|  1.63k|  }
 7675|    546|  libcrux_ml_kem_invert_ntt_invert_ntt_montgomery_1b(&result);
 7676|    546|  return libcrux_ml_kem_polynomial_add_message_error_reduce_d6_ea(
 7677|    546|      error_2, message, result);
 7678|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_message_error_reduce_d6_ea:
 7646|    546|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d result) {
 7647|    546|  return libcrux_ml_kem_polynomial_add_message_error_reduce_ea(self, message,
 7648|    546|                                                               result);
 7649|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_message_error_reduce_ea:
 7611|    546|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d result) {
 7612|    546|  for (size_t i = (size_t)0U;
 7613|  9.28k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  9.28k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (7613:8): [True: 8.73k, False: 546]
  ------------------
 7614|  8.73k|    size_t i0 = i;
 7615|  8.73k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 7616|  8.73k|        coefficient_normal_form =
 7617|  8.73k|            libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(
 7618|  8.73k|                result.coefficients[i0], (int16_t)1441);
 7619|  8.73k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector sum1 =
 7620|  8.73k|        libcrux_ml_kem_vector_portable_add_b8(myself->coefficients[i0],
 7621|  8.73k|                                              &message->coefficients[i0]);
 7622|  8.73k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector sum2 =
 7623|  8.73k|        libcrux_ml_kem_vector_portable_add_b8(coefficient_normal_form, &sum1);
 7624|  8.73k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector red =
 7625|  8.73k|        libcrux_ml_kem_vector_portable_barrett_reduce_b8(sum2);
 7626|  8.73k|    result.coefficients[i0] = red;
 7627|  8.73k|  }
 7628|    546|  return result;
 7629|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_compress_then_serialize_ring_element_v_6c:
 7751|    546|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d re, Eurydice_slice out) {
 7752|    546|  libcrux_ml_kem_serialize_compress_then_serialize_4_ea(re, out);
 7753|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_compress_then_serialize_4_ea:
 7724|    546|    Eurydice_slice serialized) {
 7725|    546|  for (size_t i = (size_t)0U;
 7726|  9.28k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  9.28k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (7726:8): [True: 8.73k, False: 546]
  ------------------
 7727|  8.73k|    size_t i0 = i;
 7728|  8.73k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 7729|  8.73k|        libcrux_ml_kem_vector_portable_compress_b8_d1(
 7730|  8.73k|            libcrux_ml_kem_serialize_to_unsigned_field_modulus_ea(
 7731|  8.73k|                re.coefficients[i0]));
 7732|  8.73k|    uint8_t bytes[8U];
 7733|  8.73k|    libcrux_ml_kem_vector_portable_serialize_4_b8(coefficient, bytes);
 7734|  8.73k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  8.73k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 7735|  8.73k|        Eurydice_slice_subslice3(serialized, (size_t)8U * i0,
 7736|  8.73k|                                 (size_t)8U * i0 + (size_t)8U, uint8_t *),
 7737|  8.73k|        Eurydice_array_to_slice((size_t)8U, bytes, uint8_t), uint8_t);
 7738|  8.73k|  }
 7739|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_b8_d1:
 7711|  8.73k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 7712|  8.73k|  return libcrux_ml_kem_vector_portable_compress_compress_d1(a);
 7713|  8.73k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_compress_compress_d1:
 7687|  8.73k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 7688|  8.73k|  for (size_t i = (size_t)0U;
 7689|   148k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   148k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (7689:8): [True: 139k, False: 8.73k]
  ------------------
 7690|   139k|    size_t i0 = i;
 7691|   139k|    int16_t uu____0 = libcrux_secrets_int_as_i16_f5(
 7692|   139k|        libcrux_ml_kem_vector_portable_compress_compress_ciphertext_coefficient(
 7693|   139k|            (uint8_t)(int32_t)4,
 7694|   139k|            libcrux_secrets_int_as_u16_f5(a.elements[i0])));
 7695|   139k|    a.elements[i0] = uu____0;
 7696|   139k|  }
 7697|  8.73k|  return a;
 7698|  8.73k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_4_b8:
 4755|  8.73k|    uint8_t ret[8U]) {
 4756|  8.73k|  libcrux_ml_kem_vector_portable_serialize_4(a, ret);
 4757|  8.73k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_4:
 4743|  8.73k|    uint8_t ret[8U]) {
 4744|  8.73k|  uint8_t ret0[8U];
 4745|  8.73k|  libcrux_ml_kem_vector_portable_serialize_serialize_4(a, ret0);
 4746|  8.73k|  libcrux_secrets_int_public_integers_declassify_d8_76(ret0, ret);
 4747|  8.73k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_4:
 4722|  8.73k|    uint8_t ret[8U]) {
 4723|  8.73k|  uint8_t_x4 result0_3 =
 4724|  8.73k|      libcrux_ml_kem_vector_portable_serialize_serialize_4_int(
 4725|  8.73k|          Eurydice_array_to_subslice3(v.elements, (size_t)0U, (size_t)8U,
  ------------------
  |  |  215|  8.73k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  8.73k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  8.73k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4726|  8.73k|                                      int16_t *));
 4727|  8.73k|  uint8_t_x4 result4_7 =
 4728|  8.73k|      libcrux_ml_kem_vector_portable_serialize_serialize_4_int(
 4729|  8.73k|          Eurydice_array_to_subslice3(v.elements, (size_t)8U, (size_t)16U,
  ------------------
  |  |  215|  8.73k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  8.73k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  8.73k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4730|  8.73k|                                      int16_t *));
 4731|  8.73k|  ret[0U] = result0_3.fst;
 4732|  8.73k|  ret[1U] = result0_3.snd;
 4733|  8.73k|  ret[2U] = result0_3.thd;
 4734|  8.73k|  ret[3U] = result0_3.f3;
 4735|  8.73k|  ret[4U] = result4_7.fst;
 4736|  8.73k|  ret[5U] = result4_7.snd;
 4737|  8.73k|  ret[6U] = result4_7.thd;
 4738|  8.73k|  ret[7U] = result4_7.f3;
 4739|  8.73k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_4_int:
 4694|  17.4k|libcrux_ml_kem_vector_portable_serialize_serialize_4_int(Eurydice_slice v) {
 4695|  17.4k|  uint8_t result0 = (uint32_t)libcrux_secrets_int_as_u8_f5(
 4696|  17.4k|                        Eurydice_slice_index(v, (size_t)1U, int16_t, int16_t *))
  ------------------
  |  |  180|  17.4k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4697|  17.4k|                        << 4U |
 4698|  17.4k|                    (uint32_t)libcrux_secrets_int_as_u8_f5(Eurydice_slice_index(
  ------------------
  |  |  180|  17.4k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4699|  17.4k|                        v, (size_t)0U, int16_t, int16_t *));
 4700|  17.4k|  uint8_t result1 = (uint32_t)libcrux_secrets_int_as_u8_f5(
 4701|  17.4k|                        Eurydice_slice_index(v, (size_t)3U, int16_t, int16_t *))
  ------------------
  |  |  180|  17.4k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4702|  17.4k|                        << 4U |
 4703|  17.4k|                    (uint32_t)libcrux_secrets_int_as_u8_f5(Eurydice_slice_index(
  ------------------
  |  |  180|  17.4k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4704|  17.4k|                        v, (size_t)2U, int16_t, int16_t *));
 4705|  17.4k|  uint8_t result2 = (uint32_t)libcrux_secrets_int_as_u8_f5(
 4706|  17.4k|                        Eurydice_slice_index(v, (size_t)5U, int16_t, int16_t *))
  ------------------
  |  |  180|  17.4k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4707|  17.4k|                        << 4U |
 4708|  17.4k|                    (uint32_t)libcrux_secrets_int_as_u8_f5(Eurydice_slice_index(
  ------------------
  |  |  180|  17.4k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4709|  17.4k|                        v, (size_t)4U, int16_t, int16_t *));
 4710|  17.4k|  uint8_t result3 = (uint32_t)libcrux_secrets_int_as_u8_f5(
 4711|  17.4k|                        Eurydice_slice_index(v, (size_t)7U, int16_t, int16_t *))
  ------------------
  |  |  180|  17.4k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4712|  17.4k|                        << 4U |
 4713|  17.4k|                    (uint32_t)libcrux_secrets_int_as_u8_f5(Eurydice_slice_index(
  ------------------
  |  |  180|  17.4k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 4714|  17.4k|                        v, (size_t)6U, int16_t, int16_t *));
 4715|  17.4k|  return (KRML_CLITERAL(uint8_t_x4){
  ------------------
  |  |  154|  17.4k|#define KRML_CLITERAL(type) (type)
  ------------------
 4716|  17.4k|      .fst = result0, .snd = result1, .thd = result2, .f3 = result3});
 4717|  17.4k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_76:
 1048|  8.73k|                                                     uint8_t ret[8U]) {
 1049|  8.73k|  memcpy(ret, self, (size_t)8U * sizeof(uint8_t));
 1050|  8.73k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_variant_kdf_39_d6:
 7903|    819|    Eurydice_slice shared_secret, uint8_t *_, uint8_t ret[32U]) {
 7904|    819|  uint8_t out[32U] = {0U};
 7905|    819|  Eurydice_slice_copy(Eurydice_array_to_slice((size_t)32U, out, uint8_t),
  ------------------
  |  |  229|    819|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 7906|    819|                      shared_secret, uint8_t);
 7907|    819|  memcpy(ret, out, (size_t)32U * sizeof(uint8_t));
 7908|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_as_slice_a9_80:
  856|    546|    libcrux_ml_kem_mlkem768_MlKem768Ciphertext *self) {
  857|    546|  return self->value;
  858|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_compare_ciphertexts_select_shared_secret_in_constant_time:
 1277|    273|    Eurydice_slice rhs_s, uint8_t ret[32U]) {
 1278|    273|  uint8_t selector =
 1279|    273|      libcrux_ml_kem_constant_time_ops_compare_ciphertexts_in_constant_time(
 1280|    273|          lhs_c, rhs_c);
 1281|    273|  uint8_t ret0[32U];
 1282|    273|  libcrux_ml_kem_constant_time_ops_select_shared_secret_in_constant_time(
 1283|    273|      lhs_s, rhs_s, selector, ret0);
 1284|    273|  memcpy(ret, ret0, (size_t)32U * sizeof(uint8_t));
 1285|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_compare_ciphertexts_in_constant_time:
 1240|    273|    Eurydice_slice lhs, Eurydice_slice rhs) {
 1241|    273|  return libcrux_ml_kem_constant_time_ops_compare(lhs, rhs);
 1242|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_compare:
 1226|    273|    Eurydice_slice lhs, Eurydice_slice rhs) {
 1227|    273|  uint8_t r = 0U;
 1228|   297k|  for (size_t i = (size_t)0U; i < Eurydice_slice_len(lhs, uint8_t); i++) {
  ------------------
  |  |  173|   297k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (1228:31): [True: 297k, False: 273]
  ------------------
 1229|   297k|    size_t i0 = i;
 1230|   297k|    uint8_t nr = (uint32_t)r |
 1231|   297k|                 ((uint32_t)Eurydice_slice_index(lhs, i0, uint8_t, uint8_t *) ^
  ------------------
  |  |  180|   297k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 1232|   297k|                  (uint32_t)Eurydice_slice_index(rhs, i0, uint8_t, uint8_t *));
  ------------------
  |  |  180|   297k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 1233|   297k|    r = nr;
 1234|   297k|  }
 1235|    273|  return libcrux_ml_kem_constant_time_ops_is_non_zero(r);
 1236|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_is_non_zero:
 1217|    546|libcrux_ml_kem_constant_time_ops_is_non_zero(uint8_t value) {
 1218|    546|  return libcrux_ml_kem_constant_time_ops_inz(value);
 1219|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_inz:
 1209|    546|libcrux_ml_kem_constant_time_ops_inz(uint8_t value) {
 1210|    546|  uint16_t value0 = (uint16_t)value;
 1211|    546|  uint8_t result =
 1212|    546|      (uint8_t)((uint32_t)core_num__u16__wrapping_add(~value0, 1U) >> 8U);
 1213|    546|  return (uint32_t)result & 1U;
 1214|    546|}
libcrux_mlkem768_sha3.c:core_num__u16__wrapping_add:
  336|    546|static inline uint16_t core_num__u16__wrapping_add(uint16_t x, uint16_t y) {
  337|    546|  return x + y;
  338|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_select_shared_secret_in_constant_time:
 1270|    273|    uint8_t ret[32U]) {
 1271|    273|  libcrux_ml_kem_constant_time_ops_select_ct(lhs, rhs, selector, ret);
 1272|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constant_time_ops_select_ct:
 1250|    273|    uint8_t ret[32U]) {
 1251|    273|  uint8_t mask = core_num__u8__wrapping_sub(
 1252|    273|      libcrux_ml_kem_constant_time_ops_is_non_zero(selector), 1U);
 1253|    273|  uint8_t out[32U] = {0U};
 1254|  9.00k|  for (size_t i = (size_t)0U; i < LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE;
  ------------------
  |  |  443|  9.00k|#define LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE ((size_t)32U)
  ------------------
  |  Branch (1254:31): [True: 8.73k, False: 273]
  ------------------
 1255|  8.73k|       i++) {
 1256|  8.73k|    size_t i0 = i;
 1257|  8.73k|    uint8_t outi =
 1258|  8.73k|        ((uint32_t)Eurydice_slice_index(lhs, i0, uint8_t, uint8_t *) &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 1259|  8.73k|         (uint32_t)mask) |
 1260|  8.73k|        ((uint32_t)Eurydice_slice_index(rhs, i0, uint8_t, uint8_t *) &
  ------------------
  |  |  180|  8.73k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 1261|  8.73k|         (uint32_t)~mask);
 1262|  8.73k|    out[i0] = outi;
 1263|  8.73k|  }
 1264|    273|  memcpy(ret, out, (size_t)32U * sizeof(uint8_t));
 1265|    273|}
libcrux_mlkem768_sha3.c:core_num__u8__wrapping_sub:
  339|    273|static inline uint8_t core_num__u8__wrapping_sub(uint8_t x, uint8_t y) {
  340|    273|  return x - y;
  341|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_instantiations_portable_encapsulate_cd:
 8159|    273|    libcrux_ml_kem_types_MlKemPublicKey_30 *public_key, uint8_t *randomness) {
 8160|    273|  return libcrux_ml_kem_ind_cca_encapsulate_ca(public_key, randomness);
 8161|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_encapsulate_ca:
 8096|    273|    libcrux_ml_kem_types_MlKemPublicKey_30 *public_key, uint8_t *randomness) {
 8097|    273|  uint8_t randomness0[32U];
 8098|    273|  libcrux_ml_kem_variant_entropy_preprocess_39_9c(
 8099|    273|      Eurydice_array_to_slice((size_t)32U, randomness, uint8_t), randomness0);
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8100|    273|  uint8_t to_hash[64U];
 8101|    273|  libcrux_ml_kem_utils_into_padded_array_24(
 8102|    273|      Eurydice_array_to_slice((size_t)32U, randomness0, uint8_t), to_hash);
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8103|    273|  Eurydice_slice uu____0 = Eurydice_array_to_subslice_from(
  ------------------
  |  |  225|    273|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8104|    273|      (size_t)64U, to_hash, LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE, uint8_t,
 8105|    273|      size_t, uint8_t[]);
 8106|    273|  uint8_t ret0[32U];
 8107|    273|  libcrux_ml_kem_hash_functions_portable_H_4a_e0(
 8108|    273|      Eurydice_array_to_slice((size_t)1184U,
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8109|    273|                              libcrux_ml_kem_types_as_slice_e6_d0(public_key),
 8110|    273|                              uint8_t),
 8111|    273|      ret0);
 8112|    273|  Eurydice_slice_copy(
  ------------------
  |  |  229|    273|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8113|    273|      uu____0, Eurydice_array_to_slice((size_t)32U, ret0, uint8_t), uint8_t);
 8114|    273|  uint8_t hashed[64U];
 8115|    273|  libcrux_ml_kem_hash_functions_portable_G_4a_e0(
 8116|    273|      Eurydice_array_to_slice((size_t)64U, to_hash, uint8_t), hashed);
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8117|    273|  Eurydice_slice_uint8_t_x2 uu____1 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    273|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    273|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    273|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    273|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    273|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    273|  }
  ------------------
 8118|    273|      Eurydice_array_to_slice((size_t)64U, hashed, uint8_t),
 8119|    273|      LIBCRUX_ML_KEM_CONSTANTS_SHARED_SECRET_SIZE, uint8_t,
 8120|    273|      Eurydice_slice_uint8_t_x2);
 8121|    273|  Eurydice_slice shared_secret = uu____1.fst;
 8122|    273|  Eurydice_slice pseudorandomness = uu____1.snd;
 8123|    273|  uint8_t ciphertext[1088U];
 8124|    273|  libcrux_ml_kem_ind_cpa_encrypt_2a(
 8125|    273|      Eurydice_array_to_slice((size_t)1184U,
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8126|    273|                              libcrux_ml_kem_types_as_slice_e6_d0(public_key),
 8127|    273|                              uint8_t),
 8128|    273|      randomness0, pseudorandomness, ciphertext);
 8129|       |  /* Passing arrays by value in Rust generates a copy in C */
 8130|    273|  uint8_t copy_of_ciphertext[1088U];
 8131|    273|  memcpy(copy_of_ciphertext, ciphertext, (size_t)1088U * sizeof(uint8_t));
 8132|    273|  tuple_c2 lit;
 8133|    273|  lit.fst = libcrux_ml_kem_types_from_e0_80(copy_of_ciphertext);
 8134|    273|  uint8_t ret[32U];
 8135|    273|  libcrux_ml_kem_variant_kdf_39_d6(shared_secret, ciphertext, ret);
 8136|    273|  memcpy(lit.snd, ret, (size_t)32U * sizeof(uint8_t));
 8137|    273|  return lit;
 8138|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_variant_entropy_preprocess_39_9c:
 8055|    273|    Eurydice_slice randomness, uint8_t ret[32U]) {
 8056|    273|  uint8_t out[32U] = {0U};
 8057|    273|  Eurydice_slice_copy(Eurydice_array_to_slice((size_t)32U, out, uint8_t),
  ------------------
  |  |  229|    273|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8058|    273|                      randomness, uint8_t);
 8059|    273|  memcpy(ret, out, (size_t)32U * sizeof(uint8_t));
 8060|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_H_4a_e0:
 8072|    546|    Eurydice_slice input, uint8_t ret[32U]) {
 8073|    546|  libcrux_ml_kem_hash_functions_portable_H(input, ret);
 8074|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_H:
 3725|    546|    Eurydice_slice input, uint8_t ret[32U]) {
 3726|    546|  uint8_t digest[32U] = {0U};
 3727|    546|  libcrux_sha3_portable_sha256(
 3728|    546|      Eurydice_array_to_slice((size_t)32U, digest, uint8_t), input);
  ------------------
  |  |  204|    546|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    546|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    546|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    546|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3729|    546|  memcpy(ret, digest, (size_t)32U * sizeof(uint8_t));
 3730|    546|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_sha256:
 3351|    546|                                                         Eurydice_slice data) {
 3352|    546|  libcrux_sha3_generic_keccak_portable_keccak1_ad(data, digest);
 3353|    546|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_keccak1_ad:
 3315|    546|    Eurydice_slice data, Eurydice_slice out) {
 3316|    546|  libcrux_sha3_generic_keccak_KeccakState_17 s =
 3317|    546|      libcrux_sha3_generic_keccak_new_80_04();
 3318|    546|  size_t data_len = Eurydice_slice_len(data, uint8_t);
  ------------------
  |  |  173|    546|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3319|  4.91k|  for (size_t i = (size_t)0U; i < data_len / (size_t)136U; i++) {
  ------------------
  |  Branch (3319:31): [True: 4.36k, False: 546]
  ------------------
 3320|  4.36k|    size_t i0 = i;
 3321|  4.36k|    Eurydice_slice buf[1U] = {data};
 3322|  4.36k|    libcrux_sha3_generic_keccak_absorb_block_80_c60(&s, buf, i0 * (size_t)136U);
 3323|  4.36k|  }
 3324|    546|  size_t rem = data_len % (size_t)136U;
 3325|    546|  Eurydice_slice buf[1U] = {data};
 3326|    546|  libcrux_sha3_generic_keccak_absorb_final_80_9e0(&s, buf, data_len - rem, rem);
 3327|    546|  size_t outlen = Eurydice_slice_len(out, uint8_t);
  ------------------
  |  |  173|    546|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3328|    546|  size_t blocks = outlen / (size_t)136U;
 3329|    546|  size_t last = outlen - outlen % (size_t)136U;
 3330|    546|  if (blocks == (size_t)0U) {
  ------------------
  |  Branch (3330:7): [True: 546, False: 0]
  ------------------
 3331|    546|    libcrux_sha3_simd_portable_squeeze_13_5b(&s, out, (size_t)0U, outlen);
 3332|    546|  } 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|    546|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_final_80_9e0:
 3250|    546|    size_t start, size_t len) {
 3251|    546|  libcrux_sha3_simd_portable_load_last_a1_ad(self, last, start, len);
 3252|    546|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3253|    546|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_a1_ad:
 3232|    546|    size_t start, size_t len) {
 3233|    546|  libcrux_sha3_simd_portable_load_last_ad(self->st, input[0U], start, len);
 3234|    546|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_ad:
 3205|    546|    uint64_t *state, Eurydice_slice blocks, size_t start, size_t len) {
 3206|    546|  uint8_t buffer[136U] = {0U};
 3207|    546|  Eurydice_slice_copy(
  ------------------
  |  |  229|    546|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3208|    546|      Eurydice_array_to_subslice3(buffer, (size_t)0U, len, uint8_t *),
 3209|    546|      Eurydice_slice_subslice3(blocks, start, start + len, uint8_t *), uint8_t);
 3210|    546|  buffer[len] = 6U;
 3211|    546|  size_t uu____0 = (size_t)136U - (size_t)1U;
 3212|    546|  buffer[uu____0] = (uint32_t)buffer[uu____0] | 128U;
 3213|    546|  libcrux_sha3_simd_portable_load_block_5b(
 3214|    546|      state, Eurydice_array_to_slice((size_t)136U, buffer, uint8_t),
  ------------------
  |  |  204|    546|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    546|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    546|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    546|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3215|    546|      (size_t)0U);
 3216|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_as_slice_e6_d0:
  843|    546|    libcrux_ml_kem_types_MlKemPublicKey_30 *self) {
  844|    546|  return self->value;
  845|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_from_e0_80:
  825|    273|libcrux_ml_kem_types_from_e0_80(uint8_t value[1088U]) {
  826|       |  /* Passing arrays by value in Rust generates a copy in C */
  827|    273|  uint8_t copy_of_value[1088U];
  828|    273|  memcpy(copy_of_value, value, (size_t)1088U * sizeof(uint8_t));
  829|    273|  libcrux_ml_kem_mlkem768_MlKem768Ciphertext lit;
  830|    273|  memcpy(lit.value, copy_of_value, (size_t)1088U * sizeof(uint8_t));
  831|    273|  return lit;
  832|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_instantiations_portable_generate_keypair_ce:
 8754|    273|    uint8_t *randomness) {
 8755|    273|  return libcrux_ml_kem_ind_cca_generate_keypair_15(randomness);
 8756|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_generate_keypair_15:
 8705|    273|libcrux_ml_kem_ind_cca_generate_keypair_15(uint8_t *randomness) {
 8706|    273|  Eurydice_slice ind_cpa_keypair_randomness = Eurydice_array_to_subslice3(
  ------------------
  |  |  215|    273|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8707|    273|      randomness, (size_t)0U,
 8708|    273|      LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE, uint8_t *);
 8709|    273|  Eurydice_slice implicit_rejection_value = Eurydice_array_to_subslice_from(
  ------------------
  |  |  225|    273|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8710|    273|      (size_t)64U, randomness,
 8711|    273|      LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE, uint8_t,
 8712|    273|      size_t, uint8_t[]);
 8713|    273|  libcrux_ml_kem_utils_extraction_helper_Keypair768 uu____0 =
 8714|    273|      libcrux_ml_kem_ind_cpa_generate_keypair_ea(ind_cpa_keypair_randomness);
 8715|    273|  uint8_t ind_cpa_private_key[1152U];
 8716|    273|  memcpy(ind_cpa_private_key, uu____0.fst, (size_t)1152U * sizeof(uint8_t));
 8717|    273|  uint8_t public_key[1184U];
 8718|    273|  memcpy(public_key, uu____0.snd, (size_t)1184U * sizeof(uint8_t));
 8719|    273|  uint8_t secret_key_serialized[2400U];
 8720|    273|  libcrux_ml_kem_ind_cca_serialize_kem_secret_key_d6(
 8721|    273|      Eurydice_array_to_slice((size_t)1152U, ind_cpa_private_key, uint8_t),
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8722|    273|      Eurydice_array_to_slice((size_t)1184U, public_key, uint8_t),
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8723|    273|      implicit_rejection_value, secret_key_serialized);
 8724|       |  /* Passing arrays by value in Rust generates a copy in C */
 8725|    273|  uint8_t copy_of_secret_key_serialized[2400U];
 8726|    273|  memcpy(copy_of_secret_key_serialized, secret_key_serialized,
 8727|    273|         (size_t)2400U * sizeof(uint8_t));
 8728|    273|  libcrux_ml_kem_types_MlKemPrivateKey_d9 private_key =
 8729|    273|      libcrux_ml_kem_types_from_77_28(copy_of_secret_key_serialized);
 8730|    273|  libcrux_ml_kem_types_MlKemPrivateKey_d9 uu____2 = private_key;
 8731|       |  /* Passing arrays by value in Rust generates a copy in C */
 8732|    273|  uint8_t copy_of_public_key[1184U];
 8733|    273|  memcpy(copy_of_public_key, public_key, (size_t)1184U * sizeof(uint8_t));
 8734|    273|  return libcrux_ml_kem_types_from_17_74(
 8735|    273|      uu____2, libcrux_ml_kem_types_from_fd_d0(copy_of_public_key));
 8736|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_generate_keypair_ea:
 8605|    273|libcrux_ml_kem_ind_cpa_generate_keypair_ea(Eurydice_slice key_generation_seed) {
 8606|    273|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPrivateKeyUnpacked_a0 private_key =
 8607|    273|      libcrux_ml_kem_ind_cpa_unpacked_default_70_1b();
 8608|    273|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0 public_key =
 8609|    273|      libcrux_ml_kem_ind_cpa_unpacked_default_8b_1b();
 8610|    273|  libcrux_ml_kem_ind_cpa_generate_keypair_unpacked_1c(
 8611|    273|      key_generation_seed, &private_key, &public_key);
 8612|    273|  return libcrux_ml_kem_ind_cpa_serialize_unpacked_secret_key_6c(&public_key,
 8613|    273|                                                                 &private_key);
 8614|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_unpacked_default_70_1b:
 8189|    273|libcrux_ml_kem_ind_cpa_unpacked_default_70_1b(void) {
 8190|    273|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPrivateKeyUnpacked_a0 lit;
 8191|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d repeat_expression[3U];
 8192|  1.09k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (8192:31): [True: 819, False: 273]
  ------------------
 8193|    819|    repeat_expression[i] = libcrux_ml_kem_polynomial_ZERO_d6_ea();
 8194|    819|  }
 8195|    273|  memcpy(
 8196|    273|      lit.secret_as_ntt, repeat_expression,
 8197|    273|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 8198|    273|  return lit;
 8199|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_generate_keypair_unpacked_1c:
 8409|    273|    libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0 *public_key) {
 8410|    273|  uint8_t hashed[64U];
 8411|    273|  libcrux_ml_kem_variant_cpa_keygen_seed_39_9c(key_generation_seed, hashed);
 8412|    273|  Eurydice_slice_uint8_t_x2 uu____0 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    273|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    273|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    273|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    273|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    273|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    273|  }
  ------------------
 8413|    273|      Eurydice_array_to_slice((size_t)64U, hashed, uint8_t), (size_t)32U,
 8414|    273|      uint8_t, Eurydice_slice_uint8_t_x2);
 8415|    273|  Eurydice_slice seed_for_A = uu____0.fst;
 8416|    273|  Eurydice_slice seed_for_secret_and_error = uu____0.snd;
 8417|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d(*uu____1)[3U] =
 8418|    273|      public_key->A;
 8419|    273|  uint8_t ret[34U];
 8420|    273|  libcrux_ml_kem_utils_into_padded_array_b6(seed_for_A, ret);
 8421|    273|  libcrux_ml_kem_matrix_sample_matrix_A_2b(uu____1, ret, true);
 8422|    273|  uint8_t prf_input[33U];
 8423|    273|  libcrux_ml_kem_utils_into_padded_array_c8(seed_for_secret_and_error,
 8424|    273|                                            prf_input);
 8425|    273|  uint8_t domain_separator =
 8426|    273|      libcrux_ml_kem_ind_cpa_sample_vector_cbd_then_ntt_3b(
 8427|    273|          private_key->secret_as_ntt, prf_input, 0U);
 8428|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d error_as_ntt[3U];
 8429|  1.09k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (8429:31): [True: 819, False: 273]
  ------------------
 8430|       |    /* original Rust expression is not an lvalue in C */
 8431|    819|    void *lvalue = (void *)0U;
 8432|    819|    error_as_ntt[i] =
 8433|    819|        libcrux_ml_kem_ind_cpa_generate_keypair_unpacked_call_mut_73_1c(&lvalue,
 8434|    819|                                                                        i);
 8435|    819|  }
 8436|    273|  libcrux_ml_kem_ind_cpa_sample_vector_cbd_then_ntt_3b(error_as_ntt, prf_input,
 8437|    273|                                                       domain_separator);
 8438|    273|  libcrux_ml_kem_matrix_compute_As_plus_e_1b(
 8439|    273|      public_key->t_as_ntt, public_key->A, private_key->secret_as_ntt,
 8440|    273|      error_as_ntt);
 8441|    273|  uint8_t uu____2[32U];
 8442|    273|  Result_fb dst;
 8443|    273|  Eurydice_slice_to_array2(&dst, seed_for_A, Eurydice_slice, uint8_t[32U],
  ------------------
  |  |  277|    273|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|    273|                           sizeof(t_arr))
  ------------------
 8444|    273|                           TryFromSliceError);
 8445|    273|  unwrap_26_b3(dst, uu____2);
 8446|    273|  memcpy(public_key->seed_for_A, uu____2, (size_t)32U * sizeof(uint8_t));
 8447|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_variant_cpa_keygen_seed_39_9c:
 8212|    273|    Eurydice_slice key_generation_seed, uint8_t ret[64U]) {
 8213|    273|  uint8_t seed[33U] = {0U};
 8214|    273|  Eurydice_slice_copy(
  ------------------
  |  |  229|    273|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8215|    273|      Eurydice_array_to_subslice3(
 8216|    273|          seed, (size_t)0U,
 8217|    273|          LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE, uint8_t *),
 8218|    273|      key_generation_seed, uint8_t);
 8219|    273|  seed[LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE] =
  ------------------
  |  |  455|    273|#define LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE ((size_t)32U)
  ------------------
 8220|    273|      (uint8_t)(size_t)3U;
 8221|    273|  uint8_t ret0[64U];
 8222|    273|  libcrux_ml_kem_hash_functions_portable_G_4a_e0(
 8223|    273|      Eurydice_array_to_slice((size_t)33U, seed, uint8_t), ret0);
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8224|    273|  memcpy(ret, ret0, (size_t)64U * sizeof(uint8_t));
 8225|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_generate_keypair_unpacked_call_mut_73_1c:
 8247|    819|    void **_, size_t tupled_args) {
 8248|    819|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 8249|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_compute_As_plus_e_1b:
 8322|    273|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error_as_ntt) {
 8323|    273|  for (size_t i = (size_t)0U;
 8324|  1.09k|       i < Eurydice_slice_len(
  ------------------
  |  |  173|  1.09k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (8324:8): [True: 819, False: 273]
  ------------------
 8325|    273|               Eurydice_array_to_slice(
 8326|    273|                   (size_t)3U, matrix_A,
 8327|    273|                   libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]),
 8328|    273|               libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]);
 8329|    819|       i++) {
 8330|    819|    size_t i0 = i;
 8331|    819|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *row = matrix_A[i0];
 8332|    819|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0 =
 8333|    819|        libcrux_ml_kem_polynomial_ZERO_d6_ea();
 8334|    819|    t_as_ntt[i0] = uu____0;
 8335|    819|    for (size_t i1 = (size_t)0U;
 8336|  3.27k|         i1 < Eurydice_slice_len(
  ------------------
  |  |  173|  3.27k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (8336:10): [True: 2.45k, False: 819]
  ------------------
 8337|    819|                  Eurydice_array_to_slice(
 8338|    819|                      (size_t)3U, row,
 8339|    819|                      libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 8340|    819|                  libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 8341|  2.45k|         i1++) {
 8342|  2.45k|      size_t j = i1;
 8343|  2.45k|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d *matrix_element =
 8344|  2.45k|          &row[j];
 8345|  2.45k|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d product =
 8346|  2.45k|          libcrux_ml_kem_polynomial_ntt_multiply_d6_ea(matrix_element,
 8347|  2.45k|                                                       &s_as_ntt[j]);
 8348|  2.45k|      libcrux_ml_kem_polynomial_add_to_ring_element_d6_1b(&t_as_ntt[i0],
 8349|  2.45k|                                                          &product);
 8350|  2.45k|    }
 8351|    819|    libcrux_ml_kem_polynomial_add_standard_error_reduce_d6_ea(
 8352|    819|        &t_as_ntt[i0], &error_as_ntt[i0]);
 8353|    819|  }
 8354|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_standard_error_reduce_d6_ea:
 8305|    819|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error) {
 8306|    819|  libcrux_ml_kem_polynomial_add_standard_error_reduce_ea(self, error);
 8307|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_standard_error_reduce_ea:
 8274|    819|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error) {
 8275|    819|  for (size_t i = (size_t)0U;
 8276|  13.9k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  13.9k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (8276:8): [True: 13.1k, False: 819]
  ------------------
 8277|  13.1k|    size_t j = i;
 8278|  13.1k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 8279|  13.1k|        coefficient_normal_form =
 8280|  13.1k|            libcrux_ml_kem_polynomial_to_standard_domain_ea(
 8281|  13.1k|                myself->coefficients[j]);
 8282|  13.1k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector sum =
 8283|  13.1k|        libcrux_ml_kem_vector_portable_add_b8(coefficient_normal_form,
 8284|  13.1k|                                              &error->coefficients[j]);
 8285|  13.1k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector red =
 8286|  13.1k|        libcrux_ml_kem_vector_portable_barrett_reduce_b8(sum);
 8287|  13.1k|    myself->coefficients[j] = red;
 8288|  13.1k|  }
 8289|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_to_standard_domain_ea:
 8259|  13.1k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vector) {
 8260|  13.1k|  return libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(
 8261|  13.1k|      vector,
 8262|  13.1k|      LIBCRUX_ML_KEM_VECTOR_TRAITS_MONTGOMERY_R_SQUARED_MOD_FIELD_MODULUS);
  ------------------
  |  | 3775|  13.1k|  ((int16_t)1353)
  ------------------
 8263|  13.1k|}
libcrux_mlkem768_sha3.c:unwrap_26_b3:
  803|    273|static inline void unwrap_26_b3(Result_fb self, uint8_t ret[32U]) {
  804|    273|  if (self.tag == Ok) {
  ------------------
  |  |  721|    273|#define Ok 0
  ------------------
  |  Branch (804:7): [True: 273, False: 0]
  ------------------
  805|    273|    uint8_t f0[32U];
  806|    273|    memcpy(f0, self.val.case_Ok, (size_t)32U * sizeof(uint8_t));
  807|    273|    memcpy(ret, f0, (size_t)32U * sizeof(uint8_t));
  808|    273|  } 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|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_serialize_unpacked_secret_key_6c:
 8567|    273|    libcrux_ml_kem_ind_cpa_unpacked_IndCpaPrivateKeyUnpacked_a0 *private_key) {
 8568|    273|  uint8_t public_key_serialized[1184U];
 8569|    273|  libcrux_ml_kem_ind_cpa_serialize_public_key_89(
 8570|    273|      public_key->t_as_ntt,
 8571|    273|      Eurydice_array_to_slice((size_t)32U, public_key->seed_for_A, uint8_t),
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8572|    273|      public_key_serialized);
 8573|    273|  uint8_t secret_key_serialized[1152U] = {0U};
 8574|    273|  libcrux_ml_kem_ind_cpa_serialize_vector_1b(
 8575|    273|      private_key->secret_as_ntt,
 8576|    273|      Eurydice_array_to_slice((size_t)1152U, secret_key_serialized, uint8_t));
  ------------------
  |  |  204|    273|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    273|                 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|    273|  uint8_t copy_of_secret_key_serialized[1152U];
 8579|    273|  memcpy(copy_of_secret_key_serialized, secret_key_serialized,
 8580|    273|         (size_t)1152U * sizeof(uint8_t));
 8581|       |  /* Passing arrays by value in Rust generates a copy in C */
 8582|    273|  uint8_t copy_of_public_key_serialized[1184U];
 8583|    273|  memcpy(copy_of_public_key_serialized, public_key_serialized,
 8584|    273|         (size_t)1184U * sizeof(uint8_t));
 8585|    273|  libcrux_ml_kem_utils_extraction_helper_Keypair768 lit;
 8586|    273|  memcpy(lit.fst, copy_of_secret_key_serialized,
 8587|    273|         (size_t)1152U * sizeof(uint8_t));
 8588|    273|  memcpy(lit.snd, copy_of_public_key_serialized,
 8589|    273|         (size_t)1184U * sizeof(uint8_t));
 8590|    273|  return lit;
 8591|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_serialize_public_key_89:
 8546|    546|    Eurydice_slice seed_for_a, uint8_t ret[1184U]) {
 8547|    546|  uint8_t public_key_serialized[1184U] = {0U};
 8548|    546|  libcrux_ml_kem_ind_cpa_serialize_public_key_mut_89(t_as_ntt, seed_for_a,
 8549|    546|                                                     public_key_serialized);
 8550|    546|  memcpy(ret, public_key_serialized, (size_t)1184U * sizeof(uint8_t));
 8551|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_serialize_public_key_mut_89:
 8519|    546|    Eurydice_slice seed_for_a, uint8_t *serialized) {
 8520|    546|  libcrux_ml_kem_ind_cpa_serialize_vector_1b(
 8521|    546|      t_as_ntt,
 8522|    546|      Eurydice_array_to_subslice3(
  ------------------
  |  |  215|    546|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    546|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    546|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8523|    546|          serialized, (size_t)0U,
 8524|    546|          libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U),
 8525|    546|          uint8_t *));
 8526|    546|  Eurydice_slice_copy(
  ------------------
  |  |  229|    546|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8527|    546|      Eurydice_array_to_subslice_from(
 8528|    546|          (size_t)1184U, serialized,
 8529|    546|          libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U),
 8530|    546|          uint8_t, size_t, uint8_t[]),
 8531|    546|      seed_for_a, uint8_t);
 8532|    546|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constants_ranked_bytes_per_ring_element:
  468|  3.54k|    size_t rank) {
  469|  3.54k|  return rank * LIBCRUX_ML_KEM_CONSTANTS_BITS_PER_RING_ELEMENT / (size_t)8U;
  ------------------
  |  |  450|  3.54k|  (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)12U)
  |  |  ------------------
  |  |  |  |  447|  3.54k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  |  |  ------------------
  ------------------
  470|  3.54k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_serialize_vector_1b:
 8486|    819|    Eurydice_slice out) {
 8487|    819|  for (size_t i = (size_t)0U;
 8488|  3.27k|       i < Eurydice_slice_len(
  ------------------
  |  |  173|  3.27k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (8488:8): [True: 2.45k, False: 819]
  ------------------
 8489|    819|               Eurydice_array_to_slice(
 8490|    819|                   (size_t)3U, key,
 8491|    819|                   libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 8492|    819|               libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 8493|  2.45k|       i++) {
 8494|  2.45k|    size_t i0 = i;
 8495|  2.45k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d re = key[i0];
 8496|  2.45k|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  2.45k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  2.45k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  2.45k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8497|  2.45k|        out, i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 8498|  2.45k|        (i0 + (size_t)1U) * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 8499|  2.45k|        uint8_t *);
 8500|  2.45k|    uint8_t ret[384U];
 8501|  2.45k|    libcrux_ml_kem_serialize_serialize_uncompressed_ring_element_ea(&re, ret);
 8502|  2.45k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  2.45k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8503|  2.45k|        uu____0, Eurydice_array_to_slice((size_t)384U, ret, uint8_t), uint8_t);
 8504|  2.45k|  }
 8505|    819|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_serialize_uncompressed_ring_element_ea:
 8457|  2.45k|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re, uint8_t ret[384U]) {
 8458|  2.45k|  uint8_t serialized[384U] = {0U};
 8459|  2.45k|  for (size_t i = (size_t)0U;
 8460|  41.7k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  41.7k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (8460:8): [True: 39.3k, False: 2.45k]
  ------------------
 8461|  39.3k|    size_t i0 = i;
 8462|  39.3k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 8463|  39.3k|        libcrux_ml_kem_serialize_to_unsigned_field_modulus_ea(
 8464|  39.3k|            re->coefficients[i0]);
 8465|  39.3k|    uint8_t bytes[24U];
 8466|  39.3k|    libcrux_ml_kem_vector_portable_serialize_12_b8(coefficient, bytes);
 8467|  39.3k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  39.3k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8468|  39.3k|        Eurydice_array_to_subslice3(serialized, (size_t)24U * i0,
 8469|  39.3k|                                    (size_t)24U * i0 + (size_t)24U, uint8_t *),
 8470|  39.3k|        Eurydice_array_to_slice((size_t)24U, bytes, uint8_t), uint8_t);
 8471|  39.3k|  }
 8472|  2.45k|  memcpy(ret, serialized, (size_t)384U * sizeof(uint8_t));
 8473|  2.45k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_12_b8:
 5116|  39.3k|    uint8_t ret[24U]) {
 5117|  39.3k|  libcrux_ml_kem_vector_portable_serialize_12(a, ret);
 5118|  39.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_12:
 5104|  39.3k|    uint8_t ret[24U]) {
 5105|  39.3k|  uint8_t ret0[24U];
 5106|  39.3k|  libcrux_ml_kem_vector_portable_serialize_serialize_12(a, ret0);
 5107|  39.3k|  libcrux_secrets_int_public_integers_declassify_d8_d2(ret0, ret);
 5108|  39.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_12:
 5051|  39.3k|    uint8_t ret[24U]) {
 5052|  39.3k|  uint8_t_x3 r0_2 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5053|  39.3k|      Eurydice_array_to_subslice3(v.elements, (size_t)0U, (size_t)2U,
  ------------------
  |  |  215|  39.3k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  39.3k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  39.3k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5054|  39.3k|                                  int16_t *));
 5055|  39.3k|  uint8_t_x3 r3_5 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5056|  39.3k|      Eurydice_array_to_subslice3(v.elements, (size_t)2U, (size_t)4U,
  ------------------
  |  |  215|  39.3k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  39.3k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  39.3k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5057|  39.3k|                                  int16_t *));
 5058|  39.3k|  uint8_t_x3 r6_8 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5059|  39.3k|      Eurydice_array_to_subslice3(v.elements, (size_t)4U, (size_t)6U,
  ------------------
  |  |  215|  39.3k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  39.3k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  39.3k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5060|  39.3k|                                  int16_t *));
 5061|  39.3k|  uint8_t_x3 r9_11 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5062|  39.3k|      Eurydice_array_to_subslice3(v.elements, (size_t)6U, (size_t)8U,
  ------------------
  |  |  215|  39.3k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  39.3k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  39.3k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5063|  39.3k|                                  int16_t *));
 5064|  39.3k|  uint8_t_x3 r12_14 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5065|  39.3k|      Eurydice_array_to_subslice3(v.elements, (size_t)8U, (size_t)10U,
  ------------------
  |  |  215|  39.3k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  39.3k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  39.3k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5066|  39.3k|                                  int16_t *));
 5067|  39.3k|  uint8_t_x3 r15_17 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5068|  39.3k|      Eurydice_array_to_subslice3(v.elements, (size_t)10U, (size_t)12U,
  ------------------
  |  |  215|  39.3k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  39.3k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  39.3k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5069|  39.3k|                                  int16_t *));
 5070|  39.3k|  uint8_t_x3 r18_20 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5071|  39.3k|      Eurydice_array_to_subslice3(v.elements, (size_t)12U, (size_t)14U,
  ------------------
  |  |  215|  39.3k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  39.3k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  39.3k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5072|  39.3k|                                  int16_t *));
 5073|  39.3k|  uint8_t_x3 r21_23 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5074|  39.3k|      Eurydice_array_to_subslice3(v.elements, (size_t)14U, (size_t)16U,
  ------------------
  |  |  215|  39.3k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  39.3k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  39.3k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5075|  39.3k|                                  int16_t *));
 5076|  39.3k|  ret[0U] = r0_2.fst;
 5077|  39.3k|  ret[1U] = r0_2.snd;
 5078|  39.3k|  ret[2U] = r0_2.thd;
 5079|  39.3k|  ret[3U] = r3_5.fst;
 5080|  39.3k|  ret[4U] = r3_5.snd;
 5081|  39.3k|  ret[5U] = r3_5.thd;
 5082|  39.3k|  ret[6U] = r6_8.fst;
 5083|  39.3k|  ret[7U] = r6_8.snd;
 5084|  39.3k|  ret[8U] = r6_8.thd;
 5085|  39.3k|  ret[9U] = r9_11.fst;
 5086|  39.3k|  ret[10U] = r9_11.snd;
 5087|  39.3k|  ret[11U] = r9_11.thd;
 5088|  39.3k|  ret[12U] = r12_14.fst;
 5089|  39.3k|  ret[13U] = r12_14.snd;
 5090|  39.3k|  ret[14U] = r12_14.thd;
 5091|  39.3k|  ret[15U] = r15_17.fst;
 5092|  39.3k|  ret[16U] = r15_17.snd;
 5093|  39.3k|  ret[17U] = r15_17.thd;
 5094|  39.3k|  ret[18U] = r18_20.fst;
 5095|  39.3k|  ret[19U] = r18_20.snd;
 5096|  39.3k|  ret[20U] = r18_20.thd;
 5097|  39.3k|  ret[21U] = r21_23.fst;
 5098|  39.3k|  ret[22U] = r21_23.snd;
 5099|  39.3k|  ret[23U] = r21_23.thd;
 5100|  39.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_12_int:
 5035|   314k|libcrux_ml_kem_vector_portable_serialize_serialize_12_int(Eurydice_slice v) {
 5036|   314k|  uint8_t r0 = libcrux_secrets_int_as_u8_f5(
 5037|   314k|      Eurydice_slice_index(v, (size_t)0U, int16_t, int16_t *) & (int16_t)255);
  ------------------
  |  |  180|   314k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5038|   314k|  uint8_t r1 = libcrux_secrets_int_as_u8_f5(
 5039|   314k|      Eurydice_slice_index(v, (size_t)0U, int16_t, int16_t *) >> 8U |
  ------------------
  |  |  180|   314k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5040|   314k|      (Eurydice_slice_index(v, (size_t)1U, int16_t, int16_t *) & (int16_t)15)
  ------------------
  |  |  180|   314k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5041|   314k|          << 4U);
 5042|   314k|  uint8_t r2 = libcrux_secrets_int_as_u8_f5(
 5043|   314k|      Eurydice_slice_index(v, (size_t)1U, int16_t, int16_t *) >> 4U &
  ------------------
  |  |  180|   314k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5044|   314k|      (int16_t)255);
 5045|   314k|  return (KRML_CLITERAL(uint8_t_x3){.fst = r0, .snd = r1, .thd = r2});
  ------------------
  |  |  154|   314k|#define KRML_CLITERAL(type) (type)
  ------------------
 5046|   314k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_d2:
 1020|  39.3k|                                                     uint8_t ret[24U]) {
 1021|  39.3k|  memcpy(ret, self, (size_t)24U * sizeof(uint8_t));
 1022|  39.3k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_serialize_kem_secret_key_d6:
 8677|    273|    Eurydice_slice implicit_rejection_value, uint8_t ret[2400U]) {
 8678|    273|  uint8_t out[2400U] = {0U};
 8679|    273|  libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_d6(
 8680|    273|      private_key, public_key, implicit_rejection_value, out);
 8681|    273|  memcpy(ret, out, (size_t)2400U * sizeof(uint8_t));
 8682|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_d6:
 8629|    273|    Eurydice_slice implicit_rejection_value, uint8_t *serialized) {
 8630|    273|  size_t pointer = (size_t)0U;
 8631|    273|  uint8_t *uu____0 = serialized;
 8632|    273|  size_t uu____1 = pointer;
 8633|    273|  size_t uu____2 = pointer;
 8634|    273|  Eurydice_slice_copy(
  ------------------
  |  |  229|    273|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8635|    273|      Eurydice_array_to_subslice3(
 8636|    273|          uu____0, uu____1, uu____2 + Eurydice_slice_len(private_key, uint8_t),
 8637|    273|          uint8_t *),
 8638|    273|      private_key, uint8_t);
 8639|    273|  pointer = pointer + Eurydice_slice_len(private_key, uint8_t);
  ------------------
  |  |  173|    273|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 8640|    273|  uint8_t *uu____3 = serialized;
 8641|    273|  size_t uu____4 = pointer;
 8642|    273|  size_t uu____5 = pointer;
 8643|    273|  Eurydice_slice_copy(
  ------------------
  |  |  229|    273|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8644|    273|      Eurydice_array_to_subslice3(
 8645|    273|          uu____3, uu____4, uu____5 + Eurydice_slice_len(public_key, uint8_t),
 8646|    273|          uint8_t *),
 8647|    273|      public_key, uint8_t);
 8648|    273|  pointer = pointer + Eurydice_slice_len(public_key, uint8_t);
  ------------------
  |  |  173|    273|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 8649|    273|  Eurydice_slice uu____6 = Eurydice_array_to_subslice3(
  ------------------
  |  |  215|    273|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8650|    273|      serialized, pointer, pointer + LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE,
 8651|    273|      uint8_t *);
 8652|    273|  uint8_t ret[32U];
 8653|    273|  libcrux_ml_kem_hash_functions_portable_H_4a_e0(public_key, ret);
 8654|    273|  Eurydice_slice_copy(
  ------------------
  |  |  229|    273|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8655|    273|      uu____6, Eurydice_array_to_slice((size_t)32U, ret, uint8_t), uint8_t);
 8656|    273|  pointer = pointer + LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE;
  ------------------
  |  |  459|    273|#define LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE ((size_t)32U)
  ------------------
 8657|    273|  uint8_t *uu____7 = serialized;
 8658|    273|  size_t uu____8 = pointer;
 8659|    273|  size_t uu____9 = pointer;
 8660|    273|  Eurydice_slice_copy(
  ------------------
  |  |  229|    273|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8661|    273|      Eurydice_array_to_subslice3(
 8662|    273|          uu____7, uu____8,
 8663|    273|          uu____9 + Eurydice_slice_len(implicit_rejection_value, uint8_t),
 8664|    273|          uint8_t *),
 8665|    273|      implicit_rejection_value, uint8_t);
 8666|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_from_77_28:
  772|    273|libcrux_ml_kem_types_from_77_28(uint8_t value[2400U]) {
  773|       |  /* Passing arrays by value in Rust generates a copy in C */
  774|    273|  uint8_t copy_of_value[2400U];
  775|    273|  memcpy(copy_of_value, value, (size_t)2400U * sizeof(uint8_t));
  776|    273|  libcrux_ml_kem_types_MlKemPrivateKey_d9 lit;
  777|    273|  memcpy(lit.value, copy_of_value, (size_t)2400U * sizeof(uint8_t));
  778|    273|  return lit;
  779|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_from_17_74:
  757|    273|                                libcrux_ml_kem_types_MlKemPublicKey_30 pk) {
  758|    273|  return (KRML_CLITERAL(libcrux_ml_kem_mlkem768_MlKem768KeyPair){.sk = sk,
  ------------------
  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  ------------------
  759|    273|                                                                 .pk = pk});
  760|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_from_fd_d0:
  736|    273|libcrux_ml_kem_types_from_fd_d0(uint8_t value[1184U]) {
  737|       |  /* Passing arrays by value in Rust generates a copy in C */
  738|    273|  uint8_t copy_of_value[1184U];
  739|    273|  memcpy(copy_of_value, value, (size_t)1184U * sizeof(uint8_t));
  740|    273|  libcrux_ml_kem_types_MlKemPublicKey_30 lit;
  741|    273|  memcpy(lit.value, copy_of_value, (size_t)1184U * sizeof(uint8_t));
  742|    273|  return lit;
  743|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_instantiations_portable_validate_public_key_41:
 8866|    273|    uint8_t *public_key) {
 8867|    273|  return libcrux_ml_kem_ind_cca_validate_public_key_89(public_key);
 8868|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_validate_public_key_89:
 8833|    273|    uint8_t *public_key) {
 8834|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d deserialized_pk[3U];
 8835|    273|  libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_out_1b(
 8836|    273|      Eurydice_array_to_subslice_to(
  ------------------
  |  |  223|    273|  EURYDICE_SLICE((t *)x, 0, r)
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8837|    273|          (size_t)1184U, public_key,
 8838|    273|          libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U),
 8839|    273|          uint8_t, size_t, uint8_t[]),
 8840|    273|      deserialized_pk);
 8841|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d *uu____0 = deserialized_pk;
 8842|    273|  uint8_t public_key_serialized[1184U];
 8843|    273|  libcrux_ml_kem_ind_cpa_serialize_public_key_89(
 8844|    273|      uu____0,
 8845|    273|      Eurydice_array_to_subslice_from(
  ------------------
  |  |  225|    273|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|    273|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    273|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8846|    273|          (size_t)1184U, public_key,
 8847|    273|          libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U),
 8848|    273|          uint8_t, size_t, uint8_t[]),
 8849|    273|      public_key_serialized);
 8850|    273|  return Eurydice_array_eq((size_t)1184U, public_key, public_key_serialized,
  ------------------
  |  |  240|    273|#define Eurydice_array_eq(sz, a1, a2, t) (memcmp(a1, a2, sz * sizeof(t)) == 0)
  ------------------
 8851|    273|                           uint8_t);
 8852|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_out_1b:
 8802|    273|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret[3U]) {
 8803|    273|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d deserialized_pk[3U];
 8804|  1.09k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (8804:31): [True: 819, False: 273]
  ------------------
 8805|       |    /* original Rust expression is not an lvalue in C */
 8806|    819|    void *lvalue = (void *)0U;
 8807|    819|    deserialized_pk[i] =
 8808|    819|        libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_out_call_mut_0b_1b(
 8809|    819|            &lvalue, i);
 8810|    819|  }
 8811|    273|  libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_1b(
 8812|    273|      public_key, deserialized_pk);
 8813|    273|  memcpy(
 8814|    273|      ret, deserialized_pk,
 8815|    273|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 8816|    273|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_deserialize_ring_elements_reduced_out_call_mut_0b_1b:
 8783|    819|    void **_, size_t tupled_args) {
 8784|    819|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 8785|    819|}

ssh_get_random:
   48|  4.91k|{
   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|  4.91k|    (void)strong;
   56|  4.91k|#endif /* HAVE_RAND_PRIV_BYTES */
   57|       |
   58|       |    /* Returns -1 when not supported, 0 on error, 1 on success */
   59|  4.91k|    return !!RAND_bytes(where, len);
   60|  4.91k|}

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

ssh_client_hybrid_mlkem_init:
  201|    273|{
  202|    273|    struct ssh_crypto_struct *crypto = session->next_crypto;
  203|    273|    ssh_buffer client_init_buffer = NULL;
  204|    273|    int rc, ret = SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  205|       |
  206|    273|    SSH_LOG(SSH_LOG_TRACE, "Initializing hybrid ML-KEM key exchange");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  207|       |
  208|       |    /* Prepare a buffer to concatenate ML-KEM + ECDH public keys */
  209|    273|    client_init_buffer = ssh_buffer_new();
  210|    273|    if (client_init_buffer == NULL) {
  ------------------
  |  Branch (210:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_mlkem_init(session);
  217|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (217:9): [True: 0, False: 273]
  ------------------
  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|    273|    switch (crypto->kex_type) {
  230|    273|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (230:5): [True: 273, False: 0]
  ------------------
  231|    273|        rc = ssh_curve25519_init(session);
  232|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (232:13): [True: 0, False: 273]
  ------------------
  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|    273|        rc = ssh_buffer_pack(client_init_buffer,
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  244|    273|                             "PP",
  245|    273|                             ssh_string_len(crypto->mlkem_client_pubkey),
  246|    273|                             ssh_string_data(crypto->mlkem_client_pubkey),
  247|    273|                             (size_t)CURVE25519_PUBKEY_SIZE,
  248|    273|                             crypto->curve25519_client_pubkey);
  249|    273|        break;
  250|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (250:5): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  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|    273|    }
  278|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (278:9): [True: 0, False: 273]
  ------------------
  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|    273|    ssh_string_free(crypto->hybrid_client_init);
  285|    273|    crypto->hybrid_client_init = ssh_string_new(ssh_buffer_get_len(client_init_buffer));
  286|    273|    if (crypto->hybrid_client_init == NULL) {
  ------------------
  |  Branch (286:9): [True: 0, False: 273]
  ------------------
  287|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  288|      0|        goto cleanup;
  289|      0|    }
  290|       |
  291|    273|    rc = ssh_string_fill(crypto->hybrid_client_init,
  292|    273|                         ssh_buffer_get(client_init_buffer),
  293|    273|                         ssh_buffer_get_len(client_init_buffer));
  294|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (294:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  300|    273|                         "bS",
  301|    273|                         SSH2_MSG_KEX_HYBRID_INIT,
  302|    273|                         crypto->hybrid_client_init);
  303|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (303:9): [True: 0, False: 273]
  ------------------
  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|    273|    ssh_packet_set_callbacks(session, &ssh_hybrid_mlkem_client_callbacks);
  309|    273|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  310|       |
  311|    273|    rc = ssh_packet_send(session);
  312|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (312:9): [True: 0, False: 273]
  ------------------
  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|    273|    ret = SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  318|       |
  319|    273|cleanup:
  320|    273|    ssh_buffer_free(client_init_buffer);
  321|    273|    return ret;
  322|    273|}
ssh_client_hybrid_mlkem_remove_callbacks:
  531|    273|{
  532|    273|    ssh_packet_remove_callbacks(session, &ssh_hybrid_mlkem_client_callbacks);
  533|    273|}
ssh_server_hybrid_mlkem_init:
  905|    273|{
  906|    273|    SSH_LOG(SSH_LOG_TRACE, "Setting up ML-KEM hybrid server callbacks");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  907|    273|    ssh_packet_set_callbacks(session, &ssh_hybrid_mlkem_server_callbacks);
  908|    273|}
hybrid_mlkem.c:ssh_packet_client_hybrid_mlkem_reply:
  325|    273|{
  326|    273|    struct ssh_crypto_struct *crypto = session->next_crypto;
  327|    273|    const struct mlkem_type_info *mlkem_info = NULL;
  328|    273|    ssh_string pubkey_blob = NULL;
  329|    273|    ssh_string signature = NULL;
  330|    273|    ssh_mlkem_shared_secret mlkem_shared_secret;
  331|    273|    ssh_string ecdh_shared_secret = NULL;
  332|    273|    ssh_buffer server_reply_buffer = NULL;
  333|    273|    size_t read_len;
  334|    273|    size_t ecdh_server_pubkey_size;
  335|    273|    int rc;
  336|    273|    (void)type;
  337|    273|    (void)user;
  338|       |
  339|    273|    SSH_LOG(SSH_LOG_TRACE, "Received ML-KEM hybrid server reply");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  340|       |
  341|    273|    ssh_client_hybrid_mlkem_remove_callbacks(session);
  342|       |
  343|    273|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
  344|    273|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (344:9): [True: 0, False: 273]
  ------------------
  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|    273|    pubkey_blob = ssh_buffer_get_ssh_string(packet);
  351|    273|    if (pubkey_blob == NULL) {
  ------------------
  |  Branch (351:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  358|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (358:9): [True: 0, False: 273]
  ------------------
  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|    273|    ssh_string_free(crypto->hybrid_server_reply);
  366|    273|    crypto->hybrid_server_reply = ssh_buffer_get_ssh_string(packet);
  367|    273|    if (crypto->hybrid_server_reply == NULL) {
  ------------------
  |  Branch (367:9): [True: 0, False: 273]
  ------------------
  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|    273|    server_reply_buffer = ssh_buffer_new();
  374|    273|    if (server_reply_buffer == NULL) {
  ------------------
  |  Branch (374:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_buffer_add_data(server_reply_buffer,
  381|    273|                             ssh_string_data(crypto->hybrid_server_reply),
  382|    273|                             ssh_string_len(crypto->hybrid_server_reply));
  383|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (383:9): [True: 0, False: 273]
  ------------------
  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|    273|    ssh_string_free(crypto->mlkem_ciphertext);
  391|    273|    crypto->mlkem_ciphertext = ssh_string_new(mlkem_info->ciphertext_size);
  392|    273|    if (crypto->mlkem_ciphertext == NULL) {
  ------------------
  |  Branch (392:9): [True: 0, False: 273]
  ------------------
  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|    273|    read_len = ssh_buffer_get_data(server_reply_buffer,
  399|    273|                                   ssh_string_data(crypto->mlkem_ciphertext),
  400|    273|                                   mlkem_info->ciphertext_size);
  401|    273|    if (read_len != mlkem_info->ciphertext_size) {
  ------------------
  |  Branch (401:9): [True: 0, False: 273]
  ------------------
  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|    273|    switch (crypto->kex_type) {
  418|    273|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (418:5): [True: 273, False: 0]
  ------------------
  419|    273|        read_len = ssh_buffer_get_data(server_reply_buffer,
  420|    273|                                       crypto->curve25519_server_pubkey,
  421|    273|                                       CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   40|    273|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  422|    273|        if (read_len != CURVE25519_PUBKEY_SIZE) {
  ------------------
  |  |   40|    273|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  |  Branch (422:13): [True: 0, False: 273]
  ------------------
  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|    273|        if (ssh_buffer_get_len(server_reply_buffer) > 0) {
  ------------------
  |  Branch (430:13): [True: 0, False: 273]
  ------------------
  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|    273|        break;
  443|    273|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (443:5): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  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|    273|    }
  468|       |
  469|       |    /* Decapsulate ML-KEM shared secret */
  470|    273|    rc = ssh_mlkem_decapsulate(session, mlkem_shared_secret);
  471|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (471:9): [True: 0, False: 273]
  ------------------
  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|    273|    ecdh_shared_secret = derive_ecdh_secret(session);
  485|    273|    if (ecdh_shared_secret == NULL) {
  ------------------
  |  Branch (485:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = derive_hybrid_secret(session, mlkem_shared_secret, ecdh_shared_secret);
  498|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (498:9): [True: 0, False: 273]
  ------------------
  499|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  500|      0|        goto cleanup;
  501|      0|    }
  502|       |
  503|       |    /* Get signature for verification */
  504|    273|    signature = ssh_buffer_get_ssh_string(packet);
  505|    273|    if (signature == NULL) {
  ------------------
  |  Branch (505:9): [True: 0, False: 273]
  ------------------
  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|    273|    crypto->dh_server_signature = signature;
  511|       |
  512|       |    /* Send the MSG_NEWKEYS */
  513|    273|    rc = ssh_packet_send_newkeys(session);
  514|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (514:9): [True: 0, False: 273]
  ------------------
  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|    273|    session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  520|       |
  521|    273|cleanup:
  522|    273|    ssh_burn(mlkem_shared_secret, sizeof(mlkem_shared_secret));
  ------------------
  |  |  388|    273|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  523|    273|    ssh_string_burn(ecdh_shared_secret);
  524|    273|    ssh_string_free(ecdh_shared_secret);
  525|    273|    ssh_string_free(pubkey_blob);
  526|    273|    ssh_buffer_free(server_reply_buffer);
  527|    273|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    273|#define SSH_PACKET_USED 1
  ------------------
  528|    273|}
hybrid_mlkem.c:derive_ecdh_secret:
   95|    546|{
   96|    546|    ssh_string secret = NULL;
   97|       |
   98|    546|    switch (session->next_crypto->kex_type) {
   99|    546|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (99:5): [True: 546, False: 0]
  ------------------
  100|    546|        secret = derive_curve25519_secret(session);
  101|    546|        break;
  102|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (102:5): [True: 0, False: 546]
  ------------------
  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: 546]
  ------------------
  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|    546|    }
  114|       |
  115|    546|    return secret;
  116|    546|}
hybrid_mlkem.c:derive_curve25519_secret:
   49|    546|{
   50|    546|    ssh_string secret = NULL;
   51|    546|    int rc;
   52|       |
   53|    546|    secret = ssh_string_new(CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   40|    546|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
   54|    546|    if (secret == NULL) {
  ------------------
  |  Branch (54:9): [True: 0, False: 546]
  ------------------
   55|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
   56|      0|        return NULL;
   57|      0|    }
   58|       |
   59|    546|    rc = ssh_curve25519_create_k(session, ssh_string_data(secret));
   60|    546|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (60:9): [True: 0, False: 546]
  ------------------
   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|    546|    return secret;
   69|    546|}
hybrid_mlkem.c:derive_hybrid_secret:
  121|    546|{
  122|    546|    struct ssh_crypto_struct *crypto = session->next_crypto;
  123|    546|    ssh_buffer combined_secret = NULL;
  124|    546|    int (*digest)(const unsigned char *, size_t, unsigned char *) = NULL;
  125|    546|    size_t digest_len;
  126|    546|    int rc, ret = SSH_ERROR;
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  127|       |
  128|    546|    switch (crypto->kex_type) {
  129|    546|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (129:5): [True: 546, False: 0]
  ------------------
  130|    546|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (130:5): [True: 0, False: 546]
  ------------------
  131|    546|        digest = sha256;
  132|    546|        digest_len = SHA256_DIGEST_LEN;
  ------------------
  |  |   45|    546|#define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
  ------------------
  133|    546|        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: 546]
  ------------------
  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|    546|    }
  144|       |
  145|       |    /* Concatenate the two shared secrets */
  146|    546|    combined_secret = ssh_buffer_new();
  147|    546|    if (combined_secret == NULL) {
  ------------------
  |  Branch (147:9): [True: 0, False: 546]
  ------------------
  148|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  149|      0|        goto cleanup;
  150|      0|    }
  151|    546|    ssh_buffer_set_secure(combined_secret);
  152|       |
  153|    546|    rc = ssh_buffer_pack(combined_secret,
  ------------------
  |  |   50|    546|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    546|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    546|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    546|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    546|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  154|    546|                         "PP",
  155|    546|                         (size_t)MLKEM_SHARED_SECRET_SIZE,
  156|    546|                         mlkem_shared_secret,
  157|    546|                         ssh_string_len(ecdh_shared_secret),
  158|    546|                         ssh_string_data(ecdh_shared_secret));
  159|    546|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (159:9): [True: 0, False: 546]
  ------------------
  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|    546|    ssh_string_burn(crypto->hybrid_shared_secret);
  172|    546|    ssh_string_free(crypto->hybrid_shared_secret);
  173|    546|    crypto->hybrid_shared_secret = ssh_string_new(digest_len);
  174|    546|    if (crypto->hybrid_shared_secret == NULL) {
  ------------------
  |  Branch (174:9): [True: 0, False: 546]
  ------------------
  175|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  176|      0|        goto cleanup;
  177|      0|    }
  178|       |
  179|    546|    rc = digest(ssh_buffer_get(combined_secret),
  180|    546|                ssh_buffer_get_len(combined_secret),
  181|    546|                ssh_string_data(crypto->hybrid_shared_secret));
  182|    546|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (182:9): [True: 0, False: 546]
  ------------------
  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|    546|    ret = SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  194|       |
  195|    546|cleanup:
  196|    546|    ssh_buffer_free(combined_secret);
  197|    546|    return ret;
  198|    546|}
hybrid_mlkem.c:ssh_packet_server_hybrid_mlkem_init:
  551|    273|{
  552|    273|    struct ssh_crypto_struct *crypto = session->next_crypto;
  553|    273|    const struct mlkem_type_info *mlkem_info = NULL;
  554|    273|    ssh_string ecdh_shared_secret = NULL;
  555|    273|    ssh_mlkem_shared_secret mlkem_shared_secret;
  556|    273|    ssh_buffer server_reply_buffer = NULL;
  557|    273|    ssh_buffer client_init_buffer = NULL;
  558|    273|    ssh_key privkey = NULL;
  559|    273|    enum ssh_digest_e digest = SSH_DIGEST_AUTO;
  560|    273|    ssh_string signature = NULL;
  561|    273|    ssh_string pubkey_blob = NULL;
  562|    273|    size_t ecdh_client_pubkey_size;
  563|    273|    size_t read_len;
  564|    273|    int rc;
  565|    273|    (void)type;
  566|    273|    (void)user;
  567|       |
  568|    273|    SSH_LOG(SSH_LOG_TRACE, "Received ML-KEM hybrid client init");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  569|       |
  570|    273|    ssh_packet_remove_callbacks(session, &ssh_hybrid_mlkem_server_callbacks);
  571|       |
  572|    273|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
  573|    273|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (573:9): [True: 0, False: 273]
  ------------------
  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|    273|    switch (crypto->kex_type) {
  581|    273|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (581:5): [True: 273, False: 0]
  ------------------
  582|    273|        rc = ssh_curve25519_init(session);
  583|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (583:13): [True: 0, False: 273]
  ------------------
  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|    273|        break;
  595|    273|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (595:5): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  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|    273|    }
  616|       |
  617|       |    /* Get client init: ML-KEM public key + ECDH public key */
  618|    273|    ssh_string_free(crypto->hybrid_client_init);
  619|    273|    crypto->hybrid_client_init = ssh_buffer_get_ssh_string(packet);
  620|    273|    if (crypto->hybrid_client_init == NULL) {
  ------------------
  |  Branch (620:9): [True: 0, False: 273]
  ------------------
  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|    273|    client_init_buffer = ssh_buffer_new();
  627|    273|    if (client_init_buffer == NULL) {
  ------------------
  |  Branch (627:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_buffer_add_data(client_init_buffer,
  634|    273|                             ssh_string_data(crypto->hybrid_client_init),
  635|    273|                             ssh_string_len(crypto->hybrid_client_init));
  636|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (636:9): [True: 0, False: 273]
  ------------------
  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|    273|    ssh_string_free(crypto->mlkem_client_pubkey);
  644|    273|    crypto->mlkem_client_pubkey = ssh_string_new(mlkem_info->pubkey_size);
  645|    273|    if (crypto->mlkem_client_pubkey == NULL) {
  ------------------
  |  Branch (645:9): [True: 0, False: 273]
  ------------------
  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|    273|    read_len = ssh_buffer_get_data(client_init_buffer,
  652|    273|                                   ssh_string_data(crypto->mlkem_client_pubkey),
  653|    273|                                   mlkem_info->pubkey_size);
  654|    273|    if (read_len != mlkem_info->pubkey_size) {
  ------------------
  |  Branch (654:9): [True: 0, False: 273]
  ------------------
  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|    273|    switch (crypto->kex_type) {
  671|    273|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (671:5): [True: 273, False: 0]
  ------------------
  672|    273|        read_len = ssh_buffer_get_data(client_init_buffer,
  673|    273|                                       crypto->curve25519_client_pubkey,
  674|    273|                                       CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   40|    273|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  675|    273|        if (read_len != CURVE25519_PUBKEY_SIZE) {
  ------------------
  |  |   40|    273|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  |  Branch (675:13): [True: 0, False: 273]
  ------------------
  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|    273|        if (ssh_buffer_get_len(client_init_buffer) > 0) {
  ------------------
  |  Branch (683:13): [True: 0, False: 273]
  ------------------
  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|    273|        break;
  696|    273|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (696:5): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  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|    273|    }
  721|       |
  722|       |    /* Encapsulate an ML-KEM shared secret using client's ML-KEM public key */
  723|    273|    rc = ssh_mlkem_encapsulate(session, mlkem_shared_secret);
  724|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (724:9): [True: 0, False: 273]
  ------------------
  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|    273|    ecdh_shared_secret = derive_ecdh_secret(session);
  741|    273|    if (ecdh_shared_secret == NULL) {
  ------------------
  |  Branch (741:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = derive_hybrid_secret(session, mlkem_shared_secret, ecdh_shared_secret);
  754|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (754:9): [True: 0, False: 273]
  ------------------
  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|    273|    server_reply_buffer = ssh_buffer_new();
  761|    273|    if (server_reply_buffer == NULL) {
  ------------------
  |  Branch (761:9): [True: 0, False: 273]
  ------------------
  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|    273|    switch (crypto->kex_type) {
  768|    273|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (768:5): [True: 273, False: 0]
  ------------------
  769|    273|        rc = ssh_buffer_pack(server_reply_buffer,
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  770|    273|                             "PP",
  771|    273|                             ssh_string_len(crypto->mlkem_ciphertext),
  772|    273|                             ssh_string_data(crypto->mlkem_ciphertext),
  773|    273|                             (size_t)CURVE25519_PUBKEY_SIZE,
  774|    273|                             crypto->curve25519_server_pubkey);
  775|    273|        break;
  776|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (776:5): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  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|    273|    }
  791|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (791:9): [True: 0, False: 273]
  ------------------
  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|    273|    ssh_string_free(crypto->hybrid_server_reply);
  798|    273|    crypto->hybrid_server_reply = ssh_string_new(ssh_buffer_get_len(server_reply_buffer));
  799|    273|    if (crypto->hybrid_server_reply == NULL) {
  ------------------
  |  Branch (799:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_string_fill(crypto->hybrid_server_reply,
  806|    273|                         ssh_buffer_get(server_reply_buffer),
  807|    273|                         ssh_buffer_get_len(server_reply_buffer));
  808|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (808:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_KEX_HYBRID_REPLY);
  ------------------
  |  |   20|    273|#define SSH2_MSG_KEX_HYBRID_REPLY 31
  ------------------
  816|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (816:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_get_key_params(session, &privkey, &digest);
  824|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (824:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_make_sessionid(session);
  832|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (832:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_dh_get_next_server_publickey_blob(session, &pubkey_blob);
  839|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (839:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_buffer_add_ssh_string(session->out_buffer, pubkey_blob);
  847|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (847:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_buffer_add_ssh_string(session->out_buffer, crypto->hybrid_server_reply);
  855|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (855:9): [True: 0, False: 273]
  ------------------
  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|    273|    signature = ssh_srv_pki_do_sign_sessionid(session, privkey, digest);
  863|    273|    if (signature == NULL) {
  ------------------
  |  Branch (863:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_buffer_add_ssh_string(session->out_buffer, signature);
  871|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (871:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_packet_send(session);
  878|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (878:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_packet_send_newkeys(session);
  886|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (886:9): [True: 0, False: 273]
  ------------------
  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|    273|    session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  892|       |
  893|    273|cleanup:
  894|    273|    ssh_burn(mlkem_shared_secret, sizeof(mlkem_shared_secret));
  ------------------
  |  |  388|    273|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  895|    273|    ssh_string_burn(ecdh_shared_secret);
  896|    273|    ssh_string_free(ecdh_shared_secret);
  897|    273|    ssh_string_free(pubkey_blob);
  898|    273|    ssh_string_free(signature);
  899|    273|    ssh_buffer_free(client_init_buffer);
  900|    273|    ssh_buffer_free(server_reply_buffer);
  901|    273|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    273|#define SSH_PACKET_USED 1
  ------------------
  902|    273|}

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|    273|bool is_ssh_initialized(void) {
  285|       |
  286|    273|    bool is_initialized = false;
  287|       |
  288|    273|    ssh_mutex_lock(&ssh_init_mutex);
  289|    273|    is_initialized = _ssh_initialized > 0;
  290|    273|    ssh_mutex_unlock(&ssh_init_mutex);
  291|       |
  292|    273|    return is_initialized;
  293|    273|}
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|  3.27k|{
  159|       |    /* Can't use VLAs with Visual Studio, so allocate the biggest
  160|       |     * digest buffer we can possibly need */
  161|  3.27k|    unsigned char digest[DIGEST_MAX_LEN];
  162|  3.27k|    size_t output_len = crypto->digest_len;
  163|  3.27k|    ssh_mac_ctx ctx;
  164|  3.27k|    int rc;
  165|       |
  166|  3.27k|    if (DIGEST_MAX_LEN < crypto->digest_len) {
  ------------------
  |  |   56|  3.27k|#define DIGEST_MAX_LEN 64
  ------------------
  |  Branch (166:9): [True: 0, False: 3.27k]
  ------------------
  167|      0|        return -1;
  168|      0|    }
  169|       |
  170|  3.27k|    ctx = ssh_mac_ctx_init(crypto->digest_type);
  171|  3.27k|    if (ctx == NULL) {
  ------------------
  |  Branch (171:9): [True: 0, False: 3.27k]
  ------------------
  172|      0|        return -1;
  173|      0|    }
  174|       |
  175|  3.27k|    rc = ssh_mac_update(ctx, key, key_len);
  176|  3.27k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  3.27k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (176:9): [True: 0, False: 3.27k]
  ------------------
  177|      0|        ssh_mac_ctx_free(ctx);
  178|      0|        return -1;
  179|      0|    }
  180|  3.27k|    rc = ssh_mac_update(ctx, crypto->secret_hash, crypto->digest_len);
  181|  3.27k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  3.27k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (181:9): [True: 0, False: 3.27k]
  ------------------
  182|      0|        ssh_mac_ctx_free(ctx);
  183|      0|        return -1;
  184|      0|    }
  185|  3.27k|    rc = ssh_mac_update(ctx, &key_type, 1);
  186|  3.27k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  3.27k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (186:9): [True: 0, False: 3.27k]
  ------------------
  187|      0|        ssh_mac_ctx_free(ctx);
  188|      0|        return -1;
  189|      0|    }
  190|  3.27k|    rc = ssh_mac_update(ctx, crypto->session_id, crypto->session_id_len);
  191|  3.27k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  3.27k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (191:9): [True: 0, False: 3.27k]
  ------------------
  192|      0|        ssh_mac_ctx_free(ctx);
  193|      0|        return -1;
  194|      0|    }
  195|  3.27k|    rc = ssh_mac_final(digest, ctx);
  196|  3.27k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  3.27k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (196:9): [True: 0, False: 3.27k]
  ------------------
  197|      0|        return -1;
  198|      0|    }
  199|       |
  200|  3.27k|    if (requested_len < output_len) {
  ------------------
  |  Branch (200:9): [True: 1.84k, False: 1.42k]
  ------------------
  201|  1.84k|        output_len = requested_len;
  202|  1.84k|    }
  203|  3.27k|    memcpy(output, digest, output_len);
  204|       |
  205|  3.27k|    while (requested_len > output_len) {
  ------------------
  |  Branch (205:12): [True: 0, False: 3.27k]
  ------------------
  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|  3.27k|    return 0;
  238|  3.27k|}
kdf.c:ssh_mac_ctx_init:
   54|  3.27k|{
   55|  3.27k|    ssh_mac_ctx ctx = malloc(sizeof(struct ssh_mac_ctx_struct));
   56|  3.27k|    if (ctx == NULL) {
  ------------------
  |  Branch (56:9): [True: 0, False: 3.27k]
  ------------------
   57|      0|        return NULL;
   58|      0|    }
   59|       |
   60|  3.27k|    ctx->digest_type = type;
   61|  3.27k|    switch (type) {
  ------------------
  |  Branch (61:13): [True: 3.27k, False: 0]
  ------------------
   62|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (62:5): [True: 0, False: 3.27k]
  ------------------
   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|  3.27k|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (68:5): [True: 3.27k, False: 0]
  ------------------
   69|  3.27k|        ctx->ctx.sha256_ctx = sha256_init();
   70|  3.27k|        if (ctx->ctx.sha256_ctx == NULL) {
  ------------------
  |  Branch (70:13): [True: 0, False: 3.27k]
  ------------------
   71|      0|            goto err;
   72|      0|        }
   73|  3.27k|        return ctx;
   74|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (74:5): [True: 0, False: 3.27k]
  ------------------
   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: 3.27k]
  ------------------
   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|  3.27k|    }
   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|  3.27k|}
kdf.c:ssh_mac_update:
  116|  13.1k|{
  117|  13.1k|    switch (ctx->digest_type) {
  ------------------
  |  Branch (117:13): [True: 13.1k, False: 0]
  ------------------
  118|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (118:5): [True: 0, False: 13.1k]
  ------------------
  119|      0|        return sha1_update(ctx->ctx.sha1_ctx, data, len);
  120|  13.1k|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (120:5): [True: 13.1k, False: 0]
  ------------------
  121|  13.1k|        return sha256_update(ctx->ctx.sha256_ctx, data, len);
  122|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (122:5): [True: 0, False: 13.1k]
  ------------------
  123|      0|        return sha384_update(ctx->ctx.sha384_ctx, data, len);
  124|      0|    case SSH_KDF_SHA512:
  ------------------
  |  Branch (124:5): [True: 0, False: 13.1k]
  ------------------
  125|      0|        return sha512_update(ctx->ctx.sha512_ctx, data, len);
  126|  13.1k|    }
  127|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  128|  13.1k|}
kdf.c:ssh_mac_final:
  131|  3.27k|{
  132|  3.27k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  3.27k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  133|       |
  134|  3.27k|    switch (ctx->digest_type) {
  ------------------
  |  Branch (134:13): [True: 3.27k, False: 0]
  ------------------
  135|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (135:5): [True: 0, False: 3.27k]
  ------------------
  136|      0|        rc = sha1_final(md, ctx->ctx.sha1_ctx);
  137|      0|        break;
  138|  3.27k|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (138:5): [True: 3.27k, False: 0]
  ------------------
  139|  3.27k|        rc = sha256_final(md, ctx->ctx.sha256_ctx);
  140|  3.27k|        break;
  141|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (141:5): [True: 0, False: 3.27k]
  ------------------
  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: 3.27k]
  ------------------
  145|      0|        rc = sha512_final(md, ctx->ctx.sha512_ctx);
  146|      0|        break;
  147|  3.27k|    }
  148|  3.27k|    SAFE_FREE(ctx);
  ------------------
  |  |  373|  3.27k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 3.27k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 3.27k]
  |  |  ------------------
  ------------------
  149|  3.27k|    return rc;
  150|  3.27k|}

ssh_kex_get_default_methods:
  300|  2.18k|{
  301|  2.18k|    if (type >= SSH_KEX_METHODS) {
  ------------------
  |  |   27|  2.18k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (301:9): [True: 0, False: 2.18k]
  ------------------
  302|      0|        return NULL;
  303|      0|    }
  304|       |
  305|  2.18k|    return default_methods[type];
  306|  2.18k|}
ssh_packet_kexinit:
  397|    546|{
  398|    546|    int i, ok;
  399|    546|    struct ssh_crypto_struct *crypto = session->next_crypto;
  400|    546|    int server_kex = session->server;
  401|    546|    ssh_string str = NULL;
  402|    546|    char *strings[SSH_KEX_METHODS] = {0};
  403|    546|    int rc = SSH_ERROR;
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  404|    546|    size_t len;
  405|       |
  406|    546|    uint8_t first_kex_packet_follows = 0;
  407|    546|    uint32_t kexinit_reserved = 0;
  408|       |
  409|    546|    (void)type;
  410|    546|    (void)user;
  411|       |
  412|    546|    SSH_LOG(SSH_LOG_TRACE, "KEXINIT received");
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  413|       |
  414|    546|    if (session->session_state == SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (414:9): [True: 0, False: 546]
  ------------------
  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|    546|    } else if (session->session_state != SSH_SESSION_STATE_INITIAL_KEX) {
  ------------------
  |  Branch (429:16): [True: 0, False: 546]
  ------------------
  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|    546|    if (server_kex) {
  ------------------
  |  Branch (435:9): [True: 273, False: 273]
  ------------------
  436|    273|#ifdef WITH_SERVER
  437|    273|        len = ssh_buffer_get_data(packet, crypto->client_kex.cookie, 16);
  438|    273|        if (len != 16) {
  ------------------
  |  Branch (438:13): [True: 0, False: 273]
  ------------------
  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|    273|        ok = ssh_hashbufin_add_cookie(session, crypto->client_kex.cookie);
  445|    273|        if (ok < 0) {
  ------------------
  |  Branch (445:13): [True: 0, False: 273]
  ------------------
  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|    273|        ok = server_set_kex(session);
  452|    273|        if (ok == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (452:13): [True: 0, False: 273]
  ------------------
  453|      0|            goto error;
  454|      0|        }
  455|    273|#endif /* WITH_SERVER */
  456|    273|    } else {
  457|    273|        len = ssh_buffer_get_data(packet, crypto->server_kex.cookie, 16);
  458|    273|        if (len != 16) {
  ------------------
  |  Branch (458:13): [True: 0, False: 273]
  ------------------
  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|    273|        ok = ssh_hashbufin_add_cookie(session, crypto->server_kex.cookie);
  465|    273|        if (ok < 0) {
  ------------------
  |  Branch (465:13): [True: 0, False: 273]
  ------------------
  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|    273|        ok = ssh_set_client_kex(session);
  472|    273|        if (ok == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (472:13): [True: 0, False: 273]
  ------------------
  473|      0|            goto error;
  474|      0|        }
  475|    273|    }
  476|       |
  477|  5.95k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  5.95k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (477:17): [True: 5.41k, False: 546]
  ------------------
  478|  5.41k|        str = ssh_buffer_get_ssh_string(packet);
  479|  5.41k|        if (str == NULL) {
  ------------------
  |  Branch (479:13): [True: 0, False: 5.41k]
  ------------------
  480|      0|          goto error;
  481|      0|        }
  482|       |
  483|  5.41k|        rc = ssh_buffer_add_ssh_string(session->in_hashbuf, str);
  484|  5.41k|        if (rc < 0) {
  ------------------
  |  Branch (484:13): [True: 0, False: 5.41k]
  ------------------
  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|  5.41k|        strings[i] = ssh_string_to_char(str);
  491|  5.41k|        if (strings[i] == NULL) {
  ------------------
  |  Branch (491:13): [True: 0, False: 5.41k]
  ------------------
  492|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  493|      0|            goto error;
  494|      0|        }
  495|  5.41k|        SSH_STRING_FREE(str);
  ------------------
  |  |  915|  5.41k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 5.39k, False: 12]
  |  |  |  Branch (915:69): [Folded, False: 5.41k]
  |  |  ------------------
  ------------------
  496|  5.41k|        str = NULL;
  497|  5.41k|    }
  498|       |
  499|       |    /* copy the peer kex info into an array of strings */
  500|    546|    if (server_kex) {
  ------------------
  |  Branch (500:9): [True: 273, False: 273]
  ------------------
  501|    273|#ifdef WITH_SERVER
  502|  3.00k|        for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.00k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (502:21): [True: 2.73k, False: 273]
  ------------------
  503|  2.73k|            crypto->client_kex.methods[i] = strings[i];
  504|  2.73k|        }
  505|    273|#endif /* WITH_SERVER */
  506|    273|    } else { /* client */
  507|  3.00k|        for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.00k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (507:21): [True: 2.73k, False: 273]
  ------------------
  508|  2.73k|            crypto->server_kex.methods[i] = strings[i];
  509|  2.73k|        }
  510|    273|    }
  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|    546|    rc = ssh_buffer_get_u8(packet, &first_kex_packet_follows);
  524|    546|    if (rc != 1) {
  ------------------
  |  Branch (524:9): [True: 0, False: 546]
  ------------------
  525|      0|        goto error;
  526|      0|    }
  527|       |
  528|    546|    rc = ssh_buffer_add_u8(session->in_hashbuf, first_kex_packet_follows);
  529|    546|    if (rc < 0) {
  ------------------
  |  Branch (529:9): [True: 0, False: 546]
  ------------------
  530|      0|        goto error;
  531|      0|    }
  532|       |
  533|    546|    rc = ssh_buffer_add_u32(session->in_hashbuf, kexinit_reserved);
  534|    546|    if (rc < 0) {
  ------------------
  |  Branch (534:9): [True: 0, False: 546]
  ------------------
  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|    546|    if (first_kex_packet_follows || session->send_first_kex_follows) {
  ------------------
  |  Branch (544:9): [True: 1, False: 545]
  |  Branch (544:37): [True: 0, False: 545]
  ------------------
  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|    546|    if (server_kex) {
  ------------------
  |  Branch (560:9): [True: 273, False: 273]
  ------------------
  561|    273|        ok = match_group(crypto->client_kex.methods[SSH_KEX],
  562|    273|                         KEX_STRICT_CLIENT);
  ------------------
  |  |  196|    273|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  563|    273|        if (ok) {
  ------------------
  |  Branch (563:13): [True: 273, False: 0]
  ------------------
  564|    273|            SSH_LOG(SSH_LOG_DEBUG, "Client supports strict kex, enabling.");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  565|    273|            session->flags |= SSH_SESSION_FLAG_KEX_STRICT;
  ------------------
  |  |   90|    273|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  566|    273|        }
  567|    273|    } else {
  568|       |        /* client kex */
  569|    273|        ok = match_group(crypto->server_kex.methods[SSH_KEX],
  570|    273|                         KEX_STRICT_SERVER);
  ------------------
  |  |  197|    273|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  571|    273|        if (ok) {
  ------------------
  |  Branch (571:13): [True: 273, False: 0]
  ------------------
  572|    273|            SSH_LOG(SSH_LOG_DEBUG, "Server supports strict kex, enabling.");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  573|    273|            session->flags |= SSH_SESSION_FLAG_KEX_STRICT;
  ------------------
  |  |   90|    273|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  574|    273|        }
  575|    273|    }
  576|    546|#ifdef WITH_SERVER
  577|    546|    if (server_kex) {
  ------------------
  |  Branch (577:9): [True: 273, False: 273]
  ------------------
  578|       |        /*
  579|       |         * If client sent a ext-info-c message in the kex list, it supports
  580|       |         * RFC 8308 extension negotiation.
  581|       |         */
  582|    273|        ok = match_group(crypto->client_kex.methods[SSH_KEX],
  583|    273|                         KEX_EXTENSION_CLIENT);
  ------------------
  |  |  194|    273|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  584|    273|        if (ok) {
  ------------------
  |  Branch (584:13): [True: 273, False: 0]
  ------------------
  585|    273|            const char *hostkeys = NULL, *wanted_hostkeys = NULL;
  586|       |
  587|       |            /* The client supports extension negotiation */
  588|    273|            session->extensions |= SSH_EXT_NEGOTIATION;
  ------------------
  |  |  123|    273|#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|    273|            hostkeys = crypto->client_kex.methods[SSH_HOSTKEYS];
  596|    273|            wanted_hostkeys = session->opts.wanted_methods[SSH_HOSTKEYS];
  597|    273|            ok = match_group(hostkeys, "rsa-sha2-512");
  598|    273|            if (ok) {
  ------------------
  |  Branch (598:17): [True: 273, False: 0]
  ------------------
  599|       |                /* Check if rsa-sha2-512 is allowed by config */
  600|    273|                if (wanted_hostkeys != NULL) {
  ------------------
  |  Branch (600:21): [True: 273, False: 0]
  ------------------
  601|    273|                    char *is_allowed = ssh_find_matching(wanted_hostkeys,
  602|    273|                                                         "rsa-sha2-512");
  603|    273|                    if (is_allowed != NULL) {
  ------------------
  |  Branch (603:25): [True: 0, False: 273]
  ------------------
  604|      0|                        session->extensions |= SSH_EXT_SIG_RSA_SHA512;
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  605|      0|                    }
  606|    273|                    SAFE_FREE(is_allowed);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  607|    273|                }
  608|    273|            }
  609|    273|            ok = match_group(hostkeys, "rsa-sha2-256");
  610|    273|            if (ok) {
  ------------------
  |  Branch (610:17): [True: 273, False: 0]
  ------------------
  611|       |                /* Check if rsa-sha2-256 is allowed by config */
  612|    273|                if (wanted_hostkeys != NULL) {
  ------------------
  |  Branch (612:21): [True: 273, False: 0]
  ------------------
  613|    273|                    char *is_allowed = ssh_find_matching(wanted_hostkeys,
  614|    273|                                                         "rsa-sha2-256");
  615|    273|                    if (is_allowed != NULL) {
  ------------------
  |  Branch (615:25): [True: 0, False: 273]
  ------------------
  616|      0|                        session->extensions |= SSH_EXT_SIG_RSA_SHA256;
  ------------------
  |  |  125|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  617|      0|                    }
  618|    273|                    SAFE_FREE(is_allowed);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  619|    273|                }
  620|    273|            }
  621|       |
  622|       |            /*
  623|       |             * Ensure that the client preference is honored for the case
  624|       |             * both signature types are enabled.
  625|       |             */
  626|    273|            if ((session->extensions & SSH_EXT_SIG_RSA_SHA256) &&
  ------------------
  |  |  125|    273|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  |  Branch (626:17): [True: 0, False: 273]
  ------------------
  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|    273|            SSH_LOG(SSH_LOG_DEBUG, "The client supports extension "
  ------------------
  |  |  281|  1.09k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 273]
  |  |  |  Branch (281:34): [True: 0, False: 273]
  |  |  ------------------
  ------------------
  646|    273|                    "negotiation. Enabled signature algorithms: %s%s",
  647|    273|                    session->extensions & SSH_EXT_SIG_RSA_SHA256 ? "SHA256" : "",
  648|    273|                    session->extensions & SSH_EXT_SIG_RSA_SHA512 ? " SHA512" : "");
  649|    273|        }
  650|    273|    }
  651|    546|#endif /* WITH_SERVER */
  652|       |
  653|       |    /* Note, that his overwrites authenticated state in case of rekeying */
  654|    546|    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|    546|    if (session->send_first_kex_follows == false) {
  ------------------
  |  Branch (658:9): [True: 546, False: 0]
  ------------------
  659|    546|        session->dh_handshake_state = DH_STATE_INIT;
  660|    546|    }
  661|    546|    session->ssh_connection_callback(session);
  662|    546|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    546|#define SSH_PACKET_USED 1
  ------------------
  663|       |
  664|      0|error:
  665|      0|    SSH_STRING_FREE(str);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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|    546|}
ssh_list_kex:
  682|  1.09k|void ssh_list_kex(struct ssh_kex_struct *kex) {
  683|  1.09k|  int i = 0;
  684|       |
  685|       |#ifdef DEBUG_CRYPTO
  686|       |  ssh_log_hexdump("session cookie", kex->cookie, 16);
  687|       |#endif
  688|       |
  689|  12.0k|  for(i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  12.0k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (689:14): [True: 10.9k, False: 1.09k]
  ------------------
  690|  10.9k|    if (kex->methods[i] == NULL) {
  ------------------
  |  Branch (690:9): [True: 0, False: 10.9k]
  ------------------
  691|      0|      continue;
  692|      0|    }
  693|  10.9k|    SSH_LOG(SSH_LOG_FUNCTIONS, "%s: %s",
  ------------------
  |  |  281|  10.9k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  694|  10.9k|        ssh_kex_descriptions[i], kex->methods[i]);
  695|  10.9k|  }
  696|  1.09k|}
ssh_client_select_hostkeys:
  708|    273|{
  709|    273|    const char *wanted = NULL;
  710|    273|    char *wanted_without_certs = NULL;
  711|    273|    char *known_hosts_algorithms = NULL;
  712|    273|    char *known_hosts_ordered = NULL;
  713|    273|    char *new_hostkeys = NULL;
  714|    273|    char *fips_hostkeys = NULL;
  715|       |
  716|    273|    wanted = session->opts.wanted_methods[SSH_HOSTKEYS];
  717|    273|    if (wanted == NULL) {
  ------------------
  |  Branch (717:9): [True: 273, False: 0]
  ------------------
  718|    273|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|    273|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 273]
  |  |  ------------------
  ------------------
  719|      0|            wanted = ssh_kex_get_fips_methods(SSH_HOSTKEYS);
  720|    273|        } else {
  721|    273|            wanted = ssh_kex_get_default_methods(SSH_HOSTKEYS);
  722|    273|        }
  723|    273|    }
  724|       |
  725|       |    /* This removes the certificate types, unsupported for now */
  726|    273|    wanted_without_certs = ssh_find_all_matching(HOSTKEYS, wanted);
  ------------------
  |  |  142|    273|#define HOSTKEYS "ssh-ed25519," \
  |  |  143|    273|                 EC_HOSTKEYS \
  |  |  144|    273|                 "sk-ssh-ed25519@openssh.com," \
  |  |  145|    273|                 EC_SK_HOSTKEYS \
  |  |  146|    273|                 "rsa-sha2-512," \
  |  |  147|    273|                 "rsa-sha2-256," \
  |  |  148|    273|                 "ssh-rsa"
  ------------------
  727|    273|    if (wanted_without_certs == NULL) {
  ------------------
  |  Branch (727:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  735|    273|            "Order of wanted host keys: \"%s\"",
  736|    273|            wanted_without_certs);
  737|       |
  738|    273|    known_hosts_algorithms = ssh_known_hosts_get_algorithms_names(session);
  739|    273|    if (known_hosts_algorithms == NULL) {
  ------------------
  |  Branch (739:9): [True: 273, False: 0]
  ------------------
  740|    273|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  741|    273|                "No key found in known_hosts; "
  742|    273|                "changing host key method to \"%s\"",
  743|    273|                wanted_without_certs);
  744|       |
  745|    273|        return wanted_without_certs;
  746|    273|    }
  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|    546|{
  802|    546|    struct ssh_kex_struct *client = &session->next_crypto->client_kex;
  803|    546|    const char *wanted = NULL;
  804|    546|    int ok;
  805|    546|    int i;
  806|    546|    bool gssapi_null_alg = false;
  807|    546|    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|    546|    if (client->methods[0] != NULL) {
  ------------------
  |  Branch (811:9): [True: 273, False: 273]
  ------------------
  812|    273|        return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  813|    273|    }
  814|       |
  815|    273|    ok = ssh_get_random(client->cookie, 16, 0);
  816|    273|    if (!ok) {
  ------------------
  |  Branch (816:9): [True: 0, False: 273]
  ------------------
  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|  3.00k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.00k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (859:17): [True: 2.73k, False: 273]
  ------------------
  860|  2.73k|        if (i == SSH_HOSTKEYS) {
  ------------------
  |  Branch (860:13): [True: 273, False: 2.45k]
  ------------------
  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|    273|            client->methods[i] = ssh_client_select_hostkeys(session);
  865|    273|            if (client->methods[i] == NULL) {
  ------------------
  |  Branch (865:17): [True: 0, False: 273]
  ------------------
  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|    273|            if (gssapi_null_alg) {
  ------------------
  |  Branch (869:17): [True: 0, False: 273]
  ------------------
  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|    273|            continue;
  880|    273|        }
  881|       |
  882|  2.45k|        wanted = session->opts.wanted_methods[i];
  883|  2.45k|        if (wanted == NULL) {
  ------------------
  |  Branch (883:13): [True: 1.36k, False: 1.09k]
  ------------------
  884|  1.36k|            if (ssh_fips_mode()) {
  ------------------
  |  |  115|  1.36k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 1.36k]
  |  |  ------------------
  ------------------
  885|      0|                wanted = fips_methods[i];
  886|  1.36k|            } else {
  887|  1.36k|                wanted = default_methods[i];
  888|  1.36k|            }
  889|  1.36k|        }
  890|  2.45k|        client->methods[i] = strdup(wanted);
  891|  2.45k|        if (client->methods[i] == NULL) {
  ------------------
  |  Branch (891:13): [True: 0, False: 2.45k]
  ------------------
  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|  2.45k|    }
  896|       |
  897|       |    /* For rekeying, skip the extension negotiation */
  898|    273|    if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) {
  ------------------
  |  |   78|    273|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (898:9): [True: 0, False: 273]
  ------------------
  899|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  900|      0|    }
  901|       |
  902|    273|    ok = ssh_kex_append_extensions(session, client);
  903|    273|    if (ok != SSH_OK){
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (903:9): [True: 0, False: 273]
  ------------------
  904|      0|        return ok;
  905|      0|    }
  906|       |
  907|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  908|    273|}
ssh_kex_append_extensions:
  911|    546|{
  912|    546|    char *kex = NULL;
  913|    546|    char *kex_tmp = NULL;
  914|    546|    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|    546|    kex = pkex->methods[SSH_KEX];
  920|    546|    len = strlen(kex);
  921|    546|    if (session->server) {
  ------------------
  |  Branch (921:9): [True: 273, False: 273]
  ------------------
  922|       |        /* Comma, nul byte */
  923|    273|        kex_len = len + 1 + strlen(KEX_STRICT_SERVER) + 1;
  ------------------
  |  |  197|    273|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  924|    273|    } else {
  925|       |        /* Comma, comma, nul byte */
  926|    273|        kex_len = len + 1 + strlen(KEX_EXTENSION_CLIENT) + 1 +
  ------------------
  |  |  194|    273|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  927|    273|                  strlen(KEX_STRICT_CLIENT) + 1;
  ------------------
  |  |  196|    273|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  928|    273|    }
  929|    546|    if (kex_len >= MAX_PACKET_LEN) {
  ------------------
  |  |  216|    546|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (929:9): [True: 0, False: 546]
  ------------------
  930|       |        /* Overflow */
  931|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  932|      0|    }
  933|    546|    kex_tmp = realloc(kex, kex_len);
  934|    546|    if (kex_tmp == NULL) {
  ------------------
  |  Branch (934:9): [True: 0, False: 546]
  ------------------
  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|    546|    if (session->server){
  ------------------
  |  Branch (938:9): [True: 273, False: 273]
  ------------------
  939|    273|        snprintf(kex_tmp + len, kex_len - len, ",%s", KEX_STRICT_SERVER);
  ------------------
  |  |  197|    273|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  940|    273|    } else {
  941|    273|        snprintf(kex_tmp + len,
  942|    273|                 kex_len - len,
  943|    273|                 ",%s,%s",
  944|    273|                 KEX_EXTENSION_CLIENT,
  ------------------
  |  |  194|    273|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  945|    273|                 KEX_STRICT_CLIENT);
  ------------------
  |  |  196|    273|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  946|    273|    }
  947|    546|    pkex->methods[SSH_KEX] = kex_tmp;
  948|    546|    return SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  949|    546|}
ssh_kex_select_methods:
 1082|    546|{
 1083|    546|    struct ssh_crypto_struct *crypto = session->next_crypto;
 1084|    546|    struct ssh_kex_struct *server = &crypto->server_kex;
 1085|    546|    struct ssh_kex_struct *client = &crypto->client_kex;
 1086|    546|    char *ext_start = NULL;
 1087|    546|    const char *aead_hmac = NULL;
 1088|    546|    enum ssh_key_exchange_e kex_type;
 1089|    546|    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|    546|    if (session->client) {
  ------------------
  |  Branch (1093:9): [True: 273, False: 273]
  ------------------
 1094|    273|        ext_start = strstr(client->methods[SSH_KEX], "," KEX_EXTENSION_CLIENT);
  ------------------
  |  |  194|    273|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
 1095|    273|        if (ext_start != NULL) {
  ------------------
  |  Branch (1095:13): [True: 273, False: 0]
  ------------------
 1096|    273|            ext_start[0] = '\0';
 1097|    273|        }
 1098|    273|    }
 1099|    546|    if (session->server) {
  ------------------
  |  Branch (1099:9): [True: 273, False: 273]
  ------------------
 1100|    273|        ext_start = strstr(server->methods[SSH_KEX], "," KEX_STRICT_SERVER);
  ------------------
  |  |  197|    273|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
 1101|    273|        if (ext_start != NULL) {
  ------------------
  |  Branch (1101:13): [True: 273, False: 0]
  ------------------
 1102|    273|            ext_start[0] = '\0';
 1103|    273|        }
 1104|    273|    }
 1105|       |
 1106|  5.98k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  5.98k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (1106:17): [True: 5.43k, False: 546]
  ------------------
 1107|  5.43k|        crypto->kex_methods[i] = ssh_find_matching(server->methods[i],
 1108|  5.43k|                                                   client->methods[i]);
 1109|       |
 1110|  5.43k|        if (i == SSH_MAC_C_S || i == SSH_MAC_S_C) {
  ------------------
  |  Branch (1110:13): [True: 524, False: 4.91k]
  |  Branch (1110:33): [True: 546, False: 4.36k]
  ------------------
 1111|  1.09k|            aead_hmac = ssh_find_aead_hmac(crypto->kex_methods[i - 2]);
 1112|  1.09k|            if (aead_hmac) {
  ------------------
  |  Branch (1112:17): [True: 0, False: 1.09k]
  ------------------
 1113|      0|                free(crypto->kex_methods[i]);
 1114|      0|                crypto->kex_methods[i] = strdup(aead_hmac);
 1115|      0|            }
 1116|  1.09k|        }
 1117|  5.43k|        if (crypto->kex_methods[i] == NULL && i < SSH_LANG_C_S) {
  ------------------
  |  Branch (1117:13): [True: 0, False: 5.43k]
  |  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|  5.43k|        } else if ((i >= SSH_LANG_C_S) && (crypto->kex_methods[i] == NULL)) {
  ------------------
  |  Branch (1123:20): [True: 1.09k, False: 4.34k]
  |  Branch (1123:43): [True: 0, False: 1.09k]
  ------------------
 1124|       |            /* we can safely do that for languages */
 1125|      0|            crypto->kex_methods[i] = strdup("");
 1126|      0|        }
 1127|  5.43k|    }
 1128|       |
 1129|       |    /* We can not set this value directly as the old value is needed to revert
 1130|       |     * callbacks if we are client */
 1131|    546|    kex_type = kex_select_kex_type(crypto->kex_methods[SSH_KEX]);
 1132|    546|    if (session->client && session->first_kex_follows_guess_wrong) {
  ------------------
  |  Branch (1132:9): [True: 273, False: 273]
  |  Branch (1132:28): [True: 0, False: 273]
  ------------------
 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|    546|    crypto->kex_type = kex_type;
 1140|       |
 1141|    546|    SSH_LOG(SSH_LOG_DEBUG, "Negotiated %s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1142|    546|            session->next_crypto->kex_methods[SSH_KEX],
 1143|    546|            session->next_crypto->kex_methods[SSH_HOSTKEYS],
 1144|    546|            session->next_crypto->kex_methods[SSH_CRYPT_C_S],
 1145|    546|            session->next_crypto->kex_methods[SSH_CRYPT_S_C],
 1146|    546|            session->next_crypto->kex_methods[SSH_MAC_C_S],
 1147|    546|            session->next_crypto->kex_methods[SSH_MAC_S_C],
 1148|    546|            session->next_crypto->kex_methods[SSH_COMP_C_S],
 1149|    546|            session->next_crypto->kex_methods[SSH_COMP_S_C],
 1150|    546|            session->next_crypto->kex_methods[SSH_LANG_C_S],
 1151|    546|            session->next_crypto->kex_methods[SSH_LANG_S_C]
 1152|    546|    );
 1153|    546|    return SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
 1154|    546|}
ssh_send_kex:
 1159|    546|{
 1160|    546|    struct ssh_kex_struct *kex = (session->server ?
  ------------------
  |  Branch (1160:35): [True: 273, False: 273]
  ------------------
 1161|    273|        &session->next_crypto->server_kex :
 1162|    546|        &session->next_crypto->client_kex);
 1163|    546|    ssh_string str = NULL;
 1164|    546|    int i;
 1165|    546|    int rc;
 1166|    546|    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|    546|    if (session->client &&
  ------------------
  |  Branch (1170:9): [True: 273, False: 273]
  ------------------
 1171|    273|        session->session_state != SSH_SESSION_STATE_KEXINIT_RECEIVED &&
  ------------------
  |  Branch (1171:9): [True: 273, False: 0]
  ------------------
 1172|    273|        session->send_first_kex_follows) {
  ------------------
  |  Branch (1172:9): [True: 0, False: 273]
  ------------------
 1173|      0|        first_kex_packet_follows = 1;
 1174|      0|    }
 1175|       |
 1176|    546|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1177|    546|            "Sending KEXINIT packet, first_kex_packet_follows = %d",
 1178|    546|            first_kex_packet_follows);
 1179|       |
 1180|    546|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    546|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    546|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    546|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    546|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    546|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1181|    546|                         "bP",
 1182|    546|                         SSH2_MSG_KEXINIT,
 1183|    546|                         (size_t)16,
 1184|    546|                         kex->cookie); /* cookie */
 1185|    546|    if (rc != SSH_OK)
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1185:9): [True: 0, False: 546]
  ------------------
 1186|      0|        goto error;
 1187|    546|    if (ssh_hashbufout_add_cookie(session) < 0) {
  ------------------
  |  Branch (1187:9): [True: 0, False: 546]
  ------------------
 1188|      0|        goto error;
 1189|      0|    }
 1190|       |
 1191|    546|    ssh_list_kex(kex);
 1192|       |
 1193|  6.00k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  6.00k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (1193:17): [True: 5.45k, False: 546]
  ------------------
 1194|  5.45k|        str = ssh_string_from_char(kex->methods[i]);
 1195|  5.45k|        if (str == NULL) {
  ------------------
  |  Branch (1195:13): [True: 0, False: 5.45k]
  ------------------
 1196|      0|            goto error;
 1197|      0|        }
 1198|       |
 1199|  5.45k|        rc = ssh_buffer_add_ssh_string(session->out_hashbuf, str);
 1200|  5.45k|        if (rc < 0) {
  ------------------
  |  Branch (1200:13): [True: 0, False: 5.45k]
  ------------------
 1201|      0|            goto error;
 1202|      0|        }
 1203|  5.45k|        rc = ssh_buffer_add_ssh_string(session->out_buffer, str);
 1204|  5.45k|        if (rc < 0) {
  ------------------
  |  Branch (1204:13): [True: 0, False: 5.45k]
  ------------------
 1205|      0|            goto error;
 1206|      0|        }
 1207|  5.45k|        SSH_STRING_FREE(str);
  ------------------
  |  |  915|  5.45k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 5.45k, False: 2]
  |  |  |  Branch (915:69): [Folded, False: 5.45k]
  |  |  ------------------
  ------------------
 1208|  5.45k|        str = NULL;
 1209|  5.45k|    }
 1210|       |
 1211|    546|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    546|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    546|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    546|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    546|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    546|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1212|    546|                         "bd",
 1213|    546|                         first_kex_packet_follows,
 1214|    546|                         0);
 1215|    546|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1215:9): [True: 0, False: 546]
  ------------------
 1216|      0|        goto error;
 1217|      0|    }
 1218|       |
 1219|       |    /* Prepare also the first_kex_packet_follows and reserved to 0 */
 1220|    546|    rc = ssh_buffer_add_u8(session->out_hashbuf, first_kex_packet_follows);
 1221|    546|    if (rc < 0) {
  ------------------
  |  Branch (1221:9): [True: 0, False: 546]
  ------------------
 1222|      0|        goto error;
 1223|      0|    }
 1224|    546|    rc = ssh_buffer_add_u32(session->out_hashbuf, 0);
 1225|    546|    if (rc < 0) {
  ------------------
  |  Branch (1225:9): [True: 0, False: 546]
  ------------------
 1226|      0|        goto error;
 1227|      0|    }
 1228|       |
 1229|    546|    rc = ssh_packet_send(session);
 1230|    546|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1230:9): [True: 0, False: 546]
  ------------------
 1231|      0|        return -1;
 1232|      0|    }
 1233|       |
 1234|    546|    session->flags |= SSH_SESSION_FLAG_KEXINIT_SENT;
  ------------------
  |  |   86|    546|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
 1235|    546|    SSH_LOG(SSH_LOG_PACKET, "SSH_MSG_KEXINIT sent");
  ------------------
  |  |  281|    546|    _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|    546|    if (first_kex_packet_follows == 1) {
  ------------------
  |  Branch (1239:9): [True: 0, False: 546]
  ------------------
 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|    546|    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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1266|       |
 1267|      0|    return -1;
 1268|    546|}
ssh_keep_known_algos:
 1324|  2.45k|{
 1325|  2.45k|    if (algo > SSH_LANG_S_C) {
  ------------------
  |  Branch (1325:9): [True: 0, False: 2.45k]
  ------------------
 1326|      0|        return NULL;
 1327|      0|    }
 1328|       |
 1329|  2.45k|    return ssh_find_all_matching(supported_methods[algo], list);
 1330|  2.45k|}
ssh_make_sessionid:
 1459|    546|{
 1460|    546|    ssh_string num = NULL;
 1461|    546|    ssh_buffer server_hash = NULL;
 1462|    546|    ssh_buffer client_hash = NULL;
 1463|    546|    ssh_buffer buf = NULL;
 1464|    546|    ssh_string server_pubkey_blob = NULL;
 1465|    546|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
 1466|    546|    const_bignum client_pubkey, server_pubkey;
 1467|       |#else
 1468|       |    bignum client_pubkey = NULL, server_pubkey = NULL;
 1469|       |#endif /* OPENSSL_VERSION_NUMBER */
 1470|    546|#ifdef WITH_GEX
 1471|    546|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
 1472|    546|    const_bignum modulus, generator;
 1473|       |#else
 1474|       |    bignum modulus = NULL, generator = NULL;
 1475|       |#endif /* OPENSSL_VERSION_NUMBER */
 1476|    546|#endif /* WITH_GEX */
 1477|    546|    int rc = SSH_ERROR;
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1478|       |
 1479|    546|    buf = ssh_buffer_new();
 1480|    546|    if (buf == NULL) {
  ------------------
  |  Branch (1480:9): [True: 0, False: 546]
  ------------------
 1481|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1482|      0|        return rc;
 1483|      0|    }
 1484|       |
 1485|    546|    rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|    546|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    546|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    546|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    546|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    546|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1486|    546|                         "ss",
 1487|    546|                         session->clientbanner,
 1488|    546|                         session->serverbanner);
 1489|    546|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1489:9): [True: 0, False: 546]
  ------------------
 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|    546|    if (session->client) {
  ------------------
  |  Branch (1496:9): [True: 273, False: 273]
  ------------------
 1497|    273|        server_hash = session->in_hashbuf;
 1498|    273|        client_hash = session->out_hashbuf;
 1499|    273|    } else {
 1500|    273|        server_hash = session->out_hashbuf;
 1501|    273|        client_hash = session->in_hashbuf;
 1502|    273|    }
 1503|       |
 1504|    546|    rc = ssh_dh_get_next_server_publickey_blob(session, &server_pubkey_blob);
 1505|    546|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1505:9): [True: 0, False: 546]
  ------------------
 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|    546|    if (server_pubkey_blob == NULL) {
  ------------------
  |  Branch (1512:9): [True: 0, False: 546]
  ------------------
 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|    546|    rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|    546|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    546|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    546|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    546|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    546|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1525|    546|                         "dPdPS",
 1526|    546|                         ssh_buffer_get_len(client_hash),
 1527|    546|                         (size_t)ssh_buffer_get_len(client_hash),
 1528|    546|                         ssh_buffer_get(client_hash),
 1529|    546|                         ssh_buffer_get_len(server_hash),
 1530|    546|                         (size_t)ssh_buffer_get_len(server_hash),
 1531|    546|                         ssh_buffer_get(server_hash),
 1532|    546|                         server_pubkey_blob);
 1533|    546|    SSH_STRING_FREE(server_pubkey_blob);
  ------------------
  |  |  915|    546|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 546, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
 1534|    546|    if (rc != SSH_OK){
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1534:9): [True: 0, False: 546]
  ------------------
 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|    546|    switch(session->next_crypto->kex_type) {
 1542|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1542:5): [True: 0, False: 546]
  ------------------
 1543|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1543:5): [True: 0, False: 546]
  ------------------
 1544|      0|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1544:5): [True: 0, False: 546]
  ------------------
 1545|      0|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1545:5): [True: 0, False: 546]
  ------------------
 1546|      0|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1546:5): [True: 0, False: 546]
  ------------------
 1547|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1547:5): [True: 0, False: 546]
  ------------------
 1548|      0|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1548:5): [True: 0, False: 546]
  ------------------
 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: 546]
  ------------------
 1574|      0|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1574:5): [True: 0, False: 546]
  ------------------
 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: 546]
  ------------------
 1611|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1611:5): [True: 0, False: 546]
  ------------------
 1612|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1612:5): [True: 0, False: 546]
  ------------------
 1613|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1613:5): [True: 0, False: 546]
  ------------------
 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: 546]
  ------------------
 1631|      0|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1631:5): [True: 0, False: 546]
  ------------------
 1632|      0|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1632:5): [True: 0, False: 546]
  ------------------
 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: 546]
  ------------------
 1652|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1652:5): [True: 0, False: 546]
  ------------------
 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|    546|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1674:5): [True: 546, False: 0]
  ------------------
 1675|    546|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1675:5): [True: 0, False: 546]
  ------------------
 1676|       |#ifdef HAVE_MLKEM1024
 1677|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1678|       |#endif
 1679|    546|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|    546|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    546|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    546|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    546|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    546|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1680|    546|                             "SS",
 1681|    546|                             session->next_crypto->hybrid_client_init,
 1682|    546|                             session->next_crypto->hybrid_server_reply);
 1683|    546|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1683:13): [True: 0, False: 546]
  ------------------
 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|    546|        break;
 1690|    546|    default:
  ------------------
  |  Branch (1690:5): [True: 0, False: 546]
  ------------------
 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|    546|    }
 1696|    546|    switch (session->next_crypto->kex_type) {
 1697|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1697:5): [True: 0, False: 546]
  ------------------
 1698|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1698:5): [True: 0, False: 546]
  ------------------
 1699|    546|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1699:5): [True: 546, False: 0]
  ------------------
 1700|    546|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1700:5): [True: 0, False: 546]
  ------------------
 1701|       |#ifdef HAVE_MLKEM1024
 1702|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1703|       |#endif
 1704|    546|        rc = ssh_buffer_pack(buf, "S", session->next_crypto->hybrid_shared_secret);
  ------------------
  |  |   50|    546|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    546|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    546|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    546|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    546|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    546|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1705|    546|        break;
 1706|      0|    default:
  ------------------
  |  Branch (1706:5): [True: 0, False: 546]
  ------------------
 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|    546|    }
 1710|    546|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1710:9): [True: 0, False: 546]
  ------------------
 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|    546|    rc = SSH_ERROR;
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1721|    546|    switch (session->next_crypto->kex_type) {
 1722|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1722:5): [True: 0, False: 546]
  ------------------
 1723|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1723:5): [True: 0, False: 546]
  ------------------
 1724|      0|#ifdef WITH_GEX
 1725|      0|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (1725:5): [True: 0, False: 546]
  ------------------
 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: 546]
  ------------------
 1738|      0|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1738:5): [True: 0, False: 546]
  ------------------
 1739|      0|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (1739:5): [True: 0, False: 546]
  ------------------
 1740|      0|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1740:5): [True: 0, False: 546]
  ------------------
 1741|      0|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1741:5): [True: 0, False: 546]
  ------------------
 1742|    546|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1742:5): [True: 546, False: 0]
  ------------------
 1743|    546|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1743:5): [True: 0, False: 546]
  ------------------
 1744|    546|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1744:5): [True: 0, False: 546]
  ------------------
 1745|    546|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1745:5): [True: 0, False: 546]
  ------------------
 1746|    546|#ifdef WITH_GEX
 1747|    546|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1747:5): [True: 0, False: 546]
  ------------------
 1748|    546|#endif /* WITH_GEX */
 1749|    546|        session->next_crypto->digest_len = SHA256_DIGEST_LENGTH;
 1750|    546|        session->next_crypto->digest_type = SSH_KDF_SHA256;
 1751|    546|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1752|    546|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1752:13): [True: 0, False: 546]
  ------------------
 1753|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1754|      0|            goto error;
 1755|      0|        }
 1756|    546|        sha256(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
 1757|    546|                                     session->next_crypto->secret_hash);
 1758|    546|        break;
 1759|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1759:5): [True: 0, False: 546]
  ------------------
 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: 546]
  ------------------
 1774|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1774:5): [True: 0, False: 546]
  ------------------
 1775|      0|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1775:5): [True: 0, False: 546]
  ------------------
 1776|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1776:5): [True: 0, False: 546]
  ------------------
 1777|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1777:5): [True: 0, False: 546]
  ------------------
 1778|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1778:5): [True: 0, False: 546]
  ------------------
 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: 546]
  ------------------
 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|    546|    }
 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|    546|    if (!session->next_crypto->session_id) {
  ------------------
  |  Branch (1801:9): [True: 546, False: 0]
  ------------------
 1802|    546|        session->next_crypto->session_id = malloc(session->next_crypto->digest_len);
 1803|    546|        if (session->next_crypto->session_id == NULL) {
  ------------------
  |  Branch (1803:13): [True: 0, False: 546]
  ------------------
 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|    546|        memcpy(session->next_crypto->session_id, session->next_crypto->secret_hash,
 1809|    546|                session->next_crypto->digest_len);
 1810|       |	/* Initial length is the same as secret hash */
 1811|    546|	session->next_crypto->session_id_len = session->next_crypto->digest_len;
 1812|    546|    }
 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|    546|    rc = SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
 1820|    546|error:
 1821|    546|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|    546|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 546, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
 1822|    546|    SSH_BUFFER_FREE(client_hash);
  ------------------
  |  |  957|    546|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 546, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
 1823|    546|    SSH_BUFFER_FREE(server_hash);
  ------------------
  |  |  957|    546|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 546, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
 1824|       |
 1825|    546|    session->in_hashbuf = NULL;
 1826|    546|    session->out_hashbuf = NULL;
 1827|       |
 1828|    546|    SSH_STRING_FREE(num);
  ------------------
  |  |  915|    546|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 546]
  |  |  |  Branch (915:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
 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|    546|    return rc;
 1835|    546|}
ssh_hashbufout_add_cookie:
 1838|    546|{
 1839|    546|    int rc;
 1840|       |
 1841|    546|    session->out_hashbuf = ssh_buffer_new();
 1842|    546|    if (session->out_hashbuf == NULL) {
  ------------------
  |  Branch (1842:9): [True: 0, False: 546]
  ------------------
 1843|      0|        return -1;
 1844|      0|    }
 1845|       |
 1846|    546|    rc = ssh_buffer_allocate_size(session->out_hashbuf,
 1847|    546|            sizeof(uint8_t) + 16);
 1848|    546|    if (rc < 0) {
  ------------------
  |  Branch (1848:9): [True: 0, False: 546]
  ------------------
 1849|      0|        ssh_buffer_reinit(session->out_hashbuf);
 1850|      0|        return -1;
 1851|      0|    }
 1852|       |
 1853|    546|    if (ssh_buffer_add_u8(session->out_hashbuf, 20) < 0) {
  ------------------
  |  Branch (1853:9): [True: 0, False: 546]
  ------------------
 1854|      0|        ssh_buffer_reinit(session->out_hashbuf);
 1855|      0|        return -1;
 1856|      0|    }
 1857|       |
 1858|    546|    if (session->server) {
  ------------------
  |  Branch (1858:9): [True: 273, False: 273]
  ------------------
 1859|    273|        if (ssh_buffer_add_data(session->out_hashbuf,
  ------------------
  |  Branch (1859:13): [True: 0, False: 273]
  ------------------
 1860|    273|                    session->next_crypto->server_kex.cookie, 16) < 0) {
 1861|      0|            ssh_buffer_reinit(session->out_hashbuf);
 1862|      0|            return -1;
 1863|      0|        }
 1864|    273|    } else {
 1865|    273|        if (ssh_buffer_add_data(session->out_hashbuf,
  ------------------
  |  Branch (1865:13): [True: 0, False: 273]
  ------------------
 1866|    273|                    session->next_crypto->client_kex.cookie, 16) < 0) {
 1867|      0|            ssh_buffer_reinit(session->out_hashbuf);
 1868|      0|            return -1;
 1869|      0|        }
 1870|    273|    }
 1871|       |
 1872|    546|    return 0;
 1873|    546|}
ssh_hashbufin_add_cookie:
 1876|    546|{
 1877|    546|    int rc;
 1878|       |
 1879|    546|    session->in_hashbuf = ssh_buffer_new();
 1880|    546|    if (session->in_hashbuf == NULL) {
  ------------------
  |  Branch (1880:9): [True: 0, False: 546]
  ------------------
 1881|      0|        return -1;
 1882|      0|    }
 1883|       |
 1884|    546|    rc = ssh_buffer_allocate_size(session->in_hashbuf,
 1885|    546|            sizeof(uint8_t) + 20 + 16);
 1886|    546|    if (rc < 0) {
  ------------------
  |  Branch (1886:9): [True: 0, False: 546]
  ------------------
 1887|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1888|      0|        return -1;
 1889|      0|    }
 1890|       |
 1891|    546|    if (ssh_buffer_add_u8(session->in_hashbuf, 20) < 0) {
  ------------------
  |  Branch (1891:9): [True: 0, False: 546]
  ------------------
 1892|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1893|      0|        return -1;
 1894|      0|    }
 1895|    546|    if (ssh_buffer_add_data(session->in_hashbuf,cookie, 16) < 0) {
  ------------------
  |  Branch (1895:9): [True: 0, False: 546]
  ------------------
 1896|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1897|      0|        return -1;
 1898|      0|    }
 1899|       |
 1900|    546|    return 0;
 1901|    546|}
ssh_generate_session_keys:
 1904|    546|{
 1905|    546|    ssh_string k_string = NULL;
 1906|    546|    struct ssh_crypto_struct *crypto = session->next_crypto;
 1907|    546|    unsigned char *key = NULL;
 1908|    546|    unsigned char *IV_cli_to_srv = NULL;
 1909|    546|    unsigned char *IV_srv_to_cli = NULL;
 1910|    546|    unsigned char *enckey_cli_to_srv = NULL;
 1911|    546|    unsigned char *enckey_srv_to_cli = NULL;
 1912|    546|    unsigned char *intkey_cli_to_srv = NULL;
 1913|    546|    unsigned char *intkey_srv_to_cli = NULL;
 1914|    546|    size_t key_len = 0;
 1915|    546|    size_t IV_len = 0;
 1916|    546|    size_t enckey_cli_to_srv_len = 0;
 1917|    546|    size_t enckey_srv_to_cli_len = 0;
 1918|    546|    size_t intkey_cli_to_srv_len = 0;
 1919|    546|    size_t intkey_srv_to_cli_len = 0;
 1920|    546|    int rc = -1;
 1921|       |
 1922|    546|    switch (session->next_crypto->kex_type) {
 1923|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1923:5): [True: 0, False: 546]
  ------------------
 1924|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1924:5): [True: 0, False: 546]
  ------------------
 1925|    546|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1925:5): [True: 546, False: 0]
  ------------------
 1926|    546|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1926:5): [True: 0, False: 546]
  ------------------
 1927|       |#ifdef HAVE_MLKEM1024
 1928|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1929|       |#endif
 1930|    546|        k_string = ssh_string_copy(crypto->hybrid_shared_secret);
 1931|    546|        break;
 1932|      0|    default:
  ------------------
  |  Branch (1932:5): [True: 0, False: 546]
  ------------------
 1933|      0|        k_string = ssh_make_bignum_string(crypto->shared_secret);
 1934|      0|        break;
 1935|    546|    }
 1936|    546|    if (k_string == NULL) {
  ------------------
  |  Branch (1936:9): [True: 0, False: 546]
  ------------------
 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|    546|    key = (unsigned char *)k_string;
 1943|    546|    key_len = ssh_string_len(k_string) + 4;
 1944|       |
 1945|    546|    IV_len = crypto->digest_len;
 1946|    546|    if (session->client) {
  ------------------
  |  Branch (1946:9): [True: 273, False: 273]
  ------------------
 1947|    273|        enckey_cli_to_srv_len = crypto->out_cipher->keysize / 8;
 1948|    273|        enckey_srv_to_cli_len = crypto->in_cipher->keysize / 8;
 1949|    273|        intkey_cli_to_srv_len = hmac_digest_len(crypto->out_hmac);
 1950|    273|        intkey_srv_to_cli_len = hmac_digest_len(crypto->in_hmac);
 1951|    273|    } else {
 1952|    273|        enckey_cli_to_srv_len = crypto->in_cipher->keysize / 8;
 1953|    273|        enckey_srv_to_cli_len = crypto->out_cipher->keysize / 8;
 1954|    273|        intkey_cli_to_srv_len = hmac_digest_len(crypto->in_hmac);
 1955|    273|        intkey_srv_to_cli_len = hmac_digest_len(crypto->out_hmac);
 1956|    273|    }
 1957|       |
 1958|    546|    IV_cli_to_srv = malloc(IV_len);
 1959|    546|    IV_srv_to_cli = malloc(IV_len);
 1960|    546|    enckey_cli_to_srv = malloc(enckey_cli_to_srv_len);
 1961|    546|    enckey_srv_to_cli = malloc(enckey_srv_to_cli_len);
 1962|    546|    intkey_cli_to_srv = malloc(intkey_cli_to_srv_len);
 1963|    546|    intkey_srv_to_cli = malloc(intkey_srv_to_cli_len);
 1964|    546|    if (IV_cli_to_srv == NULL || IV_srv_to_cli == NULL ||
  ------------------
  |  Branch (1964:9): [True: 0, False: 546]
  |  Branch (1964:34): [True: 0, False: 546]
  ------------------
 1965|    546|        enckey_cli_to_srv == NULL || enckey_srv_to_cli == NULL ||
  ------------------
  |  Branch (1965:9): [True: 0, False: 546]
  |  Branch (1965:38): [True: 0, False: 546]
  ------------------
 1966|    546|        intkey_cli_to_srv == NULL || intkey_srv_to_cli == NULL) {
  ------------------
  |  Branch (1966:9): [True: 0, False: 546]
  |  Branch (1966:38): [True: 0, False: 546]
  ------------------
 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|    546|    rc = ssh_kdf(crypto, key, key_len, 'A', IV_cli_to_srv, IV_len);
 1973|    546|    if (rc < 0) {
  ------------------
  |  Branch (1973:9): [True: 0, False: 546]
  ------------------
 1974|      0|        goto error;
 1975|      0|    }
 1976|    546|    rc = ssh_kdf(crypto, key, key_len, 'B', IV_srv_to_cli, IV_len);
 1977|    546|    if (rc < 0) {
  ------------------
  |  Branch (1977:9): [True: 0, False: 546]
  ------------------
 1978|      0|        goto error;
 1979|      0|    }
 1980|       |    /* Encryption Key */
 1981|    546|    rc = ssh_kdf(crypto, key, key_len, 'C', enckey_cli_to_srv,
 1982|    546|                 enckey_cli_to_srv_len);
 1983|    546|    if (rc < 0) {
  ------------------
  |  Branch (1983:9): [True: 0, False: 546]
  ------------------
 1984|      0|        goto error;
 1985|      0|    }
 1986|    546|    rc = ssh_kdf(crypto, key, key_len, 'D', enckey_srv_to_cli,
 1987|    546|                 enckey_srv_to_cli_len);
 1988|    546|    if (rc < 0) {
  ------------------
  |  Branch (1988:9): [True: 0, False: 546]
  ------------------
 1989|      0|        goto error;
 1990|      0|    }
 1991|       |    /* Integrity Key */
 1992|    546|    rc = ssh_kdf(crypto, key, key_len, 'E', intkey_cli_to_srv,
 1993|    546|                 intkey_cli_to_srv_len);
 1994|    546|    if (rc < 0) {
  ------------------
  |  Branch (1994:9): [True: 0, False: 546]
  ------------------
 1995|      0|        goto error;
 1996|      0|    }
 1997|    546|    rc = ssh_kdf(crypto, key, key_len, 'F', intkey_srv_to_cli,
 1998|    546|                 intkey_srv_to_cli_len);
 1999|    546|    if (rc < 0) {
  ------------------
  |  Branch (1999:9): [True: 0, False: 546]
  ------------------
 2000|      0|        goto error;
 2001|      0|    }
 2002|       |
 2003|    546|    if (session->client) {
  ------------------
  |  Branch (2003:9): [True: 273, False: 273]
  ------------------
 2004|    273|        crypto->encryptIV = IV_cli_to_srv;
 2005|    273|        crypto->decryptIV = IV_srv_to_cli;
 2006|    273|        crypto->encryptkey = enckey_cli_to_srv;
 2007|    273|        crypto->decryptkey = enckey_srv_to_cli;
 2008|    273|        crypto->encryptMAC = intkey_cli_to_srv;
 2009|    273|        crypto->decryptMAC = intkey_srv_to_cli;
 2010|    273|    } else {
 2011|    273|        crypto->encryptIV = IV_srv_to_cli;
 2012|    273|        crypto->decryptIV = IV_cli_to_srv;
 2013|    273|        crypto->encryptkey = enckey_srv_to_cli;
 2014|    273|        crypto->decryptkey = enckey_cli_to_srv;
 2015|    273|        crypto->encryptMAC = intkey_srv_to_cli;
 2016|    273|        crypto->decryptMAC = intkey_cli_to_srv;
 2017|    273|    }
 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|    546|    rc = 0;
 2033|    546|error:
 2034|    546|    ssh_string_burn(k_string);
 2035|    546|    SSH_STRING_FREE(k_string);
  ------------------
  |  |  915|    546|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 546, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
 2036|    546|    if (rc != 0) {
  ------------------
  |  Branch (2036:9): [True: 0, False: 546]
  ------------------
 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|    546|    return rc;
 2046|    546|}
kex.c:ssh_find_aead_hmac:
  952|  1.09k|{
  953|  1.09k|    if (cipher == NULL) {
  ------------------
  |  Branch (953:9): [True: 0, False: 1.09k]
  ------------------
  954|      0|        return NULL;
  955|  1.09k|    } else if (strcmp(cipher, "chacha20-poly1305@openssh.com") == 0) {
  ------------------
  |  Branch (955:16): [True: 0, False: 1.09k]
  ------------------
  956|      0|        return "aead-poly1305";
  957|  1.09k|    } else if (strcmp(cipher, "aes256-gcm@openssh.com") == 0) {
  ------------------
  |  Branch (957:16): [True: 0, False: 1.09k]
  ------------------
  958|      0|        return "aead-gcm";
  959|  1.09k|    } else if (strcmp(cipher, "aes128-gcm@openssh.com") == 0) {
  ------------------
  |  Branch (959:16): [True: 0, False: 1.09k]
  ------------------
  960|      0|        return "aead-gcm";
  961|      0|    }
  962|  1.09k|    return NULL;
  963|  1.09k|}
kex.c:kex_select_kex_type:
  967|    546|{
  968|    546|    if (strcmp(kex, "diffie-hellman-group1-sha1") == 0) {
  ------------------
  |  Branch (968:9): [True: 0, False: 546]
  ------------------
  969|      0|        return SSH_KEX_DH_GROUP1_SHA1;
  970|    546|    } else if (strncmp(kex, "gss-group14-sha256-", 19) == 0) {
  ------------------
  |  Branch (970:16): [True: 0, False: 546]
  ------------------
  971|      0|        return SSH_GSS_KEX_DH_GROUP14_SHA256;
  972|    546|    } else if (strncmp(kex, "gss-group16-sha512-", 19) == 0) {
  ------------------
  |  Branch (972:16): [True: 0, False: 546]
  ------------------
  973|      0|        return SSH_GSS_KEX_DH_GROUP16_SHA512;
  974|    546|    } else if (strncmp(kex, "gss-nistp256-sha256-", 20) == 0) {
  ------------------
  |  Branch (974:16): [True: 0, False: 546]
  ------------------
  975|      0|        return SSH_GSS_KEX_ECDH_NISTP256_SHA256;
  976|    546|    } else if (strncmp(kex, "gss-curve25519-sha256-", 22) == 0) {
  ------------------
  |  Branch (976:16): [True: 0, False: 546]
  ------------------
  977|      0|        return SSH_GSS_KEX_CURVE25519_SHA256;
  978|    546|    } else if (strcmp(kex, "diffie-hellman-group14-sha1") == 0) {
  ------------------
  |  Branch (978:16): [True: 0, False: 546]
  ------------------
  979|      0|        return SSH_KEX_DH_GROUP14_SHA1;
  980|    546|    } else if (strcmp(kex, "diffie-hellman-group14-sha256") == 0) {
  ------------------
  |  Branch (980:16): [True: 0, False: 546]
  ------------------
  981|      0|        return SSH_KEX_DH_GROUP14_SHA256;
  982|    546|    } else if (strcmp(kex, "diffie-hellman-group16-sha512") == 0) {
  ------------------
  |  Branch (982:16): [True: 0, False: 546]
  ------------------
  983|      0|        return SSH_KEX_DH_GROUP16_SHA512;
  984|    546|    } else if (strcmp(kex, "diffie-hellman-group18-sha512") == 0) {
  ------------------
  |  Branch (984:16): [True: 0, False: 546]
  ------------------
  985|      0|        return SSH_KEX_DH_GROUP18_SHA512;
  986|      0|#ifdef WITH_GEX
  987|    546|    } else if (strcmp(kex, "diffie-hellman-group-exchange-sha1") == 0) {
  ------------------
  |  Branch (987:16): [True: 0, False: 546]
  ------------------
  988|      0|        return SSH_KEX_DH_GEX_SHA1;
  989|    546|    } else if (strcmp(kex, "diffie-hellman-group-exchange-sha256") == 0) {
  ------------------
  |  Branch (989:16): [True: 0, False: 546]
  ------------------
  990|      0|        return SSH_KEX_DH_GEX_SHA256;
  991|      0|#endif /* WITH_GEX */
  992|    546|    } else if (strcmp(kex, "ecdh-sha2-nistp256") == 0) {
  ------------------
  |  Branch (992:16): [True: 0, False: 546]
  ------------------
  993|      0|        return SSH_KEX_ECDH_SHA2_NISTP256;
  994|    546|    } else if (strcmp(kex, "ecdh-sha2-nistp384") == 0) {
  ------------------
  |  Branch (994:16): [True: 0, False: 546]
  ------------------
  995|      0|        return SSH_KEX_ECDH_SHA2_NISTP384;
  996|    546|    } else if (strcmp(kex, "ecdh-sha2-nistp521") == 0) {
  ------------------
  |  Branch (996:16): [True: 0, False: 546]
  ------------------
  997|      0|        return SSH_KEX_ECDH_SHA2_NISTP521;
  998|    546|    } else if (strcmp(kex, "curve25519-sha256@libssh.org") == 0) {
  ------------------
  |  Branch (998:16): [True: 0, False: 546]
  ------------------
  999|      0|        return SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG;
 1000|    546|    } else if (strcmp(kex, "curve25519-sha256") == 0) {
  ------------------
  |  Branch (1000:16): [True: 0, False: 546]
  ------------------
 1001|      0|        return SSH_KEX_CURVE25519_SHA256;
 1002|    546|    } else if (strcmp(kex, "sntrup761x25519-sha512@openssh.com") == 0) {
  ------------------
  |  Branch (1002:16): [True: 0, False: 546]
  ------------------
 1003|      0|        return SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM;
 1004|    546|    } else if (strcmp(kex, "sntrup761x25519-sha512") == 0) {
  ------------------
  |  Branch (1004:16): [True: 0, False: 546]
  ------------------
 1005|      0|        return SSH_KEX_SNTRUP761X25519_SHA512;
 1006|    546|    } else if (strcmp(kex, "mlkem768x25519-sha256") == 0) {
  ------------------
  |  Branch (1006:16): [True: 546, False: 0]
  ------------------
 1007|    546|        return SSH_KEX_MLKEM768X25519_SHA256;
 1008|    546|    } 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|    546|}

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

ssh_reseed:
   94|    273|void ssh_reseed(void){
   95|    273|#ifndef _WIN32
   96|    273|    struct timeval tv;
   97|       |    gettimeofday(&tv, NULL);
   98|    273|    RAND_add(&tv, sizeof(tv), 0.0);
   99|    273|#endif
  100|    273|}
ssh_kdf:
  337|  3.27k|{
  338|  3.27k|    return sshkdf_derive_key(crypto, key, key_len,
  339|  3.27k|                             key_type, output, requested_len);
  340|  3.27k|}
hmac_init:
  344|  3.72k|{
  345|  3.72k|    HMACCTX ctx = NULL;
  346|  3.72k|    EVP_PKEY *pkey = NULL;
  347|  3.72k|    int rc = -1;
  348|       |
  349|  3.72k|    ctx = EVP_MD_CTX_new();
  350|  3.72k|    if (ctx == NULL) {
  ------------------
  |  Branch (350:9): [True: 0, False: 3.72k]
  ------------------
  351|      0|        return NULL;
  352|      0|    }
  353|       |
  354|  3.72k|    pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, key, (int)len);
  355|  3.72k|    if (pkey == NULL) {
  ------------------
  |  Branch (355:9): [True: 0, False: 3.72k]
  ------------------
  356|      0|        goto error;
  357|      0|    }
  358|       |
  359|  3.72k|    switch (type) {
  360|  2.77k|    case SSH_HMAC_SHA1:
  ------------------
  |  Branch (360:5): [True: 2.77k, False: 951]
  ------------------
  361|  2.77k|        rc = EVP_DigestSignInit(ctx, NULL, EVP_sha1(), NULL, pkey);
  362|  2.77k|        break;
  363|    950|    case SSH_HMAC_SHA256:
  ------------------
  |  Branch (363:5): [True: 950, False: 2.77k]
  ------------------
  364|    950|        rc = EVP_DigestSignInit(ctx, NULL, EVP_sha256(), NULL, pkey);
  365|    950|        break;
  366|      0|    case SSH_HMAC_SHA512:
  ------------------
  |  Branch (366:5): [True: 0, False: 3.72k]
  ------------------
  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: 3.72k]
  ------------------
  370|      0|        rc = EVP_DigestSignInit(ctx, NULL, EVP_md5(), NULL, pkey);
  371|      0|        break;
  372|      0|    default:
  ------------------
  |  Branch (372:5): [True: 0, False: 3.72k]
  ------------------
  373|      0|        rc = -1;
  374|      0|        break;
  375|  3.72k|    }
  376|       |
  377|  3.72k|    EVP_PKEY_free(pkey);
  378|  3.72k|    if (rc != 1) {
  ------------------
  |  Branch (378:9): [True: 0, False: 3.72k]
  ------------------
  379|      0|        goto error;
  380|      0|    }
  381|  3.72k|    return ctx;
  382|       |
  383|      0|error:
  384|      0|    EVP_MD_CTX_free(ctx);
  385|       |    return NULL;
  386|  3.72k|}
hmac_update:
  389|  7.45k|{
  390|       |    return EVP_DigestSignUpdate(ctx, data, len);
  391|  7.45k|}
hmac_final:
  394|  3.72k|{
  395|  3.72k|    size_t res = *len;
  396|  3.72k|    int rc;
  397|  3.72k|    rc = EVP_DigestSignFinal(ctx, hashmacbuf, &res);
  398|  3.72k|    EVP_MD_CTX_free(ctx);
  399|  3.72k|    if (rc == 1) {
  ------------------
  |  Branch (399:9): [True: 3.72k, False: 18.4E]
  ------------------
  400|  3.72k|        *len = res;
  401|  3.72k|    }
  402|       |
  403|  3.72k|    return rc;
  404|  3.72k|}
ssh_get_ciphertab:
 1382|  1.91k|{
 1383|  1.91k|    return ssh_ciphertab;
 1384|  1.91k|}
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|    242|{
  460|    242|    int rc;
  461|       |
  462|    242|    evp_cipher_init(cipher);
  463|       |
  464|    242|    rc = EVP_EncryptInit_ex(cipher->ctx, cipher->cipher, NULL, key, IV);
  465|    242|    if (rc != 1){
  ------------------
  |  Branch (465:9): [True: 0, False: 242]
  ------------------
  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|    242|    if (cipher->ciphertype == SSH_AEAD_AES128_GCM ||
  ------------------
  |  Branch (471:9): [True: 0, False: 242]
  ------------------
  472|    242|        cipher->ciphertype == SSH_AEAD_AES256_GCM) {
  ------------------
  |  Branch (472:9): [True: 0, False: 242]
  ------------------
  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|    242|    EVP_CIPHER_CTX_set_padding(cipher->ctx, 0);
  484|       |
  485|    242|    return SSH_OK;
  ------------------
  |  |  316|    242|#define SSH_OK 0     /* No error */
  ------------------
  486|    242|}
libcrypto.c:evp_cipher_init:
  407|    484|{
  408|    484|    if (cipher->ctx == NULL) {
  ------------------
  |  Branch (408:9): [True: 484, False: 0]
  ------------------
  409|    484|        cipher->ctx = EVP_CIPHER_CTX_new();
  410|    484|    } else {
  411|      0|        EVP_CIPHER_CTX_reset(cipher->ctx);
  412|      0|    }
  413|       |
  414|    484|    switch(cipher->ciphertype){
  ------------------
  |  Branch (414:12): [True: 484, False: 0]
  ------------------
  415|    200|    case SSH_AES128_CBC:
  ------------------
  |  Branch (415:5): [True: 200, False: 284]
  ------------------
  416|    200|        cipher->cipher = EVP_aes_128_cbc();
  417|    200|        break;
  418|      0|    case SSH_AES192_CBC:
  ------------------
  |  Branch (418:5): [True: 0, False: 484]
  ------------------
  419|      0|        cipher->cipher = EVP_aes_192_cbc();
  420|      0|        break;
  421|      0|    case SSH_AES256_CBC:
  ------------------
  |  Branch (421:5): [True: 0, False: 484]
  ------------------
  422|      0|        cipher->cipher = EVP_aes_256_cbc();
  423|      0|        break;
  424|    100|    case SSH_AES128_CTR:
  ------------------
  |  Branch (424:5): [True: 100, False: 384]
  ------------------
  425|    100|        cipher->cipher = EVP_aes_128_ctr();
  426|    100|        break;
  427|      0|    case SSH_AES192_CTR:
  ------------------
  |  Branch (427:5): [True: 0, False: 484]
  ------------------
  428|      0|        cipher->cipher = EVP_aes_192_ctr();
  429|      0|        break;
  430|    184|    case SSH_AES256_CTR:
  ------------------
  |  Branch (430:5): [True: 184, False: 300]
  ------------------
  431|    184|        cipher->cipher = EVP_aes_256_ctr();
  432|    184|        break;
  433|      0|    case SSH_AEAD_AES128_GCM:
  ------------------
  |  Branch (433:5): [True: 0, False: 484]
  ------------------
  434|      0|        cipher->cipher = EVP_aes_128_gcm();
  435|      0|        break;
  436|      0|    case SSH_AEAD_AES256_GCM:
  ------------------
  |  Branch (436:5): [True: 0, False: 484]
  ------------------
  437|      0|        cipher->cipher = EVP_aes_256_gcm();
  438|      0|        break;
  439|      0|    case SSH_3DES_CBC:
  ------------------
  |  Branch (439:5): [True: 0, False: 484]
  ------------------
  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: 484]
  ------------------
  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: 484]
  ------------------
  452|      0|        SSH_LOG(SSH_LOG_TRACE, "No valid ciphertype found");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  453|      0|        break;
  454|    484|    }
  455|    484|}
libcrypto.c:evp_cipher_set_decrypt_key:
  489|    242|            void *key, void *IV) {
  490|    242|    int rc;
  491|       |
  492|    242|    evp_cipher_init(cipher);
  493|       |
  494|    242|    rc = EVP_DecryptInit_ex(cipher->ctx, cipher->cipher, NULL, key, IV);
  495|    242|    if (rc != 1){
  ------------------
  |  Branch (495:9): [True: 0, False: 242]
  ------------------
  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|    242|    if (cipher->ciphertype == SSH_AEAD_AES128_GCM ||
  ------------------
  |  Branch (501:9): [True: 0, False: 242]
  ------------------
  502|    242|        cipher->ciphertype == SSH_AEAD_AES256_GCM) {
  ------------------
  |  Branch (502:9): [True: 0, False: 242]
  ------------------
  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|    242|    EVP_CIPHER_CTX_set_padding(cipher->ctx, 0);
  514|       |
  515|    242|    return SSH_OK;
  ------------------
  |  |  316|    242|#define SSH_OK 0     /* No error */
  ------------------
  516|    242|}
libcrypto.c:evp_cipher_encrypt:
  523|  1.69k|{
  524|  1.69k|    int outlen = 0;
  525|  1.69k|    int rc = 0;
  526|       |
  527|  1.69k|    rc = EVP_EncryptUpdate(cipher->ctx,
  528|  1.69k|                           (unsigned char *)out,
  529|  1.69k|                           &outlen,
  530|  1.69k|                           (unsigned char *)in,
  531|  1.69k|                           (int)len);
  532|  1.69k|    if (rc != 1){
  ------------------
  |  Branch (532:9): [True: 0, False: 1.69k]
  ------------------
  533|      0|        SSH_LOG(SSH_LOG_TRACE, "EVP_EncryptUpdate failed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  534|      0|        return;
  535|      0|    }
  536|  1.69k|    if (outlen != (int)len){
  ------------------
  |  Branch (536:9): [True: 0, False: 1.69k]
  ------------------
  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|  1.69k|}
libcrypto.c:evp_cipher_decrypt:
  549|  2.29k|{
  550|  2.29k|    int outlen = 0;
  551|  2.29k|    int rc = 0;
  552|       |
  553|  2.29k|    rc = EVP_DecryptUpdate(cipher->ctx,
  554|  2.29k|                           (unsigned char *)out,
  555|  2.29k|                           &outlen,
  556|  2.29k|                           (unsigned char *)in,
  557|  2.29k|                           (int)len);
  558|  2.29k|    if (rc != 1){
  ------------------
  |  Branch (558:9): [True: 0, False: 2.29k]
  ------------------
  559|      0|        SSH_LOG(SSH_LOG_TRACE, "EVP_DecryptUpdate failed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  560|      0|        return;
  561|      0|    }
  562|  2.29k|    if (outlen != (int)len){
  ------------------
  |  Branch (562:9): [True: 0, False: 2.29k]
  ------------------
  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|  2.29k|}
libcrypto.c:evp_cipher_cleanup:
  571|    484|static void evp_cipher_cleanup(struct ssh_cipher_struct *cipher) {
  572|    484|    if (cipher->ctx != NULL) {
  ------------------
  |  Branch (572:9): [True: 484, False: 0]
  ------------------
  573|    484|        EVP_CIPHER_CTX_free(cipher->ctx);
  574|    484|    }
  575|    484|}
libcrypto.c:none_crypt:
 1217|  5.47k|{
 1218|  5.47k|    memcpy(out, in, len);
 1219|  5.47k|}

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

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

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

ssh_message_free:
  676|  1.09k|void ssh_message_free(ssh_message msg){
  677|  1.09k|  if (msg == NULL) {
  ------------------
  |  Branch (677:7): [True: 0, False: 1.09k]
  ------------------
  678|      0|    return;
  679|      0|  }
  680|       |
  681|  1.09k|  switch(msg->type) {
  ------------------
  |  Branch (681:10): [True: 1.09k, False: 0]
  ------------------
  682|    273|    case SSH_REQUEST_AUTH:
  ------------------
  |  Branch (682:5): [True: 273, False: 819]
  ------------------
  683|    273|      SAFE_FREE(msg->auth_request.username);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  684|    273|      SAFE_FREE(msg->auth_request.sigtype);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  685|    273|      if (msg->auth_request.password) {
  ------------------
  |  Branch (685:11): [True: 0, False: 273]
  ------------------
  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|    273|      ssh_key_free(msg->auth_request.pubkey);
  691|    273|      ssh_key_free(msg->auth_request.server_pubkey);
  692|    273|      break;
  693|    273|    case SSH_REQUEST_CHANNEL_OPEN:
  ------------------
  |  Branch (693:5): [True: 273, False: 819]
  ------------------
  694|    273|      SAFE_FREE(msg->channel_request_open.originator);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  695|    273|      SAFE_FREE(msg->channel_request_open.destination);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  696|    273|      break;
  697|    273|    case SSH_REQUEST_CHANNEL:
  ------------------
  |  Branch (697:5): [True: 273, False: 819]
  ------------------
  698|    273|      SAFE_FREE(msg->channel_request.TERM);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  699|    273|      SAFE_FREE(msg->channel_request.modes);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  700|    273|      SAFE_FREE(msg->channel_request.var_name);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  701|    273|      SAFE_FREE(msg->channel_request.var_value);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  702|    273|      SAFE_FREE(msg->channel_request.command);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  703|    273|      SAFE_FREE(msg->channel_request.subsystem);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  704|    273|      switch (msg->channel_request.type) {
  ------------------
  |  Branch (704:15): [True: 273, False: 0]
  ------------------
  705|    273|      case SSH_CHANNEL_REQUEST_EXEC:
  ------------------
  |  Branch (705:7): [True: 273, False: 0]
  ------------------
  706|    273|          SAFE_FREE(msg->channel_request.command);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  707|    273|          break;
  708|      0|      case SSH_CHANNEL_REQUEST_ENV:
  ------------------
  |  Branch (708:7): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  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: 273]
  ------------------
  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: 273]
  ------------------
  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|    273|      }
  723|    273|      break;
  724|    273|    case SSH_REQUEST_SERVICE:
  ------------------
  |  Branch (724:5): [True: 273, False: 819]
  ------------------
  725|    273|      SAFE_FREE(msg->service_request.service);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  726|    273|      break;
  727|      0|    case SSH_REQUEST_GLOBAL:
  ------------------
  |  Branch (727:5): [True: 0, False: 1.09k]
  ------------------
  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|  1.09k|  }
  731|  1.09k|  ZERO_STRUCTP(msg);
  ------------------
  |  |  379|  1.09k|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (379:34): [True: 1.09k, False: 0]
  |  |  |  Branch (379:85): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
  732|       |  SAFE_FREE(msg);
  ------------------
  |  |  373|  1.09k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.09k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
  733|  1.09k|}
ssh_packet_service_request:
  738|    273|{
  739|    273|    char *service_c = NULL;
  740|    273|    ssh_message msg = NULL;
  741|    273|    int rc;
  742|       |
  743|    273|    (void)type;
  744|    273|    (void)user;
  745|       |
  746|    273|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|    273|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  747|    273|                           "s",
  748|    273|                           &service_c);
  749|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (749:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  757|    273|            "Received a SERVICE_REQUEST for service %s",
  758|    273|            service_c);
  759|       |
  760|    273|    msg = ssh_message_new(session);
  761|    273|    if (msg == NULL) {
  ------------------
  |  Branch (761:9): [True: 0, False: 273]
  ------------------
  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|    273|    msg->type = SSH_REQUEST_SERVICE;
  767|    273|    msg->service_request.service = service_c;
  768|       |
  769|    273|    ssh_message_queue(session, msg);
  770|    273|error:
  771|       |
  772|    273|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    273|#define SSH_PACKET_USED 1
  ------------------
  773|    273|}
ssh_packet_userauth_request:
  855|    273|{
  856|    273|    ssh_message msg = NULL;
  857|    273|    ssh_signature sig = NULL;
  858|    273|    char *service = NULL;
  859|    273|    char *method = NULL;
  860|    273|    int cmp;
  861|    273|    int rc;
  862|       |
  863|    273|    (void)user;
  864|    273|    (void)type;
  865|       |
  866|    273|    msg = ssh_message_new(session);
  867|    273|    if (msg == NULL) {
  ------------------
  |  Branch (867:9): [True: 0, False: 273]
  ------------------
  868|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  869|      0|        goto error;
  870|      0|    }
  871|    273|    msg->type = SSH_REQUEST_AUTH;
  872|    273|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|    273|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  873|    273|                           "sss",
  874|    273|                           &msg->auth_request.username,
  875|    273|                           &service,
  876|    273|                           &method);
  877|       |
  878|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (878:9): [True: 0, False: 273]
  ------------------
  879|      0|        goto error;
  880|      0|    }
  881|       |
  882|    273|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  883|    273|            "Auth request for service %s, method %s for user '%s'",
  884|    273|            service,
  885|    273|            method,
  886|    273|            msg->auth_request.username);
  887|       |
  888|    273|    cmp = strcmp(service, "ssh-connection");
  889|    273|    if (cmp != 0) {
  ------------------
  |  Branch (889:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (strcmp(method, "none") == 0) {
  ------------------
  |  Branch (894:9): [True: 273, False: 0]
  ------------------
  895|    273|        msg->auth_request.method = SSH_AUTH_METHOD_NONE;
  ------------------
  |  |  156|    273|#define SSH_AUTH_METHOD_NONE         0x0001u
  ------------------
  896|    273|        goto end;
  897|    273|    }
  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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  960|      0|                SSH_STRING_FREE(algo);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  967|       |
  968|      0|            if (rc < 0) {
  ------------------
  |  Branch (968:17): [True: 0, False: 0]
  ------------------
  969|      0|                SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  970|      0|                SSH_STRING_FREE(algo);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1050|      0|            SSH_BUFFER_FREE(digest);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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_session_kex_is_gss(session)) {
 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);
  ------------------
  |  |  719|      0|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (719:14): [True: 0, False: 0]
  |  |  |  Branch (719:72): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1242|       |
 1243|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
 1244|    273|end:
 1245|    273|    SAFE_FREE(service);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
 1246|    273|    SAFE_FREE(method);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
 1247|       |
 1248|    273|    ssh_message_queue(session, msg);
 1249|       |
 1250|    273|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    273|#define SSH_PACKET_USED 1
  ------------------
 1251|      0|}
ssh_packet_channel_open:
 1391|    273|{
 1392|    273|    ssh_message msg = NULL;
 1393|    273|    char *type_c = NULL;
 1394|    273|    uint32_t originator_port, destination_port;
 1395|    273|    int rc;
 1396|       |
 1397|    273|    (void)type;
 1398|    273|    (void)user;
 1399|       |
 1400|    273|    msg = ssh_message_new(session);
 1401|    273|    if (msg == NULL) {
  ------------------
  |  Branch (1401:9): [True: 0, False: 273]
  ------------------
 1402|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1403|      0|        goto error;
 1404|      0|    }
 1405|       |
 1406|    273|    msg->type = SSH_REQUEST_CHANNEL_OPEN;
 1407|    273|    rc = ssh_buffer_unpack(packet, "s", &type_c);
  ------------------
  |  |   60|    273|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1408|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1408:9): [True: 0, False: 273]
  ------------------
 1409|      0|        goto error;
 1410|      0|    }
 1411|       |
 1412|    273|    SSH_LOG(SSH_LOG_PACKET, "Clients wants to open a %s channel", type_c);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1413|       |
 1414|    273|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|    273|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1415|    273|                           "ddd",
 1416|    273|                           &msg->channel_request_open.sender,
 1417|    273|                           &msg->channel_request_open.window,
 1418|    273|                           &msg->channel_request_open.packet_size);
 1419|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1419:9): [True: 0, False: 273]
  ------------------
 1420|      0|        goto error;
 1421|      0|    }
 1422|       |
 1423|    273|    if (msg->channel_request_open.packet_size == 0) {
  ------------------
  |  Branch (1423:9): [True: 0, False: 273]
  ------------------
 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|    273|    if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1430:9): [True: 0, False: 273]
  ------------------
 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|    273|    if (strcmp(type_c, "session") == 0) {
  ------------------
  |  Branch (1438:9): [True: 273, False: 0]
  ------------------
 1439|    273|        if (session->flags & SSH_SESSION_FLAG_NO_MORE_SESSIONS) {
  ------------------
  |  |   81|    273|#define SSH_SESSION_FLAG_NO_MORE_SESSIONS 0x0004
  ------------------
  |  Branch (1439:13): [True: 0, False: 273]
  ------------------
 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|    273|        msg->channel_request_open.type = SSH_CHANNEL_SESSION;
 1449|    273|        SAFE_FREE(type_c);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
 1450|    273|        goto end;
 1451|    273|    }
 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);
  ------------------
  |  |  719|      0|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (719:14): [True: 0, False: 0]
  |  |  |  Branch (719:72): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1510|       |
 1511|    273|end:
 1512|    273|    SAFE_FREE(type_c);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
 1513|    273|    if (msg != NULL)
  ------------------
  |  Branch (1513:9): [True: 273, False: 0]
  ------------------
 1514|    273|        ssh_message_queue(session, msg);
 1515|       |
 1516|    273|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    273|#define SSH_PACKET_USED 1
  ------------------
 1517|      0|}
ssh_message_channel_request_open_reply_accept_channel:
 1532|    273|{
 1533|    273|    ssh_session session = NULL;
 1534|    273|    int rc;
 1535|       |
 1536|    273|    if (msg == NULL) {
  ------------------
  |  Branch (1536:9): [True: 0, False: 273]
  ------------------
 1537|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1538|      0|    }
 1539|       |
 1540|    273|    session = msg->session;
 1541|       |
 1542|    273|    chan->local_channel = ssh_channel_new_id(session);
 1543|    273|    chan->local_maxpacket = 35000;
 1544|    273|    chan->local_window = 32000;
 1545|    273|    chan->remote_channel = msg->channel_request_open.sender;
 1546|    273|    chan->remote_maxpacket = msg->channel_request_open.packet_size;
 1547|    273|    chan->remote_window = msg->channel_request_open.window;
 1548|    273|    chan->state = SSH_CHANNEL_STATE_OPEN;
 1549|    273|    chan->flags &= ~SSH_CHANNEL_FLAG_NOT_BOUND;
  ------------------
  |  |   64|    273|#define SSH_CHANNEL_FLAG_NOT_BOUND 0x0008
  ------------------
 1550|       |
 1551|    273|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1552|    273|                         "bdddd",
 1553|    273|                         SSH2_MSG_CHANNEL_OPEN_CONFIRMATION,
 1554|    273|                         chan->remote_channel,
 1555|    273|                         chan->local_channel,
 1556|    273|                         chan->local_window,
 1557|    273|                         chan->local_maxpacket);
 1558|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1558:9): [True: 0, False: 273]
  ------------------
 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|    273|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1564|    273|            "Accepting a channel request_open for chan %" PRIu32,
 1565|    273|            chan->remote_channel);
 1566|       |
 1567|    273|    rc = ssh_packet_send(session);
 1568|       |
 1569|    273|    return rc;
 1570|    273|}
ssh_message_handle_channel_request:
 1629|    273|{
 1630|    273|    ssh_message msg = NULL;
 1631|    273|    int rc;
 1632|       |
 1633|    273|    msg = ssh_message_new(session);
 1634|    273|    if (msg == NULL) {
  ------------------
  |  Branch (1634:9): [True: 0, False: 273]
  ------------------
 1635|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1636|      0|        goto error;
 1637|      0|    }
 1638|       |
 1639|    273|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1640|    273|            "Received a %s channel_request for channel (%" PRIu32 ":%" PRIu32
 1641|    273|            ") (want_reply=%hhu)",
 1642|    273|            request,
 1643|    273|            channel->local_channel,
 1644|    273|            channel->remote_channel,
 1645|    273|            want_reply);
 1646|       |
 1647|    273|    msg->type = SSH_REQUEST_CHANNEL;
 1648|    273|    msg->channel_request.channel = channel;
 1649|    273|    msg->channel_request.want_reply = want_reply;
 1650|       |
 1651|    273|    if (strcmp(request, "pty-req") == 0) {
  ------------------
  |  Branch (1651:9): [True: 0, False: 273]
  ------------------
 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|    273|    if (strcmp(request, "window-change") == 0) {
  ------------------
  |  Branch (1669:9): [True: 0, False: 273]
  ------------------
 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|    273|    if (strcmp(request, "subsystem") == 0) {
  ------------------
  |  Branch (1683:9): [True: 0, False: 273]
  ------------------
 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|    273|    if (strcmp(request, "shell") == 0) {
  ------------------
  |  Branch (1692:9): [True: 0, False: 273]
  ------------------
 1693|      0|        msg->channel_request.type = SSH_CHANNEL_REQUEST_SHELL;
 1694|      0|        goto end;
 1695|      0|    }
 1696|       |
 1697|    273|    if (strcmp(request, "exec") == 0) {
  ------------------
  |  Branch (1697:9): [True: 273, False: 0]
  ------------------
 1698|    273|        rc = ssh_buffer_unpack(packet, "s", &msg->channel_request.command);
  ------------------
  |  |   60|    273|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1699|    273|        msg->channel_request.type = SSH_CHANNEL_REQUEST_EXEC;
 1700|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1700:13): [True: 0, False: 273]
  ------------------
 1701|      0|            goto error;
 1702|      0|        }
 1703|    273|        goto end;
 1704|    273|    }
 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|    273|end:
 1736|    273|    ssh_message_queue(session, msg);
 1737|       |
 1738|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
 1739|      0|error:
 1740|      0|    SSH_MESSAGE_FREE(msg);
  ------------------
  |  |  719|      0|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (719:14): [True: 0, False: 0]
  |  |  |  Branch (719: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|    273|{
 1755|    273|    uint32_t channel;
 1756|    273|    int rc;
 1757|       |
 1758|    273|    if (msg == NULL) {
  ------------------
  |  Branch (1758:9): [True: 0, False: 273]
  ------------------
 1759|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1760|      0|    }
 1761|       |
 1762|    273|    if (msg->channel_request.want_reply) {
  ------------------
  |  Branch (1762:9): [True: 273, False: 0]
  ------------------
 1763|    273|        channel = msg->channel_request.channel->remote_channel;
 1764|       |
 1765|    273|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1766|    273|                "Sending a channel_request success to channel %" PRIu32,
 1767|    273|                channel);
 1768|       |
 1769|    273|        rc = ssh_buffer_pack(msg->session->out_buffer,
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1770|    273|                             "bd",
 1771|    273|                             SSH2_MSG_CHANNEL_SUCCESS,
 1772|    273|                             channel);
 1773|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1773:13): [True: 0, False: 273]
  ------------------
 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|    273|        return ssh_packet_send(msg->session);
 1779|    273|    }
 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|    273|}
messages.c:ssh_message_new:
   67|  1.09k|{
   68|  1.09k|    ssh_message msg = calloc(1, sizeof(struct ssh_message_struct));
   69|  1.09k|    if (msg == NULL) {
  ------------------
  |  Branch (69:9): [True: 0, False: 1.09k]
  ------------------
   70|      0|        return NULL;
   71|      0|    }
   72|  1.09k|    msg->session = session;
   73|       |
   74|       |    /* Set states explicitly */
   75|  1.09k|    msg->auth_request.signature_state = SSH_PUBLICKEY_STATE_NONE;
   76|       |
   77|  1.09k|    return msg;
   78|  1.09k|}
messages.c:ssh_message_queue:
  498|  1.09k|{
  499|  1.09k|#ifdef WITH_SERVER
  500|  1.09k|    int ret;
  501|  1.09k|#endif
  502|       |
  503|  1.09k|    if (message == NULL) {
  ------------------
  |  Branch (503:9): [True: 0, False: 1.09k]
  ------------------
  504|      0|        return;
  505|      0|    }
  506|       |
  507|  1.09k|#ifdef WITH_SERVER
  508|       |    /* probably not the best place to execute server callbacks, but still better
  509|       |     * than nothing.
  510|       |     */
  511|  1.09k|    ret = ssh_execute_server_callbacks(session, message);
  512|  1.09k|    if (ret == SSH_OK) {
  ------------------
  |  |  316|  1.09k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (512:9): [True: 819, False: 273]
  ------------------
  513|    819|        SSH_MESSAGE_FREE(message);
  ------------------
  |  |  719|    819|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (719:14): [True: 819, False: 0]
  |  |  |  Branch (719:72): [Folded, False: 819]
  |  |  ------------------
  ------------------
  514|    819|        return;
  515|    819|    }
  516|    273|#endif /* WITH_SERVER */
  517|       |
  518|    273|    if (session->ssh_message_callback != NULL) {
  ------------------
  |  Branch (518:9): [True: 0, False: 273]
  ------------------
  519|       |        /* This will transfer the message, do not free. */
  520|      0|        ssh_execute_message_callback(session, message);
  521|      0|        return;
  522|      0|    }
  523|       |
  524|    273|    if (session->server_callbacks != NULL) {
  ------------------
  |  Branch (524:9): [True: 273, 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|    273|        ssh_message_reply_default(message);
  530|    273|        SSH_MESSAGE_FREE(message);
  ------------------
  |  |  719|    273|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (719:14): [True: 273, False: 0]
  |  |  |  Branch (719:72): [Folded, False: 273]
  |  |  ------------------
  ------------------
  531|    273|        return;
  532|    273|    }
  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);
  ------------------
  |  |  719|      0|    do { if ((x) != NULL) { ssh_message_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (719:14): [True: 0, False: 0]
  |  |  |  Branch (719: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|  1.09k|static int ssh_execute_server_callbacks(ssh_session session, ssh_message msg){
  449|  1.09k|    int rc = SSH_AGAIN;
  ------------------
  |  |  318|  1.09k|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  450|       |
  451|  1.09k|    if (session->server_callbacks != NULL){
  ------------------
  |  Branch (451:9): [True: 1.09k, False: 0]
  ------------------
  452|  1.09k|        rc = ssh_execute_server_request(session, msg);
  453|  1.09k|    } 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|  1.09k|    return rc;
  459|  1.09k|}
messages.c:ssh_execute_server_request:
  138|  1.09k|{
  139|  1.09k|    ssh_channel channel = NULL;
  140|  1.09k|    int rc;
  141|       |
  142|  1.09k|    switch(msg->type) {
  ------------------
  |  Branch (142:12): [True: 1.09k, False: 0]
  ------------------
  143|    273|        case SSH_REQUEST_AUTH:
  ------------------
  |  Branch (143:9): [True: 273, False: 819]
  ------------------
  144|    273|            if (msg->auth_request.method == SSH_AUTH_METHOD_PASSWORD &&
  ------------------
  |  |  157|    546|#define SSH_AUTH_METHOD_PASSWORD     0x0002u
  ------------------
  |  Branch (144:17): [True: 0, False: 273]
  ------------------
  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|    273|            } else if(msg->auth_request.method == SSH_AUTH_METHOD_PUBLICKEY &&
  ------------------
  |  |  158|    546|#define SSH_AUTH_METHOD_PUBLICKEY    0x0004u
  ------------------
  |  Branch (156:23): [True: 0, False: 273]
  ------------------
  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|    273|            } else if (msg->auth_request.method == SSH_AUTH_METHOD_NONE &&
  ------------------
  |  |  156|    546|#define SSH_AUTH_METHOD_NONE         0x0001u
  ------------------
  |  Branch (177:24): [True: 273, False: 0]
  ------------------
  178|    273|                       ssh_callbacks_exists(session->server_callbacks, auth_none_function)) {
  ------------------
  |  |  547|    273|#define ssh_callbacks_exists(p,c) (\
  |  |  548|    273|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (548:3): [True: 273, False: 0]
  |  |  |  Branch (548:18): [True: 273, False: 0]
  |  |  ------------------
  |  |  549|    273|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 273, False: 0]
  |  |  ------------------
  |  |  550|    273|  )
  ------------------
  179|    273|                rc = session->server_callbacks->auth_none_function(session,
  180|    273|                    msg->auth_request.username, session->server_callbacks->userdata);
  181|    273|                if (rc == SSH_AUTH_SUCCESS || rc == SSH_AUTH_PARTIAL){
  ------------------
  |  Branch (181:21): [True: 273, False: 0]
  |  Branch (181:47): [True: 0, False: 0]
  ------------------
  182|    273|                    ssh_message_auth_reply_success(msg, rc == SSH_AUTH_PARTIAL);
  183|    273|                } else {
  184|      0|                    ssh_message_reply_default(msg);
  185|      0|                }
  186|       |
  187|    273|                return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  188|    273|            } 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|    273|        case SSH_REQUEST_CHANNEL_OPEN:
  ------------------
  |  Branch (203:9): [True: 273, False: 819]
  ------------------
  204|    273|            if (msg->channel_request_open.type == SSH_CHANNEL_SESSION &&
  ------------------
  |  Branch (204:17): [True: 273, False: 0]
  ------------------
  205|    273|                ssh_callbacks_exists(session->server_callbacks, channel_open_request_session_function)) {
  ------------------
  |  |  547|    273|#define ssh_callbacks_exists(p,c) (\
  |  |  548|    273|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (548:3): [True: 273, False: 0]
  |  |  |  Branch (548:18): [True: 273, False: 0]
  |  |  ------------------
  |  |  549|    273|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 273, False: 0]
  |  |  ------------------
  |  |  550|    273|  )
  ------------------
  206|    273|                channel = session->server_callbacks->channel_open_request_session_function(session,
  207|    273|                        session->server_callbacks->userdata);
  208|    273|                if (channel != NULL) {
  ------------------
  |  Branch (208:21): [True: 273, False: 0]
  ------------------
  209|    273|                    rc = ssh_message_channel_request_open_reply_accept_channel(msg, channel);
  210|    273|                    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (210:25): [True: 0, False: 273]
  ------------------
  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|    273|                    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  216|    273|                } 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|    273|#define CB channel_open_request_direct_tcpip_function
  222|    273|            } 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|    273|        case SSH_REQUEST_CHANNEL:
  ------------------
  |  Branch (250:9): [True: 273, False: 819]
  ------------------
  251|    273|            channel = msg->channel_request.channel;
  252|       |
  253|    273|            if (msg->channel_request.type == SSH_CHANNEL_REQUEST_PTY){
  ------------------
  |  Branch (253:17): [True: 0, False: 273]
  ------------------
  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|    273|            } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_SHELL){
  ------------------
  |  Branch (273:24): [True: 0, False: 273]
  ------------------
  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|    273|            } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_X11){
  ------------------
  |  Branch (288:24): [True: 0, False: 273]
  ------------------
  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|    273|            } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_WINDOW_CHANGE){
  ------------------
  |  Branch (303:24): [True: 0, False: 273]
  ------------------
  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|    273|            } else if (msg->channel_request.type == SSH_CHANNEL_REQUEST_EXEC){
  ------------------
  |  Branch (321:24): [True: 273, False: 0]
  ------------------
  322|    546|                ssh_callbacks_iterate(channel->callbacks,
  ------------------
  |  |  598|    273|    do {                                                              \
  |  |  599|    273|        struct ssh_iterator *_cb_i = ssh_list_get_iterator(_cb_list); \
  |  |  600|    273|        _cb_type _cb;                                                 \
  |  |  601|    273|        for (; _cb_i != NULL; _cb_i = _cb_i->next) {                  \
  |  |  ------------------
  |  |  |  Branch (601:16): [True: 273, False: 0]
  |  |  ------------------
  |  |  602|    273|            _cb = ssh_iterator_value(_cb_type, _cb_i);                \
  |  |  ------------------
  |  |  |  |  114|    273|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  603|    273|            if (ssh_callbacks_exists(_cb, _cb_name))
  |  |  ------------------
  |  |  |  |  547|    273|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|    273|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 273, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 273, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|    273|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 273, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|    273|  )
  |  |  ------------------
  ------------------
  323|    546|                                      ssh_channel_callbacks,
  324|    546|                                      channel_exec_request_function) {
  325|    273|                    rc = ssh_callbacks_iterate_exec(channel_exec_request_function,
  ------------------
  |  |  612|    273|                _cb->_cb_name(__VA_ARGS__, _cb->userdata)
  ------------------
  326|    273|                                                    session,
  327|    273|                                                    channel,
  328|    273|                                                    msg->channel_request.command);
  329|    273|                    if (rc == 0) {
  ------------------
  |  Branch (329:25): [True: 273, False: 0]
  ------------------
  330|    273|                        ssh_message_channel_request_reply_success(msg);
  331|    273|                    } else {
  332|      0|                        ssh_message_reply_default(msg);
  333|      0|                    }
  334|       |
  335|    273|                    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  336|    273|                }
  337|    546|                ssh_callbacks_iterate_end();
  ------------------
  |  |  618|    273|        }                           \
  |  |  619|    273|    } while(0)
  |  |  ------------------
  |  |  |  Branch (619:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  338|    273|            } 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|    273|        case SSH_REQUEST_SERVICE:
  ------------------
  |  Branch (374:9): [True: 273, False: 819]
  ------------------
  375|    273|            if (ssh_callbacks_exists(session->server_callbacks, service_request_function)) {
  ------------------
  |  |  547|    273|#define ssh_callbacks_exists(p,c) (\
  |  |  548|    273|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (548:3): [True: 273, False: 0]
  |  |  |  Branch (548:18): [True: 273, False: 0]
  |  |  ------------------
  |  |  549|    273|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 0, False: 273]
  |  |  ------------------
  |  |  550|    273|  )
  ------------------
  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|    273|            return SSH_AGAIN;
  ------------------
  |  |  318|    273|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  388|      0|        case SSH_REQUEST_GLOBAL:
  ------------------
  |  Branch (388:9): [True: 0, False: 1.09k]
  ------------------
  389|      0|            break;
  390|  1.09k|    }
  391|       |
  392|      0|    return SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  393|  1.09k|}

ssh_is_ipaddr_v4:
  430|  1.09k|{
  431|  1.09k|    int rc = -1;
  432|  1.09k|    struct in_addr dest;
  433|       |
  434|  1.09k|    rc = inet_pton(AF_INET, str, &dest);
  435|  1.09k|    if (rc > 0) {
  ------------------
  |  Branch (435:9): [True: 0, False: 1.09k]
  ------------------
  436|      0|        return 1;
  437|      0|    }
  438|       |
  439|  1.09k|    return 0;
  440|  1.09k|}
ssh_is_ipaddr:
  450|  1.09k|{
  451|  1.09k|    int rc = -1;
  452|  1.09k|    char *s = strdup(str);
  453|       |
  454|  1.09k|    if (s == NULL) {
  ------------------
  |  Branch (454:9): [True: 0, False: 1.09k]
  ------------------
  455|      0|        return -1;
  456|      0|    }
  457|  1.09k|    if (strchr(s, ':')) {
  ------------------
  |  Branch (457:9): [True: 0, False: 1.09k]
  ------------------
  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|  1.09k|    free(s);
  478|  1.09k|    return ssh_is_ipaddr_v4(str);
  479|  1.09k|}
ssh_get_user_home_dir:
  495|  1.36k|{
  496|  1.36k|    char *szPath = NULL;
  497|       |
  498|       |    /* If used previously, reuse cached value */
  499|  1.36k|    if (session != NULL && session->opts.homedir != NULL) {
  ------------------
  |  Branch (499:9): [True: 1.09k, False: 273]
  |  Branch (499:28): [True: 819, False: 273]
  ------------------
  500|    819|        return strdup(session->opts.homedir);
  501|    819|    }
  502|       |
  503|    546|    szPath = ssh_get_user_home_dir_internal();
  504|    546|    if (szPath == NULL) {
  ------------------
  |  Branch (504:9): [True: 0, False: 546]
  ------------------
  505|      0|        return NULL;
  506|      0|    }
  507|       |
  508|    546|    if (session != NULL) {
  ------------------
  |  Branch (508:9): [True: 273, False: 273]
  ------------------
  509|       |        /* cache it:
  510|       |         * failure is not fatal -- at worst we will just not cache it */
  511|    273|        session->opts.homedir = strdup(szPath);
  512|    273|    }
  513|       |
  514|    546|    return szPath;
  515|    546|}
ssh_lowercase:
  526|    546|{
  527|    546|    char *new = NULL, *p = NULL;
  528|       |
  529|    546|    if (str == NULL) {
  ------------------
  |  Branch (529:9): [True: 0, False: 546]
  ------------------
  530|      0|        return NULL;
  531|      0|    }
  532|       |
  533|    546|    new = strdup(str);
  534|    546|    if (new == NULL) {
  ------------------
  |  Branch (534:9): [True: 0, False: 546]
  ------------------
  535|      0|        return NULL;
  536|      0|    }
  537|       |
  538|  5.46k|    for (p = new; *p; p++) {
  ------------------
  |  Branch (538:19): [True: 4.91k, False: 546]
  ------------------
  539|  4.91k|        *p = tolower(*p);
  ------------------
  |  Branch (539:14): [True: 0, False: 0]
  |  Branch (539:14): [True: 0, False: 0]
  |  Branch (539:14): [Folded, False: 4.91k]
  ------------------
  540|  4.91k|    }
  541|       |
  542|    546|    return new;
  543|    546|}
ssh_list_new:
  865|  6.55k|{
  866|  6.55k|    struct ssh_list *ret = malloc(sizeof(struct ssh_list));
  867|  6.55k|    if (ret == NULL) {
  ------------------
  |  Branch (867:9): [True: 0, False: 6.55k]
  ------------------
  868|      0|        return NULL;
  869|      0|    }
  870|  6.55k|    ret->root = ret->end = NULL;
  871|  6.55k|    return ret;
  872|  6.55k|}
ssh_list_free:
  882|  6.55k|{
  883|  6.55k|    struct ssh_iterator *ptr = NULL, *next = NULL;
  884|  6.55k|    if (!list)
  ------------------
  |  Branch (884:9): [True: 0, False: 6.55k]
  ------------------
  885|      0|        return;
  886|  6.55k|    ptr = list->root;
  887|  7.64k|    while (ptr) {
  ------------------
  |  Branch (887:12): [True: 1.09k, False: 6.55k]
  ------------------
  888|  1.09k|        next = ptr->next;
  889|  1.09k|        SAFE_FREE(ptr);
  ------------------
  |  |  373|  1.09k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.09k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
  890|  1.09k|        ptr = next;
  891|  1.09k|    }
  892|       |    SAFE_FREE(list);
  ------------------
  |  |  373|  6.55k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 6.55k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 6.55k]
  |  |  ------------------
  ------------------
  893|  6.55k|}
ssh_list_get_iterator:
  903|  14.6k|{
  904|  14.6k|    if (!list)
  ------------------
  |  Branch (904:9): [True: 3.98k, False: 10.6k]
  ------------------
  905|  3.98k|        return NULL;
  906|  10.6k|    return list->root;
  907|  14.6k|}
ssh_list_find:
  918|  1.09k|{
  919|  1.09k|    struct ssh_iterator *it = NULL;
  920|       |
  921|  1.63k|    for (it = ssh_list_get_iterator(list); it != NULL ; it = it->next)
  ------------------
  |  Branch (921:44): [True: 1.63k, False: 0]
  ------------------
  922|  1.63k|        if (it->data == value)
  ------------------
  |  Branch (922:13): [True: 1.09k, False: 546]
  ------------------
  923|  1.09k|            return it;
  924|      0|    return NULL;
  925|  1.09k|}
ssh_list_append:
  969|  3.82k|{
  970|  3.82k|  struct ssh_iterator *iterator = NULL;
  971|       |
  972|  3.82k|  if (list == NULL) {
  ------------------
  |  Branch (972:7): [True: 0, False: 3.82k]
  ------------------
  973|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  974|      0|  }
  975|       |
  976|  3.82k|  iterator = ssh_iterator_new(data);
  977|  3.82k|  if (iterator == NULL) {
  ------------------
  |  Branch (977:7): [True: 0, False: 3.82k]
  ------------------
  978|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  979|      0|  }
  980|       |
  981|  3.82k|  if(!list->end){
  ------------------
  |  Branch (981:6): [True: 1.63k, False: 2.18k]
  ------------------
  982|       |    /* list is empty */
  983|  1.63k|    list->root=list->end=iterator;
  984|  2.18k|  } else {
  985|       |    /* put it on end of list */
  986|  2.18k|    list->end->next=iterator;
  987|  2.18k|    list->end=iterator;
  988|  2.18k|  }
  989|  3.82k|  return SSH_OK;
  ------------------
  |  |  316|  3.82k|#define SSH_OK 0     /* No error */
  ------------------
  990|  3.82k|}
ssh_list_prepend:
 1001|    819|{
 1002|    819|  struct ssh_iterator *it = NULL;
 1003|       |
 1004|    819|  if (list == NULL) {
  ------------------
  |  Branch (1004:7): [True: 0, False: 819]
  ------------------
 1005|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1006|      0|  }
 1007|       |
 1008|    819|  it = ssh_iterator_new(data);
 1009|    819|  if (it == NULL) {
  ------------------
  |  Branch (1009:7): [True: 0, False: 819]
  ------------------
 1010|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1011|      0|  }
 1012|       |
 1013|    819|  if (list->end == NULL) {
  ------------------
  |  Branch (1013:7): [True: 819, False: 0]
  ------------------
 1014|       |    /* list is empty */
 1015|    819|    list->root = list->end = it;
 1016|    819|  } else {
 1017|       |    /* set as new root */
 1018|      0|    it->next = list->root;
 1019|      0|    list->root = it;
 1020|      0|  }
 1021|       |
 1022|    819|  return SSH_OK;
  ------------------
  |  |  316|    819|#define SSH_OK 0     /* No error */
  ------------------
 1023|    819|}
ssh_list_remove:
 1032|  1.36k|{
 1033|  1.36k|    struct ssh_iterator *ptr = NULL, *prev = NULL;
 1034|       |
 1035|  1.36k|    if (list == NULL) {
  ------------------
  |  Branch (1035:9): [True: 0, False: 1.36k]
  ------------------
 1036|      0|        return;
 1037|      0|    }
 1038|       |
 1039|  1.36k|    prev = NULL;
 1040|  1.36k|    ptr = list->root;
 1041|  1.91k|    while (ptr && ptr != iterator) {
  ------------------
  |  Branch (1041:12): [True: 1.63k, False: 273]
  |  Branch (1041:19): [True: 546, False: 1.09k]
  ------------------
 1042|    546|        prev = ptr;
 1043|    546|        ptr = ptr->next;
 1044|    546|    }
 1045|  1.36k|    if (!ptr) {
  ------------------
  |  Branch (1045:9): [True: 273, False: 1.09k]
  ------------------
 1046|       |        /* we did not find the element */
 1047|    273|        return;
 1048|    273|    }
 1049|       |    /* unlink it */
 1050|  1.09k|    if (prev)
  ------------------
  |  Branch (1050:9): [True: 546, False: 546]
  ------------------
 1051|    546|        prev->next = ptr->next;
 1052|       |    /* if iterator was the head */
 1053|  1.09k|    if (list->root == iterator)
  ------------------
  |  Branch (1053:9): [True: 546, False: 546]
  ------------------
 1054|    546|        list->root = iterator->next;
 1055|       |    /* if iterator was the tail */
 1056|  1.09k|    if (list->end == iterator)
  ------------------
  |  Branch (1056:9): [True: 1.09k, False: 0]
  ------------------
 1057|  1.09k|        list->end = prev;
 1058|       |    SAFE_FREE(iterator);
  ------------------
  |  |  373|  1.09k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.09k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
 1059|  1.09k|}
_ssh_list_pop_head:
 1073|  7.37k|{
 1074|  7.37k|  struct ssh_iterator *iterator = NULL;
 1075|  7.37k|  const void *data = NULL;
 1076|       |
 1077|  7.37k|  if (list == NULL) {
  ------------------
  |  Branch (1077:7): [True: 0, False: 7.37k]
  ------------------
 1078|      0|      return NULL;
 1079|      0|  }
 1080|       |
 1081|  7.37k|  iterator = list->root;
 1082|  7.37k|  if (iterator == NULL) {
  ------------------
  |  Branch (1082:7): [True: 4.91k, False: 2.45k]
  ------------------
 1083|  4.91k|      return NULL;
 1084|  4.91k|  }
 1085|  2.45k|  data=iterator->data;
 1086|  2.45k|  list->root=iterator->next;
 1087|  2.45k|  if(list->end==iterator)
  ------------------
  |  Branch (1087:6): [True: 819, False: 1.63k]
  ------------------
 1088|    819|    list->end=NULL;
 1089|       |  SAFE_FREE(iterator);
  ------------------
  |  |  373|  2.45k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.45k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.45k]
  |  |  ------------------
  ------------------
 1090|  2.45k|  return data;
 1091|  7.37k|}
ssh_path_expand_tilde:
 1309|  1.36k|{
 1310|  1.36k|    char *h = NULL, *r = NULL;
 1311|  1.36k|    const char *p = NULL;
 1312|  1.36k|    size_t ld;
 1313|  1.36k|    size_t lh = 0;
 1314|       |
 1315|  1.36k|    if (d[0] != '~') {
  ------------------
  |  Branch (1315:9): [True: 1.09k, False: 273]
  ------------------
 1316|  1.09k|        return strdup(d);
 1317|  1.09k|    }
 1318|    273|    d++;
 1319|       |
 1320|       |    /* handle ~user/path */
 1321|    273|    p = strchr(d, '/');
 1322|    273|    if (p != NULL && p > d) {
  ------------------
  |  Branch (1322:9): [True: 273, False: 0]
  |  Branch (1322:22): [True: 0, False: 273]
  ------------------
 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|    273|    } else {
 1343|    273|        ld = strlen(d);
 1344|    273|        p = (char *) d;
 1345|    273|        h = ssh_get_user_home_dir(NULL);
 1346|    273|    }
 1347|    273|    if (h == NULL) {
  ------------------
  |  Branch (1347:9): [True: 0, False: 273]
  ------------------
 1348|      0|        return NULL;
 1349|      0|    }
 1350|    273|    lh = strlen(h);
 1351|       |
 1352|    273|    r = malloc(ld + lh + 1);
 1353|    273|    if (r == NULL) {
  ------------------
  |  Branch (1353:9): [True: 0, False: 273]
  ------------------
 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|    273|    if (lh > 0) {
  ------------------
  |  Branch (1358:9): [True: 273, False: 0]
  ------------------
 1359|    273|        memcpy(r, h, lh);
 1360|    273|    }
 1361|    273|    SAFE_FREE(h);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
 1362|    273|    memcpy(r + lh, p, ld + 1);
 1363|       |
 1364|    273|    return r;
 1365|    273|}
ssh_path_expand_escape:
 1699|  1.09k|{
 1700|       |    return ssh_path_expand_internal(session, s, false);
 1701|  1.09k|}
ssh_analyze_banner:
 1734|    546|{
 1735|    546|    const char *banner = NULL;
 1736|    546|    const char *openssh = NULL;
 1737|    546|    const char *ios = NULL;
 1738|       |
 1739|    546|    if (server) {
  ------------------
  |  Branch (1739:9): [True: 273, False: 273]
  ------------------
 1740|    273|        banner = session->clientbanner;
 1741|    273|    } else {
 1742|    273|        banner = session->serverbanner;
 1743|    273|    }
 1744|       |
 1745|    546|    if (banner == NULL) {
  ------------------
  |  Branch (1745:9): [True: 0, False: 546]
  ------------------
 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|    546|    if (strlen(banner) < 6 ||
  ------------------
  |  Branch (1759:9): [True: 0, False: 546]
  ------------------
 1760|    546|        strncmp(banner, "SSH-", 4) != 0) {
  ------------------
  |  Branch (1760:9): [True: 0, False: 546]
  ------------------
 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|    546|    SSH_LOG(SSH_LOG_DEBUG, "Analyzing banner: %s", banner);
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1766|       |
 1767|    546|    switch (banner[4]) {
 1768|    546|        case '2':
  ------------------
  |  Branch (1768:9): [True: 546, False: 0]
  ------------------
 1769|    546|            break;
 1770|      0|        case '1':
  ------------------
  |  Branch (1770:9): [True: 0, False: 546]
  ------------------
 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: 546]
  ------------------
 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|    546|    }
 1781|       |
 1782|       |    /* Make a best-effort to extract OpenSSH version numbers. */
 1783|    546|    openssh = strstr(banner, "OpenSSH");
 1784|    546|    if (openssh != NULL) {
  ------------------
  |  Branch (1784:9): [True: 0, False: 546]
  ------------------
 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|    546|    ios = strstr(banner, "Cisco");
 1829|    546|    if (ios != NULL) {
  ------------------
  |  Branch (1829:9): [True: 0, False: 546]
  ------------------
 1830|      0|        session->flags |= SSH_SESSION_FLAG_SCP_QUOTING_BROKEN;
  ------------------
  |  |   95|      0|#define SSH_SESSION_FLAG_SCP_QUOTING_BROKEN 0x0040
  ------------------
 1831|      0|    }
 1832|       |
 1833|    546|done:
 1834|    546|    return 0;
 1835|    546|}
ssh_timestamp_init:
 1850|  37.2k|{
 1851|  37.2k|#ifdef HAVE_CLOCK_GETTIME
 1852|  37.2k|  struct timespec tp;
 1853|  37.2k|  clock_gettime(CLOCK, &tp);
  ------------------
  |  | 1839|  37.2k|#define CLOCK CLOCK_MONOTONIC
  ------------------
 1854|  37.2k|  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|  37.2k|  ts->seconds = tp.tv_sec;
 1861|  37.2k|}
ssh_make_milliseconds:
 1898|  3.27k|{
 1899|  3.27k|    unsigned long res;
 1900|       |
 1901|  3.27k|    if (sec == (unsigned long)SSH_TIMEOUT_INFINITE) {
  ------------------
  |  |   99|  3.27k|#define SSH_TIMEOUT_INFINITE -1
  ------------------
  |  Branch (1901:9): [True: 0, False: 3.27k]
  ------------------
 1902|      0|        return SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|      0|#define SSH_TIMEOUT_INFINITE -1
  ------------------
 1903|      0|    }
 1904|  3.27k|    if (sec > (unsigned long)INT_MAX / 1000) {
  ------------------
  |  Branch (1904:9): [True: 0, False: 3.27k]
  ------------------
 1905|      0|        return INT_MAX;
 1906|      0|    }
 1907|       |
 1908|  3.27k|    res = usec / 1000;
 1909|  3.27k|    res += (sec * 1000);
 1910|  3.27k|    if (res == 0) {
  ------------------
  |  Branch (1910:9): [True: 0, False: 3.27k]
  ------------------
 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|  3.27k|    if (res > INT_MAX) {
  ------------------
  |  Branch (1915:9): [True: 0, False: 3.27k]
  ------------------
 1916|      0|        return INT_MAX;
 1917|  3.27k|    } else {
 1918|  3.27k|        return (int)res;
 1919|  3.27k|    }
 1920|  3.27k|}
ssh_timeout_elapsed:
 1933|  7.27k|{
 1934|  7.27k|    struct ssh_timestamp now;
 1935|       |
 1936|  7.27k|    switch(timeout) {
 1937|      0|        case -2: /*
  ------------------
  |  Branch (1937:9): [True: 0, False: 7.27k]
  ------------------
 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: 7.27k]
  ------------------
 1946|      0|            return 0;
 1947|      0|        case 0: /* 0 means no timeout */
  ------------------
  |  Branch (1947:9): [True: 0, False: 7.27k]
  ------------------
 1948|      0|            return 1;
 1949|  7.27k|        default:
  ------------------
  |  Branch (1949:9): [True: 7.27k, False: 0]
  ------------------
 1950|  7.27k|            break;
 1951|  7.27k|    }
 1952|       |
 1953|  7.27k|    ssh_timestamp_init(&now);
 1954|       |
 1955|  7.27k|    return (ssh_timestamp_difference(ts,&now) >= timeout);
 1956|  7.27k|}
ssh_timeout_update:
 1966|  17.0k|{
 1967|  17.0k|  struct ssh_timestamp now;
 1968|  17.0k|  int ms, ret;
 1969|  17.0k|  if (timeout <= 0) {
  ------------------
  |  Branch (1969:7): [True: 0, False: 17.0k]
  ------------------
 1970|      0|      return timeout;
 1971|      0|  }
 1972|  17.0k|  ssh_timestamp_init(&now);
 1973|  17.0k|  ms = ssh_timestamp_difference(ts,&now);
 1974|  17.0k|  if(ms < 0)
  ------------------
  |  Branch (1974:6): [True: 0, False: 17.0k]
  ------------------
 1975|      0|    ms = 0;
 1976|  17.0k|  ret = timeout - ms;
 1977|  17.0k|  return ret >= 0 ? ret: 0;
  ------------------
  |  Branch (1977:10): [True: 17.0k, False: 1]
  ------------------
 1978|  17.0k|}
ssh_quote_file_name:
 2078|    273|{
 2079|    273|    const char *src = NULL;
 2080|    273|    char *dst = NULL;
 2081|    273|    size_t required_buf_len;
 2082|       |
 2083|    273|    enum ssh_quote_state_e state = NO_QUOTE;
 2084|       |
 2085|    273|    if (file_name == NULL || buf == NULL || buf_len == 0) {
  ------------------
  |  Branch (2085:9): [True: 0, False: 273]
  |  Branch (2085:30): [True: 0, False: 273]
  |  Branch (2085:45): [True: 0, False: 273]
  ------------------
 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|    273|    if (strlen(file_name) > 32 * 1024) {
  ------------------
  |  Branch (2091:9): [True: 0, False: 273]
  ------------------
 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|    273|    required_buf_len = (size_t)3 * strlen(file_name) + 1;
 2098|    273|    if (required_buf_len > buf_len) {
  ------------------
  |  Branch (2098:9): [True: 0, False: 273]
  ------------------
 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|    273|    src = file_name;
 2104|    273|    dst = buf;
 2105|       |
 2106|  2.73k|    while ((*src != '\0')) {
  ------------------
  |  Branch (2106:12): [True: 2.45k, False: 273]
  ------------------
 2107|  2.45k|        switch (*src) {
 2108|       |
 2109|       |        /* The '\'' char is double quoted */
 2110|       |
 2111|      0|        case '\'':
  ------------------
  |  Branch (2111:9): [True: 0, False: 2.45k]
  ------------------
 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: 2.45k]
  ------------------
 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|  2.45k|        default:
  ------------------
  |  Branch (2173:9): [True: 2.45k, False: 0]
  ------------------
 2174|  2.45k|            switch (state) {
 2175|    273|            case NO_QUOTE:
  ------------------
  |  Branch (2175:13): [True: 273, False: 2.18k]
  ------------------
 2176|       |                /* Start a new single quoted string */
 2177|    273|                *dst++ = '\'';
 2178|    273|                break;
 2179|  2.18k|            case SINGLE_QUOTE:
  ------------------
  |  Branch (2179:13): [True: 2.18k, False: 273]
  ------------------
 2180|       |                /* If already in the single quoted string, keep copying the
 2181|       |                 * sequence of chars. */
 2182|  2.18k|                break;
 2183|      0|            case DOUBLE_QUOTE:
  ------------------
  |  Branch (2183:13): [True: 0, False: 2.45k]
  ------------------
 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: 2.45k]
  ------------------
 2190|       |                /* Should never be reached */
 2191|      0|                goto error;
 2192|  2.45k|            }
 2193|       |
 2194|       |            /* When an ordinary char is found, the resulting state will be
 2195|       |             * SINGLE_QUOTE in any case*/
 2196|  2.45k|            state = SINGLE_QUOTE;
 2197|  2.45k|            break;
 2198|  2.45k|        }
 2199|       |
 2200|       |        /* Copy the current char to output */
 2201|  2.45k|        *dst++ = *src++;
 2202|  2.45k|    }
 2203|       |
 2204|       |    /* Close the quoted string when necessary */
 2205|       |
 2206|    273|    switch (state) {
 2207|      0|    case NO_QUOTE:
  ------------------
  |  Branch (2207:5): [True: 0, False: 273]
  ------------------
 2208|       |        /* No open string */
 2209|      0|        break;
 2210|    273|    case SINGLE_QUOTE:
  ------------------
  |  Branch (2210:5): [True: 273, False: 0]
  ------------------
 2211|       |        /* Close current single quoted string */
 2212|    273|        *dst++ = '\'';
 2213|    273|        break;
 2214|      0|    case DOUBLE_QUOTE:
  ------------------
  |  Branch (2214:5): [True: 0, False: 273]
  ------------------
 2215|       |        /* Close current double quoted string */
 2216|      0|        *dst++ = '"';
 2217|      0|        break;
 2218|      0|    default:
  ------------------
  |  Branch (2218:5): [True: 0, False: 273]
  ------------------
 2219|       |        /* Should never be reached */
 2220|      0|        goto error;
 2221|    273|    }
 2222|       |
 2223|       |    /* Put the string terminator */
 2224|    273|    *dst = '\0';
 2225|       |
 2226|    273|    return (int)(dst - buf);
 2227|       |
 2228|      0|error:
 2229|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2230|    273|}
ssh_strerror:
 2396|  1.36k|{
 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|  1.36k|    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|  1.36k|    rv = strerror_r(err_num, buf, buflen);
 2408|  1.36k|#endif /* _WIN32 */
 2409|       |
 2410|       |    /* make sure the buffer is initialized and terminated with NULL */
 2411|  1.36k|    if (-rv == ERANGE) {
  ------------------
  |  Branch (2411:9): [True: 0, False: 1.36k]
  ------------------
 2412|      0|        buf[0] = '\0';
 2413|      0|    }
 2414|  1.36k|    return buf;
 2415|  1.36k|#endif /* ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE) */
 2416|  1.36k|}
ssh_check_hostname_syntax:
 2547|    273|{
 2548|    273|    char *it = NULL, *s = NULL, *buf = NULL;
 2549|    273|    size_t it_len;
 2550|    273|    char c;
 2551|       |
 2552|    273|    if (hostname == NULL || strlen(hostname) == 0) {
  ------------------
  |  Branch (2552:9): [True: 0, False: 273]
  |  Branch (2552:29): [True: 0, False: 273]
  ------------------
 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|    273|    s = strdup(hostname);
 2558|    273|    if (s == NULL) {
  ------------------
  |  Branch (2558:9): [True: 0, False: 273]
  ------------------
 2559|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2560|      0|    }
 2561|       |
 2562|    273|    it = strtok_r(s, ".", &buf);
 2563|       |    /* if the token has 0 length */
 2564|    273|    if (it == NULL) {
  ------------------
  |  Branch (2564:9): [True: 0, False: 273]
  ------------------
 2565|      0|        free(s);
 2566|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2567|      0|    }
 2568|    273|    do {
 2569|    273|        it_len = strlen(it);
 2570|    273|        if (it_len > ARPA_DOMAIN_MAX_LEN ||
  ------------------
  |  |  100|    546|#define ARPA_DOMAIN_MAX_LEN 63
  ------------------
  |  Branch (2570:13): [True: 0, False: 273]
  ------------------
 2571|       |            /* the first char must be a letter, but some virtual urls start
 2572|       |             * with a number */
 2573|    273|            isalnum(it[0]) == 0 ||
  ------------------
  |  Branch (2573:13): [True: 0, False: 273]
  ------------------
 2574|    273|            isalnum(it[it_len - 1]) == 0) {
  ------------------
  |  Branch (2574:13): [True: 0, False: 273]
  ------------------
 2575|      0|            free(s);
 2576|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2577|      0|        }
 2578|  2.73k|        while (*it != '\0') {
  ------------------
  |  Branch (2578:16): [True: 2.45k, False: 273]
  ------------------
 2579|  2.45k|            c = *it;
 2580|       |            /* the "." is allowed too, but tokenization removes it from the
 2581|       |             * string */
 2582|  2.45k|            if (isalnum(c) == 0 && c != '-') {
  ------------------
  |  Branch (2582:17): [True: 0, False: 2.45k]
  |  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|  2.45k|            it++;
 2587|  2.45k|        }
 2588|    273|    } while ((it = strtok_r(NULL, ".", &buf)) != NULL);
  ------------------
  |  Branch (2588:14): [True: 0, False: 273]
  ------------------
 2589|       |
 2590|    273|    free(s);
 2591|       |
 2592|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
 2593|    273|}
ssh_check_username_syntax:
 2606|    273|{
 2607|    273|    size_t username_len;
 2608|       |
 2609|    273|    if (username == NULL || *username == '-') {
  ------------------
  |  Branch (2609:9): [True: 0, False: 273]
  |  Branch (2609:29): [True: 0, False: 273]
  ------------------
 2610|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2611|      0|    }
 2612|       |
 2613|    273|    username_len = strlen(username);
 2614|    273|    if (username_len == 0 || username[username_len - 1] == '\\' ||
  ------------------
  |  Branch (2614:9): [True: 0, False: 273]
  |  Branch (2614:30): [True: 0, False: 273]
  ------------------
 2615|    273|        strpbrk(username, "'`\";&<>|(){}") != NULL) {
  ------------------
  |  Branch (2615:9): [True: 0, False: 273]
  ------------------
 2616|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2617|      0|    }
 2618|  1.36k|    for (size_t i = 0; i < username_len; i++) {
  ------------------
  |  Branch (2618:24): [True: 1.09k, False: 273]
  ------------------
 2619|  1.09k|        if (isspace(username[i]) != 0 && username[i + 1] == '-') {
  ------------------
  |  Branch (2619:13): [True: 0, False: 1.09k]
  |  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|  1.09k|    }
 2623|       |
 2624|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
 2625|    273|}
ssh_proxyjumps_free:
 2637|    546|{
 2638|    546|    struct ssh_jump_info_struct *jump = NULL;
 2639|       |
 2640|    546|    for (jump =
 2641|    546|             ssh_list_pop_head(struct ssh_jump_info_struct *, proxy_jump_list);
  ------------------
  |  |  122|    546|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2642|    546|         jump != NULL;
  ------------------
  |  Branch (2642:10): [True: 0, False: 546]
  ------------------
 2643|    546|         jump = ssh_list_pop_head(struct ssh_jump_info_struct *,
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2644|    546|                                  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|    546|}
ssh_strict_fopen:
 2683|    546|{
 2684|    546|    FILE *f = NULL;
 2685|    546|    struct stat sb;
 2686|    546|    int r, fd;
 2687|       |
 2688|       |    /* open first to avoid TOCTOU */
 2689|    546|    fd = open(filename, O_RDONLY);
 2690|    546|    if (fd == -1) {
  ------------------
  |  Branch (2690:9): [True: 546, False: 0]
  ------------------
 2691|    546|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  283|    546|    do {                                                            \
  |  |  284|    546|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|    546|        _ssh_log(priority,                                          \
  |  |  286|    546|                 __func__,                                          \
  |  |  287|    546|                 __VA_ARGS__,                                       \
  |  |  288|    546|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|    546|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|    546|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 546]
  |  |  ------------------
  ------------------
 2692|    546|                         errno,
 2693|    546|                         "Failed to open a file %s for reading: %s",
 2694|    546|                         filename);
 2695|    546|        return NULL;
 2696|    546|    }
 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|  1.09k|{
 2750|  1.09k|    size_t len = strlen(src);
 2751|       |
 2752|  1.09k|    if (size != 0) {
  ------------------
  |  Branch (2752:9): [True: 1.09k, False: 0]
  ------------------
 2753|  1.09k|        size_t copy_len = (len >= size) ? size - 1 : len;
  ------------------
  |  Branch (2753:27): [True: 0, False: 1.09k]
  ------------------
 2754|       |
 2755|  1.09k|        memcpy(dst, src, copy_len);
 2756|  1.09k|        dst[copy_len] = '\0';
 2757|  1.09k|    }
 2758|       |
 2759|  1.09k|    return len;
 2760|  1.09k|}
ssh_normalize_loose_ip:
 2797|    546|{
 2798|    546|    struct in_addr addr;
 2799|    546|    char buf[INET_ADDRSTRLEN];
 2800|    546|    const char *p = NULL;
 2801|    546|    int rc;
 2802|    546|    int is_ip;
 2803|       |#ifdef _WIN32
 2804|       |    unsigned long ip;
 2805|       |    int is_broadcast;
 2806|       |#endif
 2807|       |
 2808|    546|    if (host == NULL || result == NULL) {
  ------------------
  |  Branch (2808:9): [True: 0, False: 546]
  |  Branch (2808:25): [True: 0, False: 546]
  ------------------
 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|    546|    is_ip = ssh_is_ipaddr(host);
 2815|    546|    if (is_ip) {
  ------------------
  |  Branch (2815:9): [True: 0, False: 546]
  ------------------
 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|    546|    rc = inet_aton(host, &addr);
 2828|    546|    if (rc == 0) {
  ------------------
  |  Branch (2828:9): [True: 546, False: 0]
  ------------------
 2829|    546|        return 1; /* not a loose IP */
 2830|    546|    }
 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|    546|{
  330|    546|    char *szPath = NULL;
  331|    546|    struct passwd pwd;
  332|    546|    struct passwd *pwdbuf = NULL;
  333|    546|    char buf[NSS_BUFLEN_PASSWD] = {0};
  334|    546|    int rc;
  335|       |
  336|    546|    rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
  337|    546|    if (rc != 0 || pwdbuf == NULL ) {
  ------------------
  |  Branch (337:9): [True: 0, False: 546]
  |  Branch (337:20): [True: 0, False: 546]
  ------------------
  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|    546|    szPath = strdup(pwd.pw_dir);
  347|       |
  348|    546|    return szPath;
  349|    546|}
misc.c:ssh_iterator_new:
  947|  4.64k|{
  948|  4.64k|    struct ssh_iterator *iterator = malloc(sizeof(struct ssh_iterator));
  949|       |
  950|  4.64k|    if (iterator == NULL) {
  ------------------
  |  Branch (950:9): [True: 0, False: 4.64k]
  ------------------
  951|      0|        return NULL;
  952|      0|    }
  953|  4.64k|    iterator->next = NULL;
  954|  4.64k|    iterator->data = data;
  955|  4.64k|    return iterator;
  956|  4.64k|}
misc.c:ssh_path_expand_internal:
 1478|  1.09k|{
 1479|  1.09k|    char *buf = NULL;
 1480|  1.09k|    char *r = NULL;
 1481|  1.09k|    char *x = NULL;
 1482|  1.09k|    const char *p = NULL;
 1483|  1.09k|    size_t i, l;
 1484|       |
 1485|  1.09k|    r = ssh_path_expand_tilde(s);
 1486|  1.09k|    if (r == NULL) {
  ------------------
  |  Branch (1486:9): [True: 0, False: 1.09k]
  ------------------
 1487|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1488|      0|        return NULL;
 1489|      0|    }
 1490|       |
 1491|  1.09k|    if (strlen(r) > MAX_BUF_SIZE) {
  ------------------
  |  |  230|  1.09k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1491:9): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|    buf = malloc(MAX_BUF_SIZE);
  ------------------
  |  |  230|  1.09k|#define MAX_BUF_SIZE 4096
  ------------------
 1498|  1.09k|    if (buf == NULL) {
  ------------------
  |  Branch (1498:9): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|    p = r;
 1505|  1.09k|    buf[0] = '\0';
 1506|       |
 1507|  18.2k|    for (i = 0; *p != '\0'; p++) {
  ------------------
  |  Branch (1507:17): [True: 17.1k, False: 1.09k]
  ------------------
 1508|  17.1k|        if (*p != '%') {
  ------------------
  |  Branch (1508:13): [True: 16.1k, False: 1.09k]
  ------------------
 1509|  16.1k|            buf[i] = hostname_lenient ? tolower((unsigned char)*p) : *p;
  ------------------
  |  Branch (1509:22): [True: 0, False: 16.1k]
  |  Branch (1509:41): [True: 0, False: 0]
  |  Branch (1509:41): [True: 0, False: 0]
  |  Branch (1509:41): [Folded, False: 0]
  ------------------
 1510|  16.1k|            i++;
 1511|  16.1k|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|  16.1k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1511:17): [True: 0, False: 16.1k]
  ------------------
 1512|      0|                free(buf);
 1513|      0|                free(r);
 1514|      0|                return NULL;
 1515|      0|            }
 1516|  16.1k|            buf[i] = '\0';
 1517|  16.1k|            continue;
 1518|  16.1k|        }
 1519|       |
 1520|  1.09k|        p++;
 1521|  1.09k|        if (*p == '\0') {
  ------------------
  |  Branch (1521:13): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|        if (hostname_lenient && *p != '%' && *p != 'h') {
  ------------------
  |  Branch (1535:13): [True: 0, False: 1.09k]
  |  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|  1.09k|        switch (*p) {
 1557|      0|        case '%':
  ------------------
  |  Branch (1557:9): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|        case 'd':
  ------------------
  |  Branch (1567:9): [True: 1.09k, False: 0]
  ------------------
 1568|  1.09k|            x = ssh_get_user_home_dir(session);
 1569|  1.09k|            if (x == NULL) {
  ------------------
  |  Branch (1569:17): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|            break;
 1576|  1.09k|        case 'u':
  ------------------
  |  Branch (1576:9): [True: 0, False: 1.09k]
  ------------------
 1577|      0|            x = ssh_get_local_username();
 1578|      0|            break;
 1579|      0|        case 'l':
  ------------------
  |  Branch (1579:9): [True: 0, False: 1.09k]
  ------------------
 1580|      0|            x = ssh_get_local_hostname();
 1581|      0|            break;
 1582|      0|        case 'h':
  ------------------
  |  Branch (1582:9): [True: 0, False: 1.09k]
  ------------------
 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: 1.09k]
  ------------------
 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: 1.09k]
  ------------------
 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: 1.09k]
  ------------------
 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: 1.09k]
  ------------------
 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: 1.09k]
  ------------------
 1635|      0|            x = get_connection_hash(session);
 1636|      0|            break;
 1637|      0|        default:
  ------------------
  |  Branch (1637:9): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|        }
 1643|       |
 1644|  1.09k|        if (x == NULL) {
  ------------------
  |  Branch (1644:13): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|        i += strlen(x);
 1652|  1.09k|        if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|  1.09k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1652:13): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|        l = strlen(buf);
 1660|  1.09k|        strlcpy(buf + l, x, MAX_BUF_SIZE - l);
  ------------------
  |  |  230|  1.09k|#define MAX_BUF_SIZE 4096
  ------------------
 1661|  1.09k|        buf[i] = '\0';
 1662|  1.09k|        SAFE_FREE(x);
  ------------------
  |  |  373|  1.09k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.09k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
 1663|  1.09k|    }
 1664|       |
 1665|  1.09k|    free(r);
 1666|       |
 1667|       |    /* strip the unused space by realloc */
 1668|  1.09k|    x = realloc(buf, strlen(buf) + 1);
 1669|  1.09k|    if (x == NULL) {
  ------------------
  |  Branch (1669:9): [True: 0, False: 1.09k]
  ------------------
 1670|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1671|      0|        free(buf);
 1672|      0|    }
 1673|  1.09k|    return x;
 1674|  1.09k|}
misc.c:ssh_timestamp_difference:
 1875|  24.2k|{
 1876|  24.2k|    long seconds, usecs, msecs;
 1877|  24.2k|    seconds = new->seconds - old->seconds;
 1878|  24.2k|    usecs = new->useconds - old->useconds;
 1879|  24.2k|    if (usecs < 0){
  ------------------
  |  Branch (1879:9): [True: 10, False: 24.2k]
  ------------------
 1880|     10|        seconds--;
 1881|     10|        usecs += 1000000;
 1882|     10|    }
 1883|  24.2k|    msecs = seconds * 1000 + usecs/1000;
 1884|  24.2k|    return msecs;
 1885|  24.2k|}

kex_type_to_mlkem_info:
   28|  1.36k|{
   29|  1.36k|    switch (kex_type) {
   30|  1.36k|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (30:5): [True: 1.36k, False: 0]
  ------------------
   31|  1.36k|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (31:5): [True: 0, False: 1.36k]
  ------------------
   32|  1.36k|        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: 1.36k]
  ------------------
   38|       |        return NULL;
   39|  1.36k|    }
   40|  1.36k|}

ssh_mlkem_init:
   41|    273|{
   42|    273|    int ret = SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   43|    273|    struct ssh_crypto_struct *crypto = session->next_crypto;
   44|    273|    const struct mlkem_type_info *mlkem_info = NULL;
   45|    273|    unsigned char rnd[LIBCRUX_ML_KEM_KEY_PAIR_PRNG_LEN];
   46|    273|    struct libcrux_mlkem768_keypair keypair;
   47|    273|    int err;
   48|       |
   49|    273|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
   50|    273|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (50:9): [True: 0, False: 273]
  ------------------
   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|    273|    err = ssh_get_random(rnd, sizeof(rnd), 0);
   56|    273|    if (err != 1) {
  ------------------
  |  Branch (56:9): [True: 0, False: 273]
  ------------------
   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|    273|    keypair = libcrux_ml_kem_mlkem768_portable_generate_key_pair(rnd);
   63|       |
   64|    273|    if (ssh_string_len(crypto->mlkem_client_pubkey) < mlkem_info->pubkey_size) {
  ------------------
  |  Branch (64:9): [True: 273, False: 0]
  ------------------
   65|    273|        SSH_STRING_FREE(crypto->mlkem_client_pubkey);
  ------------------
  |  |  915|    273|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 273]
  |  |  |  Branch (915:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
   66|    273|    }
   67|    273|    if (crypto->mlkem_client_pubkey == NULL) {
  ------------------
  |  Branch (67:9): [True: 273, False: 0]
  ------------------
   68|    273|        crypto->mlkem_client_pubkey = ssh_string_new(mlkem_info->pubkey_size);
   69|    273|        if (crypto->mlkem_client_pubkey == NULL) {
  ------------------
  |  Branch (69:13): [True: 0, False: 273]
  ------------------
   70|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
   71|      0|            goto cleanup;
   72|      0|        }
   73|    273|    }
   74|    273|    err = ssh_string_fill(crypto->mlkem_client_pubkey,
   75|    273|                          keypair.pk.value,
   76|    273|                          mlkem_info->pubkey_size);
   77|    273|    if (err) {
  ------------------
  |  Branch (77:9): [True: 0, False: 273]
  ------------------
   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|    273|    if (crypto->mlkem_privkey == NULL) {
  ------------------
  |  Branch (83:9): [True: 273, False: 0]
  ------------------
   84|    273|        crypto->mlkem_privkey = malloc(mlkem_info->privkey_size);
   85|    273|        if (crypto->mlkem_privkey == NULL) {
  ------------------
  |  Branch (85:13): [True: 0, False: 273]
  ------------------
   86|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
   87|      0|            goto cleanup;
   88|      0|        }
   89|    273|    }
   90|    273|    memcpy(crypto->mlkem_privkey, keypair.sk.value, mlkem_info->privkey_size);
   91|    273|    crypto->mlkem_privkey_len = mlkem_info->privkey_size;
   92|       |
   93|    273|    ret = SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
   94|       |
   95|    273|cleanup:
   96|    273|    ssh_burn(&keypair, sizeof(keypair));
  ------------------
  |  |  388|    273|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
   97|    273|    ssh_burn(rnd, sizeof(rnd));
  ------------------
  |  |  388|    273|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
   98|    273|    return ret;
   99|    273|}
ssh_mlkem_encapsulate:
  103|    273|{
  104|    273|    int ret = SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  105|    273|    const struct mlkem_type_info *mlkem_info = NULL;
  106|    273|    struct ssh_crypto_struct *crypto = session->next_crypto;
  107|    273|    const unsigned char *pubkey_data = NULL;
  108|    273|    ssh_string pubkey = crypto->mlkem_client_pubkey;
  109|    273|    struct libcrux_mlkem768_enc_result enc;
  110|    273|    struct libcrux_mlkem768_pk mlkem_pub = {0};
  111|    273|    unsigned char rnd[LIBCRUX_ML_KEM_ENC_PRNG_LEN];
  112|    273|    int err;
  113|       |
  114|    273|    if (pubkey == NULL) {
  ------------------
  |  Branch (114:9): [True: 0, False: 273]
  ------------------
  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|    273|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
  120|    273|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (120:9): [True: 0, False: 273]
  ------------------
  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|    273|    pubkey_data = ssh_string_data(pubkey);
  126|    273|    memcpy(mlkem_pub.value, pubkey_data, mlkem_info->pubkey_size);
  127|    273|    err = libcrux_ml_kem_mlkem768_portable_validate_public_key(&mlkem_pub);
  128|    273|    if (err == 0) {
  ------------------
  |  Branch (128:9): [True: 0, False: 273]
  ------------------
  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|    273|    err = ssh_get_random(rnd, sizeof(rnd), 0);
  134|    273|    if (err != 1) {
  ------------------
  |  Branch (134:9): [True: 0, False: 273]
  ------------------
  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|    273|    enc = libcrux_ml_kem_mlkem768_portable_encapsulate(&mlkem_pub, rnd);
  141|       |
  142|    273|    if (ssh_string_len(crypto->mlkem_ciphertext) < mlkem_info->ciphertext_size) {
  ------------------
  |  Branch (142:9): [True: 273, False: 0]
  ------------------
  143|    273|        SSH_STRING_FREE(crypto->mlkem_ciphertext);
  ------------------
  |  |  915|    273|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 273]
  |  |  |  Branch (915:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
  144|    273|    }
  145|    273|    if (crypto->mlkem_ciphertext == NULL) {
  ------------------
  |  Branch (145:9): [True: 273, False: 0]
  ------------------
  146|    273|        crypto->mlkem_ciphertext = ssh_string_new(mlkem_info->ciphertext_size);
  147|    273|        if (crypto->mlkem_ciphertext == NULL) {
  ------------------
  |  Branch (147:13): [True: 0, False: 273]
  ------------------
  148|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  149|      0|            goto cleanup;
  150|      0|        }
  151|    273|    }
  152|    273|    err = ssh_string_fill(crypto->mlkem_ciphertext,
  153|    273|                          enc.fst.value,
  154|    273|                          sizeof(enc.fst.value));
  155|    273|    if (err != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (155:9): [True: 0, False: 273]
  ------------------
  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|    273|    memcpy(shared_secret, enc.snd, sizeof(enc.snd));
  160|       |
  161|    273|    ret = SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  162|       |
  163|    273|cleanup:
  164|    273|    ssh_burn(rnd, sizeof(rnd));
  ------------------
  |  |  388|    273|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  165|    273|    ssh_burn(&enc, sizeof(enc));
  ------------------
  |  |  388|    273|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  166|    273|    return ret;
  167|    273|}
ssh_mlkem_decapsulate:
  171|    273|{
  172|    273|    const struct mlkem_type_info *mlkem_info = NULL;
  173|    273|    struct ssh_crypto_struct *crypto = session->next_crypto;
  174|    273|    ssh_string ciphertext = NULL;
  175|    273|    unsigned char *ciphertext_data = NULL;
  176|    273|    struct libcrux_mlkem768_sk mlkem_priv = {0};
  177|    273|    struct libcrux_mlkem768_ciphertext mlkem_ciphertext = {0};
  178|       |
  179|    273|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
  180|    273|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (180:9): [True: 0, False: 273]
  ------------------
  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|    273|    ciphertext = crypto->mlkem_ciphertext;
  186|    273|    if (ciphertext == NULL) {
  ------------------
  |  Branch (186:9): [True: 0, False: 273]
  ------------------
  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|    273|    ciphertext_data = ssh_string_data(ciphertext);
  192|    273|    memcpy(mlkem_ciphertext.value,
  193|    273|           ciphertext_data,
  194|    273|           sizeof(mlkem_ciphertext.value));
  195|       |
  196|    273|    memcpy(mlkem_priv.value, crypto->mlkem_privkey, crypto->mlkem_privkey_len);
  197|       |
  198|    273|    libcrux_ml_kem_mlkem768_portable_decapsulate(&mlkem_priv,
  199|    273|                                                 &mlkem_ciphertext,
  200|    273|                                                 shared_secret);
  201|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  202|    273|}

ssh_options_set_algo:
  374|  2.45k|{
  375|       |    /* When the list start with +,-,^ the filtration of unknown algorithms
  376|       |     * gets handled inside the helper functions, otherwise the list is taken
  377|       |     * as it is. */
  378|  2.45k|    char *p = (char *)list;
  379|       |
  380|  2.45k|    if (algo < SSH_COMP_C_S) {
  ------------------
  |  Branch (380:9): [True: 2.45k, False: 0]
  ------------------
  381|  2.45k|        if (list[0] == '+') {
  ------------------
  |  Branch (381:13): [True: 0, False: 2.45k]
  ------------------
  382|      0|            p = ssh_add_to_default_algos(algo, list+1);
  383|  2.45k|        } else if (list[0] == '-') {
  ------------------
  |  Branch (383:20): [True: 0, False: 2.45k]
  ------------------
  384|      0|            p = ssh_remove_from_default_algos(algo, list+1);
  385|  2.45k|        } else if (list[0] == '^') {
  ------------------
  |  Branch (385:20): [True: 0, False: 2.45k]
  ------------------
  386|      0|            p = ssh_prefix_default_algos(algo, list+1);
  387|      0|        }
  388|  2.45k|    }
  389|       |
  390|  2.45k|    if (p == list) {
  ------------------
  |  Branch (390:9): [True: 2.45k, False: 0]
  ------------------
  391|  2.45k|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|  2.45k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 2.45k]
  |  |  ------------------
  ------------------
  392|      0|            p = ssh_keep_fips_algos(algo, list);
  393|  2.45k|        } else {
  394|  2.45k|            p = ssh_keep_known_algos(algo, list);
  395|  2.45k|        }
  396|  2.45k|    }
  397|       |
  398|  2.45k|    if (p == NULL) {
  ------------------
  |  Branch (398:9): [True: 0, False: 2.45k]
  ------------------
  399|      0|        ssh_set_error(session, SSH_REQUEST_DENIED,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  400|      0|                "Setting method: no allowed algorithm for method \"%s\" (%s)",
  401|      0|                ssh_kex_get_description(algo), list);
  402|      0|        return -1;
  403|      0|    }
  404|       |
  405|  2.45k|    SAFE_FREE(*place);
  ------------------
  |  |  373|  2.45k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 2.45k]
  |  |  |  Branch (373:71): [Folded, False: 2.45k]
  |  |  ------------------
  ------------------
  406|  2.45k|    *place = p;
  407|       |
  408|  2.45k|    return 0;
  409|  2.45k|}
ssh_options_set:
  882|  3.00k|{
  883|  3.00k|    const char *v = NULL;
  884|  3.00k|    char *p = NULL, *q = NULL;
  885|  3.00k|    long int i;
  886|  3.00k|    unsigned int u;
  887|  3.00k|    int rc;
  888|  3.00k|    char **wanted_methods = session->opts.wanted_methods;
  889|  3.00k|    struct ssh_jump_callbacks_struct *j = NULL;
  890|       |
  891|  3.00k|    if (session == NULL) {
  ------------------
  |  Branch (891:9): [True: 0, False: 3.00k]
  ------------------
  892|      0|        return -1;
  893|      0|    }
  894|       |
  895|  3.00k|    switch (type) {
  896|    273|        case SSH_OPTIONS_HOST:
  ------------------
  |  Branch (896:9): [True: 273, False: 2.73k]
  ------------------
  897|    273|            v = value;
  898|    273|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (898:17): [True: 0, False: 273]
  |  Branch (898:30): [True: 0, False: 273]
  ------------------
  899|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  900|      0|                return -1;
  901|    273|            } else {
  902|    273|                char *username = NULL, *hostname = NULL;
  903|    273|                char *strict_hostname = NULL;
  904|    273|                char *normalized = NULL;
  905|       |
  906|       |                /* Non-strict parse: reject shell metacharacters */
  907|    273|                rc = ssh_config_parse_uri(value,
  908|    273|                                          &username,
  909|    273|                                          &hostname,
  910|    273|                                          NULL,
  911|    273|                                          true,
  912|    273|                                          false);
  913|    273|                if (rc != SSH_OK || hostname == NULL) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (913:21): [True: 0, False: 273]
  |  Branch (913:37): [True: 0, False: 273]
  ------------------
  914|      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]
  |  |  ------------------
  ------------------
  915|      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]
  |  |  ------------------
  ------------------
  916|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  917|      0|                    return -1;
  918|      0|                }
  919|       |
  920|       |                /* Non-strict passed: set username and originalhost */
  921|    273|                if (username != NULL) {
  ------------------
  |  Branch (921:21): [True: 0, False: 273]
  ------------------
  922|      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]
  |  |  ------------------
  ------------------
  923|      0|                    session->opts.username = username;
  924|      0|                }
  925|    273|                if (!session->opts.config_hostname_only) {
  ------------------
  |  Branch (925:21): [True: 273, False: 0]
  ------------------
  926|    273|                    SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  927|    273|                    SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  928|    273|                    session->opts.originalhost = hostname;
  929|    273|                } else {
  930|      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]
  |  |  ------------------
  ------------------
  931|      0|                }
  932|       |
  933|       |                /* Strict parse: set host only if valid hostname or IP */
  934|    273|                rc = ssh_normalize_loose_ip(value, &normalized);
  935|    273|                if (rc == -1) {
  ------------------
  |  Branch (935:21): [True: 0, False: 273]
  ------------------
  936|       |                    /* Error */
  937|      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]
  |  |  ------------------
  ------------------
  938|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  939|      0|                    return -1;
  940|      0|                }
  941|    273|                rc = ssh_config_parse_uri(
  942|    273|                    (normalized != NULL) ? normalized : value,
  ------------------
  |  Branch (942:21): [True: 0, False: 273]
  ------------------
  943|    273|                    NULL,
  944|    273|                    &strict_hostname,
  945|    273|                    NULL,
  946|    273|                    true,
  947|    273|                    true);
  948|    273|                SAFE_FREE(normalized);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  949|       |
  950|    273|                if (rc != SSH_OK || strict_hostname == NULL) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (950:21): [True: 0, False: 273]
  |  Branch (950:37): [True: 0, False: 273]
  ------------------
  951|      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]
  |  |  ------------------
  ------------------
  952|      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]
  |  |  ------------------
  ------------------
  953|      0|                    if (session->opts.config_hostname_only) {
  ------------------
  |  Branch (953:25): [True: 0, False: 0]
  ------------------
  954|       |                        /* Config path: Hostname must be valid */
  955|      0|                        ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  956|      0|                        return -1;
  957|      0|                    }
  958|    273|                } else {
  959|    273|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  960|    273|                    session->opts.host = strict_hostname;
  961|    273|                }
  962|    273|            }
  963|    273|            break;
  964|    273|        case SSH_OPTIONS_PORT:
  ------------------
  |  Branch (964:9): [True: 0, False: 3.00k]
  ------------------
  965|      0|            if (value == NULL) {
  ------------------
  |  Branch (965:17): [True: 0, False: 0]
  ------------------
  966|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  967|      0|                return -1;
  968|      0|            } else {
  969|      0|                int *x = (int *) value;
  970|      0|                if (*x <= 0 || *x > 65535) {
  ------------------
  |  Branch (970:21): [True: 0, False: 0]
  |  Branch (970:32): [True: 0, False: 0]
  ------------------
  971|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  972|      0|                    return -1;
  973|      0|                }
  974|       |
  975|      0|                session->opts.port = *x;
  976|      0|            }
  977|      0|            break;
  978|      0|        case SSH_OPTIONS_PORT_STR:
  ------------------
  |  Branch (978:9): [True: 0, False: 3.00k]
  ------------------
  979|      0|            v = value;
  980|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (980:17): [True: 0, False: 0]
  |  Branch (980:30): [True: 0, False: 0]
  ------------------
  981|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  982|      0|                return -1;
  983|      0|            } else {
  984|      0|                q = strdup(v);
  985|      0|                if (q == NULL) {
  ------------------
  |  Branch (985:21): [True: 0, False: 0]
  ------------------
  986|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  987|      0|                    return -1;
  988|      0|                }
  989|      0|                i = strtol(q, &p, 10);
  990|      0|                if (q == p || *p != '\0') {
  ------------------
  |  Branch (990:21): [True: 0, False: 0]
  |  Branch (990:31): [True: 0, False: 0]
  ------------------
  991|      0|                    SSH_LOG(SSH_LOG_DEBUG, "No port number was parsed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  992|      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]
  |  |  ------------------
  ------------------
  993|      0|                    return -1;
  994|      0|                }
  995|      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]
  |  |  ------------------
  ------------------
  996|      0|                if (i <= 0 || i > 65535) {
  ------------------
  |  Branch (996:21): [True: 0, False: 0]
  |  Branch (996:31): [True: 0, False: 0]
  ------------------
  997|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  998|      0|                    return -1;
  999|      0|                }
 1000|       |
 1001|      0|                session->opts.port = i;
 1002|      0|            }
 1003|      0|            break;
 1004|    273|        case SSH_OPTIONS_FD:
  ------------------
  |  Branch (1004:9): [True: 273, False: 2.73k]
  ------------------
 1005|    273|            if (value == NULL) {
  ------------------
  |  Branch (1005:17): [True: 0, False: 273]
  ------------------
 1006|      0|                session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
 1007|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1008|      0|                return -1;
 1009|    273|            } else {
 1010|    273|                socket_t *x = (socket_t *) value;
 1011|    273|                if (*x < 0) {
  ------------------
  |  Branch (1011:21): [True: 0, False: 273]
  ------------------
 1012|      0|                    session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
 1013|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1014|      0|                    return -1;
 1015|      0|                }
 1016|       |
 1017|    273|                session->opts.fd = *x & 0xffff;
 1018|    273|            }
 1019|    273|            break;
 1020|    273|        case SSH_OPTIONS_BINDADDR:
  ------------------
  |  Branch (1020:9): [True: 0, False: 3.00k]
  ------------------
 1021|      0|            v = value;
 1022|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1022:17): [True: 0, False: 0]
  |  Branch (1022:30): [True: 0, False: 0]
  ------------------
 1023|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1024|      0|                return -1;
 1025|      0|            }
 1026|       |
 1027|      0|            q = strdup(v);
 1028|      0|            if (q == NULL) {
  ------------------
  |  Branch (1028:17): [True: 0, False: 0]
  ------------------
 1029|      0|                return -1;
 1030|      0|            }
 1031|      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]
  |  |  ------------------
  ------------------
 1032|      0|            session->opts.bindaddr = q;
 1033|      0|            break;
 1034|    273|        case SSH_OPTIONS_USER:
  ------------------
  |  Branch (1034:9): [True: 273, False: 2.73k]
  ------------------
 1035|    273|            v = value;
 1036|    273|            SAFE_FREE(session->opts.username);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
 1037|    273|            if (v == NULL) {
  ------------------
  |  Branch (1037:17): [True: 0, False: 273]
  ------------------
 1038|      0|                q = ssh_get_local_username();
 1039|      0|                if (q == NULL) {
  ------------------
  |  Branch (1039:21): [True: 0, False: 0]
  ------------------
 1040|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1041|      0|                    return -1;
 1042|      0|                }
 1043|      0|                session->opts.username = q;
 1044|    273|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1044:24): [True: 0, False: 273]
  ------------------
 1045|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1046|      0|                return -1;
 1047|    273|            } else { /* username provided */
 1048|    273|                session->opts.username = strdup(value);
 1049|    273|                if (session->opts.username == NULL) {
  ------------------
  |  Branch (1049:21): [True: 0, False: 273]
  ------------------
 1050|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1051|      0|                    return -1;
 1052|      0|                }
 1053|    273|                rc = ssh_check_username_syntax(session->opts.username);
 1054|    273|                if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1054:21): [True: 0, False: 273]
  ------------------
 1055|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1056|      0|                    return -1;
 1057|      0|                }
 1058|    273|            }
 1059|    273|            break;
 1060|    273|        case SSH_OPTIONS_SSH_DIR:
  ------------------
  |  Branch (1060:9): [True: 273, False: 2.73k]
  ------------------
 1061|    273|            v = value;
 1062|    273|            SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
 1063|    273|            if (v == NULL) {
  ------------------
  |  Branch (1063:17): [True: 273, False: 0]
  ------------------
 1064|    273|                session->opts.sshdir = ssh_path_expand_tilde("~/.ssh");
 1065|    273|                if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (1065:21): [True: 0, False: 273]
  ------------------
 1066|      0|                    return -1;
 1067|      0|                }
 1068|    273|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1068:24): [True: 0, False: 0]
  ------------------
 1069|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1070|      0|                return -1;
 1071|      0|            } else {
 1072|      0|                session->opts.sshdir = ssh_path_expand_tilde(v);
 1073|      0|                if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (1073:21): [True: 0, False: 0]
  ------------------
 1074|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1075|      0|                    return -1;
 1076|      0|                }
 1077|      0|            }
 1078|    273|            break;
 1079|    273|        case SSH_OPTIONS_IDENTITY:
  ------------------
  |  Branch (1079:9): [True: 0, False: 3.00k]
  ------------------
 1080|      0|        case SSH_OPTIONS_ADD_IDENTITY:
  ------------------
  |  Branch (1080:9): [True: 0, False: 3.00k]
  ------------------
 1081|      0|            v = value;
 1082|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1082:17): [True: 0, False: 0]
  |  Branch (1082:30): [True: 0, False: 0]
  ------------------
 1083|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1084|      0|                return -1;
 1085|      0|            }
 1086|      0|            q = strdup(v);
 1087|      0|            if (q == NULL) {
  ------------------
  |  Branch (1087:17): [True: 0, False: 0]
  ------------------
 1088|      0|                return -1;
 1089|      0|            }
 1090|      0|            if (session->opts.exp_flags & SSH_OPT_EXP_FLAG_IDENTITY) {
  ------------------
  |  |  118|      0|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
  |  Branch (1090:17): [True: 0, False: 0]
  ------------------
 1091|      0|                rc = ssh_list_append(session->opts.identity_non_exp, q);
 1092|      0|            } else {
 1093|      0|                rc = ssh_list_prepend(session->opts.identity_non_exp, q);
 1094|      0|            }
 1095|      0|            if (rc < 0) {
  ------------------
  |  Branch (1095:17): [True: 0, False: 0]
  ------------------
 1096|      0|                free(q);
 1097|      0|                return -1;
 1098|      0|            }
 1099|      0|            break;
 1100|      0|        case SSH_OPTIONS_CERTIFICATE:
  ------------------
  |  Branch (1100:9): [True: 0, False: 3.00k]
  ------------------
 1101|      0|            v = value;
 1102|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1102:17): [True: 0, False: 0]
  |  Branch (1102:30): [True: 0, False: 0]
  ------------------
 1103|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1104|      0|                return -1;
 1105|      0|            }
 1106|      0|            q = strdup(v);
 1107|      0|            if (q == NULL) {
  ------------------
  |  Branch (1107:17): [True: 0, False: 0]
  ------------------
 1108|      0|                return -1;
 1109|      0|            }
 1110|      0|            rc = ssh_list_append(session->opts.certificate_non_exp, q);
 1111|      0|            if (rc < 0) {
  ------------------
  |  Branch (1111:17): [True: 0, False: 0]
  ------------------
 1112|      0|                free(q);
 1113|      0|                return -1;
 1114|      0|            }
 1115|      0|            break;
 1116|      0|        case SSH_OPTIONS_KNOWNHOSTS:
  ------------------
  |  Branch (1116:9): [True: 0, False: 3.00k]
  ------------------
 1117|      0|            v = value;
 1118|      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]
  |  |  ------------------
  ------------------
 1119|      0|            if (v == NULL) {
  ------------------
  |  Branch (1119:17): [True: 0, False: 0]
  ------------------
 1120|       |                /* The default value will be set by the ssh_options_apply() */
 1121|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1121:24): [True: 0, False: 0]
  ------------------
 1122|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1123|      0|                return -1;
 1124|      0|            } else {
 1125|      0|                session->opts.knownhosts = strdup(v);
 1126|      0|                if (session->opts.knownhosts == NULL) {
  ------------------
  |  Branch (1126:21): [True: 0, False: 0]
  ------------------
 1127|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1128|      0|                    return -1;
 1129|      0|                }
 1130|      0|                session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_KNOWNHOSTS;
  ------------------
  |  |  115|      0|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
 1131|      0|            }
 1132|      0|            break;
 1133|      0|        case SSH_OPTIONS_GLOBAL_KNOWNHOSTS:
  ------------------
  |  Branch (1133:9): [True: 0, False: 3.00k]
  ------------------
 1134|      0|            v = value;
 1135|      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]
  |  |  ------------------
  ------------------
 1136|      0|            if (v == NULL) {
  ------------------
  |  Branch (1136:17): [True: 0, False: 0]
  ------------------
 1137|      0|                session->opts.global_knownhosts =
 1138|      0|                    strdup(GLOBAL_CONF_DIR "/ssh_known_hosts");
  ------------------
  |  |   13|      0|#define GLOBAL_CONF_DIR "/etc/ssh"
  ------------------
 1139|      0|                if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (1139:21): [True: 0, False: 0]
  ------------------
 1140|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1141|      0|                    return -1;
 1142|      0|                }
 1143|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1143:24): [True: 0, False: 0]
  ------------------
 1144|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1145|      0|                return -1;
 1146|      0|            } else {
 1147|      0|                session->opts.global_knownhosts = strdup(v);
 1148|      0|                if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (1148:21): [True: 0, False: 0]
  ------------------
 1149|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1150|      0|                    return -1;
 1151|      0|                }
 1152|      0|                session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS;
  ------------------
  |  |  116|      0|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
 1153|      0|            }
 1154|      0|            break;
 1155|    546|        case SSH_OPTIONS_TIMEOUT:
  ------------------
  |  Branch (1155:9): [True: 546, False: 2.45k]
  ------------------
 1156|    546|            if (value == NULL) {
  ------------------
  |  Branch (1156:17): [True: 0, False: 546]
  ------------------
 1157|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1158|      0|                return -1;
 1159|    546|            } else {
 1160|    546|                long *x = (long *) value;
 1161|    546|                if (*x < 0) {
  ------------------
  |  Branch (1161:21): [True: 0, False: 546]
  ------------------
 1162|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1163|      0|                    return -1;
 1164|      0|                }
 1165|       |
 1166|    546|                session->opts.timeout = *x & 0xffffffffU;
 1167|    546|            }
 1168|    546|            break;
 1169|    546|        case SSH_OPTIONS_TIMEOUT_USEC:
  ------------------
  |  Branch (1169:9): [True: 0, False: 3.00k]
  ------------------
 1170|      0|            if (value == NULL) {
  ------------------
  |  Branch (1170:17): [True: 0, False: 0]
  ------------------
 1171|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1172|      0|                return -1;
 1173|      0|            } else {
 1174|      0|                long *x = (long *) value;
 1175|      0|                if (*x < 0) {
  ------------------
  |  Branch (1175:21): [True: 0, False: 0]
  ------------------
 1176|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1177|      0|                    return -1;
 1178|      0|                }
 1179|       |
 1180|      0|                session->opts.timeout_usec = *x & 0xffffffffU;
 1181|      0|            }
 1182|      0|            break;
 1183|      0|        case SSH_OPTIONS_SSH1:
  ------------------
  |  Branch (1183:9): [True: 0, False: 3.00k]
  ------------------
 1184|      0|            break;
 1185|      0|        case SSH_OPTIONS_SSH2:
  ------------------
  |  Branch (1185:9): [True: 0, False: 3.00k]
  ------------------
 1186|      0|            break;
 1187|      0|        case SSH_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (1187:9): [True: 0, False: 3.00k]
  ------------------
 1188|      0|            if (value == NULL) {
  ------------------
  |  Branch (1188:17): [True: 0, False: 0]
  ------------------
 1189|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1190|      0|                return -1;
 1191|      0|            } else {
 1192|      0|                int *x = (int *) value;
 1193|      0|                if (*x < 0) {
  ------------------
  |  Branch (1193:21): [True: 0, False: 0]
  ------------------
 1194|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1195|      0|                    return -1;
 1196|      0|                }
 1197|       |
 1198|      0|                session->common.log_verbosity = *x & 0xffffU;
 1199|      0|                ssh_set_log_level(*x & 0xffffU);
 1200|      0|            }
 1201|      0|            break;
 1202|      0|        case SSH_OPTIONS_LOG_VERBOSITY_STR:
  ------------------
  |  Branch (1202:9): [True: 0, False: 3.00k]
  ------------------
 1203|      0|            v = value;
 1204|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1204:17): [True: 0, False: 0]
  |  Branch (1204:30): [True: 0, False: 0]
  ------------------
 1205|      0|                session->common.log_verbosity = 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|                q = strdup(v);
 1210|      0|                if (q == NULL) {
  ------------------
  |  Branch (1210:21): [True: 0, False: 0]
  ------------------
 1211|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1212|      0|                    return -1;
 1213|      0|                }
 1214|      0|                i = strtol(q, &p, 10);
 1215|      0|                if (q == p) {
  ------------------
  |  Branch (1215:21): [True: 0, False: 0]
  ------------------
 1216|      0|                    SSH_LOG(SSH_LOG_DEBUG, "No log verbositiy was parsed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1217|      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]
  |  |  ------------------
  ------------------
 1218|      0|                    return -1;
 1219|      0|                }
 1220|      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]
  |  |  ------------------
  ------------------
 1221|      0|                if (i < 0) {
  ------------------
  |  Branch (1221:21): [True: 0, False: 0]
  ------------------
 1222|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1223|      0|                    return -1;
 1224|      0|                }
 1225|       |
 1226|      0|                session->common.log_verbosity = i & 0xffffU;
 1227|      0|                ssh_set_log_level(i & 0xffffU);
 1228|      0|            }
 1229|      0|            break;
 1230|    273|        case SSH_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (1230:9): [True: 273, False: 2.73k]
  ------------------
 1231|    273|            v = value;
 1232|    273|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1232:17): [True: 0, False: 273]
  |  Branch (1232:30): [True: 0, False: 273]
  ------------------
 1233|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1234|      0|                return -1;
 1235|    273|            } else {
 1236|    273|                rc = ssh_options_set_algo(session,
 1237|    273|                                          SSH_CRYPT_C_S,
 1238|    273|                                          v,
 1239|    273|                                          &wanted_methods[SSH_CRYPT_C_S]);
 1240|    273|                if (rc < 0)
  ------------------
  |  Branch (1240:21): [True: 0, False: 273]
  ------------------
 1241|      0|                    return -1;
 1242|    273|            }
 1243|    273|            break;
 1244|    273|        case SSH_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (1244:9): [True: 273, False: 2.73k]
  ------------------
 1245|    273|            v = value;
 1246|    273|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1246:17): [True: 0, False: 273]
  |  Branch (1246:30): [True: 0, False: 273]
  ------------------
 1247|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1248|      0|                return -1;
 1249|    273|            } else {
 1250|    273|                rc = ssh_options_set_algo(session,
 1251|    273|                                          SSH_CRYPT_S_C,
 1252|    273|                                          v,
 1253|    273|                                          &wanted_methods[SSH_CRYPT_S_C]);
 1254|    273|                if (rc < 0)
  ------------------
  |  Branch (1254:21): [True: 0, False: 273]
  ------------------
 1255|      0|                    return -1;
 1256|    273|            }
 1257|    273|            break;
 1258|    273|        case SSH_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (1258:9): [True: 0, False: 3.00k]
  ------------------
 1259|      0|            v = value;
 1260|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1260:17): [True: 0, False: 0]
  |  Branch (1260:30): [True: 0, False: 0]
  ------------------
 1261|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1262|      0|                return -1;
 1263|      0|            } else {
 1264|      0|                rc = ssh_options_set_algo(session,
 1265|      0|                                          SSH_KEX,
 1266|      0|                                          v,
 1267|      0|                                          &wanted_methods[SSH_KEX]);
 1268|      0|                if (rc < 0)
  ------------------
  |  Branch (1268:21): [True: 0, False: 0]
  ------------------
 1269|      0|                    return -1;
 1270|      0|            }
 1271|      0|            break;
 1272|      0|        case SSH_OPTIONS_HOSTKEYS:
  ------------------
  |  Branch (1272:9): [True: 0, False: 3.00k]
  ------------------
 1273|      0|            v = value;
 1274|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1274:17): [True: 0, False: 0]
  |  Branch (1274:30): [True: 0, False: 0]
  ------------------
 1275|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1276|      0|                return -1;
 1277|      0|            } else {
 1278|      0|                rc = ssh_options_set_algo(session,
 1279|      0|                                          SSH_HOSTKEYS,
 1280|      0|                                          v,
 1281|      0|                                          &wanted_methods[SSH_HOSTKEYS]);
 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_PUBLICKEY_ACCEPTED_TYPES:
  ------------------
  |  Branch (1286:9): [True: 0, False: 3.00k]
  ------------------
 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|            } else {
 1292|      0|                rc = ssh_options_set_algo(session,
 1293|      0|                                          SSH_HOSTKEYS,
 1294|      0|                                          v,
 1295|      0|                                          &session->opts.pubkey_accepted_types);
 1296|      0|                if (rc < 0)
  ------------------
  |  Branch (1296:21): [True: 0, False: 0]
  ------------------
 1297|      0|                    return -1;
 1298|      0|            }
 1299|      0|            break;
 1300|    273|        case SSH_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (1300:9): [True: 273, False: 2.73k]
  ------------------
 1301|    273|            v = value;
 1302|    273|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1302:17): [True: 0, False: 273]
  |  Branch (1302:30): [True: 0, False: 273]
  ------------------
 1303|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1304|      0|                return -1;
 1305|    273|            } else {
 1306|    273|                rc = ssh_options_set_algo(session,
 1307|    273|                                          SSH_MAC_C_S,
 1308|    273|                                          v,
 1309|    273|                                          &wanted_methods[SSH_MAC_C_S]);
 1310|    273|                if (rc < 0)
  ------------------
  |  Branch (1310:21): [True: 0, False: 273]
  ------------------
 1311|      0|                    return -1;
 1312|    273|            }
 1313|    273|            break;
 1314|    273|         case SSH_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (1314:10): [True: 273, False: 2.73k]
  ------------------
 1315|    273|            v = value;
 1316|    273|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1316:17): [True: 0, False: 273]
  |  Branch (1316:30): [True: 0, False: 273]
  ------------------
 1317|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1318|      0|                return -1;
 1319|    273|            } else {
 1320|    273|                rc = ssh_options_set_algo(session,
 1321|    273|                                          SSH_MAC_S_C,
 1322|    273|                                          v,
 1323|    273|                                          &wanted_methods[SSH_MAC_S_C]);
 1324|    273|                if (rc < 0)
  ------------------
  |  Branch (1324:21): [True: 0, False: 273]
  ------------------
 1325|      0|                    return -1;
 1326|    273|            }
 1327|    273|            break;
 1328|    273|        case SSH_OPTIONS_COMPRESSION_C_S:
  ------------------
  |  Branch (1328:9): [True: 0, False: 3.00k]
  ------------------
 1329|      0|            v = value;
 1330|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1330:17): [True: 0, False: 0]
  |  Branch (1330:30): [True: 0, False: 0]
  ------------------
 1331|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1332|      0|                return -1;
 1333|      0|            } else {
 1334|      0|                const char *tmp = v;
 1335|      0|                if (strcasecmp(value, "yes") == 0){
  ------------------
  |  Branch (1335:21): [True: 0, False: 0]
  ------------------
 1336|      0|                    tmp = "zlib@openssh.com,none";
 1337|      0|                } else if (strcasecmp(value, "no") == 0){
  ------------------
  |  Branch (1337:28): [True: 0, False: 0]
  ------------------
 1338|      0|                    tmp = "none,zlib@openssh.com";
 1339|      0|                }
 1340|      0|                rc = ssh_options_set_algo(session,
 1341|      0|                                          SSH_COMP_C_S,
 1342|      0|                                          tmp,
 1343|      0|                                          &wanted_methods[SSH_COMP_C_S]);
 1344|      0|                if (rc < 0)
  ------------------
  |  Branch (1344:21): [True: 0, False: 0]
  ------------------
 1345|      0|                    return -1;
 1346|      0|            }
 1347|      0|            break;
 1348|      0|        case SSH_OPTIONS_COMPRESSION_S_C:
  ------------------
  |  Branch (1348:9): [True: 0, False: 3.00k]
  ------------------
 1349|      0|            v = value;
 1350|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1350:17): [True: 0, False: 0]
  |  Branch (1350:30): [True: 0, False: 0]
  ------------------
 1351|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1352|      0|                return -1;
 1353|      0|            } else {
 1354|      0|                const char *tmp = v;
 1355|      0|                if (strcasecmp(value, "yes") == 0){
  ------------------
  |  Branch (1355:21): [True: 0, False: 0]
  ------------------
 1356|      0|                    tmp = "zlib@openssh.com,none";
 1357|      0|                } else if (strcasecmp(value, "no") == 0){
  ------------------
  |  Branch (1357:28): [True: 0, False: 0]
  ------------------
 1358|      0|                    tmp = "none,zlib@openssh.com";
 1359|      0|                }
 1360|       |
 1361|      0|                rc = ssh_options_set_algo(session,
 1362|      0|                                          SSH_COMP_S_C,
 1363|      0|                                          tmp,
 1364|      0|                                          &wanted_methods[SSH_COMP_S_C]);
 1365|      0|                if (rc < 0)
  ------------------
  |  Branch (1365:21): [True: 0, False: 0]
  ------------------
 1366|      0|                    return -1;
 1367|      0|            }
 1368|      0|            break;
 1369|      0|        case SSH_OPTIONS_COMPRESSION:
  ------------------
  |  Branch (1369:9): [True: 0, False: 3.00k]
  ------------------
 1370|      0|            v = value;
 1371|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1371:17): [True: 0, False: 0]
  |  Branch (1371:30): [True: 0, False: 0]
  ------------------
 1372|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1373|      0|                return -1;
 1374|      0|            }
 1375|      0|            if(ssh_options_set(session,SSH_OPTIONS_COMPRESSION_C_S, v) < 0)
  ------------------
  |  Branch (1375:16): [True: 0, False: 0]
  ------------------
 1376|      0|                return -1;
 1377|      0|            if(ssh_options_set(session,SSH_OPTIONS_COMPRESSION_S_C, v) < 0)
  ------------------
  |  Branch (1377:16): [True: 0, False: 0]
  ------------------
 1378|      0|                return -1;
 1379|      0|            break;
 1380|      0|        case SSH_OPTIONS_COMPRESSION_LEVEL:
  ------------------
  |  Branch (1380:9): [True: 0, False: 3.00k]
  ------------------
 1381|      0|            if (value == NULL) {
  ------------------
  |  Branch (1381:17): [True: 0, False: 0]
  ------------------
 1382|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1383|      0|                return -1;
 1384|      0|            } else {
 1385|      0|                int *x = (int *)value;
 1386|      0|                if (*x < 1 || *x > 9) {
  ------------------
  |  Branch (1386:21): [True: 0, False: 0]
  |  Branch (1386:31): [True: 0, False: 0]
  ------------------
 1387|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1388|      0|                    return -1;
 1389|      0|                }
 1390|      0|                session->opts.compressionlevel = *x & 0xff;
 1391|      0|            }
 1392|      0|            break;
 1393|      0|        case SSH_OPTIONS_STRICTHOSTKEYCHECK:
  ------------------
  |  Branch (1393:9): [True: 0, False: 3.00k]
  ------------------
 1394|      0|            if (value == NULL) {
  ------------------
  |  Branch (1394:17): [True: 0, False: 0]
  ------------------
 1395|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1396|      0|                return -1;
 1397|      0|            } else {
 1398|      0|                int *x = (int *) value;
 1399|      0|                int mode = *x;
 1400|       |
 1401|      0|                switch (mode) {
 1402|      0|                case SSH_STRICT_HOSTKEY_OFF:
  ------------------
  |  Branch (1402:17): [True: 0, False: 0]
  ------------------
 1403|      0|                case SSH_STRICT_HOSTKEY_YES:
  ------------------
  |  Branch (1403:17): [True: 0, False: 0]
  ------------------
 1404|      0|                case SSH_STRICT_HOSTKEY_ASK:
  ------------------
  |  Branch (1404:17): [True: 0, False: 0]
  ------------------
 1405|      0|                case SSH_STRICT_HOSTKEY_ACCEPT_NEW:
  ------------------
  |  Branch (1405:17): [True: 0, False: 0]
  ------------------
 1406|      0|                    session->opts.StrictHostKeyChecking = mode;
 1407|      0|                    break;
 1408|      0|                default:
  ------------------
  |  Branch (1408:17): [True: 0, False: 0]
  ------------------
 1409|       |                    /* Preserve the legacy low-byte "non-zero means yes"
 1410|       |                     * normalization.
 1411|       |                     */
 1412|      0|                    session->opts.StrictHostKeyChecking =
 1413|      0|                        (mode & 0xff) > 0 ? SSH_STRICT_HOSTKEY_YES
  ------------------
  |  Branch (1413:25): [True: 0, False: 0]
  ------------------
 1414|      0|                                          : SSH_STRICT_HOSTKEY_OFF;
 1415|      0|                    break;
 1416|      0|                }
 1417|      0|            }
 1418|      0|            break;
 1419|      0|        case SSH_OPTIONS_PROXYCOMMAND:
  ------------------
  |  Branch (1419:9): [True: 0, False: 3.00k]
  ------------------
 1420|      0|            v = value;
 1421|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1421:17): [True: 0, False: 0]
  |  Branch (1421:30): [True: 0, False: 0]
  ------------------
 1422|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1423|      0|                return -1;
 1424|      0|            } else {
 1425|      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]
  |  |  ------------------
  ------------------
 1426|       |                /* Setting the command to 'none' disables this option. */
 1427|      0|                rc = strcasecmp(v, "none");
 1428|      0|                if (rc != 0) {
  ------------------
  |  Branch (1428:21): [True: 0, False: 0]
  ------------------
 1429|      0|                    q = strdup(v);
 1430|      0|                    if (q == NULL) {
  ------------------
  |  Branch (1430:25): [True: 0, False: 0]
  ------------------
 1431|      0|                        return -1;
 1432|      0|                    }
 1433|      0|                    session->opts.ProxyCommand = q;
 1434|      0|                    session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_PROXYCOMMAND;
  ------------------
  |  |  117|      0|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
 1435|      0|                }
 1436|      0|            }
 1437|      0|            break;
 1438|      0|        case SSH_OPTIONS_PROXYJUMP:
  ------------------
  |  Branch (1438:9): [True: 0, False: 3.00k]
  ------------------
 1439|      0|            v = value;
 1440|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1440:17): [True: 0, False: 0]
  |  Branch (1440:30): [True: 0, False: 0]
  ------------------
 1441|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1442|      0|                return -1;
 1443|      0|            } else {
 1444|      0|                rc = ssh_config_parse_proxy_jump(session, v, true);
 1445|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1445:21): [True: 0, False: 0]
  ------------------
 1446|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1447|      0|                }
 1448|      0|            }
 1449|      0|            break;
 1450|      0|        case SSH_OPTIONS_PROXYJUMP_CB_LIST_APPEND:
  ------------------
  |  Branch (1450:9): [True: 0, False: 3.00k]
  ------------------
 1451|      0|            j = (struct ssh_jump_callbacks_struct *)value;
 1452|      0|            if (j == NULL) {
  ------------------
  |  Branch (1452:17): [True: 0, False: 0]
  ------------------
 1453|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1454|      0|                return -1;
 1455|      0|            } else {
 1456|      0|                rc = ssh_list_prepend(session->opts.proxy_jumps_user_cb, j);
 1457|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1457:21): [True: 0, False: 0]
  ------------------
 1458|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1459|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1460|      0|                }
 1461|      0|            }
 1462|      0|            break;
 1463|      0|        case SSH_OPTIONS_GSSAPI_SERVER_IDENTITY:
  ------------------
  |  Branch (1463:9): [True: 0, False: 3.00k]
  ------------------
 1464|      0|            v = value;
 1465|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1465:17): [True: 0, False: 0]
  |  Branch (1465:30): [True: 0, False: 0]
  ------------------
 1466|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1467|      0|                return -1;
 1468|      0|            } else {
 1469|      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]
  |  |  ------------------
  ------------------
 1470|      0|                session->opts.gss_server_identity = strdup(v);
 1471|      0|                if (session->opts.gss_server_identity == NULL) {
  ------------------
  |  Branch (1471:21): [True: 0, False: 0]
  ------------------
 1472|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1473|      0|                    return -1;
 1474|      0|                }
 1475|      0|            }
 1476|      0|            break;
 1477|      0|        case SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY:
  ------------------
  |  Branch (1477:9): [True: 0, False: 3.00k]
  ------------------
 1478|      0|            v = value;
 1479|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1479:17): [True: 0, False: 0]
  |  Branch (1479:30): [True: 0, False: 0]
  ------------------
 1480|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1481|      0|                return -1;
 1482|      0|            } else {
 1483|      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]
  |  |  ------------------
  ------------------
 1484|      0|                session->opts.gss_client_identity = strdup(v);
 1485|      0|                if (session->opts.gss_client_identity == NULL) {
  ------------------
  |  Branch (1485:21): [True: 0, False: 0]
  ------------------
 1486|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1487|      0|                    return -1;
 1488|      0|                }
 1489|      0|            }
 1490|      0|            break;
 1491|      0|        case SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS:
  ------------------
  |  Branch (1491:9): [True: 0, False: 3.00k]
  ------------------
 1492|      0|            if (value == NULL) {
  ------------------
  |  Branch (1492:17): [True: 0, False: 0]
  ------------------
 1493|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1494|      0|                return -1;
 1495|      0|            } else {
 1496|      0|                int x = *(int *)value;
 1497|       |
 1498|      0|                session->opts.gss_delegate_creds = (x & 0xff);
 1499|      0|            }
 1500|      0|            break;
 1501|       |#ifdef WITH_GSSAPI
 1502|       |        case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE:
 1503|       |            if (value == NULL) {
 1504|       |                ssh_set_error_invalid(session);
 1505|       |                return -1;
 1506|       |            } else {
 1507|       |                bool *x = (bool *)value;
 1508|       |                session->opts.gssapi_key_exchange = *x;
 1509|       |            }
 1510|       |            break;
 1511|       |        case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE_ALGS:
 1512|       |            v = value;
 1513|       |            if (v == NULL || v[0] == '\0') {
 1514|       |                ssh_set_error_invalid(session);
 1515|       |                return -1;
 1516|       |            } else {
 1517|       |                /* Check if algorithms are supported */
 1518|       |                char *ret =
 1519|       |                    ssh_find_all_matching(GSSAPI_KEY_EXCHANGE_SUPPORTED, v);
 1520|       |                if (ret == NULL) {
 1521|       |                    ssh_set_error(session,
 1522|       |                                  SSH_FATAL,
 1523|       |                                  "GSSAPI key exchange algorithms not "
 1524|       |                                  "supported or invalid");
 1525|       |                    return -1;
 1526|       |                }
 1527|       |                SAFE_FREE(session->opts.gssapi_key_exchange_algs);
 1528|       |                session->opts.gssapi_key_exchange_algs = ret;
 1529|       |            }
 1530|       |            break;
 1531|       |#endif
 1532|      0|        case SSH_OPTIONS_PASSWORD_AUTH:
  ------------------
  |  Branch (1532:9): [True: 0, False: 3.00k]
  ------------------
 1533|      0|        case SSH_OPTIONS_PUBKEY_AUTH:
  ------------------
  |  Branch (1533:9): [True: 0, False: 3.00k]
  ------------------
 1534|      0|        case SSH_OPTIONS_KBDINT_AUTH:
  ------------------
  |  Branch (1534:9): [True: 0, False: 3.00k]
  ------------------
 1535|      0|        case SSH_OPTIONS_GSSAPI_AUTH:
  ------------------
  |  Branch (1535:9): [True: 0, False: 3.00k]
  ------------------
 1536|      0|            if (value == NULL) {
  ------------------
  |  Branch (1536:17): [True: 0, False: 0]
  ------------------
 1537|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1538|      0|                return -1;
 1539|      0|            } else {
 1540|      0|                int x = *(int *)value;
 1541|      0|                u = type == SSH_OPTIONS_PASSWORD_AUTH ?
  ------------------
  |  Branch (1541:21): [True: 0, False: 0]
  ------------------
 1542|      0|                    SSH_OPT_FLAG_PASSWORD_AUTH:
  ------------------
  |  |  109|      0|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
 1543|      0|                    type == SSH_OPTIONS_PUBKEY_AUTH ?
  ------------------
  |  Branch (1543:21): [True: 0, False: 0]
  ------------------
 1544|      0|                        SSH_OPT_FLAG_PUBKEY_AUTH:
  ------------------
  |  |  110|      0|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
 1545|      0|                        type == SSH_OPTIONS_KBDINT_AUTH ?
  ------------------
  |  Branch (1545:25): [True: 0, False: 0]
  ------------------
 1546|      0|                            SSH_OPT_FLAG_KBDINT_AUTH:
  ------------------
  |  |  111|      0|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
 1547|      0|                            SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|      0|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
 1548|      0|                if (x != 0) {
  ------------------
  |  Branch (1548:21): [True: 0, False: 0]
  ------------------
 1549|      0|                    session->opts.flags |= u;
 1550|      0|                } else {
 1551|      0|                    session->opts.flags &= ~u;
 1552|      0|                }
 1553|      0|                if (type == SSH_OPTIONS_PUBKEY_AUTH) {
  ------------------
  |  Branch (1553:21): [True: 0, False: 0]
  ------------------
 1554|       |                    /*
 1555|       |                     * Keep the legacy enabled/disabled auth flag semantics in
 1556|       |                     * sync above while also storing the selected
 1557|       |                     * PubkeyAuthentication mode here.
 1558|       |                     */
 1559|      0|                    switch (x) {
 1560|      0|                    case SSH_PUBKEY_AUTH_NO:
  ------------------
  |  Branch (1560:21): [True: 0, False: 0]
  ------------------
 1561|      0|                    case SSH_PUBKEY_AUTH_ALL:
  ------------------
  |  Branch (1561:21): [True: 0, False: 0]
  ------------------
 1562|      0|                    case SSH_PUBKEY_AUTH_UNBOUND:
  ------------------
  |  Branch (1562:21): [True: 0, False: 0]
  ------------------
 1563|      0|                    case SSH_PUBKEY_AUTH_HOST_BOUND:
  ------------------
  |  Branch (1563:21): [True: 0, False: 0]
  ------------------
 1564|      0|                        session->opts.pubkey_auth = x;
 1565|      0|                        break;
 1566|      0|                    default:
  ------------------
  |  Branch (1566:21): [True: 0, False: 0]
  ------------------
 1567|       |                        /* Preserve the legacy non-zero "yes" normalization
 1568|       |                         * here so callers passing -1 still land on
 1569|       |                         * SSH_PUBKEY_AUTH_ALL.
 1570|       |                         */
 1571|      0|                        session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
 1572|      0|                        break;
 1573|      0|                    }
 1574|      0|                }
 1575|      0|            }
 1576|      0|            break;
 1577|      0|        case SSH_OPTIONS_NODELAY:
  ------------------
  |  Branch (1577:9): [True: 0, False: 3.00k]
  ------------------
 1578|      0|            if (value == NULL) {
  ------------------
  |  Branch (1578:17): [True: 0, False: 0]
  ------------------
 1579|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1580|      0|                return -1;
 1581|      0|            } else {
 1582|      0|                int *x = (int *) value;
 1583|      0|                session->opts.nodelay = (*x & 0xff) > 0 ? 1 : 0;
  ------------------
  |  Branch (1583:41): [True: 0, False: 0]
  ------------------
 1584|      0|            }
 1585|      0|            break;
 1586|    273|        case SSH_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (1586:9): [True: 273, False: 2.73k]
  ------------------
 1587|    273|            if (value == NULL) {
  ------------------
  |  Branch (1587:17): [True: 0, False: 273]
  ------------------
 1588|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1589|      0|                return -1;
 1590|    273|            } else {
 1591|    273|                bool *x = (bool *)value;
 1592|    273|                session->opts.config_processed = !(*x);
 1593|    273|            }
 1594|    273|            break;
 1595|    273|        case SSH_OPTIONS_REKEY_DATA:
  ------------------
  |  Branch (1595:9): [True: 0, False: 3.00k]
  ------------------
 1596|      0|            if (value == NULL) {
  ------------------
  |  Branch (1596:17): [True: 0, False: 0]
  ------------------
 1597|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1598|      0|                return -1;
 1599|      0|            } else {
 1600|      0|                uint64_t *x = (uint64_t *)value;
 1601|      0|                session->opts.rekey_data = *x;
 1602|      0|            }
 1603|      0|            break;
 1604|      0|        case SSH_OPTIONS_REKEY_TIME:
  ------------------
  |  Branch (1604:9): [True: 0, False: 3.00k]
  ------------------
 1605|      0|            if (value == NULL) {
  ------------------
  |  Branch (1605:17): [True: 0, False: 0]
  ------------------
 1606|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1607|      0|                return -1;
 1608|      0|            } else {
 1609|      0|                uint32_t *x = (uint32_t *)value;
 1610|      0|                if ((*x * 1000) < *x) {
  ------------------
  |  Branch (1610:21): [True: 0, False: 0]
  ------------------
 1611|      0|                    ssh_set_error(session, SSH_REQUEST_DENIED,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1612|      0|                                  "The provided value (%" PRIu32 ") for rekey"
 1613|      0|                                  " time is too large", *x);
 1614|      0|                    return -1;
 1615|      0|                }
 1616|      0|                session->opts.rekey_time = (*x) * 1000;
 1617|      0|            }
 1618|      0|            break;
 1619|      0|        case SSH_OPTIONS_RSA_MIN_SIZE:
  ------------------
  |  Branch (1619:9): [True: 0, False: 3.00k]
  ------------------
 1620|      0|            if (value == NULL) {
  ------------------
  |  Branch (1620:17): [True: 0, False: 0]
  ------------------
 1621|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1622|      0|                return -1;
 1623|      0|            } else {
 1624|      0|                int *x = (int *)value;
 1625|       |
 1626|      0|                if (*x < 0) {
  ------------------
  |  Branch (1626:21): [True: 0, False: 0]
  ------------------
 1627|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1628|      0|                    return -1;
 1629|      0|                }
 1630|       |
 1631|       |                /* (*x == 0) is allowed as it is used to revert to default */
 1632|       |
 1633|      0|                if (*x > 0 && *x < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|      0|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (1633:21): [True: 0, False: 0]
  |  Branch (1633:31): [True: 0, False: 0]
  ------------------
 1634|      0|                    ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1635|      0|                                  SSH_REQUEST_DENIED,
 1636|      0|                                  "The provided value (%d) for minimal RSA key "
 1637|      0|                                  "size is too small. Use at least %d bits.",
 1638|      0|                                  *x,
 1639|      0|                                  RSA_MIN_KEY_SIZE);
 1640|      0|                    return -1;
 1641|      0|                }
 1642|      0|                session->opts.rsa_min_size = *x;
 1643|      0|            }
 1644|      0|            break;
 1645|      0|        case SSH_OPTIONS_IDENTITY_AGENT:
  ------------------
  |  Branch (1645:9): [True: 0, False: 3.00k]
  ------------------
 1646|      0|            v = value;
 1647|      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]
  |  |  ------------------
  ------------------
 1648|      0|            if (v == NULL) {
  ------------------
  |  Branch (1648:17): [True: 0, False: 0]
  ------------------
 1649|       |                /* The default value will be set by the ssh_options_apply() */
 1650|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1650:24): [True: 0, False: 0]
  ------------------
 1651|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1652|      0|                return -1;
 1653|      0|            } else {
 1654|      0|                session->opts.agent_socket = ssh_path_expand_tilde(v);
 1655|      0|                if (session->opts.agent_socket == NULL) {
  ------------------
  |  Branch (1655:21): [True: 0, False: 0]
  ------------------
 1656|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1657|      0|                    return -1;
 1658|      0|                }
 1659|      0|            }
 1660|      0|            break;
 1661|      0|        case SSH_OPTIONS_IDENTITIES_ONLY:
  ------------------
  |  Branch (1661:9): [True: 0, False: 3.00k]
  ------------------
 1662|      0|            if (value == NULL) {
  ------------------
  |  Branch (1662:17): [True: 0, False: 0]
  ------------------
 1663|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1664|      0|                return -1;
 1665|      0|            } else {
 1666|      0|                bool *x = (bool *)value;
 1667|      0|                session->opts.identities_only = *x;
 1668|      0|            }
 1669|      0|            break;
 1670|      0|        case SSH_OPTIONS_CONTROL_MASTER:
  ------------------
  |  Branch (1670:9): [True: 0, False: 3.00k]
  ------------------
 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 < SSH_CONTROL_MASTER_NO || *x > SSH_CONTROL_MASTER_AUTOASK) {
  ------------------
  |  Branch (1676:21): [True: 0, False: 0]
  |  Branch (1676:51): [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.control_master = *x;
 1681|      0|            }
 1682|      0|            break;
 1683|      0|        case SSH_OPTIONS_CONTROL_PATH:
  ------------------
  |  Branch (1683:9): [True: 0, False: 3.00k]
  ------------------
 1684|      0|            v = value;
 1685|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1685:17): [True: 0, False: 0]
  |  Branch (1685:30): [True: 0, False: 0]
  ------------------
 1686|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1687|      0|                return -1;
 1688|      0|            } else {
 1689|      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]
  |  |  ------------------
  ------------------
 1690|      0|                rc = strcasecmp(v, "none");
 1691|      0|                if (rc != 0) {
  ------------------
  |  Branch (1691:21): [True: 0, False: 0]
  ------------------
 1692|      0|                    session->opts.control_path = ssh_path_expand_tilde(v);
 1693|      0|                    if (session->opts.control_path == NULL) {
  ------------------
  |  Branch (1693:25): [True: 0, False: 0]
  ------------------
 1694|      0|                        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1695|      0|                        return -1;
 1696|      0|                    }
 1697|      0|                    session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_CONTROL_PATH;
  ------------------
  |  |  119|      0|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
 1698|      0|                }
 1699|      0|            }
 1700|      0|            break;
 1701|      0|        case SSH_OPTIONS_PKI_CONTEXT:
  ------------------
  |  Branch (1701:9): [True: 0, False: 3.00k]
  ------------------
 1702|      0|            if (value == NULL) {
  ------------------
  |  Branch (1702:17): [True: 0, False: 0]
  ------------------
 1703|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1704|      0|                return -1;
 1705|      0|            }
 1706|       |
 1707|      0|            SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1050|      0|    do {                         \
  |  | 1051|      0|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1051:13): [True: 0, False: 0]
  |  |  ------------------
  |  | 1052|      0|            ssh_pki_ctx_free(x); \
  |  | 1053|      0|            x = NULL;            \
  |  | 1054|      0|        }                        \
  |  | 1055|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1055:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1708|       |
 1709|      0|            session->pki_context = ssh_pki_ctx_dup((const ssh_pki_ctx)value);
 1710|      0|            if (session->pki_context == NULL) {
  ------------------
  |  Branch (1710:17): [True: 0, False: 0]
  ------------------
 1711|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1712|      0|                return -1;
 1713|      0|            }
 1714|      0|            break;
 1715|      0|        case SSH_OPTIONS_ADDRESS_FAMILY:
  ------------------
  |  Branch (1715:9): [True: 0, False: 3.00k]
  ------------------
 1716|      0|            if (value == NULL) {
  ------------------
  |  Branch (1716:17): [True: 0, False: 0]
  ------------------
 1717|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1718|      0|                return -1;
 1719|      0|            } else {
 1720|      0|                int *x = (int *)value;
 1721|      0|                if (*x < SSH_ADDRESS_FAMILY_ANY ||
  ------------------
  |  Branch (1721:21): [True: 0, False: 0]
  ------------------
 1722|      0|                    *x > SSH_ADDRESS_FAMILY_INET6) {
  ------------------
  |  Branch (1722:21): [True: 0, False: 0]
  ------------------
 1723|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1724|      0|                    return -1;
 1725|      0|                }
 1726|      0|                session->opts.address_family = *x;
 1727|      0|            }
 1728|      0|            break;
 1729|      0|        case SSH_OPTIONS_BATCH_MODE:
  ------------------
  |  Branch (1729:9): [True: 0, False: 3.00k]
  ------------------
 1730|      0|            if (value == NULL) {
  ------------------
  |  Branch (1730:17): [True: 0, False: 0]
  ------------------
 1731|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1732|      0|                return -1;
 1733|      0|            } else {
 1734|      0|                bool *x = (bool *)value;
 1735|      0|                session->opts.batch_mode = *x;
 1736|      0|            }
 1737|      0|            break;
 1738|      0|        case SSH_OPTIONS_ESCAPE_CHAR:
  ------------------
  |  Branch (1738:9): [True: 0, False: 3.00k]
  ------------------
 1739|      0|            if (value == NULL) {
  ------------------
  |  Branch (1739:17): [True: 0, False: 0]
  ------------------
 1740|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1741|      0|                return -1;
 1742|      0|            } else {
 1743|      0|                int *x = (int *)value;
 1744|      0|                if (*x == 0 || *x < -1 || *x > 255) {
  ------------------
  |  Branch (1744:21): [True: 0, False: 0]
  |  Branch (1744:32): [True: 0, False: 0]
  |  Branch (1744:43): [True: 0, False: 0]
  ------------------
 1745|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1746|      0|                    return -1;
 1747|      0|                }
 1748|      0|                session->opts.escape_char = *x;
 1749|      0|            }
 1750|      0|            break;
 1751|      0|        case SSH_OPTIONS_LOCAL_FORWARD:
  ------------------
  |  Branch (1751:9): [True: 0, False: 3.00k]
  ------------------
 1752|      0|            v = value;
 1753|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1753:17): [True: 0, False: 0]
  |  Branch (1753:30): [True: 0, False: 0]
  ------------------
 1754|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1755|      0|                return -1;
 1756|      0|            }
 1757|      0|            q = strdup(v);
 1758|      0|            if (q == NULL) {
  ------------------
  |  Branch (1758:17): [True: 0, False: 0]
  ------------------
 1759|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1760|      0|                return -1;
 1761|      0|            }
 1762|      0|            rc = ssh_list_append(session->opts.local_forward, q);
 1763|      0|            if (rc < 0) {
  ------------------
  |  Branch (1763:17): [True: 0, False: 0]
  ------------------
 1764|      0|                free(q);
 1765|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1766|      0|                return -1;
 1767|      0|            }
 1768|      0|            break;
 1769|      0|        case SSH_OPTIONS_PREFERRED_AUTHENTICATIONS:
  ------------------
  |  Branch (1769:9): [True: 0, False: 3.00k]
  ------------------
 1770|      0|            v = value;
 1771|      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]
  |  |  ------------------
  ------------------
 1772|      0|            if (v != NULL) {
  ------------------
  |  Branch (1772:17): [True: 0, False: 0]
  ------------------
 1773|      0|                if (v[0] == '\0') {
  ------------------
  |  Branch (1773:21): [True: 0, False: 0]
  ------------------
 1774|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1775|      0|                    return -1;
 1776|      0|                }
 1777|      0|                session->opts.preferred_authentications = strdup(v);
 1778|      0|                if (session->opts.preferred_authentications == NULL) {
  ------------------
  |  Branch (1778:21): [True: 0, False: 0]
  ------------------
 1779|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1780|      0|                    return -1;
 1781|      0|                }
 1782|      0|            }
 1783|      0|            break;
 1784|      0|        case SSH_OPTIONS_NUMBER_OF_PASSWORD_PROMPTS:
  ------------------
  |  Branch (1784:9): [True: 0, False: 3.00k]
  ------------------
 1785|      0|            if (value == NULL) {
  ------------------
  |  Branch (1785:17): [True: 0, False: 0]
  ------------------
 1786|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1787|      0|                return -1;
 1788|      0|            } else {
 1789|      0|                int *x = (int *)value;
 1790|      0|                if (*x <= 0) {
  ------------------
  |  Branch (1790:21): [True: 0, False: 0]
  ------------------
 1791|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1792|      0|                    return -1;
 1793|      0|                }
 1794|      0|                session->opts.number_of_password_prompts = *x;
 1795|      0|            }
 1796|      0|            break;
 1797|      0|        case SSH_OPTIONS_REQUEST_TTY:
  ------------------
  |  Branch (1797:9): [True: 0, False: 3.00k]
  ------------------
 1798|      0|            if (value == NULL) {
  ------------------
  |  Branch (1798:17): [True: 0, False: 0]
  ------------------
 1799|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1800|      0|                return -1;
 1801|      0|            } else {
 1802|      0|                int *x = (int *)value;
 1803|      0|                if (*x < SSH_REQUEST_TTY_NO || *x > SSH_REQUEST_TTY_FORCE) {
  ------------------
  |  Branch (1803:21): [True: 0, False: 0]
  |  Branch (1803:48): [True: 0, False: 0]
  ------------------
 1804|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1805|      0|                    return -1;
 1806|      0|                }
 1807|      0|                session->opts.request_tty = *x;
 1808|      0|            }
 1809|      0|            break;
 1810|      0|        case SSH_OPTIONS_SEND_ENV:
  ------------------
  |  Branch (1810:9): [True: 0, False: 3.00k]
  ------------------
 1811|      0|            v = value;
 1812|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1812:17): [True: 0, False: 0]
  |  Branch (1812:30): [True: 0, False: 0]
  ------------------
 1813|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1814|      0|                return -1;
 1815|      0|            }
 1816|       |            /* A leading '-' removes the pattern from the list */
 1817|      0|            if (v[0] == '-') {
  ------------------
  |  Branch (1817:17): [True: 0, False: 0]
  ------------------
 1818|      0|                const char *pattern = NULL;
 1819|      0|                const char *env_value = NULL;
 1820|      0|                struct ssh_iterator *it = NULL;
 1821|      0|                struct ssh_iterator *next = NULL;
 1822|      0|                int cmp = 0;
 1823|       |
 1824|      0|                pattern = v + 1;
 1825|      0|                if (pattern[0] == '\0') {
  ------------------
  |  Branch (1825:21): [True: 0, False: 0]
  ------------------
 1826|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1827|      0|                    return -1;
 1828|      0|                }
 1829|      0|                it = ssh_list_get_iterator(session->opts.send_env);
 1830|      0|                while (it != NULL) {
  ------------------
  |  Branch (1830:24): [True: 0, False: 0]
  ------------------
 1831|      0|                    env_value = ssh_iterator_value(const char *, it);
  ------------------
  |  |  114|      0|  ((type)((iterator)->data))
  ------------------
 1832|      0|                    cmp = strcmp(env_value, pattern);
 1833|      0|                    next = it->next;
 1834|      0|                    if (cmp == 0) {
  ------------------
  |  Branch (1834:25): [True: 0, False: 0]
  ------------------
 1835|      0|                        free((void *)env_value);
 1836|      0|                        ssh_list_remove(session->opts.send_env, it);
 1837|      0|                    }
 1838|      0|                    it = next;
 1839|      0|                }
 1840|      0|                rc = SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1841|      0|            } else {
 1842|      0|                q = strdup(v);
 1843|      0|                if (q == NULL) {
  ------------------
  |  Branch (1843:21): [True: 0, False: 0]
  ------------------
 1844|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1845|      0|                    return -1;
 1846|      0|                }
 1847|      0|                rc = ssh_list_append(session->opts.send_env, q);
 1848|      0|                if (rc < 0) {
  ------------------
  |  Branch (1848:21): [True: 0, False: 0]
  ------------------
 1849|      0|                    free(q);
 1850|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1851|      0|                    return -1;
 1852|      0|                }
 1853|      0|            }
 1854|      0|            break;
 1855|      0|        default:
  ------------------
  |  Branch (1855:9): [True: 0, False: 3.00k]
  ------------------
 1856|      0|            ssh_set_error(session, SSH_REQUEST_DENIED, "Unknown ssh option %d", type);
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1857|      0|            return -1;
 1858|      0|            break;
 1859|  3.00k|    }
 1860|       |
 1861|  3.00k|    return 0;
 1862|  3.00k|}
ssh_options_apply:
 2620|    273|{
 2621|    273|    char *tmp = NULL;
 2622|    273|    int rc;
 2623|       |
 2624|    273|    if (session->opts.host != NULL) {
  ------------------
  |  Branch (2624:9): [True: 273, False: 0]
  ------------------
 2625|    273|        char *normalized_host = NULL;
 2626|    273|        rc = ssh_normalize_loose_ip(session->opts.host, &normalized_host);
 2627|    273|        if (rc == -1) {
  ------------------
  |  Branch (2627:13): [True: 0, False: 273]
  ------------------
 2628|       |            /* Error (e.g. NULL input or OOM) — leave host as it is */
 2629|    273|        } else if (rc == 0) {
  ------------------
  |  Branch (2629:20): [True: 0, False: 273]
  ------------------
 2630|       |            /* Was a loose IP — use the normalized dotted-quad form */
 2631|      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]
  |  |  ------------------
  ------------------
 2632|      0|            session->opts.host = normalized_host;
 2633|    273|        } else {
 2634|       |            /* rc == 1: not a loose IP — lowercase if it's not a strict IP */
 2635|    273|            bool is_ip = ssh_is_ipaddr(session->opts.host);
 2636|    273|            if (!is_ip) {
  ------------------
  |  Branch (2636:17): [True: 273, False: 0]
  ------------------
 2637|    273|                char *lower = ssh_lowercase(session->opts.host);
 2638|    273|                if (lower != NULL) {
  ------------------
  |  Branch (2638:21): [True: 273, False: 0]
  ------------------
 2639|    273|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
 2640|    273|                    session->opts.host = lower;
 2641|    273|                }
 2642|    273|            }
 2643|    273|        }
 2644|    273|    }
 2645|       |
 2646|    273|    if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (2646:9): [True: 273, False: 0]
  ------------------
 2647|    273|        rc = ssh_options_set(session, SSH_OPTIONS_SSH_DIR, NULL);
 2648|    273|        if (rc < 0) {
  ------------------
  |  Branch (2648:13): [True: 0, False: 273]
  ------------------
 2649|      0|            return -1;
 2650|      0|        }
 2651|    273|    }
 2652|       |
 2653|    273|    if (session->opts.username == NULL) {
  ------------------
  |  Branch (2653:9): [True: 0, False: 273]
  ------------------
 2654|      0|        rc = ssh_options_set(session, SSH_OPTIONS_USER, NULL);
 2655|      0|        if (rc < 0) {
  ------------------
  |  Branch (2655:13): [True: 0, False: 0]
  ------------------
 2656|      0|            return -1;
 2657|      0|        }
 2658|      0|    }
 2659|       |
 2660|    273|    if (session->opts.config_hostname != NULL) {
  ------------------
  |  Branch (2660:9): [True: 0, False: 273]
  ------------------
 2661|      0|        char *saved_host = NULL;
 2662|       |
 2663|      0|        tmp = ssh_path_expand_hostname(session, session->opts.config_hostname);
 2664|      0|        if (tmp == NULL) {
  ------------------
  |  Branch (2664:13): [True: 0, False: 0]
  ------------------
 2665|      0|            return -1;
 2666|      0|        }
 2667|      0|        if (session->opts.host != NULL) {
  ------------------
  |  Branch (2667:13): [True: 0, False: 0]
  ------------------
 2668|      0|            saved_host = strdup(session->opts.host);
 2669|      0|            if (saved_host == NULL) {
  ------------------
  |  Branch (2669:17): [True: 0, False: 0]
  ------------------
 2670|      0|                free(tmp);
 2671|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2672|      0|                return -1;
 2673|      0|            }
 2674|      0|        }
 2675|      0|        session->opts.config_hostname_only = true;
 2676|      0|        rc = ssh_options_set(session, SSH_OPTIONS_HOST, tmp);
 2677|      0|        session->opts.config_hostname_only = false;
 2678|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2678:13): [True: 0, False: 0]
  ------------------
 2679|       |            /* If HostName expansion leaves a literal '%', keep the current
 2680|       |             * host instead of treating the deferred HostName as fatal.
 2681|       |             */
 2682|      0|            if (strchr(tmp, '%') == NULL) {
  ------------------
  |  Branch (2682:17): [True: 0, False: 0]
  ------------------
 2683|      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]
  |  |  ------------------
  ------------------
 2684|      0|                free(tmp);
 2685|      0|                return -1;
 2686|      0|            }
 2687|      0|            SSH_LOG(SSH_LOG_WARN,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2688|      0|                    "HostName %s contains unknown expansion tokens and could "
 2689|      0|                    "not be applied; falling back to current host",
 2690|      0|                    tmp);
 2691|      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]
  |  |  ------------------
  ------------------
 2692|      0|            session->opts.host = saved_host;
 2693|      0|            saved_host = NULL;
 2694|      0|        }
 2695|      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]
  |  |  ------------------
  ------------------
 2696|      0|        free(tmp);
 2697|      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]
  |  |  ------------------
  ------------------
 2698|      0|    }
 2699|       |
 2700|    273|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_KNOWNHOSTS) == 0) {
  ------------------
  |  |  115|    273|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
  |  Branch (2700:9): [True: 273, False: 0]
  ------------------
 2701|    273|        if (session->opts.knownhosts == NULL) {
  ------------------
  |  Branch (2701:13): [True: 273, False: 0]
  ------------------
 2702|    273|            tmp = ssh_path_expand_escape(session, "%d/.ssh/known_hosts");
 2703|    273|        } else {
 2704|      0|            tmp = ssh_path_expand_escape(session, session->opts.knownhosts);
 2705|      0|        }
 2706|    273|        if (tmp == NULL) {
  ------------------
  |  Branch (2706:13): [True: 0, False: 273]
  ------------------
 2707|      0|            return -1;
 2708|      0|        }
 2709|    273|        free(session->opts.knownhosts);
 2710|    273|        session->opts.knownhosts = tmp;
 2711|    273|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_KNOWNHOSTS;
  ------------------
  |  |  115|    273|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
 2712|    273|    }
 2713|       |
 2714|    273|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS) == 0) {
  ------------------
  |  |  116|    273|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
  |  Branch (2714:9): [True: 273, False: 0]
  ------------------
 2715|    273|        if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (2715:13): [True: 273, False: 0]
  ------------------
 2716|    273|            tmp = strdup(GLOBAL_CONF_DIR "/ssh_known_hosts");
  ------------------
  |  |   13|    273|#define GLOBAL_CONF_DIR "/etc/ssh"
  ------------------
 2717|    273|        } else {
 2718|      0|            tmp = ssh_path_expand_escape(session,
 2719|      0|                                         session->opts.global_knownhosts);
 2720|      0|        }
 2721|    273|        if (tmp == NULL) {
  ------------------
  |  Branch (2721:13): [True: 0, False: 273]
  ------------------
 2722|      0|            return -1;
 2723|      0|        }
 2724|    273|        free(session->opts.global_knownhosts);
 2725|    273|        session->opts.global_knownhosts = tmp;
 2726|    273|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS;
  ------------------
  |  |  116|    273|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
 2727|    273|    }
 2728|       |
 2729|       |
 2730|    273|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_PROXYCOMMAND) == 0) {
  ------------------
  |  |  117|    273|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
  |  Branch (2730:9): [True: 273, False: 0]
  ------------------
 2731|    273|        if (session->opts.ProxyCommand != NULL) {
  ------------------
  |  Branch (2731:13): [True: 0, False: 273]
  ------------------
 2732|      0|            char *p = NULL;
 2733|      0|            size_t plen = strlen(session->opts.ProxyCommand) +
 2734|      0|                          5 /* strlen("exec ") */;
 2735|       |
 2736|      0|            if (strncmp(session->opts.ProxyCommand, "exec ", 5) != 0) {
  ------------------
  |  Branch (2736:17): [True: 0, False: 0]
  ------------------
 2737|      0|                p = malloc(plen + 1 /* \0 */);
 2738|      0|                if (p == NULL) {
  ------------------
  |  Branch (2738:21): [True: 0, False: 0]
  ------------------
 2739|      0|                    return -1;
 2740|      0|                }
 2741|       |
 2742|      0|                rc = snprintf(p, plen + 1, "exec %s", session->opts.ProxyCommand);
 2743|      0|                if ((size_t)rc != plen) {
  ------------------
  |  Branch (2743:21): [True: 0, False: 0]
  ------------------
 2744|      0|                    free(p);
 2745|      0|                    return -1;
 2746|      0|                }
 2747|      0|                tmp = ssh_path_expand_escape(session, p);
 2748|      0|                free(p);
 2749|      0|            } else {
 2750|      0|                tmp = ssh_path_expand_escape(session,
 2751|      0|                                             session->opts.ProxyCommand);
 2752|      0|            }
 2753|       |
 2754|      0|            if (tmp == NULL) {
  ------------------
  |  Branch (2754:17): [True: 0, False: 0]
  ------------------
 2755|      0|                return -1;
 2756|      0|            }
 2757|      0|            free(session->opts.ProxyCommand);
 2758|      0|            session->opts.ProxyCommand = tmp;
 2759|      0|            session->opts.exp_flags |= SSH_OPT_EXP_FLAG_PROXYCOMMAND;
  ------------------
  |  |  117|      0|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
 2760|      0|        }
 2761|    273|    }
 2762|       |
 2763|    273|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_CONTROL_PATH) == 0) {
  ------------------
  |  |  119|    273|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
  |  Branch (2763:9): [True: 273, False: 0]
  ------------------
 2764|    273|        if (session->opts.control_path != NULL) {
  ------------------
  |  Branch (2764:13): [True: 0, False: 273]
  ------------------
 2765|      0|            tmp = ssh_path_expand_escape(session, session->opts.control_path);
 2766|      0|            if (tmp == NULL) {
  ------------------
  |  Branch (2766:17): [True: 0, False: 0]
  ------------------
 2767|      0|                return -1;
 2768|      0|            }
 2769|      0|            free(session->opts.control_path);
 2770|      0|            session->opts.control_path = tmp;
 2771|      0|            session->opts.exp_flags |= SSH_OPT_EXP_FLAG_CONTROL_PATH;
  ------------------
  |  |  119|      0|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
 2772|      0|        }
 2773|    273|    }
 2774|       |
 2775|    273|    for (tmp = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  122|    273|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2776|  1.09k|         tmp != NULL;
  ------------------
  |  Branch (2776:10): [True: 819, False: 273]
  ------------------
 2777|    819|         tmp = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  122|    819|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2778|    819|        char *id = tmp;
 2779|    819|        if (strncmp(id, "pkcs11:", 6) != 0) {
  ------------------
  |  Branch (2779:13): [True: 819, False: 0]
  ------------------
 2780|       |            /* PKCS#11 URIs are using percent-encoding so we can not mix
 2781|       |             * it with ssh expansion of ssh escape characters.
 2782|       |             */
 2783|    819|            tmp = ssh_path_expand_escape(session, id);
 2784|    819|            free(id);
 2785|    819|            if (tmp == NULL) {
  ------------------
  |  Branch (2785:17): [True: 0, False: 819]
  ------------------
 2786|      0|                return -1;
 2787|      0|            }
 2788|    819|        }
 2789|       |
 2790|       |        /* use append to keep the order at first call and use prepend
 2791|       |         * to put anything that comes on the nth calls to the beginning */
 2792|    819|        if (session->opts.exp_flags & SSH_OPT_EXP_FLAG_IDENTITY) {
  ------------------
  |  |  118|    819|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
  |  Branch (2792:13): [True: 0, False: 819]
  ------------------
 2793|      0|            rc = ssh_list_prepend(session->opts.identity, tmp);
 2794|    819|        } else {
 2795|    819|            rc = ssh_list_append(session->opts.identity, tmp);
 2796|    819|        }
 2797|    819|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    819|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2797:13): [True: 0, False: 819]
  ------------------
 2798|      0|            free(tmp);
 2799|      0|            return -1;
 2800|      0|        }
 2801|    819|    }
 2802|    273|    session->opts.exp_flags |= SSH_OPT_EXP_FLAG_IDENTITY;
  ------------------
  |  |  118|    273|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
 2803|       |
 2804|    273|    for (tmp = ssh_list_pop_head(char *, session->opts.certificate_non_exp);
  ------------------
  |  |  122|    273|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2805|    273|         tmp != NULL;
  ------------------
  |  Branch (2805:10): [True: 0, False: 273]
  ------------------
 2806|    273|         tmp = ssh_list_pop_head(char *, session->opts.certificate_non_exp)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2807|      0|        char *id = tmp;
 2808|       |
 2809|      0|        tmp = ssh_path_expand_escape(session, id);
 2810|      0|        free(id);
 2811|      0|        if (tmp == NULL) {
  ------------------
  |  Branch (2811:13): [True: 0, False: 0]
  ------------------
 2812|      0|            return -1;
 2813|      0|        }
 2814|       |
 2815|      0|        rc = ssh_list_append(session->opts.certificate, tmp);
 2816|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2816:13): [True: 0, False: 0]
  ------------------
 2817|      0|            free(tmp);
 2818|      0|            return -1;
 2819|      0|        }
 2820|      0|    }
 2821|       |
 2822|       |#ifdef WITH_GSSAPI
 2823|       |    if (session->opts.gssapi_key_exchange) {
 2824|       |        rc = ssh_gssapi_check_client_config(session);
 2825|       |        if (rc != SSH_OK) {
 2826|       |            SSH_LOG(SSH_LOG_WARN, "Disabled GSSAPI key exchange");
 2827|       |            session->opts.gssapi_key_exchange = false;
 2828|       |        }
 2829|       |    }
 2830|       |#endif
 2831|       |
 2832|    273|    return 0;
 2833|    273|}
ssh_bind_options_set:
 3059|  1.63k|{
 3060|  1.63k|    bool allowed;
 3061|  1.63k|    char *p = NULL, *q = NULL;
 3062|  1.63k|    const char *v = NULL;
 3063|  1.63k|    int i, rc;
 3064|  1.63k|    char **wanted_methods = sshbind->wanted_methods;
 3065|       |
 3066|  1.63k|    if (sshbind == NULL) {
  ------------------
  |  Branch (3066:9): [True: 0, False: 1.63k]
  ------------------
 3067|      0|        return -1;
 3068|      0|    }
 3069|       |
 3070|  1.63k|    switch (type) {
 3071|      0|    case SSH_BIND_OPTIONS_RSAKEY:
  ------------------
  |  Branch (3071:5): [True: 0, False: 1.63k]
  ------------------
 3072|      0|    case SSH_BIND_OPTIONS_ECDSAKEY:
  ------------------
  |  Branch (3072:5): [True: 0, False: 1.63k]
  ------------------
 3073|       |        /* deprecated */
 3074|    273|    case SSH_BIND_OPTIONS_HOSTKEY:
  ------------------
  |  Branch (3074:5): [True: 273, False: 1.36k]
  ------------------
 3075|    273|    case SSH_BIND_OPTIONS_IMPORT_KEY:
  ------------------
  |  Branch (3075:5): [True: 0, False: 1.63k]
  ------------------
 3076|    273|    case SSH_BIND_OPTIONS_IMPORT_KEY_STR:
  ------------------
  |  Branch (3076:5): [True: 0, False: 1.63k]
  ------------------
 3077|    273|        if (value == NULL) {
  ------------------
  |  Branch (3077:13): [True: 0, False: 273]
  ------------------
 3078|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3079|      0|            return -1;
 3080|    273|        } else {
 3081|    273|            int key_type;
 3082|    273|            ssh_key *bind_key_loc = NULL;
 3083|    273|            ssh_key key = NULL;
 3084|    273|            char **bind_key_path_loc = NULL;
 3085|       |
 3086|    273|            if (type == SSH_BIND_OPTIONS_IMPORT_KEY_STR) {
  ------------------
  |  Branch (3086:17): [True: 0, False: 273]
  ------------------
 3087|      0|                const char *key_str = (const char *)value;
 3088|      0|                rc = ssh_pki_import_privkey_base64(key_str,
 3089|      0|                                                   NULL,
 3090|      0|                                                   NULL,
 3091|      0|                                                   NULL,
 3092|      0|                                                   &key);
 3093|      0|                if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (3093:21): [True: 0, False: 0]
  ------------------
 3094|      0|                    ssh_set_error(sshbind,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3095|      0|                                  SSH_FATAL,
 3096|      0|                                  "Failed to import key from buffer");
 3097|      0|                    return -1;
 3098|      0|                }
 3099|    273|            } else if (type == SSH_BIND_OPTIONS_IMPORT_KEY) {
  ------------------
  |  Branch (3099:24): [True: 0, False: 273]
  ------------------
 3100|      0|                key = (ssh_key)value;
 3101|    273|            } else {
 3102|    273|                rc = ssh_pki_import_privkey_file(value, NULL, NULL, NULL, &key);
 3103|    273|                if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3103:21): [True: 0, False: 273]
  ------------------
 3104|      0|                    return -1;
 3105|      0|                }
 3106|    273|            }
 3107|    273|            allowed = ssh_bind_key_size_allowed(sshbind, key);
 3108|    273|            if (!allowed) {
  ------------------
  |  Branch (3108:17): [True: 0, False: 273]
  ------------------
 3109|      0|                ssh_set_error(sshbind,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3110|      0|                              SSH_FATAL,
 3111|      0|                              "The host key size %d is too small.",
 3112|      0|                              ssh_key_size(key));
 3113|      0|                if (type != SSH_BIND_OPTIONS_IMPORT_KEY) {
  ------------------
  |  Branch (3113:21): [True: 0, False: 0]
  ------------------
 3114|      0|                    SSH_KEY_FREE(key);
  ------------------
  |  |  774|      0|    do { if ((x) != NULL) { ssh_key_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (774:14): [True: 0, False: 0]
  |  |  |  Branch (774:66): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3115|      0|                }
 3116|      0|                return -1;
 3117|      0|            }
 3118|    273|            key_type = ssh_key_type(key);
 3119|    273|            switch (key_type) {
 3120|      0|            case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (3120:13): [True: 0, False: 273]
  ------------------
 3121|      0|            case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (3121:13): [True: 0, False: 273]
  ------------------
 3122|      0|            case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (3122:13): [True: 0, False: 273]
  ------------------
 3123|      0|#ifdef HAVE_ECC
 3124|      0|                bind_key_loc = &sshbind->ecdsa;
 3125|      0|                bind_key_path_loc = &sshbind->ecdsakey;
 3126|       |#else
 3127|       |                ssh_set_error(sshbind,
 3128|       |                              SSH_FATAL,
 3129|       |                              "ECDSA key used and libssh compiled "
 3130|       |                              "without ECDSA support");
 3131|       |#endif
 3132|      0|                break;
 3133|      0|            case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (3133:13): [True: 0, False: 273]
  ------------------
 3134|      0|                bind_key_loc = &sshbind->rsa;
 3135|      0|                bind_key_path_loc = &sshbind->rsakey;
 3136|      0|                break;
 3137|    273|            case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (3137:13): [True: 273, False: 0]
  ------------------
 3138|    273|                bind_key_loc = &sshbind->ed25519;
 3139|    273|                bind_key_path_loc = &sshbind->ed25519key;
 3140|    273|                break;
 3141|      0|            default:
  ------------------
  |  Branch (3141:13): [True: 0, False: 273]
  ------------------
 3142|      0|                ssh_set_error(sshbind,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3143|    273|                              SSH_FATAL,
 3144|    273|                              "Unsupported key type %d",
 3145|    273|                              key_type);
 3146|    273|            }
 3147|    273|            if (type == SSH_BIND_OPTIONS_RSAKEY ||
  ------------------
  |  Branch (3147:17): [True: 0, False: 273]
  ------------------
 3148|    273|                type == SSH_BIND_OPTIONS_ECDSAKEY ||
  ------------------
  |  Branch (3148:17): [True: 0, False: 273]
  ------------------
 3149|    273|                type == SSH_BIND_OPTIONS_HOSTKEY) {
  ------------------
  |  Branch (3149:17): [True: 273, False: 0]
  ------------------
 3150|    273|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (3150:21): [True: 0, False: 273]
  ------------------
 3151|      0|                    ssh_key_free(key);
 3152|      0|                    return -1;
 3153|      0|                }
 3154|       |                /* Set the location of the key on disk even though we don't
 3155|       |                   need it in case some other function wants it */
 3156|    273|                rc = ssh_bind_set_key(sshbind, bind_key_path_loc, value);
 3157|    273|                if (rc < 0) {
  ------------------
  |  Branch (3157:21): [True: 0, False: 273]
  ------------------
 3158|      0|                    ssh_key_free(key);
 3159|      0|                    return -1;
 3160|      0|                }
 3161|    273|            } else if (type == SSH_BIND_OPTIONS_IMPORT_KEY_STR) {
  ------------------
  |  Branch (3161:24): [True: 0, False: 0]
  ------------------
 3162|      0|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (3162:21): [True: 0, False: 0]
  ------------------
 3163|      0|                    ssh_key_free(key);
 3164|      0|                    return -1;
 3165|      0|                }
 3166|      0|            } else {
 3167|      0|                if (bind_key_loc == NULL) {
  ------------------
  |  Branch (3167:21): [True: 0, False: 0]
  ------------------
 3168|      0|                    return -1;
 3169|      0|                }
 3170|      0|            }
 3171|    273|            ssh_key_free(*bind_key_loc);
 3172|    273|            *bind_key_loc = key;
 3173|    273|        }
 3174|    273|        break;
 3175|    273|    case SSH_BIND_OPTIONS_BINDADDR:
  ------------------
  |  Branch (3175:5): [True: 0, False: 1.63k]
  ------------------
 3176|      0|        if (value == NULL) {
  ------------------
  |  Branch (3176:13): [True: 0, False: 0]
  ------------------
 3177|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3178|      0|            return -1;
 3179|      0|        } else {
 3180|      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]
  |  |  ------------------
  ------------------
 3181|      0|            sshbind->bindaddr = strdup(value);
 3182|      0|            if (sshbind->bindaddr == NULL) {
  ------------------
  |  Branch (3182:17): [True: 0, False: 0]
  ------------------
 3183|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3184|      0|                return -1;
 3185|      0|            }
 3186|      0|        }
 3187|      0|        break;
 3188|      0|    case SSH_BIND_OPTIONS_BINDPORT:
  ------------------
  |  Branch (3188:5): [True: 0, False: 1.63k]
  ------------------
 3189|      0|        if (value == NULL) {
  ------------------
  |  Branch (3189:13): [True: 0, False: 0]
  ------------------
 3190|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3191|      0|            return -1;
 3192|      0|        } else {
 3193|      0|            int *x = (int *)value;
 3194|      0|            sshbind->bindport = *x & 0xffffU;
 3195|      0|        }
 3196|      0|        break;
 3197|      0|    case SSH_BIND_OPTIONS_BINDPORT_STR:
  ------------------
  |  Branch (3197:5): [True: 0, False: 1.63k]
  ------------------
 3198|      0|        if (value == NULL) {
  ------------------
  |  Branch (3198:13): [True: 0, False: 0]
  ------------------
 3199|      0|            sshbind->bindport = 22 & 0xffffU;
 3200|      0|        } else {
 3201|      0|            q = strdup(value);
 3202|      0|            if (q == NULL) {
  ------------------
  |  Branch (3202:17): [True: 0, False: 0]
  ------------------
 3203|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3204|      0|                return -1;
 3205|      0|            }
 3206|      0|            i = strtol(q, &p, 10);
 3207|      0|            if (q == p) {
  ------------------
  |  Branch (3207:17): [True: 0, False: 0]
  ------------------
 3208|      0|                SSH_LOG(SSH_LOG_DEBUG, "No bind port was parsed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3209|      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]
  |  |  ------------------
  ------------------
 3210|      0|                return -1;
 3211|      0|            }
 3212|      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]
  |  |  ------------------
  ------------------
 3213|       |
 3214|      0|            sshbind->bindport = i & 0xffffU;
 3215|      0|        }
 3216|      0|        break;
 3217|      0|    case SSH_BIND_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (3217:5): [True: 0, False: 1.63k]
  ------------------
 3218|      0|        if (value == NULL) {
  ------------------
  |  Branch (3218:13): [True: 0, False: 0]
  ------------------
 3219|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3220|      0|            return -1;
 3221|      0|        } else {
 3222|      0|            int *x = (int *)value;
 3223|      0|            ssh_set_log_level(*x & 0xffffU);
 3224|      0|        }
 3225|      0|        break;
 3226|      0|    case SSH_BIND_OPTIONS_LOG_VERBOSITY_STR:
  ------------------
  |  Branch (3226:5): [True: 0, False: 1.63k]
  ------------------
 3227|      0|        if (value == NULL) {
  ------------------
  |  Branch (3227:13): [True: 0, False: 0]
  ------------------
 3228|      0|            ssh_set_log_level(0);
 3229|      0|        } else {
 3230|      0|            q = strdup(value);
 3231|      0|            if (q == NULL) {
  ------------------
  |  Branch (3231:17): [True: 0, False: 0]
  ------------------
 3232|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3233|      0|                return -1;
 3234|      0|            }
 3235|      0|            i = strtol(q, &p, 10);
 3236|      0|            if (q == p) {
  ------------------
  |  Branch (3236:17): [True: 0, False: 0]
  ------------------
 3237|      0|                SSH_LOG(SSH_LOG_DEBUG, "No log verbositiy was parsed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3238|      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]
  |  |  ------------------
  ------------------
 3239|      0|                return -1;
 3240|      0|            }
 3241|      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]
  |  |  ------------------
  ------------------
 3242|       |
 3243|      0|            ssh_set_log_level(i & 0xffffU);
 3244|      0|        }
 3245|      0|        break;
 3246|      0|    case SSH_BIND_OPTIONS_BANNER:
  ------------------
  |  Branch (3246:5): [True: 0, False: 1.63k]
  ------------------
 3247|      0|        if (value == NULL) {
  ------------------
  |  Branch (3247:13): [True: 0, False: 0]
  ------------------
 3248|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3249|      0|            return -1;
 3250|      0|        } else {
 3251|      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]
  |  |  ------------------
  ------------------
 3252|      0|            sshbind->banner = strdup(value);
 3253|      0|            if (sshbind->banner == NULL) {
  ------------------
  |  Branch (3253:17): [True: 0, False: 0]
  ------------------
 3254|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3255|      0|                return -1;
 3256|      0|            }
 3257|      0|        }
 3258|      0|        break;
 3259|    273|    case SSH_BIND_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (3259:5): [True: 273, False: 1.36k]
  ------------------
 3260|    273|        v = value;
 3261|    273|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3261:13): [True: 0, False: 273]
  |  Branch (3261:26): [True: 0, False: 273]
  ------------------
 3262|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3263|      0|            return -1;
 3264|    273|        } else {
 3265|    273|            rc = ssh_bind_set_algo(sshbind,
 3266|    273|                                   SSH_CRYPT_C_S,
 3267|    273|                                   v,
 3268|    273|                                   &wanted_methods[SSH_CRYPT_C_S]);
 3269|    273|            if (rc < 0) {
  ------------------
  |  Branch (3269:17): [True: 0, False: 273]
  ------------------
 3270|      0|                return -1;
 3271|      0|            }
 3272|    273|        }
 3273|    273|        break;
 3274|    273|    case SSH_BIND_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (3274:5): [True: 273, False: 1.36k]
  ------------------
 3275|    273|        v = value;
 3276|    273|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3276:13): [True: 0, False: 273]
  |  Branch (3276:26): [True: 0, False: 273]
  ------------------
 3277|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3278|      0|            return -1;
 3279|    273|        } else {
 3280|    273|            rc = ssh_bind_set_algo(sshbind,
 3281|    273|                                   SSH_CRYPT_S_C,
 3282|    273|                                   v,
 3283|    273|                                   &wanted_methods[SSH_CRYPT_S_C]);
 3284|    273|            if (rc < 0) {
  ------------------
  |  Branch (3284:17): [True: 0, False: 273]
  ------------------
 3285|      0|                return -1;
 3286|      0|            }
 3287|    273|        }
 3288|    273|        break;
 3289|    273|    case SSH_BIND_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (3289:5): [True: 0, False: 1.63k]
  ------------------
 3290|      0|        v = value;
 3291|      0|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3291:13): [True: 0, False: 0]
  |  Branch (3291:26): [True: 0, False: 0]
  ------------------
 3292|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3293|      0|            return -1;
 3294|      0|        } else {
 3295|      0|            rc = ssh_bind_set_algo(sshbind,
 3296|      0|                                   SSH_KEX,
 3297|      0|                                   v,
 3298|      0|                                   &wanted_methods[SSH_KEX]);
 3299|      0|            if (rc < 0) {
  ------------------
  |  Branch (3299:17): [True: 0, False: 0]
  ------------------
 3300|      0|                return -1;
 3301|      0|            }
 3302|      0|        }
 3303|      0|        break;
 3304|    273|    case SSH_BIND_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (3304:5): [True: 273, False: 1.36k]
  ------------------
 3305|    273|        v = value;
 3306|    273|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3306:13): [True: 0, False: 273]
  |  Branch (3306:26): [True: 0, False: 273]
  ------------------
 3307|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3308|      0|            return -1;
 3309|    273|        } else {
 3310|    273|            rc = ssh_bind_set_algo(sshbind,
 3311|    273|                                   SSH_MAC_C_S,
 3312|    273|                                   v,
 3313|    273|                                   &wanted_methods[SSH_MAC_C_S]);
 3314|    273|            if (rc < 0) {
  ------------------
  |  Branch (3314:17): [True: 0, False: 273]
  ------------------
 3315|      0|                return -1;
 3316|      0|            }
 3317|    273|        }
 3318|    273|        break;
 3319|    273|    case SSH_BIND_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (3319:5): [True: 273, False: 1.36k]
  ------------------
 3320|    273|        v = value;
 3321|    273|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3321:13): [True: 0, False: 273]
  |  Branch (3321:26): [True: 0, False: 273]
  ------------------
 3322|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3323|      0|            return -1;
 3324|    273|        } else {
 3325|    273|            rc = ssh_bind_set_algo(sshbind,
 3326|    273|                                   SSH_MAC_S_C,
 3327|    273|                                   v,
 3328|    273|                                   &wanted_methods[SSH_MAC_S_C]);
 3329|    273|            if (rc < 0) {
  ------------------
  |  Branch (3329:17): [True: 0, False: 273]
  ------------------
 3330|      0|                return -1;
 3331|      0|            }
 3332|    273|        }
 3333|    273|        break;
 3334|    273|    case SSH_BIND_OPTIONS_CONFIG_DIR:
  ------------------
  |  Branch (3334:5): [True: 0, False: 1.63k]
  ------------------
 3335|      0|        v = value;
 3336|      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]
  |  |  ------------------
  ------------------
 3337|      0|        if (v == NULL) {
  ------------------
  |  Branch (3337:13): [True: 0, False: 0]
  ------------------
 3338|      0|            break;
 3339|      0|        } else if (v[0] == '\0') {
  ------------------
  |  Branch (3339:20): [True: 0, False: 0]
  ------------------
 3340|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3341|      0|            return -1;
 3342|      0|        } else {
 3343|      0|            sshbind->config_dir = ssh_path_expand_tilde(v);
 3344|      0|            if (sshbind->config_dir == NULL) {
  ------------------
  |  Branch (3344:17): [True: 0, False: 0]
  ------------------
 3345|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3346|      0|                return -1;
 3347|      0|            }
 3348|      0|        }
 3349|      0|        break;
 3350|      0|    case SSH_BIND_OPTIONS_PUBKEY_ACCEPTED_KEY_TYPES:
  ------------------
  |  Branch (3350:5): [True: 0, False: 1.63k]
  ------------------
 3351|      0|        v = value;
 3352|      0|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3352:13): [True: 0, False: 0]
  |  Branch (3352:26): [True: 0, False: 0]
  ------------------
 3353|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3354|      0|            return -1;
 3355|      0|        } else {
 3356|      0|            rc = ssh_bind_set_algo(sshbind,
 3357|      0|                                   SSH_HOSTKEYS,
 3358|      0|                                   v,
 3359|      0|                                   &sshbind->pubkey_accepted_key_types);
 3360|      0|            if (rc < 0) {
  ------------------
  |  Branch (3360:17): [True: 0, False: 0]
  ------------------
 3361|      0|                return -1;
 3362|      0|            }
 3363|      0|        }
 3364|      0|        break;
 3365|      0|    case SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS:
  ------------------
  |  Branch (3365:5): [True: 0, False: 1.63k]
  ------------------
 3366|      0|        v = value;
 3367|      0|        if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (3367:13): [True: 0, False: 0]
  |  Branch (3367:26): [True: 0, False: 0]
  ------------------
 3368|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3369|      0|            return -1;
 3370|      0|        } else {
 3371|      0|            rc = ssh_bind_set_algo(sshbind,
 3372|      0|                                   SSH_HOSTKEYS,
 3373|      0|                                   v,
 3374|      0|                                   &wanted_methods[SSH_HOSTKEYS]);
 3375|      0|            if (rc < 0) {
  ------------------
  |  Branch (3375:17): [True: 0, False: 0]
  ------------------
 3376|      0|                return -1;
 3377|      0|            }
 3378|      0|        }
 3379|      0|        break;
 3380|    273|    case SSH_BIND_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (3380:5): [True: 273, False: 1.36k]
  ------------------
 3381|    273|        if (value == NULL) {
  ------------------
  |  Branch (3381:13): [True: 0, False: 273]
  ------------------
 3382|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3383|      0|            return -1;
 3384|    273|        } else {
 3385|    273|            bool *x = (bool *)value;
 3386|    273|            sshbind->config_processed = !(*x);
 3387|    273|        }
 3388|    273|        break;
 3389|    273|    case SSH_BIND_OPTIONS_MODULI:
  ------------------
  |  Branch (3389:5): [True: 0, False: 1.63k]
  ------------------
 3390|      0|        if (value == NULL) {
  ------------------
  |  Branch (3390:13): [True: 0, False: 0]
  ------------------
 3391|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3392|      0|            return -1;
 3393|      0|        } else {
 3394|      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]
  |  |  ------------------
  ------------------
 3395|      0|            sshbind->moduli_file = strdup(value);
 3396|      0|            if (sshbind->moduli_file == NULL) {
  ------------------
  |  Branch (3396:17): [True: 0, False: 0]
  ------------------
 3397|      0|                ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3398|      0|                return -1;
 3399|      0|            }
 3400|      0|        }
 3401|      0|        break;
 3402|      0|    case SSH_BIND_OPTIONS_RSA_MIN_SIZE:
  ------------------
  |  Branch (3402:5): [True: 0, False: 1.63k]
  ------------------
 3403|      0|        if (value == NULL) {
  ------------------
  |  Branch (3403:13): [True: 0, False: 0]
  ------------------
 3404|      0|            ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3405|      0|            return -1;
 3406|      0|        } else {
 3407|      0|            int *x = (int *)value;
 3408|       |
 3409|      0|            if (*x < 0) {
  ------------------
  |  Branch (3409:17): [True: 0, False: 0]
  ------------------
 3410|      0|                ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 3411|      0|                return -1;
 3412|      0|            }
 3413|       |
 3414|       |            /* (*x == 0) is allowed as it is used to revert to default */
 3415|       |
 3416|      0|            if (*x > 0 && *x < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|      0|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (3416:17): [True: 0, False: 0]
  |  Branch (3416:27): [True: 0, False: 0]
  ------------------
 3417|      0|                ssh_set_error(sshbind,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3418|      0|                              SSH_REQUEST_DENIED,
 3419|      0|                              "The provided value (%d) for minimal RSA key "
 3420|      0|                              "size is too small. Use at least %d bits.",
 3421|      0|                              *x,
 3422|      0|                              RSA_MIN_KEY_SIZE);
 3423|      0|                return -1;
 3424|      0|            }
 3425|      0|            sshbind->rsa_min_size = *x;
 3426|      0|        }
 3427|      0|        break;
 3428|       |#ifdef WITH_GSSAPI
 3429|       |    case SSH_BIND_OPTIONS_GSSAPI_KEY_EXCHANGE:
 3430|       |        if (value == NULL) {
 3431|       |            ssh_set_error_invalid(sshbind);
 3432|       |            return -1;
 3433|       |        } else {
 3434|       |            bool *x = (bool *)value;
 3435|       |            sshbind->gssapi_key_exchange = *x;
 3436|       |        }
 3437|       |        break;
 3438|       |    case SSH_BIND_OPTIONS_GSSAPI_KEY_EXCHANGE_ALGS:
 3439|       |        if (value == NULL) {
 3440|       |            ssh_set_error_invalid(sshbind);
 3441|       |            return -1;
 3442|       |        } else {
 3443|       |            char *ret = NULL;
 3444|       |            SAFE_FREE(sshbind->gssapi_key_exchange_algs);
 3445|       |            ret = ssh_find_all_matching(GSSAPI_KEY_EXCHANGE_SUPPORTED, value);
 3446|       |            if (ret == NULL) {
 3447|       |                ssh_set_error(
 3448|       |                    sshbind,
 3449|       |                    SSH_REQUEST_DENIED,
 3450|       |                    "GSSAPI key exchange algorithms not supported or invalid");
 3451|       |                return -1;
 3452|       |            }
 3453|       |            sshbind->gssapi_key_exchange_algs = ret;
 3454|       |        }
 3455|       |        break;
 3456|       |#endif /* WITH_GSSAPI */
 3457|      0|    default:
  ------------------
  |  Branch (3457:5): [True: 0, False: 1.63k]
  ------------------
 3458|      0|        ssh_set_error(sshbind,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3459|      0|                      SSH_REQUEST_DENIED,
 3460|      0|                      "Unknown ssh option %d",
 3461|      0|                      type);
 3462|      0|        return -1;
 3463|      0|        break;
 3464|  1.63k|    }
 3465|       |
 3466|  1.63k|    return 0;
 3467|  1.63k|}
options.c:ssh_bind_key_size_allowed:
 2839|    273|{
 2840|    273|    int min_size = 0;
 2841|       |
 2842|    273|    switch (ssh_key_type(key)) {
 2843|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2843:5): [True: 0, False: 273]
  ------------------
 2844|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (2844:5): [True: 0, False: 273]
  ------------------
 2845|      0|        min_size = sshbind->rsa_min_size;
 2846|      0|        return ssh_key_size_allowed_rsa(min_size, key);
 2847|    273|    default:
  ------------------
  |  Branch (2847:5): [True: 273, False: 0]
  ------------------
 2848|       |        return true;
 2849|    273|    }
 2850|    273|}
options.c:ssh_bind_set_key:
 2858|    273|{
 2859|    273|    if (value == NULL) {
  ------------------
  |  Branch (2859:9): [True: 0, False: 273]
  ------------------
 2860|      0|        ssh_set_error_invalid(sshbind);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2861|      0|        return -1;
 2862|    273|    } else {
 2863|    273|        SAFE_FREE(*key_loc);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
 2864|    273|        *key_loc = strdup(value);
 2865|    273|        if (*key_loc == NULL) {
  ------------------
  |  Branch (2865:13): [True: 0, False: 273]
  ------------------
 2866|      0|            ssh_set_error_oom(sshbind);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2867|      0|            return -1;
 2868|      0|        }
 2869|    273|    }
 2870|    273|    return 0;
 2871|    273|}
options.c:ssh_bind_set_algo:
 2877|  1.09k|{
 2878|       |    /* sshbind is needed only for ssh_set_error which takes void*
 2879|       |     * the typecast is only to satisfy function parameter type */
 2880|  1.09k|    return ssh_options_set_algo((ssh_session)sshbind, algo, list, place);
 2881|  1.09k|}

ssh_packet_get_current_crypto:
 1159|  37.9k|{
 1160|  37.9k|    struct ssh_crypto_struct *crypto = NULL;
 1161|       |
 1162|  37.9k|    if (session == NULL) {
  ------------------
  |  Branch (1162:9): [True: 0, False: 37.9k]
  ------------------
 1163|      0|        return NULL;
 1164|      0|    }
 1165|       |
 1166|  37.9k|    if (session->current_crypto != NULL &&
  ------------------
  |  Branch (1166:9): [True: 30.0k, False: 7.88k]
  ------------------
 1167|  30.0k|        session->current_crypto->used & direction) {
  ------------------
  |  Branch (1167:9): [True: 30.0k, False: 0]
  ------------------
 1168|  30.0k|        crypto = session->current_crypto;
 1169|  30.0k|    } else if (session->next_crypto != NULL &&
  ------------------
  |  Branch (1169:16): [True: 7.88k, False: 0]
  ------------------
 1170|  7.88k|               session->next_crypto->used & direction) {
  ------------------
  |  Branch (1170:16): [True: 0, False: 7.88k]
  ------------------
 1171|      0|        crypto = session->next_crypto;
 1172|  7.88k|    } else {
 1173|  7.88k|        return NULL;
 1174|  7.88k|    }
 1175|       |
 1176|  30.0k|    switch (direction) {
  ------------------
  |  Branch (1176:13): [True: 30.0k, False: 18.4E]
  ------------------
 1177|  17.2k|    case SSH_DIRECTION_IN:
  ------------------
  |  Branch (1177:5): [True: 17.2k, False: 12.8k]
  ------------------
 1178|  17.2k|        if (crypto->in_cipher != NULL) {
  ------------------
  |  Branch (1178:13): [True: 17.2k, False: 0]
  ------------------
 1179|  17.2k|            return crypto;
 1180|  17.2k|        }
 1181|      0|        break;
 1182|  8.19k|    case SSH_DIRECTION_OUT:
  ------------------
  |  Branch (1182:5): [True: 8.19k, False: 21.8k]
  ------------------
 1183|  8.19k|        if (crypto->out_cipher != NULL) {
  ------------------
  |  Branch (1183:13): [True: 8.19k, False: 0]
  ------------------
 1184|  8.19k|            return crypto;
 1185|  8.19k|        }
 1186|      0|        break;
 1187|  4.63k|    case SSH_DIRECTION_BOTH:
  ------------------
  |  Branch (1187:5): [True: 4.63k, False: 25.4k]
  ------------------
 1188|  4.63k|        if (crypto->in_cipher != NULL &&
  ------------------
  |  Branch (1188:13): [True: 4.63k, False: 0]
  ------------------
 1189|  4.63k|            crypto->out_cipher != NULL) {
  ------------------
  |  Branch (1189:13): [True: 4.63k, False: 0]
  ------------------
 1190|  4.63k|            return crypto;
 1191|  4.63k|        }
 1192|  30.0k|    }
 1193|       |
 1194|      0|    return NULL;
 1195|  30.0k|}
ssh_packet_socket_callback:
 1286|  9.38k|{
 1287|  9.38k|    ssh_session session = (ssh_session)user;
 1288|  9.38k|    uint32_t blocksize = 8;
 1289|  9.38k|    uint32_t lenfield_blocksize = 8;
 1290|  9.38k|    size_t current_macsize = 0;
 1291|  9.38k|    uint8_t *ptr = NULL;
 1292|  9.38k|    ssize_t to_be_read;
 1293|  9.38k|    int rc;
 1294|  9.38k|    uint8_t *cleartext_packet = NULL;
 1295|  9.38k|    uint8_t *packet_second_block = NULL;
 1296|  9.38k|    uint8_t *mac = NULL;
 1297|  9.38k|    size_t packet_remaining, packet_offset;
 1298|  9.38k|    uint32_t packet_len, compsize, payloadsize;
 1299|  9.38k|    uint8_t padding;
 1300|  9.38k|    size_t processed = 0; /* number of bytes processed from the callback */
 1301|  9.38k|    enum ssh_packet_filter_result_e filter_result;
 1302|  9.38k|    struct ssh_crypto_struct *crypto = NULL;
 1303|  9.38k|    bool etm = false;
 1304|  9.38k|    uint32_t etm_packet_offset = 0;
 1305|  9.38k|    bool ok;
 1306|       |
 1307|  9.38k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
 1308|  9.38k|    if (crypto != NULL) {
  ------------------
  |  Branch (1308:9): [True: 6.41k, False: 2.97k]
  ------------------
 1309|  6.41k|        current_macsize = hmac_digest_len(crypto->in_hmac);
 1310|  6.41k|        blocksize = crypto->in_cipher->blocksize;
 1311|  6.41k|        lenfield_blocksize = crypto->in_cipher->lenfield_blocksize;
 1312|  6.41k|        etm = crypto->in_hmac_etm;
 1313|  6.41k|    }
 1314|       |
 1315|  9.38k|    if (etm) {
  ------------------
  |  Branch (1315:9): [True: 0, False: 9.38k]
  ------------------
 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|  9.38k|    } else if (lenfield_blocksize == 0) {
  ------------------
  |  Branch (1322:16): [True: 6.41k, False: 2.97k]
  ------------------
 1323|  6.41k|        lenfield_blocksize = blocksize;
 1324|  6.41k|    }
 1325|  9.38k|    if (data == NULL) {
  ------------------
  |  Branch (1325:9): [True: 0, False: 9.38k]
  ------------------
 1326|      0|        goto error;
 1327|      0|    }
 1328|       |
 1329|  9.38k|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (1329:9): [True: 0, False: 9.38k]
  ------------------
 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|  9.38k|    switch (session->packet_state) {
  ------------------
  |  Branch (1343:13): [True: 9.38k, False: 0]
  ------------------
 1344|  9.31k|        case PACKET_STATE_INIT:
  ------------------
  |  Branch (1344:9): [True: 9.31k, False: 71]
  ------------------
 1345|  9.31k|            if (receivedlen < lenfield_blocksize + etm_packet_offset) {
  ------------------
  |  Branch (1345:17): [True: 4.67k, False: 4.64k]
  ------------------
 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|  4.67k|                return 0;
 1357|  4.67k|            }
 1358|       |
 1359|  4.64k|            session->in_packet = (struct packet_struct) {
 1360|  4.64k|                .type = 0,
 1361|  4.64k|            };
 1362|       |
 1363|  4.64k|            if (session->in_buffer) {
  ------------------
  |  Branch (1363:17): [True: 4.64k, False: 0]
  ------------------
 1364|  4.64k|                rc = ssh_buffer_reinit(session->in_buffer);
 1365|  4.64k|                if (rc < 0) {
  ------------------
  |  Branch (1365:21): [True: 0, False: 4.64k]
  ------------------
 1366|      0|                    goto error;
 1367|      0|                }
 1368|  4.64k|            } else {
 1369|      0|                session->in_buffer = ssh_buffer_new();
 1370|      0|                if (session->in_buffer == NULL) {
  ------------------
  |  Branch (1370:21): [True: 0, False: 0]
  ------------------
 1371|      0|                    goto error;
 1372|      0|                }
 1373|      0|            }
 1374|       |
 1375|  4.64k|            if (!etm) {
  ------------------
  |  Branch (1375:17): [True: 4.64k, False: 1]
  ------------------
 1376|  4.64k|                ptr = ssh_buffer_allocate(session->in_buffer,
 1377|  4.64k|                                          lenfield_blocksize);
 1378|  4.64k|                if (ptr == NULL) {
  ------------------
  |  Branch (1378:21): [True: 0, False: 4.64k]
  ------------------
 1379|      0|                    goto error;
 1380|      0|                }
 1381|  4.64k|                packet_len = ssh_packet_decrypt_len(session, ptr,
 1382|  4.64k|                                                    (uint8_t *)data);
 1383|  4.64k|                to_be_read = packet_len - lenfield_blocksize + sizeof(uint32_t);
 1384|  4.64k|            } else {
 1385|       |                /* Length is unencrypted in case of Encrypt-then-MAC */
 1386|      1|                packet_len = PULL_BE_U32(data, 0);
  ------------------
  |  |   75|      1|    ((((uint32_t)PULL_BE_U16(data, pos)) << 16) | (uint32_t)(PULL_BE_U16(data, (pos) + 2)))
  |  |  ------------------
  |  |  |  |   72|      1|    ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|      1|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|      1|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|      1|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|      1|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   ((((uint32_t)PULL_BE_U16(data, pos)) << 16) | (uint32_t)(PULL_BE_U16(data, (pos) + 2)))
  |  |  ------------------
  |  |  |  |   72|      1|    ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|      1|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|      1|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|      1|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|      1|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1387|      1|                to_be_read = packet_len - etm_packet_offset;
 1388|      1|            }
 1389|       |
 1390|  4.64k|            processed += lenfield_blocksize + etm_packet_offset;
 1391|  4.64k|            if (packet_len > MAX_PACKET_LEN) {
  ------------------
  |  |  216|  4.64k|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (1391:17): [True: 0, False: 4.64k]
  ------------------
 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|  4.64k|            if (to_be_read < 0) {
  ------------------
  |  Branch (1398:17): [True: 0, False: 4.64k]
  ------------------
 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|  4.64k|            session->in_packet.len = packet_len;
 1408|  4.64k|            session->packet_state = PACKET_STATE_SIZEREAD;
 1409|  4.64k|            FALL_THROUGH;
  ------------------
  |  |  494|  4.64k|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1410|  4.71k|        case PACKET_STATE_SIZEREAD:
  ------------------
  |  Branch (1410:9): [True: 71, False: 9.31k]
  ------------------
 1411|  4.71k|            packet_len = session->in_packet.len;
 1412|  4.71k|            packet_offset = processed = lenfield_blocksize + etm_packet_offset;
 1413|  4.71k|            to_be_read = packet_len + sizeof(uint32_t) + current_macsize;
 1414|       |            /* if to_be_read is zero, the whole packet was blocksize bytes. */
 1415|  4.71k|            if (to_be_read != 0) {
  ------------------
  |  Branch (1415:17): [True: 4.71k, False: 0]
  ------------------
 1416|  4.71k|                if (receivedlen < (unsigned long)to_be_read) {
  ------------------
  |  Branch (1416:21): [True: 71, False: 4.64k]
  ------------------
 1417|       |                    /* give up, not enough data in buffer */
 1418|     71|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|     71|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1419|     71|                            "packet: partial packet (read len) "
 1420|     71|                            "[len=%" PRIu32 ", receivedlen=%zu, to_be_read=%zd]",
 1421|     71|                            packet_len,
 1422|     71|                            receivedlen,
 1423|     71|                            to_be_read);
 1424|     71|                    return 0;
 1425|     71|                }
 1426|       |
 1427|  4.64k|                packet_second_block = (uint8_t*)data + packet_offset;
 1428|  4.64k|                processed = to_be_read - current_macsize;
 1429|  4.64k|            }
 1430|       |
 1431|  4.64k|            if (packet_offset - sizeof(uint32_t) > (size_t)packet_len) {
  ------------------
  |  Branch (1431:17): [True: 0, False: 4.64k]
  ------------------
 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|  4.64k|            packet_remaining = packet_len - (packet_offset - sizeof(uint32_t));
 1442|  4.64k|            cleartext_packet = ssh_buffer_allocate(session->in_buffer,
 1443|  4.64k|                                                   (uint32_t)packet_remaining);
 1444|  4.64k|            if (cleartext_packet == NULL) {
  ------------------
  |  Branch (1444:17): [True: 0, False: 4.64k]
  ------------------
 1445|      0|                goto error;
 1446|      0|            }
 1447|       |
 1448|  4.64k|            if (packet_second_block != NULL) {
  ------------------
  |  Branch (1448:17): [True: 4.64k, False: 0]
  ------------------
 1449|  4.64k|                if (crypto != NULL) {
  ------------------
  |  Branch (1449:21): [True: 3.00k, False: 1.63k]
  ------------------
 1450|  3.00k|                    mac = packet_second_block + packet_remaining;
 1451|       |
 1452|  3.00k|                    if (crypto->in_hmac != SSH_HMAC_NONE && etm) {
  ------------------
  |  Branch (1452:25): [True: 1.63k, False: 1.36k]
  |  Branch (1452:61): [True: 0, False: 1.63k]
  ------------------
 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|  3.00k|                    if (packet_remaining > 0) {
  ------------------
  |  Branch (1468:25): [True: 2.64k, False: 363]
  ------------------
 1469|  2.64k|                        rc = ssh_packet_decrypt(session,
 1470|  2.64k|                                                cleartext_packet,
 1471|  2.64k|                                                (uint8_t *)data,
 1472|  2.64k|                                                packet_offset,
 1473|  2.64k|                                                processed - packet_offset);
 1474|  2.64k|                        if (rc < 0) {
  ------------------
  |  Branch (1474:29): [True: 0, False: 2.64k]
  ------------------
 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|  2.64k|                    }
 1481|       |
 1482|  3.00k|                    if (crypto->in_hmac != SSH_HMAC_NONE && !etm) {
  ------------------
  |  Branch (1482:25): [True: 1.63k, False: 1.36k]
  |  Branch (1482:61): [True: 1.63k, False: 0]
  ------------------
 1483|  1.63k|                        ssh_buffer in = session->in_buffer;
 1484|  1.63k|                        rc = ssh_packet_hmac_verify(session,
 1485|  1.63k|                                                    ssh_buffer_get(in),
 1486|  1.63k|                                                    ssh_buffer_get_len(in),
 1487|  1.63k|                                                    mac,
 1488|  1.63k|                                                    crypto->in_hmac);
 1489|  1.63k|                        if (rc < 0) {
  ------------------
  |  Branch (1489:29): [True: 0, False: 1.63k]
  ------------------
 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|  1.63k|                    }
 1494|  3.00k|                    processed += current_macsize;
 1495|  3.00k|                } else {
 1496|  1.63k|                    memcpy(cleartext_packet,
 1497|  1.63k|                           packet_second_block,
 1498|  1.63k|                           packet_remaining);
 1499|  1.63k|                }
 1500|  4.64k|            }
 1501|       |
 1502|  4.64k|#ifdef WITH_PCAP
 1503|  4.64k|            if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1503:17): [True: 0, False: 4.64k]
  ------------------
 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|  4.64k|#endif
 1511|       |
 1512|  4.64k|            if (!etm) {
  ------------------
  |  Branch (1512:17): [True: 4.64k, False: 1]
  ------------------
 1513|       |                /* skip the size field which has been processed before */
 1514|  4.64k|                ssh_buffer_pass_bytes(session->in_buffer, sizeof(uint32_t));
 1515|  4.64k|            }
 1516|       |
 1517|  4.64k|            rc = ssh_buffer_get_u8(session->in_buffer, &padding);
 1518|  4.64k|            if (rc == 0) {
  ------------------
  |  Branch (1518:17): [True: 0, False: 4.64k]
  ------------------
 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|  4.64k|            if (padding > ssh_buffer_get_len(session->in_buffer)) {
  ------------------
  |  Branch (1525:17): [True: 0, False: 4.64k]
  ------------------
 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|  4.64k|            ssh_buffer_pass_bytes_end(session->in_buffer, padding);
 1534|  4.64k|            compsize = ssh_buffer_get_len(session->in_buffer);
 1535|       |
 1536|  4.64k|            if (crypto && crypto->do_compress_in &&
  ------------------
  |  Branch (1536:17): [True: 3.00k, False: 1.63k]
  |  Branch (1536:27): [True: 0, False: 3.00k]
  ------------------
 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|  4.64k|            payloadsize = ssh_buffer_get_len(session->in_buffer);
 1545|  4.64k|            if (session->recv_seq == UINT32_MAX) {
  ------------------
  |  Branch (1545:17): [True: 0, False: 4.64k]
  ------------------
 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|  4.64k|            session->recv_seq++;
 1559|  4.64k|            if (crypto != NULL) {
  ------------------
  |  Branch (1559:17): [True: 3.00k, False: 1.63k]
  ------------------
 1560|  3.00k|                struct ssh_cipher_struct *cipher = NULL;
 1561|       |
 1562|  3.00k|                cipher = crypto->in_cipher;
 1563|  3.00k|                cipher->packets++;
 1564|  3.00k|                cipher->blocks += payloadsize / cipher->blocksize;
 1565|  3.00k|            }
 1566|  4.64k|            if (session->raw_counter != NULL) {
  ------------------
  |  Branch (1566:17): [True: 0, False: 4.64k]
  ------------------
 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|  4.64k|            session->packet_state = PACKET_STATE_PROCESSING;
 1576|  4.64k|            ssh_packet_parse_type(session);
 1577|  4.64k|            SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  4.64k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1578|  4.64k|                    "packet: read type %hhd [len=%" PRIu32 ",padding=%hhd,"
 1579|  4.64k|                    "comp=%" PRIu32 ",payload=%" PRIu32 "]",
 1580|  4.64k|                    session->in_packet.type, packet_len, padding, compsize,
 1581|  4.64k|                    payloadsize);
 1582|  4.64k|            if (crypto == NULL) {
  ------------------
  |  Branch (1582:17): [True: 1.63k, False: 3.00k]
  ------------------
 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|  1.63k|                uint8_t type = session->in_packet.type;
 1588|       |
 1589|  1.63k|                if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   12|  3.27k|#define SSH2_MSG_KEXINIT	 20
  ------------------
                              if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   13|  2.73k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (1589:21): [True: 1.09k, False: 546]
  |  Branch (1589:49): [True: 546, False: 546]
  ------------------
 1590|    546|                    (type < SSH2_MSG_KEXDH_INIT ||
  ------------------
  |  |   15|  1.09k|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (1590:22): [True: 0, False: 546]
  ------------------
 1591|    546|                     type > SSH2_MSG_KEX_DH_GEX_REQUEST)) {
  ------------------
  |  |   26|    546|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (1591:22): [True: 0, False: 546]
  ------------------
 1592|      0|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|      0|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1593|      0|                }
 1594|  1.63k|            }
 1595|       |            /* Check if the packet is expected */
 1596|  4.64k|            filter_result = ssh_packet_incoming_filter(session);
 1597|       |
 1598|  4.64k|            switch (filter_result) {
  ------------------
  |  Branch (1598:21): [True: 4.64k, False: 0]
  ------------------
 1599|  4.64k|            case SSH_PACKET_ALLOWED:
  ------------------
  |  Branch (1599:13): [True: 4.64k, False: 0]
  ------------------
 1600|       |                /* Execute callbacks */
 1601|  4.64k|                ssh_packet_process(session, session->in_packet.type);
 1602|  4.64k|                break;
 1603|      0|            case SSH_PACKET_DENIED:
  ------------------
  |  Branch (1603:13): [True: 0, False: 4.64k]
  ------------------
 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: 4.64k]
  ------------------
 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|  4.64k|            }
 1616|       |
 1617|  4.64k|            session->packet_state = PACKET_STATE_INIT;
 1618|  4.64k|            if (processed < receivedlen) {
  ------------------
  |  Branch (1618:17): [True: 482, False: 4.15k]
  ------------------
 1619|    482|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    482|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1620|    482|                        "packet: %zu bytes still remaining in socket buffer "
 1621|    482|                        "after processing",
 1622|    482|                        receivedlen-processed);
 1623|    482|            }
 1624|       |
 1625|  4.64k|            ok = ssh_packet_need_rekey(session, 0);
 1626|  4.64k|            if (ok) {
  ------------------
  |  Branch (1626:17): [True: 0, False: 4.64k]
  ------------------
 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|  4.64k|            return processed;
 1636|      0|        case PACKET_STATE_PROCESSING:
  ------------------
  |  Branch (1636:9): [True: 0, False: 9.38k]
  ------------------
 1637|      0|            SSH_LOG(SSH_LOG_PACKET, "Nested packet processing. Delaying.");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1638|      0|            return 0;
 1639|  9.38k|    }
 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|    546|{
 1678|    546|    struct ssh_socket_callbacks_struct *callbacks = &session->socket_callbacks;
 1679|       |
 1680|    546|    callbacks->data = ssh_packet_socket_callback;
 1681|       |    callbacks->connected = NULL;
 1682|    546|    callbacks->controlflow = ssh_packet_socket_controlflow_callback;
 1683|    546|    callbacks->userdata = session;
 1684|    546|    ssh_socket_set_callbacks(s, callbacks);
 1685|    546|}
ssh_packet_set_callbacks:
 1692|  1.09k|{
 1693|  1.09k|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1693:9): [True: 546, False: 546]
  ------------------
 1694|    546|        session->packet_callbacks = ssh_list_new();
 1695|    546|        if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1695:13): [True: 0, False: 546]
  ------------------
 1696|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1697|      0|            return;
 1698|      0|        }
 1699|    546|    }
 1700|  1.09k|    ssh_list_append(session->packet_callbacks, callbacks);
 1701|  1.09k|}
ssh_packet_remove_callbacks:
 1708|    546|{
 1709|    546|    struct ssh_iterator *it = NULL;
 1710|       |
 1711|    546|    it = ssh_list_find(session->packet_callbacks, callbacks);
 1712|    546|    if (it != NULL) {
  ------------------
  |  Branch (1712:9): [True: 546, False: 0]
  ------------------
 1713|    546|        ssh_list_remove(session->packet_callbacks, it);
 1714|    546|    }
 1715|    546|}
ssh_packet_set_default_callbacks:
 1721|    546|{
 1722|    546|    struct ssh_packet_callbacks_struct *c = &session->default_packet_callbacks;
 1723|       |
 1724|    546|    c->start = 1;
 1725|    546|    c->n_callbacks = sizeof(default_packet_handlers) / sizeof(ssh_packet_callback);
 1726|    546|    c->user = session;
 1727|    546|    c->callbacks = default_packet_handlers;
 1728|    546|    ssh_packet_set_callbacks(session, c);
 1729|    546|}
ssh_packet_process:
 1736|  4.64k|{
 1737|  4.64k|    struct ssh_iterator *i = NULL;
 1738|  4.64k|    int rc = SSH_PACKET_NOT_USED;
  ------------------
  |  |  640|  4.64k|#define SSH_PACKET_NOT_USED 2
  ------------------
 1739|  4.64k|    ssh_packet_callbacks cb;
 1740|       |
 1741|  4.64k|    SSH_LOG(SSH_LOG_PACKET, "Dispatching handler for packet type %d", type);
  ------------------
  |  |  281|  4.64k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1742|  4.64k|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1742:9): [True: 0, False: 4.64k]
  ------------------
 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|  4.64k|    i = ssh_list_get_iterator(session->packet_callbacks);
 1748|  5.18k|    while (i != NULL) {
  ------------------
  |  Branch (1748:12): [True: 5.18k, False: 0]
  ------------------
 1749|  5.18k|        cb = ssh_iterator_value(ssh_packet_callbacks, i);
  ------------------
  |  |  114|  5.18k|  ((type)((iterator)->data))
  ------------------
 1750|  5.18k|        i = i->next;
 1751|       |
 1752|  5.18k|        if (!cb) {
  ------------------
  |  Branch (1752:13): [True: 0, False: 5.18k]
  ------------------
 1753|      0|            continue;
 1754|      0|        }
 1755|       |
 1756|  5.18k|        if (cb->start > type) {
  ------------------
  |  Branch (1756:13): [True: 0, False: 5.18k]
  ------------------
 1757|      0|            continue;
 1758|      0|        }
 1759|       |
 1760|  5.18k|        if (cb->start + cb->n_callbacks <= type) {
  ------------------
  |  Branch (1760:13): [True: 0, False: 5.18k]
  ------------------
 1761|      0|            continue;
 1762|      0|        }
 1763|       |
 1764|  5.18k|        if (cb->callbacks[type - cb->start] == NULL) {
  ------------------
  |  Branch (1764:13): [True: 273, False: 4.91k]
  ------------------
 1765|    273|            continue;
 1766|    273|        }
 1767|       |
 1768|  4.91k|        rc = cb->callbacks[type - cb->start](session, type, session->in_buffer,
 1769|  4.91k|                                             cb->user);
 1770|  4.91k|        if (rc == SSH_PACKET_USED) {
  ------------------
  |  |  637|  4.91k|#define SSH_PACKET_USED 1
  ------------------
  |  Branch (1770:13): [True: 4.64k, False: 272]
  ------------------
 1771|  4.64k|            break;
 1772|  4.64k|        }
 1773|  4.91k|    }
 1774|       |
 1775|  4.64k|    if (rc == SSH_PACKET_NOT_USED) {
  ------------------
  |  |  640|  4.64k|#define SSH_PACKET_NOT_USED 2
  ------------------
  |  Branch (1775:9): [True: 0, False: 4.64k]
  ------------------
 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|  4.64k|}
ssh_packet_send_newkeys:
 1794|    546|{
 1795|    546|    int rc;
 1796|       |
 1797|       |    /* Send the MSG_NEWKEYS */
 1798|    546|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS);
  ------------------
  |  |   13|    546|#define SSH2_MSG_NEWKEYS 21
  ------------------
 1799|    546|    if (rc < 0) {
  ------------------
  |  Branch (1799:9): [True: 0, False: 546]
  ------------------
 1800|      0|        return rc;
 1801|      0|    }
 1802|       |
 1803|    546|    rc = ssh_packet_send(session);
 1804|    546|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1804:9): [True: 0, False: 546]
  ------------------
 1805|      0|        return rc;
 1806|      0|    }
 1807|    546|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_NEWKEYS sent");
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1808|    546|    return rc;
 1809|    546|}
ssh_packet_parse_type:
 1861|  4.64k|{
 1862|  4.64k|    session->in_packet = (struct packet_struct) {
 1863|  4.64k|        .type = 0,
 1864|  4.64k|    };
 1865|       |
 1866|  4.64k|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (1866:9): [True: 0, False: 4.64k]
  ------------------
 1867|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1868|      0|    }
 1869|       |
 1870|  4.64k|    if (ssh_buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) {
  ------------------
  |  Branch (1870:9): [True: 0, False: 4.64k]
  ------------------
 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|  4.64k|    session->in_packet.valid = 1;
 1876|       |
 1877|  4.64k|    return SSH_OK;
  ------------------
  |  |  316|  4.64k|#define SSH_OK 0     /* No error */
  ------------------
 1878|  4.64k|}
ssh_packet_send:
 2066|  5.73k|{
 2067|  5.73k|    uint32_t payloadsize;
 2068|  5.73k|    uint8_t type, *payload;
 2069|  5.73k|    bool need_rekey, in_rekey;
 2070|  5.73k|    int rc;
 2071|       |
 2072|  5.73k|    if (session->socket == NULL || !ssh_socket_is_open(session->socket)) {
  ------------------
  |  Branch (2072:9): [True: 0, False: 5.73k]
  |  Branch (2072:36): [True: 273, False: 5.46k]
  ------------------
 2073|    273|        ssh_buffer_reinit(session->out_buffer);
 2074|    273|        return SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2075|    273|    }
 2076|       |
 2077|  5.46k|    payloadsize = ssh_buffer_get_len(session->out_buffer);
 2078|  5.46k|    if (payloadsize < 1) {
  ------------------
  |  Branch (2078:9): [True: 0, False: 5.46k]
  ------------------
 2079|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2080|      0|    }
 2081|       |
 2082|  5.46k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 2083|  5.46k|    type = payload[0]; /* type is the first byte of the packet now */
 2084|  5.46k|    need_rekey = ssh_packet_need_rekey(session, payloadsize);
 2085|  5.46k|    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|  5.46k|    if (need_rekey || (in_rekey && !ssh_packet_is_kex(type))) {
  ------------------
  |  Branch (2090:9): [True: 0, False: 5.46k]
  |  Branch (2090:24): [True: 0, False: 5.46k]
  |  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|  5.46k|    rc = packet_send2(session);
 2120|       |
 2121|       |    /* We finished the key exchange so we can try to send our queue now */
 2122|  5.46k|    if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |  316|  10.9k|#define SSH_OK 0     /* No error */
  ------------------
                  if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  5.46k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2122:9): [True: 5.46k, False: 0]
  |  Branch (2122:25): [True: 546, False: 4.91k]
  ------------------
 2123|    546|        struct ssh_iterator *it = NULL;
 2124|       |
 2125|    546|        if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|    546|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (2125:13): [True: 546, False: 0]
  ------------------
 2126|       |            /* reset packet sequence number when running in strict kex mode */
 2127|    546|            session->send_seq = 0;
 2128|    546|        }
 2129|    546|        for (it = ssh_list_get_iterator(session->out_queue);
 2130|    546|             it != NULL;
  ------------------
  |  Branch (2130:14): [True: 0, False: 546]
  ------------------
 2131|    546|             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);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957: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|    546|    }
 2154|       |
 2155|  5.46k|    return rc;
 2156|  5.46k|}
ssh_packet_set_newkeys:
 2271|  1.09k|{
 2272|  1.09k|    struct ssh_cipher_struct *in_cipher = NULL, *out_cipher = NULL;
 2273|  1.09k|    int rc;
 2274|       |
 2275|  1.09k|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|  4.36k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 546, False: 546]
  |  |  |  Branch (281:34): [True: 546, False: 546]
  |  |  ------------------
  ------------------
 2276|  1.09k|            "called, direction =%s%s",
 2277|  1.09k|            direction & SSH_DIRECTION_IN ? " IN " : "",
 2278|  1.09k|            direction & SSH_DIRECTION_OUT ? " OUT " : "");
 2279|       |
 2280|  1.09k|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2280:9): [True: 0, False: 1.09k]
  ------------------
 2281|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2282|      0|    }
 2283|       |
 2284|  1.09k|    session->next_crypto->used |= direction;
 2285|  1.09k|    if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2285:9): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|    if (session->next_crypto->used == SSH_DIRECTION_BOTH) {
  ------------------
  |  Branch (2294:9): [True: 546, False: 546]
  ------------------
 2295|    546|        size_t session_id_len;
 2296|       |
 2297|    546|        if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2297:13): [True: 0, False: 546]
  ------------------
 2298|      0|            crypto_free(session->current_crypto);
 2299|      0|            session->current_crypto = NULL;
 2300|      0|        }
 2301|       |
 2302|    546|        session->current_crypto = session->next_crypto;
 2303|    546|        session->current_crypto->used = SSH_DIRECTION_BOTH;
 2304|       |
 2305|       |        /* Initialize the next_crypto structure */
 2306|    546|        session->next_crypto = crypto_new();
 2307|    546|        if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2307:13): [True: 0, False: 546]
  ------------------
 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|    546|        session_id_len = session->current_crypto->session_id_len;
 2313|    546|        session->next_crypto->session_id = malloc(session_id_len);
 2314|    546|        if (session->next_crypto->session_id == NULL) {
  ------------------
  |  Branch (2314:13): [True: 0, False: 546]
  ------------------
 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|    546|        memcpy(session->next_crypto->session_id,
 2320|    546|               session->current_crypto->session_id,
 2321|    546|               session_id_len);
 2322|    546|        session->next_crypto->session_id_len = session_id_len;
 2323|       |
 2324|    546|        return SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
 2325|    546|    }
 2326|       |
 2327|       |    /* Initialize common structures so the next context can be used in
 2328|       |     * either direction */
 2329|    546|    if (session->client) {
  ------------------
  |  Branch (2329:9): [True: 273, False: 273]
  ------------------
 2330|       |        /* The server has this part already done */
 2331|    273|        rc = ssh_make_sessionid(session);
 2332|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2332:13): [True: 0, False: 273]
  ------------------
 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|    273|        rc = crypt_set_algorithms_client(session);
 2341|    273|        if (rc < 0) {
  ------------------
  |  Branch (2341:13): [True: 0, False: 273]
  ------------------
 2342|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2343|      0|        }
 2344|    273|    }
 2345|       |
 2346|    546|    if (ssh_generate_session_keys(session) < 0) {
  ------------------
  |  Branch (2346:9): [True: 0, False: 546]
  ------------------
 2347|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2348|      0|    }
 2349|       |
 2350|    546|    in_cipher = session->next_crypto->in_cipher;
 2351|    546|    out_cipher = session->next_crypto->out_cipher;
 2352|    546|    if (in_cipher == NULL || out_cipher == NULL) {
  ------------------
  |  Branch (2352:9): [True: 0, False: 546]
  |  Branch (2352:30): [True: 0, False: 546]
  ------------------
 2353|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2354|      0|    }
 2355|       |
 2356|       |    /* Initialize rekeying states */
 2357|    546|    ssh_init_rekey_state(session, out_cipher);
 2358|    546|    ssh_init_rekey_state(session, in_cipher);
 2359|    546|    if (session->opts.rekey_time != 0) {
  ------------------
  |  Branch (2359:9): [True: 0, False: 546]
  ------------------
 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|    546|    if (in_cipher->set_decrypt_key) {
  ------------------
  |  Branch (2365:9): [True: 242, False: 304]
  ------------------
 2366|       |        /* Initialize the encryption and decryption keys in next_crypto */
 2367|    242|        rc = in_cipher->set_decrypt_key(in_cipher,
 2368|    242|                                        session->next_crypto->decryptkey,
 2369|    242|                                        session->next_crypto->decryptIV);
 2370|    242|        if (rc < 0) {
  ------------------
  |  Branch (2370:13): [True: 0, False: 242]
  ------------------
 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|    242|    }
 2376|       |
 2377|    546|    if (out_cipher->set_encrypt_key) {
  ------------------
  |  Branch (2377:9): [True: 242, False: 304]
  ------------------
 2378|    242|        rc = out_cipher->set_encrypt_key(out_cipher,
 2379|    242|                                         session->next_crypto->encryptkey,
 2380|    242|                                         session->next_crypto->encryptIV);
 2381|    242|        if (rc < 0) {
  ------------------
  |  Branch (2381:13): [True: 0, False: 242]
  ------------------
 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|    242|    }
 2387|       |
 2388|    546|    return SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
 2389|    546|}
packet.c:ssh_packet_incoming_filter:
  143|  4.64k|{
  144|  4.64k|    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|  4.64k|    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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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|    273|    case SSH2_MSG_SERVICE_REQUEST:                    // 5
  ------------------
  |  |    8|    273|#define SSH2_MSG_SERVICE_REQUEST	5
  ------------------
  |  Branch (201:5): [True: 273, False: 4.36k]
  ------------------
  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|    273|        if (session->client) {
  ------------------
  |  Branch (215:13): [True: 0, False: 273]
  ------------------
  216|      0|            rc = SSH_PACKET_DENIED;
  217|      0|            break;
  218|      0|        }
  219|       |
  220|    273|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (220:13): [True: 0, False: 273]
  ------------------
  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|    273|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (227:13): [True: 0, False: 273]
  ------------------
  228|      0|            rc = SSH_PACKET_DENIED;
  229|      0|            break;
  230|      0|        }
  231|       |
  232|    273|        rc = SSH_PACKET_ALLOWED;
  233|    273|        break;
  234|    273|    case SSH2_MSG_SERVICE_ACCEPT:                     // 6
  ------------------
  |  |    9|    273|#define SSH2_MSG_SERVICE_ACCEPT 6
  ------------------
  |  Branch (234:5): [True: 273, False: 4.36k]
  ------------------
  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|    273|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (246:13): [True: 0, False: 273]
  ------------------
  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|    273|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (253:13): [True: 0, False: 273]
  ------------------
  254|      0|            rc = SSH_PACKET_DENIED;
  255|      0|            break;
  256|      0|        }
  257|       |
  258|       |        /* TODO check if only auth service can be requested */
  259|    273|        if (session->auth.service_state != SSH_AUTH_SERVICE_SENT) {
  ------------------
  |  Branch (259:13): [True: 0, False: 273]
  ------------------
  260|      0|            rc = SSH_PACKET_DENIED;
  261|      0|            break;
  262|      0|        }
  263|       |
  264|    273|        rc = SSH_PACKET_ALLOWED;
  265|    273|        break;
  266|    273|    case SSH2_MSG_EXT_INFO:                           // 7
  ------------------
  |  |   10|    273|#define SSH2_MSG_EXT_INFO 7
  ------------------
  |  Branch (266:5): [True: 273, False: 4.36k]
  ------------------
  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|    273|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (278:13): [True: 0, False: 273]
  ------------------
  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|    273|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (285:13): [True: 0, False: 273]
  ------------------
  286|      0|            rc = SSH_PACKET_DENIED;
  287|      0|            break;
  288|      0|        }
  289|       |
  290|    273|        rc = SSH_PACKET_ALLOWED;
  291|    273|        break;
  292|    546|    case SSH2_MSG_KEXINIT:                            // 20
  ------------------
  |  |   12|    546|#define SSH2_MSG_KEXINIT	 20
  ------------------
  |  Branch (292:5): [True: 546, False: 4.09k]
  ------------------
  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|    546|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATED) &&
  ------------------
  |  Branch (310:13): [True: 546, False: 0]
  ------------------
  311|    546|            (session->session_state != SSH_SESSION_STATE_INITIAL_KEX))
  ------------------
  |  Branch (311:13): [True: 0, False: 546]
  ------------------
  312|      0|        {
  313|      0|            rc = SSH_PACKET_DENIED;
  314|      0|            break;
  315|      0|        }
  316|       |
  317|    546|        if ((session->dh_handshake_state != DH_STATE_INIT) &&
  ------------------
  |  Branch (317:13): [True: 0, False: 546]
  ------------------
  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|    546|        rc = SSH_PACKET_ALLOWED;
  327|    546|        break;
  328|    546|    case SSH2_MSG_NEWKEYS:                            // 21
  ------------------
  |  |   13|    546|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (328:5): [True: 546, False: 4.09k]
  ------------------
  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|    546|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (342:13): [True: 0, False: 546]
  ------------------
  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|    546|        if (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (348:13): [True: 0, False: 546]
  ------------------
  349|      0|            rc = SSH_PACKET_DENIED;
  350|      0|            break;
  351|      0|        }
  352|       |
  353|    546|        rc = SSH_PACKET_ALLOWED;
  354|    546|        break;
  355|    273|    case SSH2_MSG_KEXDH_INIT:                         // 30
  ------------------
  |  |   15|    273|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (355:5): [True: 273, False: 4.36k]
  ------------------
  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|    273|        if (session->client) {
  ------------------
  |  Branch (373:13): [True: 0, False: 273]
  ------------------
  374|      0|            rc = SSH_PACKET_DENIED;
  375|      0|            break;
  376|      0|        }
  377|       |
  378|    273|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (378:13): [True: 0, False: 273]
  ------------------
  379|      0|            rc = SSH_PACKET_DENIED;
  380|      0|            break;
  381|      0|        }
  382|       |
  383|       |        /* Only allowed if dh_handshake_state is in initial state */
  384|    273|        if (session->dh_handshake_state != DH_STATE_INIT) {
  ------------------
  |  Branch (384:13): [True: 0, False: 273]
  ------------------
  385|      0|            rc = SSH_PACKET_DENIED;
  386|      0|            break;
  387|      0|        }
  388|       |
  389|    273|        rc = SSH_PACKET_ALLOWED;
  390|    273|        break;
  391|    273|    case SSH2_MSG_KEXDH_REPLY:                        // 31
  ------------------
  |  |   16|    273|#define SSH2_MSG_KEXDH_REPLY 31
  ------------------
  |  Branch (391:5): [True: 273, False: 4.36k]
  ------------------
  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|    273|        if (session->server) {
  ------------------
  |  Branch (408:13): [True: 0, False: 273]
  ------------------
  409|      0|            rc = SSH_PACKET_DENIED;
  410|      0|            break;
  411|      0|        }
  412|       |
  413|    273|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (413:13): [True: 0, False: 273]
  ------------------
  414|      0|            rc = SSH_PACKET_DENIED;
  415|      0|            break;
  416|      0|        }
  417|       |
  418|    273|        if (session->dh_handshake_state != DH_STATE_INIT_SENT &&
  ------------------
  |  Branch (418:13): [True: 0, False: 273]
  ------------------
  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|    273|        rc = SSH_PACKET_ALLOWED;
  425|    273|        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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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|    273|    case SSH2_MSG_USERAUTH_REQUEST:                   // 50
  ------------------
  |  |   36|    273|#define SSH2_MSG_USERAUTH_REQUEST 50
  ------------------
  |  Branch (553:5): [True: 273, False: 4.36k]
  ------------------
  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|    273|        if (session->client) {
  ------------------
  |  Branch (567:13): [True: 0, False: 273]
  ------------------
  568|      0|            rc = SSH_PACKET_DENIED;
  569|      0|            break;
  570|      0|        }
  571|       |
  572|    273|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (572:13): [True: 0, False: 273]
  ------------------
  573|      0|            rc = SSH_PACKET_DENIED;
  574|      0|            break;
  575|      0|        }
  576|       |
  577|    273|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (577:13): [True: 0, False: 273]
  ------------------
  578|      0|            rc = SSH_PACKET_DENIED;
  579|      0|            break;
  580|      0|        }
  581|       |
  582|    273|        rc = SSH_PACKET_ALLOWED;
  583|    273|        break;
  584|      0|    case SSH2_MSG_USERAUTH_FAILURE:                   // 51
  ------------------
  |  |   37|      0|#define SSH2_MSG_USERAUTH_FAILURE 51
  ------------------
  |  Branch (584:5): [True: 0, False: 4.64k]
  ------------------
  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|    273|    case SSH2_MSG_USERAUTH_SUCCESS:                   // 52
  ------------------
  |  |   38|    273|#define SSH2_MSG_USERAUTH_SUCCESS 52
  ------------------
  |  Branch (622:5): [True: 273, False: 4.36k]
  ------------------
  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|    273|        if (session->server) {
  ------------------
  |  Branch (642:13): [True: 0, False: 273]
  ------------------
  643|      0|            rc = SSH_PACKET_DENIED;
  644|      0|            break;
  645|      0|        }
  646|       |
  647|    273|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (647:13): [True: 0, False: 273]
  ------------------
  648|      0|            rc = SSH_PACKET_DENIED;
  649|      0|            break;
  650|      0|        }
  651|       |
  652|    273|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (652:13): [True: 0, False: 273]
  ------------------
  653|      0|            rc = SSH_PACKET_DENIED;
  654|      0|            break;
  655|      0|        }
  656|       |
  657|    273|        if ((session->auth.state != SSH_AUTH_STATE_KBDINT_SENT) &&
  ------------------
  |  Branch (657:13): [True: 273, False: 0]
  ------------------
  658|    273|            (session->auth.state != SSH_AUTH_STATE_PUBKEY_AUTH_SENT) &&
  ------------------
  |  Branch (658:13): [True: 273, False: 0]
  ------------------
  659|    273|            (session->auth.state != SSH_AUTH_STATE_PASSWORD_AUTH_SENT) &&
  ------------------
  |  Branch (659:13): [True: 273, False: 0]
  ------------------
  660|    273|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_MIC_SENT) &&
  ------------------
  |  Branch (660:13): [True: 273, False: 0]
  ------------------
  661|    273|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_KEYEX_MIC_SENT) &&
  ------------------
  |  Branch (661:13): [True: 273, False: 0]
  ------------------
  662|    273|            (session->auth.state != SSH_AUTH_STATE_AUTH_NONE_SENT)) {
  ------------------
  |  Branch (662:13): [True: 0, False: 273]
  ------------------
  663|      0|            rc = SSH_PACKET_DENIED;
  664|      0|            break;
  665|      0|        }
  666|       |
  667|    273|        rc = SSH_PACKET_ALLOWED;
  668|    273|        break;
  669|      0|    case SSH2_MSG_USERAUTH_BANNER:                    // 53
  ------------------
  |  |   39|      0|#define SSH2_MSG_USERAUTH_BANNER 53
  ------------------
  |  Branch (669:5): [True: 0, False: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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|    273|    case SSH2_MSG_CHANNEL_OPEN:                       // 90
  ------------------
  |  |   54|    273|#define SSH2_MSG_CHANNEL_OPEN 90
  ------------------
  |  Branch (927:5): [True: 273, False: 4.36k]
  ------------------
  928|       |        /*
  929|       |         * States required:
  930|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  931|       |         *
  932|       |         * Transitions:
  933|       |         * - None
  934|       |         * */
  935|       |
  936|    273|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (936:13): [True: 0, False: 273]
  ------------------
  937|      0|            rc = SSH_PACKET_DENIED;
  938|      0|            break;
  939|      0|        }
  940|       |
  941|    273|        rc = SSH_PACKET_ALLOWED;
  942|    273|        break;
  943|    273|    case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION:          // 91
  ------------------
  |  |   55|    273|#define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
  ------------------
  |  Branch (943:5): [True: 273, False: 4.36k]
  ------------------
  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|    273|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (953:13): [True: 0, False: 273]
  ------------------
  954|      0|            rc = SSH_PACKET_DENIED;
  955|      0|            break;
  956|      0|        }
  957|       |
  958|    273|        rc = SSH_PACKET_ALLOWED;
  959|    273|        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: 4.64k]
  ------------------
  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: 4.64k]
  ------------------
  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|    273|    case SSH2_MSG_CHANNEL_DATA:                       // 94
  ------------------
  |  |   58|    273|#define SSH2_MSG_CHANNEL_DATA 94
  ------------------
  |  Branch (992:5): [True: 273, False: 4.36k]
  ------------------
  993|       |        /*
  994|       |         * States required:
  995|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  996|       |         *
  997|       |         * Transitions:
  998|       |         * - None
  999|       |         * */
 1000|       |
 1001|    273|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1001:13): [True: 0, False: 273]
  ------------------
 1002|      0|            rc = SSH_PACKET_DENIED;
 1003|      0|            break;
 1004|      0|        }
 1005|       |
 1006|    273|        rc = SSH_PACKET_ALLOWED;
 1007|    273|        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: 4.64k]
  ------------------
 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|    273|    case SSH2_MSG_CHANNEL_EOF:                        // 96
  ------------------
  |  |   60|    273|#define SSH2_MSG_CHANNEL_EOF	96
  ------------------
  |  Branch (1024:5): [True: 273, False: 4.36k]
  ------------------
 1025|       |        /*
 1026|       |         * States required:
 1027|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1028|       |         *
 1029|       |         * Transitions:
 1030|       |         * - None
 1031|       |         * */
 1032|       |
 1033|    273|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1033:13): [True: 0, False: 273]
  ------------------
 1034|      0|            rc = SSH_PACKET_DENIED;
 1035|      0|            break;
 1036|      0|        }
 1037|       |
 1038|    273|        rc = SSH_PACKET_ALLOWED;
 1039|    273|        break;
 1040|    273|    case SSH2_MSG_CHANNEL_CLOSE:                      // 97
  ------------------
  |  |   61|    273|#define SSH2_MSG_CHANNEL_CLOSE 97
  ------------------
  |  Branch (1040:5): [True: 273, False: 4.36k]
  ------------------
 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|    273|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1050:13): [True: 0, False: 273]
  ------------------
 1051|      0|            rc = SSH_PACKET_DENIED;
 1052|      0|            break;
 1053|      0|        }
 1054|       |
 1055|    273|        rc = SSH_PACKET_ALLOWED;
 1056|    273|        break;
 1057|    273|    case SSH2_MSG_CHANNEL_REQUEST:                    // 98
  ------------------
  |  |   62|    273|#define SSH2_MSG_CHANNEL_REQUEST 98
  ------------------
  |  Branch (1057:5): [True: 273, False: 4.36k]
  ------------------
 1058|       |        /*
 1059|       |         * States required:
 1060|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1061|       |         *
 1062|       |         * Transitions:
 1063|       |         * - Depends on the request
 1064|       |         * */
 1065|       |
 1066|    273|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1066:13): [True: 0, False: 273]
  ------------------
 1067|      0|            rc = SSH_PACKET_DENIED;
 1068|      0|            break;
 1069|      0|        }
 1070|       |
 1071|    273|        rc = SSH_PACKET_ALLOWED;
 1072|    273|        break;
 1073|      0|    case SSH2_MSG_CHANNEL_SUCCESS:                    // 99
  ------------------
  |  |   63|      0|#define SSH2_MSG_CHANNEL_SUCCESS 99
  ------------------
  |  Branch (1073:5): [True: 0, False: 4.64k]
  ------------------
 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|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1085:13): [True: 0, False: 0]
  ------------------
 1086|      0|            rc = SSH_PACKET_DENIED;
 1087|      0|            break;
 1088|      0|        }
 1089|       |
 1090|      0|        rc = SSH_PACKET_ALLOWED;
 1091|      0|        break;
 1092|      0|    case SSH2_MSG_CHANNEL_FAILURE:                    // 100
  ------------------
  |  |   64|      0|#define SSH2_MSG_CHANNEL_FAILURE 100
  ------------------
  |  Branch (1092:5): [True: 0, False: 4.64k]
  ------------------
 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: 4.64k]
  ------------------
 1112|      0|    case SSH2_MSG_PONG: // 193
  ------------------
  |  |   70|      0|#define SSH2_MSG_PONG 193
  ------------------
  |  Branch (1112:5): [True: 0, False: 4.64k]
  ------------------
 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: 4.64k]
  ------------------
 1130|       |        /* Unknown message, do not filter */
 1131|      0|        rc = SSH_PACKET_UNKNOWN;
 1132|      0|        goto end;
 1133|  4.64k|    }
 1134|       |
 1135|  4.64k|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|  4.64k|    return rc;
 1149|  4.64k|}
packet.c:ssh_packet_need_rekey:
 1201|  10.0k|{
 1202|  10.0k|    bool data_rekey_needed = false;
 1203|  10.0k|    struct ssh_crypto_struct *crypto = NULL;
 1204|  10.0k|    struct ssh_cipher_struct *out_cipher = NULL, *in_cipher = NULL;
 1205|  10.0k|    uint32_t next_blocks;
 1206|       |
 1207|       |    /* We can safely rekey only in authenticated state */
 1208|  10.0k|    if ((session->flags & SSH_SESSION_FLAG_AUTHENTICATED) == 0) {
  ------------------
  |  |   78|  10.0k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (1208:9): [True: 5.46k, False: 4.63k]
  ------------------
 1209|  5.46k|        return false;
 1210|  5.46k|    }
 1211|       |
 1212|       |    /* Do not rekey if the rekey/key-exchange is in progress */
 1213|  4.63k|    if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (1213:9): [True: 0, False: 4.63k]
  ------------------
 1214|      0|        return false;
 1215|      0|    }
 1216|       |
 1217|  4.63k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_BOTH);
 1218|  4.63k|    if (crypto == NULL) {
  ------------------
  |  Branch (1218:9): [True: 0, False: 4.63k]
  ------------------
 1219|      0|        return false;
 1220|      0|    }
 1221|       |
 1222|  4.63k|    out_cipher = crypto->out_cipher;
 1223|  4.63k|    in_cipher = crypto->in_cipher;
 1224|       |
 1225|       |    /* Make sure we can send at least something for very small limits */
 1226|  4.63k|    if ((out_cipher->packets == 0) && (in_cipher->packets == 0)) {
  ------------------
  |  Branch (1226:9): [True: 0, False: 4.63k]
  |  Branch (1226:39): [True: 0, False: 0]
  ------------------
 1227|      0|        return false;
 1228|      0|    }
 1229|       |
 1230|       |    /* Time based rekeying */
 1231|  4.63k|    if (session->opts.rekey_time != 0 &&
  ------------------
  |  Branch (1231:9): [True: 0, False: 4.63k]
  ------------------
 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|  4.63k|    if (out_cipher->packets > MAX_PACKETS ||
  ------------------
  |  | 1197|  9.27k|#define MAX_PACKETS    (1UL<<31)
  ------------------
  |  Branch (1240:9): [True: 18.4E, False: 4.63k]
  ------------------
 1241|  4.63k|        in_cipher->packets > MAX_PACKETS) {
  ------------------
  |  | 1197|  4.63k|#define MAX_PACKETS    (1UL<<31)
  ------------------
  |  Branch (1241:9): [True: 1, False: 4.63k]
  ------------------
 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|  4.63k|    next_blocks = payloadsize / out_cipher->blocksize;
 1251|  4.63k|    data_rekey_needed = (out_cipher->max_blocks != 0 &&
  ------------------
  |  Branch (1251:26): [True: 4.63k, False: 0]
  ------------------
 1252|  4.63k|                         out_cipher->blocks + next_blocks > out_cipher->max_blocks) ||
  ------------------
  |  Branch (1252:26): [True: 0, False: 4.63k]
  ------------------
 1253|  4.63k|                         (in_cipher->max_blocks != 0 &&
  ------------------
  |  Branch (1253:27): [True: 4.63k, False: 0]
  ------------------
 1254|  4.63k|                         in_cipher->blocks + next_blocks > in_cipher->max_blocks);
  ------------------
  |  Branch (1254:26): [True: 0, False: 4.63k]
  ------------------
 1255|       |
 1256|  4.63k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  4.63k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1257|  4.63k|            "rekey: [data_rekey_needed=%d, out_blocks=%" PRIu64 ", in_blocks=%" PRIu64 "]",
 1258|  4.63k|            data_rekey_needed,
 1259|  4.63k|            out_cipher->blocks + next_blocks,
 1260|  4.63k|            in_cipher->blocks + next_blocks);
 1261|       |
 1262|  4.63k|    return data_rekey_needed;
 1263|  4.63k|}
packet.c:ssh_packet_socket_controlflow_callback:
 1653|  3.16k|{
 1654|  3.16k|    ssh_session session = userdata;
 1655|  3.16k|    struct ssh_iterator *it = NULL;
 1656|  3.16k|    ssh_channel channel = NULL;
 1657|       |
 1658|  3.16k|    if (code == SSH_SOCKET_FLOW_WRITEWONTBLOCK) {
  ------------------
  |  |  518|  3.16k|#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
  ------------------
  |  Branch (1658:9): [True: 3.16k, False: 0]
  ------------------
 1659|  3.16k|        SSH_LOG(SSH_LOG_TRACE, "sending channel_write_wontblock callback");
  ------------------
  |  |  281|  3.16k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1660|       |
 1661|       |        /* the out pipe is empty so we can forward this to channels */
 1662|  3.16k|        it = ssh_list_get_iterator(session->channels);
 1663|  3.98k|        while (it != NULL) {
  ------------------
  |  Branch (1663:16): [True: 819, False: 3.16k]
  ------------------
 1664|    819|            channel = ssh_iterator_value(ssh_channel, it);
  ------------------
  |  |  114|    819|  ((type)((iterator)->data))
  ------------------
 1665|       |            ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|    819|    do {                                                      \
  |  |  567|    819|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|    819|        cbtype cb;                                            \
  |  |  569|  1.09k|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 273, False: 819]
  |  |  ------------------
  |  |  570|    273|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  114|    273|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  571|    273|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  547|    273|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|    273|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 273, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 273, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|    273|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 273]
  |  |  |  |  ------------------
  |  |  |  |  550|    273|  )
  |  |  ------------------
  |  |  572|    273|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  573|    273|            i = i->next;                                      \
  |  |  574|    273|        }                                                     \
  |  |  575|    819|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 819]
  |  |  ------------------
  ------------------
 1666|    819|                                       ssh_channel_callbacks,
 1667|    819|                                       channel_write_wontblock_function,
 1668|    819|                                       session,
 1669|    819|                                       channel,
 1670|    819|                                       channel->remote_window);
 1671|    819|            it = it->next;
 1672|    819|        }
 1673|  3.16k|    }
 1674|  3.16k|}
packet.c:ssh_packet_in_rekey:
 2055|  5.46k|{
 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|  5.46k|    return (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) &&
  ------------------
  |  |   78|  5.46k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (2060:12): [True: 2.45k, False: 3.00k]
  ------------------
 2061|  2.45k|           (session->dh_handshake_state != DH_STATE_FINISHED) &&
  ------------------
  |  Branch (2061:12): [True: 0, False: 2.45k]
  ------------------
 2062|      0|           (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT);
  ------------------
  |  Branch (2062:12): [True: 0, False: 0]
  ------------------
 2063|  5.46k|}
packet.c:packet_send2:
 1895|  5.45k|{
 1896|  5.45k|    unsigned int blocksize = 8;
 1897|  5.45k|    unsigned int lenfield_blocksize = 0;
 1898|  5.45k|    enum ssh_hmac_e hmac_type;
 1899|  5.45k|    uint32_t currentlen = ssh_buffer_get_len(session->out_buffer);
 1900|  5.45k|    struct ssh_crypto_struct *crypto = NULL;
 1901|  5.45k|    unsigned char *hmac = NULL;
 1902|  5.45k|    uint8_t padding_data[32] = { 0 };
 1903|  5.45k|    uint8_t padding_size;
 1904|  5.45k|    uint32_t finallen, payloadsize, compsize;
 1905|  5.45k|    uint8_t header[5] = {0};
 1906|  5.45k|    uint8_t type, *payload;
 1907|  5.45k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  5.45k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1908|  5.45k|    bool etm = false;
 1909|  5.45k|    int etm_packet_offset = 0;
 1910|       |
 1911|  5.45k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
 1912|  5.45k|    if (crypto) {
  ------------------
  |  Branch (1912:9): [True: 3.82k, False: 1.63k]
  ------------------
 1913|  3.82k|        blocksize = crypto->out_cipher->blocksize;
 1914|  3.82k|        lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
 1915|  3.82k|        hmac_type = crypto->out_hmac;
 1916|  3.82k|        etm = crypto->out_hmac_etm;
 1917|  3.82k|    } else {
 1918|  1.63k|        hmac_type = session->next_crypto->out_hmac;
 1919|  1.63k|    }
 1920|       |
 1921|  5.45k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 1922|  5.45k|    type = payload[0]; /* type is the first byte of the packet now */
 1923|       |
 1924|  5.45k|    payloadsize = currentlen;
 1925|  5.45k|    if (etm) {
  ------------------
  |  Branch (1925:9): [True: 0, False: 5.45k]
  ------------------
 1926|      0|        etm_packet_offset = sizeof(uint32_t);
 1927|      0|        lenfield_blocksize = 0;
 1928|      0|    }
 1929|       |
 1930|  5.45k|    if (crypto != NULL && crypto->do_compress_out &&
  ------------------
  |  Branch (1930:9): [True: 3.82k, False: 1.63k]
  |  Branch (1930:27): [True: 0, False: 3.82k]
  ------------------
 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|  5.45k|    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|  5.45k|    padding_size = (blocksize - ((blocksize - lenfield_blocksize - etm_packet_offset + currentlen + 5) % blocksize));
 1942|  5.45k|    if (padding_size < 4) {
  ------------------
  |  Branch (1942:9): [True: 1.96k, False: 3.49k]
  ------------------
 1943|  1.96k|        padding_size += blocksize;
 1944|  1.96k|    }
 1945|       |
 1946|  5.45k|    if (crypto != NULL) {
  ------------------
  |  Branch (1946:9): [True: 3.82k, False: 1.63k]
  ------------------
 1947|  3.82k|        int ok;
 1948|       |
 1949|  3.82k|        ok = ssh_get_random(padding_data, padding_size, 0);
 1950|  3.82k|        if (!ok) {
  ------------------
  |  Branch (1950:13): [True: 0, False: 3.82k]
  ------------------
 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|  3.82k|    }
 1955|       |
 1956|  5.45k|    finallen = currentlen - etm_packet_offset + padding_size + 1;
 1957|       |
 1958|  5.45k|    PUSH_BE_U32(header, 0, finallen);
  ------------------
  |  |   89|  5.45k|    (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|  5.45k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  5.45k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  5.45k|    (((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|  5.45k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  5.45k|    (((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|  5.45k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  5.45k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  5.45k|    (((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|  5.45k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  5.45k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1959|  5.45k|    PUSH_BE_U8(header, 4, padding_size);
  ------------------
  |  |   83|  5.45k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  ------------------
  |  |  |  |   31|  5.45k|    (((uint8_t *)(data))[(pos)])
  |  |  ------------------
  ------------------
 1960|       |
 1961|  5.45k|    rc = ssh_buffer_prepend_data(session->out_buffer,
 1962|  5.45k|                                 header,
 1963|  5.45k|                                 sizeof(header));
 1964|  5.45k|    if (rc < 0) {
  ------------------
  |  Branch (1964:9): [True: 0, False: 5.45k]
  ------------------
 1965|      0|        goto error;
 1966|      0|    }
 1967|       |
 1968|  5.45k|    rc = ssh_buffer_add_data(session->out_buffer, padding_data, padding_size);
 1969|  5.45k|    if (rc < 0) {
  ------------------
  |  Branch (1969:9): [True: 0, False: 5.45k]
  ------------------
 1970|      0|        goto error;
 1971|      0|    }
 1972|       |
 1973|  5.45k|#ifdef WITH_PCAP
 1974|  5.45k|    if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1974:9): [True: 0, False: 5.45k]
  ------------------
 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|  5.45k|#endif
 1982|       |
 1983|  5.45k|    hmac = ssh_packet_encrypt(session,
 1984|  5.45k|                              ssh_buffer_get(session->out_buffer),
 1985|  5.45k|                              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|  5.45k|    if (hmac != NULL) {
  ------------------
  |  Branch (1989:9): [True: 3.82k, False: 1.63k]
  ------------------
 1990|  3.82k|        rc = ssh_buffer_add_data(session->out_buffer,
 1991|  3.82k|                                 hmac,
 1992|  3.82k|                                 (uint32_t)hmac_digest_len(hmac_type));
 1993|  3.82k|        if (rc < 0) {
  ------------------
  |  Branch (1993:13): [True: 0, False: 3.82k]
  ------------------
 1994|      0|            goto error;
 1995|      0|        }
 1996|  3.82k|    }
 1997|       |
 1998|  5.45k|    rc = ssh_packet_write(session);
 1999|  5.45k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  5.45k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1999:9): [True: 0, False: 5.45k]
  ------------------
 2000|      0|        goto error;
 2001|      0|    }
 2002|  5.45k|    session->send_seq++;
 2003|  5.45k|    if (crypto != NULL) {
  ------------------
  |  Branch (2003:9): [True: 3.82k, False: 1.63k]
  ------------------
 2004|  3.82k|        struct ssh_cipher_struct *cipher = NULL;
 2005|       |
 2006|  3.82k|        cipher = crypto->out_cipher;
 2007|  3.82k|        cipher->packets++;
 2008|  3.82k|        cipher->blocks += payloadsize / cipher->blocksize;
 2009|  3.82k|    }
 2010|  5.45k|    if (session->raw_counter != NULL) {
  ------------------
  |  Branch (2010:9): [True: 0, False: 5.45k]
  ------------------
 2011|      0|        session->raw_counter->out_bytes += payloadsize;
 2012|      0|        session->raw_counter->out_packets++;
 2013|      0|    }
 2014|       |
 2015|  5.45k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  5.45k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2016|  5.45k|            "packet: wrote [type=%u, len=%" PRIu32 ", padding_size=%hhd, comp=%" PRIu32 ", "
 2017|  5.45k|            "payload=%" PRIu32 "]",
 2018|  5.45k|            type,
 2019|  5.45k|            finallen,
 2020|  5.45k|            padding_size,
 2021|  5.45k|            compsize,
 2022|  5.45k|            payloadsize);
 2023|       |
 2024|  5.45k|    rc = ssh_buffer_reinit(session->out_buffer);
 2025|  5.45k|    if (rc < 0) {
  ------------------
  |  Branch (2025:9): [True: 0, False: 5.45k]
  ------------------
 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|  5.45k|    if (type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  5.45k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2035:9): [True: 546, False: 4.91k]
  ------------------
 2036|    546|        rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_OUT);
 2037|    546|    }
 2038|  5.45k|error:
 2039|  5.45k|    return rc; /* SSH_OK, AGAIN or ERROR */
 2040|  5.45k|}
packet.c:ssh_packet_write:
 1884|  5.46k|static int ssh_packet_write(ssh_session session) {
 1885|  5.46k|  int rc = SSH_ERROR;
  ------------------
  |  |  317|  5.46k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1886|       |
 1887|  5.46k|  rc=ssh_socket_write(session->socket,
 1888|  5.46k|      ssh_buffer_get(session->out_buffer),
 1889|  5.46k|      ssh_buffer_get_len(session->out_buffer));
 1890|       |
 1891|  5.46k|  return rc;
 1892|  5.46k|}
packet.c:ssh_init_rekey_state:
 2240|  1.09k|{
 2241|       |    /* Reset the counters: should be NOOP */
 2242|  1.09k|    cipher->packets = 0;
 2243|  1.09k|    cipher->blocks = 0;
 2244|       |
 2245|       |    /* Default rekey limits for ciphers as specified in RFC4344, Section 3.2 */
 2246|  1.09k|    if (cipher->blocksize >= 16) {
  ------------------
  |  Branch (2246:9): [True: 484, False: 608]
  ------------------
 2247|       |        /* For larger block size (L bits) use maximum of 2**(L/4) blocks */
 2248|    484|        cipher->max_blocks = (uint64_t)1 << (cipher->blocksize*2);
 2249|    608|    } else {
 2250|       |        /* For smaller blocks use limit of 1 GB as recommended in RFC4253 */
 2251|    608|        cipher->max_blocks = ((uint64_t)1 << 30) / cipher->blocksize;
 2252|    608|    }
 2253|       |    /* If we have limit provided by user, use the smaller one */
 2254|  1.09k|    if (session->opts.rekey_data != 0) {
  ------------------
  |  Branch (2254:9): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|  1.09k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2260|  1.09k|            "Set rekey after %" PRIu64 " blocks",
 2261|  1.09k|            cipher->max_blocks);
 2262|  1.09k|}

ssh_packet_newkeys:
  143|    546|{
  144|    546|    ssh_string sig_blob = NULL;
  145|    546|    ssh_signature sig = NULL;
  146|    546|    int rc;
  147|       |
  148|    546|    (void)packet;
  149|    546|    (void)user;
  150|    546|    (void)type;
  151|       |
  152|    546|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_NEWKEYS");
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  153|       |
  154|    546|    if (session->session_state != SSH_SESSION_STATE_DH ||
  ------------------
  |  Branch (154:9): [True: 0, False: 546]
  ------------------
  155|    546|        session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (155:9): [True: 0, False: 546]
  ------------------
  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|    546|    if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|    546|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (164:9): [True: 546, False: 0]
  ------------------
  165|       |        /* reset packet sequence number when running in strict kex mode */
  166|    546|        session->recv_seq = 0;
  167|       |        /* Check that we aren't tainted */
  168|    546|        if (session->flags & SSH_SESSION_FLAG_KEX_TAINTED) {
  ------------------
  |  |   92|    546|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
  |  Branch (168:13): [True: 0, False: 546]
  ------------------
  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|    546|    }
  175|       |
  176|    546|    if (session->server) {
  ------------------
  |  Branch (176:9): [True: 273, False: 273]
  ------------------
  177|       |        /* server things are done in server.c */
  178|    273|        session->dh_handshake_state=DH_STATE_FINISHED;
  179|    273|    } 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|    273|        {
  218|    273|            ssh_key server_key = NULL;
  219|       |
  220|       |            /* client */
  221|       |
  222|       |            /* Verify the host's signature. FIXME do it sooner */
  223|    273|            sig_blob = session->next_crypto->dh_server_signature;
  224|    273|            session->next_crypto->dh_server_signature = NULL;
  225|       |
  226|       |            /* get the server public key */
  227|    273|            server_key = ssh_dh_get_next_server_publickey(session);
  228|    273|            if (server_key == NULL) {
  ------------------
  |  Branch (228:17): [True: 0, False: 273]
  ------------------
  229|      0|                goto error;
  230|      0|            }
  231|       |
  232|    273|            rc = ssh_pki_import_signature_blob(sig_blob, server_key, &sig);
  233|    273|            ssh_string_burn(sig_blob);
  234|    273|            SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  915|    273|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 273, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
  235|    273|            if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (235:17): [True: 0, False: 273]
  ------------------
  236|      0|                goto error;
  237|      0|            }
  238|       |
  239|       |            /* Check if signature from server matches user preferences */
  240|    273|            if (session->opts.wanted_methods[SSH_HOSTKEYS]) {
  ------------------
  |  Branch (240:17): [True: 0, False: 273]
  ------------------
  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|    273|            rc = ssh_pki_signature_verify(session,
  256|    273|                                          sig,
  257|    273|                                          server_key,
  258|    273|                                          session->next_crypto->secret_hash,
  259|    273|                                          session->next_crypto->digest_len);
  260|    273|            SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|    273|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 273]
  |  |  ------------------
  ------------------
  261|    273|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (261:17): [True: 0, False: 273]
  ------------------
  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|    273|        }
  268|    273|        SSH_LOG(SSH_LOG_DEBUG, "Signature verified and valid");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  269|       |
  270|       |        /* When receiving this packet, we switch on the incoming crypto. */
  271|    273|        rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_IN);
  272|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (272:13): [True: 0, False: 273]
  ------------------
  273|      0|            goto error;
  274|      0|        }
  275|    273|    }
  276|    546|    session->dh_handshake_state = DH_STATE_FINISHED;
  277|    546|    session->ssh_connection_callback(session);
  278|    546|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    546|#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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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|    546|}
ssh_packet_service_accept:
  297|    273|{
  298|    273|    (void)packet;
  299|    273|    (void)type;
  300|    273|    (void)user;
  301|       |
  302|    273|    session->auth.service_state = SSH_AUTH_SERVICE_ACCEPTED;
  303|    273|    SSH_LOG(SSH_LOG_PACKET, "Received SSH_MSG_SERVICE_ACCEPT");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  304|       |
  305|    273|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    273|#define SSH_PACKET_USED 1
  ------------------
  306|    273|}
ssh_packet_ext_info:
  314|    273|{
  315|    273|    int rc;
  316|    273|    uint32_t nr_extensions = 0;
  317|    273|    uint32_t i;
  318|       |
  319|    273|    (void)type;
  320|    273|    (void)user;
  321|       |
  322|    273|    SSH_LOG(SSH_LOG_PACKET, "Received SSH_MSG_EXT_INFO");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  323|       |
  324|    273|    rc = ssh_buffer_get_u32(packet, &nr_extensions);
  325|    273|    if (rc == 0) {
  ------------------
  |  Branch (325:9): [True: 0, False: 273]
  ------------------
  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|    273|    nr_extensions = ntohl(nr_extensions);
  331|    273|    if (nr_extensions > 128) {
  ------------------
  |  Branch (331:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_PACKET, "Follows %" PRIu32 " extensions", nr_extensions);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  337|       |
  338|  1.09k|    for (i = 0; i < nr_extensions; i++) {
  ------------------
  |  Branch (338:17): [True: 819, False: 273]
  ------------------
  339|    819|        char *name = NULL;
  340|    819|        char *value = NULL;
  341|       |
  342|    819|        rc = ssh_buffer_unpack(packet, "ss", &name, &value);
  ------------------
  |  |   60|    819|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    819|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    819|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    819|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    819|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    819|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    819|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  343|    819|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    819|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (343:13): [True: 0, False: 819]
  ------------------
  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|    819|        if (strcmp(name, "server-sig-algs") == 0) {
  ------------------
  |  Branch (348:13): [True: 273, False: 546]
  ------------------
  349|       |            /* TODO check for NULL bytes */
  350|    273|            SSH_LOG(SSH_LOG_PACKET, "Extension: %s=<%s>", name, value);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  351|       |
  352|    273|            rc = match_group(value, "rsa-sha2-512");
  353|    273|            if (rc == 1) {
  ------------------
  |  Branch (353:17): [True: 273, False: 0]
  ------------------
  354|    273|                session->extensions |= SSH_EXT_SIG_RSA_SHA512;
  ------------------
  |  |  126|    273|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  355|    273|            }
  356|       |
  357|    273|            rc = match_group(value, "rsa-sha2-256");
  358|    273|            if (rc == 1) {
  ------------------
  |  Branch (358:17): [True: 273, False: 0]
  ------------------
  359|    273|                session->extensions |= SSH_EXT_SIG_RSA_SHA256;
  ------------------
  |  |  125|    273|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  360|    273|            }
  361|    546|        } else if (strcmp(name, "publickey-hostbound@openssh.com") == 0) {
  ------------------
  |  Branch (361:20): [True: 273, False: 273]
  ------------------
  362|    273|            SSH_LOG(SSH_LOG_PACKET, "Extension: %s=<%s>", name, value);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  363|    273|            session->extensions |= SSH_EXT_PUBLICKEY_HOSTBOUND;
  ------------------
  |  |  128|    273|#define SSH_EXT_PUBLICKEY_HOSTBOUND 0x08
  ------------------
  364|    273|        } else if (strcmp(name, "ping@openssh.com") == 0) {
  ------------------
  |  Branch (364:20): [True: 273, False: 0]
  ------------------
  365|    273|            if (strcmp(value, "0") == 0) {
  ------------------
  |  Branch (365:17): [True: 273, False: 0]
  ------------------
  366|    273|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  367|    273|                        "Extension: %s=<%s> (supported)",
  368|    273|                        name,
  369|    273|                        value);
  370|    273|                session->extensions |= SSH_EXT_PING;
  ------------------
  |  |  130|    273|#define SSH_EXT_PING 0x10
  ------------------
  371|    273|            } 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|    273|        } else {
  378|      0|            SSH_LOG(SSH_LOG_PACKET, "Unknown extension: %s", name);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  379|      0|        }
  380|    819|        free(name);
  381|    819|        free(value);
  382|    819|    }
  383|       |
  384|    273|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    273|#define SSH_PACKET_USED 1
  ------------------
  385|    273|}

ssh_packet_decrypt_len:
   55|  4.64k|{
   56|  4.64k|    struct ssh_crypto_struct *crypto = NULL;
   57|  4.64k|    uint32_t decrypted;
   58|  4.64k|    int rc;
   59|       |
   60|  4.64k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
   61|  4.64k|    if (crypto != NULL) {
  ------------------
  |  Branch (61:9): [True: 3.00k, False: 1.63k]
  ------------------
   62|  3.00k|        if (crypto->in_cipher->aead_decrypt_length != NULL) {
  ------------------
  |  Branch (62:13): [True: 0, False: 3.00k]
  ------------------
   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|  3.00k|        } else {
   68|  3.00k|            rc = ssh_packet_decrypt(
   69|  3.00k|                    session,
   70|  3.00k|                    destination,
   71|  3.00k|                    source,
   72|  3.00k|                    0,
   73|  3.00k|                    crypto->in_cipher->blocksize);
   74|  3.00k|        }
   75|  3.00k|        if (rc < 0) {
  ------------------
  |  Branch (75:13): [True: 0, False: 3.00k]
  ------------------
   76|      0|            return 0;
   77|      0|        }
   78|  3.00k|    } else {
   79|  1.63k|        memcpy(destination, source, 8);
   80|  1.63k|    }
   81|  4.64k|    memcpy(&decrypted,destination,sizeof(decrypted));
   82|       |
   83|       |    return ntohl(decrypted);
   84|  4.64k|}
ssh_packet_decrypt:
   97|  5.64k|{
   98|  5.64k|    struct ssh_crypto_struct *crypto = NULL;
   99|  5.64k|    struct ssh_cipher_struct *cipher = NULL;
  100|       |
  101|  5.64k|    if (encrypted_size <= 0) {
  ------------------
  |  Branch (101:9): [True: 0, False: 5.64k]
  ------------------
  102|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  103|      0|    }
  104|       |
  105|  5.64k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
  106|  5.64k|    if (crypto == NULL) {
  ------------------
  |  Branch (106:9): [True: 0, False: 5.64k]
  ------------------
  107|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  108|      0|    }
  109|  5.64k|    cipher = crypto->in_cipher;
  110|       |
  111|  5.64k|    if (encrypted_size % cipher->blocksize != 0) {
  ------------------
  |  Branch (111:9): [True: 0, False: 5.64k]
  ------------------
  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|  5.64k|    if (cipher->aead_decrypt != NULL) {
  ------------------
  |  Branch (120:9): [True: 0, False: 5.64k]
  ------------------
  121|      0|        return cipher->aead_decrypt(cipher,
  122|      0|                                    source,
  123|      0|                                    destination,
  124|      0|                                    encrypted_size,
  125|      0|                                    session->recv_seq);
  126|  5.64k|    } else {
  127|  5.64k|        cipher->decrypt(cipher, source + start, destination, encrypted_size);
  128|  5.64k|    }
  129|       |
  130|  5.64k|    return 0;
  131|  5.64k|}
ssh_packet_encrypt:
  134|  5.46k|{
  135|  5.46k|  struct ssh_crypto_struct *crypto = NULL;
  136|  5.46k|  struct ssh_cipher_struct *cipher = NULL;
  137|  5.46k|  HMACCTX ctx = NULL;
  138|  5.46k|  char *out = NULL;
  139|  5.46k|  int etm_packet_offset = 0, rc;
  140|  5.46k|  unsigned int blocksize;
  141|  5.46k|  size_t finallen = DIGEST_MAX_LEN;
  ------------------
  |  |   56|  5.46k|#define DIGEST_MAX_LEN 64
  ------------------
  142|  5.46k|  uint32_t seq, lenfield_blocksize;
  143|  5.46k|  enum ssh_hmac_e type;
  144|  5.46k|  bool etm;
  145|       |
  146|  5.46k|  assert(len);
  ------------------
  |  Branch (146:3): [True: 0, False: 5.46k]
  |  Branch (146:3): [True: 5.46k, False: 0]
  ------------------
  147|       |
  148|  5.46k|  crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
  149|  5.46k|  if (crypto == NULL) {
  ------------------
  |  Branch (149:7): [True: 1.63k, False: 3.82k]
  ------------------
  150|  1.63k|      return NULL; /* nothing to do here */
  151|  1.63k|  }
  152|       |
  153|  3.82k|  blocksize = crypto->out_cipher->blocksize;
  154|  3.82k|  lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
  155|       |
  156|  3.82k|  type = crypto->out_hmac;
  157|  3.82k|  etm = crypto->out_hmac_etm;
  158|       |
  159|  3.82k|  if (etm) {
  ------------------
  |  Branch (159:7): [True: 0, False: 3.82k]
  ------------------
  160|      0|      etm_packet_offset = sizeof(uint32_t);
  161|      0|  }
  162|       |
  163|  3.82k|  if ((len - lenfield_blocksize - etm_packet_offset) % blocksize != 0) {
  ------------------
  |  Branch (163:7): [True: 0, False: 3.82k]
  ------------------
  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|  3.82k|  out = calloc(1, len);
  169|  3.82k|  if (out == NULL) {
  ------------------
  |  Branch (169:7): [True: 0, False: 3.82k]
  ------------------
  170|      0|    return NULL;
  171|      0|  }
  172|       |
  173|  3.82k|  seq = ntohl(session->send_seq);
  174|  3.82k|  cipher = crypto->out_cipher;
  175|       |
  176|  3.82k|  if (cipher->aead_encrypt != NULL) {
  ------------------
  |  Branch (176:7): [True: 0, False: 3.82k]
  ------------------
  177|      0|      cipher->aead_encrypt(cipher, data, out, len,
  178|      0|            crypto->hmacbuf, session->send_seq);
  179|      0|      memcpy(data, out, len);
  180|  3.82k|  } else {
  181|  3.82k|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (181:11): [True: 2.08k, False: 1.73k]
  ------------------
  182|  2.08k|          ctx = hmac_init(crypto->encryptMAC, hmac_digest_len(type), type);
  183|  2.08k|          if (ctx == NULL) {
  ------------------
  |  Branch (183:15): [True: 0, False: 2.08k]
  ------------------
  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|  2.08k|          if (!etm) {
  ------------------
  |  Branch (188:15): [True: 2.08k, False: 0]
  ------------------
  189|  2.08k|              rc = hmac_update(ctx, (unsigned char *)&seq, sizeof(uint32_t));
  190|  2.08k|              if (rc != 1) {
  ------------------
  |  Branch (190:19): [True: 0, False: 2.08k]
  ------------------
  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|  2.08k|              rc = hmac_update(ctx, data, len);
  195|  2.08k|              if (rc != 1) {
  ------------------
  |  Branch (195:19): [True: 0, False: 2.08k]
  ------------------
  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|  2.08k|              rc = hmac_final(ctx, crypto->hmacbuf, &finallen);
  200|  2.08k|              if (rc != 1) {
  ------------------
  |  Branch (200:19): [True: 0, False: 2.08k]
  ------------------
  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|  2.08k|          }
  205|  2.08k|      }
  206|       |
  207|  3.82k|      cipher->encrypt(cipher, (uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  208|  3.82k|      memcpy((uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  209|       |
  210|  3.82k|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (210:11): [True: 2.08k, False: 1.73k]
  ------------------
  211|  2.08k|          if (etm) {
  ------------------
  |  Branch (211:15): [True: 0, False: 2.08k]
  ------------------
  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|  2.08k|      }
  237|  3.82k|  }
  238|  3.82k|  ssh_burn(out, len);
  ------------------
  |  |  388|  3.82k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  239|  3.82k|  SAFE_FREE(out);
  ------------------
  |  |  373|  3.82k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 3.82k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 3.82k]
  |  |  ------------------
  ------------------
  240|       |
  241|  3.82k|  return crypto->hmacbuf;
  242|  3.82k|}
ssh_packet_hmac_verify:
  262|  1.63k|{
  263|  1.63k|    struct ssh_crypto_struct *crypto = NULL;
  264|  1.63k|    unsigned char hmacbuf[DIGEST_MAX_LEN] = {0};
  265|  1.63k|    HMACCTX ctx = NULL;
  266|  1.63k|    size_t hmaclen = DIGEST_MAX_LEN;
  ------------------
  |  |   56|  1.63k|#define DIGEST_MAX_LEN 64
  ------------------
  267|  1.63k|    uint32_t seq;
  268|  1.63k|    int cmp;
  269|  1.63k|    int rc;
  270|       |
  271|       |    /* AEAD types have no mac checking */
  272|  1.63k|    if (type == SSH_HMAC_AEAD_POLY1305 ||
  ------------------
  |  Branch (272:9): [True: 0, False: 1.63k]
  ------------------
  273|  1.63k|        type == SSH_HMAC_AEAD_GCM) {
  ------------------
  |  Branch (273:9): [True: 0, False: 1.63k]
  ------------------
  274|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  275|      0|    }
  276|       |
  277|  1.63k|    crypto = ssh_packet_get_current_crypto(session,
  278|  1.63k|                                           SSH_DIRECTION_IN);
  279|  1.63k|    if (crypto == NULL) {
  ------------------
  |  Branch (279:9): [True: 0, False: 1.63k]
  ------------------
  280|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  281|      0|    }
  282|       |
  283|  1.63k|    ctx = hmac_init(crypto->decryptMAC,
  284|  1.63k|                    hmac_digest_len(type),
  285|  1.63k|                    type);
  286|  1.63k|    if (ctx == NULL) {
  ------------------
  |  Branch (286:9): [True: 0, False: 1.63k]
  ------------------
  287|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  288|      0|    }
  289|       |
  290|  1.63k|    seq = htonl(session->recv_seq);
  291|       |
  292|  1.63k|    rc = hmac_update(ctx,
  293|  1.63k|                     (unsigned char *) &seq,
  294|  1.63k|                     sizeof(uint32_t));
  295|  1.63k|    if (rc != 1) {
  ------------------
  |  Branch (295:9): [True: 0, False: 1.63k]
  ------------------
  296|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  297|      0|    }
  298|  1.63k|    rc = hmac_update(ctx,
  299|  1.63k|                     data,
  300|  1.63k|                     len);
  301|  1.63k|    if (rc != 1) {
  ------------------
  |  Branch (301:9): [True: 0, False: 1.63k]
  ------------------
  302|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  303|      0|    }
  304|  1.63k|    rc = hmac_final(ctx,
  305|  1.63k|                    hmacbuf,
  306|  1.63k|                    &hmaclen);
  307|  1.63k|    if (rc != 1) {
  ------------------
  |  Branch (307:9): [True: 0, False: 1.63k]
  ------------------
  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|  1.63k|    cmp = secure_memcmp(mac,
  323|  1.63k|                        hmacbuf,
  324|  1.63k|                        hmaclen);
  325|  1.63k|    if (cmp == 0) {
  ------------------
  |  Branch (325:9): [True: 1.63k, False: 0]
  ------------------
  326|  1.63k|        return SSH_OK;
  ------------------
  |  |  316|  1.63k|#define SSH_OK 0     /* No error */
  ------------------
  327|  1.63k|    }
  328|       |
  329|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  330|  1.63k|}

ssh_key_new:
  113|  1.36k|{
  114|  1.36k|    ssh_key ptr = malloc (sizeof (struct ssh_key_struct));
  115|  1.36k|    if (ptr == NULL) {
  ------------------
  |  Branch (115:9): [True: 0, False: 1.36k]
  ------------------
  116|      0|        return NULL;
  117|      0|    }
  118|  1.36k|    ZERO_STRUCTP(ptr);
  ------------------
  |  |  379|  1.36k|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (379:34): [True: 1.36k, False: 0]
  |  |  |  Branch (379:85): [Folded, False: 1.36k]
  |  |  ------------------
  ------------------
  119|  1.36k|    return ptr;
  120|  1.36k|}
pki_key_dup_common_init:
  145|    546|{
  146|    546|    ssh_key new = NULL;
  147|       |
  148|    546|    if (key == NULL) {
  ------------------
  |  Branch (148:9): [True: 0, False: 546]
  ------------------
  149|      0|        return NULL;
  150|      0|    }
  151|       |
  152|    546|    new = ssh_key_new();
  153|    546|    if (new == NULL) {
  ------------------
  |  Branch (153:9): [True: 0, False: 546]
  ------------------
  154|      0|        return NULL;
  155|      0|    }
  156|       |
  157|    546|    new->type = key->type;
  158|    546|    new->type_c = key->type_c;
  159|    546|    if (demote) {
  ------------------
  |  Branch (159:9): [True: 273, False: 273]
  ------------------
  160|    273|        new->flags = SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   54|    273|#define SSH_KEY_FLAG_PUBLIC  0x0001
  ------------------
  161|    273|    } else {
  162|    273|        new->flags = key->flags;
  163|    273|    }
  164|       |
  165|       |    /* Copy security key fields if present */
  166|    546|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|    546|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 0, False: 546]
  |  |  |  Branch (153:38): [True: 0, False: 546]
  |  |  ------------------
  |  |  154|    546|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 546]
  |  |  ------------------
  |  |  155|    546|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 546]
  |  |  ------------------
  ------------------
  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|    546|    return new;
  195|       |
  196|      0|fail:
  197|      0|    SSH_KEY_FREE(new);
  ------------------
  |  |  774|      0|    do { if ((x) != NULL) { ssh_key_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (774:14): [True: 0, False: 0]
  |  |  |  Branch (774:66): [Folded, False: 0]
  |  |  ------------------
  ------------------
  198|       |    return NULL;
  199|    546|}
ssh_key_dup:
  209|    273|{
  210|    273|    if (key == NULL) {
  ------------------
  |  Branch (210:9): [True: 0, False: 273]
  ------------------
  211|      0|        return NULL;
  212|      0|    }
  213|       |
  214|    273|    return pki_key_dup(key, 0);
  215|    273|}
ssh_key_clean:
  222|  1.36k|{
  223|  1.36k|    if (key == NULL)
  ------------------
  |  Branch (223:9): [True: 0, False: 1.36k]
  ------------------
  224|      0|        return;
  225|       |
  226|  1.36k|    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|  1.36k|    if (key->cert != NULL) {
  ------------------
  |  Branch (235:9): [True: 0, False: 1.36k]
  ------------------
  236|      0|        SSH_BUFFER_FREE(key->cert);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  237|      0|    }
  238|  1.36k|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|  1.36k|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 0, False: 1.36k]
  |  |  |  Branch (153:38): [True: 0, False: 1.36k]
  |  |  ------------------
  |  |  154|  1.36k|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 1.36k]
  |  |  ------------------
  |  |  155|  1.36k|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 1.36k]
  |  |  ------------------
  ------------------
  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|  1.36k|    key->cert_type = SSH_KEYTYPE_UNKNOWN;
  250|  1.36k|    key->flags = SSH_KEY_FLAG_EMPTY;
  ------------------
  |  |   53|  1.36k|#define SSH_KEY_FLAG_EMPTY   0x0
  ------------------
  251|  1.36k|    key->type = SSH_KEYTYPE_UNKNOWN;
  252|  1.36k|    key->ecdsa_nid = 0;
  253|       |    key->type_c = NULL;
  254|  1.36k|}
ssh_key_free:
  261|  5.18k|{
  262|  5.18k|    if (key) {
  ------------------
  |  Branch (262:9): [True: 1.36k, False: 3.82k]
  ------------------
  263|  1.36k|        ssh_key_clean(key);
  264|       |        SAFE_FREE(key);
  ------------------
  |  |  373|  1.36k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.36k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.36k]
  |  |  ------------------
  ------------------
  265|  1.36k|    }
  266|  5.18k|}
ssh_key_type:
  280|  1.36k|{
  281|  1.36k|    if (key == NULL) {
  ------------------
  |  Branch (281:9): [True: 0, False: 1.36k]
  ------------------
  282|      0|        return SSH_KEYTYPE_UNKNOWN;
  283|      0|    }
  284|  1.36k|    return key->type;
  285|  1.36k|}
ssh_key_signature_to_char:
  367|    546|{
  368|    546|    switch (type) {
  369|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (369:5): [True: 0, False: 546]
  ------------------
  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: 546]
  ------------------
  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|    546|    default:
  ------------------
  |  Branch (395:5): [True: 546, False: 0]
  ------------------
  396|    546|        return ssh_key_type_to_char(type);
  397|    546|    }
  398|       |
  399|       |    /* We should never reach this */
  400|      0|    return NULL;
  401|    546|}
ssh_key_type_to_char:
  410|  1.63k|const char *ssh_key_type_to_char(enum ssh_keytypes_e type) {
  411|  1.63k|  switch (type) {
  ------------------
  |  Branch (411:11): [True: 1.63k, False: 0]
  ------------------
  412|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (412:5): [True: 0, False: 1.63k]
  ------------------
  413|      0|      return "ssh-rsa";
  414|      0|    case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (414:5): [True: 0, False: 1.63k]
  ------------------
  415|      0|      return "ssh-ecdsa"; /* deprecated. invalid value */
  416|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (416:5): [True: 0, False: 1.63k]
  ------------------
  417|      0|      return "ecdsa-sha2-nistp256";
  418|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (418:5): [True: 0, False: 1.63k]
  ------------------
  419|      0|      return "ecdsa-sha2-nistp384";
  420|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (420:5): [True: 0, False: 1.63k]
  ------------------
  421|      0|      return "ecdsa-sha2-nistp521";
  422|  1.63k|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (422:5): [True: 1.63k, False: 0]
  ------------------
  423|  1.63k|      return "ssh-ed25519";
  424|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (424:5): [True: 0, False: 1.63k]
  ------------------
  425|      0|      return "ssh-rsa-cert-v01@openssh.com";
  426|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (426:5): [True: 0, False: 1.63k]
  ------------------
  427|      0|      return "ecdsa-sha2-nistp256-cert-v01@openssh.com";
  428|      0|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (428:5): [True: 0, False: 1.63k]
  ------------------
  429|      0|      return "ecdsa-sha2-nistp384-cert-v01@openssh.com";
  430|      0|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (430:5): [True: 0, False: 1.63k]
  ------------------
  431|      0|      return "ecdsa-sha2-nistp521-cert-v01@openssh.com";
  432|      0|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (432:5): [True: 0, False: 1.63k]
  ------------------
  433|      0|      return "ssh-ed25519-cert-v01@openssh.com";
  434|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (434:5): [True: 0, False: 1.63k]
  ------------------
  435|      0|      return "sk-ecdsa-sha2-nistp256@openssh.com";
  436|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (436:5): [True: 0, False: 1.63k]
  ------------------
  437|      0|      return "sk-ssh-ed25519@openssh.com";
  438|      0|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (438:5): [True: 0, False: 1.63k]
  ------------------
  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: 1.63k]
  ------------------
  441|      0|      return "sk-ssh-ed25519-cert-v01@openssh.com";
  442|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (442:5): [True: 0, False: 1.63k]
  ------------------
  443|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (443:5): [True: 0, False: 1.63k]
  ------------------
  444|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (444:5): [True: 0, False: 1.63k]
  ------------------
  445|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (445:5): [True: 0, False: 1.63k]
  ------------------
  446|      0|      return NULL;
  447|  1.63k|  }
  448|       |
  449|       |  /* We should never reach this */
  450|      0|  return NULL;
  451|  1.63k|}
ssh_key_type_and_hash_from_signature_name:
  472|    546|{
  473|    546|    size_t len;
  474|       |
  475|    546|    if (name == NULL || type == NULL || hash_type == NULL) {
  ------------------
  |  Branch (475:9): [True: 0, False: 546]
  |  Branch (475:25): [True: 0, False: 546]
  |  Branch (475:41): [True: 0, False: 546]
  ------------------
  476|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  477|      0|    }
  478|       |
  479|    546|    len = strlen(name);
  480|       |
  481|    546|    if (len == 7 && strcmp(name, "ssh-rsa") == 0) {
  ------------------
  |  Branch (481:9): [True: 0, False: 546]
  |  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|    546|    if (len == 11 && strcmp(name, "ssh-ed25519") == 0) {
  ------------------
  |  Branch (487:9): [True: 546, False: 0]
  |  Branch (487:22): [True: 546, False: 0]
  ------------------
  488|    546|        *type = SSH_KEYTYPE_ED25519;
  489|    546|        *hash_type = SSH_DIGEST_AUTO;
  490|    546|        return SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  491|    546|    }
  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|    546|{
  647|    546|    int min_size = 0;
  648|       |
  649|    546|    switch (ssh_key_type(key)) {
  650|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (650:5): [True: 0, False: 546]
  ------------------
  651|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (651:5): [True: 0, False: 546]
  ------------------
  652|      0|        min_size = session->opts.rsa_min_size;
  653|      0|        return ssh_key_size_allowed_rsa(min_size, key);
  654|    546|    default:
  ------------------
  |  Branch (654:5): [True: 546, False: 0]
  ------------------
  655|       |        return true;
  656|    546|    }
  657|    546|}
ssh_key_type_from_name:
  808|    819|{
  809|    819|    if (name == NULL) {
  ------------------
  |  Branch (809:9): [True: 0, False: 819]
  ------------------
  810|      0|        return SSH_KEYTYPE_UNKNOWN;
  811|      0|    }
  812|       |
  813|    819|    if (strcmp(name, "rsa") == 0) {
  ------------------
  |  Branch (813:9): [True: 0, False: 819]
  ------------------
  814|      0|        return SSH_KEYTYPE_RSA;
  815|    819|    } else if (strcmp(name, "ssh-rsa") == 0) {
  ------------------
  |  Branch (815:16): [True: 0, False: 819]
  ------------------
  816|      0|        return SSH_KEYTYPE_RSA;
  817|    819|    } else if (strcmp(name, "ssh-ecdsa") == 0
  ------------------
  |  Branch (817:16): [True: 0, False: 819]
  ------------------
  818|    819|            || strcmp(name, "ecdsa") == 0
  ------------------
  |  Branch (818:16): [True: 0, False: 819]
  ------------------
  819|    819|            || strcmp(name, "ecdsa-sha2-nistp256") == 0) {
  ------------------
  |  Branch (819:16): [True: 0, False: 819]
  ------------------
  820|      0|        return SSH_KEYTYPE_ECDSA_P256;
  821|    819|    } else if (strcmp(name, "ecdsa-sha2-nistp384") == 0) {
  ------------------
  |  Branch (821:16): [True: 0, False: 819]
  ------------------
  822|      0|        return SSH_KEYTYPE_ECDSA_P384;
  823|    819|    } else if (strcmp(name, "ecdsa-sha2-nistp521") == 0) {
  ------------------
  |  Branch (823:16): [True: 0, False: 819]
  ------------------
  824|      0|        return SSH_KEYTYPE_ECDSA_P521;
  825|    819|    } else if (strcmp(name, "ssh-ed25519") == 0){
  ------------------
  |  Branch (825:16): [True: 819, False: 0]
  ------------------
  826|    819|        return SSH_KEYTYPE_ED25519;
  827|    819|    } 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|    819|}
ssh_key_type_plain:
  858|    546|{
  859|    546|    switch (type) {
  860|      0|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (860:9): [True: 0, False: 546]
  ------------------
  861|      0|            return SSH_KEYTYPE_RSA;
  862|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (862:9): [True: 0, False: 546]
  ------------------
  863|      0|            return SSH_KEYTYPE_ECDSA_P256;
  864|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (864:9): [True: 0, False: 546]
  ------------------
  865|      0|            return SSH_KEYTYPE_ECDSA_P384;
  866|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (866:9): [True: 0, False: 546]
  ------------------
  867|      0|            return SSH_KEYTYPE_ECDSA_P521;
  868|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (868:9): [True: 0, False: 546]
  ------------------
  869|      0|            return SSH_KEYTYPE_ED25519;
  870|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (870:9): [True: 0, False: 546]
  ------------------
  871|      0|            return SSH_KEYTYPE_SK_ECDSA;
  872|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (872:9): [True: 0, False: 546]
  ------------------
  873|      0|            return SSH_KEYTYPE_SK_ED25519;
  874|    546|        default:
  ------------------
  |  Branch (874:9): [True: 546, False: 0]
  ------------------
  875|    546|            return type;
  876|    546|    }
  877|    546|}
ssh_key_is_private:
  902|  1.09k|int ssh_key_is_private(const ssh_key k) {
  903|  1.09k|    if (k == NULL) {
  ------------------
  |  Branch (903:9): [True: 0, False: 1.09k]
  ------------------
  904|      0|        return 0;
  905|      0|    }
  906|       |
  907|  1.09k|    return (k->flags & SSH_KEY_FLAG_PRIVATE) == SSH_KEY_FLAG_PRIVATE;
  ------------------
  |  |   55|  1.09k|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
                  return (k->flags & SSH_KEY_FLAG_PRIVATE) == SSH_KEY_FLAG_PRIVATE;
  ------------------
  |  |   55|  1.09k|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
  908|  1.09k|}
ssh_signature_new:
  997|    546|{
  998|    546|    struct ssh_signature_struct *sig = NULL;
  999|       |
 1000|    546|    sig = calloc(1, sizeof(struct ssh_signature_struct));
 1001|    546|    if (sig == NULL) {
  ------------------
  |  Branch (1001:9): [True: 0, False: 546]
  ------------------
 1002|      0|        return NULL;
 1003|      0|    }
 1004|       |
 1005|    546|    return sig;
 1006|    546|}
ssh_signature_free:
 1009|    546|{
 1010|    546|    if (sig == NULL) {
  ------------------
  |  Branch (1010:9): [True: 0, False: 546]
  ------------------
 1011|      0|        return;
 1012|      0|    }
 1013|       |
 1014|    546|    switch(sig->type) {
  ------------------
  |  Branch (1014:12): [True: 546, False: 0]
  ------------------
 1015|      0|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1015:9): [True: 0, False: 546]
  ------------------
 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: 546]
  ------------------
 1021|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1021:9): [True: 0, False: 546]
  ------------------
 1022|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1022:9): [True: 0, False: 546]
  ------------------
 1023|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1023:9): [True: 0, False: 546]
  ------------------
 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|    546|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1031:9): [True: 546, False: 0]
  ------------------
 1032|    546|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1032:9): [True: 0, False: 546]
  ------------------
 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|    546|            break;
 1038|      0|        case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (1038:9): [True: 0, False: 546]
  ------------------
 1039|      0|        case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (1039:9): [True: 0, False: 546]
  ------------------
 1040|      0|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1040:9): [True: 0, False: 546]
  ------------------
 1041|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1041:9): [True: 0, False: 546]
  ------------------
 1042|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1042:9): [True: 0, False: 546]
  ------------------
 1043|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1043:9): [True: 0, False: 546]
  ------------------
 1044|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1044:9): [True: 0, False: 546]
  ------------------
 1045|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1045:9): [True: 0, False: 546]
  ------------------
 1046|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1046:9): [True: 0, False: 546]
  ------------------
 1047|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1047:9): [True: 0, False: 546]
  ------------------
 1048|      0|        case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (1048:9): [True: 0, False: 546]
  ------------------
 1049|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1049:9): [True: 0, False: 546]
  ------------------
 1050|      0|            break;
 1051|    546|    }
 1052|       |
 1053|       |    /* Explicitly zero the signature content before free */
 1054|    546|    ssh_string_burn(sig->raw_sig);
 1055|    546|    SSH_STRING_FREE(sig->raw_sig);
  ------------------
  |  |  915|    546|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 546, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
 1056|       |    SAFE_FREE(sig);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
 1057|    546|}
ssh_pki_import_privkey_base64:
 1082|    273|{
 1083|    273|    ssh_key key = NULL;
 1084|    273|    const char *openssh_header = NULL;
 1085|       |
 1086|    273|    if (b64_key == NULL || pkey == NULL) {
  ------------------
  |  Branch (1086:9): [True: 0, False: 273]
  |  Branch (1086:28): [True: 0, False: 273]
  ------------------
 1087|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1088|      0|    }
 1089|       |
 1090|    273|    if (b64_key == NULL || !*b64_key) {
  ------------------
  |  Branch (1090:9): [True: 0, False: 273]
  |  Branch (1090:28): [True: 0, False: 273]
  ------------------
 1091|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1092|      0|    }
 1093|       |
 1094|    273|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 273]
  |  |  ------------------
  ------------------
 1095|    273|            "Trying to decode privkey passphrase=%s",
 1096|    273|            passphrase ? "true" : "false");
 1097|       |
 1098|       |    /* Test for OpenSSH key format first */
 1099|    273|    openssh_header = strstr(b64_key, OPENSSH_HEADER_BEGIN);
  ------------------
  |  |   43|    273|#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
  ------------------
 1100|    273|    if (openssh_header != NULL) {
  ------------------
  |  Branch (1100:9): [True: 273, False: 0]
  ------------------
 1101|    273|        key = ssh_pki_openssh_privkey_import(openssh_header,
 1102|    273|                                             passphrase,
 1103|    273|                                             auth_fn,
 1104|    273|                                             auth_data);
 1105|    273|    } 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|    273|    if (key == NULL) {
  ------------------
  |  Branch (1112:9): [True: 0, False: 273]
  ------------------
 1113|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1114|      0|    }
 1115|       |
 1116|    273|    *pkey = key;
 1117|       |
 1118|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
 1119|    273|}
ssh_pki_import_privkey_file:
 1266|    273|                                ssh_key *pkey) {
 1267|    273|    struct stat sb;
 1268|    273|    char *key_buf = NULL;
 1269|    273|    FILE *file = NULL;
 1270|    273|    off_t size;
 1271|    273|    int rc;
 1272|       |
 1273|    273|    if (pkey == NULL || filename == NULL || *filename == '\0') {
  ------------------
  |  Branch (1273:9): [True: 0, False: 273]
  |  Branch (1273:25): [True: 0, False: 273]
  |  Branch (1273:45): [True: 0, False: 273]
  ------------------
 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|    273|    file = fopen(filename, "rb");
 1285|    273|    if (file == NULL) {
  ------------------
  |  Branch (1285:9): [True: 0, False: 273]
  ------------------
 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|    273|    rc = fstat(fileno(file), &sb);
 1294|    273|    if (rc < 0) {
  ------------------
  |  Branch (1294:9): [True: 0, False: 273]
  ------------------
 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|    273|    if (sb.st_size > MAX_PRIVKEY_SIZE) {
  ------------------
  |  |   47|    273|#define MAX_PRIVKEY_SIZE 0x400000 /* 4M */
  ------------------
  |  Branch (1309:9): [True: 0, False: 273]
  ------------------
 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|    273|    key_buf = malloc(sb.st_size + 1);
 1317|    273|    if (key_buf == NULL) {
  ------------------
  |  Branch (1317:9): [True: 0, False: 273]
  ------------------
 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|    273|    size = fread(key_buf, 1, sb.st_size, file);
 1324|    273|    fclose(file);
 1325|       |
 1326|    273|    if (size != sb.st_size) {
  ------------------
  |  Branch (1326:9): [True: 0, False: 273]
  ------------------
 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|    273|    key_buf[size] = 0;
 1335|       |
 1336|    273|    rc = ssh_pki_import_privkey_base64(key_buf,
 1337|    273|                                       passphrase,
 1338|    273|                                       auth_fn,
 1339|    273|                                       auth_data,
 1340|    273|                                       pkey);
 1341|       |
 1342|       |    SAFE_FREE(key_buf);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
 1343|    273|    return rc;
 1344|    273|}
pki_import_privkey_buffer:
 1537|    273|{
 1538|    273|    ssh_key key = NULL;
 1539|    273|    int rc;
 1540|       |
 1541|    273|    key = ssh_key_new();
 1542|    273|    if (key == NULL) {
  ------------------
  |  Branch (1542:9): [True: 0, False: 273]
  ------------------
 1543|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1544|      0|    }
 1545|       |
 1546|    273|    key->type = type;
 1547|    273|    key->type_c = ssh_key_type_to_char(type);
 1548|    273|    key->flags = SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   55|    273|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
                  key->flags = SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   54|    273|#define SSH_KEY_FLAG_PUBLIC  0x0001
  ------------------
 1549|       |
 1550|    273|    switch (type) {
 1551|      0|    case SSH_KEYTYPE_RSA: {
  ------------------
  |  Branch (1551:5): [True: 0, False: 273]
  ------------------
 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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1576|      0|        ssh_string_burn(e);
 1577|      0|        SSH_STRING_FREE(e);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1578|      0|        ssh_string_burn(d);
 1579|      0|        SSH_STRING_FREE(d);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1580|      0|        ssh_string_burn(iqmp);
 1581|      0|        SSH_STRING_FREE(iqmp);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1582|      0|        ssh_string_burn(p);
 1583|      0|        SSH_STRING_FREE(p);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1584|      0|        ssh_string_burn(q);
 1585|      0|        SSH_STRING_FREE(q);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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: 273]
  ------------------
 1594|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1594:5): [True: 0, False: 273]
  ------------------
 1595|      0|    case SSH_KEYTYPE_ECDSA_P521: {
  ------------------
  |  Branch (1595:5): [True: 0, False: 273]
  ------------------
 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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1612|      0|            ssh_string_burn(exp);
 1613|      0|            SSH_STRING_FREE(exp);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1620|      0|        ssh_string_burn(exp);
 1621|      0|        SSH_STRING_FREE(exp);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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: 273]
  ------------------
 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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1641|      0|            SSH_STRING_FREE(pubkey);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1647|       |
 1648|      0|        if (nid == -1) {
  ------------------
  |  Branch (1648:13): [True: 0, False: 0]
  ------------------
 1649|      0|            SSH_STRING_FREE(pubkey);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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|    273|    case SSH_KEYTYPE_ED25519: {
  ------------------
  |  Branch (1661:5): [True: 273, False: 0]
  ------------------
 1662|    273|        ssh_string pubkey = NULL, privkey = NULL;
 1663|       |
 1664|    273|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|    273|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 273]
  |  |  ------------------
  ------------------
 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|    273|        rc = ssh_buffer_unpack(buffer, "SS", &pubkey, &privkey);
  ------------------
  |  |   60|    273|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1670|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1670:13): [True: 0, False: 273]
  ------------------
 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|    273|        rc = pki_privkey_build_ed25519(key, pubkey, privkey);
 1676|    273|        ssh_string_burn(privkey);
 1677|    273|        SSH_STRING_FREE(privkey);
  ------------------
  |  |  915|    273|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 273, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
 1678|    273|        SSH_STRING_FREE(pubkey);
  ------------------
  |  |  915|    273|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 273, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
 1679|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1679:13): [True: 0, False: 273]
  ------------------
 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|    273|        break;
 1684|    273|    }
 1685|    273|    case SSH_KEYTYPE_SK_ED25519: {
  ------------------
  |  Branch (1685:5): [True: 0, False: 273]
  ------------------
 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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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: 273]
  ------------------
 1712|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1712:5): [True: 0, False: 273]
  ------------------
 1713|      0|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1713:5): [True: 0, False: 273]
  ------------------
 1714|      0|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1714:5): [True: 0, False: 273]
  ------------------
 1715|      0|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1715:5): [True: 0, False: 273]
  ------------------
 1716|      0|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1716:5): [True: 0, False: 273]
  ------------------
 1717|      0|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1717:5): [True: 0, False: 273]
  ------------------
 1718|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1718:5): [True: 0, False: 273]
  ------------------
 1719|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1719:5): [True: 0, False: 273]
  ------------------
 1720|      0|    default:
  ------------------
  |  Branch (1720:5): [True: 0, False: 273]
  ------------------
 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|    273|    }
 1724|       |
 1725|    273|    *pkey = key;
 1726|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#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|    273|}
ssh_pki_import_pubkey_blob:
 2027|    546|{
 2028|    546|    ssh_buffer buffer = NULL;
 2029|    546|    ssh_string type_s = NULL;
 2030|    546|    enum ssh_keytypes_e type;
 2031|    546|    int rc;
 2032|       |
 2033|    546|    if (key_blob == NULL || pkey == NULL) {
  ------------------
  |  Branch (2033:9): [True: 0, False: 546]
  |  Branch (2033:29): [True: 0, False: 546]
  ------------------
 2034|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2035|      0|    }
 2036|       |
 2037|    546|    buffer = ssh_buffer_new();
 2038|    546|    if (buffer == NULL) {
  ------------------
  |  Branch (2038:9): [True: 0, False: 546]
  ------------------
 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|    546|    rc = ssh_buffer_add_data(buffer,
 2044|    546|                             ssh_string_data(key_blob),
 2045|    546|                             (uint32_t)ssh_string_len(key_blob));
 2046|    546|    if (rc < 0) {
  ------------------
  |  Branch (2046:9): [True: 0, False: 546]
  ------------------
 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|    546|    type_s = ssh_buffer_get_ssh_string(buffer);
 2052|    546|    if (type_s == NULL) {
  ------------------
  |  Branch (2052:9): [True: 0, False: 546]
  ------------------
 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|    546|    type = ssh_key_type_from_name(ssh_string_get_char(type_s));
 2058|    546|    if (type == SSH_KEYTYPE_UNKNOWN) {
  ------------------
  |  Branch (2058:9): [True: 0, False: 546]
  ------------------
 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|    546|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  915|    546|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 546, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
 2063|       |
 2064|    546|    if (is_cert_type(type)) {
  ------------------
  |  |  146|    546|    ((kt) == SSH_KEYTYPE_RSA_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (146:6): [True: 0, False: 546]
  |  |  ------------------
  |  |  147|    546|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (147:6): [True: 0, False: 546]
  |  |  ------------------
  |  |  148|    546|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (148:6): [True: 0, False: 546]
  |  |  ------------------
  |  |  149|    546|    ((kt) >= SSH_KEYTYPE_ECDSA_P256_CERT01 &&\
  |  |  ------------------
  |  |  |  Branch (149:6): [True: 0, False: 546]
  |  |  ------------------
  |  |  150|    546|     (kt) <= SSH_KEYTYPE_ED25519_CERT01))
  |  |  ------------------
  |  |  |  Branch (150:6): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 2065|      0|        rc = pki_import_cert_buffer(buffer, type, pkey);
 2066|    546|    } else {
 2067|    546|        rc = pki_import_pubkey_buffer(buffer, type, pkey);
 2068|    546|    }
 2069|       |
 2070|    546|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  957|    546|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 546, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
 2071|       |
 2072|    546|    return rc;
 2073|      0|fail:
 2074|      0|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2075|      0|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2076|       |
 2077|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2078|    546|}
ssh_pki_export_privkey_to_pubkey:
 2570|    273|{
 2571|    273|    ssh_key pubkey = NULL;
 2572|       |
 2573|    273|    if (privkey == NULL || !ssh_key_is_private(privkey)) {
  ------------------
  |  Branch (2573:9): [True: 0, False: 273]
  |  Branch (2573:28): [True: 0, False: 273]
  ------------------
 2574|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2575|      0|    }
 2576|       |
 2577|    273|    pubkey = pki_key_dup(privkey, 1);
 2578|    273|    if (pubkey == NULL) {
  ------------------
  |  Branch (2578:9): [True: 0, False: 273]
  ------------------
 2579|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2580|      0|    }
 2581|       |
 2582|    273|    *pkey = pubkey;
 2583|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
 2584|    273|}
ssh_pki_export_pubkey_blob:
 2666|  1.09k|{
 2667|  1.09k|    ssh_string blob = NULL;
 2668|       |
 2669|  1.09k|    if (key == NULL) {
  ------------------
  |  Branch (2669:9): [True: 0, False: 1.09k]
  ------------------
 2670|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2671|      0|    }
 2672|       |
 2673|  1.09k|    blob = pki_key_to_blob(key, SSH_KEY_PUBLIC);
 2674|  1.09k|    if (blob == NULL) {
  ------------------
  |  Branch (2674:9): [True: 0, False: 1.09k]
  ------------------
 2675|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2676|      0|    }
 2677|       |
 2678|  1.09k|    *pblob = blob;
 2679|  1.09k|    return SSH_OK;
  ------------------
  |  |  316|  1.09k|#define SSH_OK 0     /* No error */
  ------------------
 2680|  1.09k|}
ssh_pki_export_signature_blob:
 2877|    273|{
 2878|    273|    ssh_buffer buf = NULL;
 2879|    273|    ssh_string str = NULL;
 2880|    273|    int rc;
 2881|       |
 2882|    273|    if (sig == NULL || sig_blob == NULL) {
  ------------------
  |  Branch (2882:9): [True: 0, False: 273]
  |  Branch (2882:24): [True: 0, False: 273]
  ------------------
 2883|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2884|      0|    }
 2885|       |
 2886|    273|    buf = ssh_buffer_new();
 2887|    273|    if (buf == NULL) {
  ------------------
  |  Branch (2887:9): [True: 0, False: 273]
  ------------------
 2888|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2889|      0|    }
 2890|       |
 2891|    273|    str = ssh_string_from_char(sig->type_c);
 2892|    273|    if (str == NULL) {
  ------------------
  |  Branch (2892:9): [True: 0, False: 273]
  ------------------
 2893|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2894|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2895|      0|    }
 2896|       |
 2897|    273|    rc = ssh_buffer_add_ssh_string(buf, str);
 2898|    273|    SSH_STRING_FREE(str);
  ------------------
  |  |  915|    273|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 273, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
 2899|    273|    if (rc < 0) {
  ------------------
  |  Branch (2899:9): [True: 0, False: 273]
  ------------------
 2900|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2901|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2902|      0|    }
 2903|       |
 2904|    273|    str = pki_signature_to_blob(sig);
 2905|    273|    if (str == NULL) {
  ------------------
  |  Branch (2905:9): [True: 0, False: 273]
  ------------------
 2906|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2907|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2908|      0|    }
 2909|       |
 2910|    273|    rc = ssh_buffer_add_ssh_string(buf, str);
 2911|    273|    SSH_STRING_FREE(str);
  ------------------
  |  |  915|    273|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 273, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
 2912|    273|    if (rc < 0) {
  ------------------
  |  Branch (2912:9): [True: 0, False: 273]
  ------------------
 2913|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2914|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2915|      0|    }
 2916|       |
 2917|    273|    if (is_sk_key_type(sig->type)) {
  ------------------
  |  |  153|    273|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 0, False: 273]
  |  |  |  Branch (153:38): [True: 0, False: 273]
  |  |  ------------------
  |  |  154|    273|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 273]
  |  |  ------------------
  |  |  155|    273|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 273]
  |  |  ------------------
  ------------------
 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);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957: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|    273|    str = ssh_string_new(ssh_buffer_get_len(buf));
 2927|    273|    if (str == NULL) {
  ------------------
  |  Branch (2927:9): [True: 0, False: 273]
  ------------------
 2928|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2929|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2930|      0|    }
 2931|       |
 2932|    273|    rc = ssh_string_fill(str, ssh_buffer_get(buf), ssh_buffer_get_len(buf));
 2933|    273|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|    273|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 273, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
 2934|    273|    if (rc < 0) {
  ------------------
  |  Branch (2934:9): [True: 0, False: 273]
  ------------------
 2935|      0|        SSH_STRING_FREE(str);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2936|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2937|      0|    }
 2938|       |
 2939|    273|    *sig_blob = str;
 2940|       |
 2941|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
 2942|    273|}
ssh_pki_import_signature_blob:
 2947|    273|{
 2948|    273|    ssh_signature sig = NULL;
 2949|    273|    enum ssh_keytypes_e type;
 2950|    273|    enum ssh_digest_e hash_type;
 2951|    273|    ssh_string algorithm = NULL, blob = NULL;
 2952|    273|    ssh_buffer buf = NULL;
 2953|    273|    const char *alg = NULL;
 2954|    273|    uint8_t flags = 0;
 2955|    273|    uint32_t counter = 0;
 2956|    273|    int rc;
 2957|       |
 2958|    273|    if (sig_blob == NULL || psig == NULL) {
  ------------------
  |  Branch (2958:9): [True: 0, False: 273]
  |  Branch (2958:29): [True: 0, False: 273]
  ------------------
 2959|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2960|      0|    }
 2961|       |
 2962|    273|    buf = ssh_buffer_new();
 2963|    273|    if (buf == NULL) {
  ------------------
  |  Branch (2963:9): [True: 0, False: 273]
  ------------------
 2964|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2965|      0|    }
 2966|       |
 2967|    273|    rc = ssh_buffer_add_data(buf,
 2968|    273|                             ssh_string_data(sig_blob),
 2969|    273|                             (uint32_t)ssh_string_len(sig_blob));
 2970|    273|    if (rc < 0) {
  ------------------
  |  Branch (2970:9): [True: 0, False: 273]
  ------------------
 2971|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2972|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2973|      0|    }
 2974|       |
 2975|    273|    algorithm = ssh_buffer_get_ssh_string(buf);
 2976|    273|    if (algorithm == NULL) {
  ------------------
  |  Branch (2976:9): [True: 0, False: 273]
  ------------------
 2977|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2978|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2979|      0|    }
 2980|       |
 2981|    273|    alg = ssh_string_get_char(algorithm);
 2982|    273|    rc = ssh_key_type_and_hash_from_signature_name(alg, &type, &hash_type);
 2983|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2983:9): [True: 0, False: 273]
  ------------------
 2984|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2985|      0|        SSH_STRING_FREE(algorithm);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2986|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2987|      0|    }
 2988|    273|    SSH_STRING_FREE(algorithm);
  ------------------
  |  |  915|    273|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 273, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
 2989|       |
 2990|    273|    blob = ssh_buffer_get_ssh_string(buf);
 2991|    273|    if (blob == NULL) {
  ------------------
  |  Branch (2991:9): [True: 0, False: 273]
  ------------------
 2992|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2993|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2994|      0|    }
 2995|       |
 2996|    273|    if (type == SSH_KEYTYPE_SK_ECDSA ||
  ------------------
  |  Branch (2996:9): [True: 0, False: 273]
  ------------------
 2997|    273|        type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (2997:9): [True: 0, False: 273]
  ------------------
 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);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3001|      0|            SSH_STRING_FREE(blob);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3002|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3003|      0|        }
 3004|      0|    }
 3005|    273|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|    273|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 273, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
 3006|       |
 3007|    273|    sig = pki_signature_from_blob(pubkey, blob, type, hash_type);
 3008|    273|    SSH_STRING_FREE(blob);
  ------------------
  |  |  915|    273|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 273, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
 3009|    273|    if (sig == NULL) {
  ------------------
  |  Branch (3009:9): [True: 0, False: 273]
  ------------------
 3010|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3011|      0|    }
 3012|       |
 3013|       |    /* Set SK specific values */
 3014|    273|    sig->sk_flags = flags;
 3015|    273|    sig->sk_counter = counter;
 3016|       |
 3017|    273|    *psig = sig;
 3018|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
 3019|    273|}
pki_key_check_hash_compatible:
 3034|  1.09k|{
 3035|  1.09k|    if (key == NULL) {
  ------------------
  |  Branch (3035:9): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|    switch(key->type) {
  ------------------
  |  Branch (3041:12): [True: 1.09k, False: 0]
  ------------------
 3042|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (3042:5): [True: 0, False: 1.09k]
  ------------------
 3043|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (3043:5): [True: 0, False: 1.09k]
  ------------------
 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: 1.09k]
  ------------------
 3060|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (3060:5): [True: 0, False: 1.09k]
  ------------------
 3061|      0|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (3061:5): [True: 0, False: 1.09k]
  ------------------
 3062|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (3062:5): [True: 0, False: 1.09k]
  ------------------
 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: 1.09k]
  ------------------
 3068|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (3068:5): [True: 0, False: 1.09k]
  ------------------
 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: 1.09k]
  ------------------
 3074|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (3074:5): [True: 0, False: 1.09k]
  ------------------
 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: 1.09k]
  ------------------
 3080|  1.09k|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (3080:5): [True: 1.09k, False: 0]
  ------------------
 3081|  1.09k|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (3081:5): [True: 0, False: 1.09k]
  ------------------
 3082|  1.09k|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (3082:5): [True: 0, False: 1.09k]
  ------------------
 3083|  1.09k|        if (hash_type == SSH_DIGEST_AUTO) {
  ------------------
  |  Branch (3083:13): [True: 1.09k, False: 0]
  ------------------
 3084|  1.09k|            return SSH_OK;
  ------------------
  |  |  316|  1.09k|#define SSH_OK 0     /* No error */
  ------------------
 3085|  1.09k|        }
 3086|      0|        break;
 3087|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (3087:5): [True: 0, False: 1.09k]
  ------------------
 3088|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (3088:5): [True: 0, False: 1.09k]
  ------------------
 3089|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (3089:5): [True: 0, False: 1.09k]
  ------------------
 3090|      0|    case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (3090:5): [True: 0, False: 1.09k]
  ------------------
 3091|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (3091:5): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|    }
 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|  1.09k|}
ssh_pki_signature_verify:
 3190|    273|{
 3191|    273|    int rc;
 3192|    273|    bool allowed;
 3193|    273|    enum ssh_keytypes_e key_type;
 3194|       |
 3195|    273|    if (session == NULL || sig == NULL || key == NULL || input == NULL) {
  ------------------
  |  Branch (3195:9): [True: 0, False: 273]
  |  Branch (3195:28): [True: 0, False: 273]
  |  Branch (3195:43): [True: 0, False: 273]
  |  Branch (3195:58): [True: 0, False: 273]
  ------------------
 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|    273|    key_type = ssh_key_type_plain(key->type);
 3200|       |
 3201|    273|    SSH_LOG(SSH_LOG_FUNCTIONS,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3202|    273|            "Going to verify a %s type signature",
 3203|    273|            sig->type_c);
 3204|       |
 3205|    273|    if (key_type != sig->type) {
  ------------------
  |  Branch (3205:9): [True: 0, False: 273]
  ------------------
 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|    273|    allowed = ssh_key_size_allowed(session, key);
 3213|    273|    if (!allowed) {
  ------------------
  |  Branch (3213:9): [True: 0, False: 273]
  ------------------
 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|    273|    rc = pki_key_check_hash_compatible(key, sig->hash_type);
 3224|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3224:9): [True: 0, False: 273]
  ------------------
 3225|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3226|      0|    }
 3227|       |
 3228|    273|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|    273|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 0, False: 273]
  |  |  |  Branch (153:38): [True: 0, False: 273]
  |  |  ------------------
  |  |  154|    273|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 273]
  |  |  ------------------
  |  |  155|    273|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 273]
  |  |  ------------------
  ------------------
 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);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3245|      0|        return rc;
 3246|      0|    }
 3247|       |
 3248|    273|    return pki_verify_data_signature(sig, key, input, input_len);
 3249|    273|}
pki_do_sign:
 3255|    273|{
 3256|    273|    int rc;
 3257|       |
 3258|    273|    if (privkey == NULL || input == NULL) {
  ------------------
  |  Branch (3258:9): [True: 0, False: 273]
  |  Branch (3258:28): [True: 0, False: 273]
  ------------------
 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|    273|    rc = pki_key_check_hash_compatible(privkey, hash_type);
 3266|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3266:9): [True: 0, False: 273]
  ------------------
 3267|      0|        return NULL;
 3268|      0|    }
 3269|       |
 3270|    273|    return pki_sign_data(privkey, hash_type, input, input_len);
 3271|    273|}
ssh_srv_pki_do_sign_sessionid:
 4027|    273|{
 4028|    273|    struct ssh_crypto_struct *crypto = NULL;
 4029|    273|    bool allowed;
 4030|    273|    ssh_signature sig = NULL;
 4031|    273|    ssh_string sig_blob = NULL;
 4032|       |
 4033|    273|    ssh_buffer sign_input = NULL;
 4034|       |
 4035|    273|    int rc;
 4036|       |
 4037|    273|    if (session == NULL || privkey == NULL || !ssh_key_is_private(privkey)) {
  ------------------
  |  Branch (4037:9): [True: 0, False: 273]
  |  Branch (4037:28): [True: 0, False: 273]
  |  Branch (4037:47): [True: 0, False: 273]
  ------------------
 4038|      0|        return NULL;
 4039|      0|    }
 4040|       |
 4041|    273|    allowed = ssh_key_size_allowed(session, privkey);
 4042|    273|    if (!allowed) {
  ------------------
  |  Branch (4042:9): [True: 0, False: 273]
  ------------------
 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|    273|    crypto = session->next_crypto ? session->next_crypto :
  ------------------
  |  Branch (4047:14): [True: 273, False: 0]
  ------------------
 4048|    273|                                    session->current_crypto;
 4049|       |
 4050|    273|    if (crypto->secret_hash == NULL){
  ------------------
  |  Branch (4050:9): [True: 0, False: 273]
  ------------------
 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|    273|    sign_input = ssh_buffer_new();
 4057|    273|    if (sign_input == NULL) {
  ------------------
  |  Branch (4057:9): [True: 0, False: 273]
  ------------------
 4058|      0|        goto end;
 4059|      0|    }
 4060|    273|    ssh_buffer_set_secure(sign_input);
 4061|       |
 4062|    273|    rc = ssh_buffer_pack(sign_input,
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 4063|    273|                         "P",
 4064|    273|                         crypto->digest_len,
 4065|    273|                         crypto->secret_hash);
 4066|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (4066:9): [True: 0, False: 273]
  ------------------
 4067|      0|        goto end;
 4068|      0|    }
 4069|       |
 4070|       |    /* Generate the signature */
 4071|    273|    sig = pki_do_sign(privkey,
 4072|    273|                      ssh_buffer_get(sign_input),
 4073|    273|                      ssh_buffer_get_len(sign_input),
 4074|    273|                      digest);
 4075|    273|    if (sig == NULL) {
  ------------------
  |  Branch (4075:9): [True: 0, False: 273]
  ------------------
 4076|      0|        goto end;
 4077|      0|    }
 4078|       |
 4079|       |    /* Convert the signature to blob */
 4080|    273|    rc = ssh_pki_export_signature_blob(sig, &sig_blob);
 4081|    273|    if (rc < 0) {
  ------------------
  |  Branch (4081:9): [True: 0, False: 273]
  ------------------
 4082|      0|        sig_blob = NULL;
 4083|      0|    }
 4084|       |
 4085|    273|end:
 4086|    273|    ssh_signature_free(sig);
 4087|    273|    SSH_BUFFER_FREE(sign_input);
  ------------------
  |  |  957|    273|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 273, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
 4088|       |
 4089|    273|    return sig_blob;
 4090|    273|}
pki.c:pki_import_pubkey_buffer:
 1736|    546|{
 1737|    546|    ssh_key key = NULL;
 1738|    546|    int rc;
 1739|       |
 1740|    546|    key = ssh_key_new();
 1741|    546|    if (key == NULL) {
  ------------------
  |  Branch (1741:9): [True: 0, False: 546]
  ------------------
 1742|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1743|      0|    }
 1744|       |
 1745|    546|    key->type = type;
 1746|    546|    key->type_c = ssh_key_type_to_char(type);
 1747|    546|    key->flags = SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   54|    546|#define SSH_KEY_FLAG_PUBLIC  0x0001
  ------------------
 1748|       |
 1749|    546|    switch (type) {
 1750|      0|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1750:9): [True: 0, False: 546]
  ------------------
 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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1768|      0|                ssh_string_burn(n);
 1769|      0|                SSH_STRING_FREE(n);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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: 546]
  ------------------
 1778|      0|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1778:9): [True: 0, False: 546]
  ------------------
 1779|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1779:9): [True: 0, False: 546]
  ------------------
 1780|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1780:9): [True: 0, False: 546]
  ------------------
 1781|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1781:9): [True: 0, False: 546]
  ------------------
 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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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|    546|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1822:9): [True: 546, False: 0]
  ------------------
 1823|    546|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1823:9): [True: 0, False: 546]
  ------------------
 1824|    546|        {
 1825|    546|            ssh_string pubkey = ssh_buffer_get_ssh_string(buffer);
 1826|       |
 1827|    546|            if (ssh_string_len(pubkey) != ED25519_KEY_LEN) {
  ------------------
  |  |   44|    546|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1827:17): [True: 0, False: 546]
  ------------------
 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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1831|      0|                goto fail;
 1832|      0|            }
 1833|       |
 1834|    546|            rc = pki_pubkey_build_ed25519(key, pubkey);
 1835|    546|            ssh_string_burn(pubkey);
 1836|    546|            SSH_STRING_FREE(pubkey);
  ------------------
  |  |  915|    546|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 546, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
 1837|    546|            if (rc < 0) {
  ------------------
  |  Branch (1837:17): [True: 0, False: 546]
  ------------------
 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|    546|            if (type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1842:17): [True: 0, False: 546]
  ------------------
 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|    546|        }
 1851|    546|        break;
 1852|    546|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1852:9): [True: 0, False: 546]
  ------------------
 1853|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1853:9): [True: 0, False: 546]
  ------------------
 1854|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1854:9): [True: 0, False: 546]
  ------------------
 1855|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1855:9): [True: 0, False: 546]
  ------------------
 1856|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1856:9): [True: 0, False: 546]
  ------------------
 1857|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1857:9): [True: 0, False: 546]
  ------------------
 1858|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1858:9): [True: 0, False: 546]
  ------------------
 1859|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1859:9): [True: 0, False: 546]
  ------------------
 1860|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1860:9): [True: 0, False: 546]
  ------------------
 1861|      0|        default:
  ------------------
  |  Branch (1861:9): [True: 0, False: 546]
  ------------------
 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|    546|    }
 1865|       |
 1866|    546|    *pkey = key;
 1867|    546|    return SSH_OK;
  ------------------
  |  |  316|    546|#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|    546|}

ssh_pki_openssh_privkey_import:
  387|    273|{
  388|       |    return ssh_pki_openssh_import(text_key, passphrase, auth_fn, auth_data, true);
  389|    273|}
pki_container_openssh.c:ssh_pki_openssh_import:
  235|    273|{
  236|    273|    const char *ptr = text_key;
  237|    273|    const char *end = NULL;
  238|    273|    char *base64 = NULL;
  239|    273|    int cmp;
  240|    273|    int rc;
  241|    273|    int i;
  242|    273|    ssh_buffer buffer = NULL, privkey_buffer = NULL;
  243|    273|    char *magic = NULL, *ciphername = NULL, *kdfname = NULL;
  244|    273|    uint32_t nkeys = 0, checkint1 = 0, checkint2 = 0xFFFF;
  245|    273|    ssh_string kdfoptions = NULL;
  246|    273|    ssh_string pubkey0 = NULL;
  247|    273|    ssh_string privkeys = NULL;
  248|    273|    ssh_string comment = NULL;
  249|    273|    ssh_key key = NULL;
  250|    273|    uint8_t padding;
  251|       |
  252|    273|    cmp = strncmp(ptr, OPENSSH_HEADER_BEGIN, strlen(OPENSSH_HEADER_BEGIN));
  ------------------
  |  |   43|    273|#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
  ------------------
                  cmp = strncmp(ptr, OPENSSH_HEADER_BEGIN, strlen(OPENSSH_HEADER_BEGIN));
  ------------------
  |  |   43|    273|#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
  ------------------
  253|    273|    if (cmp != 0) {
  ------------------
  |  Branch (253:9): [True: 0, False: 273]
  ------------------
  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|    273|    ptr += strlen(OPENSSH_HEADER_BEGIN);
  ------------------
  |  |   43|    273|#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
  ------------------
  258|    273|    while(ptr[0] != '\0' && !isspace((int)ptr[0])) {
  ------------------
  |  Branch (258:11): [True: 273, False: 0]
  |  Branch (258:29): [True: 0, False: 273]
  ------------------
  259|      0|        ptr++;
  260|      0|    }
  261|    273|    end = strstr(ptr, OPENSSH_HEADER_END);
  ------------------
  |  |   44|    273|#define OPENSSH_HEADER_END "-----END OPENSSH PRIVATE KEY-----"
  ------------------
  262|    273|    if (end == NULL) {
  ------------------
  |  Branch (262:9): [True: 0, False: 273]
  ------------------
  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|    273|    base64 = malloc(end - ptr + 1);
  267|    273|    if (base64 == NULL) {
  ------------------
  |  Branch (267:9): [True: 0, False: 273]
  ------------------
  268|      0|        goto out;
  269|      0|    }
  270|  93.6k|    for (i = 0; ptr < end; ptr++) {
  ------------------
  |  Branch (270:17): [True: 93.3k, False: 273]
  ------------------
  271|  93.3k|        if (!isspace((int)ptr[0])) {
  ------------------
  |  Branch (271:13): [True: 91.7k, False: 1.63k]
  ------------------
  272|  91.7k|            base64[i] = ptr[0];
  273|  91.7k|            i++;
  274|  91.7k|        }
  275|  93.3k|    }
  276|    273|    base64[i] = '\0';
  277|    273|    buffer = base64_to_bin(base64);
  278|    273|    SAFE_FREE(base64);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  279|    273|    if (buffer == NULL) {
  ------------------
  |  Branch (279:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_buffer_unpack(buffer, "PssSdSS",
  ------------------
  |  |   60|    273|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  284|    273|                           strlen(OPENSSH_AUTH_MAGIC) + 1,
  285|    273|                           &magic,
  286|    273|                           &ciphername,
  287|    273|                           &kdfname,
  288|    273|                           &kdfoptions,
  289|    273|                           &nkeys,
  290|    273|                           &pubkey0,
  291|    273|                           &privkeys);
  292|    273|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (292:9): [True: 0, False: 273]
  ------------------
  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|    273|    cmp = strncmp(magic, OPENSSH_AUTH_MAGIC, strlen(OPENSSH_AUTH_MAGIC));
  ------------------
  |  |   46|    273|#define OPENSSH_AUTH_MAGIC      "openssh-key-v1"
  ------------------
                  cmp = strncmp(magic, OPENSSH_AUTH_MAGIC, strlen(OPENSSH_AUTH_MAGIC));
  ------------------
  |  |   46|    273|#define OPENSSH_AUTH_MAGIC      "openssh-key-v1"
  ------------------
  297|    273|    if (cmp != 0) {
  ------------------
  |  Branch (297:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  302|    273|            "Opening OpenSSH private key: ciphername: %s, kdf: %s, nkeys: %" PRIu32,
  303|    273|            ciphername,
  304|    273|            kdfname,
  305|    273|            nkeys);
  306|    273|    if (nkeys != 1) {
  ------------------
  |  Branch (306:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (!private) {
  ------------------
  |  Branch (314:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = pki_private_key_decrypt(privkeys,
  324|    273|                                 passphrase,
  325|    273|                                 ciphername,
  326|    273|                                 kdfname,
  327|    273|                                 kdfoptions,
  328|    273|                                 auth_fn,
  329|    273|                                 auth_data);
  330|    273|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (330:9): [True: 0, False: 273]
  ------------------
  331|      0|        goto out;
  332|      0|    }
  333|       |
  334|    273|    privkey_buffer = ssh_buffer_new();
  335|    273|    if (privkey_buffer == NULL) {
  ------------------
  |  Branch (335:9): [True: 0, False: 273]
  ------------------
  336|      0|        goto out;
  337|      0|    }
  338|       |
  339|    273|    ssh_buffer_set_secure(privkey_buffer);
  340|    273|    ssh_buffer_add_data(privkey_buffer,
  341|    273|                        ssh_string_data(privkeys),
  342|    273|                        (uint32_t)ssh_string_len(privkeys));
  343|       |
  344|    273|    rc = ssh_buffer_unpack(privkey_buffer, "dd", &checkint1, &checkint2);
  ------------------
  |  |   60|    273|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  345|    273|    if (rc == SSH_ERROR || checkint1 != checkint2) {
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (345:9): [True: 0, False: 273]
  |  Branch (345:28): [True: 0, False: 273]
  ------------------
  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|    273|    rc = pki_openssh_import_privkey_blob(privkey_buffer, &key);
  350|    273|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (350:9): [True: 0, False: 273]
  ------------------
  351|      0|        goto out;
  352|      0|    }
  353|    273|    comment = ssh_buffer_get_ssh_string(privkey_buffer);
  354|    273|    SAFE_FREE(comment);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  355|       |    /* verify that the remaining data is correct padding */
  356|  1.63k|    for (i = 1; ssh_buffer_get_len(privkey_buffer) > 0; ++i) {
  ------------------
  |  Branch (356:17): [True: 1.36k, False: 273]
  ------------------
  357|  1.36k|        ssh_buffer_get_u8(privkey_buffer, &padding);
  358|  1.36k|        if (padding != i) {
  ------------------
  |  Branch (358:13): [True: 0, False: 1.36k]
  ------------------
  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|  1.36k|    }
  365|    273|out:
  366|    273|    if (buffer != NULL) {
  ------------------
  |  Branch (366:9): [True: 273, False: 0]
  ------------------
  367|    273|        SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  957|    273|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 273, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
  368|    273|        buffer = NULL;
  369|    273|    }
  370|    273|    if (privkey_buffer != NULL) {
  ------------------
  |  Branch (370:9): [True: 273, False: 0]
  ------------------
  371|    273|        SSH_BUFFER_FREE(privkey_buffer);
  ------------------
  |  |  957|    273|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 273, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
  372|    273|        privkey_buffer = NULL;
  373|    273|    }
  374|    273|    SAFE_FREE(magic);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  375|    273|    SAFE_FREE(ciphername);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  376|    273|    SAFE_FREE(kdfname);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  377|    273|    SAFE_FREE(kdfoptions);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  378|    273|    SAFE_FREE(pubkey0);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  379|       |    SAFE_FREE(privkeys);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  380|    273|    return key;
  381|    273|}
pki_container_openssh.c:pki_private_key_decrypt:
  108|    273|{
  109|    273|    struct ssh_cipher_struct *ciphers = ssh_get_ciphertab();
  110|    273|    struct ssh_cipher_struct cipher;
  111|    273|    uint8_t key_material[128] = {0};
  112|    273|    char passphrase_buffer[128] = {0};
  113|    273|    size_t key_material_len;
  114|    273|    ssh_buffer buffer = NULL;
  115|    273|    ssh_string salt = NULL;
  116|    273|    uint32_t rounds;
  117|    273|    int cmp;
  118|    273|    int rc;
  119|    273|    int i;
  120|       |
  121|    273|    cmp = strcmp(ciphername, "none");
  122|    273|    if (cmp == 0){
  ------------------
  |  Branch (122:9): [True: 273, False: 0]
  ------------------
  123|       |        /* no decryption required */
  124|    273|        return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  125|    273|    }
  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);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957: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|    273|{
   61|    273|    enum ssh_keytypes_e type;
   62|    273|    char *type_s = NULL;
   63|    273|    ssh_key key = NULL;
   64|    273|    int rc;
   65|       |
   66|    273|    if (pkey == NULL) {
  ------------------
  |  Branch (66:9): [True: 0, False: 273]
  ------------------
   67|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   68|      0|    }
   69|       |
   70|    273|    rc = ssh_buffer_unpack(key_blob_buffer, "s", &type_s);
  ------------------
  |  |   60|    273|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
   71|    273|    if (rc == SSH_ERROR){
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (71:9): [True: 0, False: 273]
  ------------------
   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|    273|    type = ssh_key_type_from_name(type_s);
   77|    273|    if (type == SSH_KEYTYPE_UNKNOWN) {
  ------------------
  |  Branch (77:9): [True: 0, False: 273]
  ------------------
   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|    273|    SAFE_FREE(type_s);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
   82|       |
   83|    273|    rc = pki_import_privkey_buffer(type, key_blob_buffer, &key);
   84|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (84:9): [True: 0, False: 273]
  ------------------
   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|    273|    *pkey = key;
   90|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#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|    273|}

ssh_pki_ctx_new:
   49|    546|{
   50|    546|    struct ssh_pki_ctx_struct *ctx = NULL;
   51|       |
   52|    546|    ctx = calloc(1, sizeof(struct ssh_pki_ctx_struct));
   53|    546|    if (ctx == NULL) {
  ------------------
  |  Branch (53:9): [True: 0, False: 546]
  ------------------
   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|    546|    return ctx;
   77|    546|}
ssh_pki_ctx_free:
   86|    546|{
   87|    546|    if (context == NULL) {
  ------------------
  |  Branch (87:9): [True: 0, False: 546]
  ------------------
   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|    546|    SAFE_FREE(context);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
   99|    546|}

pki_key_clean:
   96|  1.36k|{
   97|  1.36k|    if (key == NULL)
  ------------------
  |  Branch (97:9): [True: 0, False: 1.36k]
  ------------------
   98|      0|        return;
   99|  1.36k|    EVP_PKEY_free(key->key);
  100|       |    key->key = NULL;
  101|  1.36k|}
pki_privkey_build_ed25519:
  418|    273|{
  419|    273|    EVP_PKEY *pkey = NULL;
  420|       |
  421|    273|    if (ssh_string_len(pubkey) != ED25519_KEY_LEN ||
  ------------------
  |  |   44|    546|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (421:9): [True: 0, False: 273]
  ------------------
  422|    273|        ssh_string_len(privkey) != (2 * ED25519_KEY_LEN)) {
  ------------------
  |  |   44|    273|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (422:9): [True: 0, False: 273]
  ------------------
  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|    273|    pkey = EVP_PKEY_new_raw_private_key(EVP_PKEY_ED25519,
  428|    273|                                        NULL,
  429|    273|                                        (const uint8_t *)ssh_string_data(privkey),
  430|    273|                                        ED25519_KEY_LEN);
  ------------------
  |  |   44|    273|#define ED25519_KEY_LEN 32
  ------------------
  431|    273|    if (pkey == NULL) {
  ------------------
  |  Branch (431:9): [True: 0, False: 273]
  ------------------
  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|    273|    key->key = pkey;
  439|       |
  440|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  441|    273|}
pki_pubkey_build_ed25519:
  444|    546|{
  445|    546|    EVP_PKEY *pkey = NULL;
  446|       |
  447|    546|    if (ssh_string_len(pubkey) != ED25519_KEY_LEN) {
  ------------------
  |  |   44|    546|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (447:9): [True: 0, False: 546]
  ------------------
  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|    546|    if (ssh_fips_mode()) {
  ------------------
  |  |  115|    546|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 546]
  |  |  ------------------
  ------------------
  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|    546|    pkey = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519,
  468|    546|                                       NULL,
  469|    546|                                       (const uint8_t *)ssh_string_data(pubkey),
  470|    546|                                       ED25519_KEY_LEN);
  ------------------
  |  |   44|    546|#define ED25519_KEY_LEN 32
  ------------------
  471|    546|    if (pkey == NULL) {
  ------------------
  |  Branch (471:9): [True: 0, False: 546]
  ------------------
  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|    546|    key->key = pkey;
  479|       |
  480|    546|    return SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  481|    546|}
pki_key_dup:
  484|    546|{
  485|    546|    ssh_key new = NULL;
  486|    546|    int rc;
  487|       |
  488|    546|    new = pki_key_dup_common_init(key, demote);
  489|    546|    if (new == NULL) {
  ------------------
  |  Branch (489:9): [True: 0, False: 546]
  ------------------
  490|      0|        return NULL;
  491|      0|    }
  492|       |
  493|    546|    switch (key->type) {
  494|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (494:5): [True: 0, False: 546]
  ------------------
  495|      0|    case SSH_KEYTYPE_RSA1: {
  ------------------
  |  Branch (495:5): [True: 0, False: 546]
  ------------------
  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: 546]
  ------------------
  639|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (639:5): [True: 0, False: 546]
  ------------------
  640|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (640:5): [True: 0, False: 546]
  ------------------
  641|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (641:5): [True: 0, False: 546]
  ------------------
  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|    546|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (711:5): [True: 546, False: 0]
  ------------------
  712|    546|    case SSH_KEYTYPE_SK_ED25519: {
  ------------------
  |  Branch (712:5): [True: 0, False: 546]
  ------------------
  713|    546|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  714|       |        /* Take the PKCS#11 keys as they are */
  715|    546|        if (key->flags & SSH_KEY_FLAG_PKCS11_URI && !demote) {
  ------------------
  |  |   56|  1.09k|#define SSH_KEY_FLAG_PKCS11_URI 0x0004
  ------------------
  |  Branch (715:13): [True: 0, False: 546]
  |  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|    546|        if (!demote && (key->flags & SSH_KEY_FLAG_PRIVATE) &&
  ------------------
  |  |   55|    273|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
  |  Branch (724:13): [True: 273, False: 273]
  |  Branch (724:24): [True: 273, False: 0]
  ------------------
  725|    273|            key->type == SSH_KEYTYPE_ED25519) {
  ------------------
  |  Branch (725:13): [True: 273, False: 0]
  ------------------
  726|    273|            rc = EVP_PKEY_up_ref(key->key);
  727|    273|            if (rc != 1) {
  ------------------
  |  Branch (727:17): [True: 0, False: 273]
  ------------------
  728|      0|                goto fail;
  729|      0|            }
  730|    273|            new->key = key->key;
  731|    273|        } else {
  732|    273|            unsigned char *ed25519_pubkey = NULL;
  733|    273|            size_t key_len = 0;
  734|       |
  735|    273|            rc = EVP_PKEY_get_raw_public_key(key->key, NULL, &key_len);
  736|    273|            if (rc != 1) {
  ------------------
  |  Branch (736:17): [True: 0, False: 273]
  ------------------
  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|    273|            if (key_len != ED25519_KEY_LEN) {
  ------------------
  |  |   44|    273|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (743:17): [True: 0, False: 273]
  ------------------
  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|    273|            ed25519_pubkey = malloc(key_len);
  752|    273|            if (ed25519_pubkey == NULL) {
  ------------------
  |  Branch (752:17): [True: 0, False: 273]
  ------------------
  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|    273|            rc = EVP_PKEY_get_raw_public_key(key->key,
  758|    273|                                             ed25519_pubkey,
  759|    273|                                             &key_len);
  760|    273|            if (rc != 1) {
  ------------------
  |  Branch (760:17): [True: 0, False: 273]
  ------------------
  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|    273|            new->key = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519,
  769|    273|                                                   NULL,
  770|    273|                                                   ed25519_pubkey,
  771|    273|                                                   key_len);
  772|    273|            free(ed25519_pubkey);
  773|    273|        }
  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|    546|        break;
  782|    546|    }
  783|    546|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (783:5): [True: 0, False: 546]
  ------------------
  784|      0|    default:
  ------------------
  |  Branch (784:5): [True: 0, False: 546]
  ------------------
  785|      0|        ssh_key_free(new);
  786|      0|        return NULL;
  787|    546|    }
  788|       |
  789|    546|    return new;
  790|      0|fail:
  791|      0|    ssh_key_free(new);
  792|       |    return NULL;
  793|    546|}
pki_key_to_blob:
 1493|  1.09k|{
 1494|  1.09k|    ssh_buffer buffer = NULL;
 1495|  1.09k|    ssh_string type_s = NULL;
 1496|  1.09k|    ssh_string str = NULL;
 1497|  1.09k|    ssh_string e = NULL;
 1498|  1.09k|    ssh_string n = NULL;
 1499|  1.09k|    ssh_string p = NULL;
 1500|  1.09k|    ssh_string g = NULL;
 1501|  1.09k|    ssh_string q = NULL;
 1502|  1.09k|    ssh_string d = NULL;
 1503|  1.09k|    ssh_string iqmp = NULL;
 1504|  1.09k|    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|  1.09k|    uint8_t *ed25519_pubkey = NULL;
 1512|  1.09k|    uint8_t *ed25519_privkey = NULL;
 1513|  1.09k|    size_t key_len = 0;
 1514|       |
 1515|  1.09k|    buffer = ssh_buffer_new();
 1516|  1.09k|    if (buffer == NULL) {
  ------------------
  |  Branch (1516:9): [True: 0, False: 1.09k]
  ------------------
 1517|      0|        return NULL;
 1518|      0|    }
 1519|       |    /* The buffer will contain sensitive information. Make sure it is erased */
 1520|  1.09k|    ssh_buffer_set_secure(buffer);
 1521|       |
 1522|  1.09k|    if (key->cert != NULL) {
  ------------------
  |  Branch (1522:9): [True: 0, False: 1.09k]
  ------------------
 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);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1526|      0|            return NULL;
 1527|      0|        }
 1528|      0|        goto makestring;
 1529|      0|    }
 1530|       |
 1531|  1.09k|    type_s = ssh_string_from_char(key->type_c);
 1532|  1.09k|    if (type_s == NULL) {
  ------------------
  |  Branch (1532:9): [True: 0, False: 1.09k]
  ------------------
 1533|      0|        SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1534|      0|        return NULL;
 1535|      0|    }
 1536|       |
 1537|  1.09k|    rc = ssh_buffer_add_ssh_string(buffer, type_s);
 1538|  1.09k|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  915|  1.09k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 1.09k, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
 1539|  1.09k|    if (rc < 0) {
  ------------------
  |  Branch (1539:9): [True: 0, False: 1.09k]
  ------------------
 1540|      0|        SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1541|      0|        return NULL;
 1542|      0|    }
 1543|       |
 1544|  1.09k|    switch (key->type) {
 1545|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1545:5): [True: 0, False: 1.09k]
  ------------------
 1546|      0|    case SSH_KEYTYPE_RSA1: {
  ------------------
  |  Branch (1546:5): [True: 0, False: 1.09k]
  ------------------
 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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1697|      0|            ssh_string_burn(iqmp);
 1698|      0|            SSH_STRING_FREE(iqmp);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1699|      0|            ssh_string_burn(p);
 1700|      0|            SSH_STRING_FREE(p);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1701|      0|            ssh_string_burn(q);
 1702|      0|            SSH_STRING_FREE(q);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1712|      0|        ssh_string_burn(n);
 1713|      0|        SSH_STRING_FREE(n);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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|  1.09k|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1722:5): [True: 1.09k, False: 0]
  ------------------
 1723|  1.09k|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1723:5): [True: 0, False: 1.09k]
  ------------------
 1724|  1.09k|        rc = EVP_PKEY_get_raw_public_key(key->key, NULL, &key_len);
 1725|  1.09k|        if (rc != 1) {
  ------------------
  |  Branch (1725:13): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|        if (key_len != ED25519_KEY_LEN) {
  ------------------
  |  |   44|  1.09k|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1732:13): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|        ed25519_pubkey = malloc(key_len);
 1741|  1.09k|        if (ed25519_pubkey == NULL) {
  ------------------
  |  Branch (1741:13): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|        rc = EVP_PKEY_get_raw_public_key(key->key,
 1747|  1.09k|                                         (uint8_t *)ed25519_pubkey,
 1748|  1.09k|                                         &key_len);
 1749|  1.09k|        if (rc != 1) {
  ------------------
  |  Branch (1749:13): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|        rc = ssh_buffer_pack(buffer,
  ------------------
  |  |   50|  1.09k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.09k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.09k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.09k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.09k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.09k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.09k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1757|  1.09k|                             "dP",
 1758|  1.09k|                             (uint32_t)ED25519_KEY_LEN,
 1759|  1.09k|                             (size_t)ED25519_KEY_LEN,
 1760|  1.09k|                             ed25519_pubkey);
 1761|  1.09k|        if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  1.09k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1761:13): [True: 0, False: 1.09k]
  ------------------
 1762|      0|            goto fail;
 1763|      0|        }
 1764|       |
 1765|  1.09k|        if (type == SSH_KEY_PRIVATE && key->type == SSH_KEYTYPE_ED25519) {
  ------------------
  |  Branch (1765:13): [True: 0, False: 1.09k]
  |  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|  1.09k|        } else if (type == SSH_KEY_PRIVATE &&
  ------------------
  |  Branch (1811:20): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|        } else if (type == SSH_KEY_PUBLIC &&
  ------------------
  |  Branch (1818:20): [True: 1.09k, False: 0]
  ------------------
 1819|  1.09k|                   key->type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1819:20): [True: 0, False: 1.09k]
  ------------------
 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|  1.09k|        SAFE_FREE(ed25519_pubkey);
  ------------------
  |  |  373|  1.09k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.09k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
 1828|  1.09k|        break;
 1829|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1829:5): [True: 0, False: 1.09k]
  ------------------
 1830|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1830:5): [True: 0, False: 1.09k]
  ------------------
 1831|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1831:5): [True: 0, False: 1.09k]
  ------------------
 1832|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1832:5): [True: 0, False: 1.09k]
  ------------------
 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);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1856|      0|        if (rc < 0) {
  ------------------
  |  Branch (1856:13): [True: 0, False: 0]
  ------------------
 1857|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957: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);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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: 1.09k]
  ------------------
 1993|      0|    default:
  ------------------
  |  Branch (1993:5): [True: 0, False: 1.09k]
  ------------------
 1994|      0|        goto fail;
 1995|  1.09k|    }
 1996|       |
 1997|  1.09k|makestring:
 1998|  1.09k|    str = ssh_string_new(ssh_buffer_get_len(buffer));
 1999|  1.09k|    if (str == NULL) {
  ------------------
  |  Branch (1999:9): [True: 0, False: 1.09k]
  ------------------
 2000|      0|        goto fail;
 2001|      0|    }
 2002|       |
 2003|  1.09k|    rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
 2004|  1.09k|    if (rc < 0) {
  ------------------
  |  Branch (2004:9): [True: 0, False: 1.09k]
  ------------------
 2005|      0|        goto fail;
 2006|      0|    }
 2007|  1.09k|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  957|  1.09k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 1.09k, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
 2008|       |
 2009|  1.09k|    return str;
 2010|      0|fail:
 2011|      0|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2012|      0|    ssh_string_burn(str);
 2013|      0|    SSH_STRING_FREE(str);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2014|      0|    ssh_string_burn(e);
 2015|      0|    SSH_STRING_FREE(e);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2016|      0|    ssh_string_burn(p);
 2017|      0|    SSH_STRING_FREE(p);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2018|      0|    ssh_string_burn(g);
 2019|      0|    SSH_STRING_FREE(g);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2020|      0|    ssh_string_burn(q);
 2021|      0|    SSH_STRING_FREE(q);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2022|      0|    ssh_string_burn(n);
 2023|      0|    SSH_STRING_FREE(n);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2024|      0|    ssh_string_burn(d);
 2025|      0|    SSH_STRING_FREE(d);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2026|      0|    ssh_string_burn(iqmp);
 2027|      0|    SSH_STRING_FREE(iqmp);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915: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|  1.09k|}
pki_signature_to_blob:
 2136|    273|{
 2137|    273|    ssh_string sig_blob = NULL;
 2138|       |
 2139|    273|    switch(sig->type) {
 2140|      0|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2140:9): [True: 0, False: 273]
  ------------------
 2141|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2141:9): [True: 0, False: 273]
  ------------------
 2142|      0|            sig_blob = ssh_string_copy(sig->raw_sig);
 2143|      0|            break;
 2144|    273|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2144:9): [True: 273, False: 0]
  ------------------
 2145|    273|            sig_blob = pki_ed25519_signature_to_blob(sig);
 2146|    273|            break;
 2147|      0|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2147:9): [True: 0, False: 273]
  ------------------
 2148|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2148:9): [True: 0, False: 273]
  ------------------
 2149|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2149:9): [True: 0, False: 273]
  ------------------
 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: 273]
  ------------------
 2155|      0|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2155:9): [True: 0, False: 273]
  ------------------
 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: 273]
  ------------------
 2160|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2160:9): [True: 0, False: 273]
  ------------------
 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|    273|    }
 2164|       |
 2165|    273|    return sig_blob;
 2166|    273|}
pki_signature_from_blob:
 2393|    273|{
 2394|    273|    ssh_signature sig;
 2395|    273|    int rc;
 2396|       |
 2397|    273|    if (ssh_key_type_plain(pubkey->type) != type) {
  ------------------
  |  Branch (2397:9): [True: 0, False: 273]
  ------------------
 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|    273|    sig = ssh_signature_new();
 2406|    273|    if (sig == NULL) {
  ------------------
  |  Branch (2406:9): [True: 0, False: 273]
  ------------------
 2407|      0|        return NULL;
 2408|      0|    }
 2409|       |
 2410|    273|    sig->type = type;
 2411|    273|    sig->type_c = ssh_key_signature_to_char(type, hash_type);
 2412|    273|    sig->hash_type = hash_type;
 2413|       |
 2414|    273|    switch(type) {
 2415|      0|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2415:9): [True: 0, False: 273]
  ------------------
 2416|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2416:9): [True: 0, False: 273]
  ------------------
 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|    273|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2422:9): [True: 273, False: 0]
  ------------------
 2423|    273|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2423:9): [True: 0, False: 273]
  ------------------
 2424|    273|            rc = pki_signature_from_ed25519_blob(sig, sig_blob);
 2425|    273|            if (rc != SSH_OK){
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2425:17): [True: 0, False: 273]
  ------------------
 2426|      0|                goto error;
 2427|      0|            }
 2428|    273|            break;
 2429|    273|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2429:9): [True: 0, False: 273]
  ------------------
 2430|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2430:9): [True: 0, False: 273]
  ------------------
 2431|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2431:9): [True: 0, False: 273]
  ------------------
 2432|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2432:9): [True: 0, False: 273]
  ------------------
 2433|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2433:9): [True: 0, False: 273]
  ------------------
 2434|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2434:9): [True: 0, False: 273]
  ------------------
 2435|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2435:9): [True: 0, False: 273]
  ------------------
 2436|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2436:9): [True: 0, False: 273]
  ------------------
 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: 273]
  ------------------
 2445|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2445:9): [True: 0, False: 273]
  ------------------
 2446|      0|            SSH_LOG(SSH_LOG_TRACE, "Unknown signature type");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2447|      0|            goto error;
 2448|    273|    }
 2449|       |
 2450|    273|    return sig;
 2451|       |
 2452|      0|error:
 2453|      0|    ssh_signature_free(sig);
 2454|       |    return NULL;
 2455|    273|}
pki_sign_data:
 2549|    273|{
 2550|    273|    const EVP_MD *md = NULL;
 2551|    273|    EVP_MD_CTX *ctx = NULL;
 2552|    273|    EVP_PKEY *pkey = NULL;
 2553|       |
 2554|    273|    unsigned char *raw_sig_data = NULL;
 2555|    273|    size_t raw_sig_len;
 2556|       |
 2557|    273|    ssh_signature sig = NULL;
 2558|       |
 2559|    273|    int rc;
 2560|       |
 2561|    273|    if (privkey == NULL || !ssh_key_is_private(privkey) || input == NULL) {
  ------------------
  |  Branch (2561:9): [True: 0, False: 273]
  |  Branch (2561:28): [True: 0, False: 273]
  |  Branch (2561:60): [True: 0, False: 273]
  ------------------
 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|    273|    rc = pki_key_check_hash_compatible(privkey, hash_type);
 2569|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2569:9): [True: 0, False: 273]
  ------------------
 2570|      0|        return NULL;
 2571|      0|    }
 2572|       |
 2573|       |    /* Set hash algorithm to be used */
 2574|    273|    md = pki_digest_to_md(hash_type);
 2575|    273|    if (md == NULL) {
  ------------------
  |  Branch (2575:9): [True: 273, False: 0]
  ------------------
 2576|    273|        if (hash_type != SSH_DIGEST_AUTO) {
  ------------------
  |  Branch (2576:13): [True: 0, False: 273]
  ------------------
 2577|      0|            return NULL;
 2578|      0|        }
 2579|    273|    }
 2580|       |
 2581|       |    /* Setup private key EVP_PKEY */
 2582|    273|    pkey = pki_key_to_pkey(privkey);
 2583|    273|    if (pkey == NULL) {
  ------------------
  |  Branch (2583:9): [True: 0, False: 273]
  ------------------
 2584|      0|        return NULL;
 2585|      0|    }
 2586|       |
 2587|       |    /* Allocate buffer for signature */
 2588|    273|    raw_sig_len = (size_t)EVP_PKEY_size(pkey);
 2589|    273|    raw_sig_data = (unsigned char *)malloc(raw_sig_len);
 2590|    273|    if (raw_sig_data == NULL) {
  ------------------
  |  Branch (2590:9): [True: 0, False: 273]
  ------------------
 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|    273|    ctx = EVP_MD_CTX_new();
 2597|    273|    if (ctx == NULL) {
  ------------------
  |  Branch (2597:9): [True: 0, False: 273]
  ------------------
 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|    273|    rc = EVP_DigestSignInit(ctx, NULL, md, NULL, pkey);
 2604|    273|    if (rc != 1){
  ------------------
  |  Branch (2604:9): [True: 0, False: 273]
  ------------------
 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|    273|    rc = EVP_DigestSign(ctx, raw_sig_data, &raw_sig_len, input, input_len);
 2612|    273|    if (rc != 1) {
  ------------------
  |  Branch (2612:9): [True: 0, False: 273]
  ------------------
 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|    273|    sig = ssh_signature_new();
 2625|    273|    if (sig == NULL) {
  ------------------
  |  Branch (2625:9): [True: 0, False: 273]
  ------------------
 2626|      0|        goto out;
 2627|      0|    }
 2628|       |
 2629|    273|    sig->raw_sig = ssh_string_new(raw_sig_len);
 2630|    273|    if (sig->raw_sig == NULL) {
  ------------------
  |  Branch (2630:9): [True: 0, False: 273]
  ------------------
 2631|      0|        ssh_signature_free(sig);
 2632|      0|        sig = NULL;
 2633|      0|        goto out;
 2634|      0|    }
 2635|       |
 2636|    273|    rc = ssh_string_fill(sig->raw_sig, raw_sig_data, raw_sig_len);
 2637|    273|    if (rc < 0) {
  ------------------
  |  Branch (2637:9): [True: 0, False: 273]
  ------------------
 2638|      0|        ssh_signature_free(sig);
 2639|      0|        sig = NULL;
 2640|      0|        goto out;
 2641|      0|    }
 2642|       |
 2643|    273|    sig->type = privkey->type;
 2644|    273|    sig->hash_type = hash_type;
 2645|    273|    sig->type_c = ssh_key_signature_to_char(privkey->type, hash_type);
 2646|       |
 2647|    273|out:
 2648|    273|    if (ctx != NULL) {
  ------------------
  |  Branch (2648:9): [True: 273, False: 0]
  ------------------
 2649|    273|        EVP_MD_CTX_free(ctx);
 2650|    273|    }
 2651|    273|    if (raw_sig_data != NULL) {
  ------------------
  |  Branch (2651:9): [True: 273, False: 0]
  ------------------
 2652|    273|        ssh_burn(raw_sig_data, raw_sig_len);
  ------------------
  |  |  388|    273|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 2653|    273|    }
 2654|       |    SAFE_FREE(raw_sig_data);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
 2655|    273|    EVP_PKEY_free(pkey);
 2656|    273|    return sig;
 2657|    273|}
pki_verify_data_signature:
 2676|    273|{
 2677|    273|    const EVP_MD *md = NULL;
 2678|    273|    EVP_MD_CTX *ctx = NULL;
 2679|    273|    EVP_PKEY *pkey = NULL;
 2680|       |
 2681|    273|    unsigned char *raw_sig_data = NULL;
 2682|    273|    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|    273|    int rc = SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2689|    273|    int ok;
 2690|       |
 2691|    273|    if (pubkey == NULL || ssh_key_is_private(pubkey) || input == NULL ||
  ------------------
  |  Branch (2691:9): [True: 0, False: 273]
  |  Branch (2691:27): [True: 0, False: 273]
  |  Branch (2691:57): [True: 0, False: 273]
  ------------------
 2692|    273|        signature == NULL || signature->raw_sig == NULL)
  ------------------
  |  Branch (2692:9): [True: 0, False: 273]
  |  Branch (2692:30): [True: 0, False: 273]
  ------------------
 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|    273|    ok = pki_key_check_hash_compatible(pubkey, signature->hash_type);
 2701|    273|    if (ok != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2701:9): [True: 0, False: 273]
  ------------------
 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|    273|    raw_sig_data = ssh_string_data(signature->raw_sig);
 2707|    273|    raw_sig_len = ssh_string_len(signature->raw_sig);
 2708|    273|    if (raw_sig_data == NULL) {
  ------------------
  |  Branch (2708:9): [True: 0, False: 273]
  ------------------
 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|    273|    md = pki_digest_to_md(signature->hash_type);
 2714|    273|    if (md == NULL) {
  ------------------
  |  Branch (2714:9): [True: 273, False: 0]
  ------------------
 2715|    273|        if (signature->hash_type != SSH_DIGEST_AUTO) {
  ------------------
  |  Branch (2715:13): [True: 0, False: 273]
  ------------------
 2716|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2717|      0|        }
 2718|    273|    }
 2719|       |
 2720|       |    /* Setup public key EVP_PKEY */
 2721|    273|    pkey = pki_key_to_pkey(pubkey);
 2722|    273|    if (pkey == NULL) {
  ------------------
  |  Branch (2722:9): [True: 0, False: 273]
  ------------------
 2723|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2724|      0|    }
 2725|       |
 2726|       |    /* Create the context */
 2727|    273|    ctx = EVP_MD_CTX_new();
 2728|    273|    if (ctx == NULL) {
  ------------------
  |  Branch (2728:9): [True: 0, False: 273]
  ------------------
 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|    273|    ok = EVP_DigestVerifyInit(ctx, NULL, md, NULL, pkey);
 2737|    273|    if (ok != 1){
  ------------------
  |  Branch (2737:9): [True: 0, False: 273]
  ------------------
 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|    273|    ok = EVP_DigestVerify(ctx, raw_sig_data, raw_sig_len, input, input_len);
 2745|    273|    if (ok != 1) {
  ------------------
  |  Branch (2745:9): [True: 0, False: 273]
  ------------------
 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|    273|    SSH_LOG(SSH_LOG_TRACE, "Signature valid");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2753|    273|    rc = SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
 2754|       |
 2755|    273|out:
 2756|    273|    EVP_MD_CTX_free(ctx);
 2757|    273|    EVP_PKEY_free(pkey);
 2758|    273|    return rc;
 2759|    273|}
pki_crypto.c:pki_digest_to_md:
 2458|    546|{
 2459|    546|    const EVP_MD *md = NULL;
 2460|       |
 2461|    546|    switch (hash_type) {
 2462|      0|    case SSH_DIGEST_SHA256:
  ------------------
  |  Branch (2462:5): [True: 0, False: 546]
  ------------------
 2463|      0|        md = EVP_sha256();
 2464|      0|        break;
 2465|      0|    case SSH_DIGEST_SHA384:
  ------------------
  |  Branch (2465:5): [True: 0, False: 546]
  ------------------
 2466|      0|        md = EVP_sha384();
 2467|      0|        break;
 2468|      0|    case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (2468:5): [True: 0, False: 546]
  ------------------
 2469|      0|        md = EVP_sha512();
 2470|      0|        break;
 2471|      0|    case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (2471:5): [True: 0, False: 546]
  ------------------
 2472|      0|        md = EVP_sha1();
 2473|      0|        break;
 2474|    546|    case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (2474:5): [True: 546, False: 0]
  ------------------
 2475|    546|        md = NULL;
 2476|    546|        break;
 2477|      0|    default:
  ------------------
  |  Branch (2477:5): [True: 0, False: 546]
  ------------------
 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|    546|    }
 2482|       |
 2483|    546|    return md;
 2484|    546|}
pki_crypto.c:pki_key_to_pkey:
 2487|    546|{
 2488|    546|    EVP_PKEY *pkey = NULL;
 2489|    546|    int rc = 0;
 2490|       |
 2491|    546|    switch (key->type) {
 2492|      0|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2492:5): [True: 0, False: 546]
  ------------------
 2493|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2493:5): [True: 0, False: 546]
  ------------------
 2494|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (2494:5): [True: 0, False: 546]
  ------------------
 2495|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2495:5): [True: 0, False: 546]
  ------------------
 2496|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2496:5): [True: 0, False: 546]
  ------------------
 2497|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2497:5): [True: 0, False: 546]
  ------------------
 2498|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2498:5): [True: 0, False: 546]
  ------------------
 2499|      0|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2499:5): [True: 0, False: 546]
  ------------------
 2500|      0|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2500:5): [True: 0, False: 546]
  ------------------
 2501|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2501:5): [True: 0, False: 546]
  ------------------
 2502|      0|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2502:5): [True: 0, False: 546]
  ------------------
 2503|    546|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2503:5): [True: 546, False: 0]
  ------------------
 2504|    546|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (2504:5): [True: 0, False: 546]
  ------------------
 2505|    546|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2505:5): [True: 0, False: 546]
  ------------------
 2506|    546|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (2506:5): [True: 0, False: 546]
  ------------------
 2507|    546|        if (key->key == NULL) {
  ------------------
  |  Branch (2507:13): [True: 0, False: 546]
  ------------------
 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|    546|        rc = EVP_PKEY_up_ref(key->key);
 2512|    546|        if (rc != 1) {
  ------------------
  |  Branch (2512:13): [True: 0, False: 546]
  ------------------
 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|    546|        pkey = key->key;
 2517|    546|        break;
 2518|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2518:5): [True: 0, False: 546]
  ------------------
 2519|      0|    default:
  ------------------
  |  Branch (2519:5): [True: 0, False: 546]
  ------------------
 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|    546|    }
 2524|       |
 2525|    546|    return pkey;
 2526|       |
 2527|      0|error:
 2528|      0|    EVP_PKEY_free(pkey);
 2529|       |    return NULL;
 2530|    546|}

pki_ed25519_signature_to_blob:
   40|    273|{
   41|    273|    ssh_string sig_blob = NULL;
   42|    273|    int rc;
   43|       |
   44|    273|#ifdef HAVE_LIBCRYPTO
   45|       |    /* When using the OpenSSL implementation, the signature is stored in raw_sig
   46|       |     * which is shared by all algorithms.*/
   47|    273|    if (sig->raw_sig == NULL) {
  ------------------
  |  Branch (47:9): [True: 0, False: 273]
  ------------------
   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|    273|    sig_blob = ssh_string_new(ED25519_SIG_LEN);
  ------------------
  |  |   39|    273|#define ED25519_SIG_LEN 64
  ------------------
   59|    273|    if (sig_blob == NULL) {
  ------------------
  |  Branch (59:9): [True: 0, False: 273]
  ------------------
   60|      0|        return NULL;
   61|      0|    }
   62|       |
   63|    273|#ifdef HAVE_LIBCRYPTO
   64|    273|    rc = ssh_string_fill(sig_blob, ssh_string_data(sig->raw_sig),
   65|    273|                         ssh_string_len(sig->raw_sig));
   66|       |#else
   67|       |    rc = ssh_string_fill(sig_blob, sig->ed25519_sig, ED25519_SIG_LEN);
   68|       |#endif
   69|    273|    if (rc < 0) {
  ------------------
  |  Branch (69:9): [True: 0, False: 273]
  ------------------
   70|      0|        SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
   71|      0|        return NULL;
   72|      0|    }
   73|       |
   74|    273|    return sig_blob;
   75|    273|}
pki_signature_from_ed25519_blob:
   89|    273|{
   90|    273|    size_t len;
   91|       |
   92|    273|    len = ssh_string_len(sig_blob);
   93|    273|    if (len != ED25519_SIG_LEN){
  ------------------
  |  |   39|    273|#define ED25519_SIG_LEN 64
  ------------------
  |  Branch (93:9): [True: 0, False: 273]
  ------------------
   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|    273|#ifdef HAVE_LIBCRYPTO
   99|    273|    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|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  109|    273|}

ssh_poll_init:
   91|      2|{
   92|      2|    return;
   93|      2|}
ssh_poll:
  115|  9.73k|{
  116|  9.73k|    return poll((struct pollfd *)fds, nfds, timeout);
  117|  9.73k|}
ssh_poll_new:
  396|    546|{
  397|    546|    ssh_poll_handle p = NULL;
  398|       |
  399|    546|    p = malloc(sizeof(struct ssh_poll_handle_struct));
  400|    546|    if (p == NULL) {
  ------------------
  |  Branch (400:9): [True: 0, False: 546]
  ------------------
  401|      0|        return NULL;
  402|      0|    }
  403|    546|    ZERO_STRUCTP(p);
  ------------------
  |  |  379|    546|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (379:34): [True: 546, False: 0]
  |  |  |  Branch (379:85): [Folded, False: 546]
  |  |  ------------------
  ------------------
  404|       |
  405|    546|    p->x.fd = fd;
  406|    546|    p->events = events;
  407|    546|    p->cb = cb;
  408|    546|    p->cb_data = userdata;
  409|       |
  410|    546|    return p;
  411|    546|}
ssh_poll_free:
  420|    546|{
  421|    546|    if (p->ctx != NULL) {
  ------------------
  |  Branch (421:9): [True: 546, False: 0]
  ------------------
  422|    546|        ssh_poll_ctx_remove(p->ctx, p);
  423|    546|        p->ctx = NULL;
  424|    546|    }
  425|       |    SAFE_FREE(p);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  426|    546|}
ssh_poll_get_ctx:
  436|  7.54k|{
  437|  7.54k|    return p->ctx;
  438|  7.54k|}
ssh_poll_get_events:
  448|  20.1k|{
  449|  20.1k|    return p->events;
  450|  20.1k|}
ssh_poll_set_events:
  461|  21.1k|{
  462|  21.1k|    p->events = events;
  463|  21.1k|    if (p->ctx != NULL) {
  ------------------
  |  Branch (463:9): [True: 19.5k, False: 1.63k]
  ------------------
  464|  19.5k|        if (!ssh_poll_is_locked(p)) {
  ------------------
  |  Branch (464:13): [True: 7.82k, False: 11.7k]
  ------------------
  465|  7.82k|            p->ctx->pollfds[p->x.idx].events = events;
  466|  11.7k|        } else if (!(p->ctx->pollfds[p->x.idx].events & POLLOUT)) {
  ------------------
  |  Branch (466:20): [True: 9.35k, False: 2.38k]
  ------------------
  467|       |            /* if locked, allow only setting POLLOUT to prevent recursive
  468|       |             * callbacks */
  469|       |            p->ctx->pollfds[p->x.idx].events = events & POLLOUT;
  470|  9.35k|        }
  471|  19.5k|    }
  472|  21.1k|}
ssh_poll_add_events:
  498|  15.3k|{
  499|  15.3k|    ssh_poll_set_events(p, ssh_poll_get_events(p) | events);
  500|  15.3k|}
ssh_poll_remove_events:
  510|  4.71k|{
  511|  4.71k|    ssh_poll_set_events(p, ssh_poll_get_events(p) & ~events);
  512|  4.71k|}
ssh_poll_ctx_new:
  560|    819|{
  561|    819|    ssh_poll_ctx ctx;
  562|       |
  563|    819|    ctx = malloc(sizeof(struct ssh_poll_ctx_struct));
  564|    819|    if (ctx == NULL) {
  ------------------
  |  Branch (564:9): [True: 0, False: 819]
  ------------------
  565|      0|        return NULL;
  566|      0|    }
  567|    819|    ZERO_STRUCTP(ctx);
  ------------------
  |  |  379|    819|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (379:34): [True: 819, False: 0]
  |  |  |  Branch (379:85): [Folded, False: 819]
  |  |  ------------------
  ------------------
  568|       |
  569|    819|    if (chunk_size == 0) {
  ------------------
  |  Branch (569:9): [True: 0, False: 819]
  ------------------
  570|      0|        chunk_size = SSH_POLL_CTX_CHUNK;
  ------------------
  |  |   43|      0|#define SSH_POLL_CTX_CHUNK			5
  ------------------
  571|      0|    }
  572|       |
  573|    819|    ctx->chunk_size = chunk_size;
  574|       |
  575|    819|    return ctx;
  576|    819|}
ssh_poll_ctx_free:
  584|    819|{
  585|    819|    if (ctx->polls_allocated > 0) {
  ------------------
  |  Branch (585:9): [True: 819, False: 0]
  ------------------
  586|    819|        while (ctx->polls_used > 0) {
  ------------------
  |  Branch (586:16): [True: 0, False: 819]
  ------------------
  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|    819|        SAFE_FREE(ctx->pollptrs);
  ------------------
  |  |  373|    819|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 819, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 819]
  |  |  ------------------
  ------------------
  596|    819|        SAFE_FREE(ctx->pollfds);
  ------------------
  |  |  373|    819|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 819, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 819]
  |  |  ------------------
  ------------------
  597|    819|    }
  598|       |
  599|       |    SAFE_FREE(ctx);
  ------------------
  |  |  373|    819|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 819, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 819]
  |  |  ------------------
  ------------------
  600|    819|}
ssh_poll_ctx_add:
  647|  1.09k|{
  648|  1.09k|    socket_t fd;
  649|       |
  650|  1.09k|    if (p->ctx != NULL) {
  ------------------
  |  Branch (650:9): [True: 0, False: 1.09k]
  ------------------
  651|       |        /* already attached to a context */
  652|      0|        return -1;
  653|      0|    }
  654|       |
  655|  1.09k|    if (ctx->polls_used == ctx->polls_allocated &&
  ------------------
  |  Branch (655:9): [True: 819, False: 273]
  ------------------
  656|    819|        ssh_poll_ctx_resize(ctx, ctx->polls_allocated + ctx->chunk_size) < 0) {
  ------------------
  |  Branch (656:9): [True: 0, False: 819]
  ------------------
  657|      0|        return -1;
  658|      0|    }
  659|       |
  660|  1.09k|    fd = p->x.fd;
  661|  1.09k|    p->x.idx = ctx->polls_used++;
  662|  1.09k|    ctx->pollptrs[p->x.idx] = p;
  663|  1.09k|    ctx->pollfds[p->x.idx].fd = fd;
  664|  1.09k|    ctx->pollfds[p->x.idx].events = p->events;
  665|  1.09k|    ctx->pollfds[p->x.idx].revents = 0;
  666|  1.09k|    p->ctx = ctx;
  667|       |
  668|  1.09k|    return 0;
  669|  1.09k|}
ssh_poll_ctx_remove:
  697|  1.09k|{
  698|  1.09k|    size_t i;
  699|       |
  700|  1.09k|    i = p->x.idx;
  701|  1.09k|    p->x.fd = ctx->pollfds[i].fd;
  702|  1.09k|    p->ctx = NULL;
  703|       |
  704|  1.09k|    ctx->polls_used--;
  705|       |
  706|       |    /* fill the empty poll slot with the last one */
  707|  1.09k|    if (ctx->polls_used > 0 && ctx->polls_used != i) {
  ------------------
  |  Branch (707:9): [True: 0, False: 1.09k]
  |  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|  1.09k|    if (ctx->polls_allocated - ctx->polls_used > ctx->chunk_size) {
  ------------------
  |  Branch (714:9): [True: 0, False: 1.09k]
  ------------------
  715|      0|        ssh_poll_ctx_resize(ctx, ctx->polls_allocated - ctx->chunk_size);
  716|      0|    }
  717|  1.09k|}
ssh_poll_is_locked:
  726|  29.8k|{
  727|  29.8k|    if (p == NULL) {
  ------------------
  |  Branch (727:9): [True: 0, False: 29.8k]
  ------------------
  728|      0|        return false;
  729|      0|    }
  730|  29.8k|    return p->lock_cnt > 0;
  731|  29.8k|}
ssh_poll_ctx_dopoll:
  750|  9.73k|{
  751|  9.73k|    int rc;
  752|  9.73k|    size_t i, used;
  753|  9.73k|    ssh_poll_handle p = NULL;
  754|  9.73k|    socket_t fd;
  755|  9.73k|    int revents;
  756|  9.73k|    struct ssh_timestamp ts;
  757|       |
  758|  9.73k|    if (ctx->polls_used == 0) {
  ------------------
  |  Branch (758:9): [True: 0, False: 9.73k]
  ------------------
  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|  19.4k|    for (i = 0; i < ctx->polls_used; i++) {
  ------------------
  |  Branch (765:17): [True: 9.73k, False: 9.73k]
  ------------------
  766|       |        /* The lock allows only POLLOUT events: drop the rest */
  767|  9.73k|        if (ssh_poll_is_locked(ctx->pollptrs[i])) {
  ------------------
  |  Branch (767:13): [True: 546, False: 9.18k]
  ------------------
  768|    546|            ctx->pollfds[i].events &= POLLOUT;
  769|    546|        }
  770|  9.73k|    }
  771|  9.73k|    ssh_timestamp_init(&ts);
  772|  9.73k|    do {
  773|  9.73k|        int tm = ssh_timeout_update(&ts, timeout);
  774|  9.73k|        rc = ssh_poll(ctx->pollfds, ctx->polls_used, tm);
  775|  9.73k|    } while (rc == -1 && errno == EINTR);
  ------------------
  |  Branch (775:14): [True: 0, False: 9.73k]
  |  Branch (775:26): [True: 0, False: 0]
  ------------------
  776|       |
  777|  9.73k|    if (rc < 0) {
  ------------------
  |  Branch (777:9): [True: 0, False: 9.73k]
  ------------------
  778|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  779|      0|    }
  780|  9.73k|    if (rc == 0) {
  ------------------
  |  Branch (780:9): [True: 0, False: 9.73k]
  ------------------
  781|      0|        return SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  782|      0|    }
  783|       |
  784|  9.73k|    used = ctx->polls_used;
  785|  19.1k|    for (i = 0; i < used && rc > 0; ) {
  ------------------
  |  Branch (785:17): [True: 9.73k, False: 9.45k]
  |  Branch (785:29): [True: 9.73k, False: 0]
  ------------------
  786|  9.73k|        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|  9.73k|        if (ctx->pollptrs[i]->lock_cnt > 2) {
  ------------------
  |  Branch (791:13): [True: 0, False: 9.73k]
  ------------------
  792|      0|            revents &= POLLOUT;
  793|      0|        }
  794|  9.73k|        if (revents == 0) {
  ------------------
  |  Branch (794:13): [True: 0, False: 9.73k]
  ------------------
  795|      0|            i++;
  796|  9.73k|        } else {
  797|  9.73k|            int ret;
  798|       |
  799|  9.73k|            p = ctx->pollptrs[i];
  800|  9.73k|            fd = ctx->pollfds[i].fd;
  801|       |            /* avoid having any event caught during callback */
  802|  9.73k|            ctx->pollfds[i].events = 0;
  803|  9.73k|            p->lock_cnt++;
  804|  9.73k|            if (p->cb && (ret = p->cb(p, fd, revents, p->cb_data)) < 0) {
  ------------------
  |  Branch (804:17): [True: 9.73k, False: 0]
  |  Branch (804:26): [True: 273, False: 9.45k]
  ------------------
  805|    273|                if (ret == -2) {
  ------------------
  |  Branch (805:21): [True: 273, False: 0]
  ------------------
  806|    273|                    return -1;
  807|    273|                }
  808|       |                /* the poll was removed, reload the used counter and start again
  809|       |                 */
  810|      0|                used = ctx->polls_used;
  811|      0|                i = 0;
  812|  9.45k|            } else {
  813|  9.45k|                ctx->pollfds[i].revents = 0;
  814|  9.45k|                ctx->pollfds[i].events = p->events;
  815|  9.45k|                p->lock_cnt--;
  816|  9.45k|                i++;
  817|  9.45k|            }
  818|       |
  819|  9.45k|            rc--;
  820|  9.45k|        }
  821|  9.73k|    }
  822|       |
  823|  9.45k|    return rc;
  824|  9.73k|}
ssh_poll_get_default_ctx:
  834|    546|{
  835|    546|    if (session->default_poll_ctx != NULL) {
  ------------------
  |  Branch (835:9): [True: 0, False: 546]
  ------------------
  836|      0|        return session->default_poll_ctx;
  837|      0|    }
  838|       |    /* 2 is enough for the default one */
  839|    546|    session->default_poll_ctx = ssh_poll_ctx_new(2);
  840|    546|    return session->default_poll_ctx;
  841|    546|}
ssh_event_new:
  866|    273|{
  867|    273|    ssh_event event;
  868|       |
  869|    273|    event = malloc(sizeof(struct ssh_event_struct));
  870|    273|    if (event == NULL) {
  ------------------
  |  Branch (870:9): [True: 0, False: 273]
  ------------------
  871|      0|        return NULL;
  872|      0|    }
  873|    273|    ZERO_STRUCTP(event);
  ------------------
  |  |  379|    273|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (379:34): [True: 273, False: 0]
  |  |  |  Branch (379:85): [Folded, False: 273]
  |  |  ------------------
  ------------------
  874|       |
  875|    273|    event->ctx = ssh_poll_ctx_new(2);
  876|    273|    if (event->ctx == NULL) {
  ------------------
  |  Branch (876:9): [True: 0, False: 273]
  ------------------
  877|      0|        free(event);
  878|      0|        return NULL;
  879|      0|    }
  880|       |
  881|    273|#ifdef WITH_SERVER
  882|    273|    event->sessions = ssh_list_new();
  883|    273|    if (event->sessions == NULL) {
  ------------------
  |  Branch (883:9): [True: 0, False: 273]
  ------------------
  884|      0|        ssh_poll_ctx_free(event->ctx);
  885|      0|        free(event);
  886|      0|        return NULL;
  887|      0|    }
  888|    273|#endif
  889|       |
  890|    273|    return event;
  891|    273|}
ssh_event_add_session:
 1000|    273|{
 1001|    273|    ssh_poll_handle p = NULL;
 1002|    273|#ifdef WITH_SERVER
 1003|    273|    struct ssh_iterator *iterator = NULL;
 1004|    273|#endif
 1005|    273|    int rc;
 1006|       |
 1007|    273|    if (event == NULL || event->ctx == NULL || session == NULL) {
  ------------------
  |  Branch (1007:9): [True: 0, False: 273]
  |  Branch (1007:26): [True: 0, False: 273]
  |  Branch (1007:48): [True: 0, False: 273]
  ------------------
 1008|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1009|      0|    }
 1010|    273|    if (session->default_poll_ctx == NULL) {
  ------------------
  |  Branch (1010:9): [True: 0, False: 273]
  ------------------
 1011|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1012|      0|    }
 1013|    546|    while (session->default_poll_ctx->polls_used > 0) {
  ------------------
  |  Branch (1013:12): [True: 273, False: 273]
  ------------------
 1014|    273|        p = session->default_poll_ctx->pollptrs[0];
 1015|       |        /*
 1016|       |         * ssh_poll_ctx_remove() decrements
 1017|       |         * session->default_poll_ctx->polls_used
 1018|       |         */
 1019|    273|        ssh_poll_ctx_remove(session->default_poll_ctx, p);
 1020|    273|        rc = ssh_poll_ctx_add(event->ctx, p);
 1021|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1021:13): [True: 0, False: 273]
  ------------------
 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|    273|        p->session = session;
 1028|    273|    }
 1029|    273|#ifdef WITH_SERVER
 1030|    273|    iterator = ssh_list_get_iterator(event->sessions);
 1031|    273|    while (iterator != NULL) {
  ------------------
  |  Branch (1031:12): [True: 0, False: 273]
  ------------------
 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|    273|    if (ssh_list_append(event->sessions, session) == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1038:9): [True: 0, False: 273]
  ------------------
 1039|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1040|      0|    }
 1041|    273|#endif
 1042|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
 1043|    273|}
ssh_event_dopoll:
 1082|  2.18k|{
 1083|  2.18k|    int rc;
 1084|       |
 1085|  2.18k|    if (event == NULL || event->ctx == NULL) {
  ------------------
  |  Branch (1085:9): [True: 0, False: 2.18k]
  |  Branch (1085:26): [True: 0, False: 2.18k]
  ------------------
 1086|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1087|      0|    }
 1088|  2.18k|    rc = ssh_poll_ctx_dopoll(event->ctx, timeout);
 1089|  2.18k|    return rc;
 1090|  2.18k|}
ssh_event_free:
 1220|    273|{
 1221|    273|    size_t used, i;
 1222|    273|    ssh_poll_handle p = NULL;
 1223|       |
 1224|    273|    if (event == NULL) {
  ------------------
  |  Branch (1224:9): [True: 0, False: 273]
  ------------------
 1225|      0|        return;
 1226|      0|    }
 1227|       |
 1228|    273|    if (event->ctx != NULL) {
  ------------------
  |  Branch (1228:9): [True: 273, False: 0]
  ------------------
 1229|    273|        used = event->ctx->polls_used;
 1230|    546|        for (i = 0; i < used; i++) {
  ------------------
  |  Branch (1230:21): [True: 273, False: 273]
  ------------------
 1231|    273|            p = event->ctx->pollptrs[i];
 1232|    273|            if (p->session != NULL) {
  ------------------
  |  Branch (1232:17): [True: 273, False: 0]
  ------------------
 1233|    273|                ssh_poll_ctx_remove(event->ctx, p);
 1234|    273|                ssh_poll_ctx_add(p->session->default_poll_ctx, p);
 1235|    273|                p->session = NULL;
 1236|    273|                used = 0;
 1237|    273|            }
 1238|    273|        }
 1239|       |
 1240|    273|        ssh_poll_ctx_free(event->ctx);
 1241|    273|    }
 1242|    273|#ifdef WITH_SERVER
 1243|    273|    if (event->sessions != NULL) {
  ------------------
  |  Branch (1243:9): [True: 273, False: 0]
  ------------------
 1244|    273|        ssh_list_free(event->sessions);
 1245|    273|    }
 1246|    273|#endif
 1247|    273|    free(event);
 1248|    273|}
poll.c:ssh_poll_ctx_resize:
  603|    819|{
  604|    819|    ssh_poll_handle *pollptrs = NULL;
  605|    819|    ssh_pollfd_t *pollfds = NULL;
  606|       |
  607|    819|    pollptrs = realloc(ctx->pollptrs, sizeof(ssh_poll_handle) * new_size);
  608|    819|    if (pollptrs == NULL) {
  ------------------
  |  Branch (608:9): [True: 0, False: 819]
  ------------------
  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|    819|    ctx->pollptrs = pollptrs;
  613|       |
  614|    819|    pollfds = realloc(ctx->pollfds, sizeof(ssh_pollfd_t) * new_size);
  615|    819|    if (pollfds == NULL) {
  ------------------
  |  Branch (615:9): [True: 0, False: 819]
  ------------------
  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|    819|    ctx->pollfds = pollfds;
  633|    819|    ctx->polls_allocated = new_size;
  634|       |
  635|    819|    return SSH_OK;
  ------------------
  |  |  316|    819|#define SSH_OK 0     /* No error */
  ------------------
  636|    819|}

ssh_scp_new:
   67|    273|{
   68|    273|    ssh_scp scp = NULL;
   69|       |
   70|    273|    if (session == NULL || location == NULL) {
  ------------------
  |  Branch (70:9): [True: 0, False: 273]
  |  Branch (70:28): [True: 0, False: 273]
  ------------------
   71|      0|        goto error;
   72|      0|    }
   73|       |
   74|    273|    scp = (ssh_scp)calloc(1, sizeof(struct ssh_scp_struct));
   75|    273|    if (scp == NULL) {
  ------------------
  |  Branch (75:9): [True: 0, False: 273]
  ------------------
   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|    273|    if ((mode & ~SSH_SCP_RECURSIVE) != SSH_SCP_WRITE &&
  ------------------
  |  Branch (81:9): [True: 273, False: 0]
  ------------------
   82|    273|        (mode & ~SSH_SCP_RECURSIVE) != SSH_SCP_READ)
  ------------------
  |  Branch (82:9): [True: 0, False: 273]
  ------------------
   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|    273|    if (strlen(location) > 32 * 1024) {
  ------------------
  |  Branch (89:9): [True: 0, False: 273]
  ------------------
   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|    273|    scp->location = strdup(location);
   96|    273|    if (scp->location == NULL) {
  ------------------
  |  Branch (96:9): [True: 0, False: 273]
  ------------------
   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|    273|    scp->session = session;
  103|    273|    scp->mode = mode & ~SSH_SCP_RECURSIVE;
  104|    273|    scp->recursive = (mode & SSH_SCP_RECURSIVE) != 0;
  105|    273|    scp->channel = NULL;
  106|    273|    scp->state = SSH_SCP_NEW;
  107|       |
  108|    273|    return scp;
  109|       |
  110|      0|error:
  111|      0|    ssh_scp_free(scp);
  112|       |    return NULL;
  113|    273|}
ssh_scp_init:
  127|    273|{
  128|    273|    int rc;
  129|    273|    char execbuffer[PATH_MAX] = {0};
  130|    273|    char *quoted_location = NULL;
  131|    273|    size_t quoted_location_len = 0;
  132|    273|    size_t scp_location_len;
  133|       |
  134|    273|    if (scp == NULL) {
  ------------------
  |  Branch (134:9): [True: 0, False: 273]
  ------------------
  135|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  136|      0|    }
  137|       |
  138|    273|    if (scp->state != SSH_SCP_NEW) {
  ------------------
  |  Branch (138:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (scp->location == NULL) {
  ------------------
  |  Branch (144:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_DEBUG, "Initializing scp session %s %son location '%s'",
  ------------------
  |  |  281|  1.09k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 273]
  |  |  |  Branch (281:34): [True: 0, False: 273]
  |  |  ------------------
  ------------------
  151|    273|            scp->mode == SSH_SCP_WRITE?"write":"read",
  152|    273|            scp->recursive ? "recursive " : "",
  153|    273|            scp->location);
  154|       |
  155|    273|    scp->channel = ssh_channel_new(scp->session);
  156|    273|    if (scp->channel == NULL) {
  ------------------
  |  Branch (156:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_channel_open_session(scp->channel);
  164|    273|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (164:9): [True: 0, False: 273]
  ------------------
  165|      0|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  166|      0|                      "Failed to open channel for scp");
  167|      0|        scp->state = SSH_SCP_ERROR;
  168|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  169|      0|    }
  170|       |
  171|       |    /* In the worst case, each character would be replaced by 3 plus the string
  172|       |     * terminator '\0' */
  173|    273|    scp_location_len = strlen(scp->location);
  174|    273|    quoted_location_len = ((size_t)3 * scp_location_len) + 1;
  175|       |    /* Paranoia check */
  176|    273|    if (quoted_location_len < scp_location_len) {
  ------------------
  |  Branch (176:9): [True: 0, False: 273]
  ------------------
  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|    273|    quoted_location = (char *)calloc(1, quoted_location_len);
  184|    273|    if (quoted_location == NULL) {
  ------------------
  |  Branch (184:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_quote_file_name(scp->location, quoted_location,
  192|    273|                             quoted_location_len);
  193|    273|    if (rc <= 0) {
  ------------------
  |  Branch (193:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (scp->session->flags & SSH_SESSION_FLAG_SCP_QUOTING_BROKEN) {
  ------------------
  |  |   95|    273|#define SSH_SESSION_FLAG_SCP_QUOTING_BROKEN 0x0040
  ------------------
  |  Branch (203:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (scp->mode == SSH_SCP_WRITE) {
  ------------------
  |  Branch (212:9): [True: 0, False: 273]
  ------------------
  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|    273|    } else {
  216|    273|        snprintf(execbuffer, sizeof(execbuffer), "scp -f %s %s",
  217|    273|                scp->recursive ? "-r" : "", quoted_location);
  ------------------
  |  Branch (217:17): [True: 0, False: 273]
  ------------------
  218|    273|    }
  219|       |
  220|    273|    SAFE_FREE(quoted_location);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  221|       |
  222|    273|    SSH_LOG(SSH_LOG_DEBUG, "Executing command: %s", execbuffer);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  223|       |
  224|    273|    rc = ssh_channel_request_exec(scp->channel, execbuffer);
  225|    273|    if (rc == SSH_ERROR){
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (225:9): [True: 273, False: 0]
  ------------------
  226|    273|        ssh_set_error(scp->session, SSH_FATAL,
  ------------------
  |  |  311|    273|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  227|    273|                      "Failed executing command: %s", execbuffer);
  228|    273|        scp->state = SSH_SCP_ERROR;
  229|    273|        return SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  230|    273|    }
  231|       |
  232|      0|    if (scp->mode == SSH_SCP_WRITE) {
  ------------------
  |  Branch (232:9): [True: 0, False: 0]
  ------------------
  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|      0|    } else {
  238|      0|        ssh_channel_write(scp->channel, "", 1);
  239|      0|    }
  240|       |
  241|      0|    if (scp->mode == SSH_SCP_WRITE) {
  ------------------
  |  Branch (241:9): [True: 0, False: 0]
  ------------------
  242|      0|        scp->state = SSH_SCP_WRITE_INITED;
  243|      0|    } else {
  244|      0|        scp->state = SSH_SCP_READ_INITED;
  245|      0|    }
  246|       |
  247|      0|    return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  248|      0|}
ssh_scp_close:
  262|    273|{
  263|    273|    char buffer[128] = {0};
  264|    273|    int rc;
  265|       |
  266|    273|    if (scp == NULL) {
  ------------------
  |  Branch (266:9): [True: 0, False: 273]
  ------------------
  267|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  268|      0|    }
  269|       |
  270|    273|    if (scp->channel != NULL) {
  ------------------
  |  Branch (270:9): [True: 273, False: 0]
  ------------------
  271|    273|        if (ssh_channel_send_eof(scp->channel) == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (271:13): [True: 0, False: 273]
  ------------------
  272|      0|            scp->state = SSH_SCP_ERROR;
  273|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  274|      0|        }
  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|    273|        while (!ssh_channel_is_eof(scp->channel)) {
  ------------------
  |  Branch (279:16): [True: 273, False: 0]
  ------------------
  280|    273|            rc = ssh_channel_read(scp->channel, buffer, sizeof(buffer), 0);
  281|    273|            if (rc == SSH_ERROR || rc == SSH_AGAIN || rc == 0) {
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
                          if (rc == SSH_ERROR || rc == SSH_AGAIN || rc == 0) {
  ------------------
  |  |  318|    273|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  |  Branch (281:17): [True: 273, False: 0]
  |  Branch (281:36): [True: 0, False: 0]
  |  Branch (281:55): [True: 0, False: 0]
  ------------------
  282|    273|                break;
  283|    273|            }
  284|    273|        }
  285|       |
  286|    273|        if (ssh_channel_close(scp->channel) == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (286:13): [True: 0, False: 273]
  ------------------
  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|    273|        ssh_channel_free(scp->channel);
  292|    273|        scp->channel = NULL;
  293|    273|    }
  294|       |
  295|    273|    scp->state = SSH_SCP_NEW;
  296|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  297|    273|}
ssh_scp_free:
  309|    273|{
  310|    273|    if (scp == NULL) {
  ------------------
  |  Branch (310:9): [True: 0, False: 273]
  ------------------
  311|      0|        return;
  312|      0|    }
  313|       |
  314|    273|    if (scp->state != SSH_SCP_NEW) {
  ------------------
  |  Branch (314:9): [True: 0, False: 273]
  ------------------
  315|      0|        ssh_scp_close(scp);
  316|      0|    }
  317|       |
  318|    273|    if (scp->channel) {
  ------------------
  |  Branch (318:9): [True: 0, False: 273]
  ------------------
  319|      0|        ssh_channel_free(scp->channel);
  320|      0|    }
  321|       |
  322|    273|    SAFE_FREE(scp->location);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  323|    273|    SAFE_FREE(scp->request_name);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  324|    273|    SAFE_FREE(scp->warning);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  325|       |    SAFE_FREE(scp);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  326|    273|}

server_set_kex:
   93|    546|{
   94|    546|    struct ssh_kex_struct *server = &session->next_crypto->server_kex;
   95|    546|    int i, j, rc;
   96|    546|    const char *wanted = NULL, *allowed = NULL;
   97|    546|    char *kept = NULL;
   98|    546|    char hostkeys[128] = {0};
   99|    546|    enum ssh_keytypes_e keytype;
  100|    546|    size_t len;
  101|    546|    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|    546|    if (server->methods[0] != NULL) {
  ------------------
  |  Branch (108:9): [True: 273, False: 273]
  ------------------
  109|    273|        return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  110|    273|    }
  111|       |
  112|    273|    ok = ssh_get_random(server->cookie, 16, 0);
  113|    273|    if (!ok) {
  ------------------
  |  Branch (113:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (session->srv.ed25519_key != NULL) {
  ------------------
  |  Branch (118:9): [True: 273, False: 0]
  ------------------
  119|    273|        snprintf(hostkeys,
  120|    273|                 sizeof(hostkeys),
  121|    273|                 "%s",
  122|    273|                 ssh_key_type_to_char(ssh_key_type(session->srv.ed25519_key)));
  123|    273|    }
  124|    273|#ifdef HAVE_ECC
  125|    273|    if (session->srv.ecdsa_key != NULL) {
  ------------------
  |  Branch (125:9): [True: 0, False: 273]
  ------------------
  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|    273|#endif
  131|    273|    if (session->srv.rsa_key != NULL) {
  ------------------
  |  Branch (131:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (session->opts.wanted_methods[SSH_HOSTKEYS]) {
  ------------------
  |  Branch (144:9): [True: 0, False: 273]
  ------------------
  145|      0|        allowed = session->opts.wanted_methods[SSH_HOSTKEYS];
  146|    273|    } else {
  147|    273|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|    273|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 273]
  |  |  ------------------
  ------------------
  148|      0|            allowed = ssh_kex_get_fips_methods(SSH_HOSTKEYS);
  149|    273|        } else {
  150|    273|            allowed = ssh_kex_get_default_methods(SSH_HOSTKEYS);
  151|    273|        }
  152|    273|    }
  153|       |
  154|    273|    if (strlen(hostkeys) != 0) {
  ------------------
  |  Branch (154:9): [True: 273, False: 0]
  ------------------
  155|       |        /* It is expected for the list of allowed hostkeys to be ordered by
  156|       |         * preference */
  157|    273|        kept =
  158|    273|            ssh_find_all_matching(hostkeys[0] == ',' ? hostkeys + 1 : hostkeys,
  ------------------
  |  Branch (158:35): [True: 0, False: 273]
  ------------------
  159|    273|                                  allowed);
  160|    273|        if (kept == NULL) {
  ------------------
  |  Branch (160:13): [True: 0, False: 273]
  ------------------
  161|       |            /* Nothing was allowed */
  162|      0|            return -1;
  163|      0|        }
  164|       |
  165|    273|        rc = ssh_options_set_algo(session,
  166|    273|                                  SSH_HOSTKEYS,
  167|    273|                                  kept,
  168|    273|                                  &session->opts.wanted_methods[SSH_HOSTKEYS]);
  169|    273|        SAFE_FREE(kept);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  170|    273|        if (rc < 0) {
  ------------------
  |  Branch (170:13): [True: 0, False: 273]
  ------------------
  171|      0|            return -1;
  172|      0|        }
  173|    273|    }
  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|  3.00k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.00k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (201:17): [True: 2.73k, False: 273]
  ------------------
  202|  2.73k|        wanted = session->opts.wanted_methods[i];
  203|  2.73k|        if (wanted == NULL) {
  ------------------
  |  Branch (203:13): [True: 1.36k, False: 1.36k]
  ------------------
  204|  1.36k|            if (ssh_fips_mode()) {
  ------------------
  |  |  115|  1.36k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 1.36k]
  |  |  ------------------
  ------------------
  205|      0|                wanted = ssh_kex_get_fips_methods(i);
  206|  1.36k|            } else {
  207|  1.36k|                wanted = ssh_kex_get_default_methods(i);
  208|  1.36k|            }
  209|  1.36k|        }
  210|  2.73k|        if (wanted == NULL) {
  ------------------
  |  Branch (210:13): [True: 0, False: 2.73k]
  ------------------
  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|  2.73k|        server->methods[i] = strdup(wanted);
  218|  2.73k|        if (server->methods[i] == NULL) {
  ------------------
  |  Branch (218:13): [True: 0, False: 2.73k]
  ------------------
  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|  2.73k|    }
  225|       |
  226|       |    /* Do not append the extensions during rekey */
  227|    273|    if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) {
  ------------------
  |  |   78|    273|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (227:9): [True: 0, False: 273]
  ------------------
  228|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  229|      0|    }
  230|       |
  231|    273|    rc = ssh_kex_append_extensions(session, server);
  232|    273|    return rc;
  233|    273|}
ssh_packet_kexdh_init:
  310|    273|SSH_PACKET_CALLBACK(ssh_packet_kexdh_init){
  311|    273|  (void)packet;
  312|    273|  (void)type;
  313|    273|  (void)user;
  314|       |
  315|    273|  SSH_LOG(SSH_LOG_PACKET,"Received SSH_MSG_KEXDH_INIT");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  316|    273|  if(session->dh_handshake_state != DH_STATE_INIT){
  ------------------
  |  Branch (316:6): [True: 0, False: 273]
  ------------------
  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|    273|  if (session->first_kex_follows_guess_wrong != 0) {
  ------------------
  |  Branch (323:7): [True: 0, False: 273]
  ------------------
  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|    273|  SSH_LOG(SSH_LOG_DEBUG, "Calling next KEXDH handler");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  331|    273|  return SSH_PACKET_NOT_USED;
  ------------------
  |  |  640|    273|#define SSH_PACKET_NOT_USED 2
  ------------------
  332|    273|}
ssh_get_key_params:
  354|    273|{
  355|    273|    ssh_key pubkey = NULL;
  356|    273|    ssh_string pubkey_blob = NULL;
  357|    273|    int rc;
  358|       |
  359|    273|    switch(session->srv.hostkey) {
  360|      0|      case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (360:7): [True: 0, False: 273]
  ------------------
  361|      0|        *privkey = session->srv.rsa_key;
  362|      0|        break;
  363|      0|      case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (363:7): [True: 0, False: 273]
  ------------------
  364|      0|      case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (364:7): [True: 0, False: 273]
  ------------------
  365|      0|      case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (365:7): [True: 0, False: 273]
  ------------------
  366|      0|        *privkey = session->srv.ecdsa_key;
  367|      0|        break;
  368|    273|      case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (368:7): [True: 273, False: 0]
  ------------------
  369|    273|        *privkey = session->srv.ed25519_key;
  370|    273|        break;
  371|      0|      case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (371:7): [True: 0, False: 273]
  ------------------
  372|      0|      case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (372:7): [True: 0, False: 273]
  ------------------
  373|      0|      default:
  ------------------
  |  Branch (373:7): [True: 0, False: 273]
  ------------------
  374|      0|        *privkey = NULL;
  375|    273|    }
  376|       |
  377|    273|    *digest = session->srv.hostkey_digest;
  378|    273|    rc = ssh_pki_export_privkey_to_pubkey(*privkey, &pubkey);
  379|    273|    if (rc < 0) {
  ------------------
  |  Branch (379:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_pki_export_pubkey_blob(pubkey, &pubkey_blob);
  387|    273|    ssh_key_free(pubkey);
  388|    273|    if (rc < 0) {
  ------------------
  |  Branch (388:9): [True: 0, False: 273]
  ------------------
  389|      0|      ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  390|      0|      return -1;
  391|      0|    }
  392|       |
  393|    273|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  394|    273|    SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  915|    273|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 273, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 273]
  |  |  ------------------
  ------------------
  395|    273|    if (rc != 0) {
  ------------------
  |  Branch (395:9): [True: 0, False: 273]
  ------------------
  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|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  403|    273|}
ssh_set_auth_methods:
  613|    273|{
  614|       |    /* accept only methods in range */
  615|    273|    session->auth.supported_methods = (uint32_t)auth_methods & 0x3fU;
  616|    273|}
ssh_handle_key_exchange:
  645|    273|{
  646|    273|    int rc;
  647|       |
  648|    273|    if (session->session_state != SSH_SESSION_STATE_NONE) {
  ------------------
  |  Branch (648:9): [True: 0, False: 273]
  ------------------
  649|      0|        goto pending;
  650|      0|    }
  651|       |
  652|    273|    rc = ssh_send_banner(session, 1);
  653|    273|    if (rc < 0) {
  ------------------
  |  Branch (653:9): [True: 0, False: 273]
  ------------------
  654|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  655|      0|    }
  656|       |
  657|    273|    session->alive = 1;
  658|       |
  659|    273|    session->ssh_connection_callback = ssh_server_connection_callback;
  660|    273|    session->session_state = SSH_SESSION_STATE_SOCKET_CONNECTED;
  661|    273|    ssh_socket_set_callbacks(session->socket,&session->socket_callbacks);
  662|    273|    session->socket_callbacks.data = callback_receive_banner;
  663|    273|    session->socket_callbacks.exception = ssh_socket_exception_callback;
  664|    273|    session->socket_callbacks.userdata = session;
  665|       |
  666|    273|    rc = server_set_kex(session);
  667|    273|    if (rc < 0) {
  ------------------
  |  Branch (667:9): [True: 0, False: 273]
  ------------------
  668|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  669|      0|    }
  670|    273|pending:
  671|    273|    rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_USER,
  ------------------
  |  |  101|    273|#define SSH_TIMEOUT_USER -2
  ------------------
  672|    273|                                        ssh_server_kex_termination,session);
  673|    273|    SSH_LOG(SSH_LOG_PACKET, "ssh_handle_key_exchange: current state : %d",
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  674|    273|            session->session_state);
  675|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (675:9): [True: 0, False: 273]
  ------------------
  676|      0|        return rc;
  677|      0|    }
  678|    273|    if (session->session_state == SSH_SESSION_STATE_ERROR ||
  ------------------
  |  Branch (678:9): [True: 0, False: 273]
  ------------------
  679|    273|        session->session_state == SSH_SESSION_STATE_DISCONNECTED) {
  ------------------
  |  Branch (679:9): [True: 0, False: 273]
  ------------------
  680|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  681|      0|    }
  682|       |
  683|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  684|    273|}
ssh_message_service_reply_success:
  834|    273|{
  835|    273|    ssh_session session = NULL;
  836|    273|    int rc;
  837|       |
  838|    273|    if (msg == NULL) {
  ------------------
  |  Branch (838:9): [True: 0, False: 273]
  ------------------
  839|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  840|      0|    }
  841|    273|    session = msg->session;
  842|       |
  843|    273|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  844|    273|            "Sending a SERVICE_ACCEPT for service %s", msg->service_request.service);
  845|       |
  846|    273|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  847|    273|                         "bs",
  848|    273|                         SSH2_MSG_SERVICE_ACCEPT,
  849|    273|                         msg->service_request.service);
  850|    273|    if (rc != SSH_OK){
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (850:9): [True: 0, False: 273]
  ------------------
  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|    273|    rc = ssh_packet_send(msg->session);
  855|    273|    return rc;
  856|    273|}
ssh_message_reply_default:
  933|    273|int ssh_message_reply_default(ssh_message msg) {
  934|    273|  if (msg == NULL) {
  ------------------
  |  Branch (934:7): [True: 0, False: 273]
  ------------------
  935|      0|    return -1;
  936|      0|  }
  937|       |
  938|    273|  switch(msg->type) {
  939|      0|    case SSH_REQUEST_AUTH:
  ------------------
  |  Branch (939:5): [True: 0, False: 273]
  ------------------
  940|      0|      return ssh_auth_reply_default(msg->session, 0);
  941|      0|    case SSH_REQUEST_CHANNEL_OPEN:
  ------------------
  |  Branch (941:5): [True: 0, False: 273]
  ------------------
  942|      0|      return ssh_message_channel_request_open_reply_default(msg);
  943|      0|    case SSH_REQUEST_CHANNEL:
  ------------------
  |  Branch (943:5): [True: 0, False: 273]
  ------------------
  944|      0|      return ssh_message_channel_request_reply_default(msg);
  945|    273|    case SSH_REQUEST_SERVICE:
  ------------------
  |  Branch (945:5): [True: 273, False: 0]
  ------------------
  946|    273|      return ssh_message_service_request_reply_default(msg);
  947|      0|    case SSH_REQUEST_GLOBAL:
  ------------------
  |  Branch (947:5): [True: 0, False: 273]
  ------------------
  948|      0|      return ssh_message_global_request_reply_default(msg);
  949|      0|    default:
  ------------------
  |  Branch (949:5): [True: 0, False: 273]
  ------------------
  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|    273|  }
  955|       |
  956|      0|  return -1;
  957|    273|}
ssh_auth_reply_success:
 1192|    273|{
 1193|    273|    struct ssh_crypto_struct *crypto = NULL;
 1194|    273|    int r;
 1195|       |
 1196|    273|    if (session == NULL) {
  ------------------
  |  Branch (1196:9): [True: 0, False: 273]
  ------------------
 1197|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1198|      0|    }
 1199|       |
 1200|    273|    if (partial) {
  ------------------
  |  Branch (1200:9): [True: 0, False: 273]
  ------------------
 1201|      0|        return ssh_auth_reply_default(session, partial);
 1202|      0|    }
 1203|       |
 1204|    273|    r = ssh_buffer_add_u8(session->out_buffer,SSH2_MSG_USERAUTH_SUCCESS);
  ------------------
  |  |   38|    273|#define SSH2_MSG_USERAUTH_SUCCESS 52
  ------------------
 1205|    273|    if (r < 0) {
  ------------------
  |  Branch (1205:9): [True: 0, False: 273]
  ------------------
 1206|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1207|      0|    }
 1208|       |
 1209|    273|    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|    273|    session->session_state = SSH_SESSION_STATE_AUTHENTICATED;
 1218|    273|    session->flags |= SSH_SESSION_FLAG_AUTHENTICATED;
  ------------------
  |  |   78|    273|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
 1219|       |
 1220|    273|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
 1221|    273|    if (crypto != NULL && crypto->delayed_compress_out) {
  ------------------
  |  Branch (1221:9): [True: 273, False: 0]
  |  Branch (1221:27): [True: 0, False: 273]
  ------------------
 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|    273|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
 1227|    273|    if (crypto != NULL && crypto->delayed_compress_in) {
  ------------------
  |  Branch (1227:9): [True: 273, False: 0]
  |  Branch (1227:27): [True: 0, False: 273]
  ------------------
 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|    273|    return r;
 1232|    273|}
ssh_message_auth_reply_success:
 1246|    273|int ssh_message_auth_reply_success(ssh_message msg, int partial) {
 1247|    273|	if(msg == NULL)
  ------------------
  |  Branch (1247:5): [True: 0, False: 273]
  ------------------
 1248|      0|		return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1249|    273|	return ssh_auth_reply_success(msg->session, partial);
 1250|    273|}
server.c:ssh_server_connection_callback:
  412|    819|{
  413|    819|    int rc;
  414|       |
  415|    819|    switch (session->session_state) {
  416|      0|    case SSH_SESSION_STATE_NONE:
  ------------------
  |  Branch (416:5): [True: 0, False: 819]
  ------------------
  417|      0|    case SSH_SESSION_STATE_CONNECTING:
  ------------------
  |  Branch (417:5): [True: 0, False: 819]
  ------------------
  418|      0|    case SSH_SESSION_STATE_SOCKET_CONNECTED:
  ------------------
  |  Branch (418:5): [True: 0, False: 819]
  ------------------
  419|      0|        break;
  420|    273|    case SSH_SESSION_STATE_BANNER_RECEIVED:
  ------------------
  |  Branch (420:5): [True: 273, False: 546]
  ------------------
  421|    273|        if (session->clientbanner == NULL) {
  ------------------
  |  Branch (421:13): [True: 0, False: 273]
  ------------------
  422|      0|            goto error;
  423|      0|        }
  424|    273|        set_status(session, 0.4f);
  ------------------
  |  |   65|    273|#define set_status(session, status) do {\
  |  |   66|    273|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 273]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    273|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    273|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 273]
  |  |  ------------------
  ------------------
  425|    273|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  426|    273|                "SSH client banner: %s", session->clientbanner);
  427|       |
  428|       |        /* Here we analyze the different protocols the server allows. */
  429|    273|        rc = ssh_analyze_banner(session, 1);
  430|    273|        if (rc < 0) {
  ------------------
  |  Branch (430:13): [True: 0, False: 273]
  ------------------
  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|    273|        ssh_packet_register_socket_callback(session, session->socket);
  439|       |
  440|    273|        ssh_packet_set_default_callbacks(session);
  441|    273|        set_status(session, 0.5f);
  ------------------
  |  |   65|    273|#define set_status(session, status) do {\
  |  |   66|    273|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 273]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    273|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    273|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 273]
  |  |  ------------------
  ------------------
  442|    273|        session->session_state = SSH_SESSION_STATE_INITIAL_KEX;
  443|    273|        rc = ssh_send_kex(session);
  444|    273|        if (rc < 0) {
  ------------------
  |  Branch (444:13): [True: 0, False: 273]
  ------------------
  445|      0|            goto error;
  446|      0|        }
  447|    273|        break;
  448|    273|    case SSH_SESSION_STATE_INITIAL_KEX:
  ------------------
  |  Branch (448:5): [True: 0, False: 819]
  ------------------
  449|       |        /* TODO: This state should disappear in favor of get_key handle */
  450|      0|        break;
  451|    273|    case SSH_SESSION_STATE_KEXINIT_RECEIVED:
  ------------------
  |  Branch (451:5): [True: 273, False: 546]
  ------------------
  452|    273|        set_status(session, 0.6f);
  ------------------
  |  |   65|    273|#define set_status(session, status) do {\
  |  |   66|    273|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 273]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    273|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    273|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 273]
  |  |  ------------------
  ------------------
  453|    273|        if ((session->flags & SSH_SESSION_FLAG_KEXINIT_SENT) == 0) {
  ------------------
  |  |   86|    273|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
  |  Branch (453:13): [True: 0, False: 273]
  ------------------
  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|    273|        ssh_list_kex(&session->next_crypto->client_kex); // log client kex
  465|    273|        rc = ssh_kex_select_methods(session);
  466|    273|        if (rc < 0) {
  ------------------
  |  Branch (466:13): [True: 0, False: 273]
  ------------------
  467|      0|            goto error;
  468|      0|        }
  469|    273|        rc = crypt_set_algorithms_server(session);
  470|    273|        if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (470:13): [True: 0, False: 273]
  ------------------
  471|      0|            goto error;
  472|      0|        }
  473|    273|        set_status(session, 0.8f);
  ------------------
  |  |   65|    273|#define set_status(session, status) do {\
  |  |   66|    273|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 273]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    273|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    273|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 273]
  |  |  ------------------
  ------------------
  474|    273|        session->session_state = SSH_SESSION_STATE_DH;
  475|    273|        break;
  476|    273|    case SSH_SESSION_STATE_DH:
  ------------------
  |  Branch (476:5): [True: 273, False: 546]
  ------------------
  477|    273|        if (session->dh_handshake_state == DH_STATE_FINISHED) {
  ------------------
  |  Branch (477:13): [True: 273, False: 0]
  ------------------
  478|       |
  479|    273|            rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_IN);
  480|    273|            if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (480:17): [True: 0, False: 273]
  ------------------
  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|    273|            if (session->extensions & SSH_EXT_NEGOTIATION &&
  ------------------
  |  |  123|    546|#define SSH_EXT_NEGOTIATION     0x01
  ------------------
  |  Branch (489:17): [True: 273, False: 0]
  ------------------
  490|    273|                session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (490:17): [True: 273, 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|    273|                if (session->connected == 0) {
  ------------------
  |  Branch (505:21): [True: 273, False: 0]
  ------------------
  506|    273|                    ssh_server_send_extensions(session);
  507|    273|                }
  508|    273|            }
  509|       |
  510|    273|            set_status(session, 1.0f);
  ------------------
  |  |   65|    273|#define set_status(session, status) do {\
  |  |   66|    273|        if (session->common.callbacks && session->common.callbacks->connect_status_function) \
  |  |  ------------------
  |  |  |  Branch (66:13): [True: 0, False: 273]
  |  |  |  Branch (66:42): [True: 0, False: 0]
  |  |  ------------------
  |  |   67|    273|            session->common.callbacks->connect_status_function(session->common.callbacks->userdata, status); \
  |  |   68|    273|    } while (0)
  |  |  ------------------
  |  |  |  Branch (68:14): [Folded, False: 273]
  |  |  ------------------
  ------------------
  511|    273|            session->connected = 1;
  512|    273|            session->session_state = SSH_SESSION_STATE_AUTHENTICATING;
  513|    273|            if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED)
  ------------------
  |  |   78|    273|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (513:17): [True: 0, False: 273]
  ------------------
  514|      0|                session->session_state = SSH_SESSION_STATE_AUTHENTICATED;
  515|       |
  516|    273|        }
  517|    273|        break;
  518|    273|    case SSH_SESSION_STATE_AUTHENTICATING:
  ------------------
  |  Branch (518:5): [True: 0, False: 819]
  ------------------
  519|      0|        break;
  520|      0|    case SSH_SESSION_STATE_ERROR:
  ------------------
  |  Branch (520:5): [True: 0, False: 819]
  ------------------
  521|      0|        goto error;
  522|      0|    default:
  ------------------
  |  Branch (522:5): [True: 0, False: 819]
  ------------------
  523|      0|        ssh_set_error(session, SSH_FATAL, "Invalid state %d",
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  524|    819|                      session->session_state);
  525|    819|    }
  526|       |
  527|    819|    return;
  528|    819|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|    273|{
  269|    273|    int rc;
  270|    273|    const char *hostkey_algorithms = NULL;
  271|       |
  272|    273|    SSH_LOG(SSH_LOG_PACKET, "Sending SSH_MSG_EXT_INFO");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  273|       |
  274|    273|    if (session->opts.pubkey_accepted_types) {
  ------------------
  |  Branch (274:9): [True: 0, False: 273]
  ------------------
  275|      0|        hostkey_algorithms = session->opts.pubkey_accepted_types;
  276|    273|    } else {
  277|    273|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|    273|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 273]
  |  |  ------------------
  ------------------
  278|      0|            hostkey_algorithms = ssh_kex_get_fips_methods(SSH_HOSTKEYS);
  279|    273|        } else {
  280|       |            /* There are no restrictions to the accepted public keys */
  281|    273|            hostkey_algorithms = ssh_kex_get_default_methods(SSH_HOSTKEYS);
  282|    273|        }
  283|    273|    }
  284|       |
  285|    273|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    273|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    273|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    273|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    273|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    273|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    273|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  286|    273|                         "bdssssss",
  287|    273|                         SSH2_MSG_EXT_INFO,
  288|    273|                         3, /* nr. of extensions */
  289|    273|                         "server-sig-algs",
  290|    273|                         hostkey_algorithms,
  291|    273|                         "publickey-hostbound@openssh.com",
  292|    273|                         "0",
  293|    273|                         "ping@openssh.com",
  294|    273|                         "0");
  295|    273|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (295:9): [True: 0, False: 273]
  ------------------
  296|      0|        goto error;
  297|      0|    }
  298|       |
  299|    273|    if (ssh_packet_send(session) == SSH_ERROR) {
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (299:9): [True: 0, False: 273]
  ------------------
  300|      0|        goto error;
  301|      0|    }
  302|       |
  303|    273|    return 0;
  304|      0|error:
  305|      0|    ssh_buffer_reinit(session->out_buffer);
  306|       |
  307|      0|    return -1;
  308|    273|}
server.c:callback_receive_banner:
  546|    273|{
  547|    273|    char *buffer = (char *)data;
  548|    273|    ssh_session session = (ssh_session)user;
  549|    273|    char *str = NULL;
  550|    273|    size_t i;
  551|    273|    size_t processed = 0;
  552|       |
  553|  6.27k|    for (i = 0; i < len; i++) {
  ------------------
  |  Branch (553:17): [True: 6.27k, False: 0]
  ------------------
  554|  6.27k|#ifdef WITH_PCAP
  555|  6.27k|        if (session->pcap_ctx && buffer[i] == '\n') {
  ------------------
  |  Branch (555:13): [True: 0, False: 6.27k]
  |  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|  6.27k|#endif
  563|  6.27k|        if (buffer[i] == '\r') {
  ------------------
  |  Branch (563:13): [True: 273, False: 6.00k]
  ------------------
  564|    273|            buffer[i] = '\0';
  565|    273|        }
  566|       |
  567|  6.27k|        if (buffer[i] == '\n') {
  ------------------
  |  Branch (567:13): [True: 273, False: 6.00k]
  ------------------
  568|    273|            buffer[i] = '\0';
  569|       |
  570|    273|            str = strdup(buffer);
  571|    273|            if (str == NULL) {
  ------------------
  |  Branch (571:17): [True: 0, False: 273]
  ------------------
  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|    273|            processed = i + 1;
  578|    273|            session->clientbanner = str;
  579|    273|            session->session_state = SSH_SESSION_STATE_BANNER_RECEIVED;
  580|    273|            SSH_LOG(SSH_LOG_PACKET, "Received banner: %s", str);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  581|    273|            session->ssh_connection_callback(session);
  582|       |
  583|    273|            return processed;
  584|    273|        }
  585|       |
  586|  6.00k|        if (i > 127) {
  ------------------
  |  Branch (586:13): [True: 0, False: 6.00k]
  ------------------
  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|  6.00k|    }
  595|       |
  596|      0|    return processed;
  597|    273|}
server.c:ssh_server_kex_termination:
  600|  2.69k|static int ssh_server_kex_termination(void *s){
  601|  2.69k|  ssh_session session = s;
  602|  2.69k|  if (session->session_state != SSH_SESSION_STATE_ERROR &&
  ------------------
  |  Branch (602:7): [True: 2.69k, False: 0]
  ------------------
  603|  2.69k|      session->session_state != SSH_SESSION_STATE_AUTHENTICATING &&
  ------------------
  |  Branch (603:7): [True: 2.42k, False: 273]
  ------------------
  604|  2.42k|      session->session_state != SSH_SESSION_STATE_AUTHENTICATED &&
  ------------------
  |  Branch (604:7): [True: 2.42k, False: 0]
  ------------------
  605|  2.42k|      session->session_state != SSH_SESSION_STATE_DISCONNECTED)
  ------------------
  |  Branch (605:7): [True: 2.42k, False: 0]
  ------------------
  606|  2.42k|    return 0;
  607|    273|  else
  608|    273|    return 1;
  609|  2.69k|}
server.c:ssh_message_service_request_reply_default:
  821|    273|static int ssh_message_service_request_reply_default(ssh_message msg) {
  822|       |  /* The only return code accepted by specifications are success or disconnect */
  823|    273|  return ssh_message_service_reply_success(msg);
  824|    273|}

ssh_new:
   66|    546|{
   67|    546|    ssh_session session = NULL;
   68|    546|    char *id = NULL;
   69|    546|    int rc;
   70|       |
   71|    546|    session = calloc(1, sizeof (struct ssh_session_struct));
   72|    546|    if (session == NULL) {
  ------------------
  |  Branch (72:9): [True: 0, False: 546]
  ------------------
   73|      0|        return NULL;
   74|      0|    }
   75|       |
   76|    546|    session->next_crypto = crypto_new();
   77|    546|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (77:9): [True: 0, False: 546]
  ------------------
   78|      0|        goto err;
   79|      0|    }
   80|       |
   81|    546|    session->socket = ssh_socket_new(session);
   82|    546|    if (session->socket == NULL) {
  ------------------
  |  Branch (82:9): [True: 0, False: 546]
  ------------------
   83|      0|        goto err;
   84|      0|    }
   85|       |
   86|    546|    session->out_buffer = ssh_buffer_new();
   87|    546|    if (session->out_buffer == NULL) {
  ------------------
  |  Branch (87:9): [True: 0, False: 546]
  ------------------
   88|      0|        goto err;
   89|      0|    }
   90|       |
   91|    546|    session->in_buffer = ssh_buffer_new();
   92|    546|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (92:9): [True: 0, False: 546]
  ------------------
   93|      0|        goto err;
   94|      0|    }
   95|       |
   96|    546|    session->out_queue = ssh_list_new();
   97|    546|    if (session->out_queue == NULL) {
  ------------------
  |  Branch (97:9): [True: 0, False: 546]
  ------------------
   98|      0|        goto err;
   99|      0|    }
  100|       |
  101|    546|    session->alive = 0;
  102|    546|    session->auth.supported_methods = 0;
  103|    546|    ssh_set_blocking(session, 1);
  104|    546|    session->maxchannel = FIRST_CHANNEL;
  ------------------
  |  |   49|    546|#define FIRST_CHANNEL 42 // why not ? it helps to find bugs.
  ------------------
  105|    546|    session->proxy_root = true;
  106|       |
  107|    546|    session->agent = ssh_agent_new(session);
  108|    546|    if (session->agent == NULL) {
  ------------------
  |  Branch (108:9): [True: 0, False: 546]
  ------------------
  109|      0|        goto err;
  110|      0|    }
  111|       |
  112|       |    /* Initialise a default PKI context */
  113|    546|    session->pki_context = ssh_pki_ctx_new();
  114|    546|    if (session->pki_context == NULL) {
  ------------------
  |  Branch (114:9): [True: 0, False: 546]
  ------------------
  115|      0|        goto err;
  116|      0|    }
  117|       |
  118|       |    /* OPTIONS */
  119|    546|    session->opts.StrictHostKeyChecking = SSH_STRICT_HOSTKEY_ASK;
  120|    546|    session->opts.port = 22;
  121|    546|    session->opts.fd = -1;
  122|    546|    session->opts.compressionlevel = 7;
  123|    546|    session->opts.nodelay = 0;
  124|    546|    session->opts.identities_only = false;
  125|    546|    session->opts.batch_mode = false;
  126|    546|    session->opts.control_master = SSH_CONTROL_MASTER_NO;
  127|       |
  128|    546|    session->opts.flags = SSH_OPT_FLAG_PASSWORD_AUTH |
  ------------------
  |  |  109|    546|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
  129|    546|                          SSH_OPT_FLAG_PUBKEY_AUTH |
  ------------------
  |  |  110|    546|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
  130|    546|                          SSH_OPT_FLAG_KBDINT_AUTH |
  ------------------
  |  |  111|    546|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
  131|    546|                          SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|    546|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
  132|    546|    session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
  133|       |
  134|    546|    session->opts.exp_flags = 0;
  135|       |
  136|    546|    session->opts.identity = ssh_list_new();
  137|    546|    if (session->opts.identity == NULL) {
  ------------------
  |  Branch (137:9): [True: 0, False: 546]
  ------------------
  138|      0|        goto err;
  139|      0|    }
  140|    546|    session->opts.identity_non_exp = ssh_list_new();
  141|    546|    if (session->opts.identity_non_exp == NULL) {
  ------------------
  |  Branch (141:9): [True: 0, False: 546]
  ------------------
  142|      0|        goto err;
  143|      0|    }
  144|       |
  145|    546|    session->opts.certificate = ssh_list_new();
  146|    546|    if (session->opts.certificate == NULL) {
  ------------------
  |  Branch (146:9): [True: 0, False: 546]
  ------------------
  147|      0|        goto err;
  148|      0|    }
  149|    546|    session->opts.certificate_non_exp = ssh_list_new();
  150|    546|    if (session->opts.certificate_non_exp == NULL) {
  ------------------
  |  Branch (150:9): [True: 0, False: 546]
  ------------------
  151|      0|        goto err;
  152|      0|    }
  153|       |    /* the default certificates are loaded automatically from the default
  154|       |     * identities later */
  155|       |
  156|    546|    session->opts.local_forward = ssh_list_new();
  157|    546|    if (session->opts.local_forward == NULL) {
  ------------------
  |  Branch (157:9): [True: 0, False: 546]
  ------------------
  158|      0|        goto err;
  159|      0|    }
  160|       |
  161|    546|    session->opts.proxy_jumps = ssh_list_new();
  162|    546|    if (session->opts.proxy_jumps == NULL) {
  ------------------
  |  Branch (162:9): [True: 0, False: 546]
  ------------------
  163|      0|        goto err;
  164|      0|    }
  165|       |
  166|    546|    session->opts.send_env = ssh_list_new();
  167|    546|    if (session->opts.send_env == NULL) {
  ------------------
  |  Branch (167:9): [True: 0, False: 546]
  ------------------
  168|      0|        goto err;
  169|      0|    }
  170|       |
  171|    546|    session->opts.proxy_jumps_user_cb = ssh_list_new();
  172|    546|    if (session->opts.proxy_jumps_user_cb == NULL) {
  ------------------
  |  Branch (172:9): [True: 0, False: 546]
  ------------------
  173|      0|        goto err;
  174|      0|    }
  175|       |
  176|       |#ifdef WITH_GSSAPI
  177|       |    session->opts.gssapi_key_exchange_algs =
  178|       |        strdup(GSSAPI_KEY_EXCHANGE_SUPPORTED);
  179|       |    if (session->opts.gssapi_key_exchange_algs == NULL) {
  180|       |        goto err;
  181|       |    }
  182|       |#endif /* WITH_GSSAPI */
  183|       |
  184|    546|    id = strdup("%d/.ssh/id_ed25519");
  185|    546|    if (id == NULL) {
  ------------------
  |  Branch (185:9): [True: 0, False: 546]
  ------------------
  186|      0|        goto err;
  187|      0|    }
  188|       |
  189|    546|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  190|    546|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (190:9): [True: 0, False: 546]
  ------------------
  191|      0|        goto err;
  192|      0|    }
  193|       |
  194|    546|#ifdef HAVE_ECC
  195|    546|    id = strdup("%d/.ssh/id_ecdsa");
  196|    546|    if (id == NULL) {
  ------------------
  |  Branch (196:9): [True: 0, False: 546]
  ------------------
  197|      0|        goto err;
  198|      0|    }
  199|    546|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  200|    546|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (200:9): [True: 0, False: 546]
  ------------------
  201|      0|        goto err;
  202|      0|    }
  203|    546|#endif
  204|       |
  205|    546|    id = strdup("%d/.ssh/id_rsa");
  206|    546|    if (id == NULL) {
  ------------------
  |  Branch (206:9): [True: 0, False: 546]
  ------------------
  207|      0|        goto err;
  208|      0|    }
  209|    546|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  210|    546|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    546|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (210:9): [True: 0, False: 546]
  ------------------
  211|      0|        goto err;
  212|      0|    }
  213|       |
  214|       |#ifdef WITH_FIDO2
  215|       |    /* Add security key identities */
  216|       |    id = strdup("%d/.ssh/id_ed25519_sk");
  217|       |    if (id == NULL) {
  218|       |        goto err;
  219|       |    }
  220|       |    rc = ssh_list_append(session->opts.identity_non_exp, id);
  221|       |    if (rc == SSH_ERROR) {
  222|       |        goto err;
  223|       |    }
  224|       |
  225|       |#ifdef HAVE_ECC
  226|       |    id = strdup("%d/.ssh/id_ecdsa_sk");
  227|       |    if (id == NULL) {
  228|       |        goto err;
  229|       |    }
  230|       |    rc = ssh_list_append(session->opts.identity_non_exp, id);
  231|       |    if (rc == SSH_ERROR) {
  232|       |        goto err;
  233|       |    }
  234|       |#endif /* HAVE_ECC */
  235|       |#endif /* WITH_FIDO2 */
  236|       |
  237|       |    /* Explicitly initialize states */
  238|    546|    session->session_state = SSH_SESSION_STATE_NONE;
  239|    546|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  240|    546|    session->packet_state = PACKET_STATE_INIT;
  241|    546|    session->dh_handshake_state = DH_STATE_INIT;
  242|    546|    session->global_req_state = SSH_CHANNEL_REQ_STATE_NONE;
  243|       |
  244|    546|    session->auth.state = SSH_AUTH_STATE_NONE;
  245|    546|    session->auth.service_state = SSH_AUTH_SERVICE_NONE;
  246|       |
  247|    546|    return session;
  248|       |
  249|      0|err:
  250|      0|    free(id);
  251|      0|    ssh_free(session);
  252|       |    return NULL;
  253|    546|}
ssh_free:
  264|    546|{
  265|    546|  int i;
  266|    546|  struct ssh_iterator *it = NULL;
  267|    546|  struct ssh_buffer_struct *b = NULL;
  268|       |
  269|    546|  if (session == NULL) {
  ------------------
  |  Branch (269:7): [True: 0, False: 546]
  ------------------
  270|      0|    return;
  271|      0|  }
  272|       |
  273|       |  /*
  274|       |   * Delete all channels
  275|       |   *
  276|       |   * This needs the first thing we clean up cause if there is still an open
  277|       |   * channel we call ssh_channel_close() first. So we need a working socket
  278|       |   * and poll context for it.
  279|       |   */
  280|    546|  for (it = ssh_list_get_iterator(session->channels);
  281|    546|       it != NULL;
  ------------------
  |  Branch (281:8): [True: 0, False: 546]
  ------------------
  282|    546|       it = ssh_list_get_iterator(session->channels)) {
  283|      0|      ssh_channel_do_free(ssh_iterator_value(ssh_channel,it));
  ------------------
  |  |  114|      0|  ((type)((iterator)->data))
  ------------------
  284|      0|      ssh_list_remove(session->channels, it);
  285|      0|  }
  286|    546|  ssh_list_free(session->channels);
  287|    546|  session->channels = NULL;
  288|       |
  289|    546|#ifdef WITH_PCAP
  290|    546|  if (session->pcap_ctx) {
  ------------------
  |  Branch (290:7): [True: 0, False: 546]
  ------------------
  291|      0|      ssh_pcap_context_free(session->pcap_ctx);
  292|      0|      session->pcap_ctx = NULL;
  293|      0|  }
  294|    546|#endif
  295|       |
  296|    546|  ssh_socket_free(session->socket);
  297|    546|  session->socket = NULL;
  298|       |
  299|    546|  if (session->default_poll_ctx) {
  ------------------
  |  Branch (299:7): [True: 546, False: 0]
  ------------------
  300|    546|      ssh_poll_ctx_free(session->default_poll_ctx);
  301|    546|  }
  302|       |
  303|    546|  SSH_BUFFER_FREE(session->in_buffer);
  ------------------
  |  |  957|    546|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 546, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
  304|    546|  SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  957|    546|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 546, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
  305|    546|  session->in_buffer = session->out_buffer = NULL;
  306|       |
  307|    546|  if (session->in_hashbuf != NULL) {
  ------------------
  |  Branch (307:7): [True: 0, False: 546]
  ------------------
  308|      0|      SSH_BUFFER_FREE(session->in_hashbuf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  309|      0|  }
  310|    546|  if (session->out_hashbuf != NULL) {
  ------------------
  |  Branch (310:7): [True: 0, False: 546]
  ------------------
  311|      0|      SSH_BUFFER_FREE(session->out_hashbuf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  312|      0|  }
  313|       |
  314|    546|  crypto_free(session->current_crypto);
  315|    546|  crypto_free(session->next_crypto);
  316|       |
  317|    546|  ssh_agent_free(session->agent);
  318|       |
  319|    546|  SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1050|    546|    do {                         \
  |  | 1051|    546|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1051:13): [True: 546, False: 0]
  |  |  ------------------
  |  | 1052|    546|            ssh_pki_ctx_free(x); \
  |  | 1053|    546|            x = NULL;            \
  |  | 1054|    546|        }                        \
  |  | 1055|    546|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1055:14): [Folded, False: 546]
  |  |  ------------------
  ------------------
  320|       |
  321|    546|  ssh_key_free(session->srv.rsa_key);
  322|    546|  session->srv.rsa_key = NULL;
  323|    546|  ssh_key_free(session->srv.ecdsa_key);
  324|    546|  session->srv.ecdsa_key = NULL;
  325|    546|  ssh_key_free(session->srv.ed25519_key);
  326|    546|  session->srv.ed25519_key = NULL;
  327|       |
  328|    546|  if (session->ssh_message_list) {
  ------------------
  |  Branch (328:7): [True: 0, False: 546]
  ------------------
  329|      0|      ssh_message msg;
  330|       |
  331|      0|      for (msg = ssh_list_pop_head(ssh_message, session->ssh_message_list);
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  332|      0|           msg != NULL;
  ------------------
  |  Branch (332:12): [True: 0, False: 0]
  ------------------
  333|      0|           msg = ssh_list_pop_head(ssh_message, session->ssh_message_list)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  334|      0|          ssh_message_free(msg);
  335|      0|      }
  336|      0|      ssh_list_free(session->ssh_message_list);
  337|      0|  }
  338|       |
  339|    546|  if (session->kbdint != NULL) {
  ------------------
  |  Branch (339:7): [True: 0, False: 546]
  ------------------
  340|      0|    ssh_kbdint_free(session->kbdint);
  341|      0|  }
  342|       |
  343|    546|  if (session->packet_callbacks) {
  ------------------
  |  Branch (343:7): [True: 0, False: 546]
  ------------------
  344|      0|    ssh_list_free(session->packet_callbacks);
  345|      0|  }
  346|       |
  347|       |#ifdef WITH_GSSAPI
  348|       |    ssh_gssapi_free(session);
  349|       |    SAFE_FREE(session->opts.gssapi_key_exchange_algs);
  350|       |#endif
  351|       |
  352|       |  /* options */
  353|    546|  if (session->opts.identity) {
  ------------------
  |  Branch (353:7): [True: 546, False: 0]
  ------------------
  354|    546|      char *id = NULL;
  355|       |
  356|    546|      for (id = ssh_list_pop_head(char *, session->opts.identity);
  ------------------
  |  |  122|    546|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  357|  1.36k|           id != NULL;
  ------------------
  |  Branch (357:12): [True: 819, False: 546]
  ------------------
  358|    819|           id = ssh_list_pop_head(char *, session->opts.identity)) {
  ------------------
  |  |  122|    819|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  359|    819|          SAFE_FREE(id);
  ------------------
  |  |  373|    819|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 819, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 819]
  |  |  ------------------
  ------------------
  360|    819|      }
  361|    546|      ssh_list_free(session->opts.identity);
  362|    546|  }
  363|       |
  364|    546|  if (session->opts.identity_non_exp) {
  ------------------
  |  Branch (364:7): [True: 546, False: 0]
  ------------------
  365|    546|      char *id = NULL;
  366|       |
  367|    546|      for (id = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  122|    546|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  368|  1.36k|           id != NULL;
  ------------------
  |  Branch (368:12): [True: 819, False: 546]
  ------------------
  369|    819|           id = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  122|    819|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  370|    819|          SAFE_FREE(id);
  ------------------
  |  |  373|    819|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 819, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 819]
  |  |  ------------------
  ------------------
  371|    819|      }
  372|    546|      ssh_list_free(session->opts.identity_non_exp);
  373|    546|  }
  374|       |
  375|    546|    if (session->opts.certificate) {
  ------------------
  |  Branch (375:9): [True: 546, False: 0]
  ------------------
  376|    546|        char *cert = NULL;
  377|       |
  378|    546|        for (cert = ssh_list_pop_head(char *, session->opts.certificate);
  ------------------
  |  |  122|    546|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  379|    546|             cert != NULL;
  ------------------
  |  Branch (379:14): [True: 0, False: 546]
  ------------------
  380|    546|             cert = ssh_list_pop_head(char *, session->opts.certificate)) {
  ------------------
  |  |  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|    546|        ssh_list_free(session->opts.certificate);
  384|    546|    }
  385|       |
  386|    546|    if (session->opts.certificate_non_exp) {
  ------------------
  |  Branch (386:9): [True: 546, False: 0]
  ------------------
  387|    546|        char *cert = NULL;
  388|       |
  389|    546|        for (cert = ssh_list_pop_head(char *, session->opts.certificate_non_exp);
  ------------------
  |  |  122|    546|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  390|    546|             cert != NULL;
  ------------------
  |  Branch (390:14): [True: 0, False: 546]
  ------------------
  391|    546|             cert = ssh_list_pop_head(char *, session->opts.certificate_non_exp)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  392|      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]
  |  |  ------------------
  ------------------
  393|      0|        }
  394|    546|        ssh_list_free(session->opts.certificate_non_exp);
  395|    546|    }
  396|       |
  397|    546|    ssh_proxyjumps_free(session->opts.proxy_jumps);
  398|    546|    SSH_LIST_FREE(session->opts.proxy_jumps);
  ------------------
  |  |  125|    546|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (125:14): [True: 546, False: 0]
  |  |  |  Branch (125:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
  399|    546|    SSH_LIST_FREE(session->opts.proxy_jumps_user_cb);
  ------------------
  |  |  125|    546|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (125:14): [True: 546, False: 0]
  |  |  |  Branch (125:69): [Folded, False: 546]
  |  |  ------------------
  ------------------
  400|    546|    SAFE_FREE(session->opts.proxy_jumps_str);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  401|       |
  402|    546|    if (session->opts.send_env) {
  ------------------
  |  Branch (402:9): [True: 546, False: 0]
  ------------------
  403|    546|        char *pattern = NULL;
  404|       |
  405|    546|        for (pattern = ssh_list_pop_head(char *, session->opts.send_env);
  ------------------
  |  |  122|    546|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  406|    546|             pattern != NULL;
  ------------------
  |  Branch (406:14): [True: 0, False: 546]
  ------------------
  407|    546|             pattern = ssh_list_pop_head(char *, session->opts.send_env)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  408|      0|            SAFE_FREE(pattern);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  409|      0|        }
  410|    546|        ssh_list_free(session->opts.send_env);
  411|    546|    }
  412|       |
  413|    546|    while ((b = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  122|    546|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  |  Branch (413:12): [True: 0, False: 546]
  ------------------
  414|    546|                                  session->out_queue)) != NULL) {
  415|      0|        SSH_BUFFER_FREE(b);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  416|      0|    }
  417|    546|    ssh_list_free(session->out_queue);
  418|       |
  419|    546|  ssh_agent_state_free(session->agent_state);
  420|    546|  session->agent_state = NULL;
  421|       |
  422|    546|  SAFE_FREE(session->auth.auto_state);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  423|    546|  SAFE_FREE(session->serverbanner);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  424|    546|  SAFE_FREE(session->clientbanner);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  425|    546|  SAFE_FREE(session->banner);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  426|    546|  SAFE_FREE(session->disconnect_message);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  427|    546|  SAFE_FREE(session->peer_discon_msg);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  428|       |
  429|    546|  SAFE_FREE(session->opts.agent_socket);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  430|    546|  SAFE_FREE(session->opts.bindaddr);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  431|    546|  SAFE_FREE(session->opts.username);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  432|    546|  SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  433|    546|  SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  434|    546|  SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  435|    546|  SAFE_FREE(session->opts.tag);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  436|    546|  SAFE_FREE(session->opts.homedir);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  437|    546|  SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  438|    546|  SAFE_FREE(session->opts.knownhosts);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  439|    546|  SAFE_FREE(session->opts.global_knownhosts);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 273]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  440|    546|  SAFE_FREE(session->opts.ProxyCommand);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  441|    546|  SAFE_FREE(session->opts.gss_server_identity);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  442|    546|  SAFE_FREE(session->opts.gss_client_identity);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  443|    546|  SAFE_FREE(session->opts.pubkey_accepted_types);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  444|    546|  SAFE_FREE(session->opts.control_path);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  445|    546|  SAFE_FREE(session->opts.preferred_authentications);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  446|       |
  447|    546|  if (session->opts.local_forward) {
  ------------------
  |  Branch (447:7): [True: 546, False: 0]
  ------------------
  448|    546|      char *entry = NULL;
  449|       |
  450|    546|      for (entry = ssh_list_pop_head(char *, session->opts.local_forward);
  ------------------
  |  |  122|    546|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  451|    546|           entry != NULL;
  ------------------
  |  Branch (451:12): [True: 0, False: 546]
  ------------------
  452|    546|           entry = ssh_list_pop_head(char *, session->opts.local_forward)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  453|      0|          SAFE_FREE(entry);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  454|      0|      }
  455|    546|      ssh_list_free(session->opts.local_forward);
  456|    546|  }
  457|       |
  458|  6.00k|  for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  6.00k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (458:15): [True: 5.46k, False: 546]
  ------------------
  459|  5.46k|      if (session->opts.wanted_methods[i]) {
  ------------------
  |  Branch (459:11): [True: 2.45k, False: 3.00k]
  ------------------
  460|  2.45k|          SAFE_FREE(session->opts.wanted_methods[i]);
  ------------------
  |  |  373|  2.45k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.45k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.45k]
  |  |  ------------------
  ------------------
  461|  2.45k|      }
  462|  5.46k|  }
  463|       |
  464|    546|  SAFE_FREE(session->server_opts.custombanner);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  465|    546|  SAFE_FREE(session->server_opts.moduli_file);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 546]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  466|       |
  467|    546|  _ssh_remove_legacy_log_cb();
  468|       |
  469|       |  /* burn connection, it could contain sensitive data */
  470|    546|  ssh_burn(session, sizeof(struct ssh_session_struct));
  ------------------
  |  |  388|    546|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  471|       |  SAFE_FREE(session);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  472|    546|}
ssh_session_socket_close:
  652|    819|{
  653|    819|    if (session->opts.fd == SSH_INVALID_SOCKET) {
  ------------------
  |  |  124|    819|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  |  Branch (653:9): [True: 273, False: 546]
  ------------------
  654|    273|        ssh_socket_close(session->socket);
  655|    273|    }
  656|    819|    session->alive = 0;
  657|    819|    session->session_state = SSH_SESSION_STATE_ERROR;
  658|    819|}
ssh_set_blocking:
  686|    546|{
  687|    546|    if (session == NULL) {
  ------------------
  |  Branch (687:9): [True: 0, False: 546]
  ------------------
  688|      0|        return;
  689|      0|    }
  690|    546|    session->flags &= ~SSH_SESSION_FLAG_BLOCKING;
  ------------------
  |  |   75|    546|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  691|    546|    session->flags |= blocking ? SSH_SESSION_FLAG_BLOCKING : 0;
  ------------------
  |  |   75|    546|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (691:23): [True: 546, False: 0]
  ------------------
  692|    546|}
ssh_is_blocking:
  701|  3.54k|{
  702|  3.54k|    return (session->flags & SSH_SESSION_FLAG_BLOCKING) ? 1 : 0;
  ------------------
  |  |   75|  3.54k|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (702:12): [True: 3.54k, False: 0]
  ------------------
  703|  3.54k|}
ssh_blocking_flush:
  725|  1.36k|int ssh_blocking_flush(ssh_session session, int timeout){
  726|  1.36k|    int rc;
  727|  1.36k|    if (session == NULL) {
  ------------------
  |  Branch (727:9): [True: 0, False: 1.36k]
  ------------------
  728|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  729|      0|    }
  730|       |
  731|  1.36k|    rc = ssh_handle_packets_termination(session, timeout,
  732|  1.36k|            ssh_flush_termination, session);
  733|  1.36k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  1.36k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (733:9): [True: 0, False: 1.36k]
  ------------------
  734|      0|        return rc;
  735|      0|    }
  736|  1.36k|    if (!ssh_flush_termination(session)) {
  ------------------
  |  Branch (736:9): [True: 0, False: 1.36k]
  ------------------
  737|      0|        rc = SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  738|      0|    }
  739|       |
  740|  1.36k|    return rc;
  741|  1.36k|}
ssh_set_fd_towrite:
  795|    273|void ssh_set_fd_towrite(ssh_session session) {
  796|    273|  if (session == NULL) {
  ------------------
  |  Branch (796:7): [True: 0, False: 273]
  ------------------
  797|      0|    return;
  798|      0|  }
  799|       |
  800|    273|  ssh_socket_set_write_wontblock(session->socket);
  801|    273|}
ssh_handle_packets:
  838|  7.54k|{
  839|  7.54k|    ssh_poll_handle spoll = NULL;
  840|  7.54k|    ssh_poll_ctx ctx = NULL;
  841|  7.54k|    int tm = timeout;
  842|  7.54k|    int rc;
  843|       |
  844|  7.54k|    if (session == NULL || session->socket == NULL) {
  ------------------
  |  Branch (844:9): [True: 0, False: 7.54k]
  |  Branch (844:28): [True: 0, False: 7.54k]
  ------------------
  845|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  846|      0|    }
  847|       |
  848|  7.54k|    spoll = ssh_socket_get_poll_handle(session->socket);
  849|  7.54k|    if (spoll == NULL) {
  ------------------
  |  Branch (849:9): [True: 0, False: 7.54k]
  ------------------
  850|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  851|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  852|      0|    }
  853|  7.54k|    ssh_poll_add_events(spoll, POLLIN);
  854|  7.54k|    ctx = ssh_poll_get_ctx(spoll);
  855|       |
  856|  7.54k|    if (ctx == NULL) {
  ------------------
  |  Branch (856:9): [True: 546, False: 7.00k]
  ------------------
  857|    546|        ctx = ssh_poll_get_default_ctx(session);
  858|    546|        if (ctx == NULL) {
  ------------------
  |  Branch (858:13): [True: 0, False: 546]
  ------------------
  859|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  860|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  861|      0|        }
  862|    546|        rc = ssh_poll_ctx_add(ctx, spoll);
  863|    546|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (863:13): [True: 0, False: 546]
  ------------------
  864|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  865|      0|        }
  866|    546|    }
  867|       |
  868|  7.54k|    if (timeout == SSH_TIMEOUT_USER) {
  ------------------
  |  |  101|  7.54k|#define SSH_TIMEOUT_USER -2
  ------------------
  |  Branch (868:9): [True: 0, False: 7.54k]
  ------------------
  869|      0|        if (ssh_is_blocking(session)) {
  ------------------
  |  Branch (869:13): [True: 0, False: 0]
  ------------------
  870|      0|            tm = ssh_make_milliseconds(session->opts.timeout,
  871|      0|                                       session->opts.timeout_usec);
  872|      0|        } else {
  873|      0|            tm = 0;
  874|      0|        }
  875|      0|    }
  876|  7.54k|    rc = ssh_poll_ctx_dopoll(ctx, tm);
  877|  7.54k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  7.54k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (877:9): [True: 273, False: 7.27k]
  ------------------
  878|    273|        session->session_state = SSH_SESSION_STATE_ERROR;
  879|    273|    }
  880|       |
  881|  7.54k|    return rc;
  882|  7.54k|}
ssh_handle_packets_termination:
  915|  3.27k|{
  916|  3.27k|    struct ssh_timestamp ts;
  917|  3.27k|    int timeout_ms = SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|  3.27k|#define SSH_TIMEOUT_INFINITE -1
  ------------------
  918|  3.27k|    int tm;
  919|  3.27k|    int ret = SSH_OK;
  ------------------
  |  |  316|  3.27k|#define SSH_OK 0     /* No error */
  ------------------
  920|       |
  921|       |    /* If a timeout has been provided, use it */
  922|  3.27k|    if (timeout >= 0) {
  ------------------
  |  Branch (922:9): [True: 273, False: 3.00k]
  ------------------
  923|    273|        timeout_ms = timeout;
  924|  3.00k|    } else {
  925|  3.00k|        if (ssh_is_blocking(session)) {
  ------------------
  |  Branch (925:13): [True: 3.00k, False: 0]
  ------------------
  926|  3.00k|            if (timeout == SSH_TIMEOUT_USER || timeout == SSH_TIMEOUT_DEFAULT) {
  ------------------
  |  |  101|  6.00k|#define SSH_TIMEOUT_USER -2
  ------------------
                          if (timeout == SSH_TIMEOUT_USER || timeout == SSH_TIMEOUT_DEFAULT) {
  ------------------
  |  |  103|  2.18k|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
  |  Branch (926:17): [True: 819, False: 2.18k]
  |  Branch (926:48): [True: 2.18k, False: 0]
  ------------------
  927|  3.00k|                if (session->opts.timeout > 0 ||
  ------------------
  |  Branch (927:21): [True: 3.00k, False: 0]
  ------------------
  928|  3.00k|                    session->opts.timeout_usec > 0) {
  ------------------
  |  Branch (928:21): [True: 0, False: 0]
  ------------------
  929|  3.00k|                    timeout_ms =
  930|  3.00k|                        ssh_make_milliseconds(session->opts.timeout,
  931|  3.00k|                                              session->opts.timeout_usec);
  932|  3.00k|                }
  933|  3.00k|            }
  934|  3.00k|        } else {
  935|      0|            timeout_ms = SSH_TIMEOUT_NONBLOCKING;
  ------------------
  |  |  105|      0|#define SSH_TIMEOUT_NONBLOCKING 0
  ------------------
  936|      0|        }
  937|  3.00k|    }
  938|       |
  939|       |    /* avoid unnecessary syscall for the SSH_TIMEOUT_NONBLOCKING case */
  940|  3.27k|    if (timeout_ms != SSH_TIMEOUT_NONBLOCKING) {
  ------------------
  |  |  105|  3.27k|#define SSH_TIMEOUT_NONBLOCKING 0
  ------------------
  |  Branch (940:9): [True: 3.27k, False: 0]
  ------------------
  941|  3.27k|        ssh_timestamp_init(&ts);
  942|  3.27k|    }
  943|       |
  944|  3.27k|    tm = timeout_ms;
  945|  10.5k|    while(!fct(user)) {
  ------------------
  |  Branch (945:11): [True: 7.54k, False: 3.00k]
  ------------------
  946|  7.54k|        ret = ssh_handle_packets(session, tm);
  947|  7.54k|        if (ret == SSH_ERROR) {
  ------------------
  |  |  317|  7.54k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (947:13): [True: 273, False: 7.27k]
  ------------------
  948|    273|            break;
  949|    273|        }
  950|  7.27k|        if (ssh_timeout_elapsed(&ts, timeout_ms)) {
  ------------------
  |  Branch (950:13): [True: 0, False: 7.27k]
  ------------------
  951|      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 (951:19): [True: 0, False: 0]
  ------------------
  952|      0|            break;
  953|      0|        }
  954|       |
  955|  7.27k|        tm = ssh_timeout_update(&ts, timeout_ms);
  956|  7.27k|    }
  957|       |
  958|  3.27k|    return ret;
  959|  3.27k|}
ssh_socket_exception_callback:
 1070|    546|void ssh_socket_exception_callback(int code, int errno_code, void *user){
 1071|    546|    ssh_session session = (ssh_session)user;
 1072|       |
 1073|    546|    SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  281|    546|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1074|    546|            "Socket exception callback: %d (%d)",
 1075|    546|            code,
 1076|    546|            errno_code);
 1077|    546|    session->session_state = SSH_SESSION_STATE_ERROR;
 1078|    546|    if (errno_code == 0 && code == SSH_SOCKET_EXCEPTION_EOF) {
  ------------------
  |  |  520|    273|#define SSH_SOCKET_EXCEPTION_EOF 	     1
  ------------------
  |  Branch (1078:9): [True: 273, False: 273]
  |  Branch (1078:28): [True: 273, False: 0]
  ------------------
 1079|    273|        ssh_set_error(session, SSH_FATAL, "Socket error: disconnected");
  ------------------
  |  |  311|    273|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1080|       |#ifdef _WIN32
 1081|       |    } else if (errno_code == WSAENETDOWN) {
 1082|       |        ssh_set_error(session, SSH_FATAL, "Socket error: network down");
 1083|       |    } else if (errno_code == WSAENETUNREACH) {
 1084|       |        ssh_set_error(session, SSH_FATAL, "Socket error: network unreachable");
 1085|       |    } else if (errno_code == WSAENETRESET) {
 1086|       |        ssh_set_error(session, SSH_FATAL, "Socket error: network reset");
 1087|       |    } else if (errno_code == WSAECONNABORTED) {
 1088|       |        ssh_set_error(session, SSH_FATAL, "Socket error: connection aborted");
 1089|       |    } else if (errno_code == WSAECONNRESET) {
 1090|       |        ssh_set_error(session,
 1091|       |                      SSH_FATAL,
 1092|       |                      "Socket error: connection reset by peer");
 1093|       |    } else if (errno_code == WSAETIMEDOUT) {
 1094|       |        ssh_set_error(session, SSH_FATAL, "Socket error: connection timed out");
 1095|       |    } else if (errno_code == WSAECONNREFUSED) {
 1096|       |        ssh_set_error(session, SSH_FATAL, "Socket error: connection refused");
 1097|       |    } else if (errno_code == WSAEHOSTUNREACH) {
 1098|       |        ssh_set_error(session, SSH_FATAL, "Socket error: host unreachable");
 1099|       |#endif
 1100|    273|    } else {
 1101|    273|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};
 1102|    273|        ssh_set_error(session,
  ------------------
  |  |  311|    273|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1103|    273|                      SSH_FATAL,
 1104|    273|                      "Socket error: %s",
 1105|    273|                      ssh_strerror(errno_code, err_msg, SSH_ERRNO_MSG_MAX));
 1106|    273|    }
 1107|       |
 1108|    546|    session->ssh_connection_callback(session);
 1109|    546|}
session.c:ssh_flush_termination:
  706|  3.27k|static int ssh_flush_termination(void *c){
  707|  3.27k|  ssh_session session = c;
  708|  3.27k|  if (ssh_socket_buffered_write_bytes(session->socket) == 0 ||
  ------------------
  |  Branch (708:7): [True: 1.63k, False: 1.63k]
  ------------------
  709|  1.63k|      session->session_state == SSH_SESSION_STATE_ERROR)
  ------------------
  |  Branch (709:7): [True: 1.09k, False: 546]
  ------------------
  710|  2.73k|    return 1;
  711|    546|  else
  712|    546|    return 0;
  713|  3.27k|}

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|  1.36k|{
  183|  1.36k|    ssh_socket s;
  184|       |
  185|  1.36k|    s = calloc(1, sizeof(struct ssh_socket_struct));
  186|  1.36k|    if (s == NULL) {
  ------------------
  |  Branch (186:9): [True: 0, False: 1.36k]
  ------------------
  187|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  188|      0|        return NULL;
  189|      0|    }
  190|  1.36k|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|  1.36k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  191|  1.36k|    s->last_errno = -1;
  192|  1.36k|    s->fd_is_socket = 1;
  193|  1.36k|    s->session = session;
  194|  1.36k|    s->in_buffer = ssh_buffer_new();
  195|  1.36k|    if (s->in_buffer == NULL) {
  ------------------
  |  Branch (195:9): [True: 0, False: 1.36k]
  ------------------
  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|  1.36k|    s->out_buffer=ssh_buffer_new();
  201|  1.36k|    if (s->out_buffer == NULL) {
  ------------------
  |  Branch (201:9): [True: 0, False: 1.36k]
  ------------------
  202|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  203|      0|        SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957: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|  1.36k|    s->read_wontblock = 0;
  208|  1.36k|    s->write_wontblock = 0;
  209|  1.36k|    s->data_except = 0;
  210|       |    s->poll_handle = NULL;
  211|  1.36k|    s->state=SSH_SOCKET_NONE;
  212|  1.36k|    return s;
  213|  1.36k|}
ssh_socket_reset:
  226|    546|{
  227|    546|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|    546|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  228|    546|    s->last_errno = -1;
  229|    546|    s->fd_is_socket = 1;
  230|    546|    ssh_buffer_reinit(s->in_buffer);
  231|    546|    ssh_buffer_reinit(s->out_buffer);
  232|    546|    s->read_wontblock = 0;
  233|    546|    s->write_wontblock = 0;
  234|    546|    s->data_except = 0;
  235|    546|    if (s->poll_handle != NULL) {
  ------------------
  |  Branch (235:9): [True: 273, False: 273]
  ------------------
  236|    273|        ssh_poll_free(s->poll_handle);
  237|       |        s->poll_handle = NULL;
  238|    273|    }
  239|    546|    s->state=SSH_SOCKET_NONE;
  240|    546|#ifndef _WIN32
  241|    546|    s->proxy_pid = 0;
  242|    546|#endif
  243|    546|}
ssh_socket_set_callbacks:
  253|  1.09k|{
  254|  1.09k|    s->callbacks = callbacks;
  255|  1.09k|}
ssh_socket_set_connected:
  269|    546|{
  270|    546|    s->state = SSH_SOCKET_CONNECTED;
  271|       |    /* `POLLOUT` is the event to wait for in a non-blocking connect */
  272|    546|    if (p != NULL) {
  ------------------
  |  Branch (272:9): [True: 546, False: 0]
  ------------------
  273|    546|        ssh_poll_set_events(p, POLLIN | POLLOUT);
  274|    546|    }
  275|    546|}
ssh_socket_pollcallback:
  296|  9.73k|{
  297|  9.73k|    ssh_socket s = (ssh_socket)v_s;
  298|  9.73k|    void *buffer = NULL;
  299|  9.73k|    ssize_t nread = 0;
  300|  9.73k|    int rc;
  301|  9.73k|    int err = 0;
  302|  9.73k|    socklen_t errlen = sizeof(err);
  303|       |
  304|       |    /* Do not do anything if this socket was already closed */
  305|  9.73k|    if (!ssh_socket_is_open(s)) {
  ------------------
  |  Branch (305:9): [True: 0, False: 9.73k]
  ------------------
  306|      0|        return -1;
  307|      0|    }
  308|  9.73k|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|  58.3k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 5.28k, False: 4.44k]
  |  |  |  Branch (281:34): [True: 5.54k, False: 4.19k]
  |  |  |  Branch (281:34): [True: 0, False: 9.73k]
  |  |  ------------------
  ------------------
  309|  9.73k|            "Poll callback on socket %d (%s%s%s), out buffer %" PRIu32, fd,
  310|  9.73k|            (revents & POLLIN) ? "POLLIN ":"",
  311|  9.73k|            (revents & POLLOUT) ? "POLLOUT ":"",
  312|  9.73k|            (revents & POLLERR) ? "POLLERR":"",
  313|  9.73k|            ssh_buffer_get_len(s->out_buffer));
  314|  9.73k|    if ((revents & POLLERR) || (revents & POLLHUP)) {
  ------------------
  |  Branch (314:9): [True: 4, False: 9.72k]
  |  Branch (314:32): [True: 297, False: 9.43k]
  ------------------
  315|       |        /* Check if we are in a connecting state */
  316|    297|        if (s->state == SSH_SOCKET_CONNECTING) {
  ------------------
  |  Branch (316:13): [True: 0, False: 297]
  ------------------
  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|    297|        revents |= POLLIN;
  338|    297|    }
  339|  9.73k|    if ((revents & POLLIN) && s->state == SSH_SOCKET_CONNECTED) {
  ------------------
  |  Branch (339:9): [True: 5.28k, False: 4.44k]
  |  Branch (339:31): [True: 5.01k, False: 273]
  ------------------
  340|  5.01k|        s->read_wontblock = 1;
  341|  5.01k|        buffer = ssh_buffer_allocate(s->in_buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|  5.01k|#define MAX_BUF_SIZE 4096
  ------------------
  342|  5.01k|        if (buffer) {
  ------------------
  |  Branch (342:13): [True: 5.01k, False: 0]
  ------------------
  343|  5.01k|            nread = ssh_socket_unbuffered_read(s, buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|  5.01k|#define MAX_BUF_SIZE 4096
  ------------------
  344|  5.01k|        }
  345|  5.01k|        if (nread < 0) {
  ------------------
  |  Branch (345:13): [True: 0, False: 5.01k]
  ------------------
  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|  5.01k|        ssh_buffer_pass_bytes_end(s->in_buffer,
  361|  5.01k|                                  (uint32_t)(MAX_BUF_SIZE - nread));
  ------------------
  |  |  230|  5.01k|#define MAX_BUF_SIZE 4096
  ------------------
  362|       |
  363|  5.01k|        if (nread == 0) {
  ------------------
  |  Branch (363:13): [True: 273, False: 4.74k]
  ------------------
  364|    273|            if (p != NULL) {
  ------------------
  |  Branch (364:17): [True: 273, False: 0]
  ------------------
  365|    273|                ssh_poll_remove_events(p, POLLIN);
  366|    273|            }
  367|    273|            if (s->callbacks != NULL && s->callbacks->exception != NULL) {
  ------------------
  |  Branch (367:17): [True: 273, False: 0]
  |  Branch (367:41): [True: 273, False: 0]
  ------------------
  368|    273|                s->callbacks->exception(SSH_SOCKET_EXCEPTION_EOF,
  ------------------
  |  |  520|    273|#define SSH_SOCKET_EXCEPTION_EOF 	     1
  ------------------
  369|    273|                                        0,
  370|    273|                                        s->callbacks->userdata);
  371|    273|            }
  372|    273|            return -2;
  373|    273|        }
  374|       |
  375|  4.74k|        if (s->session->socket_counter != NULL) {
  ------------------
  |  Branch (375:13): [True: 0, False: 4.74k]
  ------------------
  376|      0|            s->session->socket_counter->in_bytes += nread;
  377|      0|        }
  378|       |
  379|       |        /* Call the callback */
  380|  4.74k|        if (s->callbacks != NULL && s->callbacks->data != NULL) {
  ------------------
  |  Branch (380:13): [True: 4.74k, False: 0]
  |  Branch (380:37): [True: 4.74k, False: 0]
  ------------------
  381|  4.74k|            size_t processed;
  382|  9.93k|            do {
  383|  9.93k|                processed = s->callbacks->data(ssh_buffer_get(s->in_buffer),
  384|  9.93k|                                               ssh_buffer_get_len(s->in_buffer),
  385|  9.93k|                                               s->callbacks->userdata);
  386|  9.93k|                ssh_buffer_pass_bytes(s->in_buffer, (uint32_t)processed);
  387|  9.93k|            } while ((processed > 0) && (s->state == SSH_SOCKET_CONNECTED));
  ------------------
  |  Branch (387:22): [True: 5.18k, False: 4.74k]
  |  Branch (387:41): [True: 5.18k, False: 0]
  ------------------
  388|       |
  389|       |            /* p may have been freed, so don't use it
  390|       |             * anymore in this function */
  391|  4.74k|            p = NULL;
  392|  4.74k|        }
  393|  4.74k|    }
  394|       |#ifdef _WIN32
  395|       |    if (revents & POLLOUT || revents & POLLWRNORM) {
  396|       |#else
  397|  9.45k|    if (revents & POLLOUT) {
  ------------------
  |  Branch (397:9): [True: 5.54k, False: 3.91k]
  ------------------
  398|  5.54k|#endif
  399|  5.54k|        uint32_t len;
  400|       |
  401|       |        /* First, POLLOUT is a sign we may be connected */
  402|  5.54k|        if (s->state == SSH_SOCKET_CONNECTING) {
  ------------------
  |  Branch (402:13): [True: 273, False: 5.26k]
  ------------------
  403|    273|            SSH_LOG(SSH_LOG_PACKET, "Received POLLOUT in connecting state");
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  404|    273|            ssh_socket_set_connected(s, p);
  405|       |
  406|    273|            rc = ssh_socket_set_blocking(ssh_socket_get_fd(s));
  407|    273|            if (rc < 0) {
  ------------------
  |  Branch (407:17): [True: 0, False: 273]
  ------------------
  408|      0|                return -1;
  409|      0|            }
  410|       |
  411|    273|            if (s->callbacks != NULL && s->callbacks->connected != NULL) {
  ------------------
  |  Branch (411:17): [True: 273, False: 0]
  |  Branch (411:41): [True: 273, False: 0]
  ------------------
  412|    273|                s->callbacks->connected(SSH_SOCKET_CONNECTED_OK,
  ------------------
  |  |  523|    273|#define SSH_SOCKET_CONNECTED_OK 			1
  ------------------
  413|    273|                                        0,
  414|    273|                                        s->callbacks->userdata);
  415|    273|            }
  416|       |
  417|    273|            return 0;
  418|    273|        }
  419|       |
  420|       |        /* So, we can write data */
  421|  5.26k|        s->write_wontblock = 1;
  422|  5.26k|        if (p != NULL) {
  ------------------
  |  Branch (422:13): [True: 4.44k, False: 825]
  ------------------
  423|  4.44k|            ssh_poll_remove_events(p, POLLOUT);
  424|  4.44k|        }
  425|       |
  426|       |        /* If buffered data is pending, write it */
  427|  5.26k|        len = ssh_buffer_get_len(s->out_buffer);
  428|  5.26k|        if (len > 0) {
  ------------------
  |  Branch (428:13): [True: 1.83k, False: 3.43k]
  ------------------
  429|  1.83k|            ssh_socket_nonblocking_flush(s);
  430|  3.43k|        } else if (s->callbacks != NULL && s->callbacks->controlflow != NULL) {
  ------------------
  |  Branch (430:20): [True: 3.43k, False: 18.4E]
  |  Branch (430:44): [True: 3.16k, False: 272]
  ------------------
  431|       |            /* Otherwise advertise the upper level that write can be done */
  432|  3.16k|            SSH_LOG(SSH_LOG_TRACE, "sending control flow event");
  ------------------
  |  |  281|  3.16k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  433|  3.16k|            s->callbacks->controlflow(SSH_SOCKET_FLOW_WRITEWONTBLOCK,
  ------------------
  |  |  518|  3.16k|#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
  ------------------
  434|  3.16k|                                      s->callbacks->userdata);
  435|  3.16k|        }
  436|       |        /* TODO: Find a way to put back POLLOUT when buffering occurs */
  437|  5.26k|    }
  438|       |
  439|       |    /* Return -1 if the poll handler disappeared */
  440|  9.18k|    if (s->poll_handle == NULL) {
  ------------------
  |  Branch (440:9): [True: 0, False: 9.18k]
  ------------------
  441|      0|        return -1;
  442|      0|    }
  443|       |
  444|  9.18k|    return 0;
  445|  9.18k|}
ssh_socket_get_poll_handle:
  454|  8.36k|{
  455|  8.36k|    if (s->poll_handle) {
  ------------------
  |  Branch (455:9): [True: 7.82k, False: 546]
  ------------------
  456|  7.82k|        return s->poll_handle;
  457|  7.82k|    }
  458|    546|    s->poll_handle = ssh_poll_new(s->fd, 0, ssh_socket_pollcallback, s);
  459|    546|    return s->poll_handle;
  460|  8.36k|}
ssh_socket_free:
  473|  1.36k|{
  474|  1.36k|    if (s == NULL) {
  ------------------
  |  Branch (474:9): [True: 0, False: 1.36k]
  ------------------
  475|      0|        return;
  476|      0|    }
  477|  1.36k|    ssh_socket_close(s);
  478|  1.36k|    SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  957|  1.36k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 1.36k, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 1.36k]
  |  |  ------------------
  ------------------
  479|  1.36k|    SSH_BUFFER_FREE(s->out_buffer);
  ------------------
  |  |  957|  1.36k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 1.36k, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 1.36k]
  |  |  ------------------
  ------------------
  480|       |    SAFE_FREE(s);
  ------------------
  |  |  373|  1.36k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.36k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.36k]
  |  |  ------------------
  ------------------
  481|  1.36k|}
ssh_socket_close:
  546|  2.45k|{
  547|  2.45k|    if (ssh_socket_is_open(s)) {
  ------------------
  |  Branch (547:9): [True: 546, False: 1.91k]
  ------------------
  548|       |#ifdef _WIN32
  549|       |        CLOSE_SOCKET(s->fd);
  550|       |        s->last_errno = WSAGetLastError();
  551|       |#else
  552|    546|        CLOSE_SOCKET(s->fd);
  ------------------
  |  |  472|    546|#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  124|    546|#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|    546|#define _XCLOSESOCKET close
  |  |  ------------------
  |  |               #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  124|    546|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |  |  Branch (472:34): [True: 546, False: 0]
  |  |  |  Branch (472:116): [Folded, False: 546]
  |  |  ------------------
  ------------------
  553|    546|        s->last_errno = errno;
  554|    546|#endif
  555|    546|    }
  556|       |
  557|  2.45k|    if (s->poll_handle != NULL && !ssh_poll_is_locked(s->poll_handle)) {
  ------------------
  |  Branch (557:9): [True: 546, False: 1.91k]
  |  Branch (557:35): [True: 273, False: 273]
  ------------------
  558|    273|        ssh_poll_free(s->poll_handle);
  559|    273|        s->poll_handle = NULL;
  560|    273|    }
  561|       |
  562|  2.45k|    s->state = SSH_SOCKET_CLOSED;
  563|       |
  564|  2.45k|#ifndef _WIN32
  565|       |    /* If the proxy command still runs try to kill it */
  566|  2.45k|    if (s->proxy_pid != 0) {
  ------------------
  |  Branch (566:9): [True: 0, False: 2.45k]
  ------------------
  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|  2.45k|#endif
  585|  2.45k|}
ssh_socket_set_fd:
  596|    546|{
  597|    546|    ssh_poll_handle h = NULL;
  598|       |
  599|    546|    s->fd = fd;
  600|       |
  601|    546|    if (s->poll_handle) {
  ------------------
  |  Branch (601:9): [True: 0, False: 546]
  ------------------
  602|      0|        ssh_poll_set_fd(s->poll_handle,fd);
  603|    546|    } else {
  604|    546|        s->state = SSH_SOCKET_CONNECTING;
  605|    546|        h = ssh_socket_get_poll_handle(s);
  606|    546|        if (h == NULL) {
  ------------------
  |  Branch (606:13): [True: 0, False: 546]
  ------------------
  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|    546|        ssh_poll_set_events(h, POLLOUT);
  612|       |#ifdef _WIN32
  613|       |        ssh_poll_add_events(h, POLLWRNORM);
  614|       |#endif
  615|    546|    }
  616|    546|    return SSH_OK;
  ------------------
  |  |  316|    546|#define SSH_OK 0     /* No error */
  ------------------
  617|    546|}
ssh_socket_get_fd:
  629|    273|{
  630|    273|    return s->fd;
  631|    273|}
ssh_socket_is_open:
  643|  26.3k|{
  644|  26.3k|    return s->fd != SSH_INVALID_SOCKET;
  ------------------
  |  |  124|  26.3k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  645|  26.3k|}
ssh_socket_write:
  811|  6.00k|{
  812|  6.00k|    if (len > 0) {
  ------------------
  |  Branch (812:9): [True: 6.00k, False: 0]
  ------------------
  813|  6.00k|        if (ssh_buffer_add_data(s->out_buffer, buffer, len) < 0) {
  ------------------
  |  Branch (813:13): [True: 0, False: 6.00k]
  ------------------
  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|  6.00k|        ssh_socket_nonblocking_flush(s);
  818|  6.00k|    }
  819|       |
  820|  6.00k|    return SSH_OK;
  ------------------
  |  |  316|  6.00k|#define SSH_OK 0     /* No error */
  ------------------
  821|  6.00k|}
ssh_socket_nonblocking_flush:
  841|  7.83k|{
  842|  7.83k|    ssh_session session = s->session;
  843|  7.83k|    uint32_t len;
  844|       |
  845|  7.83k|    if (!ssh_socket_is_open(s)) {
  ------------------
  |  Branch (845:9): [True: 0, False: 7.83k]
  ------------------
  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|  7.83k|    len = ssh_buffer_get_len(s->out_buffer);
  864|  7.83k|    if (!s->write_wontblock && s->poll_handle && len > 0) {
  ------------------
  |  Branch (864:9): [True: 2.37k, False: 5.45k]
  |  Branch (864:32): [True: 2.37k, False: 0]
  |  Branch (864:50): [True: 2.37k, False: 0]
  ------------------
  865|       |        /* force the poll system to catch pollout events */
  866|  2.37k|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  867|       |
  868|  2.37k|        return SSH_AGAIN;
  ------------------
  |  |  318|  2.37k|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  869|  2.37k|    }
  870|       |
  871|  5.46k|    if (s->write_wontblock && len > 0) {
  ------------------
  |  Branch (871:9): [True: 5.46k, False: 18.4E]
  |  Branch (871:31): [True: 5.46k, False: 0]
  ------------------
  872|  5.46k|        ssize_t bwritten;
  873|       |
  874|  5.46k|        bwritten = ssh_socket_unbuffered_write(s,
  875|  5.46k|                                               ssh_buffer_get(s->out_buffer),
  876|  5.46k|                                               len);
  877|  5.46k|        if (bwritten < 0) {
  ------------------
  |  Branch (877:13): [True: 273, False: 5.18k]
  ------------------
  878|    273|            session->alive = 0;
  879|    273|            ssh_socket_close(s);
  880|       |
  881|    273|            if (s->callbacks && s->callbacks->exception) {
  ------------------
  |  Branch (881:17): [True: 273, False: 0]
  |  Branch (881:33): [True: 273, False: 0]
  ------------------
  882|    273|                s->callbacks->exception(SSH_SOCKET_EXCEPTION_ERROR,
  ------------------
  |  |  521|    273|#define SSH_SOCKET_EXCEPTION_ERROR     2
  ------------------
  883|    273|                                        s->last_errno,
  884|    273|                                        s->callbacks->userdata);
  885|    273|            } 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|    273|            return SSH_ERROR;
  ------------------
  |  |  317|    273|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  895|    273|        }
  896|       |
  897|  5.18k|        ssh_buffer_pass_bytes(s->out_buffer, (uint32_t)bwritten);
  898|  5.18k|        if (s->session->socket_counter != NULL) {
  ------------------
  |  Branch (898:13): [True: 0, False: 5.18k]
  ------------------
  899|      0|            s->session->socket_counter->out_bytes += bwritten;
  900|      0|        }
  901|  5.18k|    }
  902|       |
  903|       |    /* Is there some data pending? */
  904|  5.18k|    len = ssh_buffer_get_len(s->out_buffer);
  905|  5.18k|    if (s->poll_handle && len > 0) {
  ------------------
  |  Branch (905:9): [True: 5.18k, False: 0]
  |  Branch (905:27): [True: 0, False: 5.18k]
  ------------------
  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|  5.18k|    return SSH_OK;
  ------------------
  |  |  316|  5.18k|#define SSH_OK 0     /* No error */
  ------------------
  916|  5.18k|}
ssh_socket_set_write_wontblock:
  929|    273|{
  930|    273|    s->write_wontblock = 1;
  931|    273|}
ssh_socket_buffered_write_bytes:
 1002|  3.27k|{
 1003|  3.27k|    if (s==NULL || s->out_buffer == NULL) {
  ------------------
  |  Branch (1003:9): [True: 0, False: 3.27k]
  |  Branch (1003:20): [True: 0, False: 3.27k]
  ------------------
 1004|      0|        return 0;
 1005|      0|    }
 1006|       |
 1007|  3.27k|    return ssh_buffer_get_len(s->out_buffer);
 1008|  3.27k|}
ssh_socket_set_blocking:
 1114|    273|{
 1115|       |    return fcntl(fd, F_SETFL, 0);
 1116|    273|}
socket.c:ssh_socket_unbuffered_read:
  665|  5.01k|{
  666|  5.01k|    ssize_t rc = -1;
  667|       |
  668|  5.01k|    if (s->data_except) {
  ------------------
  |  Branch (668:9): [True: 0, False: 5.01k]
  ------------------
  669|      0|        return -1;
  670|      0|    }
  671|  5.01k|    if (s->fd_is_socket) {
  ------------------
  |  Branch (671:9): [True: 5.01k, False: 0]
  ------------------
  672|  5.01k|        rc = recv(s->fd, buffer, len, 0);
  673|  5.01k|    } else {
  674|      0|        rc = read(s->fd, buffer, len);
  675|      0|    }
  676|       |#ifdef _WIN32
  677|       |    s->last_errno = WSAGetLastError();
  678|       |#else
  679|  5.01k|    s->last_errno = errno;
  680|  5.01k|#endif
  681|  5.01k|    s->read_wontblock = 0;
  682|       |
  683|  5.01k|    if (rc < 0) {
  ------------------
  |  Branch (683:9): [True: 0, False: 5.01k]
  ------------------
  684|      0|        s->data_except = 1;
  685|  5.01k|    } else {
  686|  5.01k|        SSH_LOG(SSH_LOG_TRACE, "read %zd", rc);
  ------------------
  |  |  281|  5.01k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  687|  5.01k|    }
  688|       |
  689|  5.01k|    return rc;
  690|  5.01k|}
socket.c:ssh_socket_unbuffered_write:
  711|  5.46k|{
  712|  5.46k|    ssize_t w = -1;
  713|  5.46k|    int flags = 0;
  714|       |
  715|  5.46k|#ifdef MSG_NOSIGNAL
  716|  5.46k|    flags |= MSG_NOSIGNAL;
  717|  5.46k|#endif
  718|       |
  719|  5.46k|    if (s->data_except) {
  ------------------
  |  Branch (719:9): [True: 0, False: 5.46k]
  ------------------
  720|      0|        return -1;
  721|      0|    }
  722|       |
  723|  5.46k|    if (s->fd_is_socket) {
  ------------------
  |  Branch (723:9): [True: 5.46k, False: 0]
  ------------------
  724|  5.46k|        w = send(s->fd, buffer, len, flags);
  725|  5.46k|    } else {
  726|      0|        w = write(s->fd, buffer, len);
  727|      0|    }
  728|       |#ifdef _WIN32
  729|       |    s->last_errno = WSAGetLastError();
  730|       |#else
  731|  5.46k|    s->last_errno = errno;
  732|  5.46k|#endif
  733|  5.46k|    s->write_wontblock = 0;
  734|       |    /* Reactive the POLLOUT detector in the poll multiplexer system */
  735|  5.46k|    if (s->poll_handle) {
  ------------------
  |  Branch (735:9): [True: 5.46k, False: 0]
  ------------------
  736|  5.46k|        SSH_LOG(SSH_LOG_PACKET, "Enabling POLLOUT for socket");
  ------------------
  |  |  281|  5.46k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  737|  5.46k|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  738|  5.46k|    }
  739|  5.46k|    if (w < 0) {
  ------------------
  |  Branch (739:9): [True: 273, False: 5.18k]
  ------------------
  740|    273|        s->data_except = 1;
  741|    273|    }
  742|       |
  743|  5.46k|    SSH_LOG(SSH_LOG_TRACE, "wrote %zd", w);
  ------------------
  |  |  281|  5.46k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  744|  5.46k|    return w;
  745|  5.46k|}

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

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|    273|{
   97|    273|    if (user_callbacks != NULL) {
  ------------------
  |  Branch (97:9): [True: 273, False: 0]
  ------------------
   98|    273|        return user_callbacks->type;
   99|    273|    }
  100|      0|    return NULL;
  101|    273|}

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

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

ssh_get_hmactab:
   74|    546|struct ssh_hmac_struct *ssh_get_hmactab(void) {
   75|    546|  return ssh_hmac_tab;
   76|    546|}
hmac_digest_len:
   78|  15.0k|size_t hmac_digest_len(enum ssh_hmac_e type) {
   79|  15.0k|  switch(type) {
   80|  7.39k|    case SSH_HMAC_SHA1:
  ------------------
  |  Branch (80:5): [True: 7.39k, False: 7.65k]
  ------------------
   81|  7.39k|      return SHA_DIGEST_LEN;
  ------------------
  |  |   44|  7.39k|#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
  ------------------
   82|  2.53k|    case SSH_HMAC_SHA256:
  ------------------
  |  Branch (82:5): [True: 2.53k, False: 12.5k]
  ------------------
   83|  2.53k|      return SHA256_DIGEST_LEN;
  ------------------
  |  |   45|  2.53k|#define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
  ------------------
   84|      0|    case SSH_HMAC_SHA512:
  ------------------
  |  Branch (84:5): [True: 0, False: 15.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: 15.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: 15.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: 15.0k]
  ------------------
   91|      0|      return AES_GCM_TAGLEN;
  ------------------
  |  |   58|      0|#define AES_GCM_TAGLEN 16
  ------------------
   92|  5.11k|    default:
  ------------------
  |  Branch (92:5): [True: 5.11k, False: 9.93k]
  ------------------
   93|  5.11k|      return 0;
   94|  15.0k|  }
   95|  15.0k|}
ssh_cipher_clear:
  124|  3.27k|void ssh_cipher_clear(struct ssh_cipher_struct *cipher){
  125|       |#ifdef HAVE_LIBGCRYPT
  126|       |    unsigned int i;
  127|       |#endif
  128|       |
  129|  3.27k|    if (cipher == NULL) {
  ------------------
  |  Branch (129:9): [True: 2.18k, False: 1.09k]
  ------------------
  130|  2.18k|        return;
  131|  2.18k|    }
  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|  1.09k|    if (cipher->cleanup != NULL) {
  ------------------
  |  Branch (142:9): [True: 484, False: 608]
  ------------------
  143|    484|        cipher->cleanup(cipher);
  144|    484|    }
  145|  1.09k|}
crypto_new:
  153|  1.63k|{
  154|  1.63k|    struct ssh_crypto_struct *crypto = NULL;
  155|       |
  156|  1.63k|    crypto = calloc(1, sizeof(struct ssh_crypto_struct));
  157|  1.63k|    if (crypto == NULL) {
  ------------------
  |  Branch (157:9): [True: 0, False: 1.63k]
  ------------------
  158|      0|        return NULL;
  159|      0|    }
  160|  1.63k|    return crypto;
  161|  1.63k|}
crypto_free:
  164|  2.18k|{
  165|  2.18k|    size_t i;
  166|       |
  167|  2.18k|    if (crypto == NULL) {
  ------------------
  |  Branch (167:9): [True: 546, False: 1.63k]
  ------------------
  168|    546|        return;
  169|    546|    }
  170|       |
  171|  1.63k|    ssh_key_free(crypto->server_pubkey);
  172|       |
  173|  1.63k|    ssh_dh_cleanup(crypto);
  174|  1.63k|    bignum_safe_free(crypto->shared_secret);
  ------------------
  |  |   71|  1.63k|#define bignum_safe_free(num) do { \
  |  |   72|  1.63k|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 0, False: 1.63k]
  |  |  ------------------
  |  |   73|      0|        BN_clear_free((num)); \
  |  |   74|      0|        (num)=NULL; \
  |  |   75|      0|    } \
  |  |   76|  1.63k|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 1.63k]
  |  |  ------------------
  ------------------
  175|  1.63k|#ifdef HAVE_ECDH
  176|  1.63k|    SAFE_FREE(crypto->ecdh_client_pubkey);
  ------------------
  |  |  373|  1.63k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.63k]
  |  |  |  Branch (373:71): [Folded, False: 1.63k]
  |  |  ------------------
  ------------------
  177|  1.63k|    SAFE_FREE(crypto->ecdh_server_pubkey);
  ------------------
  |  |  373|  1.63k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.63k]
  |  |  |  Branch (373:71): [Folded, False: 1.63k]
  |  |  ------------------
  ------------------
  178|  1.63k|    if (crypto->ecdh_privkey != NULL) {
  ------------------
  |  Branch (178:9): [True: 0, False: 1.63k]
  ------------------
  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|  1.63k|#endif
  194|  1.63k|#ifdef HAVE_LIBCRYPTO
  195|  1.63k|    EVP_PKEY_free(crypto->curve25519_privkey);
  196|       |#elif defined(HAVE_GCRYPT_CURVE25519)
  197|       |    gcry_sexp_release(crypto->curve25519_privkey);
  198|       |#endif
  199|  1.63k|    SAFE_FREE(crypto->dh_server_signature);
  ------------------
  |  |  373|  1.63k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 1.63k]
  |  |  |  Branch (373:71): [Folded, False: 1.63k]
  |  |  ------------------
  ------------------
  200|  1.63k|    if (crypto->session_id != NULL) {
  ------------------
  |  Branch (200:9): [True: 1.09k, False: 546]
  ------------------
  201|  1.09k|        ssh_burn(crypto->session_id, crypto->session_id_len);
  ------------------
  |  |  388|  1.09k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  202|  1.09k|        SAFE_FREE(crypto->session_id);
  ------------------
  |  |  373|  1.09k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.09k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
  203|  1.09k|    }
  204|  1.63k|    if (crypto->secret_hash != NULL) {
  ------------------
  |  Branch (204:9): [True: 546, False: 1.09k]
  ------------------
  205|    546|        ssh_burn(crypto->secret_hash, crypto->digest_len);
  ------------------
  |  |  388|    546|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  206|    546|        SAFE_FREE(crypto->secret_hash);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  207|    546|    }
  208|  1.63k|    compress_cleanup(crypto);
  209|  1.63k|    SAFE_FREE(crypto->encryptIV);
  ------------------
  |  |  373|  1.63k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 1.09k]
  |  |  |  Branch (373:71): [Folded, False: 1.63k]
  |  |  ------------------
  ------------------
  210|  1.63k|    SAFE_FREE(crypto->decryptIV);
  ------------------
  |  |  373|  1.63k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 1.09k]
  |  |  |  Branch (373:71): [Folded, False: 1.63k]
  |  |  ------------------
  ------------------
  211|  1.63k|    SAFE_FREE(crypto->encryptMAC);
  ------------------
  |  |  373|  1.63k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 1.09k]
  |  |  |  Branch (373:71): [Folded, False: 1.63k]
  |  |  ------------------
  ------------------
  212|  1.63k|    SAFE_FREE(crypto->decryptMAC);
  ------------------
  |  |  373|  1.63k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 1.09k]
  |  |  |  Branch (373:71): [Folded, False: 1.63k]
  |  |  ------------------
  ------------------
  213|  1.63k|    if (crypto->encryptkey != NULL) {
  ------------------
  |  Branch (213:9): [True: 546, False: 1.09k]
  ------------------
  214|    546|        ssh_burn(crypto->encryptkey, crypto->out_cipher->keysize / 8);
  ------------------
  |  |  388|    546|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  215|    546|        SAFE_FREE(crypto->encryptkey);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  216|    546|    }
  217|  1.63k|    if (crypto->decryptkey != NULL) {
  ------------------
  |  Branch (217:9): [True: 546, False: 1.09k]
  ------------------
  218|    546|        ssh_burn(crypto->decryptkey, crypto->in_cipher->keysize / 8);
  ------------------
  |  |  388|    546|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  219|    546|        SAFE_FREE(crypto->decryptkey);
  ------------------
  |  |  373|    546|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 546, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 546]
  |  |  ------------------
  ------------------
  220|    546|    }
  221|       |
  222|  1.63k|    cipher_free(crypto->in_cipher);
  223|  1.63k|    cipher_free(crypto->out_cipher);
  224|       |
  225|  18.0k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  18.0k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (225:17): [True: 16.3k, False: 1.63k]
  ------------------
  226|  16.3k|        SAFE_FREE(crypto->client_kex.methods[i]);
  ------------------
  |  |  373|  16.3k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 5.46k, False: 10.9k]
  |  |  |  Branch (373:71): [Folded, False: 16.3k]
  |  |  ------------------
  ------------------
  227|  16.3k|        SAFE_FREE(crypto->server_kex.methods[i]);
  ------------------
  |  |  373|  16.3k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 5.46k, False: 10.9k]
  |  |  |  Branch (373:71): [Folded, False: 16.3k]
  |  |  ------------------
  ------------------
  228|  16.3k|        SAFE_FREE(crypto->kex_methods[i]);
  ------------------
  |  |  373|  16.3k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 5.46k, False: 10.9k]
  |  |  |  Branch (373:71): [Folded, False: 16.3k]
  |  |  ------------------
  ------------------
  229|  16.3k|    }
  230|       |
  231|       |#ifdef HAVE_OPENSSL_MLKEM
  232|       |    EVP_PKEY_free(crypto->mlkem_privkey);
  233|       |#else
  234|  1.63k|    if (crypto->mlkem_privkey != NULL) {
  ------------------
  |  Branch (234:9): [True: 273, False: 1.36k]
  ------------------
  235|    273|        ssh_burn(crypto->mlkem_privkey, crypto->mlkem_privkey_len);
  ------------------
  |  |  388|    273|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  236|    273|        SAFE_FREE(crypto->mlkem_privkey);
  ------------------
  |  |  373|    273|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 273, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 273]
  |  |  ------------------
  ------------------
  237|    273|        crypto->mlkem_privkey_len = 0;
  238|    273|    }
  239|  1.63k|#endif
  240|  1.63k|    ssh_string_burn(crypto->hybrid_shared_secret);
  241|  1.63k|    ssh_string_free(crypto->mlkem_client_pubkey);
  242|  1.63k|    ssh_string_free(crypto->mlkem_ciphertext);
  243|  1.63k|    ssh_string_free(crypto->hybrid_client_init);
  244|  1.63k|    ssh_string_free(crypto->hybrid_server_reply);
  245|  1.63k|    ssh_string_free(crypto->hybrid_shared_secret);
  246|       |
  247|  1.63k|    ssh_burn(crypto, sizeof(struct ssh_crypto_struct));
  ------------------
  |  |  388|  1.63k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  248|       |
  249|       |    SAFE_FREE(crypto);
  ------------------
  |  |  373|  1.63k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.63k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.63k]
  |  |  ------------------
  ------------------
  250|  1.63k|}
crypt_set_algorithms_client:
  429|    273|{
  430|    273|    return crypt_set_algorithms2(session);
  431|    273|}
crypt_set_algorithms_server:
  434|    273|int crypt_set_algorithms_server(ssh_session session){
  435|    273|    const char *method = NULL;
  436|    273|    uint8_t i = 0;
  437|    273|    struct ssh_cipher_struct *ssh_ciphertab=ssh_get_ciphertab();
  438|    273|    struct ssh_hmac_struct   *ssh_hmactab=ssh_get_hmactab();
  439|    273|    int cmp;
  440|    273|    int rc;
  441|       |
  442|    273|    if (session == NULL) {
  ------------------
  |  Branch (442:9): [True: 0, False: 273]
  ------------------
  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|    273|    method = session->next_crypto->kex_methods[SSH_CRYPT_S_C];
  452|       |
  453|  2.03k|    for (i = 0; ssh_ciphertab[i].name != NULL; i++) {
  ------------------
  |  Branch (453:17): [True: 2.03k, False: 0]
  ------------------
  454|  2.03k|        cmp = strcmp(method, ssh_ciphertab[i].name);
  455|  2.03k|        if (cmp == 0) {
  ------------------
  |  Branch (455:13): [True: 273, False: 1.76k]
  ------------------
  456|    273|          break;
  457|    273|        }
  458|  2.03k|    }
  459|       |
  460|    273|    if (ssh_ciphertab[i].name == NULL) {
  ------------------
  |  Branch (460:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_PACKET,"Set output algorithm %s",method);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  466|       |
  467|    273|    session->next_crypto->out_cipher = cipher_new(i);
  468|    273|    if (session->next_crypto->out_cipher == NULL) {
  ------------------
  |  Branch (468:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (session->next_crypto->out_cipher->aead_encrypt != NULL){
  ------------------
  |  Branch (473:9): [True: 0, False: 273]
  ------------------
  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|    273|    } else {
  481|       |        /* we must scan the kex entries to find hmac algorithms and set their appropriate structure */
  482|       |        /* out */
  483|    273|        method = session->next_crypto->kex_methods[SSH_MAC_S_C];
  484|    273|    }
  485|       |    /* HMAC algorithm selection */
  486|       |
  487|  1.55k|    for (i = 0; ssh_hmactab[i].name != NULL; i++) {
  ------------------
  |  Branch (487:17): [True: 1.55k, False: 0]
  ------------------
  488|  1.55k|        cmp = strcmp(method, ssh_hmactab[i].name);
  489|  1.55k|        if (cmp == 0) {
  ------------------
  |  Branch (489:13): [True: 273, False: 1.27k]
  ------------------
  490|    273|            break;
  491|    273|        }
  492|  1.55k|    }
  493|       |
  494|    273|    if (ssh_hmactab[i].name == NULL) {
  ------------------
  |  Branch (494:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_PACKET, "Set HMAC output algorithm to %s", method);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  501|       |
  502|    273|    session->next_crypto->out_hmac = ssh_hmactab[i].hmac_type;
  503|    273|    session->next_crypto->out_hmac_etm = ssh_hmactab[i].etm;
  504|       |
  505|       |    /* in */
  506|    273|    method = session->next_crypto->kex_methods[SSH_CRYPT_C_S];
  507|       |
  508|  2.03k|    for (i = 0; ssh_ciphertab[i].name; i++) {
  ------------------
  |  Branch (508:17): [True: 2.03k, False: 0]
  ------------------
  509|  2.03k|        cmp = strcmp(method, ssh_ciphertab[i].name);
  510|  2.03k|        if (cmp == 0) {
  ------------------
  |  Branch (510:13): [True: 273, False: 1.76k]
  ------------------
  511|    273|            break;
  512|    273|        }
  513|  2.03k|    }
  514|       |
  515|    273|    if (ssh_ciphertab[i].name == NULL) {
  ------------------
  |  Branch (515:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_PACKET,"Set input algorithm %s",method);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  521|       |
  522|    273|    session->next_crypto->in_cipher = cipher_new(i);
  523|    273|    if (session->next_crypto->in_cipher == NULL) {
  ------------------
  |  Branch (523:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (session->next_crypto->in_cipher->aead_encrypt != NULL){
  ------------------
  |  Branch (528:9): [True: 0, False: 273]
  ------------------
  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|    273|    } else {
  536|       |        /* we must scan the kex entries to find hmac algorithms and set their appropriate structure */
  537|    273|        method = session->next_crypto->kex_methods[SSH_MAC_C_S];
  538|    273|    }
  539|       |
  540|  1.55k|    for (i = 0; ssh_hmactab[i].name != NULL; i++) {
  ------------------
  |  Branch (540:17): [True: 1.55k, False: 0]
  ------------------
  541|  1.55k|        cmp = strcmp(method, ssh_hmactab[i].name);
  542|  1.55k|        if (cmp == 0) {
  ------------------
  |  Branch (542:13): [True: 273, False: 1.27k]
  ------------------
  543|    273|            break;
  544|    273|        }
  545|  1.55k|    }
  546|       |
  547|    273|    if (ssh_hmactab[i].name == NULL) {
  ------------------
  |  Branch (547:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_PACKET, "Set HMAC input algorithm to %s", method);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  554|       |
  555|    273|    session->next_crypto->in_hmac = ssh_hmactab[i].hmac_type;
  556|    273|    session->next_crypto->in_hmac_etm = ssh_hmactab[i].etm;
  557|       |
  558|       |    /* compression */
  559|    273|    method = session->next_crypto->kex_methods[SSH_COMP_C_S];
  560|    273|    cmp = strcmp(method, "zlib");
  561|    273|    if (cmp == 0) {
  ------------------
  |  Branch (561:9): [True: 0, False: 273]
  ------------------
  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|    273|    cmp = strcmp(method, "zlib@openssh.com");
  566|    273|    if (cmp == 0) {
  ------------------
  |  Branch (566:9): [True: 0, False: 273]
  ------------------
  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|    273|    method = session->next_crypto->kex_methods[SSH_COMP_S_C];
  572|    273|    cmp = strcmp(method, "zlib");
  573|    273|    if (cmp == 0) {
  ------------------
  |  Branch (573:9): [True: 0, False: 273]
  ------------------
  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|    273|    cmp = strcmp(method, "zlib@openssh.com");
  578|    273|    if (cmp == 0) {
  ------------------
  |  Branch (578:9): [True: 0, False: 273]
  ------------------
  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|    273|    method = session->next_crypto->kex_methods[SSH_HOSTKEYS];
  584|       |
  585|       |    /* For GSSAPI key exchange, hostkey algorithm may be "null" */
  586|    273|    if (strcmp(method, "null") == 0) {
  ------------------
  |  Branch (586:9): [True: 0, False: 273]
  ------------------
  587|      0|        session->srv.hostkey = SSH_KEYTYPE_UNKNOWN;
  588|      0|        session->srv.hostkey_digest = SSH_DIGEST_AUTO;
  589|    273|    } else {
  590|    273|        rc = ssh_key_type_and_hash_from_signature_name(
  591|    273|            method,
  592|    273|            &session->srv.hostkey,
  593|    273|            &session->srv.hostkey_digest);
  594|    273|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (594:13): [True: 0, False: 273]
  ------------------
  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|    273|    }
  602|       |
  603|       |    /* setup DH key exchange type */
  604|    273|    switch (session->next_crypto->kex_type) {
  605|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (605:5): [True: 0, False: 273]
  ------------------
  606|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (606:5): [True: 0, False: 273]
  ------------------
  607|      0|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (607:5): [True: 0, False: 273]
  ------------------
  608|      0|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (608:5): [True: 0, False: 273]
  ------------------
  609|      0|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (609:5): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  622|      0|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (622:5): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  628|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (628:5): [True: 0, False: 273]
  ------------------
  629|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (629:5): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  635|      0|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (635:5): [True: 0, False: 273]
  ------------------
  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: 273]
  ------------------
  641|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (641:5): [True: 0, False: 273]
  ------------------
  642|      0|        ssh_server_sntrup761x25519_init(session);
  643|      0|        break;
  644|      0|#endif
  645|    273|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (645:5): [True: 273, False: 0]
  ------------------
  646|    273|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (646:5): [True: 0, False: 273]
  ------------------
  647|       |#ifdef HAVE_MLKEM1024
  648|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  649|       |#endif
  650|    273|        ssh_server_hybrid_mlkem_init(session);
  651|    273|        break;
  652|      0|    default:
  ------------------
  |  Branch (652:5): [True: 0, False: 273]
  ------------------
  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|    273|    }
  660|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  661|    273|}
wrapper.c:cipher_free:
  147|  3.27k|static void cipher_free(struct ssh_cipher_struct *cipher) {
  148|  3.27k|  ssh_cipher_clear(cipher);
  149|       |  SAFE_FREE(cipher);
  ------------------
  |  |  373|  3.27k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.09k, False: 2.18k]
  |  |  |  Branch (373:71): [Folded, False: 3.27k]
  |  |  ------------------
  ------------------
  150|  3.27k|}
wrapper.c:crypt_set_algorithms2:
  275|    273|{
  276|    273|    const char *wanted = NULL;
  277|    273|    const char *method = NULL;
  278|    273|    struct ssh_cipher_struct *ssh_ciphertab=ssh_get_ciphertab();
  279|    273|    struct ssh_hmac_struct *ssh_hmactab=ssh_get_hmactab();
  280|    273|    uint8_t i = 0;
  281|    273|    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|    273|    wanted = session->next_crypto->kex_methods[SSH_CRYPT_C_S];
  290|  2.03k|    for (i = 0; i < 64 && ssh_ciphertab[i].name != NULL; ++i) {
  ------------------
  |  Branch (290:17): [True: 2.03k, False: 0]
  |  Branch (290:27): [True: 2.03k, False: 0]
  ------------------
  291|  2.03k|        cmp = strcmp(wanted, ssh_ciphertab[i].name);
  292|  2.03k|        if (cmp == 0) {
  ------------------
  |  Branch (292:13): [True: 273, False: 1.76k]
  ------------------
  293|    273|            break;
  294|    273|        }
  295|  2.03k|    }
  296|       |
  297|    273|    if (ssh_ciphertab[i].name == NULL) {
  ------------------
  |  Branch (297:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_PACKET, "Set output algorithm to %s", wanted);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  304|       |
  305|    273|    session->next_crypto->out_cipher = cipher_new(i);
  306|    273|    if (session->next_crypto->out_cipher == NULL) {
  ------------------
  |  Branch (306:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (session->next_crypto->out_cipher->aead_encrypt != NULL) {
  ------------------
  |  Branch (311:9): [True: 0, False: 273]
  ------------------
  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|    273|    } else {
  319|       |        /*
  320|       |         * We must scan the kex entries to find hmac algorithms and set their
  321|       |         * appropriate structure.
  322|       |         */
  323|       |
  324|       |        /* out */
  325|    273|        wanted = session->next_crypto->kex_methods[SSH_MAC_C_S];
  326|    273|    }
  327|       |
  328|  1.55k|    for (i = 0; ssh_hmactab[i].name != NULL; i++) {
  ------------------
  |  Branch (328:17): [True: 1.55k, False: 0]
  ------------------
  329|  1.55k|        cmp = strcmp(wanted, ssh_hmactab[i].name);
  330|  1.55k|        if (cmp == 0) {
  ------------------
  |  Branch (330:13): [True: 273, False: 1.27k]
  ------------------
  331|    273|            break;
  332|    273|        }
  333|  1.55k|    }
  334|       |
  335|    273|    if (ssh_hmactab[i].name == NULL) {
  ------------------
  |  Branch (335:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_PACKET, "Set HMAC output algorithm to %s", wanted);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  342|       |
  343|    273|    session->next_crypto->out_hmac = ssh_hmactab[i].hmac_type;
  344|    273|    session->next_crypto->out_hmac_etm = ssh_hmactab[i].etm;
  345|       |
  346|       |    /* in */
  347|    273|    wanted = session->next_crypto->kex_methods[SSH_CRYPT_S_C];
  348|       |
  349|  2.03k|    for (i = 0; ssh_ciphertab[i].name != NULL; i++) {
  ------------------
  |  Branch (349:17): [True: 2.03k, False: 0]
  ------------------
  350|  2.03k|        cmp = strcmp(wanted, ssh_ciphertab[i].name);
  351|  2.03k|        if (cmp == 0) {
  ------------------
  |  Branch (351:13): [True: 273, False: 1.76k]
  ------------------
  352|    273|            break;
  353|    273|        }
  354|  2.03k|    }
  355|       |
  356|    273|    if (ssh_ciphertab[i].name == NULL) {
  ------------------
  |  Branch (356:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_PACKET, "Set input algorithm to %s", wanted);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  363|       |
  364|    273|    session->next_crypto->in_cipher = cipher_new(i);
  365|    273|    if (session->next_crypto->in_cipher == NULL) {
  ------------------
  |  Branch (365:9): [True: 0, False: 273]
  ------------------
  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|    273|    if (session->next_crypto->in_cipher->aead_encrypt != NULL){
  ------------------
  |  Branch (370:9): [True: 0, False: 273]
  ------------------
  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|    273|    } else {
  378|       |        /* we must scan the kex entries to find hmac algorithms and set their appropriate structure */
  379|    273|        wanted = session->next_crypto->kex_methods[SSH_MAC_S_C];
  380|    273|    }
  381|       |
  382|  1.55k|    for (i = 0; ssh_hmactab[i].name != NULL; i++) {
  ------------------
  |  Branch (382:17): [True: 1.55k, False: 0]
  ------------------
  383|  1.55k|        cmp = strcmp(wanted, ssh_hmactab[i].name);
  384|  1.55k|        if (cmp == 0) {
  ------------------
  |  Branch (384:13): [True: 273, False: 1.27k]
  ------------------
  385|    273|            break;
  386|    273|        }
  387|  1.55k|    }
  388|       |
  389|    273|    if (ssh_hmactab[i].name == NULL) {
  ------------------
  |  Branch (389:9): [True: 0, False: 273]
  ------------------
  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|    273|    SSH_LOG(SSH_LOG_PACKET, "Set HMAC input algorithm to %s", wanted);
  ------------------
  |  |  281|    273|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  396|       |
  397|    273|    session->next_crypto->in_hmac = ssh_hmactab[i].hmac_type;
  398|    273|    session->next_crypto->in_hmac_etm = ssh_hmactab[i].etm;
  399|       |
  400|       |    /* compression: client */
  401|    273|    method = session->next_crypto->kex_methods[SSH_COMP_C_S];
  402|    273|    cmp = strcmp(method, "zlib");
  403|    273|    if (cmp == 0) {
  ------------------
  |  Branch (403:9): [True: 0, False: 273]
  ------------------
  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|    273|    cmp = strcmp(method, "zlib@openssh.com");
  408|    273|    if (cmp == 0) {
  ------------------
  |  Branch (408:9): [True: 0, False: 273]
  ------------------
  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|    273|    method = session->next_crypto->kex_methods[SSH_COMP_S_C];
  414|    273|    cmp = strcmp(method, "zlib");
  415|    273|    if (cmp == 0) {
  ------------------
  |  Branch (415:9): [True: 0, False: 273]
  ------------------
  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|    273|    cmp = strcmp(method, "zlib@openssh.com");
  420|    273|    if (cmp == 0) {
  ------------------
  |  Branch (420:9): [True: 0, False: 273]
  ------------------
  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|    273|    return SSH_OK;
  ------------------
  |  |  316|    273|#define SSH_OK 0     /* No error */
  ------------------
  426|    273|}
wrapper.c:cipher_new:
  110|  1.09k|static struct ssh_cipher_struct *cipher_new(uint8_t offset) {
  111|  1.09k|  struct ssh_cipher_struct *cipher = NULL;
  112|       |
  113|  1.09k|  cipher = malloc(sizeof(struct ssh_cipher_struct));
  114|  1.09k|  if (cipher == NULL) {
  ------------------
  |  Branch (114:7): [True: 0, False: 1.09k]
  ------------------
  115|      0|    return NULL;
  116|      0|  }
  117|       |
  118|       |  /* note the memcpy will copy the pointers : so, you shouldn't free them */
  119|  1.09k|  memcpy(cipher, &ssh_get_ciphertab()[offset], sizeof(*cipher));
  120|       |
  121|  1.09k|  return cipher;
  122|  1.09k|}

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|  5.01k|{
  290|  5.01k|    if (nalloc_fail(count, "recv")) {
  ------------------
  |  Branch (290:9): [True: 0, False: 5.01k]
  ------------------
  291|      0|        errno = EIO;
  292|      0|        return -1;
  293|      0|    }
  294|  5.01k|    return nalloc_recv(fd, buf, count, flags);
  ------------------
  |  |  265|  5.01k|#define nalloc_recv(f, b, s, x) __recv(f, b, s, x)
  ------------------
  295|  5.01k|}
send:
  298|  5.45k|{
  299|  5.45k|    if (nalloc_fail(count, "send")) {
  ------------------
  |  Branch (299:9): [True: 0, False: 5.45k]
  ------------------
  300|      0|        errno = EIO;
  301|      0|        return -1;
  302|      0|    }
  303|  5.45k|    return nalloc_send(fd, buf, count, flags);
  ------------------
  |  |  266|  5.45k|#define nalloc_send(f, b, s, x) __send(f, b, s, x)
  ------------------
  304|  5.45k|}
calloc:
  307|  83.7k|{
  308|  83.7k|    if (nalloc_fail(size, "calloc")) {
  ------------------
  |  Branch (308:9): [True: 0, False: 83.7k]
  ------------------
  309|      0|        errno = ENOMEM;
  310|      0|        return NULL;
  311|      0|    }
  312|  83.7k|    return nalloc_calloc(nmemb, size);
  ------------------
  |  |  259|  83.7k|#define nalloc_calloc(s, n)          __libc_calloc(s, n)
  ------------------
  313|  83.7k|}
malloc:
  316|   242k|{
  317|   242k|    if (nalloc_fail(size, "malloc")) {
  ------------------
  |  Branch (317:9): [True: 0, False: 242k]
  ------------------
  318|      0|        errno = ENOMEM;
  319|      0|        return NULL;
  320|      0|    }
  321|   242k|    return nalloc_malloc(size);
  ------------------
  |  |  258|   242k|#define nalloc_malloc(s)             __libc_malloc(s)
  ------------------
  322|   242k|}
realloc:
  325|  24.0k|{
  326|  24.0k|    if (nalloc_fail(size, "realloc")) {
  ------------------
  |  Branch (326:9): [True: 0, False: 24.0k]
  ------------------
  327|      0|        errno = ENOMEM;
  328|      0|        return NULL;
  329|      0|    }
  330|  24.0k|    return nalloc_realloc(ptr, size);
  ------------------
  |  |  260|  24.0k|#define nalloc_realloc(p, s)         __libc_realloc(p, s)
  ------------------
  331|  24.0k|}
ssh_scp_fuzzer.c:nalloc_fail:
  194|   359k|{
  195|       |    // do not fail before thread init
  196|   359k|    if (nalloc_runs == 0) {
  ------------------
  |  Branch (196:9): [True: 359k, False: 18.4E]
  ------------------
  197|   359k|        return false;
  198|   359k|    }
  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|    273|{
  152|    273|    if (nalloc_random_bitmask) {
  ------------------
  |  Branch (152:9): [True: 0, False: 273]
  ------------------
  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|    273|    } else if (nalloc_bitmask == 0) {
  ------------------
  |  Branch (158:16): [True: 273, False: 0]
  ------------------
  159|       |        // nalloc disabled
  160|    273|        return 2;
  161|    273|    }
  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|    273|{
  177|    273|    __sync_fetch_and_sub(&nalloc_running, 1);
  178|    273|}

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

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

