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

ssh_agent_state_free:
 1148|    706|{
 1149|    706|    struct ssh_agent_state_struct *state = data;
 1150|       |
 1151|    706|    if (state) {
  ------------------
  |  Branch (1151:9): [True: 0, False: 706]
  ------------------
 1152|       |        SSH_STRING_FREE_CHAR(state->comment);
  ------------------
  |  |  933|      0|    do { if ((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (933:14): [True: 0, False: 0]
  |  |  |  Branch (933:74): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1153|      0|        ssh_key_free(state->pubkey);
 1154|      0|        free(state);
 1155|      0|    }
 1156|    706|}

ssh_make_bignum_string:
   69|    186|{
   70|    186|    return make_bignum_string(num, 0);
   71|    186|}
ssh_make_string_bn:
   79|    108|{
   80|    108|    bignum bn = NULL;
   81|    108|    size_t len = ssh_string_len(string);
   82|       |
   83|       |#ifdef DEBUG_CRYPTO
   84|       |    SSH_LOG(SSH_LOG_TRACE,
   85|       |            "Importing a %zu bits, %zu bytes object ...",
   86|       |            len * 8,
   87|       |            len);
   88|       |#endif /* DEBUG_CRYPTO */
   89|       |
   90|    108|    bignum_bin2bn(string->data, (int)len, &bn);
  ------------------
  |  |   79|    108|    do {                                     \
  |  |   80|    108|        (*dest) = BN_new();                  \
  |  |   81|    108|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 108, False: 0]
  |  |  ------------------
  |  |   82|    108|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|    108|        }                                    \
  |  |   84|    108|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 108]
  |  |  ------------------
  ------------------
   91|       |
   92|    108|    return bn;
   93|    108|}
bignum.c:make_bignum_string:
   31|    186|{
   32|    186|    ssh_string ptr = NULL;
   33|    186|    size_t pad = 0;
   34|    186|    size_t len = bignum_num_bytes(num);
  ------------------
  |  |   98|    186|#define bignum_num_bytes(num) (size_t)BN_num_bytes(num)
  ------------------
   35|    186|    size_t bits = bignum_num_bits(num);
  ------------------
  |  |   99|    186|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
   36|       |
   37|    186|    if (pad_to_len == 0) {
  ------------------
  |  Branch (37:9): [True: 186, False: 0]
  ------------------
   38|       |        /* If the first bit is set we have a negative number */
   39|    186|        if (!(bits % 8) && bignum_is_bit_set(num, bits - 1)) {
  ------------------
  |  |  100|     73|#define bignum_is_bit_set(num,bit) BN_is_bit_set(num, (int)bit)
  |  |  ------------------
  |  |  |  Branch (100:36): [True: 71, False: 2]
  |  |  ------------------
  ------------------
  |  Branch (39:13): [True: 73, False: 113]
  ------------------
   40|     71|            pad++;
   41|     71|        }
   42|    186|    } else {
   43|      0|        if (len > pad_to_len) {
  ------------------
  |  Branch (43:13): [True: 0, False: 0]
  ------------------
   44|      0|            return NULL;
   45|      0|        }
   46|      0|        pad = pad_to_len - len;
   47|      0|    }
   48|       |
   49|       |#ifdef DEBUG_CRYPTO
   50|       |    SSH_LOG(SSH_LOG_TRACE, "%zu bits, %zu bytes, %zu padding", bits, len, pad);
   51|       |#endif /* DEBUG_CRYPTO */
   52|       |
   53|    186|    ptr = ssh_string_new(len + pad);
   54|    186|    if (ptr == NULL) {
  ------------------
  |  Branch (54:9): [True: 0, False: 186]
  ------------------
   55|      0|        return NULL;
   56|      0|    }
   57|       |
   58|       |    /* We have a negative number so we need a leading zero */
   59|    186|    if (pad) {
  ------------------
  |  Branch (59:9): [True: 71, False: 115]
  ------------------
   60|     71|        memset(ptr->data, 0, pad);
   61|     71|    }
   62|       |
   63|    186|    bignum_bn2bin(num, len, ptr->data + pad);
  ------------------
  |  |  101|    186|#define bignum_bn2bin(num,len, ptr) BN_bn2bin(num, ptr)
  ------------------
   64|       |
   65|    186|    return ptr;
   66|    186|}

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

_ssh_remove_legacy_log_cb:
   49|    706|{
   50|    706|    if (ssh_get_log_callback() == ssh_legacy_log_callback) {
  ------------------
  |  Branch (50:9): [True: 0, False: 706]
  ------------------
   51|      0|        _ssh_reset_log_cb();
   52|       |        ssh_set_log_userdata(NULL);
   53|      0|    }
   54|    706|}
ssh_set_callbacks:
   57|    486|{
   58|    486|    if (session == NULL || cb == NULL) {
  ------------------
  |  Branch (58:9): [True: 0, False: 486]
  |  Branch (58:28): [True: 0, False: 486]
  ------------------
   59|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   60|      0|    }
   61|       |
   62|    486|    if (!is_callback_valid(session, cb)) {
  ------------------
  |  |   31|    486|    (cb->size > 0 || cb->size <= 1024 * sizeof(void *))
  |  |  ------------------
  |  |  |  Branch (31:6): [True: 486, False: 0]
  |  |  |  Branch (31:22): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   63|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   64|      0|                      SSH_FATAL,
   65|      0|                      "Invalid callback passed in (badly initialized)");
   66|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   67|    486|    };
   68|    486|    session->common.callbacks = cb;
   69|       |
   70|       |    /* LEGACY */
   71|    486|    if (ssh_get_log_callback() == NULL && cb->log_function) {
  ------------------
  |  Branch (71:9): [True: 486, False: 0]
  |  Branch (71:43): [True: 0, False: 486]
  ------------------
   72|      0|        ssh_set_log_callback(ssh_legacy_log_callback);
   73|      0|        ssh_set_log_userdata(session);
   74|      0|    }
   75|       |
   76|    486|    return 0;
   77|    486|}

ssh_channel_free:
 1301|    941|{
 1302|    941|    ssh_session session = NULL;
 1303|       |
 1304|    941|    if (channel == NULL) {
  ------------------
  |  Branch (1304:9): [True: 941, False: 0]
  ------------------
 1305|    941|        return;
 1306|    941|    }
 1307|       |
 1308|      0|    session = channel->session;
 1309|      0|    if (session->alive) {
  ------------------
  |  Branch (1309:9): [True: 0, False: 0]
  ------------------
 1310|      0|        bool send_close = false;
 1311|       |
 1312|      0|        switch (channel->state) {
 1313|      0|        case SSH_CHANNEL_STATE_OPEN:
  ------------------
  |  Branch (1313:9): [True: 0, False: 0]
  ------------------
 1314|      0|            send_close = true;
 1315|      0|            break;
 1316|      0|        case SSH_CHANNEL_STATE_CLOSED:
  ------------------
  |  Branch (1316:9): [True: 0, False: 0]
  ------------------
 1317|      0|            if (channel->flags & SSH_CHANNEL_FLAG_CLOSED_REMOTE) {
  ------------------
  |  |   55|      0|#define SSH_CHANNEL_FLAG_CLOSED_REMOTE 0x0001
  ------------------
  |  Branch (1317:17): [True: 0, False: 0]
  ------------------
 1318|      0|                send_close = true;
 1319|      0|            }
 1320|      0|            if (channel->flags & SSH_CHANNEL_FLAG_CLOSED_LOCAL) {
  ------------------
  |  |   58|      0|#define SSH_CHANNEL_FLAG_CLOSED_LOCAL 0x0002
  ------------------
  |  Branch (1320:17): [True: 0, False: 0]
  ------------------
 1321|      0|                send_close = false;
 1322|      0|            }
 1323|      0|            break;
 1324|      0|        default:
  ------------------
  |  Branch (1324:9): [True: 0, False: 0]
  ------------------
 1325|      0|            send_close = false;
 1326|      0|            break;
 1327|      0|        }
 1328|       |
 1329|      0|        if (send_close) {
  ------------------
  |  Branch (1329:13): [True: 0, False: 0]
  ------------------
 1330|      0|            ssh_channel_close(channel);
 1331|      0|        }
 1332|      0|    }
 1333|      0|    channel->flags |= SSH_CHANNEL_FLAG_FREED_LOCAL;
  ------------------
  |  |   61|      0|#define SSH_CHANNEL_FLAG_FREED_LOCAL 0x0004
  ------------------
 1334|       |
 1335|      0|    if (channel->callbacks != NULL) {
  ------------------
  |  Branch (1335:9): [True: 0, False: 0]
  ------------------
 1336|      0|        ssh_list_free(channel->callbacks);
 1337|      0|        channel->callbacks = NULL;
 1338|      0|    }
 1339|       |
 1340|       |    /* The idea behind the flags is the following : it is well possible
 1341|       |     * that a client closes a channel that still exists on the server side.
 1342|       |     * We definitively close the channel when we receive a close message *and*
 1343|       |     * the user closed it.
 1344|       |     */
 1345|      0|    if ((channel->flags & SSH_CHANNEL_FLAG_CLOSED_REMOTE) ||
  ------------------
  |  |   55|      0|#define SSH_CHANNEL_FLAG_CLOSED_REMOTE 0x0001
  ------------------
  |  Branch (1345:9): [True: 0, False: 0]
  ------------------
 1346|      0|        (channel->flags & SSH_CHANNEL_FLAG_NOT_BOUND)) {
  ------------------
  |  |   64|      0|#define SSH_CHANNEL_FLAG_NOT_BOUND 0x0008
  ------------------
  |  Branch (1346:9): [True: 0, False: 0]
  ------------------
 1347|      0|        ssh_channel_do_free(channel);
 1348|      0|    }
 1349|      0|}

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

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

ssh_curve25519_create_k:
   52|     19|{
   53|     19|    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|     19|    rc = curve25519_do_create_k(session, k);
   65|     19|    return rc;
   66|     19|}
ssh_client_curve25519_init:
   72|     41|{
   73|     41|    int rc;
   74|       |
   75|     41|    rc = ssh_curve25519_init(session);
   76|     41|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     41|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (76:9): [True: 0, False: 41]
  ------------------
   77|      0|        return rc;
   78|      0|    }
   79|       |
   80|     41|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|     41|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     41|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     41|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     41|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     41|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     41|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     41|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
   81|     41|                         "bdP",
   82|     41|                         SSH2_MSG_KEX_ECDH_INIT,
   83|     41|                         CURVE25519_PUBKEY_SIZE,
   84|     41|                         (size_t)CURVE25519_PUBKEY_SIZE,
   85|     41|                         session->next_crypto->curve25519_client_pubkey);
   86|     41|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     41|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (86:9): [True: 0, False: 41]
  ------------------
   87|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
   88|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   89|      0|    }
   90|       |
   91|       |    /* register the packet callbacks */
   92|     41|    ssh_packet_set_callbacks(session, &ssh_curve25519_client_callbacks);
   93|     41|    session->dh_handshake_state = DH_STATE_INIT_SENT;
   94|     41|    rc = ssh_packet_send(session);
   95|       |
   96|     41|    return rc;
   97|     41|}
ssh_client_curve25519_remove_callbacks:
  100|     39|{
  101|     39|    ssh_packet_remove_callbacks(session, &ssh_curve25519_client_callbacks);
  102|     39|}
ssh_curve25519_build_k:
  105|     19|{
  106|     19|    ssh_curve25519_pubkey k;
  107|     19|    int rc;
  108|       |
  109|     19|    rc = ssh_curve25519_create_k(session, k);
  110|     19|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     19|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (110:9): [True: 1, False: 18]
  ------------------
  111|      1|        return rc;
  112|      1|    }
  113|       |
  114|     18|    bignum_bin2bn(k,
  ------------------
  |  |   79|     18|    do {                                     \
  |  |   80|     18|        (*dest) = BN_new();                  \
  |  |   81|     18|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 18, False: 0]
  |  |  ------------------
  |  |   82|     18|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|     18|        }                                    \
  |  |   84|     18|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 18]
  |  |  ------------------
  ------------------
  115|     18|                  CURVE25519_PUBKEY_SIZE,
  116|     18|                  &session->next_crypto->shared_secret);
  117|     18|    if (session->next_crypto->shared_secret == NULL) {
  ------------------
  |  Branch (117:9): [True: 0, False: 18]
  ------------------
  118|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  119|      0|    }
  120|       |
  121|       |#ifdef DEBUG_CRYPTO
  122|       |    ssh_print_bignum("Shared secret key", session->next_crypto->shared_secret);
  123|       |#endif
  124|       |
  125|     18|    return SSH_OK;
  ------------------
  |  |  316|     18|#define SSH_OK 0     /* No error */
  ------------------
  126|     18|}
curve25519.c:ssh_packet_client_curve25519_reply:
  133|     39|{
  134|     39|    ssh_string q_s_string = NULL;
  135|     39|    ssh_string pubkey_blob = NULL;
  136|     39|    ssh_string signature = NULL;
  137|     39|    int rc;
  138|     39|    (void)type;
  139|     39|    (void)user;
  140|       |
  141|     39|    ssh_client_curve25519_remove_callbacks(session);
  142|       |
  143|     39|    pubkey_blob = ssh_buffer_get_ssh_string(packet);
  144|     39|    if (pubkey_blob == NULL) {
  ------------------
  |  Branch (144:9): [True: 0, False: 39]
  ------------------
  145|      0|        ssh_set_error(session, SSH_FATAL, "No public key in packet");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  146|      0|        goto error;
  147|      0|    }
  148|       |
  149|     39|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  150|     39|    SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  924|     39|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 39, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 39]
  |  |  ------------------
  ------------------
  151|     39|    if (rc != 0) {
  ------------------
  |  Branch (151:9): [True: 18, False: 21]
  ------------------
  152|     18|        ssh_set_error(session, SSH_FATAL, "Failed to import next public key");
  ------------------
  |  |  313|     18|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  153|     18|        goto error;
  154|     18|    }
  155|       |
  156|     21|    q_s_string = ssh_buffer_get_ssh_string(packet);
  157|     21|    if (q_s_string == NULL) {
  ------------------
  |  Branch (157:9): [True: 1, False: 20]
  ------------------
  158|      1|        ssh_set_error(session, SSH_FATAL, "No Q_S ECC point in packet");
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  159|      1|        goto error;
  160|      1|    }
  161|     20|    if (ssh_string_len(q_s_string) != CURVE25519_PUBKEY_SIZE) {
  ------------------
  |  |   40|     20|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  |  Branch (161:9): [True: 1, False: 19]
  ------------------
  162|      1|        ssh_set_error(session,
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  163|      1|                      SSH_FATAL,
  164|      1|                      "Incorrect size for server Curve25519 public key: %zu",
  165|      1|                      ssh_string_len(q_s_string));
  166|      1|        SSH_STRING_FREE(q_s_string);
  ------------------
  |  |  924|      1|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 1, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
  167|      1|        goto error;
  168|      1|    }
  169|     19|    memcpy(session->next_crypto->curve25519_server_pubkey,
  170|     19|           ssh_string_data(q_s_string),
  171|     19|           CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   40|     19|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  172|     19|    SSH_STRING_FREE(q_s_string);
  ------------------
  |  |  924|     19|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 19, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 19]
  |  |  ------------------
  ------------------
  173|       |
  174|     19|    signature = ssh_buffer_get_ssh_string(packet);
  175|     19|    if (signature == NULL) {
  ------------------
  |  Branch (175:9): [True: 0, False: 19]
  ------------------
  176|      0|        ssh_set_error(session, SSH_FATAL, "No signature in packet");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  177|      0|        goto error;
  178|      0|    }
  179|     19|    session->next_crypto->dh_server_signature = signature;
  180|     19|    signature = NULL; /* ownership changed */
  181|       |    /* TODO: verify signature now instead of waiting for NEWKEYS */
  182|     19|    if (ssh_curve25519_build_k(session) < 0) {
  ------------------
  |  Branch (182:9): [True: 1, False: 18]
  ------------------
  183|      1|        ssh_set_error(session, SSH_FATAL, "Cannot build k number");
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  184|      1|        goto error;
  185|      1|    }
  186|       |
  187|       |    /* Send the MSG_NEWKEYS */
  188|     18|    rc = ssh_packet_send_newkeys(session);
  189|     18|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     18|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (189:9): [True: 0, False: 18]
  ------------------
  190|      0|        goto error;
  191|      0|    }
  192|     18|    session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  193|       |
  194|     18|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     18|#define SSH_PACKET_USED 1
  ------------------
  195|       |
  196|     21|error:
  197|     21|    session->session_state = SSH_SESSION_STATE_ERROR;
  198|     21|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     21|#define SSH_PACKET_USED 1
  ------------------
  199|     18|}

ssh_curve25519_init:
   34|     67|{
   35|     67|    ssh_curve25519_pubkey *pubkey_loc = NULL;
   36|     67|    EVP_PKEY_CTX *pctx = NULL;
   37|     67|    EVP_PKEY *pkey = NULL;
   38|     67|    size_t pubkey_len = CURVE25519_PUBKEY_SIZE;
  ------------------
  |  |   40|     67|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
   39|     67|    int rc;
   40|       |
   41|     67|    if (session->server) {
  ------------------
  |  Branch (41:9): [True: 0, False: 67]
  ------------------
   42|      0|        pubkey_loc = &session->next_crypto->curve25519_server_pubkey;
   43|     67|    } else {
   44|     67|        pubkey_loc = &session->next_crypto->curve25519_client_pubkey;
   45|     67|    }
   46|       |
   47|     67|    pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_X25519, NULL);
   48|     67|    if (pctx == NULL) {
  ------------------
  |  Branch (48:9): [True: 0, False: 67]
  ------------------
   49|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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|     67|    rc = EVP_PKEY_keygen_init(pctx);
   56|     67|    if (rc != 1) {
  ------------------
  |  Branch (56:9): [True: 0, False: 67]
  ------------------
   57|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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|     67|    rc = EVP_PKEY_keygen(pctx, &pkey);
   65|     67|    EVP_PKEY_CTX_free(pctx);
   66|     67|    if (rc != 1) {
  ------------------
  |  Branch (66:9): [True: 0, False: 67]
  ------------------
   67|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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|     67|    rc = EVP_PKEY_get_raw_public_key(pkey, *pubkey_loc, &pubkey_len);
   74|     67|    if (rc != 1) {
  ------------------
  |  Branch (74:9): [True: 0, False: 67]
  ------------------
   75|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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|     67|    if (session->next_crypto->curve25519_privkey != NULL) {
  ------------------
  |  Branch (83:9): [True: 0, False: 67]
  ------------------
   84|      0|        EVP_PKEY_free(session->next_crypto->curve25519_privkey);
   85|      0|        session->next_crypto->curve25519_privkey = NULL;
   86|      0|    }
   87|       |
   88|     67|    session->next_crypto->curve25519_privkey = pkey;
   89|     67|    pkey = NULL;
   90|       |
   91|     67|    return SSH_OK;
  ------------------
  |  |  316|     67|#define SSH_OK 0     /* No error */
  ------------------
   92|     67|}
curve25519_do_create_k:
   95|     19|{
   96|     19|    ssh_curve25519_pubkey *peer_pubkey_loc = NULL;
   97|     19|    int rc, ret = SSH_ERROR;
  ------------------
  |  |  317|     19|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   98|     19|    EVP_PKEY_CTX *pctx = NULL;
   99|     19|    EVP_PKEY *pkey = NULL, *pubkey = NULL;
  100|     19|    size_t shared_key_len = CURVE25519_PUBKEY_SIZE;
  ------------------
  |  |   40|     19|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  101|       |
  102|     19|    if (session->server) {
  ------------------
  |  Branch (102:9): [True: 0, False: 19]
  ------------------
  103|      0|        peer_pubkey_loc = &session->next_crypto->curve25519_client_pubkey;
  104|     19|    } else {
  105|     19|        peer_pubkey_loc = &session->next_crypto->curve25519_server_pubkey;
  106|     19|    }
  107|       |
  108|     19|    pkey = session->next_crypto->curve25519_privkey;
  109|     19|    if (pkey == NULL) {
  ------------------
  |  Branch (109:9): [True: 0, False: 19]
  ------------------
  110|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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|     19|    pctx = EVP_PKEY_CTX_new(pkey, NULL);
  117|     19|    if (pctx == NULL) {
  ------------------
  |  Branch (117:9): [True: 0, False: 19]
  ------------------
  118|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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|     19|    rc = EVP_PKEY_derive_init(pctx);
  125|     19|    if (rc != 1) {
  ------------------
  |  Branch (125:9): [True: 0, False: 19]
  ------------------
  126|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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|     19|    pubkey = EVP_PKEY_new_raw_public_key(EVP_PKEY_X25519,
  133|     19|                                         NULL,
  134|     19|                                         *peer_pubkey_loc,
  135|     19|                                         CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   40|     19|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  136|     19|    if (pubkey == NULL) {
  ------------------
  |  Branch (136:9): [True: 0, False: 19]
  ------------------
  137|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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|     19|    rc = EVP_PKEY_derive_set_peer(pctx, pubkey);
  144|     19|    if (rc != 1) {
  ------------------
  |  Branch (144:9): [True: 0, False: 19]
  ------------------
  145|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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|     19|    rc = EVP_PKEY_derive(pctx, k, &shared_key_len);
  152|     19|    if (rc != 1) {
  ------------------
  |  Branch (152:9): [True: 1, False: 18]
  ------------------
  153|      1|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  154|      1|                "Failed to derive X25519 shared secret: %s",
  155|      1|                ERR_error_string(ERR_get_error(), NULL));
  156|      1|        goto out;
  157|      1|    }
  158|     18|    ret = SSH_OK;
  ------------------
  |  |  316|     18|#define SSH_OK 0     /* No error */
  ------------------
  159|       |
  160|     19|out:
  161|     19|    EVP_PKEY_free(pubkey);
  162|     19|    EVP_PKEY_CTX_free(pctx);
  163|     19|    return ret;
  164|     18|}

ssh_client_dhgex_init:
   65|      7|{
   66|      7|    int rc;
   67|       |
   68|      7|    rc = ssh_dh_init_common(session->next_crypto);
   69|      7|    if (rc != SSH_OK){
  ------------------
  |  |  316|      7|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (69:9): [True: 0, False: 7]
  ------------------
   70|      0|        goto error;
   71|      0|    }
   72|       |
   73|      7|    session->next_crypto->dh_pmin = DH_PMIN;
  ------------------
  |  |   41|      7|#define DH_PMIN 2048
  ------------------
   74|      7|    session->next_crypto->dh_pn = DH_PREQ;
  ------------------
  |  |   42|      7|#define DH_PREQ 2048
  ------------------
   75|      7|    session->next_crypto->dh_pmax = DH_PMAX;
  ------------------
  |  |   43|      7|#define DH_PMAX 8192
  ------------------
   76|       |    /* Minimum group size, preferred group size, maximum group size */
   77|      7|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      7|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      7|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      7|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      7|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      7|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      7|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      7|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
   78|      7|                         "bddd",
   79|      7|                         SSH2_MSG_KEX_DH_GEX_REQUEST,
   80|      7|                         session->next_crypto->dh_pmin,
   81|      7|                         session->next_crypto->dh_pn,
   82|      7|                         session->next_crypto->dh_pmax);
   83|      7|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      7|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (83:9): [True: 0, False: 7]
  ------------------
   84|      0|        goto error;
   85|      0|    }
   86|       |
   87|       |    /* register the packet callbacks */
   88|      7|    ssh_packet_set_callbacks(session, &ssh_dhgex_client_callbacks);
   89|      7|    session->dh_handshake_state = DH_STATE_REQUEST_SENT;
   90|      7|    rc = ssh_packet_send(session);
   91|      7|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      7|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (91:9): [True: 0, False: 7]
  ------------------
   92|      0|        goto error;
   93|      0|    }
   94|      7|    return rc;
   95|      0|error:
   96|      0|    ssh_dh_cleanup(session->next_crypto);
   97|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   98|      7|}
ssh_client_dhgex_remove_callbacks:
  243|      1|{
  244|      1|    ssh_packet_remove_callbacks(session, &ssh_dhgex_client_callbacks);
  245|      1|}
dh-gex.c:ssh_packet_client_dhgex_group:
  105|      7|{
  106|      7|    int rc;
  107|      7|    int blen;
  108|      7|    bignum pmin1 = NULL, one = NULL;
  109|      7|    bignum modulus = NULL, generator = NULL;
  110|      7|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
  111|      7|    const_bignum pubkey;
  112|       |#else
  113|       |    bignum pubkey = NULL;
  114|       |#endif /* OPENSSL_VERSION_NUMBER */
  115|      7|    (void) type;
  116|      7|    (void) user;
  117|       |
  118|      7|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_KEX_DH_GEX_GROUP received");
  ------------------
  |  |  283|      7|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  119|       |
  120|      7|    if (session->dh_handshake_state != DH_STATE_REQUEST_SENT) {
  ------------------
  |  Branch (120:9): [True: 0, False: 7]
  ------------------
  121|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  122|      0|                      SSH_FATAL,
  123|      0|                      "Received DH_GEX_GROUP in invalid state");
  124|      0|        goto error;
  125|      0|    }
  126|      7|    one = bignum_new();
  ------------------
  |  |   70|      7|#define bignum_new() BN_new()
  ------------------
  127|      7|    pmin1 = bignum_new();
  ------------------
  |  |   70|      7|#define bignum_new() BN_new()
  ------------------
  128|      7|    if (one == NULL || pmin1 == NULL) {
  ------------------
  |  Branch (128:9): [True: 0, False: 7]
  |  Branch (128:24): [True: 0, False: 7]
  ------------------
  129|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  130|      0|        goto error;
  131|      0|    }
  132|      7|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      7|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      7|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      7|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      7|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      7|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      7|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      7|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  133|      7|                           "BB",
  134|      7|                           &modulus,
  135|      7|                           &generator);
  136|      7|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      7|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (136:9): [True: 0, False: 7]
  ------------------
  137|      0|        ssh_set_error(session, SSH_FATAL, "Invalid DH_GEX_GROUP packet");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  138|      0|        goto error;
  139|      0|    }
  140|       |    /* basic checks */
  141|      7|    if (ssh_fips_mode() &&
  ------------------
  |  |  115|     14|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 7]
  |  |  ------------------
  ------------------
  142|      0|        !ssh_dh_is_known_group(modulus, generator)) {
  ------------------
  |  Branch (142:9): [True: 0, False: 0]
  ------------------
  143|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  144|      0|                      SSH_FATAL,
  145|      0|                      "The received DH group is not FIPS approved");
  146|      0|        goto error;
  147|      0|    }
  148|      7|    rc = bignum_set_word(one, 1);
  ------------------
  |  |   77|      7|#define bignum_set_word(bn,n) BN_set_word(bn,n)
  ------------------
  149|      7|    if (rc != 1) {
  ------------------
  |  Branch (149:9): [True: 0, False: 7]
  ------------------
  150|      0|        goto error;
  151|      0|    }
  152|      7|    blen = bignum_num_bits(modulus);
  ------------------
  |  |   99|      7|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
  153|      7|    if (blen < DH_PMIN || blen > DH_PMAX) {
  ------------------
  |  |   41|     14|#define DH_PMIN 2048
  ------------------
                  if (blen < DH_PMIN || blen > DH_PMAX) {
  ------------------
  |  |   43|      5|#define DH_PMAX 8192
  ------------------
  |  Branch (153:9): [True: 2, False: 5]
  |  Branch (153:27): [True: 0, False: 5]
  ------------------
  154|      2|        ssh_set_error(session,
  ------------------
  |  |  313|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  155|      2|                SSH_FATAL,
  156|      2|                "Invalid dh group parameter p: %d not in [%d:%d]",
  157|      2|                blen,
  158|      2|                DH_PMIN,
  159|      2|                DH_PMAX);
  160|      2|        goto error;
  161|      2|    }
  162|      5|    if (bignum_cmp(modulus, one) <= 0) {
  ------------------
  |  |  102|      5|#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
  ------------------
  |  Branch (162:9): [True: 0, False: 5]
  ------------------
  163|       |        /* p must be positive and preferably bigger than one */
  164|      0|        ssh_set_error(session, SSH_FATAL, "Invalid dh group parameter p");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  165|      0|        goto error;
  166|      0|    }
  167|      5|    if (!bignum_is_bit_set(modulus, 0)) {
  ------------------
  |  |  100|      5|#define bignum_is_bit_set(num,bit) BN_is_bit_set(num, (int)bit)
  ------------------
  |  Branch (167:9): [True: 2, False: 3]
  ------------------
  168|       |        /* p must be a prime and therefore not divisible by 2 */
  169|      2|        ssh_set_error(session, SSH_FATAL, "Invalid dh group parameter p");
  ------------------
  |  |  313|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  170|      2|        goto error;
  171|      2|    }
  172|      3|    bignum_sub(pmin1, modulus, one);
  ------------------
  |  |   96|      3|#define bignum_sub(dest, a, b) BN_sub(dest, a, b)
  ------------------
  173|      3|    if (bignum_cmp(generator, one) <= 0 ||
  ------------------
  |  |  102|      3|#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
  ------------------
  |  Branch (173:9): [True: 1, False: 2]
  ------------------
  174|      2|        bignum_cmp(generator, pmin1) > 0) {
  ------------------
  |  |  102|      2|#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
  ------------------
  |  Branch (174:9): [True: 0, False: 2]
  ------------------
  175|       |        /* generator must be at least 2 and smaller than p-1*/
  176|      1|        ssh_set_error(session, SSH_FATAL, "Invalid dh group parameter g");
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  177|      1|        goto error;
  178|      1|    }
  179|       |
  180|       |    /* all checks passed, set parameters (the BNs are copied in openssl backend) */
  181|      2|    rc = ssh_dh_set_parameters(session->next_crypto->dh_ctx,
  182|      2|                               modulus, generator);
  183|      2|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (183:9): [True: 0, False: 2]
  ------------------
  184|      0|        goto error;
  185|      0|    }
  186|      2|#ifdef HAVE_LIBCRYPTO
  187|      2|    bignum_safe_free(modulus);
  ------------------
  |  |   71|      2|#define bignum_safe_free(num) do { \
  |  |   72|      2|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 2, False: 0]
  |  |  ------------------
  |  |   73|      2|        BN_clear_free((num)); \
  |  |   74|      2|        (num)=NULL; \
  |  |   75|      2|    } \
  |  |   76|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  188|      2|    bignum_safe_free(generator);
  ------------------
  |  |   71|      2|#define bignum_safe_free(num) do { \
  |  |   72|      2|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 2, False: 0]
  |  |  ------------------
  |  |   73|      2|        BN_clear_free((num)); \
  |  |   74|      2|        (num)=NULL; \
  |  |   75|      2|    } \
  |  |   76|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  189|      2|#endif
  190|      2|    modulus = NULL;
  191|      2|    generator = NULL;
  192|       |
  193|       |    /* compute and send DH public parameter */
  194|      2|    rc = ssh_dh_keypair_gen_keys(session->next_crypto->dh_ctx,
  195|      2|                                 DH_CLIENT_KEYPAIR);
  ------------------
  |  |   30|      2|#define DH_CLIENT_KEYPAIR 0
  ------------------
  196|      2|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (196:9): [True: 0, False: 2]
  ------------------
  197|      0|        goto error;
  198|      0|    }
  199|       |
  200|      2|    rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
  201|      2|                                 DH_CLIENT_KEYPAIR, NULL, &pubkey);
  ------------------
  |  |   30|      2|#define DH_CLIENT_KEYPAIR 0
  ------------------
  202|      2|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (202:9): [True: 0, False: 2]
  ------------------
  203|      0|        goto error;
  204|      0|    }
  205|       |
  206|      2|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      2|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      2|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      2|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      2|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      2|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      2|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  207|      2|                         "bB",
  208|      2|                         SSH2_MSG_KEX_DH_GEX_INIT,
  209|      2|                         pubkey);
  210|      2|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (210:9): [True: 0, False: 2]
  ------------------
  211|      0|        goto error;
  212|      0|    }
  213|       |#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
  214|       |    bignum_safe_free(pubkey);
  215|       |#endif /* OPENSSL_VERSION_NUMBER */
  216|       |
  217|      2|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  218|       |
  219|      2|    rc = ssh_packet_send(session);
  220|      2|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (220:9): [True: 0, False: 2]
  ------------------
  221|      0|        goto error;
  222|      0|    }
  223|       |
  224|      2|    bignum_safe_free(one);
  ------------------
  |  |   71|      2|#define bignum_safe_free(num) do { \
  |  |   72|      2|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 2, False: 0]
  |  |  ------------------
  |  |   73|      2|        BN_clear_free((num)); \
  |  |   74|      2|        (num)=NULL; \
  |  |   75|      2|    } \
  |  |   76|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  225|      2|    bignum_safe_free(pmin1);
  ------------------
  |  |   71|      2|#define bignum_safe_free(num) do { \
  |  |   72|      2|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 2, False: 0]
  |  |  ------------------
  |  |   73|      2|        BN_clear_free((num)); \
  |  |   74|      2|        (num)=NULL; \
  |  |   75|      2|    } \
  |  |   76|      2|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 2]
  |  |  ------------------
  ------------------
  226|      2|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      2|#define SSH_PACKET_USED 1
  ------------------
  227|       |
  228|      5|error:
  229|      5|    bignum_safe_free(modulus);
  ------------------
  |  |   71|      5|#define bignum_safe_free(num) do { \
  |  |   72|      5|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 5, False: 0]
  |  |  ------------------
  |  |   73|      5|        BN_clear_free((num)); \
  |  |   74|      5|        (num)=NULL; \
  |  |   75|      5|    } \
  |  |   76|      5|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 5]
  |  |  ------------------
  ------------------
  230|      5|    bignum_safe_free(generator);
  ------------------
  |  |   71|      5|#define bignum_safe_free(num) do { \
  |  |   72|      5|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 5, False: 0]
  |  |  ------------------
  |  |   73|      5|        BN_clear_free((num)); \
  |  |   74|      5|        (num)=NULL; \
  |  |   75|      5|    } \
  |  |   76|      5|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 5]
  |  |  ------------------
  ------------------
  231|      5|    bignum_safe_free(one);
  ------------------
  |  |   71|      5|#define bignum_safe_free(num) do { \
  |  |   72|      5|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 5, False: 0]
  |  |  ------------------
  |  |   73|      5|        BN_clear_free((num)); \
  |  |   74|      5|        (num)=NULL; \
  |  |   75|      5|    } \
  |  |   76|      5|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 5]
  |  |  ------------------
  ------------------
  232|      5|    bignum_safe_free(pmin1);
  ------------------
  |  |   71|      5|#define bignum_safe_free(num) do { \
  |  |   72|      5|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 5, False: 0]
  |  |  ------------------
  |  |   73|      5|        BN_clear_free((num)); \
  |  |   74|      5|        (num)=NULL; \
  |  |   75|      5|    } \
  |  |   76|      5|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 5]
  |  |  ------------------
  ------------------
  233|       |#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
  234|       |    bignum_safe_free(pubkey);
  235|       |#endif /* OPENSSL_VERSION_NUMBER */
  236|      5|    ssh_dh_cleanup(session->next_crypto);
  237|      5|    session->session_state = SSH_SESSION_STATE_ERROR;
  238|       |
  239|      5|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      5|#define SSH_PACKET_USED 1
  ------------------
  240|      2|}
dh-gex.c:ssh_packet_client_dhgex_reply:
  248|      1|{
  249|      1|    struct ssh_crypto_struct *crypto=session->next_crypto;
  250|      1|    int rc;
  251|      1|    ssh_string pubkey_blob = NULL;
  252|      1|    bignum server_pubkey = NULL;
  253|      1|    (void)type;
  254|      1|    (void)user;
  255|      1|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_KEX_DH_GEX_REPLY received");
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  256|       |
  257|      1|    ssh_client_dhgex_remove_callbacks(session);
  258|      1|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      1|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      1|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      1|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      1|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      1|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      1|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      1|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  259|      1|                           "SBS",
  260|      1|                           &pubkey_blob, &server_pubkey,
  261|      1|                           &crypto->dh_server_signature);
  262|      1|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (262:9): [True: 1, False: 0]
  ------------------
  263|      1|        ssh_set_error(session, SSH_FATAL, "Invalid DH_GEX_REPLY packet");
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  264|      1|        goto error;
  265|      1|    }
  266|      0|    rc = ssh_dh_keypair_set_keys(crypto->dh_ctx, DH_SERVER_KEYPAIR,
  ------------------
  |  |   31|      0|#define DH_SERVER_KEYPAIR 1
  ------------------
  267|      0|                                 NULL, server_pubkey);
  268|      0|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (268:9): [True: 0, False: 0]
  ------------------
  269|      0|        bignum_safe_free(server_pubkey);
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
  270|      0|        goto error;
  271|      0|    }
  272|       |    /* The ownership was passed to the crypto structure */
  273|      0|    server_pubkey = NULL;
  274|       |
  275|      0|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  276|      0|    SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  277|      0|    if (rc != 0) {
  ------------------
  |  Branch (277:9): [True: 0, False: 0]
  ------------------
  278|      0|        goto error;
  279|      0|    }
  280|       |
  281|      0|    rc = ssh_dh_compute_shared_secret(session->next_crypto->dh_ctx,
  282|      0|                                      DH_CLIENT_KEYPAIR, DH_SERVER_KEYPAIR,
  ------------------
  |  |   30|      0|#define DH_CLIENT_KEYPAIR 0
  ------------------
                                                    DH_CLIENT_KEYPAIR, DH_SERVER_KEYPAIR,
  ------------------
  |  |   31|      0|#define DH_SERVER_KEYPAIR 1
  ------------------
  283|      0|                                      &session->next_crypto->shared_secret);
  284|      0|    ssh_dh_debug_crypto(session->next_crypto);
  285|      0|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (285:9): [True: 0, False: 0]
  ------------------
  286|      0|        ssh_set_error(session, SSH_FATAL, "Could not generate shared secret");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  287|      0|        goto error;
  288|      0|    }
  289|       |
  290|       |    /* Send the MSG_NEWKEYS */
  291|      0|    rc = ssh_packet_send_newkeys(session);
  292|      0|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (292:9): [True: 0, False: 0]
  ------------------
  293|      0|        goto error;
  294|      0|    }
  295|      0|    session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  296|       |
  297|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  298|      1|error:
  299|      1|    SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  924|      1|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 1]
  |  |  |  Branch (924:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
  300|      1|    ssh_dh_cleanup(session->next_crypto);
  301|      1|    session->session_state = SSH_SESSION_STATE_ERROR;
  302|       |
  303|      1|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      1|#define SSH_PACKET_USED 1
  ------------------
  304|      0|}

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|    140|{
  296|    140|    return ssh_pki_import_pubkey_blob(pubkey_blob,
  297|    140|                                      &session->next_crypto->server_pubkey);
  298|       |
  299|    140|}
ssh_client_dh_init:
  317|     22|int ssh_client_dh_init(ssh_session session){
  318|     22|  struct ssh_crypto_struct *crypto = session->next_crypto;
  319|     22|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
  320|     22|  const_bignum pubkey;
  321|       |#else
  322|       |  bignum pubkey = NULL;
  323|       |#endif /* OPENSSL_VERSION_NUMBER */
  324|     22|  int rc;
  325|       |
  326|     22|  rc = ssh_dh_init_common(crypto);
  327|     22|  if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     22|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (327:7): [True: 0, False: 22]
  ------------------
  328|      0|    goto error;
  329|      0|  }
  330|       |
  331|     22|  rc = ssh_dh_keypair_gen_keys(crypto->dh_ctx, DH_CLIENT_KEYPAIR);
  ------------------
  |  |   30|     22|#define DH_CLIENT_KEYPAIR 0
  ------------------
  332|     22|  if (rc == SSH_ERROR){
  ------------------
  |  |  317|     22|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (332:7): [True: 0, False: 22]
  ------------------
  333|      0|      goto error;
  334|      0|  }
  335|     22|  rc = ssh_dh_keypair_get_keys(crypto->dh_ctx, DH_CLIENT_KEYPAIR,
  ------------------
  |  |   30|     22|#define DH_CLIENT_KEYPAIR 0
  ------------------
  336|     22|                               NULL, &pubkey);
  337|     22|  if (rc != SSH_OK) {
  ------------------
  |  |  316|     22|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (337:7): [True: 0, False: 22]
  ------------------
  338|      0|    goto error;
  339|      0|  }
  340|     22|  rc = ssh_buffer_pack(session->out_buffer, "bB", SSH2_MSG_KEXDH_INIT, pubkey);
  ------------------
  |  |   50|     22|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     22|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     22|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     22|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     22|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     22|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     22|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  341|     22|  if (rc != SSH_OK) {
  ------------------
  |  |  316|     22|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (341:7): [True: 0, False: 22]
  ------------------
  342|      0|    goto error;
  343|      0|  }
  344|       |#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
  345|       |  bignum_safe_free(pubkey);
  346|       |#endif
  347|       |
  348|       |  /* register the packet callbacks */
  349|     22|  ssh_packet_set_callbacks(session, &ssh_dh_client_callbacks);
  350|     22|  session->dh_handshake_state = DH_STATE_INIT_SENT;
  351|       |
  352|     22|  rc = ssh_packet_send(session);
  353|     22|  return rc;
  354|      0|error:
  355|       |#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
  356|       |  bignum_safe_free(pubkey);
  357|       |#endif
  358|      0|  ssh_dh_cleanup(crypto);
  359|      0|  return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  360|     22|}
ssh_client_dh_remove_callbacks:
  363|     17|{
  364|     17|    ssh_packet_remove_callbacks(session, &ssh_dh_client_callbacks);
  365|     17|}
ssh_dh_get_next_server_publickey:
  676|     48|{
  677|     48|    return session->next_crypto->server_pubkey;
  678|     48|}
ssh_dh_get_next_server_publickey_blob:
  683|     33|{
  684|     33|    const ssh_key pubkey = ssh_dh_get_next_server_publickey(session);
  685|       |
  686|     33|    return ssh_pki_export_pubkey_blob(pubkey, pubkey_blob);
  687|     33|}
dh.c:ssh_packet_client_dh_reply:
  367|     17|SSH_PACKET_CALLBACK(ssh_packet_client_dh_reply){
  368|     17|  struct ssh_crypto_struct *crypto=session->next_crypto;
  369|     17|  ssh_string pubkey_blob = NULL;
  370|     17|  bignum server_pubkey;
  371|     17|  int rc;
  372|       |
  373|     17|  (void)type;
  374|     17|  (void)user;
  375|       |
  376|     17|  ssh_client_dh_remove_callbacks(session);
  377|       |
  378|     17|  rc = ssh_buffer_unpack(packet, "SBS", &pubkey_blob, &server_pubkey,
  ------------------
  |  |   60|     17|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     17|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     17|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     17|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     17|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     17|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     17|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  379|     17|          &crypto->dh_server_signature);
  380|     17|  if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     17|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (380:7): [True: 1, False: 16]
  ------------------
  381|      1|      goto error;
  382|      1|  }
  383|     16|  rc = ssh_dh_keypair_set_keys(crypto->dh_ctx, DH_SERVER_KEYPAIR,
  ------------------
  |  |   31|     16|#define DH_SERVER_KEYPAIR 1
  ------------------
  384|     16|                               NULL, server_pubkey);
  385|     16|  if (rc != SSH_OK) {
  ------------------
  |  |  316|     16|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (385:7): [True: 0, False: 16]
  ------------------
  386|      0|      SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  387|      0|      bignum_safe_free(server_pubkey);
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
  388|      0|      goto error;
  389|      0|  }
  390|     16|  rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  391|     16|  SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  924|     16|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 16, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 16]
  |  |  ------------------
  ------------------
  392|     16|  if (rc != 0) {
  ------------------
  |  Branch (392:7): [True: 1, False: 15]
  ------------------
  393|      1|      goto error;
  394|      1|  }
  395|       |
  396|     15|  rc = ssh_dh_compute_shared_secret(session->next_crypto->dh_ctx,
  397|     15|                                    DH_CLIENT_KEYPAIR, DH_SERVER_KEYPAIR,
  ------------------
  |  |   30|     15|#define DH_CLIENT_KEYPAIR 0
  ------------------
                                                  DH_CLIENT_KEYPAIR, DH_SERVER_KEYPAIR,
  ------------------
  |  |   31|     15|#define DH_SERVER_KEYPAIR 1
  ------------------
  398|     15|                                    &session->next_crypto->shared_secret);
  399|     15|  ssh_dh_debug_crypto(session->next_crypto);
  400|     15|  if (rc == SSH_ERROR){
  ------------------
  |  |  317|     15|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (400:7): [True: 0, False: 15]
  ------------------
  401|      0|    ssh_set_error(session, SSH_FATAL, "Could not generate shared secret");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  402|      0|    goto error;
  403|      0|  }
  404|       |
  405|       |  /* Send the MSG_NEWKEYS */
  406|     15|  rc = ssh_packet_send_newkeys(session);
  407|     15|  if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     15|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (407:7): [True: 0, False: 15]
  ------------------
  408|      0|    goto error;
  409|      0|  }
  410|     15|  session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  411|     15|  return SSH_PACKET_USED;
  ------------------
  |  |  638|     15|#define SSH_PACKET_USED 1
  ------------------
  412|      2|error:
  413|      2|  ssh_dh_cleanup(session->next_crypto);
  414|      2|  session->session_state=SSH_SESSION_STATE_ERROR;
  415|      2|  return SSH_PACKET_USED;
  ------------------
  |  |  638|      2|#define SSH_PACKET_USED 1
  ------------------
  416|     15|}

ssh_dh_debug_crypto:
   56|     15|{
   57|       |#ifdef DEBUG_CRYPTO
   58|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
   59|       |    const_bignum x = NULL, y = NULL, e = NULL, f = NULL;
   60|       |#else
   61|       |    bignum x = NULL, y = NULL, e = NULL, f = NULL;
   62|       |#endif /* OPENSSL_VERSION_NUMBER */
   63|       |
   64|       |    ssh_dh_keypair_get_keys(c->dh_ctx, DH_CLIENT_KEYPAIR, &x, &e);
   65|       |    ssh_dh_keypair_get_keys(c->dh_ctx, DH_SERVER_KEYPAIR, &y, &f);
   66|       |    ssh_print_bignum("x", x);
   67|       |    ssh_print_bignum("y", y);
   68|       |    ssh_print_bignum("e", e);
   69|       |    ssh_print_bignum("f", f);
   70|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
   71|       |    bignum_safe_free(x);
   72|       |    bignum_safe_free(y);
   73|       |    bignum_safe_free(e);
   74|       |    bignum_safe_free(f);
   75|       |#endif /* OPENSSL_VERSION_NUMBER */
   76|       |
   77|       |    ssh_log_hexdump("Session server cookie", c->server_kex.cookie, 16);
   78|       |    ssh_log_hexdump("Session client cookie", c->client_kex.cookie, 16);
   79|       |    ssh_print_bignum("k", c->shared_secret);
   80|       |
   81|       |#else
   82|     15|    (void)c; /* UNUSED_PARAM */
   83|     15|#endif /* DEBUG_CRYPTO */
   84|     15|}
ssh_dh_keypair_get_keys:
   89|     69|{
   90|     69|    if (((peer != DH_CLIENT_KEYPAIR) && (peer != DH_SERVER_KEYPAIR)) ||
  ------------------
  |  |   30|     69|#define DH_CLIENT_KEYPAIR 0
  ------------------
                  if (((peer != DH_CLIENT_KEYPAIR) && (peer != DH_SERVER_KEYPAIR)) ||
  ------------------
  |  |   31|     30|#define DH_SERVER_KEYPAIR 1
  ------------------
  |  Branch (90:10): [True: 30, False: 39]
  |  Branch (90:41): [True: 0, False: 30]
  ------------------
   91|     69|        ((priv == NULL) && (pub == NULL)) || (ctx == NULL) ||
  ------------------
  |  Branch (91:10): [True: 69, False: 0]
  |  Branch (91:28): [True: 0, False: 69]
  |  Branch (91:46): [True: 0, False: 69]
  ------------------
   92|     69|        (ctx->keypair[peer] == NULL)) {
  ------------------
  |  Branch (92:9): [True: 0, False: 69]
  ------------------
   93|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   94|      0|    }
   95|       |
   96|     69|    DH_get0_key(ctx->keypair[peer], pub, priv);
   97|       |
   98|     69|    if (priv && (*priv == NULL || bignum_num_bits(*priv) == 0)) {
  ------------------
  |  |   99|      0|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
  |  Branch (98:9): [True: 0, False: 69]
  |  Branch (98:18): [True: 0, False: 0]
  |  Branch (98:35): [True: 0, False: 0]
  ------------------
   99|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  100|      0|    }
  101|     69|    if (pub && (*pub == NULL || bignum_num_bits(*pub) == 0)) {
  ------------------
  |  |   99|     69|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
  |  Branch (101:9): [True: 69, False: 0]
  |  Branch (101:17): [True: 0, False: 69]
  |  Branch (101:33): [True: 0, False: 69]
  ------------------
  102|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  103|      0|    }
  104|       |
  105|     69|    return SSH_OK;
  ------------------
  |  |  316|     69|#define SSH_OK 0     /* No error */
  ------------------
  106|     69|}
ssh_dh_keypair_set_keys:
  158|     16|{
  159|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  160|       |    int rc;
  161|       |    OSSL_PARAM *params = NULL, *out_params = NULL, *merged_params = NULL;
  162|       |    OSSL_PARAM_BLD *param_bld = NULL;
  163|       |    EVP_PKEY_CTX *evp_ctx = NULL;
  164|       |#endif /* OPENSSL_VERSION_NUMBER */
  165|       |
  166|     16|    if (((peer != DH_CLIENT_KEYPAIR) && (peer != DH_SERVER_KEYPAIR)) ||
  ------------------
  |  |   30|     16|#define DH_CLIENT_KEYPAIR 0
  ------------------
                  if (((peer != DH_CLIENT_KEYPAIR) && (peer != DH_SERVER_KEYPAIR)) ||
  ------------------
  |  |   31|     16|#define DH_SERVER_KEYPAIR 1
  ------------------
  |  Branch (166:10): [True: 16, False: 0]
  |  Branch (166:41): [True: 0, False: 16]
  ------------------
  167|     16|        ((priv == NULL) && (pub == NULL)) || (ctx == NULL) ||
  ------------------
  |  Branch (167:10): [True: 16, False: 0]
  |  Branch (167:28): [True: 0, False: 16]
  |  Branch (167:46): [True: 0, False: 16]
  ------------------
  168|     16|        (ctx->keypair[peer] == NULL)) {
  ------------------
  |  Branch (168:9): [True: 0, False: 16]
  ------------------
  169|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  170|      0|    }
  171|       |
  172|     16|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  173|     16|    (void)DH_set0_key(ctx->keypair[peer], pub, priv);
  174|       |
  175|     16|    return SSH_OK;
  ------------------
  |  |  316|     16|#define SSH_OK 0     /* No error */
  ------------------
  176|       |#else
  177|       |    rc = EVP_PKEY_todata(ctx->keypair[peer], EVP_PKEY_KEYPAIR, &out_params);
  178|       |    if (rc != 1) {
  179|       |        return SSH_ERROR;
  180|       |    }
  181|       |
  182|       |    param_bld = OSSL_PARAM_BLD_new();
  183|       |    if (param_bld == NULL) {
  184|       |        rc = SSH_ERROR;
  185|       |        goto out;
  186|       |    }
  187|       |
  188|       |    evp_ctx = EVP_PKEY_CTX_new_from_pkey(NULL, ctx->keypair[peer], NULL);
  189|       |    if (evp_ctx == NULL) {
  190|       |        rc = SSH_ERROR;
  191|       |        goto out;
  192|       |    }
  193|       |
  194|       |    rc = EVP_PKEY_fromdata_init(evp_ctx);
  195|       |    if (rc != 1) {
  196|       |        rc = SSH_ERROR;
  197|       |        goto out;
  198|       |    }
  199|       |
  200|       |    if (priv) {
  201|       |        rc = OSSL_PARAM_BLD_push_BN(param_bld, OSSL_PKEY_PARAM_PRIV_KEY, priv);
  202|       |        if (rc != 1) {
  203|       |            rc = SSH_ERROR;
  204|       |            goto out;
  205|       |        }
  206|       |    }
  207|       |    if (pub) {
  208|       |        rc = OSSL_PARAM_BLD_push_BN(param_bld, OSSL_PKEY_PARAM_PUB_KEY, pub);
  209|       |        if (rc != 1) {
  210|       |            rc = SSH_ERROR;
  211|       |            goto out;
  212|       |        }
  213|       |    }
  214|       |
  215|       |    params = OSSL_PARAM_BLD_to_param(param_bld);
  216|       |    if (params == NULL) {
  217|       |        rc = SSH_ERROR;
  218|       |        goto out;
  219|       |    }
  220|       |    OSSL_PARAM_BLD_free(param_bld);
  221|       |
  222|       |    merged_params = OSSL_PARAM_merge(out_params, params);
  223|       |    if (merged_params == NULL) {
  224|       |        rc = SSH_ERROR;
  225|       |        goto out;
  226|       |    }
  227|       |
  228|       |    rc = EVP_PKEY_fromdata(evp_ctx,
  229|       |                           &(ctx->keypair[peer]),
  230|       |                           EVP_PKEY_PUBLIC_KEY,
  231|       |                           merged_params);
  232|       |    if (rc != 1) {
  233|       |        rc = SSH_ERROR;
  234|       |        goto out;
  235|       |    }
  236|       |
  237|       |    rc = SSH_OK;
  238|       |out:
  239|       |    bignum_safe_free(priv);
  240|       |    bignum_safe_free(pub);
  241|       |    EVP_PKEY_CTX_free(evp_ctx);
  242|       |    OSSL_PARAM_free(out_params);
  243|       |    OSSL_PARAM_free(params);
  244|       |    OSSL_PARAM_free(merged_params);
  245|       |
  246|       |    return rc;
  247|       |#endif /* OPENSSL_VERSION_NUMBER */
  248|     16|}
ssh_dh_set_parameters:
  286|     24|{
  287|     24|    size_t i;
  288|     24|    int rc;
  289|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  290|       |    OSSL_PARAM *params = NULL;
  291|       |    OSSL_PARAM_BLD *param_bld = NULL;
  292|       |    EVP_PKEY_CTX *evp_ctx = NULL;
  293|       |#endif /* OPENSSL_VERSION_NUMBER */
  294|       |
  295|     24|    if ((ctx == NULL) || (modulus == NULL) || (generator == NULL)) {
  ------------------
  |  Branch (295:9): [True: 0, False: 24]
  |  Branch (295:26): [True: 0, False: 24]
  |  Branch (295:47): [True: 0, False: 24]
  ------------------
  296|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  297|      0|    }
  298|       |
  299|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  300|       |    evp_ctx = EVP_PKEY_CTX_new_from_name(NULL, "DHX", NULL);
  301|       |#endif
  302|       |
  303|     72|    for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (303:17): [True: 48, False: 24]
  ------------------
  304|     48|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  305|     48|        bignum p = NULL;
  306|     48|        bignum g = NULL;
  307|       |
  308|       |        /* when setting modulus or generator,
  309|       |         * make sure to invalidate existing keys */
  310|     48|        DH_free(ctx->keypair[i]);
  311|     48|        ctx->keypair[i] = DH_new();
  312|     48|        if (ctx->keypair[i] == NULL) {
  ------------------
  |  Branch (312:13): [True: 0, False: 48]
  ------------------
  313|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  314|      0|            goto done;
  315|      0|        }
  316|       |
  317|     48|        p = BN_dup(modulus);
  318|     48|        g = BN_dup(generator);
  319|     48|        rc = DH_set0_pqg(ctx->keypair[i], p, NULL, g);
  320|     48|        if (rc != 1) {
  ------------------
  |  Branch (320:13): [True: 0, False: 48]
  ------------------
  321|      0|            BN_free(p);
  322|      0|            BN_free(g);
  323|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  324|      0|            goto done;
  325|      0|        }
  326|       |#else
  327|       |        param_bld = OSSL_PARAM_BLD_new();
  328|       |
  329|       |        if (param_bld == NULL) {
  330|       |            rc = SSH_ERROR;
  331|       |            goto done;
  332|       |        }
  333|       |
  334|       |        rc = OSSL_PARAM_BLD_push_BN(param_bld, OSSL_PKEY_PARAM_FFC_P, modulus);
  335|       |        if (rc != 1) {
  336|       |            rc = SSH_ERROR;
  337|       |            goto done;
  338|       |        }
  339|       |        rc = OSSL_PARAM_BLD_push_BN(param_bld, OSSL_PKEY_PARAM_FFC_G, generator);
  340|       |        if (rc != 1) {
  341|       |            rc = SSH_ERROR;
  342|       |            goto done;
  343|       |        }
  344|       |        params = OSSL_PARAM_BLD_to_param(param_bld);
  345|       |        if (params == NULL) {
  346|       |            OSSL_PARAM_BLD_free(param_bld);
  347|       |            rc = SSH_ERROR;
  348|       |            goto done;
  349|       |        }
  350|       |        OSSL_PARAM_BLD_free(param_bld);
  351|       |
  352|       |        rc = EVP_PKEY_fromdata_init(evp_ctx);
  353|       |        if (rc != 1) {
  354|       |            OSSL_PARAM_free(params);
  355|       |            rc = SSH_ERROR;
  356|       |            goto done;
  357|       |        }
  358|       |
  359|       |        /* make sure to invalidate existing keys */
  360|       |        EVP_PKEY_free(ctx->keypair[i]);
  361|       |        ctx->keypair[i] = NULL;
  362|       |
  363|       |        rc = EVP_PKEY_fromdata(evp_ctx,
  364|       |                               &(ctx->keypair[i]),
  365|       |                               EVP_PKEY_KEY_PARAMETERS,
  366|       |                               params);
  367|       |        if (rc != 1) {
  368|       |            OSSL_PARAM_free(params);
  369|       |            rc = SSH_ERROR;
  370|       |            goto done;
  371|       |        }
  372|       |
  373|       |        OSSL_PARAM_free(params);
  374|       |#endif /* OPENSSL_VERSION_NUMBER */
  375|     48|    }
  376|       |
  377|     24|    rc = SSH_OK;
  ------------------
  |  |  316|     24|#define SSH_OK 0     /* No error */
  ------------------
  378|     24|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  379|     24|done:
  380|     24|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     24|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (380:9): [True: 0, False: 24]
  ------------------
  381|      0|        DH_free(ctx->keypair[0]);
  382|      0|        DH_free(ctx->keypair[1]);
  383|      0|    }
  384|       |#else
  385|       |done:
  386|       |    EVP_PKEY_CTX_free(evp_ctx);
  387|       |
  388|       |    if (rc != SSH_OK) {
  389|       |        EVP_PKEY_free(ctx->keypair[0]);
  390|       |        EVP_PKEY_free(ctx->keypair[1]);
  391|       |    }
  392|       |#endif /* OPENSSL_VERSION_NUMBER */
  393|     24|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     24|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (393:9): [True: 0, False: 24]
  ------------------
  394|      0|        ctx->keypair[0] = NULL;
  395|      0|        ctx->keypair[1] = NULL;
  396|      0|    }
  397|       |
  398|     24|    return rc;
  399|     24|}
ssh_dh_init_common:
  406|     29|{
  407|     29|    struct dh_ctx *ctx = NULL;
  408|     29|    int rc;
  409|       |
  410|       |    /* Cleanup any previously allocated dh_ctx */
  411|     29|    if (crypto->dh_ctx != NULL) {
  ------------------
  |  Branch (411:9): [True: 0, False: 29]
  ------------------
  412|      0|        ssh_dh_cleanup(crypto);
  413|      0|    }
  414|       |
  415|     29|    ctx = calloc(1, sizeof(*ctx));
  416|     29|    if (ctx == NULL) {
  ------------------
  |  Branch (416:9): [True: 0, False: 29]
  ------------------
  417|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  418|      0|    }
  419|     29|    crypto->dh_ctx = ctx;
  420|       |
  421|     29|    switch (crypto->kex_type) {
  422|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (422:5): [True: 0, False: 29]
  ------------------
  423|      0|        rc = ssh_dh_set_parameters(ctx, ssh_dh_group1, ssh_dh_generator);
  424|      0|        break;
  425|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (425:5): [True: 0, False: 29]
  ------------------
  426|      4|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (426:5): [True: 4, False: 25]
  ------------------
  427|      4|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (427:5): [True: 0, False: 29]
  ------------------
  428|      4|        rc = ssh_dh_set_parameters(ctx, ssh_dh_group14, ssh_dh_generator);
  429|      4|        break;
  430|      2|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (430:5): [True: 2, False: 27]
  ------------------
  431|      2|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (431:5): [True: 0, False: 29]
  ------------------
  432|      2|        rc = ssh_dh_set_parameters(ctx, ssh_dh_group16, ssh_dh_generator);
  433|      2|        break;
  434|     16|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (434:5): [True: 16, False: 13]
  ------------------
  435|     16|        rc = ssh_dh_set_parameters(ctx, ssh_dh_group18, ssh_dh_generator);
  436|     16|        break;
  437|      7|    default:
  ------------------
  |  Branch (437:5): [True: 7, False: 22]
  ------------------
  438|      7|        rc = SSH_OK;
  ------------------
  |  |  316|      7|#define SSH_OK 0     /* No error */
  ------------------
  439|      7|        break;
  440|     29|    }
  441|       |
  442|     29|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     29|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (442:9): [True: 0, False: 29]
  ------------------
  443|      0|        ssh_dh_cleanup(crypto);
  444|      0|    }
  445|     29|    return rc;
  446|     29|}
ssh_dh_cleanup:
  449|  1.09k|{
  450|  1.09k|    if (crypto->dh_ctx != NULL) {
  ------------------
  |  Branch (450:9): [True: 29, False: 1.06k]
  ------------------
  451|     29|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  452|     29|        DH_free(crypto->dh_ctx->keypair[0]);
  453|     29|        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|     29|        free(crypto->dh_ctx);
  459|       |        crypto->dh_ctx = NULL;
  460|     29|    }
  461|  1.09k|}
ssh_dh_keypair_gen_keys:
  474|     24|{
  475|     24|    int rc;
  476|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  477|       |    EVP_PKEY_CTX *evp_ctx = NULL;
  478|       |#endif
  479|       |
  480|     24|    if ((dh_ctx == NULL) || (dh_ctx->keypair[peer] == NULL)) {
  ------------------
  |  Branch (480:9): [True: 0, False: 24]
  |  Branch (480:29): [True: 0, False: 24]
  ------------------
  481|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  482|      0|    }
  483|       |
  484|     24|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  485|     24|    rc = DH_generate_key(dh_ctx->keypair[peer]);
  486|     24|    if (rc != 1) {
  ------------------
  |  Branch (486:9): [True: 0, False: 24]
  ------------------
  487|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  488|      0|    }
  489|       |#else
  490|       |    evp_ctx = EVP_PKEY_CTX_new_from_pkey(NULL, dh_ctx->keypair[peer], NULL);
  491|       |    if (evp_ctx == NULL) {
  492|       |        return SSH_ERROR;
  493|       |    }
  494|       |
  495|       |    rc = EVP_PKEY_keygen_init(evp_ctx);
  496|       |    if (rc != 1) {
  497|       |        EVP_PKEY_CTX_free(evp_ctx);
  498|       |        return SSH_ERROR;
  499|       |    }
  500|       |
  501|       |    rc = EVP_PKEY_generate(evp_ctx, &(dh_ctx->keypair[peer]));
  502|       |    if (rc != 1) {
  503|       |        EVP_PKEY_CTX_free(evp_ctx);
  504|       |        SSH_LOG(SSH_LOG_TRACE,
  505|       |                "Failed to generate DH: %s",
  506|       |                ERR_error_string(ERR_get_error(), NULL));
  507|       |        return SSH_ERROR;
  508|       |    }
  509|       |
  510|       |    EVP_PKEY_CTX_free(evp_ctx);
  511|       |#endif /* OPENSSL_VERSION_NUMBER */
  512|       |
  513|     24|    return SSH_OK;
  ------------------
  |  |  316|     24|#define SSH_OK 0     /* No error */
  ------------------
  514|     24|}
ssh_dh_compute_shared_secret:
  529|     15|{
  530|     15|    unsigned char *kstring = NULL;
  531|     15|    int rc;
  532|     15|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  533|     15|    const_bignum pub_key = NULL;
  534|     15|    int klen;
  535|       |#else
  536|       |    size_t klen;
  537|       |    EVP_PKEY_CTX *evp_ctx = NULL;
  538|       |#endif /* OPENSSL_VERSION_NUMBER */
  539|       |
  540|     15|    if ((dh_ctx == NULL) ||
  ------------------
  |  Branch (540:9): [True: 0, False: 15]
  ------------------
  541|     15|        (dh_ctx->keypair[local] == NULL) ||
  ------------------
  |  Branch (541:9): [True: 0, False: 15]
  ------------------
  542|     15|        (dh_ctx->keypair[remote] == NULL)) {
  ------------------
  |  Branch (542:9): [True: 0, False: 15]
  ------------------
  543|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  544|      0|    }
  545|       |
  546|     15|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  547|     15|    kstring = malloc(DH_size(dh_ctx->keypair[local]));
  548|     15|    if (kstring == NULL) {
  ------------------
  |  Branch (548:9): [True: 0, False: 15]
  ------------------
  549|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  550|      0|        goto done;
  551|      0|    }
  552|       |
  553|     15|    rc = ssh_dh_keypair_get_keys(dh_ctx, remote, NULL, &pub_key);
  554|     15|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     15|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (554:9): [True: 0, False: 15]
  ------------------
  555|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  556|      0|        goto done;
  557|      0|    }
  558|       |
  559|     15|    klen = DH_compute_key(kstring, pub_key, dh_ctx->keypair[local]);
  560|     15|    if (klen == -1) {
  ------------------
  |  Branch (560:9): [True: 0, False: 15]
  ------------------
  561|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  562|      0|        goto done;
  563|      0|    }
  564|       |#else
  565|       |    evp_ctx = EVP_PKEY_CTX_new_from_pkey(NULL, dh_ctx->keypair[local], NULL);
  566|       |
  567|       |    rc = EVP_PKEY_derive_init(evp_ctx);
  568|       |    if (rc != 1) {
  569|       |        rc = SSH_ERROR;
  570|       |        goto done;
  571|       |    }
  572|       |
  573|       |    rc = EVP_PKEY_derive_set_peer(evp_ctx, dh_ctx->keypair[remote]);
  574|       |    if (rc != 1) {
  575|       |        SSH_LOG(SSH_LOG_TRACE,
  576|       |                "Failed to set peer key: %s",
  577|       |                ERR_error_string(ERR_get_error(), NULL));
  578|       |        rc = SSH_ERROR;
  579|       |        goto done;
  580|       |    }
  581|       |
  582|       |    /* getting the size of the secret */
  583|       |    rc = EVP_PKEY_derive(evp_ctx, kstring, &klen);
  584|       |    if (rc != 1) {
  585|       |        rc = SSH_ERROR;
  586|       |        goto done;
  587|       |    }
  588|       |
  589|       |    kstring = malloc(klen);
  590|       |    if (kstring == NULL) {
  591|       |        rc = SSH_ERROR;
  592|       |        goto done;
  593|       |    }
  594|       |
  595|       |    rc = EVP_PKEY_derive(evp_ctx, kstring, &klen);
  596|       |    if (rc != 1) {
  597|       |        rc = SSH_ERROR;
  598|       |        goto done;
  599|       |    }
  600|       |#endif /* OPENSSL_VERSION_NUMBER */
  601|       |
  602|     15|    *dest = BN_bin2bn(kstring, (int)klen, NULL);
  603|     15|    if (*dest == NULL) {
  ------------------
  |  Branch (603:9): [True: 0, False: 15]
  ------------------
  604|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  605|      0|        goto done;
  606|      0|    }
  607|       |
  608|     15|    rc = SSH_OK;
  ------------------
  |  |  316|     15|#define SSH_OK 0     /* No error */
  ------------------
  609|     15|done:
  610|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  611|       |    EVP_PKEY_CTX_free(evp_ctx);
  612|       |#endif
  613|     15|    free(kstring);
  614|     15|    return rc;
  615|     15|}

ssh_client_ecdh_remove_callbacks:
   47|      4|{
   48|      4|    ssh_packet_remove_callbacks(session, &ssh_ecdh_client_callbacks);
   49|      4|}
ecdh.c:ssh_packet_client_ecdh_reply:
   55|      4|SSH_PACKET_CALLBACK(ssh_packet_client_ecdh_reply){
   56|      4|  ssh_string q_s_string = NULL;
   57|      4|  ssh_string pubkey_blob = NULL;
   58|      4|  ssh_string signature = NULL;
   59|      4|  int rc;
   60|      4|  (void)type;
   61|      4|  (void)user;
   62|       |
   63|      4|  ssh_client_ecdh_remove_callbacks(session);
   64|      4|  pubkey_blob = ssh_buffer_get_ssh_string(packet);
   65|      4|  if (pubkey_blob == NULL) {
  ------------------
  |  Branch (65:7): [True: 0, False: 4]
  ------------------
   66|      0|    ssh_set_error(session,SSH_FATAL, "No public key in packet");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   67|      0|    goto error;
   68|      0|  }
   69|       |
   70|      4|  rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
   71|      4|  SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  924|      4|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 4, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 4]
  |  |  ------------------
  ------------------
   72|      4|  if (rc != 0) {
  ------------------
  |  Branch (72:7): [True: 2, False: 2]
  ------------------
   73|      2|      goto error;
   74|      2|  }
   75|       |
   76|      2|  q_s_string = ssh_buffer_get_ssh_string(packet);
   77|      2|  if (q_s_string == NULL) {
  ------------------
  |  Branch (77:7): [True: 0, False: 2]
  ------------------
   78|      0|    ssh_set_error(session,SSH_FATAL, "No Q_S ECC point in packet");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   79|      0|    goto error;
   80|      0|  }
   81|      2|  session->next_crypto->ecdh_server_pubkey = q_s_string;
   82|      2|  signature = ssh_buffer_get_ssh_string(packet);
   83|      2|  if (signature == NULL) {
  ------------------
  |  Branch (83:7): [True: 1, False: 1]
  ------------------
   84|      1|    ssh_set_error(session, SSH_FATAL, "No signature in packet");
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   85|      1|    goto error;
   86|      1|  }
   87|      1|  session->next_crypto->dh_server_signature = signature;
   88|      1|  signature=NULL; /* ownership changed */
   89|       |  /* TODO: verify signature now instead of waiting for NEWKEYS */
   90|      1|  if (ecdh_build_k(session) < 0) {
  ------------------
  |  Branch (90:7): [True: 1, False: 0]
  ------------------
   91|      1|    ssh_set_error(session, SSH_FATAL, "Cannot build k number");
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   92|      1|    goto error;
   93|      1|  }
   94|       |
   95|       |  /* Send the MSG_NEWKEYS */
   96|      0|  rc = ssh_packet_send_newkeys(session);
   97|      0|  if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (97:7): [True: 0, False: 0]
  ------------------
   98|      0|    goto error;
   99|      0|  }
  100|      0|  session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  101|       |
  102|      0|  return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  103|       |
  104|      4|error:
  105|      4|  session->session_state=SSH_SESSION_STATE_ERROR;
  106|      4|  return SSH_PACKET_USED;
  ------------------
  |  |  638|      4|#define SSH_PACKET_USED 1
  ------------------
  107|      0|}

ssh_ecdh_init:
  235|    110|{
  236|    110|    ssh_string pubkey = NULL;
  237|    110|    ssh_string *pubkey_loc = NULL;
  238|       |
  239|    110|    pubkey = ssh_ecdh_generate(session);
  240|    110|    if (pubkey == NULL) {
  ------------------
  |  Branch (240:9): [True: 0, False: 110]
  ------------------
  241|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  242|      0|    }
  243|       |
  244|    110|    if (session->server) {
  ------------------
  |  Branch (244:9): [True: 0, False: 110]
  ------------------
  245|      0|        pubkey_loc = &session->next_crypto->ecdh_server_pubkey;
  246|    110|    } else {
  247|    110|        pubkey_loc = &session->next_crypto->ecdh_client_pubkey;
  248|    110|    }
  249|       |
  250|    110|    ssh_string_free(*pubkey_loc);
  251|    110|    *pubkey_loc = pubkey;
  252|       |
  253|    110|    return SSH_OK;
  ------------------
  |  |  316|    110|#define SSH_OK 0     /* No error */
  ------------------
  254|    110|}
ssh_client_ecdh_init:
  260|      6|{
  261|      6|    int rc;
  262|       |
  263|      6|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_KEX_ECDH_INIT);
  ------------------
  |  |   17|      6|#define SSH2_MSG_KEX_ECDH_INIT 30
  ------------------
  264|      6|    if (rc < 0) {
  ------------------
  |  Branch (264:9): [True: 0, False: 6]
  ------------------
  265|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  266|      0|    }
  267|       |
  268|      6|    rc = ssh_ecdh_init(session);
  269|      6|    if (rc < 0) {
  ------------------
  |  Branch (269:9): [True: 0, False: 6]
  ------------------
  270|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  271|      0|    }
  272|       |
  273|      6|    rc = ssh_buffer_add_ssh_string(session->out_buffer,
  274|      6|                                   session->next_crypto->ecdh_client_pubkey);
  275|      6|    if (rc < 0) {
  ------------------
  |  Branch (275:9): [True: 0, False: 6]
  ------------------
  276|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  277|      0|    }
  278|       |
  279|       |    /* register the packet callbacks */
  280|      6|    ssh_packet_set_callbacks(session, &ssh_ecdh_client_callbacks);
  281|      6|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  282|       |
  283|      6|    rc = ssh_packet_send(session);
  284|       |
  285|      6|    return rc;
  286|      6|}
ecdh_build_k:
  289|      1|{
  290|      1|  struct ssh_crypto_struct *next_crypto = session->next_crypto;
  291|      1|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  292|      1|  const EC_GROUP *group = EC_KEY_get0_group(next_crypto->ecdh_privkey);
  293|      1|  EC_POINT *pubkey = NULL;
  294|      1|  void *buffer = NULL;
  295|      1|  int rc;
  296|      1|  int len = (EC_GROUP_get_degree(group) + 7) / 8;
  297|      1|  bignum_CTX ctx = bignum_ctx_new();
  ------------------
  |  |   91|      1|#define bignum_ctx_new() BN_CTX_new()
  ------------------
  298|      1|  if (ctx == NULL) {
  ------------------
  |  Branch (298:7): [True: 0, False: 1]
  ------------------
  299|      0|    return -1;
  300|      0|  }
  301|      1|  pubkey = EC_POINT_new(group);
  302|      1|  if (pubkey == NULL) {
  ------------------
  |  Branch (302:7): [True: 0, False: 1]
  ------------------
  303|      0|    bignum_ctx_free(ctx);
  ------------------
  |  |   92|      0|#define bignum_ctx_free(num) BN_CTX_free(num)
  ------------------
  304|      0|    return -1;
  305|      0|  }
  306|       |
  307|      1|  if (session->server) {
  ------------------
  |  Branch (307:7): [True: 0, False: 1]
  ------------------
  308|      0|      rc = EC_POINT_oct2point(group,
  309|      0|                              pubkey,
  310|      0|                              ssh_string_data(next_crypto->ecdh_client_pubkey),
  311|      0|                              ssh_string_len(next_crypto->ecdh_client_pubkey),
  312|      0|                              ctx);
  313|      1|  } else {
  314|      1|      rc = EC_POINT_oct2point(group,
  315|      1|                              pubkey,
  316|      1|                              ssh_string_data(next_crypto->ecdh_server_pubkey),
  317|      1|                              ssh_string_len(next_crypto->ecdh_server_pubkey),
  318|      1|                              ctx);
  319|      1|  }
  320|      1|  bignum_ctx_free(ctx);
  ------------------
  |  |   92|      1|#define bignum_ctx_free(num) BN_CTX_free(num)
  ------------------
  321|      1|  if (rc <= 0) {
  ------------------
  |  Branch (321:7): [True: 1, False: 0]
  ------------------
  322|      1|      EC_POINT_clear_free(pubkey);
  323|      1|      return -1;
  324|      1|  }
  325|       |
  326|      0|  buffer = malloc(len);
  327|      0|  if (buffer == NULL) {
  ------------------
  |  Branch (327:7): [True: 0, False: 0]
  ------------------
  328|      0|      EC_POINT_clear_free(pubkey);
  329|      0|      return -1;
  330|      0|  }
  331|       |
  332|      0|  rc = ECDH_compute_key(buffer,
  333|      0|                        len,
  334|      0|                        pubkey,
  335|      0|                        next_crypto->ecdh_privkey,
  336|      0|                        NULL);
  337|      0|  EC_POINT_clear_free(pubkey);
  338|      0|  if (rc <= 0) {
  ------------------
  |  Branch (338:7): [True: 0, False: 0]
  ------------------
  339|      0|      free(buffer);
  340|      0|      return -1;
  341|      0|  }
  342|       |
  343|      0|  bignum_bin2bn(buffer, len, &next_crypto->shared_secret);
  ------------------
  |  |   79|      0|    do {                                     \
  |  |   80|      0|        (*dest) = BN_new();                  \
  |  |   81|      0|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 0, False: 0]
  |  |  ------------------
  |  |   82|      0|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|      0|        }                                    \
  |  |   84|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
  344|      0|  free(buffer);
  345|       |#else
  346|       |  const char *curve = NULL;
  347|       |  EVP_PKEY *pubkey = NULL;
  348|       |  void *secret = NULL;
  349|       |  size_t secret_len;
  350|       |  int rc;
  351|       |  ssh_string peer_pubkey = NULL;
  352|       |  OSSL_PARAM_BLD *param_bld = OSSL_PARAM_BLD_new();
  353|       |  EVP_PKEY_CTX *dh_ctx = EVP_PKEY_CTX_new_from_pkey(NULL,
  354|       |                                                    next_crypto->ecdh_privkey,
  355|       |                                                    NULL);
  356|       |
  357|       |  if (dh_ctx == NULL || param_bld == NULL) {
  358|       |      ssh_set_error_oom(session);
  359|       |      EVP_PKEY_CTX_free(dh_ctx);
  360|       |      OSSL_PARAM_BLD_free(param_bld);
  361|       |      return -1;
  362|       |  }
  363|       |
  364|       |  rc = EVP_PKEY_derive_init(dh_ctx);
  365|       |  if (rc != 1) {
  366|       |      ssh_set_error(session,
  367|       |                    SSH_FATAL,
  368|       |                    "Could not init PKEY derive: %s",
  369|       |                    ERR_error_string(ERR_get_error(), NULL));
  370|       |      EVP_PKEY_CTX_free(dh_ctx);
  371|       |      OSSL_PARAM_BLD_free(param_bld);
  372|       |      return -1;
  373|       |  }
  374|       |
  375|       |  if (session->server) {
  376|       |      peer_pubkey = next_crypto->ecdh_client_pubkey;
  377|       |  } else {
  378|       |      peer_pubkey = next_crypto->ecdh_server_pubkey;
  379|       |  }
  380|       |  rc = OSSL_PARAM_BLD_push_octet_string(param_bld,
  381|       |                                        OSSL_PKEY_PARAM_PUB_KEY,
  382|       |                                        ssh_string_data(peer_pubkey),
  383|       |                                        ssh_string_len(peer_pubkey));
  384|       |  if (rc != 1) {
  385|       |      ssh_set_error(session,
  386|       |                    SSH_FATAL,
  387|       |                    "Could not push the pub key: %s",
  388|       |                    ERR_error_string(ERR_get_error(), NULL));
  389|       |      EVP_PKEY_CTX_free(dh_ctx);
  390|       |      OSSL_PARAM_BLD_free(param_bld);
  391|       |      return -1;
  392|       |  }
  393|       |  curve = ecdh_kex_type_to_curve(next_crypto->kex_type);
  394|       |  rc = OSSL_PARAM_BLD_push_utf8_string(param_bld,
  395|       |                                       OSSL_PKEY_PARAM_GROUP_NAME,
  396|       |                                       (char *)curve,
  397|       |                                       strlen(curve));
  398|       |  if (rc != 1) {
  399|       |      ssh_set_error(session,
  400|       |                    SSH_FATAL,
  401|       |                    "Could not push the group name: %s",
  402|       |                    ERR_error_string(ERR_get_error(), NULL));
  403|       |      EVP_PKEY_CTX_free(dh_ctx);
  404|       |      OSSL_PARAM_BLD_free(param_bld);
  405|       |      return -1;
  406|       |  }
  407|       |
  408|       |  rc = evp_build_pkey("EC", param_bld, &pubkey, EVP_PKEY_PUBLIC_KEY);
  409|       |  OSSL_PARAM_BLD_free(param_bld);
  410|       |  if (rc != SSH_OK) {
  411|       |      ssh_set_error(session,
  412|       |                    SSH_FATAL,
  413|       |                    "Could not build the pkey: %s",
  414|       |                    ERR_error_string(ERR_get_error(), NULL));
  415|       |      EVP_PKEY_CTX_free(dh_ctx);
  416|       |      return -1;
  417|       |  }
  418|       |
  419|       |  rc = EVP_PKEY_derive_set_peer(dh_ctx, pubkey);
  420|       |  EVP_PKEY_free(pubkey);
  421|       |  if (rc != 1) {
  422|       |      ssh_set_error(session,
  423|       |                    SSH_FATAL,
  424|       |                    "Could not set peer pubkey: %s",
  425|       |                    ERR_error_string(ERR_get_error(), NULL));
  426|       |      EVP_PKEY_CTX_free(dh_ctx);
  427|       |      return -1;
  428|       |  }
  429|       |
  430|       |  /* get the max length of the secret */
  431|       |  rc = EVP_PKEY_derive(dh_ctx, NULL, &secret_len);
  432|       |  if (rc != 1) {
  433|       |      ssh_set_error(session,
  434|       |                    SSH_FATAL,
  435|       |                    "Could not set peer pubkey: %s",
  436|       |                    ERR_error_string(ERR_get_error(), NULL));
  437|       |      EVP_PKEY_CTX_free(dh_ctx);
  438|       |      return -1;
  439|       |  }
  440|       |
  441|       |  secret = malloc(secret_len);
  442|       |  if (secret == NULL) {
  443|       |      ssh_set_error_oom(session);
  444|       |      EVP_PKEY_CTX_free(dh_ctx);
  445|       |      return -1;
  446|       |  }
  447|       |
  448|       |  rc = EVP_PKEY_derive(dh_ctx, secret, &secret_len);
  449|       |  if (rc != 1) {
  450|       |      ssh_set_error(session,
  451|       |                    SSH_FATAL,
  452|       |                    "Could not derive shared key: %s",
  453|       |                    ERR_error_string(ERR_get_error(), NULL));
  454|       |      EVP_PKEY_CTX_free(dh_ctx);
  455|       |      free(secret);
  456|       |      return -1;
  457|       |  }
  458|       |
  459|       |  EVP_PKEY_CTX_free(dh_ctx);
  460|       |
  461|       |  bignum_bin2bn(secret, secret_len, &next_crypto->shared_secret);
  462|       |  free(secret);
  463|       |#endif /* OPENSSL_VERSION_NUMBER */
  464|      0|  if (next_crypto->shared_secret == NULL) {
  ------------------
  |  Branch (464:7): [True: 0, False: 0]
  ------------------
  465|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  466|      0|      EC_KEY_free(next_crypto->ecdh_privkey);
  467|       |#else
  468|       |      EVP_PKEY_free(next_crypto->ecdh_privkey);
  469|       |#endif /* OPENSSL_VERSION_NUMBER */
  470|      0|      next_crypto->ecdh_privkey = NULL;
  471|      0|      return -1;
  472|      0|  }
  473|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  474|      0|  EC_KEY_free(next_crypto->ecdh_privkey);
  475|       |#else
  476|       |  EVP_PKEY_free(next_crypto->ecdh_privkey);
  477|       |#endif /* OPENSSL_VERSION_NUMBER */
  478|      0|  next_crypto->ecdh_privkey = NULL;
  479|       |
  480|       |#ifdef DEBUG_CRYPTO
  481|       |    ssh_log_hexdump("Session server cookie",
  482|       |                   next_crypto->server_kex.cookie, 16);
  483|       |    ssh_log_hexdump("Session client cookie",
  484|       |                   next_crypto->client_kex.cookie, 16);
  485|       |    ssh_print_bignum("Shared secret key", next_crypto->shared_secret);
  486|       |#endif /* DEBUG_CRYPTO */
  487|       |
  488|      0|  return 0;
  489|      0|}
ecdh_crypto.c:ssh_ecdh_generate:
   80|    110|{
   81|    110|    ssh_string pubkey_string = NULL;
   82|    110|#if OPENSSL_VERSION_NUMBER < 0x30000000L
   83|    110|    const EC_POINT *point = NULL;
   84|    110|    const EC_GROUP *group = NULL;
   85|    110|    EC_KEY *key = NULL;
   86|    110|    int curve;
   87|       |#else
   88|       |    EC_POINT *point = NULL;
   89|       |    EC_GROUP *group = NULL;
   90|       |    const char *curve = NULL;
   91|       |    EVP_PKEY *key = NULL;
   92|       |    OSSL_PARAM *out_params = NULL;
   93|       |    const OSSL_PARAM *pubkey_param = NULL;
   94|       |    const void *pubkey = NULL;
   95|       |    size_t pubkey_len;
   96|       |    int nid;
   97|       |#endif /* OPENSSL_VERSION_NUMBER */
   98|    110|    int rc;
   99|       |
  100|    110|    curve = ecdh_kex_type_to_curve(session->next_crypto->kex_type);
  101|    110|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  102|    110|    if (curve == SSH_ERROR) {
  ------------------
  |  |  317|    110|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (102:9): [True: 0, False: 110]
  ------------------
  103|      0|        SSH_LOG(SSH_LOG_TRACE, "Failed to get curve name");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  104|      0|        return NULL;
  105|      0|    }
  106|       |
  107|    110|    key = EC_KEY_new_by_curve_name(curve);
  108|       |#else
  109|       |    if (curve == NULL) {
  110|       |        SSH_LOG(SSH_LOG_TRACE, "Failed to get curve name");
  111|       |        return NULL;
  112|       |    }
  113|       |
  114|       |    key = EVP_EC_gen(curve);
  115|       |#endif /* OPENSSL_VERSION_NUMBER */
  116|    110|    if (key == NULL) {
  ------------------
  |  Branch (116:9): [True: 0, False: 110]
  ------------------
  117|      0|        SSH_LOG(SSH_LOG_TRACE, "Failed to generate key");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  118|      0|        return NULL;
  119|      0|    }
  120|       |
  121|    110|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  122|    110|    group = EC_KEY_get0_group(key);
  123|    110|    if (group == NULL) {
  ------------------
  |  Branch (123:9): [True: 0, False: 110]
  ------------------
  124|      0|        SSH_LOG(SSH_LOG_TRACE, "Failed to get group");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  125|      0|        EC_KEY_free(key);
  126|      0|        return NULL;
  127|      0|    }
  128|       |
  129|    110|    rc = EC_KEY_generate_key(key);
  130|    110|    if (rc != 1) {
  ------------------
  |  Branch (130:9): [True: 0, False: 110]
  ------------------
  131|      0|        SSH_LOG(SSH_LOG_TRACE, "Failed to generate EC key");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  132|      0|        EC_KEY_free(key);
  133|      0|        return NULL;
  134|      0|    }
  135|       |
  136|    110|    point = EC_KEY_get0_public_key(key);
  137|    110|    if (point == NULL) {
  ------------------
  |  Branch (137:9): [True: 0, False: 110]
  ------------------
  138|      0|        SSH_LOG(SSH_LOG_TRACE, "Failed to get EC point");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  139|      0|        EC_KEY_free(key);
  140|      0|        return NULL;
  141|      0|    }
  142|       |
  143|    110|    pubkey_string = pki_key_make_ecpoint_string(group, point);
  144|       |#else
  145|       |    rc = EVP_PKEY_todata(key, EVP_PKEY_PUBLIC_KEY, &out_params);
  146|       |    if (rc != 1) {
  147|       |        SSH_LOG(SSH_LOG_TRACE, "Failed to export public key");
  148|       |        EVP_PKEY_free(key);
  149|       |        return NULL;
  150|       |    }
  151|       |
  152|       |    pubkey_param = OSSL_PARAM_locate_const(out_params, OSSL_PKEY_PARAM_PUB_KEY);
  153|       |    if (pubkey_param == NULL) {
  154|       |        SSH_LOG(SSH_LOG_TRACE, "Failed to find public key");
  155|       |        EVP_PKEY_free(key);
  156|       |        OSSL_PARAM_free(out_params);
  157|       |        return NULL;
  158|       |    }
  159|       |
  160|       |    rc = OSSL_PARAM_get_octet_string_ptr(pubkey_param,
  161|       |                                         (const void**)&pubkey,
  162|       |                                         &pubkey_len);
  163|       |    if (rc != 1) {
  164|       |        SSH_LOG(SSH_LOG_TRACE, "Failed to read public key");
  165|       |        OSSL_PARAM_free(out_params);
  166|       |        EVP_PKEY_free(key);
  167|       |        return NULL;
  168|       |    }
  169|       |
  170|       |    /* Convert the data to low-level representation */
  171|       |    nid = pki_key_ecgroup_name_to_nid(curve);
  172|       |    group = EC_GROUP_new_by_curve_name_ex(NULL, NULL, nid);
  173|       |    if (group == NULL) {
  174|       |        ssh_set_error(session,
  175|       |                      SSH_FATAL,
  176|       |                      "Could not create group: %s",
  177|       |                      ERR_error_string(ERR_get_error(), NULL));
  178|       |        OSSL_PARAM_free(out_params);
  179|       |        EVP_PKEY_free(key);
  180|       |        return NULL;
  181|       |    }
  182|       |    point = EC_POINT_new(group);
  183|       |    if (point == NULL) {
  184|       |        ssh_set_error(session,
  185|       |                      SSH_FATAL,
  186|       |                      "Could not create point: %s",
  187|       |                      ERR_error_string(ERR_get_error(), NULL));
  188|       |        EC_GROUP_free(group);
  189|       |        OSSL_PARAM_free(out_params);
  190|       |        EVP_PKEY_free(key);
  191|       |        return NULL;
  192|       |    }
  193|       |    rc = EC_POINT_oct2point(group, point, pubkey, pubkey_len, NULL);
  194|       |    OSSL_PARAM_free(out_params);
  195|       |    if (rc != 1) {
  196|       |        SSH_LOG(SSH_LOG_TRACE, "Failed to export public key");
  197|       |        EC_GROUP_free(group);
  198|       |        EC_POINT_free(point);
  199|       |        EVP_PKEY_free(key);
  200|       |        return NULL;
  201|       |    }
  202|       |
  203|       |    pubkey_string = pki_key_make_ecpoint_string(group, point);
  204|       |    EC_GROUP_free(group);
  205|       |    EC_POINT_free(point);
  206|       |#endif /* OPENSSL_VERSION_NUMBER */
  207|    110|    if (pubkey_string == NULL) {
  ------------------
  |  Branch (207:9): [True: 0, False: 110]
  ------------------
  208|      0|        SSH_LOG(SSH_LOG_TRACE, "Failed to convert public key");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  209|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  210|      0|        EC_KEY_free(key);
  211|       |#else
  212|       |        EVP_PKEY_free(key);
  213|       |#endif /* OPENSSL_VERSION_NUMBER */
  214|      0|        return NULL;
  215|      0|    }
  216|       |
  217|       |    /* Free any previously allocated privkey */
  218|    110|    if (session->next_crypto->ecdh_privkey != NULL) {
  ------------------
  |  Branch (218:9): [True: 0, False: 110]
  ------------------
  219|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  220|      0|        EC_KEY_free(session->next_crypto->ecdh_privkey);
  221|       |#else
  222|       |        EVP_PKEY_free(session->next_crypto->ecdh_privkey);
  223|       |#endif
  224|      0|        session->next_crypto->ecdh_privkey = NULL;
  225|      0|    }
  226|       |
  227|    110|    session->next_crypto->ecdh_privkey = key;
  228|    110|    return pubkey_string;
  229|    110|}
ecdh_crypto.c:ecdh_kex_type_to_curve:
   50|    110|static int ecdh_kex_type_to_curve(enum ssh_key_exchange_e kex_type) {
   51|       |#else
   52|       |static const char *ecdh_kex_type_to_curve(enum ssh_key_exchange_e kex_type) {
   53|       |#endif /* OPENSSL_VERSION_NUMBER */
   54|    110|    switch (kex_type) {
   55|      4|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (55:5): [True: 4, False: 106]
  ------------------
   56|    108|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (56:5): [True: 104, False: 6]
  ------------------
   57|    108|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (57:5): [True: 0, False: 110]
  ------------------
   58|    108|        return NISTP256;
  ------------------
  |  |   34|    108|#define NISTP256 NID_X9_62_prime256v1
  ------------------
   59|      1|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (59:5): [True: 1, False: 109]
  ------------------
   60|       |#if HAVE_MLKEM1024
   61|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
   62|       |#endif
   63|      1|        return NISTP384;
  ------------------
  |  |   35|      1|#define NISTP384 NID_secp384r1
  ------------------
   64|      1|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (64:5): [True: 1, False: 109]
  ------------------
   65|      1|        return NISTP521;
  ------------------
  |  |   36|      1|#define NISTP521 NID_secp521r1
  ------------------
   66|      0|    default:
  ------------------
  |  Branch (66:5): [True: 0, False: 110]
  ------------------
   67|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
   68|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   69|       |#else
   70|       |        return NULL;
   71|       |#endif
   72|    110|    }
   73|    110|}

_ssh_set_error:
   55|  7.81k|{
   56|  7.81k|    struct ssh_common_struct *err = error;
   57|  7.81k|    va_list va;
   58|       |
   59|  7.81k|    va_start(va, descr);
   60|  7.81k|    vsnprintf(err->error.error_buffer, ERROR_BUFFERLEN, descr, va);
  ------------------
  |  |  219|  7.81k|#define ERROR_BUFFERLEN 1024
  ------------------
   61|  7.81k|    va_end(va);
   62|       |
   63|  7.81k|    err->error.error_code = code;
   64|  7.81k|    if (ssh_get_log_level() == SSH_LOG_TRACE) {
  ------------------
  |  |  363|  7.81k|#define SSH_LOG_TRACE 4
  ------------------
  |  Branch (64:9): [True: 0, False: 7.81k]
  ------------------
   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|  7.81k|}
_ssh_set_error_oom:
   81|    106|{
   82|    106|    struct error_struct *err = error;
   83|       |
   84|    106|    snprintf(err->error_buffer, sizeof(err->error_buffer),
   85|    106|            "%s: Out of memory", function);
   86|    106|    err->error_code = SSH_FATAL;
   87|    106|}
ssh_get_error:
  127|    212|const char *ssh_get_error(void *error) {
  128|    212|  struct error_struct *err = error;
  129|       |
  130|    212|  return err->error_buffer;
  131|    212|}

libcrux_ml_kem_mlkem768_portable_generate_key_pair:
 8762|    104|libcrux_ml_kem_mlkem768_portable_generate_key_pair(uint8_t randomness[64U]) {
 8763|    104|  return libcrux_ml_kem_ind_cca_instantiations_portable_generate_keypair_ce(
 8764|    104|      randomness);
 8765|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_ZERO_d6_ea:
 5317|  2.18k|libcrux_ml_kem_polynomial_ZERO_d6_ea(void) {
 5318|  2.18k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d lit;
 5319|  2.18k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector
 5320|  2.18k|      repeat_expression[16U];
 5321|  37.1k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5321:31): [True: 34.9k, False: 2.18k]
  ------------------
 5322|  34.9k|    repeat_expression[i] = libcrux_ml_kem_vector_portable_ZERO_b8();
 5323|  34.9k|  }
 5324|  2.18k|  memcpy(lit.coefficients, repeat_expression,
 5325|  2.18k|         (size_t)16U *
 5326|  2.18k|             sizeof(libcrux_ml_kem_vector_portable_vector_type_PortableVector));
 5327|  2.18k|  return lit;
 5328|  2.18k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ZERO_b8:
 3836|  74.8k|libcrux_ml_kem_vector_portable_ZERO_b8(void) {
 3837|  74.8k|  return libcrux_ml_kem_vector_portable_vector_type_zero();
 3838|  74.8k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_vector_type_zero:
 3822|  89.8k|libcrux_ml_kem_vector_portable_vector_type_zero(void) {
 3823|  89.8k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector lit;
 3824|  89.8k|  int16_t ret[16U];
 3825|  89.8k|  int16_t buf[16U] = {0U};
 3826|  89.8k|  libcrux_secrets_int_public_integers_classify_27_46(buf, ret);
 3827|  89.8k|  memcpy(lit.elements, ret, (size_t)16U * sizeof(int16_t));
 3828|  89.8k|  return lit;
 3829|  89.8k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_46:
 1075|  89.8k|    int16_t self[16U], int16_t ret[16U]) {
 1076|  89.8k|  memcpy(ret, self, (size_t)16U * sizeof(int16_t));
 1077|  89.8k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_39:
  515|  5.21M|libcrux_secrets_int_public_integers_classify_27_39(int16_t self) {
  516|  5.21M|  return self;
  517|  5.21M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_39:
  494|  5.55M|libcrux_secrets_int_public_integers_declassify_d8_39(int16_t self) {
  495|  5.55M|  return self;
  496|  5.55M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i32_f5:
  556|  5.31M|static KRML_MUSTINLINE int32_t libcrux_secrets_int_as_i32_f5(int16_t self) {
  557|  5.31M|  return libcrux_secrets_int_public_integers_classify_27_a8(
  558|  5.31M|      (int32_t)libcrux_secrets_int_public_integers_declassify_d8_39(self));
  559|  5.31M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_a8:
  549|  6.23M|libcrux_secrets_int_public_integers_classify_27_a8(int32_t self) {
  550|  6.23M|  return self;
  551|  6.23M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i16_36:
  577|  3.91M|static KRML_MUSTINLINE int16_t libcrux_secrets_int_as_i16_36(int32_t self) {
  578|  3.91M|  return libcrux_secrets_int_public_integers_classify_27_39(
  579|  3.91M|      (int16_t)libcrux_secrets_int_public_integers_declassify_d8_a8(self));
  580|  3.91M|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_a8:
  570|  3.91M|libcrux_secrets_int_public_integers_declassify_d8_a8(int32_t self) {
  571|  3.91M|  return self;
  572|  3.91M|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea:
 5538|  1.87k|    size_t layer, size_t _initial_coefficient_bound) {
 5539|  1.87k|  size_t step = (size_t)1U << (uint32_t)layer;
 5540|  10.6k|  for (size_t i0 = (size_t)0U; i0 < (size_t)128U >> (uint32_t)layer; i0++) {
  ------------------
  |  Branch (5540:32): [True: 8.73k, False: 1.87k]
  ------------------
 5541|  8.73k|    size_t round = i0;
 5542|  8.73k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5543|  8.73k|    size_t offset = round * step * (size_t)2U;
 5544|  8.73k|    size_t offset_vec = offset / (size_t)16U;
 5545|  8.73k|    size_t step_vec = step / (size_t)16U;
 5546|  23.7k|    for (size_t i = offset_vec; i < offset_vec + step_vec; i++) {
  ------------------
  |  Branch (5546:33): [True: 14.9k, False: 8.73k]
  ------------------
 5547|  14.9k|      size_t j = i;
 5548|  14.9k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2 uu____0 =
 5549|  14.9k|          libcrux_ml_kem_ntt_ntt_layer_int_vec_step_ea(
 5550|  14.9k|              re->coefficients[j], re->coefficients[j + step_vec],
 5551|  14.9k|              libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
 5552|  14.9k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector x = uu____0.fst;
 5553|  14.9k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector y = uu____0.snd;
 5554|  14.9k|      re->coefficients[j] = x;
 5555|  14.9k|      re->coefficients[j + step_vec] = y;
 5556|  14.9k|    }
 5557|  8.73k|  }
 5558|  1.87k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_layer_int_vec_step_ea:
 5519|  14.9k|        int16_t zeta_r) {
 5520|  14.9k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector t =
 5521|  14.9k|      libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(b,
 5522|  14.9k|                                                                        zeta_r);
 5523|  14.9k|  b = libcrux_ml_kem_vector_portable_sub_b8(a, &t);
 5524|  14.9k|  a = libcrux_ml_kem_vector_portable_add_b8(a, &t);
 5525|  14.9k|  return (KRML_CLITERAL(
  ------------------
  |  |  154|  14.9k|#define KRML_CLITERAL(type) (type)
  ------------------
 5526|  14.9k|      libcrux_ml_kem_vector_portable_vector_type_PortableVector_x2){.fst = a,
 5527|  14.9k|                                                                    .snd = b});
 5528|  14.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8:
 4077|  19.9k|    int16_t constant) {
 4078|  19.9k|  return libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_by_constant(
 4079|  19.9k|      vector, libcrux_secrets_int_public_integers_classify_27_39(constant));
 4080|  19.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_by_constant:
 4059|  19.9k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec, int16_t c) {
 4060|  19.9k|  for (size_t i = (size_t)0U;
 4061|   339k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   339k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (4061:8): [True: 319k, False: 19.9k]
  ------------------
 4062|   319k|    size_t i0 = i;
 4063|   319k|    vec.elements[i0] =
 4064|   319k|        libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer(
 4065|   319k|            vec.elements[i0], c);
 4066|   319k|  }
 4067|  19.9k|  return vec;
 4068|  19.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer:
 4050|   559k|    int16_t fe, int16_t fer) {
 4051|   559k|  int32_t product =
 4052|   559k|      libcrux_secrets_int_as_i32_f5(fe) * libcrux_secrets_int_as_i32_f5(fer);
 4053|   559k|  return libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(
 4054|   559k|      product);
 4055|   559k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element:
 4017|   918k|    int32_t value) {
 4018|   918k|  int32_t k =
 4019|   918k|      libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_as_i16_36(value)) *
 4020|   918k|      libcrux_secrets_int_as_i32_b8(
 4021|   918k|          libcrux_secrets_int_public_integers_classify_27_df(
 4022|   918k|              LIBCRUX_ML_KEM_VECTOR_TRAITS_INVERSE_OF_MODULUS_MOD_MONTGOMERY_R));
  ------------------
  |  | 3780|   918k|  (62209U)
  ------------------
 4023|   918k|  int32_t k_times_modulus =
 4024|   918k|      libcrux_secrets_int_as_i32_f5(libcrux_secrets_int_as_i16_36(k)) *
 4025|   918k|      libcrux_secrets_int_as_i32_f5(
 4026|   918k|          libcrux_secrets_int_public_integers_classify_27_39(
 4027|   918k|              LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS));
  ------------------
  |  | 3777|   918k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 4028|   918k|  int16_t c = libcrux_secrets_int_as_i16_36(
 4029|   918k|      k_times_modulus >>
 4030|   918k|      (uint32_t)LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT);
  ------------------
  |  | 3997|   918k|#define LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT (16U)
  ------------------
 4031|   918k|  int16_t value_high = libcrux_secrets_int_as_i16_36(
 4032|   918k|      value >>
 4033|   918k|      (uint32_t)LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT);
  ------------------
  |  | 3997|   918k|#define LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_MONTGOMERY_SHIFT (16U)
  ------------------
 4034|   918k|  return value_high - c;
 4035|   918k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_i32_b8:
  598|   918k|static KRML_MUSTINLINE int32_t libcrux_secrets_int_as_i32_b8(uint32_t self) {
  599|   918k|  return libcrux_secrets_int_public_integers_classify_27_a8(
  600|   918k|      (int32_t)libcrux_secrets_int_public_integers_declassify_d8_df(self));
  601|   918k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_df:
  591|   918k|libcrux_secrets_int_public_integers_declassify_d8_df(uint32_t self) {
  592|   918k|  return self;
  593|   918k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_df:
  675|   918k|libcrux_secrets_int_public_integers_classify_27_df(uint32_t self) {
  676|   918k|  return self;
  677|   918k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_sub_b8:
 3884|  19.9k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector *rhs) {
 3885|  19.9k|  return libcrux_ml_kem_vector_portable_arithmetic_sub(lhs, rhs);
 3886|  19.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_sub:
 3867|  19.9k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector *rhs) {
 3868|  19.9k|  for (size_t i = (size_t)0U;
 3869|   339k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   339k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3869:8): [True: 319k, False: 19.9k]
  ------------------
 3870|   319k|    size_t i0 = i;
 3871|   319k|    size_t uu____0 = i0;
 3872|   319k|    lhs.elements[uu____0] = lhs.elements[uu____0] - rhs->elements[i0];
 3873|   319k|  }
 3874|  19.9k|  return lhs;
 3875|  19.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_add_b8:
 3860|  39.9k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector *rhs) {
 3861|  39.9k|  return libcrux_ml_kem_vector_portable_arithmetic_add(lhs, rhs);
 3862|  39.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_add:
 3843|  49.9k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector *rhs) {
 3844|  49.9k|  for (size_t i = (size_t)0U;
 3845|   848k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   848k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3845:8): [True: 798k, False: 49.9k]
  ------------------
 3846|   798k|    size_t i0 = i;
 3847|   798k|    size_t uu____0 = i0;
 3848|   798k|    lhs.elements[uu____0] = lhs.elements[uu____0] + rhs->elements[i0];
 3849|   798k|  }
 3850|  49.9k|  return lhs;
 3851|  49.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_zeta:
 3766|   144k|static KRML_MUSTINLINE int16_t libcrux_ml_kem_polynomial_zeta(size_t i) {
 3767|   144k|  return libcrux_ml_kem_polynomial_ZETAS_TIMES_MONTGOMERY_R[i];
 3768|   144k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_3_ea:
 5568|    624|    size_t _initial_coefficient_bound) {
 5569|  10.6k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5569:31): [True: 9.98k, False: 624]
  ------------------
 5570|  9.98k|    size_t round = i;
 5571|  9.98k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5572|  9.98k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5573|  9.98k|        libcrux_ml_kem_vector_portable_ntt_layer_3_step_b8(
 5574|  9.98k|            re->coefficients[round],
 5575|  9.98k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U]));
 5576|  9.98k|    re->coefficients[round] = uu____0;
 5577|  9.98k|  }
 5578|    624|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_layer_3_step_b8:
 4344|  9.98k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a, int16_t zeta) {
 4345|  9.98k|  return libcrux_ml_kem_vector_portable_ntt_ntt_layer_3_step(a, zeta);
 4346|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_layer_3_step:
 4318|  9.98k|    int16_t zeta) {
 4319|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)0U,
 4320|  9.98k|                                              (size_t)8U);
 4321|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)1U,
 4322|  9.98k|                                              (size_t)9U);
 4323|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)2U,
 4324|  9.98k|                                              (size_t)10U);
 4325|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)3U,
 4326|  9.98k|                                              (size_t)11U);
 4327|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)4U,
 4328|  9.98k|                                              (size_t)12U);
 4329|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)5U,
 4330|  9.98k|                                              (size_t)13U);
 4331|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)6U,
 4332|  9.98k|                                              (size_t)14U);
 4333|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta, (size_t)7U,
 4334|  9.98k|                                              (size_t)15U);
 4335|  9.98k|  return vec;
 4336|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_step:
 4235|   239k|    int16_t zeta, size_t i, size_t j) {
 4236|   239k|  int16_t t =
 4237|   239k|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_multiply_fe_by_fer(
 4238|   239k|          vec->elements[j],
 4239|   239k|          libcrux_secrets_int_public_integers_classify_27_39(zeta));
 4240|   239k|  int16_t a_minus_t = vec->elements[i] - t;
 4241|   239k|  int16_t a_plus_t = vec->elements[i] + t;
 4242|   239k|  vec->elements[j] = a_minus_t;
 4243|   239k|  vec->elements[i] = a_plus_t;
 4244|   239k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_2_ea:
 5588|    624|    size_t _initial_coefficient_bound) {
 5589|  10.6k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5589:31): [True: 9.98k, False: 624]
  ------------------
 5590|  9.98k|    size_t round = i;
 5591|  9.98k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5592|  9.98k|    re->coefficients[round] =
 5593|  9.98k|        libcrux_ml_kem_vector_portable_ntt_layer_2_step_b8(
 5594|  9.98k|            re->coefficients[round], libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
 5595|  9.98k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)1U));
 5596|  9.98k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5597|  9.98k|  }
 5598|    624|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_layer_2_step_b8:
 4311|  9.98k|    int16_t zeta1) {
 4312|  9.98k|  return libcrux_ml_kem_vector_portable_ntt_ntt_layer_2_step(a, zeta0, zeta1);
 4313|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_layer_2_step:
 4284|  9.98k|    int16_t zeta0, int16_t zeta1) {
 4285|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)0U,
 4286|  9.98k|                                              (size_t)4U);
 4287|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)1U,
 4288|  9.98k|                                              (size_t)5U);
 4289|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)2U,
 4290|  9.98k|                                              (size_t)6U);
 4291|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)3U,
 4292|  9.98k|                                              (size_t)7U);
 4293|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)8U,
 4294|  9.98k|                                              (size_t)12U);
 4295|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)9U,
 4296|  9.98k|                                              (size_t)13U);
 4297|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)10U,
 4298|  9.98k|                                              (size_t)14U);
 4299|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)11U,
 4300|  9.98k|                                              (size_t)15U);
 4301|  9.98k|  return vec;
 4302|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_1_ea:
 5608|    624|    size_t _initial_coefficient_bound) {
 5609|  10.6k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5609:31): [True: 9.98k, False: 624]
  ------------------
 5610|  9.98k|    size_t round = i;
 5611|  9.98k|    zeta_i[0U] = zeta_i[0U] + (size_t)1U;
 5612|  9.98k|    re->coefficients[round] =
 5613|  9.98k|        libcrux_ml_kem_vector_portable_ntt_layer_1_step_b8(
 5614|  9.98k|            re->coefficients[round], libcrux_ml_kem_polynomial_zeta(zeta_i[0U]),
 5615|  9.98k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)1U),
 5616|  9.98k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)2U),
 5617|  9.98k|            libcrux_ml_kem_polynomial_zeta(zeta_i[0U] + (size_t)3U));
 5618|  9.98k|    zeta_i[0U] = zeta_i[0U] + (size_t)3U;
 5619|  9.98k|  }
 5620|    624|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_layer_1_step_b8:
 4276|  9.98k|    int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4277|  9.98k|  return libcrux_ml_kem_vector_portable_ntt_ntt_layer_1_step(a, zeta0, zeta1,
 4278|  9.98k|                                                             zeta2, zeta3);
 4279|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_layer_1_step:
 4249|  9.98k|    int16_t zeta0, int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4250|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)0U,
 4251|  9.98k|                                              (size_t)2U);
 4252|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta0, (size_t)1U,
 4253|  9.98k|                                              (size_t)3U);
 4254|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)4U,
 4255|  9.98k|                                              (size_t)6U);
 4256|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta1, (size_t)5U,
 4257|  9.98k|                                              (size_t)7U);
 4258|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta2, (size_t)8U,
 4259|  9.98k|                                              (size_t)10U);
 4260|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta2, (size_t)9U,
 4261|  9.98k|                                              (size_t)11U);
 4262|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta3, (size_t)12U,
 4263|  9.98k|                                              (size_t)14U);
 4264|  9.98k|  libcrux_ml_kem_vector_portable_ntt_ntt_step(&vec, zeta3, (size_t)13U,
 4265|  9.98k|                                              (size_t)15U);
 4266|  9.98k|  return vec;
 4267|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_poly_barrett_reduce_d6_ea:
 5652|    624|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *self) {
 5653|    624|  libcrux_ml_kem_polynomial_poly_barrett_reduce_ea(self);
 5654|    624|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_poly_barrett_reduce_ea:
 5629|    624|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *myself) {
 5630|    624|  for (size_t i = (size_t)0U;
 5631|  10.6k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  10.6k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (5631:8): [True: 9.98k, False: 624]
  ------------------
 5632|  9.98k|    size_t i0 = i;
 5633|  9.98k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5634|  9.98k|        libcrux_ml_kem_vector_portable_barrett_reduce_b8(
 5635|  9.98k|            myself->coefficients[i0]);
 5636|  9.98k|    myself->coefficients[i0] = uu____0;
 5637|  9.98k|  }
 5638|    624|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_barrett_reduce_b8:
 3993|  14.9k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vector) {
 3994|  14.9k|  return libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce(vector);
 3995|  14.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce:
 3975|  14.9k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec) {
 3976|  14.9k|  for (size_t i = (size_t)0U;
 3977|   254k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   254k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3977:8): [True: 239k, False: 14.9k]
  ------------------
 3978|   239k|    size_t i0 = i;
 3979|   239k|    int16_t vi =
 3980|   239k|        libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce_element(
 3981|   239k|            vec.elements[i0]);
 3982|   239k|    vec.elements[i0] = vi;
 3983|   239k|  }
 3984|  14.9k|  return vec;
 3985|  14.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_barrett_reduce_element:
 3964|   239k|    int16_t value) {
 3965|   239k|  int32_t t = libcrux_secrets_int_as_i32_f5(value) *
 3966|   239k|                  LIBCRUX_ML_KEM_VECTOR_PORTABLE_ARITHMETIC_BARRETT_MULTIPLIER +
  ------------------
  |  | 3940|   239k|  ((int32_t)20159)
  ------------------
 3967|   239k|              (LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_R >> 1U);
  ------------------
  |  | 3945|   239k|  ((int32_t)1 << (uint32_t)LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT)
  |  |  ------------------
  |  |  |  | 3942|   239k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT ((int32_t)26)
  |  |  ------------------
  ------------------
 3968|   239k|  int16_t quotient = libcrux_secrets_int_as_i16_36(
 3969|   239k|      t >> (uint32_t)LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT);
  ------------------
  |  | 3942|   239k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_BARRETT_SHIFT ((int32_t)26)
  ------------------
 3970|   239k|  return value - quotient * LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS;
  ------------------
  |  | 3777|   239k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 3971|   239k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_ntt_multiply_d6_ea:
 5901|    936|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *rhs) {
 5902|    936|  return libcrux_ml_kem_polynomial_ntt_multiply_ea(self, rhs);
 5903|    936|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_ntt_multiply_ea:
 5866|    936|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *rhs) {
 5867|    936|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d out =
 5868|    936|      libcrux_ml_kem_polynomial_ZERO_ea();
 5869|    936|  for (size_t i = (size_t)0U;
 5870|  15.9k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  15.9k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (5870:8): [True: 14.9k, False: 936]
  ------------------
 5871|  14.9k|    size_t i0 = i;
 5872|  14.9k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5873|  14.9k|        libcrux_ml_kem_vector_portable_ntt_multiply_b8(
 5874|  14.9k|            &myself->coefficients[i0], &rhs->coefficients[i0],
 5875|  14.9k|            libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0),
 5876|  14.9k|            libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0 +
 5877|  14.9k|                                           (size_t)1U),
 5878|  14.9k|            libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0 +
 5879|  14.9k|                                           (size_t)2U),
 5880|  14.9k|            libcrux_ml_kem_polynomial_zeta((size_t)64U + (size_t)4U * i0 +
 5881|  14.9k|                                           (size_t)3U));
 5882|  14.9k|    out.coefficients[i0] = uu____0;
 5883|  14.9k|  }
 5884|    936|  return out;
 5885|    936|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_ZERO_ea:
 5817|  2.49k|libcrux_ml_kem_polynomial_ZERO_ea(void) {
 5818|  2.49k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d lit;
 5819|  2.49k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector
 5820|  2.49k|      repeat_expression[16U];
 5821|  42.4k|  for (size_t i = (size_t)0U; i < (size_t)16U; i++) {
  ------------------
  |  Branch (5821:31): [True: 39.9k, False: 2.49k]
  ------------------
 5822|  39.9k|    repeat_expression[i] = libcrux_ml_kem_vector_portable_ZERO_b8();
 5823|  39.9k|  }
 5824|  2.49k|  memcpy(lit.coefficients, repeat_expression,
 5825|  2.49k|         (size_t)16U *
 5826|  2.49k|             sizeof(libcrux_ml_kem_vector_portable_vector_type_PortableVector));
 5827|  2.49k|  return lit;
 5828|  2.49k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_multiply_b8:
 4567|  14.9k|    int16_t zeta0, int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4568|  14.9k|  return libcrux_ml_kem_vector_portable_ntt_ntt_multiply(lhs, rhs, zeta0, zeta1,
 4569|  14.9k|                                                         zeta2, zeta3);
 4570|  14.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_multiply:
 4525|  14.9k|    int16_t zeta0, int16_t zeta1, int16_t zeta2, int16_t zeta3) {
 4526|  14.9k|  int16_t nzeta0 = -zeta0;
 4527|  14.9k|  int16_t nzeta1 = -zeta1;
 4528|  14.9k|  int16_t nzeta2 = -zeta2;
 4529|  14.9k|  int16_t nzeta3 = -zeta3;
 4530|  14.9k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector out =
 4531|  14.9k|      libcrux_ml_kem_vector_portable_vector_type_zero();
 4532|  14.9k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4533|  14.9k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(zeta0),
 4534|  14.9k|      (size_t)0U, &out);
 4535|  14.9k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4536|  14.9k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(nzeta0),
 4537|  14.9k|      (size_t)1U, &out);
 4538|  14.9k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4539|  14.9k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(zeta1),
 4540|  14.9k|      (size_t)2U, &out);
 4541|  14.9k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4542|  14.9k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(nzeta1),
 4543|  14.9k|      (size_t)3U, &out);
 4544|  14.9k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4545|  14.9k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(zeta2),
 4546|  14.9k|      (size_t)4U, &out);
 4547|  14.9k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4548|  14.9k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(nzeta2),
 4549|  14.9k|      (size_t)5U, &out);
 4550|  14.9k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4551|  14.9k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(zeta3),
 4552|  14.9k|      (size_t)6U, &out);
 4553|  14.9k|  libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials(
 4554|  14.9k|      lhs, rhs, libcrux_secrets_int_public_integers_classify_27_39(nzeta3),
 4555|  14.9k|      (size_t)7U, &out);
 4556|  14.9k|  return out;
 4557|  14.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_ntt_ntt_multiply_binomials:
 4491|   119k|    size_t i, libcrux_ml_kem_vector_portable_vector_type_PortableVector *out) {
 4492|   119k|  int16_t ai = a->elements[(size_t)2U * i];
 4493|   119k|  int16_t bi = b->elements[(size_t)2U * i];
 4494|   119k|  int16_t aj = a->elements[(size_t)2U * i + (size_t)1U];
 4495|   119k|  int16_t bj = b->elements[(size_t)2U * i + (size_t)1U];
 4496|   119k|  int32_t ai_bi =
 4497|   119k|      libcrux_secrets_int_as_i32_f5(ai) * libcrux_secrets_int_as_i32_f5(bi);
 4498|   119k|  int32_t aj_bj_ =
 4499|   119k|      libcrux_secrets_int_as_i32_f5(aj) * libcrux_secrets_int_as_i32_f5(bj);
 4500|   119k|  int16_t aj_bj =
 4501|   119k|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(
 4502|   119k|          aj_bj_);
 4503|   119k|  int32_t aj_bj_zeta = libcrux_secrets_int_as_i32_f5(aj_bj) *
 4504|   119k|                       libcrux_secrets_int_as_i32_f5(zeta);
 4505|   119k|  int32_t ai_bi_aj_bj = ai_bi + aj_bj_zeta;
 4506|   119k|  int16_t o0 =
 4507|   119k|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(
 4508|   119k|          ai_bi_aj_bj);
 4509|   119k|  int32_t ai_bj =
 4510|   119k|      libcrux_secrets_int_as_i32_f5(ai) * libcrux_secrets_int_as_i32_f5(bj);
 4511|   119k|  int32_t aj_bi =
 4512|   119k|      libcrux_secrets_int_as_i32_f5(aj) * libcrux_secrets_int_as_i32_f5(bi);
 4513|   119k|  int32_t ai_bj_aj_bi = ai_bj + aj_bi;
 4514|   119k|  int16_t o1 =
 4515|   119k|      libcrux_ml_kem_vector_portable_arithmetic_montgomery_reduce_element(
 4516|   119k|          ai_bj_aj_bi);
 4517|   119k|  out->elements[(size_t)2U * i] = o0;
 4518|   119k|  out->elements[(size_t)2U * i + (size_t)1U] = o1;
 4519|   119k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_to_ring_element_d6_1b:
 5946|    936|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *rhs) {
 5947|    936|  libcrux_ml_kem_polynomial_add_to_ring_element_1b(self, rhs);
 5948|    936|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_to_ring_element_1b:
 5917|    936|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *rhs) {
 5918|    936|  for (size_t i = (size_t)0U;
 5919|  15.9k|       i < Eurydice_slice_len(
  ------------------
  |  |  173|  15.9k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5919:8): [True: 14.9k, False: 936]
  ------------------
 5920|    936|               Eurydice_array_to_slice(
 5921|    936|                   (size_t)16U, myself->coefficients,
 5922|    936|                   libcrux_ml_kem_vector_portable_vector_type_PortableVector),
 5923|    936|               libcrux_ml_kem_vector_portable_vector_type_PortableVector);
 5924|  14.9k|       i++) {
 5925|  14.9k|    size_t i0 = i;
 5926|  14.9k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 5927|  14.9k|        libcrux_ml_kem_vector_portable_add_b8(myself->coefficients[i0],
 5928|  14.9k|                                              &rhs->coefficients[i0]);
 5929|  14.9k|    myself->coefficients[i0] = uu____0;
 5930|  14.9k|  }
 5931|    936|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_to_unsigned_field_modulus_ea:
 6172|  9.98k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 6173|  9.98k|  return libcrux_ml_kem_vector_portable_to_unsigned_representative_b8(a);
 6174|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_to_unsigned_representative_b8:
 4127|  9.98k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4128|  9.98k|  return libcrux_ml_kem_vector_portable_arithmetic_to_unsigned_representative(
 4129|  9.98k|      a);
 4130|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_to_unsigned_representative:
 4112|  9.98k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector a) {
 4113|  9.98k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector t =
 4114|  9.98k|      libcrux_ml_kem_vector_portable_arithmetic_shift_right_ef(a);
 4115|  9.98k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector fm =
 4116|  9.98k|      libcrux_ml_kem_vector_portable_arithmetic_bitwise_and_with_constant(
 4117|  9.98k|          t, LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS);
  ------------------
  |  | 3777|  9.98k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
 4118|  9.98k|  return libcrux_ml_kem_vector_portable_arithmetic_add(a, &fm);
 4119|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_shift_right_ef:
 4101|  9.98k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec) {
 4102|  9.98k|  for (size_t i = (size_t)0U;
 4103|   169k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   169k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (4103:8): [True: 159k, False: 9.98k]
  ------------------
 4104|   159k|    size_t i0 = i;
 4105|   159k|    vec.elements[i0] = vec.elements[i0] >> (uint32_t)(int32_t)15;
 4106|   159k|  }
 4107|  9.98k|  return vec;
 4108|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_bitwise_and_with_constant:
 4084|  9.98k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec, int16_t c) {
 4085|  9.98k|  for (size_t i = (size_t)0U;
 4086|   169k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|   169k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (4086:8): [True: 159k, False: 9.98k]
  ------------------
 4087|   159k|    size_t i0 = i;
 4088|   159k|    size_t uu____0 = i0;
 4089|   159k|    vec.elements[uu____0] = vec.elements[uu____0] & c;
 4090|   159k|  }
 4091|  9.98k|  return vec;
 4092|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_as_u8_f5:
  501|   239k|static KRML_MUSTINLINE uint8_t libcrux_secrets_int_as_u8_f5(int16_t self) {
  502|   239k|  return libcrux_secrets_int_public_integers_classify_27_90(
  503|   239k|      (uint8_t)libcrux_secrets_int_public_integers_declassify_d8_39(self));
  504|   239k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_classify_27_90:
  481|   239k|libcrux_secrets_int_public_integers_classify_27_90(uint8_t self) {
  482|   239k|  return self;
  483|   239k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_G_4a_e0:
 6298|    104|    Eurydice_slice input, uint8_t ret[64U]) {
 6299|    104|  libcrux_ml_kem_hash_functions_portable_G(input, ret);
 6300|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_G:
 3717|    104|    Eurydice_slice input, uint8_t ret[64U]) {
 3718|    104|  uint8_t digest[64U] = {0U};
 3719|    104|  libcrux_sha3_portable_sha512(
 3720|    104|      Eurydice_array_to_slice((size_t)64U, digest, uint8_t), input);
  ------------------
  |  |  204|    104|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    104|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3721|    104|  memcpy(ret, digest, (size_t)64U * sizeof(uint8_t));
 3722|    104|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_sha512:
 3128|    104|                                                         Eurydice_slice data) {
 3129|    104|  libcrux_sha3_generic_keccak_portable_keccak1_96(data, digest);
 3130|    104|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_keccak1_96:
 3092|    104|    Eurydice_slice data, Eurydice_slice out) {
 3093|    104|  libcrux_sha3_generic_keccak_KeccakState_17 s =
 3094|    104|      libcrux_sha3_generic_keccak_new_80_04();
 3095|    104|  size_t data_len = Eurydice_slice_len(data, uint8_t);
  ------------------
  |  |  173|    104|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3096|    104|  for (size_t i = (size_t)0U; i < data_len / (size_t)72U; i++) {
  ------------------
  |  Branch (3096:31): [True: 0, False: 104]
  ------------------
 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|    104|  size_t rem = data_len % (size_t)72U;
 3102|    104|  Eurydice_slice buf[1U] = {data};
 3103|    104|  libcrux_sha3_generic_keccak_absorb_final_80_9e(&s, buf, data_len - rem, rem);
 3104|    104|  size_t outlen = Eurydice_slice_len(out, uint8_t);
  ------------------
  |  |  173|    104|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3105|    104|  size_t blocks = outlen / (size_t)72U;
 3106|    104|  size_t last = outlen - outlen % (size_t)72U;
 3107|    104|  if (blocks == (size_t)0U) {
  ------------------
  |  Branch (3107:7): [True: 104, False: 0]
  ------------------
 3108|    104|    libcrux_sha3_simd_portable_squeeze_13_f8(&s, out, (size_t)0U, outlen);
 3109|    104|  } 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|    104|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_new_80_04:
 1449|  1.76k|libcrux_sha3_generic_keccak_new_80_04(void) {
 1450|  1.76k|  libcrux_sha3_generic_keccak_KeccakState_17 lit;
 1451|  1.76k|  uint64_t repeat_expression[25U];
 1452|  45.9k|  for (size_t i = (size_t)0U; i < (size_t)25U; i++) {
  ------------------
  |  Branch (1452:31): [True: 44.2k, False: 1.76k]
  ------------------
 1453|  44.2k|    repeat_expression[i] = libcrux_sha3_simd_portable_zero_d2();
 1454|  44.2k|  }
 1455|  1.76k|  memcpy(lit.st, repeat_expression, (size_t)25U * sizeof(uint64_t));
 1456|  1.76k|  return lit;
 1457|  1.76k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_zero_d2:
 1320|  44.2k|static KRML_MUSTINLINE uint64_t libcrux_sha3_simd_portable_zero_d2(void) {
 1321|  44.2k|  return 0ULL;
 1322|  44.2k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_block_f8:
 1489|    104|    uint64_t *state, Eurydice_slice blocks, size_t start) {
 1490|    104|  uint64_t state_flat[25U] = {0U};
 1491|  1.04k|  for (size_t i = (size_t)0U; i < (size_t)72U / (size_t)8U; i++) {
  ------------------
  |  Branch (1491:31): [True: 936, False: 104]
  ------------------
 1492|    936|    size_t i0 = i;
 1493|    936|    size_t offset = start + (size_t)8U * i0;
 1494|    936|    uint8_t uu____0[8U];
 1495|    936|    Result_15 dst;
 1496|    936|    Eurydice_slice_to_array2(
  ------------------
  |  |  277|    936|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|    936|                           sizeof(t_arr))
  ------------------
 1497|    936|        &dst,
 1498|    936|        Eurydice_slice_subslice3(blocks, offset, offset + (size_t)8U,
 1499|    936|                                 uint8_t *),
 1500|    936|        Eurydice_slice, uint8_t[8U], TryFromSliceError);
 1501|    936|    unwrap_26_68(dst, uu____0);
 1502|    936|    state_flat[i0] = core_num__u64__from_le_bytes(uu____0);
 1503|    936|  }
 1504|  1.04k|  for (size_t i = (size_t)0U; i < (size_t)72U / (size_t)8U; i++) {
  ------------------
  |  Branch (1504:31): [True: 936, False: 104]
  ------------------
 1505|    936|    size_t i0 = i;
 1506|    936|    libcrux_sha3_traits_set_ij_04(
 1507|    936|        state, i0 / (size_t)5U, i0 % (size_t)5U,
 1508|    936|        libcrux_sha3_traits_get_ij_04(state, i0 / (size_t)5U,
 1509|    936|                                      i0 % (size_t)5U)[0U] ^
 1510|    936|            state_flat[i0]);
 1511|    936|  }
 1512|    104|}
libcrux_mlkem768_sha3.c:Eurydice_slice_to_array3:
  281|  72.1k|                                            Eurydice_slice src, size_t sz) {
  282|  72.1k|  *dst_tag = 0;
  283|  72.1k|  memcpy(dst_ok, src.ptr, sz);
  284|  72.1k|}
libcrux_mlkem768_sha3.c:unwrap_26_68:
 1163|  47.1k|static inline void unwrap_26_68(Result_15 self, uint8_t ret[8U]) {
 1164|  47.1k|  if (self.tag == Ok) {
  ------------------
  |  |  721|  47.1k|#define Ok 0
  ------------------
  |  Branch (1164:7): [True: 47.1k, False: 0]
  ------------------
 1165|  47.1k|    uint8_t f0[8U];
 1166|  47.1k|    memcpy(f0, self.val.case_Ok, (size_t)8U * sizeof(uint8_t));
 1167|  47.1k|    memcpy(ret, f0, (size_t)8U * sizeof(uint8_t));
 1168|  47.1k|  } 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|  47.1k|}
libcrux_mlkem768_sha3.c:core_num__u64__from_le_bytes:
  331|  47.1k|static inline uint64_t core_num__u64__from_le_bytes(uint8_t buf[8]) {
  332|  47.1k|  return load64_le(buf);
  333|  47.1k|}
libcrux_mlkem768_sha3.c:load64_le:
   61|  47.1k|{
   62|  47.1k|	return (uint64_t)(src[0]) |
   63|  47.1k|	    ((uint64_t)(src[1]) << 8) |
   64|  47.1k|	    ((uint64_t)(src[2]) << 16) |
   65|  47.1k|	    ((uint64_t)(src[3]) << 24) |
   66|  47.1k|	    ((uint64_t)(src[4]) << 32) |
   67|  47.1k|	    ((uint64_t)(src[5]) << 40) |
   68|  47.1k|	    ((uint64_t)(src[6]) << 48) |
   69|  47.1k|	    ((uint64_t)(src[7]) << 56);
   70|  47.1k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_traits_set_ij_04:
 1479|  8.11M|                                                          uint64_t value) {
 1480|  8.11M|  arr[(size_t)5U * j + i] = value;
 1481|  8.11M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_traits_get_ij_04:
 1467|  16.2M|                                                               size_t j) {
 1468|  16.2M|  return &arr[(size_t)5U * j + i];
 1469|  16.2M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_final_80_9e:
 3027|    104|    size_t start, size_t len) {
 3028|    104|  libcrux_sha3_simd_portable_load_last_a1_96(self, last, start, len);
 3029|    104|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3030|    104|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_a1_96:
 3009|    104|    size_t start, size_t len) {
 3010|    104|  libcrux_sha3_simd_portable_load_last_96(self->st, input[0U], start, len);
 3011|    104|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_96:
 2983|    104|    uint64_t *state, Eurydice_slice blocks, size_t start, size_t len) {
 2984|    104|  uint8_t buffer[72U] = {0U};
 2985|    104|  Eurydice_slice_copy(
  ------------------
  |  |  229|    104|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 2986|    104|      Eurydice_array_to_subslice3(buffer, (size_t)0U, len, uint8_t *),
 2987|    104|      Eurydice_slice_subslice3(blocks, start, start + len, uint8_t *), uint8_t);
 2988|    104|  buffer[len] = 6U;
 2989|    104|  size_t uu____0 = (size_t)72U - (size_t)1U;
 2990|    104|  buffer[uu____0] = (uint32_t)buffer[uu____0] | 128U;
 2991|    104|  libcrux_sha3_simd_portable_load_block_f8(
 2992|    104|      state, Eurydice_array_to_slice((size_t)72U, buffer, uint8_t), (size_t)0U);
  ------------------
  |  |  204|    104|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    104|                 end) /* x is already at an array type, no need for cast */
  ------------------
 2993|    104|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_squeeze_13_f8:
 3081|    104|    size_t start, size_t len) {
 3082|    104|  libcrux_sha3_simd_portable_store_block_f8(self->st, out, start, len);
 3083|    104|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_store_block_f8:
 3038|    104|    uint64_t *s, Eurydice_slice out, size_t start, size_t len) {
 3039|    104|  size_t octets = len / (size_t)8U;
 3040|    936|  for (size_t i = (size_t)0U; i < octets; i++) {
  ------------------
  |  Branch (3040:31): [True: 832, False: 104]
  ------------------
 3041|    832|    size_t i0 = i;
 3042|    832|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|    832|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    832|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    832|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3043|    832|        out, start + (size_t)8U * i0, start + (size_t)8U * i0 + (size_t)8U,
 3044|    832|        uint8_t *);
 3045|    832|    uint8_t ret[8U];
 3046|    832|    core_num__u64__to_le_bytes(
 3047|    832|        libcrux_sha3_traits_get_ij_04(s, i0 / (size_t)5U, i0 % (size_t)5U)[0U],
 3048|    832|        ret);
 3049|    832|    Eurydice_slice_copy(
  ------------------
  |  |  229|    832|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3050|    832|        uu____0, Eurydice_array_to_slice((size_t)8U, ret, uint8_t), uint8_t);
 3051|    832|  }
 3052|    104|  size_t remaining = len % (size_t)8U;
 3053|    104|  if (remaining > (size_t)0U) {
  ------------------
  |  Branch (3053:7): [True: 0, False: 104]
  ------------------
 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|    104|}
libcrux_mlkem768_sha3.c:core_num__u64__to_le_bytes:
  327|  70.3k|static inline void core_num__u64__to_le_bytes(uint64_t v, uint8_t buf[8]) {
  328|  70.3k|  store64_le(buf, v);
  329|  70.3k|}
libcrux_mlkem768_sha3.c:store64_le:
   48|  70.3k|{
   49|  70.3k|	dst[0] = src & 0xff;
   50|  70.3k|	dst[1] = (src >> 8) & 0xff;
   51|  70.3k|	dst[2] = (src >> 16) & 0xff;
   52|  70.3k|	dst[3] = (src >> 24) & 0xff;
   53|  70.3k|	dst[4] = (src >> 32) & 0xff;
   54|  70.3k|	dst[5] = (src >> 40) & 0xff;
   55|  70.3k|	dst[6] = (src >> 48) & 0xff;
   56|  70.3k|	dst[7] = (src >> 56) & 0xff;
   57|  70.3k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_keccakf1600_80_04:
 2943|  4.48k|    libcrux_sha3_generic_keccak_KeccakState_17 *self) {
 2944|   112k|  for (size_t i = (size_t)0U; i < (size_t)24U; i++) {
  ------------------
  |  Branch (2944:31): [True: 107k, False: 4.48k]
  ------------------
 2945|   107k|    size_t i0 = i;
 2946|   107k|    uint64_t t[5U];
 2947|   107k|    libcrux_sha3_generic_keccak_theta_80_04(self, t);
 2948|   107k|    libcrux_sha3_generic_keccak_KeccakState_17 *uu____0 = self;
 2949|   107k|    uint64_t uu____1[5U];
 2950|   107k|    memcpy(uu____1, t, (size_t)5U * sizeof(uint64_t));
 2951|   107k|    libcrux_sha3_generic_keccak_rho_80_04(uu____0, uu____1);
 2952|   107k|    libcrux_sha3_generic_keccak_pi_80_04(self);
 2953|   107k|    libcrux_sha3_generic_keccak_chi_80_04(self);
 2954|   107k|    libcrux_sha3_generic_keccak_iota_80_04(self, i0);
 2955|   107k|  }
 2956|  4.48k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_theta_80_04:
 1557|   107k|    libcrux_sha3_generic_keccak_KeccakState_17 *self, uint64_t ret[5U]) {
 1558|   107k|  uint64_t c[5U] = {
 1559|   107k|      libcrux_sha3_simd_portable_xor5_d2(
 1560|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1561|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1562|   107k|                                              .snd = (size_t)0U}))[0U],
 1563|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1564|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1565|   107k|                                              .snd = (size_t)0U}))[0U],
 1566|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1567|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1568|   107k|                                              .snd = (size_t)0U}))[0U],
 1569|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1570|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1571|   107k|                                              .snd = (size_t)0U}))[0U],
 1572|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1573|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1574|   107k|                                              .snd = (size_t)0U}))[0U]),
 1575|   107k|      libcrux_sha3_simd_portable_xor5_d2(
 1576|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1577|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1578|   107k|                                              .snd = (size_t)1U}))[0U],
 1579|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1580|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1581|   107k|                                              .snd = (size_t)1U}))[0U],
 1582|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1583|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1584|   107k|                                              .snd = (size_t)1U}))[0U],
 1585|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1586|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1587|   107k|                                              .snd = (size_t)1U}))[0U],
 1588|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1589|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1590|   107k|                                              .snd = (size_t)1U}))[0U]),
 1591|   107k|      libcrux_sha3_simd_portable_xor5_d2(
 1592|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1593|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1594|   107k|                                              .snd = (size_t)2U}))[0U],
 1595|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1596|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1597|   107k|                                              .snd = (size_t)2U}))[0U],
 1598|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1599|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1600|   107k|                                              .snd = (size_t)2U}))[0U],
 1601|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1602|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1603|   107k|                                              .snd = (size_t)2U}))[0U],
 1604|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1605|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1606|   107k|                                              .snd = (size_t)2U}))[0U]),
 1607|   107k|      libcrux_sha3_simd_portable_xor5_d2(
 1608|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1609|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1610|   107k|                                              .snd = (size_t)3U}))[0U],
 1611|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1612|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1613|   107k|                                              .snd = (size_t)3U}))[0U],
 1614|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1615|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1616|   107k|                                              .snd = (size_t)3U}))[0U],
 1617|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1618|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1619|   107k|                                              .snd = (size_t)3U}))[0U],
 1620|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1621|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1622|   107k|                                              .snd = (size_t)3U}))[0U]),
 1623|   107k|      libcrux_sha3_simd_portable_xor5_d2(
 1624|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1625|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1626|   107k|                                              .snd = (size_t)4U}))[0U],
 1627|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1628|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1629|   107k|                                              .snd = (size_t)4U}))[0U],
 1630|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1631|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1632|   107k|                                              .snd = (size_t)4U}))[0U],
 1633|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1634|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1635|   107k|                                              .snd = (size_t)4U}))[0U],
 1636|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 1637|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 1638|   107k|                                              .snd = (size_t)4U}))[0U])};
 1639|   107k|  uint64_t uu____0 = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1640|   107k|      c[((size_t)0U + (size_t)4U) % (size_t)5U],
 1641|   107k|      c[((size_t)0U + (size_t)1U) % (size_t)5U]);
 1642|   107k|  uint64_t uu____1 = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1643|   107k|      c[((size_t)1U + (size_t)4U) % (size_t)5U],
 1644|   107k|      c[((size_t)1U + (size_t)1U) % (size_t)5U]);
 1645|   107k|  uint64_t uu____2 = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1646|   107k|      c[((size_t)2U + (size_t)4U) % (size_t)5U],
 1647|   107k|      c[((size_t)2U + (size_t)1U) % (size_t)5U]);
 1648|   107k|  uint64_t uu____3 = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1649|   107k|      c[((size_t)3U + (size_t)4U) % (size_t)5U],
 1650|   107k|      c[((size_t)3U + (size_t)1U) % (size_t)5U]);
 1651|   107k|  ret[0U] = uu____0;
 1652|   107k|  ret[1U] = uu____1;
 1653|   107k|  ret[2U] = uu____2;
 1654|   107k|  ret[3U] = uu____3;
 1655|   107k|  ret[4U] = libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(
 1656|   107k|      c[((size_t)4U + (size_t)4U) % (size_t)5U],
 1657|   107k|      c[((size_t)4U + (size_t)1U) % (size_t)5U]);
 1658|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor5_d2:
 1333|   537k|    uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e) {
 1334|   537k|  return libcrux_sha3_simd_portable__veor5q_u64(a, b, c, d, e);
 1335|   537k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__veor5q_u64:
 1325|   537k|    uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e) {
 1326|   537k|  return (((a ^ b) ^ c) ^ d) ^ e;
 1327|   537k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_index_c2_04:
 1542|  16.1M|    libcrux_sha3_generic_keccak_KeccakState_17 *self, size_t_x2 index) {
 1543|  16.1M|  return libcrux_sha3_traits_get_ij_04(self->st, index.fst, index.snd);
 1544|  16.1M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left1_and_xor_d2:
 1358|   537k|libcrux_sha3_simd_portable_rotate_left1_and_xor_d2(uint64_t a, uint64_t b) {
 1359|   537k|  return libcrux_sha3_simd_portable__vrax1q_u64(a, b);
 1360|   537k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vrax1q_u64:
 1349|   537k|libcrux_sha3_simd_portable__vrax1q_u64(uint64_t a, uint64_t b) {
 1350|   537k|  uint64_t uu____0 = a;
 1351|   537k|  return uu____0 ^ libcrux_sha3_simd_portable_rotate_left_76(b);
 1352|   537k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_76:
 1344|   645k|libcrux_sha3_simd_portable_rotate_left_76(uint64_t x) {
 1345|   645k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)1);
 1346|   645k|}
libcrux_mlkem768_sha3.c:core_num__u64__rotate_left:
  342|  3.11M|static inline uint64_t core_num__u64__rotate_left(uint64_t x0, uint32_t x1) {
  343|  3.11M|  return (x0 << x1 | x0 >> (64 - x1));
  344|  3.11M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_rho_80_04:
 2540|   107k|    libcrux_sha3_generic_keccak_KeccakState_17 *self, uint64_t t[5U]) {
 2541|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2542|   107k|      self, (size_t)0U, (size_t)0U,
 2543|   107k|      libcrux_sha3_simd_portable_xor_d2(
 2544|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2545|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2546|   107k|                                              .snd = (size_t)0U}))[0U],
 2547|   107k|          t[0U]));
 2548|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____0 = self;
 2549|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2550|   107k|      uu____0, (size_t)1U, (size_t)0U,
 2551|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_02(
 2552|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2553|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2554|   107k|                                              .snd = (size_t)0U}))[0U],
 2555|   107k|          t[0U]));
 2556|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____1 = self;
 2557|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2558|   107k|      uu____1, (size_t)2U, (size_t)0U,
 2559|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_ac(
 2560|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2561|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2562|   107k|                                              .snd = (size_t)0U}))[0U],
 2563|   107k|          t[0U]));
 2564|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____2 = self;
 2565|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2566|   107k|      uu____2, (size_t)3U, (size_t)0U,
 2567|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_020(
 2568|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2569|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2570|   107k|                                              .snd = (size_t)0U}))[0U],
 2571|   107k|          t[0U]));
 2572|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____3 = self;
 2573|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2574|   107k|      uu____3, (size_t)4U, (size_t)0U,
 2575|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_a9(
 2576|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2577|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2578|   107k|                                              .snd = (size_t)0U}))[0U],
 2579|   107k|          t[0U]));
 2580|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____4 = self;
 2581|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2582|   107k|      uu____4, (size_t)0U, (size_t)1U,
 2583|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_76(
 2584|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2585|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2586|   107k|                                              .snd = (size_t)1U}))[0U],
 2587|   107k|          t[1U]));
 2588|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____5 = self;
 2589|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2590|   107k|      uu____5, (size_t)1U, (size_t)1U,
 2591|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_58(
 2592|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2593|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2594|   107k|                                              .snd = (size_t)1U}))[0U],
 2595|   107k|          t[1U]));
 2596|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____6 = self;
 2597|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2598|   107k|      uu____6, (size_t)2U, (size_t)1U,
 2599|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_e0(
 2600|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2601|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2602|   107k|                                              .snd = (size_t)1U}))[0U],
 2603|   107k|          t[1U]));
 2604|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____7 = self;
 2605|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2606|   107k|      uu____7, (size_t)3U, (size_t)1U,
 2607|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_63(
 2608|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2609|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2610|   107k|                                              .snd = (size_t)1U}))[0U],
 2611|   107k|          t[1U]));
 2612|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____8 = self;
 2613|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2614|   107k|      uu____8, (size_t)4U, (size_t)1U,
 2615|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_6a(
 2616|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2617|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2618|   107k|                                              .snd = (size_t)1U}))[0U],
 2619|   107k|          t[1U]));
 2620|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____9 = self;
 2621|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2622|   107k|      uu____9, (size_t)0U, (size_t)2U,
 2623|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_ab(
 2624|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2625|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2626|   107k|                                              .snd = (size_t)2U}))[0U],
 2627|   107k|          t[2U]));
 2628|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____10 = self;
 2629|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2630|   107k|      uu____10, (size_t)1U, (size_t)2U,
 2631|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_5b(
 2632|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2633|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2634|   107k|                                              .snd = (size_t)2U}))[0U],
 2635|   107k|          t[2U]));
 2636|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____11 = self;
 2637|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2638|   107k|      uu____11, (size_t)2U, (size_t)2U,
 2639|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_6f(
 2640|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2641|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2642|   107k|                                              .snd = (size_t)2U}))[0U],
 2643|   107k|          t[2U]));
 2644|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____12 = self;
 2645|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2646|   107k|      uu____12, (size_t)3U, (size_t)2U,
 2647|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_62(
 2648|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2649|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2650|   107k|                                              .snd = (size_t)2U}))[0U],
 2651|   107k|          t[2U]));
 2652|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____13 = self;
 2653|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2654|   107k|      uu____13, (size_t)4U, (size_t)2U,
 2655|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_23(
 2656|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2657|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2658|   107k|                                              .snd = (size_t)2U}))[0U],
 2659|   107k|          t[2U]));
 2660|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____14 = self;
 2661|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2662|   107k|      uu____14, (size_t)0U, (size_t)3U,
 2663|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_37(
 2664|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2665|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2666|   107k|                                              .snd = (size_t)3U}))[0U],
 2667|   107k|          t[3U]));
 2668|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____15 = self;
 2669|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2670|   107k|      uu____15, (size_t)1U, (size_t)3U,
 2671|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_bb(
 2672|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2673|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2674|   107k|                                              .snd = (size_t)3U}))[0U],
 2675|   107k|          t[3U]));
 2676|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____16 = self;
 2677|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2678|   107k|      uu____16, (size_t)2U, (size_t)3U,
 2679|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_b9(
 2680|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2681|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2682|   107k|                                              .snd = (size_t)3U}))[0U],
 2683|   107k|          t[3U]));
 2684|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____17 = self;
 2685|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2686|   107k|      uu____17, (size_t)3U, (size_t)3U,
 2687|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_54(
 2688|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2689|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2690|   107k|                                              .snd = (size_t)3U}))[0U],
 2691|   107k|          t[3U]));
 2692|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____18 = self;
 2693|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2694|   107k|      uu____18, (size_t)4U, (size_t)3U,
 2695|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_4c(
 2696|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2697|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2698|   107k|                                              .snd = (size_t)3U}))[0U],
 2699|   107k|          t[3U]));
 2700|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____19 = self;
 2701|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2702|   107k|      uu____19, (size_t)0U, (size_t)4U,
 2703|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_ce(
 2704|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2705|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2706|   107k|                                              .snd = (size_t)4U}))[0U],
 2707|   107k|          t[4U]));
 2708|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____20 = self;
 2709|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2710|   107k|      uu____20, (size_t)1U, (size_t)4U,
 2711|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_77(
 2712|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2713|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2714|   107k|                                              .snd = (size_t)4U}))[0U],
 2715|   107k|          t[4U]));
 2716|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____21 = self;
 2717|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2718|   107k|      uu____21, (size_t)2U, (size_t)4U,
 2719|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_25(
 2720|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2721|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2722|   107k|                                              .snd = (size_t)4U}))[0U],
 2723|   107k|          t[4U]));
 2724|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____22 = self;
 2725|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2726|   107k|      uu____22, (size_t)3U, (size_t)4U,
 2727|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_af(
 2728|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2729|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2730|   107k|                                              .snd = (size_t)4U}))[0U],
 2731|   107k|          t[4U]));
 2732|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____23 = self;
 2733|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2734|   107k|      uu____23, (size_t)4U, (size_t)4U,
 2735|   107k|      libcrux_sha3_simd_portable_xor_and_rotate_d2_fd(
 2736|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2737|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2738|   107k|                                              .snd = (size_t)4U}))[0U],
 2739|   107k|          t[4U]));
 2740|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_set_80_04:
 1672|  8.06M|    uint64_t v) {
 1673|  8.06M|  libcrux_sha3_traits_set_ij_04(self->st, i, j, v);
 1674|  8.06M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_d2:
 1392|   107k|                                                                  uint64_t b) {
 1393|   107k|  return a ^ b;
 1394|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_02:
 1708|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_02(uint64_t a, uint64_t b) {
 1709|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_02(a, b);
 1710|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_02:
 1694|   107k|libcrux_sha3_simd_portable__vxarq_u64_02(uint64_t a, uint64_t b) {
 1695|   107k|  return libcrux_sha3_simd_portable_rotate_left_02(a ^ b);
 1696|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_02:
 1683|   107k|libcrux_sha3_simd_portable_rotate_left_02(uint64_t x) {
 1684|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)36);
 1685|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_ac:
 1744|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_ac(uint64_t a, uint64_t b) {
 1745|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_ac(a, b);
 1746|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_ac:
 1730|   107k|libcrux_sha3_simd_portable__vxarq_u64_ac(uint64_t a, uint64_t b) {
 1731|   107k|  return libcrux_sha3_simd_portable_rotate_left_ac(a ^ b);
 1732|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_ac:
 1719|   107k|libcrux_sha3_simd_portable_rotate_left_ac(uint64_t x) {
 1720|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)3);
 1721|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_020:
 1780|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_020(uint64_t a, uint64_t b) {
 1781|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_020(a, b);
 1782|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_020:
 1766|   107k|libcrux_sha3_simd_portable__vxarq_u64_020(uint64_t a, uint64_t b) {
 1767|   107k|  return libcrux_sha3_simd_portable_rotate_left_020(a ^ b);
 1768|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_020:
 1755|   107k|libcrux_sha3_simd_portable_rotate_left_020(uint64_t x) {
 1756|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)41);
 1757|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_a9:
 1816|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_a9(uint64_t a, uint64_t b) {
 1817|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_a9(a, b);
 1818|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_a9:
 1802|   107k|libcrux_sha3_simd_portable__vxarq_u64_a9(uint64_t a, uint64_t b) {
 1803|   107k|  return libcrux_sha3_simd_portable_rotate_left_a9(a ^ b);
 1804|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_a9:
 1791|   107k|libcrux_sha3_simd_portable_rotate_left_a9(uint64_t x) {
 1792|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)18);
 1793|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_76:
 1841|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_76(uint64_t a, uint64_t b) {
 1842|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_76(a, b);
 1843|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_76:
 1827|   107k|libcrux_sha3_simd_portable__vxarq_u64_76(uint64_t a, uint64_t b) {
 1828|   107k|  return libcrux_sha3_simd_portable_rotate_left_76(a ^ b);
 1829|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_58:
 1877|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_58(uint64_t a, uint64_t b) {
 1878|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_58(a, b);
 1879|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_58:
 1863|   107k|libcrux_sha3_simd_portable__vxarq_u64_58(uint64_t a, uint64_t b) {
 1864|   107k|  return libcrux_sha3_simd_portable_rotate_left_58(a ^ b);
 1865|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_58:
 1852|   107k|libcrux_sha3_simd_portable_rotate_left_58(uint64_t x) {
 1853|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)44);
 1854|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_e0:
 1913|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_e0(uint64_t a, uint64_t b) {
 1914|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_e0(a, b);
 1915|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_e0:
 1899|   107k|libcrux_sha3_simd_portable__vxarq_u64_e0(uint64_t a, uint64_t b) {
 1900|   107k|  return libcrux_sha3_simd_portable_rotate_left_e0(a ^ b);
 1901|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_e0:
 1888|   107k|libcrux_sha3_simd_portable_rotate_left_e0(uint64_t x) {
 1889|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)10);
 1890|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_63:
 1949|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_63(uint64_t a, uint64_t b) {
 1950|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_63(a, b);
 1951|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_63:
 1935|   107k|libcrux_sha3_simd_portable__vxarq_u64_63(uint64_t a, uint64_t b) {
 1936|   107k|  return libcrux_sha3_simd_portable_rotate_left_63(a ^ b);
 1937|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_63:
 1924|   107k|libcrux_sha3_simd_portable_rotate_left_63(uint64_t x) {
 1925|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)45);
 1926|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_6a:
 1985|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_6a(uint64_t a, uint64_t b) {
 1986|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_6a(a, b);
 1987|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_6a:
 1971|   107k|libcrux_sha3_simd_portable__vxarq_u64_6a(uint64_t a, uint64_t b) {
 1972|   107k|  return libcrux_sha3_simd_portable_rotate_left_6a(a ^ b);
 1973|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_6a:
 1960|   107k|libcrux_sha3_simd_portable_rotate_left_6a(uint64_t x) {
 1961|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)2);
 1962|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_ab:
 2021|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_ab(uint64_t a, uint64_t b) {
 2022|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_ab(a, b);
 2023|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_ab:
 2007|   107k|libcrux_sha3_simd_portable__vxarq_u64_ab(uint64_t a, uint64_t b) {
 2008|   107k|  return libcrux_sha3_simd_portable_rotate_left_ab(a ^ b);
 2009|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_ab:
 1996|   107k|libcrux_sha3_simd_portable_rotate_left_ab(uint64_t x) {
 1997|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)62);
 1998|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_5b:
 2057|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_5b(uint64_t a, uint64_t b) {
 2058|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_5b(a, b);
 2059|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_5b:
 2043|   107k|libcrux_sha3_simd_portable__vxarq_u64_5b(uint64_t a, uint64_t b) {
 2044|   107k|  return libcrux_sha3_simd_portable_rotate_left_5b(a ^ b);
 2045|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_5b:
 2032|   107k|libcrux_sha3_simd_portable_rotate_left_5b(uint64_t x) {
 2033|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)6);
 2034|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_6f:
 2093|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_6f(uint64_t a, uint64_t b) {
 2094|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_6f(a, b);
 2095|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_6f:
 2079|   107k|libcrux_sha3_simd_portable__vxarq_u64_6f(uint64_t a, uint64_t b) {
 2080|   107k|  return libcrux_sha3_simd_portable_rotate_left_6f(a ^ b);
 2081|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_6f:
 2068|   107k|libcrux_sha3_simd_portable_rotate_left_6f(uint64_t x) {
 2069|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)43);
 2070|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_62:
 2129|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_62(uint64_t a, uint64_t b) {
 2130|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_62(a, b);
 2131|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_62:
 2115|   107k|libcrux_sha3_simd_portable__vxarq_u64_62(uint64_t a, uint64_t b) {
 2116|   107k|  return libcrux_sha3_simd_portable_rotate_left_62(a ^ b);
 2117|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_62:
 2104|   107k|libcrux_sha3_simd_portable_rotate_left_62(uint64_t x) {
 2105|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)15);
 2106|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_23:
 2165|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_23(uint64_t a, uint64_t b) {
 2166|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_23(a, b);
 2167|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_23:
 2151|   107k|libcrux_sha3_simd_portable__vxarq_u64_23(uint64_t a, uint64_t b) {
 2152|   107k|  return libcrux_sha3_simd_portable_rotate_left_23(a ^ b);
 2153|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_23:
 2140|   107k|libcrux_sha3_simd_portable_rotate_left_23(uint64_t x) {
 2141|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)61);
 2142|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_37:
 2201|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_37(uint64_t a, uint64_t b) {
 2202|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_37(a, b);
 2203|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_37:
 2187|   107k|libcrux_sha3_simd_portable__vxarq_u64_37(uint64_t a, uint64_t b) {
 2188|   107k|  return libcrux_sha3_simd_portable_rotate_left_37(a ^ b);
 2189|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_37:
 2176|   107k|libcrux_sha3_simd_portable_rotate_left_37(uint64_t x) {
 2177|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)28);
 2178|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_bb:
 2237|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_bb(uint64_t a, uint64_t b) {
 2238|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_bb(a, b);
 2239|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_bb:
 2223|   107k|libcrux_sha3_simd_portable__vxarq_u64_bb(uint64_t a, uint64_t b) {
 2224|   107k|  return libcrux_sha3_simd_portable_rotate_left_bb(a ^ b);
 2225|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_bb:
 2212|   107k|libcrux_sha3_simd_portable_rotate_left_bb(uint64_t x) {
 2213|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)55);
 2214|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_b9:
 2273|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_b9(uint64_t a, uint64_t b) {
 2274|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_b9(a, b);
 2275|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_b9:
 2259|   107k|libcrux_sha3_simd_portable__vxarq_u64_b9(uint64_t a, uint64_t b) {
 2260|   107k|  return libcrux_sha3_simd_portable_rotate_left_b9(a ^ b);
 2261|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_b9:
 2248|   107k|libcrux_sha3_simd_portable_rotate_left_b9(uint64_t x) {
 2249|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)25);
 2250|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_54:
 2309|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_54(uint64_t a, uint64_t b) {
 2310|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_54(a, b);
 2311|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_54:
 2295|   107k|libcrux_sha3_simd_portable__vxarq_u64_54(uint64_t a, uint64_t b) {
 2296|   107k|  return libcrux_sha3_simd_portable_rotate_left_54(a ^ b);
 2297|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_54:
 2284|   107k|libcrux_sha3_simd_portable_rotate_left_54(uint64_t x) {
 2285|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)21);
 2286|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_4c:
 2345|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_4c(uint64_t a, uint64_t b) {
 2346|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_4c(a, b);
 2347|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_4c:
 2331|   107k|libcrux_sha3_simd_portable__vxarq_u64_4c(uint64_t a, uint64_t b) {
 2332|   107k|  return libcrux_sha3_simd_portable_rotate_left_4c(a ^ b);
 2333|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_4c:
 2320|   107k|libcrux_sha3_simd_portable_rotate_left_4c(uint64_t x) {
 2321|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)56);
 2322|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_ce:
 2381|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_ce(uint64_t a, uint64_t b) {
 2382|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_ce(a, b);
 2383|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_ce:
 2367|   107k|libcrux_sha3_simd_portable__vxarq_u64_ce(uint64_t a, uint64_t b) {
 2368|   107k|  return libcrux_sha3_simd_portable_rotate_left_ce(a ^ b);
 2369|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_ce:
 2356|   107k|libcrux_sha3_simd_portable_rotate_left_ce(uint64_t x) {
 2357|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)27);
 2358|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_77:
 2417|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_77(uint64_t a, uint64_t b) {
 2418|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_77(a, b);
 2419|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_77:
 2403|   107k|libcrux_sha3_simd_portable__vxarq_u64_77(uint64_t a, uint64_t b) {
 2404|   107k|  return libcrux_sha3_simd_portable_rotate_left_77(a ^ b);
 2405|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_77:
 2392|   107k|libcrux_sha3_simd_portable_rotate_left_77(uint64_t x) {
 2393|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)20);
 2394|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_25:
 2453|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_25(uint64_t a, uint64_t b) {
 2454|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_25(a, b);
 2455|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_25:
 2439|   107k|libcrux_sha3_simd_portable__vxarq_u64_25(uint64_t a, uint64_t b) {
 2440|   107k|  return libcrux_sha3_simd_portable_rotate_left_25(a ^ b);
 2441|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_25:
 2428|   107k|libcrux_sha3_simd_portable_rotate_left_25(uint64_t x) {
 2429|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)39);
 2430|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_af:
 2489|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_af(uint64_t a, uint64_t b) {
 2490|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_af(a, b);
 2491|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_af:
 2475|   107k|libcrux_sha3_simd_portable__vxarq_u64_af(uint64_t a, uint64_t b) {
 2476|   107k|  return libcrux_sha3_simd_portable_rotate_left_af(a ^ b);
 2477|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_af:
 2464|   107k|libcrux_sha3_simd_portable_rotate_left_af(uint64_t x) {
 2465|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)8);
 2466|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_and_rotate_d2_fd:
 2525|   107k|libcrux_sha3_simd_portable_xor_and_rotate_d2_fd(uint64_t a, uint64_t b) {
 2526|   107k|  return libcrux_sha3_simd_portable__vxarq_u64_fd(a, b);
 2527|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vxarq_u64_fd:
 2511|   107k|libcrux_sha3_simd_portable__vxarq_u64_fd(uint64_t a, uint64_t b) {
 2512|   107k|  return libcrux_sha3_simd_portable_rotate_left_fd(a ^ b);
 2513|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_rotate_left_fd:
 2500|   107k|libcrux_sha3_simd_portable_rotate_left_fd(uint64_t x) {
 2501|   107k|  return core_num__u64__rotate_left(x, (uint32_t)(int32_t)14);
 2502|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_pi_80_04:
 2753|   107k|    libcrux_sha3_generic_keccak_KeccakState_17 *self) {
 2754|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 old = self[0U];
 2755|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2756|   107k|      self, (size_t)1U, (size_t)0U,
 2757|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2758|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2759|   107k|                                          .snd = (size_t)3U}))[0U]);
 2760|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2761|   107k|      self, (size_t)2U, (size_t)0U,
 2762|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2763|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2764|   107k|                                          .snd = (size_t)1U}))[0U]);
 2765|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2766|   107k|      self, (size_t)3U, (size_t)0U,
 2767|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2768|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2769|   107k|                                          .snd = (size_t)4U}))[0U]);
 2770|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2771|   107k|      self, (size_t)4U, (size_t)0U,
 2772|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2773|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2774|   107k|                                          .snd = (size_t)2U}))[0U]);
 2775|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2776|   107k|      self, (size_t)0U, (size_t)1U,
 2777|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2778|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2779|   107k|                                          .snd = (size_t)1U}))[0U]);
 2780|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2781|   107k|      self, (size_t)1U, (size_t)1U,
 2782|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2783|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2784|   107k|                                          .snd = (size_t)4U}))[0U]);
 2785|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2786|   107k|      self, (size_t)2U, (size_t)1U,
 2787|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2788|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2789|   107k|                                          .snd = (size_t)2U}))[0U]);
 2790|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2791|   107k|      self, (size_t)3U, (size_t)1U,
 2792|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2793|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2794|   107k|                                          .snd = (size_t)0U}))[0U]);
 2795|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2796|   107k|      self, (size_t)4U, (size_t)1U,
 2797|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2798|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)1U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2799|   107k|                                          .snd = (size_t)3U}))[0U]);
 2800|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2801|   107k|      self, (size_t)0U, (size_t)2U,
 2802|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2803|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2804|   107k|                                          .snd = (size_t)2U}))[0U]);
 2805|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2806|   107k|      self, (size_t)1U, (size_t)2U,
 2807|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2808|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2809|   107k|                                          .snd = (size_t)0U}))[0U]);
 2810|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2811|   107k|      self, (size_t)2U, (size_t)2U,
 2812|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2813|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2814|   107k|                                          .snd = (size_t)3U}))[0U]);
 2815|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2816|   107k|      self, (size_t)3U, (size_t)2U,
 2817|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2818|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2819|   107k|                                          .snd = (size_t)1U}))[0U]);
 2820|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2821|   107k|      self, (size_t)4U, (size_t)2U,
 2822|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2823|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)2U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2824|   107k|                                          .snd = (size_t)4U}))[0U]);
 2825|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2826|   107k|      self, (size_t)0U, (size_t)3U,
 2827|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2828|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2829|   107k|                                          .snd = (size_t)3U}))[0U]);
 2830|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2831|   107k|      self, (size_t)1U, (size_t)3U,
 2832|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2833|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2834|   107k|                                          .snd = (size_t)1U}))[0U]);
 2835|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2836|   107k|      self, (size_t)2U, (size_t)3U,
 2837|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2838|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2839|   107k|                                          .snd = (size_t)4U}))[0U]);
 2840|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2841|   107k|      self, (size_t)3U, (size_t)3U,
 2842|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2843|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2844|   107k|                                          .snd = (size_t)2U}))[0U]);
 2845|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2846|   107k|      self, (size_t)4U, (size_t)3U,
 2847|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2848|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)3U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2849|   107k|                                          .snd = (size_t)0U}))[0U]);
 2850|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2851|   107k|      self, (size_t)0U, (size_t)4U,
 2852|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2853|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2854|   107k|                                          .snd = (size_t)4U}))[0U]);
 2855|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2856|   107k|      self, (size_t)1U, (size_t)4U,
 2857|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2858|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2859|   107k|                                          .snd = (size_t)2U}))[0U]);
 2860|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2861|   107k|      self, (size_t)2U, (size_t)4U,
 2862|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2863|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2864|   107k|                                          .snd = (size_t)0U}))[0U]);
 2865|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2866|   107k|      self, (size_t)3U, (size_t)4U,
 2867|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2868|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2869|   107k|                                          .snd = (size_t)3U}))[0U]);
 2870|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2871|   107k|      self, (size_t)4U, (size_t)4U,
 2872|   107k|      libcrux_sha3_generic_keccak_index_c2_04(
 2873|   107k|          &old, (KRML_CLITERAL(size_t_x2){.fst = (size_t)4U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2874|   107k|                                          .snd = (size_t)1U}))[0U]);
 2875|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_chi_80_04:
 2888|   107k|    libcrux_sha3_generic_keccak_KeccakState_17 *self) {
 2889|   107k|  libcrux_sha3_generic_keccak_KeccakState_17 old = self[0U];
 2890|   645k|  for (size_t i0 = (size_t)0U; i0 < (size_t)5U; i0++) {
  ------------------
  |  Branch (2890:32): [True: 537k, False: 107k]
  ------------------
 2891|   537k|    size_t i1 = i0;
 2892|  3.22M|    for (size_t i = (size_t)0U; i < (size_t)5U; i++) {
  ------------------
  |  Branch (2892:33): [True: 2.68M, False: 537k]
  ------------------
 2893|  2.68M|      size_t j = i;
 2894|  2.68M|      libcrux_sha3_generic_keccak_set_80_04(
 2895|  2.68M|          self, i1, j,
 2896|  2.68M|          libcrux_sha3_simd_portable_and_not_xor_d2(
 2897|  2.68M|              libcrux_sha3_generic_keccak_index_c2_04(
 2898|  2.68M|                  self, (KRML_CLITERAL(size_t_x2){.fst = i1, .snd = j}))[0U],
  ------------------
  |  |  154|  2.68M|#define KRML_CLITERAL(type) (type)
  ------------------
 2899|  2.68M|              libcrux_sha3_generic_keccak_index_c2_04(
 2900|  2.68M|                  &old,
 2901|  2.68M|                  (KRML_CLITERAL(size_t_x2){
  ------------------
  |  |  154|  2.68M|#define KRML_CLITERAL(type) (type)
  ------------------
 2902|  2.68M|                      .fst = i1, .snd = (j + (size_t)2U) % (size_t)5U}))[0U],
 2903|  2.68M|              libcrux_sha3_generic_keccak_index_c2_04(
 2904|  2.68M|                  &old,
 2905|  2.68M|                  (KRML_CLITERAL(size_t_x2){
  ------------------
  |  |  154|  2.68M|#define KRML_CLITERAL(type) (type)
  ------------------
 2906|  2.68M|                      .fst = i1, .snd = (j + (size_t)1U) % (size_t)5U}))[0U]));
 2907|  2.68M|    }
 2908|   537k|  }
 2909|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_and_not_xor_d2:
 1371|  2.68M|libcrux_sha3_simd_portable_and_not_xor_d2(uint64_t a, uint64_t b, uint64_t c) {
 1372|  2.68M|  return libcrux_sha3_simd_portable__vbcaxq_u64(a, b, c);
 1373|  2.68M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__vbcaxq_u64:
 1363|  2.68M|libcrux_sha3_simd_portable__vbcaxq_u64(uint64_t a, uint64_t b, uint64_t c) {
 1364|  2.68M|  return a ^ (b & ~c);
 1365|  2.68M|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_iota_80_04:
 2922|   107k|    libcrux_sha3_generic_keccak_KeccakState_17 *self, size_t i) {
 2923|   107k|  libcrux_sha3_generic_keccak_set_80_04(
 2924|   107k|      self, (size_t)0U, (size_t)0U,
 2925|   107k|      libcrux_sha3_simd_portable_xor_constant_d2(
 2926|   107k|          libcrux_sha3_generic_keccak_index_c2_04(
 2927|   107k|              self, (KRML_CLITERAL(size_t_x2){.fst = (size_t)0U,
  ------------------
  |  |  154|   107k|#define KRML_CLITERAL(type) (type)
  ------------------
 2928|   107k|                                              .snd = (size_t)0U}))[0U],
 2929|   107k|          libcrux_sha3_generic_keccak_constants_ROUNDCONSTANTS[i]));
 2930|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_xor_constant_d2:
 1384|   107k|libcrux_sha3_simd_portable_xor_constant_d2(uint64_t a, uint64_t c) {
 1385|   107k|  return libcrux_sha3_simd_portable__veorq_n_u64(a, c);
 1386|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable__veorq_n_u64:
 1376|   107k|libcrux_sha3_simd_portable__veorq_n_u64(uint64_t a, uint64_t c) {
 1377|   107k|  return a ^ c;
 1378|   107k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_shake256:
 3455|    624|    Eurydice_slice digest, Eurydice_slice data) {
 3456|    624|  libcrux_sha3_generic_keccak_portable_keccak1_ad0(data, digest);
 3457|    624|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_keccak1_ad0:
 3419|    624|    Eurydice_slice data, Eurydice_slice out) {
 3420|    624|  libcrux_sha3_generic_keccak_KeccakState_17 s =
 3421|    624|      libcrux_sha3_generic_keccak_new_80_04();
 3422|    624|  size_t data_len = Eurydice_slice_len(data, uint8_t);
  ------------------
  |  |  173|    624|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3423|    624|  for (size_t i = (size_t)0U; i < data_len / (size_t)136U; i++) {
  ------------------
  |  Branch (3423:31): [True: 0, False: 624]
  ------------------
 3424|      0|    size_t i0 = i;
 3425|      0|    Eurydice_slice buf[1U] = {data};
 3426|      0|    libcrux_sha3_generic_keccak_absorb_block_80_c60(&s, buf, i0 * (size_t)136U);
 3427|      0|  }
 3428|    624|  size_t rem = data_len % (size_t)136U;
 3429|    624|  Eurydice_slice buf[1U] = {data};
 3430|    624|  libcrux_sha3_generic_keccak_absorb_final_80_9e1(&s, buf, data_len - rem, rem);
 3431|    624|  size_t outlen = Eurydice_slice_len(out, uint8_t);
  ------------------
  |  |  173|    624|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3432|    624|  size_t blocks = outlen / (size_t)136U;
 3433|    624|  size_t last = outlen - outlen % (size_t)136U;
 3434|    624|  if (blocks == (size_t)0U) {
  ------------------
  |  Branch (3434:7): [True: 624, False: 0]
  ------------------
 3435|    624|    libcrux_sha3_simd_portable_squeeze_13_5b(&s, out, (size_t)0U, outlen);
 3436|    624|  } 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|    624|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_block_80_c60:
 3193|    832|    size_t start) {
 3194|    832|  libcrux_sha3_simd_portable_load_block_a1_5b(self, blocks, start);
 3195|    832|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3196|    832|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_block_a1_5b:
 3176|    832|    size_t start) {
 3177|    832|  libcrux_sha3_simd_portable_load_block_5b(self->st, input[0U], start);
 3178|    832|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_block_5b:
 3138|  1.56k|    uint64_t *state, Eurydice_slice blocks, size_t start) {
 3139|  1.56k|  uint64_t state_flat[25U] = {0U};
 3140|  28.0k|  for (size_t i = (size_t)0U; i < (size_t)136U / (size_t)8U; i++) {
  ------------------
  |  Branch (3140:31): [True: 26.5k, False: 1.56k]
  ------------------
 3141|  26.5k|    size_t i0 = i;
 3142|  26.5k|    size_t offset = start + (size_t)8U * i0;
 3143|  26.5k|    uint8_t uu____0[8U];
 3144|  26.5k|    Result_15 dst;
 3145|  26.5k|    Eurydice_slice_to_array2(
  ------------------
  |  |  277|  26.5k|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|  26.5k|                           sizeof(t_arr))
  ------------------
 3146|  26.5k|        &dst,
 3147|  26.5k|        Eurydice_slice_subslice3(blocks, offset, offset + (size_t)8U,
 3148|  26.5k|                                 uint8_t *),
 3149|  26.5k|        Eurydice_slice, uint8_t[8U], TryFromSliceError);
 3150|  26.5k|    unwrap_26_68(dst, uu____0);
 3151|  26.5k|    state_flat[i0] = core_num__u64__from_le_bytes(uu____0);
 3152|  26.5k|  }
 3153|  28.0k|  for (size_t i = (size_t)0U; i < (size_t)136U / (size_t)8U; i++) {
  ------------------
  |  Branch (3153:31): [True: 26.5k, False: 1.56k]
  ------------------
 3154|  26.5k|    size_t i0 = i;
 3155|  26.5k|    libcrux_sha3_traits_set_ij_04(
 3156|  26.5k|        state, i0 / (size_t)5U, i0 % (size_t)5U,
 3157|  26.5k|        libcrux_sha3_traits_get_ij_04(state, i0 / (size_t)5U,
 3158|  26.5k|                                      i0 % (size_t)5U)[0U] ^
 3159|  26.5k|            state_flat[i0]);
 3160|  26.5k|  }
 3161|  1.56k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_final_80_9e1:
 3407|    624|    size_t start, size_t len) {
 3408|    624|  libcrux_sha3_simd_portable_load_last_a1_ad0(self, last, start, len);
 3409|    624|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3410|    624|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_a1_ad0:
 3389|    624|    size_t start, size_t len) {
 3390|    624|  libcrux_sha3_simd_portable_load_last_ad0(self->st, input[0U], start, len);
 3391|    624|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_ad0:
 3362|    624|    uint64_t *state, Eurydice_slice blocks, size_t start, size_t len) {
 3363|    624|  uint8_t buffer[136U] = {0U};
 3364|    624|  Eurydice_slice_copy(
  ------------------
  |  |  229|    624|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3365|    624|      Eurydice_array_to_subslice3(buffer, (size_t)0U, len, uint8_t *),
 3366|    624|      Eurydice_slice_subslice3(blocks, start, start + len, uint8_t *), uint8_t);
 3367|    624|  buffer[len] = 31U;
 3368|    624|  size_t uu____0 = (size_t)136U - (size_t)1U;
 3369|    624|  buffer[uu____0] = (uint32_t)buffer[uu____0] | 128U;
 3370|    624|  libcrux_sha3_simd_portable_load_block_5b(
 3371|    624|      state, Eurydice_array_to_slice((size_t)136U, buffer, uint8_t),
  ------------------
  |  |  204|    624|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    624|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    624|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    624|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3372|    624|      (size_t)0U);
 3373|    624|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_squeeze_13_5b:
 3304|    728|    size_t start, size_t len) {
 3305|    728|  libcrux_sha3_simd_portable_store_block_5b(self->st, out, start, len);
 3306|    728|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_store_block_5b:
 3261|    728|    uint64_t *s, Eurydice_slice out, size_t start, size_t len) {
 3262|    728|  size_t octets = len / (size_t)8U;
 3263|  11.1k|  for (size_t i = (size_t)0U; i < octets; i++) {
  ------------------
  |  Branch (3263:31): [True: 10.4k, False: 728]
  ------------------
 3264|  10.4k|    size_t i0 = i;
 3265|  10.4k|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  10.4k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  10.4k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  10.4k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3266|  10.4k|        out, start + (size_t)8U * i0, start + (size_t)8U * i0 + (size_t)8U,
 3267|  10.4k|        uint8_t *);
 3268|  10.4k|    uint8_t ret[8U];
 3269|  10.4k|    core_num__u64__to_le_bytes(
 3270|  10.4k|        libcrux_sha3_traits_get_ij_04(s, i0 / (size_t)5U, i0 % (size_t)5U)[0U],
 3271|  10.4k|        ret);
 3272|  10.4k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  10.4k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3273|  10.4k|        uu____0, Eurydice_array_to_slice((size_t)8U, ret, uint8_t), uint8_t);
 3274|  10.4k|  }
 3275|    728|  size_t remaining = len % (size_t)8U;
 3276|    728|  if (remaining > (size_t)0U) {
  ------------------
  |  Branch (3276:7): [True: 0, False: 728]
  ------------------
 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|    728|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_unpacked_default_8b_1b:
 6354|    104|libcrux_ml_kem_ind_cpa_unpacked_default_8b_1b(void) {
 6355|    104|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0[3U];
 6356|    416|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6356:31): [True: 312, False: 104]
  ------------------
 6357|    312|    uu____0[i] = libcrux_ml_kem_polynomial_ZERO_d6_ea();
 6358|    312|  }
 6359|    104|  uint8_t uu____1[32U] = {0U};
 6360|    104|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0 lit;
 6361|    104|  memcpy(
 6362|    104|      lit.t_as_ntt, uu____0,
 6363|    104|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 6364|    104|  memcpy(lit.seed_for_A, uu____1, (size_t)32U * sizeof(uint8_t));
 6365|    104|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d repeat_expression0[3U][3U];
 6366|    416|  for (size_t i0 = (size_t)0U; i0 < (size_t)3U; i0++) {
  ------------------
  |  Branch (6366:32): [True: 312, False: 104]
  ------------------
 6367|    312|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d repeat_expression[3U];
 6368|  1.24k|    for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6368:33): [True: 936, False: 312]
  ------------------
 6369|    936|      repeat_expression[i] = libcrux_ml_kem_polynomial_ZERO_d6_ea();
 6370|    936|    }
 6371|    312|    memcpy(repeat_expression0[i0], repeat_expression,
 6372|    312|           (size_t)3U *
 6373|    312|               sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 6374|    312|  }
 6375|    104|  memcpy(lit.A, repeat_expression0,
 6376|    104|         (size_t)3U *
 6377|    104|             sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]));
 6378|    104|  return lit;
 6379|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_into_padded_array_b6:
  903|    104|    Eurydice_slice slice, uint8_t ret[34U]) {
  904|    104|  uint8_t out[34U] = {0U};
  905|    104|  uint8_t *uu____0 = out;
  906|    104|  Eurydice_slice_copy(
  ------------------
  |  |  229|    104|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
  907|    104|      Eurydice_array_to_subslice3(
  908|    104|          uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *),
  909|    104|      slice, uint8_t);
  910|    104|  memcpy(ret, out, (size_t)34U * sizeof(uint8_t));
  911|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_sample_matrix_A_2b:
 6854|    104|    uint8_t *seed, bool transpose) {
 6855|    416|  for (size_t i0 = (size_t)0U; i0 < (size_t)3U; i0++) {
  ------------------
  |  Branch (6855:32): [True: 312, False: 104]
  ------------------
 6856|    312|    size_t i1 = i0;
 6857|    312|    uint8_t seeds[3U][34U];
 6858|  1.24k|    for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6858:33): [True: 936, False: 312]
  ------------------
 6859|    936|      core_array__core__clone__Clone_for__Array_T__N___clone(
  ------------------
  |  |  236|    936|  (memcpy(dst, src, len * sizeof(elem_type)))
  ------------------
 6860|    936|          (size_t)34U, seed, seeds[i], uint8_t, void *);
 6861|    936|    }
 6862|  1.24k|    for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6862:33): [True: 936, False: 312]
  ------------------
 6863|    936|      size_t j = i;
 6864|    936|      seeds[j][32U] = (uint8_t)i1;
 6865|    936|      seeds[j][33U] = (uint8_t)j;
 6866|    936|    }
 6867|    312|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d sampled[3U];
 6868|    312|    libcrux_ml_kem_sampling_sample_from_xof_2b(seeds, sampled);
 6869|    312|    for (size_t i = (size_t)0U;
 6870|  1.24k|         i < Eurydice_slice_len(
  ------------------
  |  |  173|  1.24k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (6870:10): [True: 936, False: 312]
  ------------------
 6871|    312|                 Eurydice_array_to_slice(
 6872|    312|                     (size_t)3U, sampled,
 6873|    312|                     libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 6874|    312|                 libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 6875|    936|         i++) {
 6876|    936|      size_t j = i;
 6877|    936|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d sample = sampled[j];
 6878|    936|      if (transpose) {
  ------------------
  |  Branch (6878:11): [True: 936, False: 0]
  ------------------
 6879|    936|        A_transpose[j][i1] = sample;
 6880|    936|      } else {
 6881|      0|        A_transpose[i1][j] = sample;
 6882|      0|      }
 6883|    936|    }
 6884|    312|  }
 6885|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_xof_2b:
 6808|    312|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret[3U]) {
 6809|    312|  size_t sampled_coefficients[3U] = {0U};
 6810|    312|  int16_t out[3U][272U] = {{0U}};
 6811|    312|  libcrux_ml_kem_hash_functions_portable_PortableHash_88 xof_state =
 6812|    312|      libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_4a_e0(
 6813|    312|          seeds);
 6814|    312|  uint8_t randomness0[3U][504U];
 6815|    312|  libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_4a_e0(
 6816|    312|      &xof_state, randomness0);
 6817|    312|  bool done = libcrux_ml_kem_sampling_sample_from_uniform_distribution_next_89(
 6818|    312|      randomness0, sampled_coefficients, out);
 6819|    315|  while (true) {
  ------------------
  |  Branch (6819:10): [True: 315, Folded]
  ------------------
 6820|    315|    if (done) {
  ------------------
  |  Branch (6820:9): [True: 312, False: 3]
  ------------------
 6821|    312|      break;
 6822|    312|    } else {
 6823|      3|      uint8_t randomness[3U][168U];
 6824|      3|      libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_4a_e0(
 6825|      3|          &xof_state, randomness);
 6826|      3|      done = libcrux_ml_kem_sampling_sample_from_uniform_distribution_next_890(
 6827|      3|          randomness, sampled_coefficients, out);
 6828|      3|    }
 6829|    315|  }
 6830|       |  /* Passing arrays by value in Rust generates a copy in C */
 6831|    312|  int16_t copy_of_out[3U][272U];
 6832|    312|  memcpy(copy_of_out, out, (size_t)3U * sizeof(int16_t[272U]));
 6833|    312|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d ret0[3U];
 6834|  1.24k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6834:31): [True: 936, False: 312]
  ------------------
 6835|       |    /* original Rust expression is not an lvalue in C */
 6836|    936|    void *lvalue = (void *)0U;
 6837|    936|    ret0[i] = libcrux_ml_kem_sampling_sample_from_xof_call_mut_e7_2b(
 6838|    936|        &lvalue, copy_of_out[i]);
 6839|    936|  }
 6840|    312|  memcpy(
 6841|    312|      ret, ret0,
 6842|    312|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 6843|    312|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_4a_e0:
 6489|    312|    uint8_t (*input)[34U]) {
 6490|    312|  return libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_e0(
 6491|    312|      input);
 6492|    312|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_init_absorb_final_e0:
 6460|    312|    uint8_t (*input)[34U]) {
 6461|    312|  libcrux_ml_kem_hash_functions_portable_PortableHash_88 shake128_state;
 6462|    312|  libcrux_sha3_generic_keccak_KeccakState_17 repeat_expression[3U];
 6463|  1.24k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6463:31): [True: 936, False: 312]
  ------------------
 6464|    936|    repeat_expression[i] = libcrux_sha3_portable_incremental_shake128_init();
 6465|    936|  }
 6466|    312|  memcpy(shake128_state.shake128_state, repeat_expression,
 6467|    312|         (size_t)3U * sizeof(libcrux_sha3_generic_keccak_KeccakState_17));
 6468|  1.24k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6468:31): [True: 936, False: 312]
  ------------------
 6469|    936|    size_t i0 = i;
 6470|    936|    libcrux_sha3_portable_incremental_shake128_absorb_final(
 6471|    936|        &shake128_state.shake128_state[i0],
 6472|    936|        Eurydice_array_to_slice((size_t)34U, input[i0], uint8_t));
  ------------------
  |  |  204|    936|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    936|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    936|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    936|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6473|    936|  }
 6474|    312|  return shake128_state;
 6475|    312|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_incremental_shake128_init:
 3466|    936|libcrux_sha3_portable_incremental_shake128_init(void) {
 3467|    936|  return libcrux_sha3_generic_keccak_new_80_04();
 3468|    936|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_incremental_shake128_absorb_final:
 3563|    936|    libcrux_sha3_generic_keccak_KeccakState_17 *s, Eurydice_slice data0) {
 3564|    936|  libcrux_sha3_generic_keccak_KeccakState_17 *uu____0 = s;
 3565|    936|  Eurydice_slice uu____1[1U] = {data0};
 3566|    936|  libcrux_sha3_generic_keccak_absorb_final_80_9e2(
 3567|    936|      uu____0, uu____1, (size_t)0U, Eurydice_slice_len(data0, uint8_t));
  ------------------
  |  |  173|    936|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3568|    936|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_final_80_9e2:
 3553|    936|    size_t start, size_t len) {
 3554|    936|  libcrux_sha3_simd_portable_load_last_a1_c6(self, last, start, len);
 3555|    936|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3556|    936|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_a1_c6:
 3535|    936|    size_t start, size_t len) {
 3536|    936|  libcrux_sha3_simd_portable_load_last_c6(self->st, input[0U], start, len);
 3537|    936|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_c6:
 3508|    936|    uint64_t *state, Eurydice_slice blocks, size_t start, size_t len) {
 3509|    936|  uint8_t buffer[168U] = {0U};
 3510|    936|  Eurydice_slice_copy(
  ------------------
  |  |  229|    936|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3511|    936|      Eurydice_array_to_subslice3(buffer, (size_t)0U, len, uint8_t *),
 3512|    936|      Eurydice_slice_subslice3(blocks, start, start + len, uint8_t *), uint8_t);
 3513|    936|  buffer[len] = 31U;
 3514|    936|  size_t uu____0 = (size_t)168U - (size_t)1U;
 3515|    936|  buffer[uu____0] = (uint32_t)buffer[uu____0] | 128U;
 3516|    936|  libcrux_sha3_simd_portable_load_block_3a(
 3517|    936|      state, Eurydice_array_to_slice((size_t)168U, buffer, uint8_t),
  ------------------
  |  |  204|    936|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    936|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    936|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    936|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3518|    936|      (size_t)0U);
 3519|    936|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_block_3a:
 3476|    936|    uint64_t *state, Eurydice_slice blocks, size_t start) {
 3477|    936|  uint64_t state_flat[25U] = {0U};
 3478|  20.5k|  for (size_t i = (size_t)0U; i < (size_t)168U / (size_t)8U; i++) {
  ------------------
  |  Branch (3478:31): [True: 19.6k, False: 936]
  ------------------
 3479|  19.6k|    size_t i0 = i;
 3480|  19.6k|    size_t offset = start + (size_t)8U * i0;
 3481|  19.6k|    uint8_t uu____0[8U];
 3482|  19.6k|    Result_15 dst;
 3483|  19.6k|    Eurydice_slice_to_array2(
  ------------------
  |  |  277|  19.6k|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|  19.6k|                           sizeof(t_arr))
  ------------------
 3484|  19.6k|        &dst,
 3485|  19.6k|        Eurydice_slice_subslice3(blocks, offset, offset + (size_t)8U,
 3486|  19.6k|                                 uint8_t *),
 3487|  19.6k|        Eurydice_slice, uint8_t[8U], TryFromSliceError);
 3488|  19.6k|    unwrap_26_68(dst, uu____0);
 3489|  19.6k|    state_flat[i0] = core_num__u64__from_le_bytes(uu____0);
 3490|  19.6k|  }
 3491|  20.5k|  for (size_t i = (size_t)0U; i < (size_t)168U / (size_t)8U; i++) {
  ------------------
  |  Branch (3491:31): [True: 19.6k, False: 936]
  ------------------
 3492|  19.6k|    size_t i0 = i;
 3493|  19.6k|    libcrux_sha3_traits_set_ij_04(
 3494|  19.6k|        state, i0 / (size_t)5U, i0 % (size_t)5U,
 3495|  19.6k|        libcrux_sha3_traits_get_ij_04(state, i0 / (size_t)5U,
 3496|  19.6k|                                      i0 % (size_t)5U)[0U] ^
 3497|  19.6k|            state_flat[i0]);
 3498|  19.6k|  }
 3499|    936|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_4a_e0:
 6527|    312|    uint8_t ret[3U][504U]) {
 6528|    312|  libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_e0(
 6529|    312|      self, ret);
 6530|    312|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_squeeze_first_three_blocks_e0:
 6503|    312|    uint8_t ret[3U][504U]) {
 6504|    312|  uint8_t out[3U][504U] = {{0U}};
 6505|  1.24k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6505:31): [True: 936, False: 312]
  ------------------
 6506|    936|    size_t i0 = i;
 6507|    936|    libcrux_sha3_portable_incremental_shake128_squeeze_first_three_blocks(
 6508|    936|        &st->shake128_state[i0],
 6509|    936|        Eurydice_array_to_slice((size_t)504U, out[i0], uint8_t));
  ------------------
  |  |  204|    936|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    936|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    936|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    936|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6510|    936|  }
 6511|    312|  memcpy(ret, out, (size_t)3U * sizeof(uint8_t[504U]));
 6512|    312|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_incremental_shake128_squeeze_first_three_blocks:
 3652|    936|    libcrux_sha3_generic_keccak_KeccakState_17 *s, Eurydice_slice out0) {
 3653|    936|  libcrux_sha3_generic_keccak_portable_squeeze_first_three_blocks_b4_3a(s,
 3654|    936|                                                                        out0);
 3655|    936|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_squeeze_first_three_blocks_b4_3a:
 3637|    936|    libcrux_sha3_generic_keccak_KeccakState_17 *self, Eurydice_slice out) {
 3638|    936|  libcrux_sha3_simd_portable_squeeze_13_3a(self, out, (size_t)0U, (size_t)168U);
 3639|    936|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3640|    936|  libcrux_sha3_simd_portable_squeeze_13_3a(self, out, (size_t)168U,
 3641|    936|                                           (size_t)168U);
 3642|    936|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3643|    936|  libcrux_sha3_simd_portable_squeeze_13_3a(self, out, (size_t)2U * (size_t)168U,
 3644|    936|                                           (size_t)168U);
 3645|    936|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_squeeze_13_3a:
 3619|  2.81k|    size_t start, size_t len) {
 3620|  2.81k|  libcrux_sha3_simd_portable_store_block_3a(self->st, out, start, len);
 3621|  2.81k|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_store_block_3a:
 3576|  2.81k|    uint64_t *s, Eurydice_slice out, size_t start, size_t len) {
 3577|  2.81k|  size_t octets = len / (size_t)8U;
 3578|  61.9k|  for (size_t i = (size_t)0U; i < octets; i++) {
  ------------------
  |  Branch (3578:31): [True: 59.1k, False: 2.81k]
  ------------------
 3579|  59.1k|    size_t i0 = i;
 3580|  59.1k|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  59.1k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  59.1k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  59.1k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3581|  59.1k|        out, start + (size_t)8U * i0, start + (size_t)8U * i0 + (size_t)8U,
 3582|  59.1k|        uint8_t *);
 3583|  59.1k|    uint8_t ret[8U];
 3584|  59.1k|    core_num__u64__to_le_bytes(
 3585|  59.1k|        libcrux_sha3_traits_get_ij_04(s, i0 / (size_t)5U, i0 % (size_t)5U)[0U],
 3586|  59.1k|        ret);
 3587|  59.1k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  59.1k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3588|  59.1k|        uu____0, Eurydice_array_to_slice((size_t)8U, ret, uint8_t), uint8_t);
 3589|  59.1k|  }
 3590|  2.81k|  size_t remaining = len % (size_t)8U;
 3591|  2.81k|  if (remaining > (size_t)0U) {
  ------------------
  |  Branch (3591:7): [True: 0, False: 2.81k]
  ------------------
 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|  2.81k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_uniform_distribution_next_89:
 6583|    312|    int16_t (*out)[272U]) {
 6584|  1.24k|  for (size_t i0 = (size_t)0U; i0 < (size_t)3U; i0++) {
  ------------------
  |  Branch (6584:32): [True: 936, False: 312]
  ------------------
 6585|    936|    size_t i1 = i0;
 6586|  20.5k|    for (size_t i = (size_t)0U; i < (size_t)504U / (size_t)24U; i++) {
  ------------------
  |  Branch (6586:33): [True: 19.6k, False: 936]
  ------------------
 6587|  19.6k|      size_t r = i;
 6588|  19.6k|      if (sampled_coefficients[i1] <
  ------------------
  |  Branch (6588:11): [True: 18.8k, False: 836]
  ------------------
 6589|  19.6k|          LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT) {
  ------------------
  |  |  447|  19.6k|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6590|  18.8k|        size_t sampled = libcrux_ml_kem_vector_portable_rej_sample_b8(
 6591|  18.8k|            Eurydice_array_to_subslice3(randomness[i1], r * (size_t)24U,
  ------------------
  |  |  215|  18.8k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  18.8k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  18.8k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6592|  18.8k|                                        r * (size_t)24U + (size_t)24U,
 6593|  18.8k|                                        uint8_t *),
 6594|  18.8k|            Eurydice_array_to_subslice3(out[i1], sampled_coefficients[i1],
  ------------------
  |  |  215|  18.8k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  18.8k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  18.8k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6595|  18.8k|                                        sampled_coefficients[i1] + (size_t)16U,
 6596|  18.8k|                                        int16_t *));
 6597|  18.8k|        size_t uu____0 = i1;
 6598|  18.8k|        sampled_coefficients[uu____0] = sampled_coefficients[uu____0] + sampled;
 6599|  18.8k|      }
 6600|  19.6k|    }
 6601|    936|  }
 6602|    312|  bool done = true;
 6603|  1.24k|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6603:31): [True: 936, False: 312]
  ------------------
 6604|    936|    size_t i0 = i;
 6605|    936|    if (sampled_coefficients[i0] >=
  ------------------
  |  Branch (6605:9): [True: 933, False: 3]
  ------------------
 6606|    936|        LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT) {
  ------------------
  |  |  447|    936|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6607|    933|      sampled_coefficients[i0] =
 6608|    933|          LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT;
  ------------------
  |  |  447|    933|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6609|    933|    } else {
 6610|       |      done = false;
 6611|      3|    }
 6612|    936|  }
 6613|    312|  return done;
 6614|    312|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_rej_sample_b8:
 5219|  18.8k|    Eurydice_slice a, Eurydice_slice out) {
 5220|  18.8k|  return libcrux_ml_kem_vector_portable_sampling_rej_sample(a, out);
 5221|  18.8k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_sampling_rej_sample:
 5185|  18.8k|                                                   Eurydice_slice result) {
 5186|  18.8k|  size_t sampled = (size_t)0U;
 5187|   169k|  for (size_t i = (size_t)0U; i < Eurydice_slice_len(a, uint8_t) / (size_t)3U;
  ------------------
  |  |  173|   169k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (5187:31): [True: 150k, False: 18.8k]
  ------------------
 5188|   150k|       i++) {
 5189|   150k|    size_t i0 = i;
 5190|   150k|    int16_t b1 = (int16_t)Eurydice_slice_index(a, i0 * (size_t)3U + (size_t)0U,
  ------------------
  |  |  180|   150k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5191|   150k|                                               uint8_t, uint8_t *);
 5192|   150k|    int16_t b2 = (int16_t)Eurydice_slice_index(a, i0 * (size_t)3U + (size_t)1U,
  ------------------
  |  |  180|   150k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5193|   150k|                                               uint8_t, uint8_t *);
 5194|   150k|    int16_t b3 = (int16_t)Eurydice_slice_index(a, i0 * (size_t)3U + (size_t)2U,
  ------------------
  |  |  180|   150k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5195|   150k|                                               uint8_t, uint8_t *);
 5196|   150k|    int16_t d1 = (b2 & (int16_t)15) << 8U | b1;
 5197|   150k|    int16_t d2 = b3 << 4U | b2 >> 4U;
 5198|   150k|    if (d1 < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS) {
  ------------------
  |  | 3777|   150k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
  |  Branch (5198:9): [True: 122k, False: 27.9k]
  ------------------
 5199|   122k|      if (sampled < (size_t)16U) {
  ------------------
  |  Branch (5199:11): [True: 122k, False: 0]
  ------------------
 5200|   122k|        Eurydice_slice_index(result, sampled, int16_t, int16_t *) = d1;
  ------------------
  |  |  180|   122k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5201|   122k|        sampled++;
 5202|   122k|      }
 5203|   122k|    }
 5204|   150k|    if (d2 < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS) {
  ------------------
  |  | 3777|   150k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_MODULUS ((int16_t)3329)
  ------------------
  |  Branch (5204:9): [True: 122k, False: 28.0k]
  ------------------
 5205|   122k|      if (sampled < (size_t)16U) {
  ------------------
  |  Branch (5205:11): [True: 122k, False: 0]
  ------------------
 5206|   122k|        Eurydice_slice_index(result, sampled, int16_t, int16_t *) = d2;
  ------------------
  |  |  180|   122k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5207|   122k|        sampled++;
 5208|   122k|      }
 5209|   122k|    }
 5210|   150k|  }
 5211|  18.8k|  return sampled;
 5212|  18.8k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_4a_e0:
 6649|      3|    uint8_t ret[3U][168U]) {
 6650|      3|  libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_e0(self,
 6651|      3|                                                                        ret);
 6652|      3|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_shake128_squeeze_next_block_e0:
 6625|      3|    uint8_t ret[3U][168U]) {
 6626|      3|  uint8_t out[3U][168U] = {{0U}};
 6627|     12|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6627:31): [True: 9, False: 3]
  ------------------
 6628|      9|    size_t i0 = i;
 6629|      9|    libcrux_sha3_portable_incremental_shake128_squeeze_next_block(
 6630|      9|        &st->shake128_state[i0],
 6631|      9|        Eurydice_array_to_slice((size_t)168U, out[i0], uint8_t));
  ------------------
  |  |  204|      9|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|      9|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|      9|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|      9|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6632|      9|  }
 6633|      3|  memcpy(ret, out, (size_t)3U * sizeof(uint8_t[168U]));
 6634|      3|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_incremental_shake128_squeeze_next_block:
 3681|      9|    libcrux_sha3_generic_keccak_KeccakState_17 *s, Eurydice_slice out0) {
 3682|      9|  libcrux_sha3_generic_keccak_portable_squeeze_next_block_b4_3a(s, out0,
 3683|      9|                                                                (size_t)0U);
 3684|      9|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_squeeze_next_block_b4_3a:
 3671|      9|    size_t start) {
 3672|      9|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3673|      9|  libcrux_sha3_simd_portable_squeeze_13_3a(self, out, start, (size_t)168U);
 3674|      9|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_uniform_distribution_next_890:
 6705|      3|    int16_t (*out)[272U]) {
 6706|     12|  for (size_t i0 = (size_t)0U; i0 < (size_t)3U; i0++) {
  ------------------
  |  Branch (6706:32): [True: 9, False: 3]
  ------------------
 6707|      9|    size_t i1 = i0;
 6708|     72|    for (size_t i = (size_t)0U; i < (size_t)168U / (size_t)24U; i++) {
  ------------------
  |  Branch (6708:33): [True: 63, False: 9]
  ------------------
 6709|     63|      size_t r = i;
 6710|     63|      if (sampled_coefficients[i1] <
  ------------------
  |  Branch (6710:11): [True: 3, False: 60]
  ------------------
 6711|     63|          LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT) {
  ------------------
  |  |  447|     63|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6712|      3|        size_t sampled = libcrux_ml_kem_vector_portable_rej_sample_b8(
 6713|      3|            Eurydice_array_to_subslice3(randomness[i1], r * (size_t)24U,
  ------------------
  |  |  215|      3|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|      3|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|      3|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6714|      3|                                        r * (size_t)24U + (size_t)24U,
 6715|      3|                                        uint8_t *),
 6716|      3|            Eurydice_array_to_subslice3(out[i1], sampled_coefficients[i1],
  ------------------
  |  |  215|      3|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|      3|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|      3|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6717|      3|                                        sampled_coefficients[i1] + (size_t)16U,
 6718|      3|                                        int16_t *));
 6719|      3|        size_t uu____0 = i1;
 6720|      3|        sampled_coefficients[uu____0] = sampled_coefficients[uu____0] + sampled;
 6721|      3|      }
 6722|     63|    }
 6723|      9|  }
 6724|      3|  bool done = true;
 6725|     12|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6725:31): [True: 9, False: 3]
  ------------------
 6726|      9|    size_t i0 = i;
 6727|      9|    if (sampled_coefficients[i0] >=
  ------------------
  |  Branch (6727:9): [True: 9, False: 0]
  ------------------
 6728|      9|        LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT) {
  ------------------
  |  |  447|      9|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6729|      9|      sampled_coefficients[i0] =
 6730|      9|          LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT;
  ------------------
  |  |  447|      9|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  ------------------
 6731|      9|    } else {
 6732|       |      done = false;
 6733|      0|    }
 6734|      9|  }
 6735|      3|  return done;
 6736|      3|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_xof_call_mut_e7_2b:
 6792|    936|    void **_, int16_t tupled_args[272U]) {
 6793|    936|  int16_t s[272U];
 6794|    936|  memcpy(s, tupled_args, (size_t)272U * sizeof(int16_t));
 6795|    936|  return libcrux_ml_kem_polynomial_from_i16_array_d6_ea(
 6796|    936|      Eurydice_array_to_subslice3(s, (size_t)0U, (size_t)256U, int16_t *));
  ------------------
  |  |  215|    936|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    936|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    936|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6797|    936|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_from_i16_array_d6_ea:
 6773|  1.56k|libcrux_ml_kem_polynomial_from_i16_array_d6_ea(Eurydice_slice a) {
 6774|  1.56k|  return libcrux_ml_kem_polynomial_from_i16_array_ea(a);
 6775|  1.56k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_from_i16_array_ea:
 6745|  1.56k|libcrux_ml_kem_polynomial_from_i16_array_ea(Eurydice_slice a) {
 6746|  1.56k|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d result =
 6747|  1.56k|      libcrux_ml_kem_polynomial_ZERO_ea();
 6748|  1.56k|  for (size_t i = (size_t)0U;
 6749|  26.5k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  26.5k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (6749:8): [True: 24.9k, False: 1.56k]
  ------------------
 6750|  24.9k|    size_t i0 = i;
 6751|  24.9k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____0 =
 6752|  24.9k|        libcrux_ml_kem_vector_portable_from_i16_array_b8(
 6753|  24.9k|            Eurydice_slice_subslice3(a, i0 * (size_t)16U,
  ------------------
  |  |  195|  24.9k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  24.9k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  24.9k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6754|  24.9k|                                     (i0 + (size_t)1U) * (size_t)16U,
 6755|  24.9k|                                     int16_t *));
 6756|  24.9k|    result.coefficients[i0] = uu____0;
 6757|  24.9k|  }
 6758|  1.56k|  return result;
 6759|  1.56k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_from_i16_array_b8:
 3805|  24.9k|libcrux_ml_kem_vector_portable_from_i16_array_b8(Eurydice_slice array) {
 3806|  24.9k|  return libcrux_ml_kem_vector_portable_vector_type_from_i16_array(
 3807|  24.9k|      libcrux_secrets_int_classify_public_classify_ref_9b_39(array));
 3808|  24.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_vector_type_from_i16_array:
 3788|  24.9k|    Eurydice_slice array) {
 3789|  24.9k|  libcrux_ml_kem_vector_portable_vector_type_PortableVector lit;
 3790|  24.9k|  int16_t ret[16U];
 3791|  24.9k|  Result_0a dst;
 3792|  24.9k|  Eurydice_slice_to_array2(
  ------------------
  |  |  277|  24.9k|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|  24.9k|                           sizeof(t_arr))
  ------------------
 3793|  24.9k|      &dst, Eurydice_slice_subslice3(array, (size_t)0U, (size_t)16U, int16_t *),
 3794|  24.9k|      Eurydice_slice, int16_t[16U], TryFromSliceError);
 3795|  24.9k|  unwrap_26_00(dst, ret);
 3796|  24.9k|  memcpy(lit.elements, ret, (size_t)16U * sizeof(int16_t));
 3797|  24.9k|  return lit;
 3798|  24.9k|}
libcrux_mlkem768_sha3.c:unwrap_26_00:
 1129|  24.9k|static inline void unwrap_26_00(Result_0a self, int16_t ret[16U]) {
 1130|  24.9k|  if (self.tag == Ok) {
  ------------------
  |  |  721|  24.9k|#define Ok 0
  ------------------
  |  Branch (1130:7): [True: 24.9k, False: 0]
  ------------------
 1131|  24.9k|    int16_t f0[16U];
 1132|  24.9k|    memcpy(f0, self.val.case_Ok, (size_t)16U * sizeof(int16_t));
 1133|  24.9k|    memcpy(ret, f0, (size_t)16U * sizeof(int16_t));
 1134|  24.9k|  } 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|  24.9k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_classify_public_classify_ref_9b_39:
 1103|  24.9k|libcrux_secrets_int_classify_public_classify_ref_9b_39(Eurydice_slice self) {
 1104|  24.9k|  return self;
 1105|  24.9k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_into_padded_array_c8:
  884|    104|    Eurydice_slice slice, uint8_t ret[33U]) {
  885|    104|  uint8_t out[33U] = {0U};
  886|    104|  uint8_t *uu____0 = out;
  887|    104|  Eurydice_slice_copy(
  ------------------
  |  |  229|    104|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
  888|    104|      Eurydice_array_to_subslice3(
  889|    104|          uu____0, (size_t)0U, Eurydice_slice_len(slice, uint8_t), uint8_t *),
  890|    104|      slice, uint8_t);
  891|    104|  memcpy(ret, out, (size_t)33U * sizeof(uint8_t));
  892|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_sample_vector_cbd_then_ntt_3b:
 7177|    208|    uint8_t *prf_input, uint8_t domain_separator) {
 7178|    208|  uint8_t prf_inputs[3U][33U];
 7179|    832|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7179:31): [True: 624, False: 208]
  ------------------
 7180|    624|    core_array__core__clone__Clone_for__Array_T__N___clone(
  ------------------
  |  |  236|    624|  (memcpy(dst, src, len * sizeof(elem_type)))
  ------------------
 7181|    624|        (size_t)33U, prf_input, prf_inputs[i], uint8_t, void *);
 7182|    624|  }
 7183|    208|  domain_separator =
 7184|    208|      libcrux_ml_kem_utils_prf_input_inc_e0(prf_inputs, domain_separator);
 7185|    208|  uint8_t prf_outputs[3U][128U];
 7186|    208|  libcrux_ml_kem_hash_functions_portable_PRFxN_4a_41(prf_inputs, prf_outputs);
 7187|    832|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (7187:31): [True: 624, False: 208]
  ------------------
 7188|    624|    size_t i0 = i;
 7189|    624|    re_as_ntt[i0] =
 7190|    624|        libcrux_ml_kem_sampling_sample_from_binomial_distribution_a0(
 7191|    624|            Eurydice_array_to_slice((size_t)128U, prf_outputs[i0], uint8_t));
  ------------------
  |  |  204|    624|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    624|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    624|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    624|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7192|    624|    libcrux_ml_kem_ntt_ntt_binomially_sampled_ring_element_ea(&re_as_ntt[i0]);
 7193|    624|  }
 7194|    208|  return domain_separator;
 7195|    208|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_utils_prf_input_inc_e0:
  866|    208|    uint8_t (*prf_inputs)[33U], uint8_t domain_separator) {
  867|    832|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (867:31): [True: 624, False: 208]
  ------------------
  868|    624|    size_t i0 = i;
  869|    624|    prf_inputs[i0][32U] = domain_separator;
  870|    624|    domain_separator = (uint32_t)domain_separator + 1U;
  871|    624|  }
  872|    208|  return domain_separator;
  873|    208|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRFxN_4a_41:
 7001|    208|    uint8_t (*input)[33U], uint8_t ret[3U][128U]) {
 7002|    208|  libcrux_ml_kem_hash_functions_portable_PRFxN_41(input, ret);
 7003|    208|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_PRFxN_41:
 6979|    208|    uint8_t (*input)[33U], uint8_t ret[3U][128U]) {
 6980|    208|  uint8_t out[3U][128U] = {{0U}};
 6981|    832|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (6981:31): [True: 624, False: 208]
  ------------------
 6982|    624|    size_t i0 = i;
 6983|    624|    libcrux_sha3_portable_shake256(
 6984|    624|        Eurydice_array_to_slice((size_t)128U, out[i0], uint8_t),
  ------------------
  |  |  204|    624|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    624|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    624|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    624|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6985|    624|        Eurydice_array_to_slice((size_t)33U, input[i0], uint8_t));
  ------------------
  |  |  204|    624|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    624|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    624|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    624|                 end) /* x is already at an array type, no need for cast */
  ------------------
 6986|    624|  }
 6987|    208|  memcpy(ret, out, (size_t)3U * sizeof(uint8_t[128U]));
 6988|    208|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_binomially_sampled_ring_element_ea:
 7143|    624|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 7144|    624|  libcrux_ml_kem_ntt_ntt_at_layer_7_ea(re);
 7145|    624|  size_t zeta_i = (size_t)1U;
 7146|    624|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)6U,
 7147|    624|                                            (size_t)11207U);
 7148|    624|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(&zeta_i, re, (size_t)5U,
 7149|    624|                                            (size_t)11207U + (size_t)3328U);
 7150|    624|  libcrux_ml_kem_ntt_ntt_at_layer_4_plus_ea(
 7151|    624|      &zeta_i, re, (size_t)4U, (size_t)11207U + (size_t)2U * (size_t)3328U);
 7152|    624|  libcrux_ml_kem_ntt_ntt_at_layer_3_ea(
 7153|    624|      &zeta_i, re, (size_t)11207U + (size_t)3U * (size_t)3328U);
 7154|    624|  libcrux_ml_kem_ntt_ntt_at_layer_2_ea(
 7155|    624|      &zeta_i, re, (size_t)11207U + (size_t)4U * (size_t)3328U);
 7156|    624|  libcrux_ml_kem_ntt_ntt_at_layer_1_ea(
 7157|    624|      &zeta_i, re, (size_t)11207U + (size_t)5U * (size_t)3328U);
 7158|    624|  libcrux_ml_kem_polynomial_poly_barrett_reduce_d6_ea(re);
 7159|    624|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ntt_ntt_at_layer_7_ea:
 7120|    624|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re) {
 7121|    624|  size_t step = LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT / (size_t)2U;
  ------------------
  |  | 3770|    624|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
 7122|  5.61k|  for (size_t i = (size_t)0U; i < step; i++) {
  ------------------
  |  Branch (7122:31): [True: 4.99k, False: 624]
  ------------------
 7123|  4.99k|    size_t j = i;
 7124|  4.99k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector t =
 7125|  4.99k|        libcrux_ml_kem_vector_portable_multiply_by_constant_b8(
 7126|  4.99k|            re->coefficients[j + step], (int16_t)-1600);
 7127|  4.99k|    re->coefficients[j + step] =
 7128|  4.99k|        libcrux_ml_kem_vector_portable_sub_b8(re->coefficients[j], &t);
 7129|  4.99k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector uu____1 =
 7130|  4.99k|        libcrux_ml_kem_vector_portable_add_b8(re->coefficients[j], &t);
 7131|  4.99k|    re->coefficients[j] = uu____1;
 7132|  4.99k|  }
 7133|    624|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_multiply_by_constant_b8:
 3906|  4.99k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec, int16_t c) {
 3907|  4.99k|  return libcrux_ml_kem_vector_portable_arithmetic_multiply_by_constant(vec, c);
 3908|  4.99k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_arithmetic_multiply_by_constant:
 3890|  4.99k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vec, int16_t c) {
 3891|  4.99k|  for (size_t i = (size_t)0U;
 3892|  84.8k|       i < LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR; i++) {
  ------------------
  |  | 3772|  84.8k|#define LIBCRUX_ML_KEM_VECTOR_TRAITS_FIELD_ELEMENTS_IN_VECTOR ((size_t)16U)
  ------------------
  |  Branch (3892:8): [True: 79.8k, False: 4.99k]
  ------------------
 3893|  79.8k|    size_t i0 = i;
 3894|  79.8k|    size_t uu____0 = i0;
 3895|  79.8k|    vec.elements[uu____0] = vec.elements[uu____0] * c;
 3896|  79.8k|  }
 3897|  4.99k|  return vec;
 3898|  4.99k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_binomial_distribution_a0:
 7108|    624|    Eurydice_slice randomness) {
 7109|    624|  return libcrux_ml_kem_sampling_sample_from_binomial_distribution_2_ea(
 7110|    624|      randomness);
 7111|    624|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_sampling_sample_from_binomial_distribution_2_ea:
 7062|    624|    Eurydice_slice randomness) {
 7063|    624|  int16_t sampled_i16s[256U] = {0U};
 7064|    624|  for (size_t i0 = (size_t)0U;
 7065|  20.5k|       i0 < Eurydice_slice_len(randomness, uint8_t) / (size_t)4U; i0++) {
  ------------------
  |  |  173|  20.5k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (7065:8): [True: 19.9k, False: 624]
  ------------------
 7066|  19.9k|    size_t chunk_number = i0;
 7067|  19.9k|    Eurydice_slice byte_chunk = Eurydice_slice_subslice3(
  ------------------
  |  |  195|  19.9k|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  19.9k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  19.9k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7068|  19.9k|        randomness, chunk_number * (size_t)4U,
 7069|  19.9k|        chunk_number * (size_t)4U + (size_t)4U, uint8_t *);
 7070|  19.9k|    uint32_t random_bits_as_u32 =
 7071|  19.9k|        (((uint32_t)Eurydice_slice_index(byte_chunk, (size_t)0U, uint8_t,
  ------------------
  |  |  180|  19.9k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 7072|  19.9k|                                         uint8_t *) |
 7073|  19.9k|          (uint32_t)Eurydice_slice_index(byte_chunk, (size_t)1U, uint8_t,
  ------------------
  |  |  180|  19.9k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 7074|  19.9k|                                         uint8_t *)
 7075|  19.9k|              << 8U) |
 7076|  19.9k|         (uint32_t)Eurydice_slice_index(byte_chunk, (size_t)2U, uint8_t,
  ------------------
  |  |  180|  19.9k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 7077|  19.9k|                                        uint8_t *)
 7078|  19.9k|             << 16U) |
 7079|  19.9k|        (uint32_t)Eurydice_slice_index(byte_chunk, (size_t)3U, uint8_t,
  ------------------
  |  |  180|  19.9k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 7080|  19.9k|                                       uint8_t *)
 7081|  19.9k|            << 24U;
 7082|  19.9k|    uint32_t even_bits = random_bits_as_u32 & 1431655765U;
 7083|  19.9k|    uint32_t odd_bits = random_bits_as_u32 >> 1U & 1431655765U;
 7084|  19.9k|    uint32_t coin_toss_outcomes = even_bits + odd_bits;
 7085|   179k|    for (uint32_t i = 0U; i < 32U / 4U; i++) {
  ------------------
  |  Branch (7085:27): [True: 159k, False: 19.9k]
  ------------------
 7086|   159k|      uint32_t outcome_set = i;
 7087|   159k|      uint32_t outcome_set0 = outcome_set * 4U;
 7088|   159k|      int16_t outcome_1 =
 7089|   159k|          (int16_t)(coin_toss_outcomes >> (uint32_t)outcome_set0 & 3U);
 7090|   159k|      int16_t outcome_2 =
 7091|   159k|          (int16_t)(coin_toss_outcomes >> (uint32_t)(outcome_set0 + 2U) & 3U);
 7092|   159k|      size_t offset = (size_t)(outcome_set0 >> 2U);
 7093|   159k|      sampled_i16s[(size_t)8U * chunk_number + offset] = outcome_1 - outcome_2;
 7094|   159k|    }
 7095|  19.9k|  }
 7096|    624|  return libcrux_ml_kem_polynomial_from_i16_array_d6_ea(
 7097|    624|      Eurydice_array_to_slice((size_t)256U, sampled_i16s, int16_t));
  ------------------
  |  |  204|    624|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    624|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    624|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    624|                 end) /* x is already at an array type, no need for cast */
  ------------------
 7098|    624|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_H_4a_e0:
 8072|    104|    Eurydice_slice input, uint8_t ret[32U]) {
 8073|    104|  libcrux_ml_kem_hash_functions_portable_H(input, ret);
 8074|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_hash_functions_portable_H:
 3725|    104|    Eurydice_slice input, uint8_t ret[32U]) {
 3726|    104|  uint8_t digest[32U] = {0U};
 3727|    104|  libcrux_sha3_portable_sha256(
 3728|    104|      Eurydice_array_to_slice((size_t)32U, digest, uint8_t), input);
  ------------------
  |  |  204|    104|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    104|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3729|    104|  memcpy(ret, digest, (size_t)32U * sizeof(uint8_t));
 3730|    104|}
libcrux_mlkem768_sha3.c:libcrux_sha3_portable_sha256:
 3351|    104|                                                         Eurydice_slice data) {
 3352|    104|  libcrux_sha3_generic_keccak_portable_keccak1_ad(data, digest);
 3353|    104|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_portable_keccak1_ad:
 3315|    104|    Eurydice_slice data, Eurydice_slice out) {
 3316|    104|  libcrux_sha3_generic_keccak_KeccakState_17 s =
 3317|    104|      libcrux_sha3_generic_keccak_new_80_04();
 3318|    104|  size_t data_len = Eurydice_slice_len(data, uint8_t);
  ------------------
  |  |  173|    104|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3319|    936|  for (size_t i = (size_t)0U; i < data_len / (size_t)136U; i++) {
  ------------------
  |  Branch (3319:31): [True: 832, False: 104]
  ------------------
 3320|    832|    size_t i0 = i;
 3321|    832|    Eurydice_slice buf[1U] = {data};
 3322|    832|    libcrux_sha3_generic_keccak_absorb_block_80_c60(&s, buf, i0 * (size_t)136U);
 3323|    832|  }
 3324|    104|  size_t rem = data_len % (size_t)136U;
 3325|    104|  Eurydice_slice buf[1U] = {data};
 3326|    104|  libcrux_sha3_generic_keccak_absorb_final_80_9e0(&s, buf, data_len - rem, rem);
 3327|    104|  size_t outlen = Eurydice_slice_len(out, uint8_t);
  ------------------
  |  |  173|    104|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 3328|    104|  size_t blocks = outlen / (size_t)136U;
 3329|    104|  size_t last = outlen - outlen % (size_t)136U;
 3330|    104|  if (blocks == (size_t)0U) {
  ------------------
  |  Branch (3330:7): [True: 104, False: 0]
  ------------------
 3331|    104|    libcrux_sha3_simd_portable_squeeze_13_5b(&s, out, (size_t)0U, outlen);
 3332|    104|  } 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|    104|}
libcrux_mlkem768_sha3.c:libcrux_sha3_generic_keccak_absorb_final_80_9e0:
 3250|    104|    size_t start, size_t len) {
 3251|    104|  libcrux_sha3_simd_portable_load_last_a1_ad(self, last, start, len);
 3252|    104|  libcrux_sha3_generic_keccak_keccakf1600_80_04(self);
 3253|    104|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_a1_ad:
 3232|    104|    size_t start, size_t len) {
 3233|    104|  libcrux_sha3_simd_portable_load_last_ad(self->st, input[0U], start, len);
 3234|    104|}
libcrux_mlkem768_sha3.c:libcrux_sha3_simd_portable_load_last_ad:
 3205|    104|    uint64_t *state, Eurydice_slice blocks, size_t start, size_t len) {
 3206|    104|  uint8_t buffer[136U] = {0U};
 3207|    104|  Eurydice_slice_copy(
  ------------------
  |  |  229|    104|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 3208|    104|      Eurydice_array_to_subslice3(buffer, (size_t)0U, len, uint8_t *),
 3209|    104|      Eurydice_slice_subslice3(blocks, start, start + len, uint8_t *), uint8_t);
 3210|    104|  buffer[len] = 6U;
 3211|    104|  size_t uu____0 = (size_t)136U - (size_t)1U;
 3212|    104|  buffer[uu____0] = (uint32_t)buffer[uu____0] | 128U;
 3213|    104|  libcrux_sha3_simd_portable_load_block_5b(
 3214|    104|      state, Eurydice_array_to_slice((size_t)136U, buffer, uint8_t),
  ------------------
  |  |  204|    104|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    104|                 end) /* x is already at an array type, no need for cast */
  ------------------
 3215|    104|      (size_t)0U);
 3216|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_instantiations_portable_generate_keypair_ce:
 8754|    104|    uint8_t *randomness) {
 8755|    104|  return libcrux_ml_kem_ind_cca_generate_keypair_15(randomness);
 8756|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_generate_keypair_15:
 8705|    104|libcrux_ml_kem_ind_cca_generate_keypair_15(uint8_t *randomness) {
 8706|    104|  Eurydice_slice ind_cpa_keypair_randomness = Eurydice_array_to_subslice3(
  ------------------
  |  |  215|    104|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8707|    104|      randomness, (size_t)0U,
 8708|    104|      LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE, uint8_t *);
 8709|    104|  Eurydice_slice implicit_rejection_value = Eurydice_array_to_subslice_from(
  ------------------
  |  |  225|    104|  EURYDICE_SLICE((t *)x, r, size)
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8710|    104|      (size_t)64U, randomness,
 8711|    104|      LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE, uint8_t,
 8712|    104|      size_t, uint8_t[]);
 8713|    104|  libcrux_ml_kem_utils_extraction_helper_Keypair768 uu____0 =
 8714|    104|      libcrux_ml_kem_ind_cpa_generate_keypair_ea(ind_cpa_keypair_randomness);
 8715|    104|  uint8_t ind_cpa_private_key[1152U];
 8716|    104|  memcpy(ind_cpa_private_key, uu____0.fst, (size_t)1152U * sizeof(uint8_t));
 8717|    104|  uint8_t public_key[1184U];
 8718|    104|  memcpy(public_key, uu____0.snd, (size_t)1184U * sizeof(uint8_t));
 8719|    104|  uint8_t secret_key_serialized[2400U];
 8720|    104|  libcrux_ml_kem_ind_cca_serialize_kem_secret_key_d6(
 8721|    104|      Eurydice_array_to_slice((size_t)1152U, ind_cpa_private_key, uint8_t),
  ------------------
  |  |  204|    104|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    104|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8722|    104|      Eurydice_array_to_slice((size_t)1184U, public_key, uint8_t),
  ------------------
  |  |  204|    104|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    104|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8723|    104|      implicit_rejection_value, secret_key_serialized);
 8724|       |  /* Passing arrays by value in Rust generates a copy in C */
 8725|    104|  uint8_t copy_of_secret_key_serialized[2400U];
 8726|    104|  memcpy(copy_of_secret_key_serialized, secret_key_serialized,
 8727|    104|         (size_t)2400U * sizeof(uint8_t));
 8728|    104|  libcrux_ml_kem_types_MlKemPrivateKey_d9 private_key =
 8729|    104|      libcrux_ml_kem_types_from_77_28(copy_of_secret_key_serialized);
 8730|    104|  libcrux_ml_kem_types_MlKemPrivateKey_d9 uu____2 = private_key;
 8731|       |  /* Passing arrays by value in Rust generates a copy in C */
 8732|    104|  uint8_t copy_of_public_key[1184U];
 8733|    104|  memcpy(copy_of_public_key, public_key, (size_t)1184U * sizeof(uint8_t));
 8734|    104|  return libcrux_ml_kem_types_from_17_74(
 8735|    104|      uu____2, libcrux_ml_kem_types_from_fd_d0(copy_of_public_key));
 8736|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_generate_keypair_ea:
 8605|    104|libcrux_ml_kem_ind_cpa_generate_keypair_ea(Eurydice_slice key_generation_seed) {
 8606|    104|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPrivateKeyUnpacked_a0 private_key =
 8607|    104|      libcrux_ml_kem_ind_cpa_unpacked_default_70_1b();
 8608|    104|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0 public_key =
 8609|    104|      libcrux_ml_kem_ind_cpa_unpacked_default_8b_1b();
 8610|    104|  libcrux_ml_kem_ind_cpa_generate_keypair_unpacked_1c(
 8611|    104|      key_generation_seed, &private_key, &public_key);
 8612|    104|  return libcrux_ml_kem_ind_cpa_serialize_unpacked_secret_key_6c(&public_key,
 8613|    104|                                                                 &private_key);
 8614|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_unpacked_default_70_1b:
 8189|    104|libcrux_ml_kem_ind_cpa_unpacked_default_70_1b(void) {
 8190|    104|  libcrux_ml_kem_ind_cpa_unpacked_IndCpaPrivateKeyUnpacked_a0 lit;
 8191|    104|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d repeat_expression[3U];
 8192|    416|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (8192:31): [True: 312, False: 104]
  ------------------
 8193|    312|    repeat_expression[i] = libcrux_ml_kem_polynomial_ZERO_d6_ea();
 8194|    312|  }
 8195|    104|  memcpy(
 8196|    104|      lit.secret_as_ntt, repeat_expression,
 8197|    104|      (size_t)3U * sizeof(libcrux_ml_kem_polynomial_PolynomialRingElement_1d));
 8198|    104|  return lit;
 8199|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_generate_keypair_unpacked_1c:
 8409|    104|    libcrux_ml_kem_ind_cpa_unpacked_IndCpaPublicKeyUnpacked_a0 *public_key) {
 8410|    104|  uint8_t hashed[64U];
 8411|    104|  libcrux_ml_kem_variant_cpa_keygen_seed_39_9c(key_generation_seed, hashed);
 8412|    104|  Eurydice_slice_uint8_t_x2 uu____0 = Eurydice_slice_split_at(
  ------------------
  |  |  254|    104|  KRML_CLITERAL(ret_t) {                                                  \
  |  |  ------------------
  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  ------------------
  |  |  255|    104|    EURYDICE_CFIELD(.fst =)                                               \
  |  |  256|    104|    EURYDICE_SLICE((element_type *)(slice).ptr, 0, mid),                  \
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  257|    104|        EURYDICE_CFIELD(.snd =)                                           \
  |  |  258|    104|            EURYDICE_SLICE((element_type *)(slice).ptr, mid, (slice).len) \
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  259|    104|  }
  ------------------
 8413|    104|      Eurydice_array_to_slice((size_t)64U, hashed, uint8_t), (size_t)32U,
 8414|    104|      uint8_t, Eurydice_slice_uint8_t_x2);
 8415|    104|  Eurydice_slice seed_for_A = uu____0.fst;
 8416|    104|  Eurydice_slice seed_for_secret_and_error = uu____0.snd;
 8417|    104|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d(*uu____1)[3U] =
 8418|    104|      public_key->A;
 8419|    104|  uint8_t ret[34U];
 8420|    104|  libcrux_ml_kem_utils_into_padded_array_b6(seed_for_A, ret);
 8421|    104|  libcrux_ml_kem_matrix_sample_matrix_A_2b(uu____1, ret, true);
 8422|    104|  uint8_t prf_input[33U];
 8423|    104|  libcrux_ml_kem_utils_into_padded_array_c8(seed_for_secret_and_error,
 8424|    104|                                            prf_input);
 8425|    104|  uint8_t domain_separator =
 8426|    104|      libcrux_ml_kem_ind_cpa_sample_vector_cbd_then_ntt_3b(
 8427|    104|          private_key->secret_as_ntt, prf_input, 0U);
 8428|    104|  libcrux_ml_kem_polynomial_PolynomialRingElement_1d error_as_ntt[3U];
 8429|    416|  for (size_t i = (size_t)0U; i < (size_t)3U; i++) {
  ------------------
  |  Branch (8429:31): [True: 312, False: 104]
  ------------------
 8430|       |    /* original Rust expression is not an lvalue in C */
 8431|    312|    void *lvalue = (void *)0U;
 8432|    312|    error_as_ntt[i] =
 8433|    312|        libcrux_ml_kem_ind_cpa_generate_keypair_unpacked_call_mut_73_1c(&lvalue,
 8434|    312|                                                                        i);
 8435|    312|  }
 8436|    104|  libcrux_ml_kem_ind_cpa_sample_vector_cbd_then_ntt_3b(error_as_ntt, prf_input,
 8437|    104|                                                       domain_separator);
 8438|    104|  libcrux_ml_kem_matrix_compute_As_plus_e_1b(
 8439|    104|      public_key->t_as_ntt, public_key->A, private_key->secret_as_ntt,
 8440|    104|      error_as_ntt);
 8441|    104|  uint8_t uu____2[32U];
 8442|    104|  Result_fb dst;
 8443|    104|  Eurydice_slice_to_array2(&dst, seed_for_A, Eurydice_slice, uint8_t[32U],
  ------------------
  |  |  277|    104|  Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
  |  |  278|    104|                           sizeof(t_arr))
  ------------------
 8444|    104|                           TryFromSliceError);
 8445|    104|  unwrap_26_b3(dst, uu____2);
 8446|    104|  memcpy(public_key->seed_for_A, uu____2, (size_t)32U * sizeof(uint8_t));
 8447|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_variant_cpa_keygen_seed_39_9c:
 8212|    104|    Eurydice_slice key_generation_seed, uint8_t ret[64U]) {
 8213|    104|  uint8_t seed[33U] = {0U};
 8214|    104|  Eurydice_slice_copy(
  ------------------
  |  |  229|    104|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8215|    104|      Eurydice_array_to_subslice3(
 8216|    104|          seed, (size_t)0U,
 8217|    104|          LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE, uint8_t *),
 8218|    104|      key_generation_seed, uint8_t);
 8219|    104|  seed[LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE] =
  ------------------
  |  |  455|    104|#define LIBCRUX_ML_KEM_CONSTANTS_CPA_PKE_KEY_GENERATION_SEED_SIZE ((size_t)32U)
  ------------------
 8220|    104|      (uint8_t)(size_t)3U;
 8221|    104|  uint8_t ret0[64U];
 8222|    104|  libcrux_ml_kem_hash_functions_portable_G_4a_e0(
 8223|    104|      Eurydice_array_to_slice((size_t)33U, seed, uint8_t), ret0);
  ------------------
  |  |  204|    104|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    104|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8224|    104|  memcpy(ret, ret0, (size_t)64U * sizeof(uint8_t));
 8225|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_generate_keypair_unpacked_call_mut_73_1c:
 8247|    312|    void **_, size_t tupled_args) {
 8248|    312|  return libcrux_ml_kem_polynomial_ZERO_d6_ea();
 8249|    312|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_matrix_compute_As_plus_e_1b:
 8322|    104|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error_as_ntt) {
 8323|    104|  for (size_t i = (size_t)0U;
 8324|    416|       i < Eurydice_slice_len(
  ------------------
  |  |  173|    416|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (8324:8): [True: 312, False: 104]
  ------------------
 8325|    104|               Eurydice_array_to_slice(
 8326|    104|                   (size_t)3U, matrix_A,
 8327|    104|                   libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]),
 8328|    104|               libcrux_ml_kem_polynomial_PolynomialRingElement_1d[3U]);
 8329|    312|       i++) {
 8330|    312|    size_t i0 = i;
 8331|    312|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *row = matrix_A[i0];
 8332|    312|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d uu____0 =
 8333|    312|        libcrux_ml_kem_polynomial_ZERO_d6_ea();
 8334|    312|    t_as_ntt[i0] = uu____0;
 8335|    312|    for (size_t i1 = (size_t)0U;
 8336|  1.24k|         i1 < Eurydice_slice_len(
  ------------------
  |  |  173|  1.24k|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (8336:10): [True: 936, False: 312]
  ------------------
 8337|    312|                  Eurydice_array_to_slice(
 8338|    312|                      (size_t)3U, row,
 8339|    312|                      libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 8340|    312|                  libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 8341|    936|         i1++) {
 8342|    936|      size_t j = i1;
 8343|    936|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d *matrix_element =
 8344|    936|          &row[j];
 8345|    936|      libcrux_ml_kem_polynomial_PolynomialRingElement_1d product =
 8346|    936|          libcrux_ml_kem_polynomial_ntt_multiply_d6_ea(matrix_element,
 8347|    936|                                                       &s_as_ntt[j]);
 8348|    936|      libcrux_ml_kem_polynomial_add_to_ring_element_d6_1b(&t_as_ntt[i0],
 8349|    936|                                                          &product);
 8350|    936|    }
 8351|    312|    libcrux_ml_kem_polynomial_add_standard_error_reduce_d6_ea(
 8352|    312|        &t_as_ntt[i0], &error_as_ntt[i0]);
 8353|    312|  }
 8354|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_standard_error_reduce_d6_ea:
 8305|    312|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error) {
 8306|    312|  libcrux_ml_kem_polynomial_add_standard_error_reduce_ea(self, error);
 8307|    312|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_add_standard_error_reduce_ea:
 8274|    312|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *error) {
 8275|    312|  for (size_t i = (size_t)0U;
 8276|  5.30k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  5.30k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (8276:8): [True: 4.99k, False: 312]
  ------------------
 8277|  4.99k|    size_t j = i;
 8278|  4.99k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector
 8279|  4.99k|        coefficient_normal_form =
 8280|  4.99k|            libcrux_ml_kem_polynomial_to_standard_domain_ea(
 8281|  4.99k|                myself->coefficients[j]);
 8282|  4.99k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector sum =
 8283|  4.99k|        libcrux_ml_kem_vector_portable_add_b8(coefficient_normal_form,
 8284|  4.99k|                                              &error->coefficients[j]);
 8285|  4.99k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector red =
 8286|  4.99k|        libcrux_ml_kem_vector_portable_barrett_reduce_b8(sum);
 8287|  4.99k|    myself->coefficients[j] = red;
 8288|  4.99k|  }
 8289|    312|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_polynomial_to_standard_domain_ea:
 8259|  4.99k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector vector) {
 8260|  4.99k|  return libcrux_ml_kem_vector_portable_montgomery_multiply_by_constant_b8(
 8261|  4.99k|      vector,
 8262|  4.99k|      LIBCRUX_ML_KEM_VECTOR_TRAITS_MONTGOMERY_R_SQUARED_MOD_FIELD_MODULUS);
  ------------------
  |  | 3775|  4.99k|  ((int16_t)1353)
  ------------------
 8263|  4.99k|}
libcrux_mlkem768_sha3.c:unwrap_26_b3:
  803|    104|static inline void unwrap_26_b3(Result_fb self, uint8_t ret[32U]) {
  804|    104|  if (self.tag == Ok) {
  ------------------
  |  |  721|    104|#define Ok 0
  ------------------
  |  Branch (804:7): [True: 104, False: 0]
  ------------------
  805|    104|    uint8_t f0[32U];
  806|    104|    memcpy(f0, self.val.case_Ok, (size_t)32U * sizeof(uint8_t));
  807|    104|    memcpy(ret, f0, (size_t)32U * sizeof(uint8_t));
  808|    104|  } 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|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_serialize_unpacked_secret_key_6c:
 8567|    104|    libcrux_ml_kem_ind_cpa_unpacked_IndCpaPrivateKeyUnpacked_a0 *private_key) {
 8568|    104|  uint8_t public_key_serialized[1184U];
 8569|    104|  libcrux_ml_kem_ind_cpa_serialize_public_key_89(
 8570|    104|      public_key->t_as_ntt,
 8571|    104|      Eurydice_array_to_slice((size_t)32U, public_key->seed_for_A, uint8_t),
  ------------------
  |  |  204|    104|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    104|                 end) /* x is already at an array type, no need for cast */
  ------------------
 8572|    104|      public_key_serialized);
 8573|    104|  uint8_t secret_key_serialized[1152U] = {0U};
 8574|    104|  libcrux_ml_kem_ind_cpa_serialize_vector_1b(
 8575|    104|      private_key->secret_as_ntt,
 8576|    104|      Eurydice_array_to_slice((size_t)1152U, secret_key_serialized, uint8_t));
  ------------------
  |  |  204|    104|  EURYDICE_SLICE(x, 0,                     \
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  205|    104|                 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|    104|  uint8_t copy_of_secret_key_serialized[1152U];
 8579|    104|  memcpy(copy_of_secret_key_serialized, secret_key_serialized,
 8580|    104|         (size_t)1152U * sizeof(uint8_t));
 8581|       |  /* Passing arrays by value in Rust generates a copy in C */
 8582|    104|  uint8_t copy_of_public_key_serialized[1184U];
 8583|    104|  memcpy(copy_of_public_key_serialized, public_key_serialized,
 8584|    104|         (size_t)1184U * sizeof(uint8_t));
 8585|    104|  libcrux_ml_kem_utils_extraction_helper_Keypair768 lit;
 8586|    104|  memcpy(lit.fst, copy_of_secret_key_serialized,
 8587|    104|         (size_t)1152U * sizeof(uint8_t));
 8588|    104|  memcpy(lit.snd, copy_of_public_key_serialized,
 8589|    104|         (size_t)1184U * sizeof(uint8_t));
 8590|    104|  return lit;
 8591|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_serialize_public_key_89:
 8546|    104|    Eurydice_slice seed_for_a, uint8_t ret[1184U]) {
 8547|    104|  uint8_t public_key_serialized[1184U] = {0U};
 8548|    104|  libcrux_ml_kem_ind_cpa_serialize_public_key_mut_89(t_as_ntt, seed_for_a,
 8549|    104|                                                     public_key_serialized);
 8550|    104|  memcpy(ret, public_key_serialized, (size_t)1184U * sizeof(uint8_t));
 8551|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_serialize_public_key_mut_89:
 8519|    104|    Eurydice_slice seed_for_a, uint8_t *serialized) {
 8520|    104|  libcrux_ml_kem_ind_cpa_serialize_vector_1b(
 8521|    104|      t_as_ntt,
 8522|    104|      Eurydice_array_to_subslice3(
  ------------------
  |  |  215|    104|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8523|    104|          serialized, (size_t)0U,
 8524|    104|          libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U),
 8525|    104|          uint8_t *));
 8526|    104|  Eurydice_slice_copy(
  ------------------
  |  |  229|    104|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8527|    104|      Eurydice_array_to_subslice_from(
 8528|    104|          (size_t)1184U, serialized,
 8529|    104|          libcrux_ml_kem_constants_ranked_bytes_per_ring_element((size_t)3U),
 8530|    104|          uint8_t, size_t, uint8_t[]),
 8531|    104|      seed_for_a, uint8_t);
 8532|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_constants_ranked_bytes_per_ring_element:
  468|    520|    size_t rank) {
  469|    520|  return rank * LIBCRUX_ML_KEM_CONSTANTS_BITS_PER_RING_ELEMENT / (size_t)8U;
  ------------------
  |  |  450|    520|  (LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT * (size_t)12U)
  |  |  ------------------
  |  |  |  |  447|    520|#define LIBCRUX_ML_KEM_CONSTANTS_COEFFICIENTS_IN_RING_ELEMENT ((size_t)256U)
  |  |  ------------------
  ------------------
  470|    520|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cpa_serialize_vector_1b:
 8486|    208|    Eurydice_slice out) {
 8487|    208|  for (size_t i = (size_t)0U;
 8488|    832|       i < Eurydice_slice_len(
  ------------------
  |  |  173|    832|#define Eurydice_slice_len(s, _) (s).len
  ------------------
  |  Branch (8488:8): [True: 624, False: 208]
  ------------------
 8489|    208|               Eurydice_array_to_slice(
 8490|    208|                   (size_t)3U, key,
 8491|    208|                   libcrux_ml_kem_polynomial_PolynomialRingElement_1d),
 8492|    208|               libcrux_ml_kem_polynomial_PolynomialRingElement_1d);
 8493|    624|       i++) {
 8494|    624|    size_t i0 = i;
 8495|    624|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d re = key[i0];
 8496|    624|    Eurydice_slice uu____0 = Eurydice_slice_subslice3(
  ------------------
  |  |  195|    624|  EURYDICE_SLICE((t_ptr)s.ptr, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    624|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    624|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8497|    624|        out, i0 * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 8498|    624|        (i0 + (size_t)1U) * LIBCRUX_ML_KEM_CONSTANTS_BYTES_PER_RING_ELEMENT,
 8499|    624|        uint8_t *);
 8500|    624|    uint8_t ret[384U];
 8501|    624|    libcrux_ml_kem_serialize_serialize_uncompressed_ring_element_ea(&re, ret);
 8502|    624|    Eurydice_slice_copy(
  ------------------
  |  |  229|    624|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8503|    624|        uu____0, Eurydice_array_to_slice((size_t)384U, ret, uint8_t), uint8_t);
 8504|    624|  }
 8505|    208|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_serialize_serialize_uncompressed_ring_element_ea:
 8457|    624|    libcrux_ml_kem_polynomial_PolynomialRingElement_1d *re, uint8_t ret[384U]) {
 8458|    624|  uint8_t serialized[384U] = {0U};
 8459|    624|  for (size_t i = (size_t)0U;
 8460|  10.6k|       i < LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT; i++) {
  ------------------
  |  | 3770|  10.6k|#define LIBCRUX_ML_KEM_POLYNOMIAL_VECTORS_IN_RING_ELEMENT ((size_t)16U)
  ------------------
  |  Branch (8460:8): [True: 9.98k, False: 624]
  ------------------
 8461|  9.98k|    size_t i0 = i;
 8462|  9.98k|    libcrux_ml_kem_vector_portable_vector_type_PortableVector coefficient =
 8463|  9.98k|        libcrux_ml_kem_serialize_to_unsigned_field_modulus_ea(
 8464|  9.98k|            re->coefficients[i0]);
 8465|  9.98k|    uint8_t bytes[24U];
 8466|  9.98k|    libcrux_ml_kem_vector_portable_serialize_12_b8(coefficient, bytes);
 8467|  9.98k|    Eurydice_slice_copy(
  ------------------
  |  |  229|  9.98k|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8468|  9.98k|        Eurydice_array_to_subslice3(serialized, (size_t)24U * i0,
 8469|  9.98k|                                    (size_t)24U * i0 + (size_t)24U, uint8_t *),
 8470|  9.98k|        Eurydice_array_to_slice((size_t)24U, bytes, uint8_t), uint8_t);
 8471|  9.98k|  }
 8472|    624|  memcpy(ret, serialized, (size_t)384U * sizeof(uint8_t));
 8473|    624|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_12_b8:
 5116|  9.98k|    uint8_t ret[24U]) {
 5117|  9.98k|  libcrux_ml_kem_vector_portable_serialize_12(a, ret);
 5118|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_12:
 5104|  9.98k|    uint8_t ret[24U]) {
 5105|  9.98k|  uint8_t ret0[24U];
 5106|  9.98k|  libcrux_ml_kem_vector_portable_serialize_serialize_12(a, ret0);
 5107|  9.98k|  libcrux_secrets_int_public_integers_declassify_d8_d2(ret0, ret);
 5108|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_12:
 5051|  9.98k|    uint8_t ret[24U]) {
 5052|  9.98k|  uint8_t_x3 r0_2 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5053|  9.98k|      Eurydice_array_to_subslice3(v.elements, (size_t)0U, (size_t)2U,
  ------------------
  |  |  215|  9.98k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  9.98k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  9.98k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5054|  9.98k|                                  int16_t *));
 5055|  9.98k|  uint8_t_x3 r3_5 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5056|  9.98k|      Eurydice_array_to_subslice3(v.elements, (size_t)2U, (size_t)4U,
  ------------------
  |  |  215|  9.98k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  9.98k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  9.98k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5057|  9.98k|                                  int16_t *));
 5058|  9.98k|  uint8_t_x3 r6_8 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5059|  9.98k|      Eurydice_array_to_subslice3(v.elements, (size_t)4U, (size_t)6U,
  ------------------
  |  |  215|  9.98k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  9.98k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  9.98k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5060|  9.98k|                                  int16_t *));
 5061|  9.98k|  uint8_t_x3 r9_11 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5062|  9.98k|      Eurydice_array_to_subslice3(v.elements, (size_t)6U, (size_t)8U,
  ------------------
  |  |  215|  9.98k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  9.98k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  9.98k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5063|  9.98k|                                  int16_t *));
 5064|  9.98k|  uint8_t_x3 r12_14 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5065|  9.98k|      Eurydice_array_to_subslice3(v.elements, (size_t)8U, (size_t)10U,
  ------------------
  |  |  215|  9.98k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  9.98k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  9.98k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5066|  9.98k|                                  int16_t *));
 5067|  9.98k|  uint8_t_x3 r15_17 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5068|  9.98k|      Eurydice_array_to_subslice3(v.elements, (size_t)10U, (size_t)12U,
  ------------------
  |  |  215|  9.98k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  9.98k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  9.98k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5069|  9.98k|                                  int16_t *));
 5070|  9.98k|  uint8_t_x3 r18_20 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5071|  9.98k|      Eurydice_array_to_subslice3(v.elements, (size_t)12U, (size_t)14U,
  ------------------
  |  |  215|  9.98k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  9.98k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  9.98k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5072|  9.98k|                                  int16_t *));
 5073|  9.98k|  uint8_t_x3 r21_23 = libcrux_ml_kem_vector_portable_serialize_serialize_12_int(
 5074|  9.98k|      Eurydice_array_to_subslice3(v.elements, (size_t)14U, (size_t)16U,
  ------------------
  |  |  215|  9.98k|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|  9.98k|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|  9.98k|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5075|  9.98k|                                  int16_t *));
 5076|  9.98k|  ret[0U] = r0_2.fst;
 5077|  9.98k|  ret[1U] = r0_2.snd;
 5078|  9.98k|  ret[2U] = r0_2.thd;
 5079|  9.98k|  ret[3U] = r3_5.fst;
 5080|  9.98k|  ret[4U] = r3_5.snd;
 5081|  9.98k|  ret[5U] = r3_5.thd;
 5082|  9.98k|  ret[6U] = r6_8.fst;
 5083|  9.98k|  ret[7U] = r6_8.snd;
 5084|  9.98k|  ret[8U] = r6_8.thd;
 5085|  9.98k|  ret[9U] = r9_11.fst;
 5086|  9.98k|  ret[10U] = r9_11.snd;
 5087|  9.98k|  ret[11U] = r9_11.thd;
 5088|  9.98k|  ret[12U] = r12_14.fst;
 5089|  9.98k|  ret[13U] = r12_14.snd;
 5090|  9.98k|  ret[14U] = r12_14.thd;
 5091|  9.98k|  ret[15U] = r15_17.fst;
 5092|  9.98k|  ret[16U] = r15_17.snd;
 5093|  9.98k|  ret[17U] = r15_17.thd;
 5094|  9.98k|  ret[18U] = r18_20.fst;
 5095|  9.98k|  ret[19U] = r18_20.snd;
 5096|  9.98k|  ret[20U] = r18_20.thd;
 5097|  9.98k|  ret[21U] = r21_23.fst;
 5098|  9.98k|  ret[22U] = r21_23.snd;
 5099|  9.98k|  ret[23U] = r21_23.thd;
 5100|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_vector_portable_serialize_serialize_12_int:
 5035|  79.8k|libcrux_ml_kem_vector_portable_serialize_serialize_12_int(Eurydice_slice v) {
 5036|  79.8k|  uint8_t r0 = libcrux_secrets_int_as_u8_f5(
 5037|  79.8k|      Eurydice_slice_index(v, (size_t)0U, int16_t, int16_t *) & (int16_t)255);
  ------------------
  |  |  180|  79.8k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5038|  79.8k|  uint8_t r1 = libcrux_secrets_int_as_u8_f5(
 5039|  79.8k|      Eurydice_slice_index(v, (size_t)0U, int16_t, int16_t *) >> 8U |
  ------------------
  |  |  180|  79.8k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5040|  79.8k|      (Eurydice_slice_index(v, (size_t)1U, int16_t, int16_t *) & (int16_t)15)
  ------------------
  |  |  180|  79.8k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5041|  79.8k|          << 4U);
 5042|  79.8k|  uint8_t r2 = libcrux_secrets_int_as_u8_f5(
 5043|  79.8k|      Eurydice_slice_index(v, (size_t)1U, int16_t, int16_t *) >> 4U &
  ------------------
  |  |  180|  79.8k|#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
  ------------------
 5044|  79.8k|      (int16_t)255);
 5045|  79.8k|  return (KRML_CLITERAL(uint8_t_x3){.fst = r0, .snd = r1, .thd = r2});
  ------------------
  |  |  154|  79.8k|#define KRML_CLITERAL(type) (type)
  ------------------
 5046|  79.8k|}
libcrux_mlkem768_sha3.c:libcrux_secrets_int_public_integers_declassify_d8_d2:
 1020|  9.98k|                                                     uint8_t ret[24U]) {
 1021|  9.98k|  memcpy(ret, self, (size_t)24U * sizeof(uint8_t));
 1022|  9.98k|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_serialize_kem_secret_key_d6:
 8677|    104|    Eurydice_slice implicit_rejection_value, uint8_t ret[2400U]) {
 8678|    104|  uint8_t out[2400U] = {0U};
 8679|    104|  libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_d6(
 8680|    104|      private_key, public_key, implicit_rejection_value, out);
 8681|    104|  memcpy(ret, out, (size_t)2400U * sizeof(uint8_t));
 8682|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_ind_cca_serialize_kem_secret_key_mut_d6:
 8629|    104|    Eurydice_slice implicit_rejection_value, uint8_t *serialized) {
 8630|    104|  size_t pointer = (size_t)0U;
 8631|    104|  uint8_t *uu____0 = serialized;
 8632|    104|  size_t uu____1 = pointer;
 8633|    104|  size_t uu____2 = pointer;
 8634|    104|  Eurydice_slice_copy(
  ------------------
  |  |  229|    104|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8635|    104|      Eurydice_array_to_subslice3(
 8636|    104|          uu____0, uu____1, uu____2 + Eurydice_slice_len(private_key, uint8_t),
 8637|    104|          uint8_t *),
 8638|    104|      private_key, uint8_t);
 8639|    104|  pointer = pointer + Eurydice_slice_len(private_key, uint8_t);
  ------------------
  |  |  173|    104|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 8640|    104|  uint8_t *uu____3 = serialized;
 8641|    104|  size_t uu____4 = pointer;
 8642|    104|  size_t uu____5 = pointer;
 8643|    104|  Eurydice_slice_copy(
  ------------------
  |  |  229|    104|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8644|    104|      Eurydice_array_to_subslice3(
 8645|    104|          uu____3, uu____4, uu____5 + Eurydice_slice_len(public_key, uint8_t),
 8646|    104|          uint8_t *),
 8647|    104|      public_key, uint8_t);
 8648|    104|  pointer = pointer + Eurydice_slice_len(public_key, uint8_t);
  ------------------
  |  |  173|    104|#define Eurydice_slice_len(s, _) (s).len
  ------------------
 8649|    104|  Eurydice_slice uu____6 = Eurydice_array_to_subslice3(
  ------------------
  |  |  215|    104|  EURYDICE_SLICE((t_ptr)x, (start), (end))
  |  |  ------------------
  |  |  |  |  169|    104|  (KRML_CLITERAL(Eurydice_slice){(void *)(x + start), end - start})
  |  |  |  |  ------------------
  |  |  |  |  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8650|    104|      serialized, pointer, pointer + LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE,
 8651|    104|      uint8_t *);
 8652|    104|  uint8_t ret[32U];
 8653|    104|  libcrux_ml_kem_hash_functions_portable_H_4a_e0(public_key, ret);
 8654|    104|  Eurydice_slice_copy(
  ------------------
  |  |  229|    104|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8655|    104|      uu____6, Eurydice_array_to_slice((size_t)32U, ret, uint8_t), uint8_t);
 8656|    104|  pointer = pointer + LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE;
  ------------------
  |  |  459|    104|#define LIBCRUX_ML_KEM_CONSTANTS_H_DIGEST_SIZE ((size_t)32U)
  ------------------
 8657|    104|  uint8_t *uu____7 = serialized;
 8658|    104|  size_t uu____8 = pointer;
 8659|    104|  size_t uu____9 = pointer;
 8660|    104|  Eurydice_slice_copy(
  ------------------
  |  |  229|    104|  memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
  ------------------
 8661|    104|      Eurydice_array_to_subslice3(
 8662|    104|          uu____7, uu____8,
 8663|    104|          uu____9 + Eurydice_slice_len(implicit_rejection_value, uint8_t),
 8664|    104|          uint8_t *),
 8665|    104|      implicit_rejection_value, uint8_t);
 8666|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_from_77_28:
  772|    104|libcrux_ml_kem_types_from_77_28(uint8_t value[2400U]) {
  773|       |  /* Passing arrays by value in Rust generates a copy in C */
  774|    104|  uint8_t copy_of_value[2400U];
  775|    104|  memcpy(copy_of_value, value, (size_t)2400U * sizeof(uint8_t));
  776|    104|  libcrux_ml_kem_types_MlKemPrivateKey_d9 lit;
  777|    104|  memcpy(lit.value, copy_of_value, (size_t)2400U * sizeof(uint8_t));
  778|    104|  return lit;
  779|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_from_17_74:
  757|    104|                                libcrux_ml_kem_types_MlKemPublicKey_30 pk) {
  758|    104|  return (KRML_CLITERAL(libcrux_ml_kem_mlkem768_MlKem768KeyPair){.sk = sk,
  ------------------
  |  |  154|    104|#define KRML_CLITERAL(type) (type)
  ------------------
  759|    104|                                                                 .pk = pk});
  760|    104|}
libcrux_mlkem768_sha3.c:libcrux_ml_kem_types_from_fd_d0:
  736|    104|libcrux_ml_kem_types_from_fd_d0(uint8_t value[1184U]) {
  737|       |  /* Passing arrays by value in Rust generates a copy in C */
  738|    104|  uint8_t copy_of_value[1184U];
  739|    104|  memcpy(copy_of_value, value, (size_t)1184U * sizeof(uint8_t));
  740|    104|  libcrux_ml_kem_types_MlKemPublicKey_30 lit;
  741|    104|  memcpy(lit.value, copy_of_value, (size_t)1184U * sizeof(uint8_t));
  742|    104|  return lit;
  743|    104|}

sntrup761_keypair:
  989|     26|{
  990|     26|  int i;
  991|       |
  992|     26|  ZKeyGen (pk, sk, random_ctx, random);
  993|     26|  sk += SecretKeys_bytes;
  ------------------
  |  |  906|     26|#define SecretKeys_bytes (2*Small_bytes)
  |  |  ------------------
  |  |  |  |  799|     26|#define Small_bytes ((p+3)/4)
  |  |  |  |  ------------------
  |  |  |  |  |  |  236|     26|#define p 761
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  994|  30.1k|  for (i = 0; i < PublicKeys_bytes; ++i)
  ------------------
  |  |  907|  30.1k|#define PublicKeys_bytes Rq_bytes
  |  |  ------------------
  |  |  |  |  239|  30.1k|#define Rq_bytes 1158
  |  |  ------------------
  ------------------
  |  Branch (994:15): [True: 30.1k, False: 26]
  ------------------
  995|  30.1k|    *sk++ = pk[i];
  996|     26|  random (random_ctx, Inputs_bytes, sk);
  ------------------
  |  |  903|     26|#define Inputs_bytes Small_bytes
  |  |  ------------------
  |  |  |  |  799|     26|#define Small_bytes ((p+3)/4)
  |  |  |  |  ------------------
  |  |  |  |  |  |  236|     26|#define p 761
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  997|     26|  sk += Inputs_bytes;
  ------------------
  |  |  903|     26|#define Inputs_bytes Small_bytes
  |  |  ------------------
  |  |  |  |  799|     26|#define Small_bytes ((p+3)/4)
  |  |  |  |  ------------------
  |  |  |  |  |  |  236|     26|#define p 761
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  998|     26|  Hash_prefix (sk, 4, pk, PublicKeys_bytes);
  ------------------
  |  |  907|     26|#define PublicKeys_bytes Rq_bytes
  |  |  ------------------
  |  |  |  |  239|     26|#define Rq_bytes 1158
  |  |  ------------------
  ------------------
  999|     26|}
sntrup761.c:ZKeyGen:
  913|     26|{
  914|     26|  Fq h[p];
  915|     26|  small f[p], v[p];
  916|       |
  917|     26|  KeyGen (h, f, v, random_ctx, random);
  918|     26|  Rq_encode (pk, h);
  919|     26|  Small_encode (sk, f);
  920|     26|  sk += Small_bytes;
  ------------------
  |  |  799|     26|#define Small_bytes ((p+3)/4)
  |  |  ------------------
  |  |  |  |  236|     26|#define p 761
  |  |  ------------------
  ------------------
  921|     26|  Small_encode (sk, v);
  922|     26|}
sntrup761.c:KeyGen:
  749|     26|{
  750|     26|  small g[p];
  751|     26|  Fq finv[p];
  752|       |
  753|     26|  for (;;)
  754|     26|    {
  755|     26|      Small_random (g, random_ctx, random);
  756|     26|      if (R3_recip (ginv, g) == 0)
  ------------------
  |  Branch (756:11): [True: 26, False: 0]
  ------------------
  757|     26|	break;
  758|     26|    }
  759|     26|  Short_random (f, random_ctx, random);
  760|     26|  Rq_recip3 (finv, f);		/* always works */
  761|     26|  Rq_mult_small (h, finv, g);
  762|     26|}
sntrup761.c:Small_random:
  736|     26|{
  737|     26|  int i;
  738|       |
  739|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (739:15): [True: 19.7k, False: 26]
  ------------------
  740|  19.7k|    out[i] = (((urandom32 (random_ctx, random) & 0x3fffffff) * 3) >> 30) - 1;
  741|     26|}
sntrup761.c:urandom32:
  711|  39.5k|{
  712|  39.5k|  unsigned char c[4];
  713|  39.5k|  uint32_t out[4];
  714|       |
  715|  39.5k|  random (random_ctx, 4, c);
  716|  39.5k|  out[0] = (uint32_t) c[0];
  717|  39.5k|  out[1] = ((uint32_t) c[1]) << 8;
  718|  39.5k|  out[2] = ((uint32_t) c[2]) << 16;
  719|  39.5k|  out[3] = ((uint32_t) c[3]) << 24;
  720|  39.5k|  return out[0] + out[1] + out[2] + out[3];
  721|  39.5k|}
sntrup761.c:R3_recip:
  491|     26|{
  492|     26|  small f[p + 1], g[p + 1], v[p + 1], r[p + 1];
  493|     26|  int i, loop, delta;
  494|     26|  int sign, swap, t;
  495|       |
  496|  19.8k|  for (i = 0; i < p + 1; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (496:15): [True: 19.8k, False: 26]
  ------------------
  497|  19.8k|    v[i] = 0;
  498|  19.8k|  for (i = 0; i < p + 1; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (498:15): [True: 19.8k, False: 26]
  ------------------
  499|  19.8k|    r[i] = 0;
  500|     26|  r[0] = 1;
  501|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (501:15): [True: 19.7k, False: 26]
  ------------------
  502|  19.7k|    f[i] = 0;
  503|     26|  f[0] = 1;
  504|     26|  f[p - 1] = f[p] = -1;
  ------------------
  |  |  236|     26|#define p 761
  ------------------
                f[p - 1] = f[p] = -1;
  ------------------
  |  |  236|     26|#define p 761
  ------------------
  505|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (505:15): [True: 19.7k, False: 26]
  ------------------
  506|  19.7k|    g[p - 1 - i] = in[i];
  ------------------
  |  |  236|  19.7k|#define p 761
  ------------------
  507|     26|  g[p] = 0;
  ------------------
  |  |  236|     26|#define p 761
  ------------------
  508|       |
  509|     26|  delta = 1;
  510|       |
  511|  39.5k|  for (loop = 0; loop < 2 * p - 1; ++loop)
  ------------------
  |  |  236|  39.5k|#define p 761
  ------------------
  |  Branch (511:18): [True: 39.5k, False: 26]
  ------------------
  512|  39.5k|    {
  513|  30.1M|      for (i = p; i > 0; --i)
  ------------------
  |  |  236|  39.5k|#define p 761
  ------------------
  |  Branch (513:19): [True: 30.0M, False: 39.5k]
  ------------------
  514|  30.0M|	v[i] = v[i - 1];
  515|  39.5k|      v[0] = 0;
  516|       |
  517|  39.5k|      sign = -g[0] * f[0];
  518|  39.5k|      swap = int16_t_negative_mask (-delta) & int16_t_nonzero_mask (g[0]);
  519|  39.5k|      delta ^= swap & (delta ^ -delta);
  520|  39.5k|      delta += 1;
  521|       |
  522|  30.1M|      for (i = 0; i < p + 1; ++i)
  ------------------
  |  |  236|  30.1M|#define p 761
  ------------------
  |  Branch (522:19): [True: 30.1M, False: 39.5k]
  ------------------
  523|  30.1M|	{
  524|  30.1M|	  t = swap & (f[i] ^ g[i]);
  525|  30.1M|	  f[i] ^= t;
  526|  30.1M|	  g[i] ^= t;
  527|  30.1M|	  t = swap & (v[i] ^ r[i]);
  528|  30.1M|	  v[i] ^= t;
  529|  30.1M|	  r[i] ^= t;
  530|  30.1M|	}
  531|       |
  532|  30.1M|      for (i = 0; i < p + 1; ++i)
  ------------------
  |  |  236|  30.1M|#define p 761
  ------------------
  |  Branch (532:19): [True: 30.1M, False: 39.5k]
  ------------------
  533|  30.1M|	g[i] = F3_freeze (g[i] + sign * f[i]);
  534|  30.1M|      for (i = 0; i < p + 1; ++i)
  ------------------
  |  |  236|  30.1M|#define p 761
  ------------------
  |  Branch (534:19): [True: 30.1M, False: 39.5k]
  ------------------
  535|  30.1M|	r[i] = F3_freeze (r[i] + sign * v[i]);
  536|       |
  537|  30.1M|      for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  30.1M|#define p 761
  ------------------
  |  Branch (537:19): [True: 30.0M, False: 39.5k]
  ------------------
  538|  30.0M|	g[i] = g[i + 1];
  539|  39.5k|      g[p] = 0;
  ------------------
  |  |  236|  39.5k|#define p 761
  ------------------
  540|  39.5k|    }
  541|       |
  542|     26|  sign = f[0];
  543|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (543:15): [True: 19.7k, False: 26]
  ------------------
  544|  19.7k|    out[i] = sign * v[p - 1 - i];
  ------------------
  |  |  236|  19.7k|#define p 761
  ------------------
  545|       |
  546|     26|  return int16_t_nonzero_mask (delta);
  547|     26|}
sntrup761.c:int16_t_negative_mask:
  382|  79.0k|{
  383|  79.0k|  uint16_t u = x;
  384|  79.0k|  u >>= 15;
  385|  79.0k|  return -(int) u;
  386|       |  /* alternative with gcc -fwrapv: */
  387|       |  /* x>>15 compiles to CPU's arithmetic right shift */
  388|  79.0k|}
sntrup761.c:int16_t_nonzero_mask:
  371|  79.1k|{
  372|  79.1k|  uint16_t u = x;		/* 0, else 1...65535 */
  373|  79.1k|  uint32_t v = u;		/* 0, else 1...65535 */
  374|  79.1k|  v = -v;			/* 0, else 2^32-65535...2^32-1 */
  375|  79.1k|  v >>= 31;			/* 0, else 1 */
  376|  79.1k|  return -v;			/* 0, else -1 */
  377|  79.1k|}
sntrup761.c:F3_freeze:
  400|  60.2M|{
  401|  60.2M|  return int32_mod_uint14 (x + 1, 3) - 1;
  402|  60.2M|}
sntrup761.c:int32_mod_uint14:
  228|   135M|{
  229|   135M|  int32_t q;
  230|   135M|  uint16_t r;
  231|   135M|  int32_divmod_uint14 (&q, &r, x, m);
  232|   135M|  return r;
  233|   135M|}
sntrup761.c:int32_divmod_uint14:
  209|   135M|{
  210|   135M|  uint32_t uq, uq2;
  211|   135M|  uint16_t ur, ur2;
  212|   135M|  uint32_t mask;
  213|       |
  214|   135M|  uint32_divmod_uint14 (&uq, &ur, 0x80000000 + (uint32_t) x, m);
  215|   135M|  uint32_divmod_uint14 (&uq2, &ur2, 0x80000000, m);
  216|   135M|  ur -= ur2;
  217|   135M|  uq -= uq2;
  218|   135M|  mask = -(uint32_t) (ur >> 15);
  219|   135M|  ur += mask & m;
  220|   135M|  uq += mask;
  221|   135M|  *r = ur;
  222|   135M|  *q = uq;
  223|   135M|}
sntrup761.c:uint32_divmod_uint14:
  149|   271M|{
  150|   271M|  uint32_t v = 0x80000000;
  151|   271M|  uint32_t qpart;
  152|   271M|  uint32_t mask;
  153|       |
  154|   271M|  v /= m;
  155|       |
  156|       |  /* caller guarantees m > 0 */
  157|       |  /* caller guarantees m < 16384 */
  158|       |  /* vm <= 2^31 <= vm+m-1 */
  159|       |  /* xvm <= 2^31 x <= xvm+x(m-1) */
  160|       |
  161|   271M|  *q = 0;
  162|       |
  163|   271M|  qpart = (x * (uint64_t) v) >> 31;
  164|       |  /* 2^31 qpart <= xv <= 2^31 qpart + 2^31-1 */
  165|       |  /* 2^31 qpart m <= xvm <= 2^31 qpart m + (2^31-1)m */
  166|       |  /* 2^31 qpart m <= 2^31 x <= 2^31 qpart m + (2^31-1)m + x(m-1) */
  167|       |  /* 0 <= 2^31 newx <= (2^31-1)m + x(m-1) */
  168|       |  /* 0 <= newx <= (1-1/2^31)m + x(m-1)/2^31 */
  169|       |  /* 0 <= newx <= (1-1/2^31)(2^14-1) + (2^32-1)((2^14-1)-1)/2^31 */
  170|       |
  171|   271M|  x -= qpart * m;
  172|   271M|  *q += qpart;
  173|       |  /* x <= 49146 */
  174|       |
  175|   271M|  qpart = (x * (uint64_t) v) >> 31;
  176|       |  /* 0 <= newx <= (1-1/2^31)m + x(m-1)/2^31 */
  177|       |  /* 0 <= newx <= m + 49146(2^14-1)/2^31 */
  178|       |  /* 0 <= newx <= m + 0.4 */
  179|       |  /* 0 <= newx <= m */
  180|       |
  181|   271M|  x -= qpart * m;
  182|   271M|  *q += qpart;
  183|       |  /* x <= m */
  184|       |
  185|   271M|  x -= m;
  186|   271M|  *q += 1;
  187|   271M|  mask = -(x >> 31);
  188|   271M|  x += mask & (uint32_t) m;
  189|   271M|  *q += mask;
  190|       |  /* x < m */
  191|       |
  192|   271M|  *r = x;
  193|   271M|}
sntrup761.c:Rq_recip3:
  598|     26|{
  599|     26|  Fq f[p + 1], g[p + 1], v[p + 1], r[p + 1];
  600|     26|  int i, loop, delta;
  601|     26|  int swap, t;
  602|     26|  int32_t f0, g0;
  603|     26|  Fq scale;
  604|       |
  605|  19.8k|  for (i = 0; i < p + 1; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (605:15): [True: 19.8k, False: 26]
  ------------------
  606|  19.8k|    v[i] = 0;
  607|  19.8k|  for (i = 0; i < p + 1; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (607:15): [True: 19.8k, False: 26]
  ------------------
  608|  19.8k|    r[i] = 0;
  609|     26|  r[0] = Fq_recip (3);
  610|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (610:15): [True: 19.7k, False: 26]
  ------------------
  611|  19.7k|    f[i] = 0;
  612|     26|  f[0] = 1;
  613|     26|  f[p - 1] = f[p] = -1;
  ------------------
  |  |  236|     26|#define p 761
  ------------------
                f[p - 1] = f[p] = -1;
  ------------------
  |  |  236|     26|#define p 761
  ------------------
  614|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (614:15): [True: 19.7k, False: 26]
  ------------------
  615|  19.7k|    g[p - 1 - i] = in[i];
  ------------------
  |  |  236|  19.7k|#define p 761
  ------------------
  616|     26|  g[p] = 0;
  ------------------
  |  |  236|     26|#define p 761
  ------------------
  617|       |
  618|     26|  delta = 1;
  619|       |
  620|  39.5k|  for (loop = 0; loop < 2 * p - 1; ++loop)
  ------------------
  |  |  236|  39.5k|#define p 761
  ------------------
  |  Branch (620:18): [True: 39.5k, False: 26]
  ------------------
  621|  39.5k|    {
  622|  30.1M|      for (i = p; i > 0; --i)
  ------------------
  |  |  236|  39.5k|#define p 761
  ------------------
  |  Branch (622:19): [True: 30.0M, False: 39.5k]
  ------------------
  623|  30.0M|	v[i] = v[i - 1];
  624|  39.5k|      v[0] = 0;
  625|       |
  626|  39.5k|      swap = int16_t_negative_mask (-delta) & int16_t_nonzero_mask (g[0]);
  627|  39.5k|      delta ^= swap & (delta ^ -delta);
  628|  39.5k|      delta += 1;
  629|       |
  630|  30.1M|      for (i = 0; i < p + 1; ++i)
  ------------------
  |  |  236|  30.1M|#define p 761
  ------------------
  |  Branch (630:19): [True: 30.1M, False: 39.5k]
  ------------------
  631|  30.1M|	{
  632|  30.1M|	  t = swap & (f[i] ^ g[i]);
  633|  30.1M|	  f[i] ^= t;
  634|  30.1M|	  g[i] ^= t;
  635|  30.1M|	  t = swap & (v[i] ^ r[i]);
  636|  30.1M|	  v[i] ^= t;
  637|  30.1M|	  r[i] ^= t;
  638|  30.1M|	}
  639|       |
  640|  39.5k|      f0 = f[0];
  641|  39.5k|      g0 = g[0];
  642|  30.1M|      for (i = 0; i < p + 1; ++i)
  ------------------
  |  |  236|  30.1M|#define p 761
  ------------------
  |  Branch (642:19): [True: 30.1M, False: 39.5k]
  ------------------
  643|  30.1M|	g[i] = Fq_freeze (f0 * g[i] - g0 * f[i]);
  644|  30.1M|      for (i = 0; i < p + 1; ++i)
  ------------------
  |  |  236|  30.1M|#define p 761
  ------------------
  |  Branch (644:19): [True: 30.1M, False: 39.5k]
  ------------------
  645|  30.1M|	r[i] = Fq_freeze (f0 * r[i] - g0 * v[i]);
  646|       |
  647|  30.1M|      for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  30.1M|#define p 761
  ------------------
  |  Branch (647:19): [True: 30.0M, False: 39.5k]
  ------------------
  648|  30.0M|	g[i] = g[i + 1];
  649|  39.5k|      g[p] = 0;
  ------------------
  |  |  236|  39.5k|#define p 761
  ------------------
  650|  39.5k|    }
  651|       |
  652|     26|  scale = Fq_recip (f[0]);
  653|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (653:15): [True: 19.7k, False: 26]
  ------------------
  654|  19.7k|    out[i] = Fq_freeze (scale * (int32_t) v[p - 1 - i]);
  ------------------
  |  |  236|  19.7k|#define p 761
  ------------------
  655|       |
  656|     26|  return int16_t_nonzero_mask (delta);
  657|     26|}
sntrup761.c:Fq_recip:
  420|     52|{
  421|     52|  int i = 1;
  422|     52|  Fq ai = a1;
  423|       |
  424|   238k|  while (i < q - 2)
  ------------------
  |  |  237|   238k|#define q 4591
  ------------------
  |  Branch (424:10): [True: 238k, False: 52]
  ------------------
  425|   238k|    {
  426|   238k|      ai = Fq_freeze (a1 * (int32_t) ai);
  427|   238k|      i += 1;
  428|   238k|    }
  429|     52|  return ai;
  430|     52|}
sntrup761.c:Fq_freeze:
  414|  75.6M|{
  415|  75.6M|  return int32_mod_uint14 (x + q12, q) - q12;
  ------------------
  |  |  406|  75.6M|#define q12 ((q-1)/2)
  |  |  ------------------
  |  |  |  |  237|  75.6M|#define q 4591
  |  |  ------------------
  ------------------
                return int32_mod_uint14 (x + q12, q) - q12;
  ------------------
  |  |  237|  75.6M|#define q 4591
  ------------------
                return int32_mod_uint14 (x + q12, q) - q12;
  ------------------
  |  |  406|  75.6M|#define q12 ((q-1)/2)
  |  |  ------------------
  |  |  |  |  237|  75.6M|#define q 4591
  |  |  ------------------
  ------------------
  416|  75.6M|}
sntrup761.c:Rq_mult_small:
  554|     26|{
  555|     26|  Fq fg[p + p - 1];
  556|     26|  Fq result;
  557|     26|  int i, j;
  558|       |
  559|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (559:15): [True: 19.7k, False: 26]
  ------------------
  560|  19.7k|    {
  561|  19.7k|      result = 0;
  562|  7.55M|      for (j = 0; j <= i; ++j)
  ------------------
  |  Branch (562:19): [True: 7.53M, False: 19.7k]
  ------------------
  563|  7.53M|	result = Fq_freeze (result + f[j] * (int32_t) g[i - j]);
  564|  19.7k|      fg[i] = result;
  565|  19.7k|    }
  566|  19.7k|  for (i = p; i < p + p - 1; ++i)
  ------------------
  |  |  236|     26|#define p 761
  ------------------
                for (i = p; i < p + p - 1; ++i)
  ------------------
  |  |  236|  19.7k|#define p 761
  ------------------
                for (i = p; i < p + p - 1; ++i)
  ------------------
  |  |  236|  19.7k|#define p 761
  ------------------
  |  Branch (566:15): [True: 19.7k, False: 26]
  ------------------
  567|  19.7k|    {
  568|  19.7k|      result = 0;
  569|  7.53M|      for (j = i - p + 1; j < p; ++j)
  ------------------
  |  |  236|  19.7k|#define p 761
  ------------------
                    for (j = i - p + 1; j < p; ++j)
  ------------------
  |  |  236|  7.53M|#define p 761
  ------------------
  |  Branch (569:27): [True: 7.51M, False: 19.7k]
  ------------------
  570|  7.51M|	result = Fq_freeze (result + f[j] * (int32_t) g[i - j]);
  571|  19.7k|      fg[i] = result;
  572|  19.7k|    }
  573|       |
  574|  19.7k|  for (i = p + p - 2; i >= p; --i)
  ------------------
  |  |  236|     26|#define p 761
  ------------------
                for (i = p + p - 2; i >= p; --i)
  ------------------
  |  |  236|     26|#define p 761
  ------------------
                for (i = p + p - 2; i >= p; --i)
  ------------------
  |  |  236|  19.7k|#define p 761
  ------------------
  |  Branch (574:23): [True: 19.7k, False: 26]
  ------------------
  575|  19.7k|    {
  576|  19.7k|      fg[i - p] = Fq_freeze (fg[i - p] + fg[i]);
  ------------------
  |  |  236|  19.7k|#define p 761
  ------------------
                    fg[i - p] = Fq_freeze (fg[i - p] + fg[i]);
  ------------------
  |  |  236|  19.7k|#define p 761
  ------------------
  577|  19.7k|      fg[i - p + 1] = Fq_freeze (fg[i - p + 1] + fg[i]);
  ------------------
  |  |  236|  19.7k|#define p 761
  ------------------
                    fg[i - p + 1] = Fq_freeze (fg[i - p + 1] + fg[i]);
  ------------------
  |  |  236|  19.7k|#define p 761
  ------------------
  578|  19.7k|    }
  579|       |
  580|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (580:15): [True: 19.7k, False: 26]
  ------------------
  581|  19.7k|    h[i] = fg[i];
  582|     26|}
sntrup761.c:Rq_encode:
  846|     26|{
  847|     26|  uint16_t R[p], M[p];
  848|     26|  int i;
  849|       |
  850|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (850:15): [True: 19.7k, False: 26]
  ------------------
  851|  19.7k|    R[i] = r[i] + q12;
  ------------------
  |  |  406|  19.7k|#define q12 ((q-1)/2)
  |  |  ------------------
  |  |  |  |  237|  19.7k|#define q 4591
  |  |  ------------------
  ------------------
  852|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (852:15): [True: 19.7k, False: 26]
  ------------------
  853|  19.7k|    M[i] = q;
  ------------------
  |  |  237|  19.7k|#define q 4591
  ------------------
  854|     26|  Encode (s, R, M, p);
  ------------------
  |  |  236|     26|#define p 761
  ------------------
  855|     26|}
sntrup761.c:Encode:
  324|    286|{
  325|    286|  if (len == 1)
  ------------------
  |  Branch (325:7): [True: 26, False: 260]
  ------------------
  326|     26|    {
  327|     26|      uint16_t r = R[0];
  328|     26|      uint16_t m = M[0];
  329|     78|      while (m > 1)
  ------------------
  |  Branch (329:14): [True: 52, False: 26]
  ------------------
  330|     52|	{
  331|     52|	  *out++ = r;
  332|     52|	  r >>= 8;
  333|     52|	  m = (m + 255) >> 8;
  334|     52|	}
  335|     26|    }
  336|    286|  if (len > 1)
  ------------------
  |  Branch (336:7): [True: 260, False: 26]
  ------------------
  337|    260|    {
  338|    260|      uint16_t R2[(MAX_LEN + 1) / 2];
  339|    260|      uint16_t M2[(MAX_LEN + 1) / 2];
  340|    260|      long long i;
  341|  20.0k|      for (i = 0; i < len - 1; i += 2)
  ------------------
  |  Branch (341:19): [True: 19.7k, False: 260]
  ------------------
  342|  19.7k|	{
  343|  19.7k|	  uint32_t m0 = M[i];
  344|  19.7k|	  uint32_t r = R[i] + R[i + 1] * m0;
  345|  19.7k|	  uint32_t m = M[i + 1] * m0;
  346|  49.8k|	  while (m >= 16384)
  ------------------
  |  Branch (346:11): [True: 30.0k, False: 19.7k]
  ------------------
  347|  30.0k|	    {
  348|  30.0k|	      *out++ = r;
  349|  30.0k|	      r >>= 8;
  350|  30.0k|	      m = (m + 255) >> 8;
  351|  30.0k|	    }
  352|  19.7k|	  R2[i / 2] = r;
  353|  19.7k|	  M2[i / 2] = m;
  354|  19.7k|	}
  355|    260|      if (i < len)
  ------------------
  |  Branch (355:11): [True: 104, False: 156]
  ------------------
  356|    104|	{
  357|    104|	  R2[i / 2] = R[i];
  358|    104|	  M2[i / 2] = M[i];
  359|    104|	}
  360|    260|      Encode (out, R2, M2, (len + 1) / 2);
  361|    260|    }
  362|    286|}
sntrup761.c:Small_encode:
  805|     52|{
  806|     52|  small x;
  807|     52|  int i;
  808|       |
  809|  9.93k|  for (i = 0; i < p / 4; ++i)
  ------------------
  |  |  236|  9.93k|#define p 761
  ------------------
  |  Branch (809:15): [True: 9.88k, False: 52]
  ------------------
  810|  9.88k|    {
  811|  9.88k|      x = *f++ + 1;
  812|  9.88k|      x += (*f++ + 1) << 2;
  813|  9.88k|      x += (*f++ + 1) << 4;
  814|  9.88k|      x += (*f++ + 1) << 6;
  815|  9.88k|      *s++ = x;
  816|  9.88k|    }
  817|     52|  x = *f++ + 1;
  818|     52|  *s++ = x;
  819|     52|}
sntrup761.c:Hash_prefix:
  693|     26|{
  694|     26|#define MAX_X_LEN 1158
  695|     26|  unsigned char x[MAX_X_LEN + 1];
  696|     26|  unsigned char h[64];
  697|     26|  int i;
  698|       |
  699|     26|  x[0] = b;
  700|  30.1k|  for (i = 0; i < inlen; ++i)
  ------------------
  |  Branch (700:15): [True: 30.1k, False: 26]
  ------------------
  701|  30.1k|    x[i + 1] = in[i];
  702|     26|  sha512 (x, inlen + 1, h);
  703|    858|  for (i = 0; i < 32; ++i)
  ------------------
  |  Branch (703:15): [True: 832, False: 26]
  ------------------
  704|    832|    out[i] = h[i];
  705|     26|}
sntrup761.c:Short_random:
  725|     26|{
  726|     26|  uint32_t L[p];
  727|     26|  int i;
  728|       |
  729|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (729:15): [True: 19.7k, False: 26]
  ------------------
  730|  19.7k|    L[i] = urandom32 (random_ctx, random);
  731|     26|  Short_fromlist (out, L);
  732|     26|}
sntrup761.c:Short_fromlist:
  673|     26|{
  674|     26|  uint32_t L[p];
  675|     26|  int i;
  676|       |
  677|  7.46k|  for (i = 0; i < w; ++i)
  ------------------
  |  |  240|  7.46k|#define w 286
  ------------------
  |  Branch (677:15): [True: 7.43k, False: 26]
  ------------------
  678|  7.43k|    L[i] = in[i] & (uint32_t) - 2;
  679|  12.3k|  for (i = w; i < p; ++i)
  ------------------
  |  |  240|     26|#define w 286
  ------------------
                for (i = w; i < p; ++i)
  ------------------
  |  |  236|  12.3k|#define p 761
  ------------------
  |  Branch (679:15): [True: 12.3k, False: 26]
  ------------------
  680|  12.3k|    L[i] = (in[i] & (uint32_t) - 3) | 1;
  681|     26|  crypto_sort_uint32 (L, p);
  ------------------
  |  |  236|     26|#define p 761
  ------------------
  682|  19.8k|  for (i = 0; i < p; ++i)
  ------------------
  |  |  236|  19.8k|#define p 761
  ------------------
  |  Branch (682:15): [True: 19.7k, False: 26]
  ------------------
  683|  19.7k|    out[i] = (L[i] & 3) - 1;
  684|     26|}
sntrup761.c:crypto_sort_uint32:
  126|     26|{
  127|     26|  uint32_t *x = array;
  128|     26|  long long j;
  129|  19.8k|  for (j = 0; j < n; ++j)
  ------------------
  |  Branch (129:15): [True: 19.7k, False: 26]
  ------------------
  130|  19.7k|    x[j] ^= 0x80000000;
  131|     26|  crypto_sort_int32 (array, n);
  132|  19.8k|  for (j = 0; j < n; ++j)
  ------------------
  |  Branch (132:15): [True: 19.7k, False: 26]
  ------------------
  133|  19.7k|    x[j] ^= 0x80000000;
  134|     26|}
sntrup761.c:crypto_sort_int32:
   49|     26|{
   50|     26|  long long top, p, q, r, i, j;
   51|     26|  int32_t *x = array;
   52|       |
   53|     26|  if (n < 2)
  ------------------
  |  Branch (53:7): [True: 0, False: 26]
  ------------------
   54|      0|    return;
   55|     26|  top = 1;
   56|    260|  while (top < n - top)
  ------------------
  |  Branch (56:10): [True: 234, False: 26]
  ------------------
   57|    234|    top += top;
   58|       |
   59|    286|  for (p = top; p >= 1; p >>= 1)
  ------------------
  |  Branch (59:17): [True: 260, False: 26]
  ------------------
   60|    260|    {
   61|    260|      i = 0;
   62|  19.8k|      while (i + 2 * p <= n)
  ------------------
  |  Branch (62:14): [True: 19.6k, False: 260]
  ------------------
   63|  19.6k|	{
   64|  99.3k|	  for (j = i; j < i + p; ++j)
  ------------------
  |  Branch (64:16): [True: 79.7k, False: 19.6k]
  ------------------
   65|  79.7k|	    int32_MINMAX (x[j], x[j + p]);
  ------------------
  |  |   35|  79.7k|#define int32_MINMAX(a,b) \
  |  |   36|  79.7k|do { \
  |  |   37|  79.7k|  int64_t ab = (int64_t)b ^ (int64_t)a; \
  |  |   38|  79.7k|  int64_t c = (int64_t)b - (int64_t)a; \
  |  |   39|  79.7k|  c ^= ab & (c ^ b); \
  |  |   40|  79.7k|  c >>= 31; \
  |  |   41|  79.7k|  c &= ab; \
  |  |   42|  79.7k|  a ^= c; \
  |  |   43|  79.7k|  b ^= c; \
  |  |   44|  79.7k|} while(0)
  |  |  ------------------
  |  |  |  Branch (44:9): [Folded, False: 79.7k]
  |  |  ------------------
  ------------------
   66|  19.6k|	  i += 2 * p;
   67|  19.6k|	}
   68|  12.2k|      for (j = i; j < n - p; ++j)
  ------------------
  |  Branch (68:19): [True: 12.0k, False: 260]
  ------------------
   69|  12.0k|	int32_MINMAX (x[j], x[j + p]);
  ------------------
  |  |   35|  12.0k|#define int32_MINMAX(a,b) \
  |  |   36|  12.0k|do { \
  |  |   37|  12.0k|  int64_t ab = (int64_t)b ^ (int64_t)a; \
  |  |   38|  12.0k|  int64_t c = (int64_t)b - (int64_t)a; \
  |  |   39|  12.0k|  c ^= ab & (c ^ b); \
  |  |   40|  12.0k|  c >>= 31; \
  |  |   41|  12.0k|  c &= ab; \
  |  |   42|  12.0k|  a ^= c; \
  |  |   43|  12.0k|  b ^= c; \
  |  |   44|  12.0k|} while(0)
  |  |  ------------------
  |  |  |  Branch (44:9): [Folded, False: 12.0k]
  |  |  ------------------
  ------------------
   70|       |
   71|    260|      i = 0;
   72|    260|      j = 0;
   73|  1.43k|      for (q = top; q > p; q >>= 1)
  ------------------
  |  Branch (73:21): [True: 1.17k, False: 260]
  ------------------
   74|  1.17k|	{
   75|  1.17k|	  if (j != i)
  ------------------
  |  Branch (75:8): [True: 338, False: 832]
  ------------------
   76|    338|	    for (;;)
   77|    650|	      {
   78|    650|		int32_t a;
   79|    650|		if (j == n - q)
  ------------------
  |  Branch (79:7): [True: 0, False: 650]
  ------------------
   80|      0|		  goto done;
   81|    650|		a = x[j + p];
   82|  3.01k|		for (r = q; r > p; r >>= 1)
  ------------------
  |  Branch (82:15): [True: 2.36k, False: 650]
  ------------------
   83|  2.36k|		  int32_MINMAX (a, x[j + r]);
  ------------------
  |  |   35|  3.01k|#define int32_MINMAX(a,b) \
  |  |   36|  3.01k|do { \
  |  |   37|  2.36k|  int64_t ab = (int64_t)b ^ (int64_t)a; \
  |  |   38|  2.36k|  int64_t c = (int64_t)b - (int64_t)a; \
  |  |   39|  2.36k|  c ^= ab & (c ^ b); \
  |  |   40|  2.36k|  c >>= 31; \
  |  |   41|  2.36k|  c &= ab; \
  |  |   42|  2.36k|  a ^= c; \
  |  |   43|  2.36k|  b ^= c; \
  |  |   44|  2.36k|} while(0)
  |  |  ------------------
  |  |  |  Branch (44:9): [Folded, False: 2.36k]
  |  |  ------------------
  ------------------
   84|    650|		x[j + p] = a;
   85|    650|		++j;
   86|    650|		if (j == i + p)
  ------------------
  |  Branch (86:7): [True: 338, False: 312]
  ------------------
   87|    338|		  {
   88|    338|		    i += 2 * p;
   89|    338|		    break;
   90|    338|		  }
   91|    650|	      }
   92|  20.3k|	  while (i + p <= n - q)
  ------------------
  |  Branch (92:11): [True: 19.1k, False: 1.17k]
  ------------------
   93|  19.1k|	    {
   94|  91.1k|	      for (j = i; j < i + p; ++j)
  ------------------
  |  Branch (94:20): [True: 71.9k, False: 19.1k]
  ------------------
   95|  71.9k|		{
   96|  71.9k|		  int32_t a = x[j + p];
   97|   405k|		  for (r = q; r > p; r >>= 1)
  ------------------
  |  Branch (97:17): [True: 333k, False: 71.9k]
  ------------------
   98|   333k|		    int32_MINMAX (a, x[j + r]);
  ------------------
  |  |   35|   333k|#define int32_MINMAX(a,b) \
  |  |   36|   333k|do { \
  |  |   37|   333k|  int64_t ab = (int64_t)b ^ (int64_t)a; \
  |  |   38|   333k|  int64_t c = (int64_t)b - (int64_t)a; \
  |  |   39|   333k|  c ^= ab & (c ^ b); \
  |  |   40|   333k|  c >>= 31; \
  |  |   41|   333k|  c &= ab; \
  |  |   42|   333k|  a ^= c; \
  |  |   43|   333k|  b ^= c; \
  |  |   44|   333k|} while(0)
  |  |  ------------------
  |  |  |  Branch (44:9): [Folded, False: 333k]
  |  |  ------------------
  ------------------
   99|  71.9k|		  x[j + p] = a;
  100|  71.9k|		}
  101|  19.1k|	      i += 2 * p;
  102|  19.1k|	    }
  103|       |	  /* now i + p > n - q */
  104|  1.17k|	  j = i;
  105|  8.03k|	  while (j < n - q)
  ------------------
  |  Branch (105:11): [True: 6.86k, False: 1.17k]
  ------------------
  106|  6.86k|	    {
  107|  6.86k|	      int32_t a = x[j + p];
  108|  15.0k|	      for (r = q; r > p; r >>= 1)
  ------------------
  |  Branch (108:20): [True: 8.13k, False: 6.86k]
  ------------------
  109|  8.13k|		int32_MINMAX (a, x[j + r]);
  ------------------
  |  |   35|  8.13k|#define int32_MINMAX(a,b) \
  |  |   36|  8.13k|do { \
  |  |   37|  8.13k|  int64_t ab = (int64_t)b ^ (int64_t)a; \
  |  |   38|  8.13k|  int64_t c = (int64_t)b - (int64_t)a; \
  |  |   39|  8.13k|  c ^= ab & (c ^ b); \
  |  |   40|  8.13k|  c >>= 31; \
  |  |   41|  8.13k|  c &= ab; \
  |  |   42|  8.13k|  a ^= c; \
  |  |   43|  8.13k|  b ^= c; \
  |  |   44|  8.13k|} while(0)
  |  |  ------------------
  |  |  |  Branch (44:9): [Folded, False: 8.13k]
  |  |  ------------------
  ------------------
  110|  6.86k|	      x[j + p] = a;
  111|  6.86k|	      ++j;
  112|  6.86k|	    }
  113|       |
  114|  1.17k|	done:;
  115|  1.17k|	}
  116|    260|    }
  117|     26|}

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

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

ssh_client_hybrid_mlkem_init:
  201|    104|{
  202|    104|    struct ssh_crypto_struct *crypto = session->next_crypto;
  203|    104|    ssh_buffer client_init_buffer = NULL;
  204|    104|    int rc, ret = SSH_ERROR;
  ------------------
  |  |  317|    104|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  205|       |
  206|    104|    SSH_LOG(SSH_LOG_TRACE, "Initializing hybrid ML-KEM key exchange");
  ------------------
  |  |  283|    104|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  207|       |
  208|       |    /* Prepare a buffer to concatenate ML-KEM + ECDH public keys */
  209|    104|    client_init_buffer = ssh_buffer_new();
  210|    104|    if (client_init_buffer == NULL) {
  ------------------
  |  Branch (210:9): [True: 0, False: 104]
  ------------------
  211|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  212|      0|        goto cleanup;
  213|      0|    }
  214|       |
  215|       |    /* Generate an ML-KEM keypair */
  216|    104|    rc = ssh_mlkem_init(session);
  217|    104|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    104|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (217:9): [True: 0, False: 104]
  ------------------
  218|      0|        ssh_set_error(session, SSH_FATAL, "Failed to generate an ML-KEM keypair");
  ------------------
  |  |  313|      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|    104|    switch (crypto->kex_type) {
  230|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (230:5): [True: 0, False: 104]
  ------------------
  231|      0|        rc = ssh_curve25519_init(session);
  232|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (232:13): [True: 0, False: 0]
  ------------------
  233|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      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|      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)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      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)
  |  |  ------------------
  ------------------
  244|      0|                             "PP",
  245|      0|                             ssh_string_len(crypto->mlkem_client_pubkey),
  246|      0|                             ssh_string_data(crypto->mlkem_client_pubkey),
  247|      0|                             (size_t)CURVE25519_PUBKEY_SIZE,
  248|      0|                             crypto->curve25519_client_pubkey);
  249|      0|        break;
  250|    104|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (250:5): [True: 104, False: 0]
  ------------------
  251|       |#ifdef HAVE_MLKEM1024
  252|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  253|       |#endif
  254|    104|        rc = ssh_ecdh_init(session);
  255|    104|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    104|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (255:13): [True: 0, False: 104]
  ------------------
  256|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      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|    104|        rc = ssh_buffer_pack(client_init_buffer,
  ------------------
  |  |   50|    104|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    104|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    104|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    104|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    104|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    104|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    104|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  267|    104|                             "PP",
  268|    104|                             ssh_string_len(crypto->mlkem_client_pubkey),
  269|    104|                             ssh_string_data(crypto->mlkem_client_pubkey),
  270|    104|                             ssh_string_len(crypto->ecdh_client_pubkey),
  271|    104|                             ssh_string_data(crypto->ecdh_client_pubkey));
  272|       |
  273|    104|        break;
  274|      0|    default:
  ------------------
  |  Branch (274:5): [True: 0, False: 104]
  ------------------
  275|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX type");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  276|      0|        goto cleanup;
  277|    104|    }
  278|    104|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    104|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (278:9): [True: 0, False: 104]
  ------------------
  279|      0|        ssh_set_error(session, SSH_FATAL, "Failed to construct client init buffer");
  ------------------
  |  |  313|      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|    104|    ssh_string_free(crypto->hybrid_client_init);
  285|    104|    crypto->hybrid_client_init = ssh_string_new(ssh_buffer_get_len(client_init_buffer));
  286|    104|    if (crypto->hybrid_client_init == NULL) {
  ------------------
  |  Branch (286:9): [True: 0, False: 104]
  ------------------
  287|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  288|      0|        goto cleanup;
  289|      0|    }
  290|       |
  291|    104|    rc = ssh_string_fill(crypto->hybrid_client_init,
  292|    104|                         ssh_buffer_get(client_init_buffer),
  293|    104|                         ssh_buffer_get_len(client_init_buffer));
  294|    104|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    104|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (294:9): [True: 0, False: 104]
  ------------------
  295|      0|        ssh_set_error(session, SSH_FATAL, "Failed to convert client init to string");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  296|      0|        goto cleanup;
  297|      0|    }
  298|       |
  299|    104|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    104|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    104|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    104|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    104|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    104|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    104|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    104|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  300|    104|                         "bS",
  301|    104|                         SSH2_MSG_KEX_HYBRID_INIT,
  302|    104|                         crypto->hybrid_client_init);
  303|    104|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    104|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (303:9): [True: 0, False: 104]
  ------------------
  304|      0|        ssh_set_error(session, SSH_FATAL, "Failed to construct SSH_MSG_KEX_HYBRID_INIT");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  305|      0|        goto cleanup;
  306|      0|    }
  307|       |
  308|    104|    ssh_packet_set_callbacks(session, &ssh_hybrid_mlkem_client_callbacks);
  309|    104|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  310|       |
  311|    104|    rc = ssh_packet_send(session);
  312|    104|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    104|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (312:9): [True: 0, False: 104]
  ------------------
  313|      0|        ssh_set_error(session, SSH_FATAL, "Failed to send SSH_MSG_KEX_HYBRID_INIT");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  314|      0|        goto cleanup;
  315|      0|    }
  316|       |
  317|    104|    ret = SSH_OK;
  ------------------
  |  |  316|    104|#define SSH_OK 0     /* No error */
  ------------------
  318|       |
  319|    104|cleanup:
  320|    104|    ssh_buffer_free(client_init_buffer);
  321|    104|    return ret;
  322|    104|}
ssh_client_hybrid_mlkem_remove_callbacks:
  531|     68|{
  532|     68|    ssh_packet_remove_callbacks(session, &ssh_hybrid_mlkem_client_callbacks);
  533|     68|}
hybrid_mlkem.c:ssh_packet_client_hybrid_mlkem_reply:
  325|     68|{
  326|     68|    struct ssh_crypto_struct *crypto = session->next_crypto;
  327|     68|    const struct mlkem_type_info *mlkem_info = NULL;
  328|     68|    ssh_string pubkey_blob = NULL;
  329|     68|    ssh_string signature = NULL;
  330|     68|    ssh_mlkem_shared_secret mlkem_shared_secret;
  331|     68|    ssh_string ecdh_shared_secret = NULL;
  332|     68|    ssh_buffer server_reply_buffer = NULL;
  333|     68|    size_t read_len;
  334|     68|    size_t ecdh_server_pubkey_size;
  335|     68|    int rc;
  336|     68|    (void)type;
  337|     68|    (void)user;
  338|       |
  339|     68|    SSH_LOG(SSH_LOG_TRACE, "Received ML-KEM hybrid server reply");
  ------------------
  |  |  283|     68|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  340|       |
  341|     68|    ssh_client_hybrid_mlkem_remove_callbacks(session);
  342|       |
  343|     68|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
  344|     68|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (344:9): [True: 0, False: 68]
  ------------------
  345|      0|        ssh_set_error(session, SSH_FATAL, "Unknown ML-KEM type");
  ------------------
  |  |  313|      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|     68|    pubkey_blob = ssh_buffer_get_ssh_string(packet);
  351|     68|    if (pubkey_blob == NULL) {
  ------------------
  |  Branch (351:9): [True: 0, False: 68]
  ------------------
  352|      0|        ssh_set_error(session, SSH_FATAL, "No public key in packet");
  ------------------
  |  |  313|      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|     68|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  358|     68|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     68|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (358:9): [True: 64, False: 4]
  ------------------
  359|     64|        ssh_set_error(session, SSH_FATAL, "Failed to import public key");
  ------------------
  |  |  313|     64|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  360|     64|        session->session_state = SSH_SESSION_STATE_ERROR;
  361|     64|        goto cleanup;
  362|     64|    }
  363|       |
  364|       |    /* Get server reply containing ML-KEM ciphertext + ECDH public key */
  365|      4|    ssh_string_free(crypto->hybrid_server_reply);
  366|      4|    crypto->hybrid_server_reply = ssh_buffer_get_ssh_string(packet);
  367|      4|    if (crypto->hybrid_server_reply == NULL) {
  ------------------
  |  Branch (367:9): [True: 2, False: 2]
  ------------------
  368|      2|        ssh_set_error(session, SSH_FATAL, "No server reply in packet");
  ------------------
  |  |  313|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  369|      2|        session->session_state = SSH_SESSION_STATE_ERROR;
  370|      2|        goto cleanup;
  371|      2|    }
  372|       |
  373|      2|    server_reply_buffer = ssh_buffer_new();
  374|      2|    if (server_reply_buffer == NULL) {
  ------------------
  |  Branch (374:9): [True: 0, False: 2]
  ------------------
  375|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  376|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  377|      0|        goto cleanup;
  378|      0|    }
  379|       |
  380|      2|    rc = ssh_buffer_add_data(server_reply_buffer,
  381|      2|                             ssh_string_data(crypto->hybrid_server_reply),
  382|      2|                             ssh_string_len(crypto->hybrid_server_reply));
  383|      2|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (383:9): [True: 0, False: 2]
  ------------------
  384|      0|        ssh_set_error(session, SSH_FATAL, "Failed to pack server reply to a buffer");
  ------------------
  |  |  313|      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|      2|    ssh_string_free(crypto->mlkem_ciphertext);
  391|      2|    crypto->mlkem_ciphertext = ssh_string_new(mlkem_info->ciphertext_size);
  392|      2|    if (crypto->mlkem_ciphertext == NULL) {
  ------------------
  |  Branch (392:9): [True: 0, False: 2]
  ------------------
  393|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  394|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  395|      0|        goto cleanup;
  396|      0|    }
  397|       |
  398|      2|    read_len = ssh_buffer_get_data(server_reply_buffer,
  399|      2|                                   ssh_string_data(crypto->mlkem_ciphertext),
  400|      2|                                   mlkem_info->ciphertext_size);
  401|      2|    if (read_len != mlkem_info->ciphertext_size) {
  ------------------
  |  Branch (401:9): [True: 2, False: 0]
  ------------------
  402|      2|        ssh_set_error(session,
  ------------------
  |  |  313|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  403|      2|                      SSH_FATAL,
  404|      2|                      "Could not read ML-KEM ciphertext from "
  405|      2|                      "the server reply buffer, buffer too short");
  406|      2|        session->session_state = SSH_SESSION_STATE_ERROR;
  407|      2|        goto cleanup;
  408|      2|    }
  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|      0|    switch (crypto->kex_type) {
  418|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (418:5): [True: 0, False: 0]
  ------------------
  419|      0|        read_len = ssh_buffer_get_data(server_reply_buffer,
  420|      0|                                       crypto->curve25519_server_pubkey,
  421|      0|                                       CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   40|      0|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  422|      0|        if (read_len != CURVE25519_PUBKEY_SIZE) {
  ------------------
  |  |   40|      0|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  |  Branch (422:13): [True: 0, False: 0]
  ------------------
  423|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      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|      0|        if (ssh_buffer_get_len(server_reply_buffer) > 0) {
  ------------------
  |  Branch (430:13): [True: 0, False: 0]
  ------------------
  431|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      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|      0|        break;
  443|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (443:5): [True: 0, False: 0]
  ------------------
  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);
  ------------------
  |  |  320|      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: 0]
  ------------------
  465|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX type");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  466|      0|        goto cleanup;
  467|      0|    }
  468|       |
  469|       |    /* Decapsulate ML-KEM shared secret */
  470|      0|    rc = ssh_mlkem_decapsulate(session, mlkem_shared_secret);
  471|      0|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (471:9): [True: 0, False: 0]
  ------------------
  472|      0|        ssh_set_error(session, SSH_FATAL, "ML-KEM decapsulation failed");
  ------------------
  |  |  313|      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|      0|    ecdh_shared_secret = derive_ecdh_secret(session);
  485|      0|    if (ecdh_shared_secret == NULL) {
  ------------------
  |  Branch (485:9): [True: 0, False: 0]
  ------------------
  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|      0|    rc = derive_hybrid_secret(session, mlkem_shared_secret, ecdh_shared_secret);
  498|      0|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (498:9): [True: 0, False: 0]
  ------------------
  499|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  500|      0|        goto cleanup;
  501|      0|    }
  502|       |
  503|       |    /* Get signature for verification */
  504|      0|    signature = ssh_buffer_get_ssh_string(packet);
  505|      0|    if (signature == NULL) {
  ------------------
  |  Branch (505:9): [True: 0, False: 0]
  ------------------
  506|      0|        ssh_set_error(session, SSH_FATAL, "No signature in packet");
  ------------------
  |  |  313|      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|      0|    crypto->dh_server_signature = signature;
  511|       |
  512|       |    /* Send the MSG_NEWKEYS */
  513|      0|    rc = ssh_packet_send_newkeys(session);
  514|      0|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (514:9): [True: 0, False: 0]
  ------------------
  515|      0|        ssh_set_error(session, SSH_FATAL, "Failed to send SSH_MSG_NEWKEYS");
  ------------------
  |  |  313|      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|      0|    session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  520|       |
  521|     68|cleanup:
  522|     68|    ssh_burn(mlkem_shared_secret, sizeof(mlkem_shared_secret));
  ------------------
  |  |  390|     68|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  523|     68|    ssh_string_burn(ecdh_shared_secret);
  524|     68|    ssh_string_free(ecdh_shared_secret);
  525|     68|    ssh_string_free(pubkey_blob);
  526|     68|    ssh_buffer_free(server_reply_buffer);
  527|     68|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     68|#define SSH_PACKET_USED 1
  ------------------
  528|      0|}

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

ssh_kex_get_default_methods:
  300|    442|{
  301|    442|    if (type >= SSH_KEX_METHODS) {
  ------------------
  |  |   27|    442|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (301:9): [True: 0, False: 442]
  ------------------
  302|      0|        return NULL;
  303|      0|    }
  304|       |
  305|    442|    return default_methods[type];
  306|    442|}
ssh_packet_kexinit:
  397|    288|{
  398|    288|    int i, ok;
  399|    288|    struct ssh_crypto_struct *crypto = session->next_crypto;
  400|    288|    int server_kex = session->server;
  401|    288|    ssh_string str = NULL;
  402|    288|    char *strings[SSH_KEX_METHODS] = {0};
  403|    288|    int rc = SSH_ERROR;
  ------------------
  |  |  317|    288|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  404|    288|    size_t len;
  405|       |
  406|    288|    uint8_t first_kex_packet_follows = 0;
  407|    288|    uint32_t kexinit_reserved = 0;
  408|       |
  409|    288|    (void)type;
  410|    288|    (void)user;
  411|       |
  412|    288|    SSH_LOG(SSH_LOG_TRACE, "KEXINIT received");
  ------------------
  |  |  283|    288|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  413|       |
  414|    288|    if (session->session_state == SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (414:9): [True: 0, False: 288]
  ------------------
  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");
  ------------------
  |  |  283|      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.");
  ------------------
  |  |  283|      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,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  426|      0|                          "SSH_KEXINIT received in wrong state");
  427|      0|            goto error;
  428|      0|        }
  429|    288|    } else if (session->session_state != SSH_SESSION_STATE_INITIAL_KEX) {
  ------------------
  |  Branch (429:16): [True: 0, False: 288]
  ------------------
  430|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      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|    288|    if (server_kex) {
  ------------------
  |  Branch (435:9): [True: 0, False: 288]
  ------------------
  436|      0|#ifdef WITH_SERVER
  437|      0|        len = ssh_buffer_get_data(packet, crypto->client_kex.cookie, 16);
  438|      0|        if (len != 16) {
  ------------------
  |  Branch (438:13): [True: 0, False: 0]
  ------------------
  439|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      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|      0|        ok = ssh_hashbufin_add_cookie(session, crypto->client_kex.cookie);
  445|      0|        if (ok < 0) {
  ------------------
  |  Branch (445:13): [True: 0, False: 0]
  ------------------
  446|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      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|      0|        ok = server_set_kex(session);
  452|      0|        if (ok == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (452:13): [True: 0, False: 0]
  ------------------
  453|      0|            goto error;
  454|      0|        }
  455|      0|#endif /* WITH_SERVER */
  456|    288|    } else {
  457|    288|        len = ssh_buffer_get_data(packet, crypto->server_kex.cookie, 16);
  458|    288|        if (len != 16) {
  ------------------
  |  Branch (458:13): [True: 1, False: 287]
  ------------------
  459|      1|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  460|      1|                          "ssh_packet_kexinit: no cookie in packet");
  461|      1|            goto error;
  462|      1|        }
  463|       |
  464|    287|        ok = ssh_hashbufin_add_cookie(session, crypto->server_kex.cookie);
  465|    287|        if (ok < 0) {
  ------------------
  |  Branch (465:13): [True: 0, False: 287]
  ------------------
  466|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      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|    287|        ok = ssh_set_client_kex(session);
  472|    287|        if (ok == SSH_ERROR) {
  ------------------
  |  |  317|    287|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (472:13): [True: 0, False: 287]
  ------------------
  473|      0|            goto error;
  474|      0|        }
  475|    287|    }
  476|       |
  477|  3.00k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.00k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (477:17): [True: 2.74k, False: 267]
  ------------------
  478|  2.74k|        str = ssh_buffer_get_ssh_string(packet);
  479|  2.74k|        if (str == NULL) {
  ------------------
  |  Branch (479:13): [True: 20, False: 2.72k]
  ------------------
  480|     20|          goto error;
  481|     20|        }
  482|       |
  483|  2.72k|        rc = ssh_buffer_add_ssh_string(session->in_hashbuf, str);
  484|  2.72k|        if (rc < 0) {
  ------------------
  |  Branch (484:13): [True: 0, False: 2.72k]
  ------------------
  485|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      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|  2.72k|        strings[i] = ssh_string_to_char(str);
  491|  2.72k|        if (strings[i] == NULL) {
  ------------------
  |  Branch (491:13): [True: 0, False: 2.72k]
  ------------------
  492|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  493|      0|            goto error;
  494|      0|        }
  495|  2.72k|        SSH_STRING_FREE(str);
  ------------------
  |  |  924|  2.72k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 2.72k, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 2.72k]
  |  |  ------------------
  ------------------
  496|  2.72k|        str = NULL;
  497|  2.72k|    }
  498|       |
  499|       |    /* copy the peer kex info into an array of strings */
  500|    267|    if (server_kex) {
  ------------------
  |  Branch (500:9): [True: 0, False: 267]
  ------------------
  501|      0|#ifdef WITH_SERVER
  502|      0|        for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|      0|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (502:21): [True: 0, False: 0]
  ------------------
  503|      0|            crypto->client_kex.methods[i] = strings[i];
  504|      0|        }
  505|      0|#endif /* WITH_SERVER */
  506|    267|    } else { /* client */
  507|  2.93k|        for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  2.93k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (507:21): [True: 2.67k, False: 267]
  ------------------
  508|  2.67k|            crypto->server_kex.methods[i] = strings[i];
  509|  2.67k|        }
  510|    267|    }
  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|    267|    rc = ssh_buffer_get_u8(packet, &first_kex_packet_follows);
  524|    267|    if (rc != 1) {
  ------------------
  |  Branch (524:9): [True: 0, False: 267]
  ------------------
  525|      0|        goto error;
  526|      0|    }
  527|       |
  528|    267|    rc = ssh_buffer_add_u8(session->in_hashbuf, first_kex_packet_follows);
  529|    267|    if (rc < 0) {
  ------------------
  |  Branch (529:9): [True: 0, False: 267]
  ------------------
  530|      0|        goto error;
  531|      0|    }
  532|       |
  533|    267|    rc = ssh_buffer_add_u32(session->in_hashbuf, kexinit_reserved);
  534|    267|    if (rc < 0) {
  ------------------
  |  Branch (534:9): [True: 0, False: 267]
  ------------------
  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|    267|    if (first_kex_packet_follows || session->send_first_kex_follows) {
  ------------------
  |  Branch (544:9): [True: 167, False: 100]
  |  Branch (544:37): [True: 0, False: 100]
  ------------------
  545|    167|        char **client_methods = crypto->client_kex.methods;
  546|    167|        char **server_methods = crypto->server_kex.methods;
  547|    167|        session->first_kex_follows_guess_wrong =
  548|    167|            cmp_first_kex_algo(client_methods[SSH_KEX],
  ------------------
  |  Branch (548:13): [True: 166, False: 1]
  ------------------
  549|    167|                               server_methods[SSH_KEX]) ||
  550|      1|            cmp_first_kex_algo(client_methods[SSH_HOSTKEYS],
  ------------------
  |  Branch (550:13): [True: 0, False: 1]
  ------------------
  551|      1|                               server_methods[SSH_HOSTKEYS]);
  552|    167|            SSH_LOG(SSH_LOG_DEBUG, "The initial guess was %s.",
  ------------------
  |  |  283|    334|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 166, False: 1]
  |  |  ------------------
  ------------------
  553|    167|                    session->first_kex_follows_guess_wrong ? "wrong" : "right");
  554|    167|    }
  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|    267|    if (server_kex) {
  ------------------
  |  Branch (560:9): [True: 0, False: 267]
  ------------------
  561|      0|        ok = match_group(crypto->client_kex.methods[SSH_KEX],
  562|      0|                         KEX_STRICT_CLIENT);
  ------------------
  |  |  196|      0|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  563|      0|        if (ok) {
  ------------------
  |  Branch (563:13): [True: 0, False: 0]
  ------------------
  564|      0|            SSH_LOG(SSH_LOG_DEBUG, "Client supports strict kex, enabling.");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  565|      0|            session->flags |= SSH_SESSION_FLAG_KEX_STRICT;
  ------------------
  |  |   90|      0|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  566|      0|        }
  567|    267|    } else {
  568|       |        /* client kex */
  569|    267|        ok = match_group(crypto->server_kex.methods[SSH_KEX],
  570|    267|                         KEX_STRICT_SERVER);
  ------------------
  |  |  197|    267|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  571|    267|        if (ok) {
  ------------------
  |  Branch (571:13): [True: 5, False: 262]
  ------------------
  572|      5|            SSH_LOG(SSH_LOG_DEBUG, "Server supports strict kex, enabling.");
  ------------------
  |  |  283|      5|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  573|      5|            session->flags |= SSH_SESSION_FLAG_KEX_STRICT;
  ------------------
  |  |   90|      5|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  574|      5|        }
  575|    267|    }
  576|    267|#ifdef WITH_SERVER
  577|    267|    if (server_kex) {
  ------------------
  |  Branch (577:9): [True: 0, False: 267]
  ------------------
  578|       |        /*
  579|       |         * If client sent a ext-info-c message in the kex list, it supports
  580|       |         * RFC 8308 extension negotiation.
  581|       |         */
  582|      0|        ok = match_group(crypto->client_kex.methods[SSH_KEX],
  583|      0|                         KEX_EXTENSION_CLIENT);
  ------------------
  |  |  194|      0|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  584|      0|        if (ok) {
  ------------------
  |  Branch (584:13): [True: 0, False: 0]
  ------------------
  585|      0|            const char *hostkeys = NULL, *wanted_hostkeys = NULL;
  586|       |
  587|       |            /* The client supports extension negotiation */
  588|      0|            session->extensions |= SSH_EXT_NEGOTIATION;
  ------------------
  |  |  124|      0|#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|      0|            hostkeys = crypto->client_kex.methods[SSH_HOSTKEYS];
  596|      0|            wanted_hostkeys = session->opts.wanted_methods[SSH_HOSTKEYS];
  597|      0|            ok = match_group(hostkeys, "rsa-sha2-512");
  598|      0|            if (ok) {
  ------------------
  |  Branch (598:17): [True: 0, False: 0]
  ------------------
  599|       |                /* Check if rsa-sha2-512 is allowed by config */
  600|      0|                if (wanted_hostkeys != NULL) {
  ------------------
  |  Branch (600:21): [True: 0, False: 0]
  ------------------
  601|      0|                    char *is_allowed = ssh_find_matching(wanted_hostkeys,
  602|      0|                                                         "rsa-sha2-512");
  603|      0|                    if (is_allowed != NULL) {
  ------------------
  |  Branch (603:25): [True: 0, False: 0]
  ------------------
  604|      0|                        session->extensions |= SSH_EXT_SIG_RSA_SHA512;
  ------------------
  |  |  127|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  605|      0|                    }
  606|      0|                    SAFE_FREE(is_allowed);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  607|      0|                }
  608|      0|            }
  609|      0|            ok = match_group(hostkeys, "rsa-sha2-256");
  610|      0|            if (ok) {
  ------------------
  |  Branch (610:17): [True: 0, False: 0]
  ------------------
  611|       |                /* Check if rsa-sha2-256 is allowed by config */
  612|      0|                if (wanted_hostkeys != NULL) {
  ------------------
  |  Branch (612:21): [True: 0, False: 0]
  ------------------
  613|      0|                    char *is_allowed = ssh_find_matching(wanted_hostkeys,
  614|      0|                                                         "rsa-sha2-256");
  615|      0|                    if (is_allowed != NULL) {
  ------------------
  |  Branch (615:25): [True: 0, False: 0]
  ------------------
  616|      0|                        session->extensions |= SSH_EXT_SIG_RSA_SHA256;
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  617|      0|                    }
  618|      0|                    SAFE_FREE(is_allowed);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  619|      0|                }
  620|      0|            }
  621|       |
  622|       |            /*
  623|       |             * Ensure that the client preference is honored for the case
  624|       |             * both signature types are enabled.
  625|       |             */
  626|      0|            if ((session->extensions & SSH_EXT_SIG_RSA_SHA256) &&
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  |  Branch (626:17): [True: 0, False: 0]
  ------------------
  627|      0|                (session->extensions & SSH_EXT_SIG_RSA_SHA512)) {
  ------------------
  |  |  127|      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);
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
                              session->extensions &= ~(SSH_EXT_SIG_RSA_SHA256 | SSH_EXT_SIG_RSA_SHA512);
  ------------------
  |  |  127|      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;
  ------------------
  |  |  127|      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;
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  638|      0|                } else {
  639|      0|                    SAFE_FREE(rsa_sig_ext);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  640|      0|                    goto error; /* should never happen */
  641|      0|                }
  642|      0|                SAFE_FREE(rsa_sig_ext);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  643|      0|            }
  644|       |
  645|      0|            SSH_LOG(SSH_LOG_DEBUG, "The client supports extension "
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 0, False: 0]
  |  |  |  Branch (283:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  646|      0|                    "negotiation. Enabled signature algorithms: %s%s",
  647|      0|                    session->extensions & SSH_EXT_SIG_RSA_SHA256 ? "SHA256" : "",
  648|      0|                    session->extensions & SSH_EXT_SIG_RSA_SHA512 ? " SHA512" : "");
  649|      0|        }
  650|      0|    }
  651|    267|#endif /* WITH_SERVER */
  652|       |
  653|       |    /* Note, that his overwrites authenticated state in case of rekeying */
  654|    267|    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|    267|    if (session->send_first_kex_follows == false) {
  ------------------
  |  Branch (658:9): [True: 267, False: 0]
  ------------------
  659|    267|        session->dh_handshake_state = DH_STATE_INIT;
  660|    267|    }
  661|    267|    session->ssh_connection_callback(session);
  662|    267|    return SSH_PACKET_USED;
  ------------------
  |  |  638|    267|#define SSH_PACKET_USED 1
  ------------------
  663|       |
  664|     21|error:
  665|     21|    SSH_STRING_FREE(str);
  ------------------
  |  |  924|     21|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 21]
  |  |  |  Branch (924:69): [Folded, False: 21]
  |  |  ------------------
  ------------------
  666|    231|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|    231|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (666:17): [True: 210, False: 21]
  ------------------
  667|    210|        if (server_kex) {
  ------------------
  |  Branch (667:13): [True: 0, False: 210]
  ------------------
  668|      0|#ifdef WITH_SERVER
  669|      0|            session->next_crypto->client_kex.methods[i] = NULL;
  670|      0|#endif /* WITH_SERVER */
  671|    210|        } else { /* client */
  672|    210|            session->next_crypto->server_kex.methods[i] = NULL;
  673|    210|        }
  674|    210|        SAFE_FREE(strings[i]);
  ------------------
  |  |  375|    210|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 51, False: 159]
  |  |  |  Branch (375:71): [Folded, False: 210]
  |  |  ------------------
  ------------------
  675|    210|    }
  676|       |
  677|     21|    session->session_state = SSH_SESSION_STATE_ERROR;
  678|       |
  679|     21|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     21|#define SSH_PACKET_USED 1
  ------------------
  680|    267|}
ssh_list_kex:
  682|    709|void ssh_list_kex(struct ssh_kex_struct *kex) {
  683|    709|  int i = 0;
  684|       |
  685|       |#ifdef DEBUG_CRYPTO
  686|       |  ssh_log_hexdump("session cookie", kex->cookie, 16);
  687|       |#endif
  688|       |
  689|  7.79k|  for(i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  7.79k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (689:14): [True: 7.09k, False: 709]
  ------------------
  690|  7.09k|    if (kex->methods[i] == NULL) {
  ------------------
  |  Branch (690:9): [True: 0, False: 7.09k]
  ------------------
  691|      0|      continue;
  692|      0|    }
  693|  7.09k|    SSH_LOG(SSH_LOG_FUNCTIONS, "%s: %s",
  ------------------
  |  |  283|  7.09k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  694|  7.09k|        ssh_kex_descriptions[i], kex->methods[i]);
  695|  7.09k|  }
  696|    709|}
ssh_client_select_hostkeys:
  708|    442|{
  709|    442|    const char *wanted = NULL;
  710|    442|    char *wanted_without_certs = NULL;
  711|    442|    char *known_hosts_algorithms = NULL;
  712|    442|    char *known_hosts_ordered = NULL;
  713|    442|    char *new_hostkeys = NULL;
  714|    442|    char *fips_hostkeys = NULL;
  715|       |
  716|    442|    wanted = session->opts.wanted_methods[SSH_HOSTKEYS];
  717|    442|    if (wanted == NULL) {
  ------------------
  |  Branch (717:9): [True: 442, False: 0]
  ------------------
  718|    442|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|    442|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 442]
  |  |  ------------------
  ------------------
  719|      0|            wanted = ssh_kex_get_fips_methods(SSH_HOSTKEYS);
  720|    442|        } else {
  721|    442|            wanted = ssh_kex_get_default_methods(SSH_HOSTKEYS);
  722|    442|        }
  723|    442|    }
  724|       |
  725|       |    /* This removes the certificate types, unsupported for now */
  726|    442|    wanted_without_certs = ssh_find_all_matching(HOSTKEYS, wanted);
  ------------------
  |  |  142|    442|#define HOSTKEYS "ssh-ed25519," \
  |  |  143|    442|                 EC_HOSTKEYS \
  |  |  144|    442|                 "sk-ssh-ed25519@openssh.com," \
  |  |  145|    442|                 EC_SK_HOSTKEYS \
  |  |  146|    442|                 "rsa-sha2-512," \
  |  |  147|    442|                 "rsa-sha2-256," \
  |  |  148|    442|                 "ssh-rsa"
  ------------------
  727|    442|    if (wanted_without_certs == NULL) {
  ------------------
  |  Branch (727:9): [True: 0, False: 442]
  ------------------
  728|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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|    442|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|    442|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  735|    442|            "Order of wanted host keys: \"%s\"",
  736|    442|            wanted_without_certs);
  737|       |
  738|    442|    known_hosts_algorithms = ssh_known_hosts_get_algorithms_names(session);
  739|    442|    if (known_hosts_algorithms == NULL) {
  ------------------
  |  Branch (739:9): [True: 442, False: 0]
  ------------------
  740|    442|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|    442|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  741|    442|                "No key found in known_hosts; "
  742|    442|                "changing host key method to \"%s\"",
  743|    442|                wanted_without_certs);
  744|       |
  745|    442|        return wanted_without_certs;
  746|    442|    }
  747|       |
  748|      0|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      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);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375: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,
  ------------------
  |  |  283|      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);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  770|      0|    SAFE_FREE(wanted_without_certs);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  771|      0|    if (new_hostkeys == NULL) {
  ------------------
  |  Branch (771:9): [True: 0, False: 0]
  ------------------
  772|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      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);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  780|      0|        if (fips_hostkeys == NULL) {
  ------------------
  |  Branch (780:13): [True: 0, False: 0]
  ------------------
  781|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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,
  ------------------
  |  |  283|      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|    729|{
  802|    729|    struct ssh_kex_struct *client = &session->next_crypto->client_kex;
  803|    729|    const char *wanted = NULL;
  804|    729|    int ok;
  805|    729|    int i;
  806|    729|    bool gssapi_null_alg = false;
  807|    729|    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|    729|    if (client->methods[0] != NULL) {
  ------------------
  |  Branch (811:9): [True: 287, False: 442]
  ------------------
  812|    287|        return SSH_OK;
  ------------------
  |  |  316|    287|#define SSH_OK 0     /* No error */
  ------------------
  813|    287|    }
  814|       |
  815|    442|    ok = ssh_get_random(client->cookie, 16, 0);
  816|    442|    if (!ok) {
  ------------------
  |  Branch (816:9): [True: 0, False: 442]
  ------------------
  817|      0|        ssh_set_error(session, SSH_FATAL, "PRNG error");
  ------------------
  |  |  313|      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|  4.86k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  4.86k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (859:17): [True: 4.42k, False: 442]
  ------------------
  860|  4.42k|        if (i == SSH_HOSTKEYS) {
  ------------------
  |  Branch (860:13): [True: 442, False: 3.97k]
  ------------------
  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|    442|            client->methods[i] = ssh_client_select_hostkeys(session);
  865|    442|            if (client->methods[i] == NULL) {
  ------------------
  |  Branch (865:17): [True: 0, False: 442]
  ------------------
  866|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  320|      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|    442|            if (gssapi_null_alg) {
  ------------------
  |  Branch (869:17): [True: 0, False: 442]
  ------------------
  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);
  ------------------
  |  |  320|      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]);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  877|      0|                client->methods[i] = hostkeys;
  878|      0|            }
  879|    442|            continue;
  880|    442|        }
  881|       |
  882|  3.97k|        wanted = session->opts.wanted_methods[i];
  883|  3.97k|        if (wanted == NULL) {
  ------------------
  |  Branch (883:13): [True: 2.21k, False: 1.76k]
  ------------------
  884|  2.21k|            if (ssh_fips_mode()) {
  ------------------
  |  |  115|  2.21k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 2.21k]
  |  |  ------------------
  ------------------
  885|      0|                wanted = fips_methods[i];
  886|  2.21k|            } else {
  887|  2.21k|                wanted = default_methods[i];
  888|  2.21k|            }
  889|  2.21k|        }
  890|  3.97k|        client->methods[i] = strdup(wanted);
  891|  3.97k|        if (client->methods[i] == NULL) {
  ------------------
  |  Branch (891:13): [True: 0, False: 3.97k]
  ------------------
  892|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      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|  3.97k|    }
  896|       |
  897|       |    /* For rekeying, skip the extension negotiation */
  898|    442|    if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) {
  ------------------
  |  |   78|    442|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (898:9): [True: 0, False: 442]
  ------------------
  899|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  900|      0|    }
  901|       |
  902|    442|    ok = ssh_kex_append_extensions(session, client);
  903|    442|    if (ok != SSH_OK){
  ------------------
  |  |  316|    442|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (903:9): [True: 0, False: 442]
  ------------------
  904|      0|        return ok;
  905|      0|    }
  906|       |
  907|    442|    return SSH_OK;
  ------------------
  |  |  316|    442|#define SSH_OK 0     /* No error */
  ------------------
  908|    442|}
ssh_kex_append_extensions:
  911|    442|{
  912|    442|    char *kex = NULL;
  913|    442|    char *kex_tmp = NULL;
  914|    442|    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|    442|    kex = pkex->methods[SSH_KEX];
  920|    442|    len = strlen(kex);
  921|    442|    if (session->server) {
  ------------------
  |  Branch (921:9): [True: 0, False: 442]
  ------------------
  922|       |        /* Comma, nul byte */
  923|      0|        kex_len = len + 1 + strlen(KEX_STRICT_SERVER) + 1;
  ------------------
  |  |  197|      0|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  924|    442|    } else {
  925|       |        /* Comma, comma, nul byte */
  926|    442|        kex_len = len + 1 + strlen(KEX_EXTENSION_CLIENT) + 1 +
  ------------------
  |  |  194|    442|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  927|    442|                  strlen(KEX_STRICT_CLIENT) + 1;
  ------------------
  |  |  196|    442|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  928|    442|    }
  929|    442|    if (kex_len >= MAX_PACKET_LEN) {
  ------------------
  |  |  216|    442|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (929:9): [True: 0, False: 442]
  ------------------
  930|       |        /* Overflow */
  931|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  932|      0|    }
  933|    442|    kex_tmp = realloc(kex, kex_len);
  934|    442|    if (kex_tmp == NULL) {
  ------------------
  |  Branch (934:9): [True: 0, False: 442]
  ------------------
  935|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      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|    442|    if (session->server){
  ------------------
  |  Branch (938:9): [True: 0, False: 442]
  ------------------
  939|      0|        snprintf(kex_tmp + len, kex_len - len, ",%s", KEX_STRICT_SERVER);
  ------------------
  |  |  197|      0|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  940|    442|    } else {
  941|    442|        snprintf(kex_tmp + len,
  942|    442|                 kex_len - len,
  943|    442|                 ",%s,%s",
  944|    442|                 KEX_EXTENSION_CLIENT,
  ------------------
  |  |  194|    442|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  945|    442|                 KEX_STRICT_CLIENT);
  ------------------
  |  |  196|    442|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  946|    442|    }
  947|    442|    pkex->methods[SSH_KEX] = kex_tmp;
  948|    442|    return SSH_OK;
  ------------------
  |  |  316|    442|#define SSH_OK 0     /* No error */
  ------------------
  949|    442|}
ssh_kex_select_methods:
 1082|    267|{
 1083|    267|    struct ssh_crypto_struct *crypto = session->next_crypto;
 1084|    267|    struct ssh_kex_struct *server = &crypto->server_kex;
 1085|    267|    struct ssh_kex_struct *client = &crypto->client_kex;
 1086|    267|    char *ext_start = NULL;
 1087|    267|    const char *aead_hmac = NULL;
 1088|    267|    enum ssh_key_exchange_e kex_type;
 1089|    267|    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|    267|    if (session->client) {
  ------------------
  |  Branch (1093:9): [True: 267, False: 0]
  ------------------
 1094|    267|        ext_start = strstr(client->methods[SSH_KEX], "," KEX_EXTENSION_CLIENT);
  ------------------
  |  |  194|    267|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
 1095|    267|        if (ext_start != NULL) {
  ------------------
  |  Branch (1095:13): [True: 267, False: 0]
  ------------------
 1096|    267|            ext_start[0] = '\0';
 1097|    267|        }
 1098|    267|    }
 1099|    267|    if (session->server) {
  ------------------
  |  Branch (1099:9): [True: 0, False: 267]
  ------------------
 1100|      0|        ext_start = strstr(server->methods[SSH_KEX], "," KEX_STRICT_SERVER);
  ------------------
  |  |  197|      0|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
 1101|      0|        if (ext_start != NULL) {
  ------------------
  |  Branch (1101:13): [True: 0, False: 0]
  ------------------
 1102|      0|            ext_start[0] = '\0';
 1103|      0|        }
 1104|      0|    }
 1105|       |
 1106|  2.34k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  2.34k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (1106:17): [True: 2.14k, False: 206]
  ------------------
 1107|  2.14k|        crypto->kex_methods[i] = ssh_find_matching(server->methods[i],
 1108|  2.14k|                                                   client->methods[i]);
 1109|       |
 1110|  2.14k|        if (i == SSH_MAC_C_S || i == SSH_MAC_S_C) {
  ------------------
  |  Branch (1110:13): [True: 209, False: 1.93k]
  |  Branch (1110:33): [True: 207, False: 1.72k]
  ------------------
 1111|    416|            aead_hmac = ssh_find_aead_hmac(crypto->kex_methods[i - 2]);
 1112|    416|            if (aead_hmac) {
  ------------------
  |  Branch (1112:17): [True: 0, False: 416]
  ------------------
 1113|      0|                free(crypto->kex_methods[i]);
 1114|      0|                crypto->kex_methods[i] = strdup(aead_hmac);
 1115|      0|            }
 1116|    416|        }
 1117|  2.14k|        if (crypto->kex_methods[i] == NULL && i < SSH_LANG_C_S) {
  ------------------
  |  Branch (1117:13): [True: 88, False: 2.05k]
  |  Branch (1117:47): [True: 61, False: 27]
  ------------------
 1118|     61|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|     61|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1119|     61|                          "kex error : no match for method %s: server [%s], "
 1120|     61|                          "client [%s]", ssh_kex_descriptions[i],
 1121|     61|                          server->methods[i], client->methods[i]);
 1122|     61|            return SSH_ERROR;
  ------------------
  |  |  317|     61|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1123|  2.08k|        } else if ((i >= SSH_LANG_C_S) && (crypto->kex_methods[i] == NULL)) {
  ------------------
  |  Branch (1123:20): [True: 412, False: 1.66k]
  |  Branch (1123:43): [True: 27, False: 385]
  ------------------
 1124|       |            /* we can safely do that for languages */
 1125|     27|            crypto->kex_methods[i] = strdup("");
 1126|     27|        }
 1127|  2.14k|    }
 1128|       |
 1129|       |    /* We can not set this value directly as the old value is needed to revert
 1130|       |     * callbacks if we are client */
 1131|    206|    kex_type = kex_select_kex_type(crypto->kex_methods[SSH_KEX]);
 1132|    206|    if (session->client && session->first_kex_follows_guess_wrong) {
  ------------------
  |  Branch (1132:9): [True: 206, False: 0]
  |  Branch (1132:28): [True: 142, False: 64]
  ------------------
 1133|    142|        SSH_LOG(SSH_LOG_DEBUG, "Our guess was wrong. Restarting the KEX");
  ------------------
  |  |  283|    142|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1134|       |        /* We need to remove the wrong callbacks and start kex again */
 1135|    142|        revert_kex_callbacks(session);
 1136|    142|        session->dh_handshake_state = DH_STATE_INIT;
 1137|    142|        session->first_kex_follows_guess_wrong = false;
 1138|    142|    }
 1139|    206|    crypto->kex_type = kex_type;
 1140|       |
 1141|    206|    SSH_LOG(SSH_LOG_DEBUG, "Negotiated %s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
  ------------------
  |  |  283|    206|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1142|    206|            session->next_crypto->kex_methods[SSH_KEX],
 1143|    206|            session->next_crypto->kex_methods[SSH_HOSTKEYS],
 1144|    206|            session->next_crypto->kex_methods[SSH_CRYPT_C_S],
 1145|    206|            session->next_crypto->kex_methods[SSH_CRYPT_S_C],
 1146|    206|            session->next_crypto->kex_methods[SSH_MAC_C_S],
 1147|    206|            session->next_crypto->kex_methods[SSH_MAC_S_C],
 1148|    206|            session->next_crypto->kex_methods[SSH_COMP_C_S],
 1149|    206|            session->next_crypto->kex_methods[SSH_COMP_S_C],
 1150|    206|            session->next_crypto->kex_methods[SSH_LANG_C_S],
 1151|    206|            session->next_crypto->kex_methods[SSH_LANG_S_C]
 1152|    206|    );
 1153|    206|    return SSH_OK;
  ------------------
  |  |  316|    206|#define SSH_OK 0     /* No error */
  ------------------
 1154|    267|}
ssh_send_kex:
 1159|    442|{
 1160|    442|    struct ssh_kex_struct *kex = (session->server ?
  ------------------
  |  Branch (1160:35): [True: 0, False: 442]
  ------------------
 1161|      0|        &session->next_crypto->server_kex :
 1162|    442|        &session->next_crypto->client_kex);
 1163|    442|    ssh_string str = NULL;
 1164|    442|    int i;
 1165|    442|    int rc;
 1166|    442|    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|    442|    if (session->client &&
  ------------------
  |  Branch (1170:9): [True: 442, False: 0]
  ------------------
 1171|    442|        session->session_state != SSH_SESSION_STATE_KEXINIT_RECEIVED &&
  ------------------
  |  Branch (1171:9): [True: 442, False: 0]
  ------------------
 1172|    442|        session->send_first_kex_follows) {
  ------------------
  |  Branch (1172:9): [True: 0, False: 442]
  ------------------
 1173|      0|        first_kex_packet_follows = 1;
 1174|      0|    }
 1175|       |
 1176|    442|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|    442|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1177|    442|            "Sending KEXINIT packet, first_kex_packet_follows = %d",
 1178|    442|            first_kex_packet_follows);
 1179|       |
 1180|    442|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    442|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    442|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    442|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    442|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    442|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    442|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    442|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1181|    442|                         "bP",
 1182|    442|                         SSH2_MSG_KEXINIT,
 1183|    442|                         (size_t)16,
 1184|    442|                         kex->cookie); /* cookie */
 1185|    442|    if (rc != SSH_OK)
  ------------------
  |  |  316|    442|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1185:9): [True: 0, False: 442]
  ------------------
 1186|      0|        goto error;
 1187|    442|    if (ssh_hashbufout_add_cookie(session) < 0) {
  ------------------
  |  Branch (1187:9): [True: 0, False: 442]
  ------------------
 1188|      0|        goto error;
 1189|      0|    }
 1190|       |
 1191|    442|    ssh_list_kex(kex);
 1192|       |
 1193|  4.86k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  4.86k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (1193:17): [True: 4.42k, False: 442]
  ------------------
 1194|  4.42k|        str = ssh_string_from_char(kex->methods[i]);
 1195|  4.42k|        if (str == NULL) {
  ------------------
  |  Branch (1195:13): [True: 0, False: 4.42k]
  ------------------
 1196|      0|            goto error;
 1197|      0|        }
 1198|       |
 1199|  4.42k|        rc = ssh_buffer_add_ssh_string(session->out_hashbuf, str);
 1200|  4.42k|        if (rc < 0) {
  ------------------
  |  Branch (1200:13): [True: 0, False: 4.42k]
  ------------------
 1201|      0|            goto error;
 1202|      0|        }
 1203|  4.42k|        rc = ssh_buffer_add_ssh_string(session->out_buffer, str);
 1204|  4.42k|        if (rc < 0) {
  ------------------
  |  Branch (1204:13): [True: 0, False: 4.42k]
  ------------------
 1205|      0|            goto error;
 1206|      0|        }
 1207|  4.42k|        SSH_STRING_FREE(str);
  ------------------
  |  |  924|  4.42k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 4.42k, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 4.42k]
  |  |  ------------------
  ------------------
 1208|  4.42k|        str = NULL;
 1209|  4.42k|    }
 1210|       |
 1211|    442|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    442|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    442|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    442|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    442|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    442|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    442|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    442|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1212|    442|                         "bd",
 1213|    442|                         first_kex_packet_follows,
 1214|    442|                         0);
 1215|    442|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    442|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1215:9): [True: 0, False: 442]
  ------------------
 1216|      0|        goto error;
 1217|      0|    }
 1218|       |
 1219|       |    /* Prepare also the first_kex_packet_follows and reserved to 0 */
 1220|    442|    rc = ssh_buffer_add_u8(session->out_hashbuf, first_kex_packet_follows);
 1221|    442|    if (rc < 0) {
  ------------------
  |  Branch (1221:9): [True: 0, False: 442]
  ------------------
 1222|      0|        goto error;
 1223|      0|    }
 1224|    442|    rc = ssh_buffer_add_u32(session->out_hashbuf, 0);
 1225|    442|    if (rc < 0) {
  ------------------
  |  Branch (1225:9): [True: 0, False: 442]
  ------------------
 1226|      0|        goto error;
 1227|      0|    }
 1228|       |
 1229|    442|    rc = ssh_packet_send(session);
 1230|    442|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    442|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1230:9): [True: 0, False: 442]
  ------------------
 1231|      0|        return -1;
 1232|      0|    }
 1233|       |
 1234|    442|    session->flags |= SSH_SESSION_FLAG_KEXINIT_SENT;
  ------------------
  |  |   86|    442|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
 1235|    442|    SSH_LOG(SSH_LOG_PACKET, "SSH_MSG_KEXINIT sent");
  ------------------
  |  |  283|    442|    _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|    442|    if (first_kex_packet_follows == 1) {
  ------------------
  |  Branch (1239:9): [True: 0, False: 442]
  ------------------
 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);
  ------------------
  |  |  320|      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);
  ------------------
  |  |  283|      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|    442|    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);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1266|       |
 1267|      0|    return -1;
 1268|    442|}
ssh_keep_known_algos:
 1324|  1.94k|{
 1325|  1.94k|    if (algo > SSH_LANG_S_C) {
  ------------------
  |  Branch (1325:9): [True: 0, False: 1.94k]
  ------------------
 1326|      0|        return NULL;
 1327|      0|    }
 1328|       |
 1329|  1.94k|    return ssh_find_all_matching(supported_methods[algo], list);
 1330|  1.94k|}
ssh_make_sessionid:
 1459|     33|{
 1460|     33|    ssh_string num = NULL;
 1461|     33|    ssh_buffer server_hash = NULL;
 1462|     33|    ssh_buffer client_hash = NULL;
 1463|     33|    ssh_buffer buf = NULL;
 1464|     33|    ssh_string server_pubkey_blob = NULL;
 1465|     33|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
 1466|     33|    const_bignum client_pubkey, server_pubkey;
 1467|       |#else
 1468|       |    bignum client_pubkey = NULL, server_pubkey = NULL;
 1469|       |#endif /* OPENSSL_VERSION_NUMBER */
 1470|     33|#ifdef WITH_GEX
 1471|     33|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
 1472|     33|    const_bignum modulus, generator;
 1473|       |#else
 1474|       |    bignum modulus = NULL, generator = NULL;
 1475|       |#endif /* OPENSSL_VERSION_NUMBER */
 1476|     33|#endif /* WITH_GEX */
 1477|     33|    int rc = SSH_ERROR;
  ------------------
  |  |  317|     33|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1478|       |
 1479|     33|    buf = ssh_buffer_new();
 1480|     33|    if (buf == NULL) {
  ------------------
  |  Branch (1480:9): [True: 0, False: 33]
  ------------------
 1481|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1482|      0|        return rc;
 1483|      0|    }
 1484|       |
 1485|     33|    rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|     33|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     33|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     33|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     33|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     33|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     33|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     33|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1486|     33|                         "ss",
 1487|     33|                         session->clientbanner,
 1488|     33|                         session->serverbanner);
 1489|     33|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     33|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1489:9): [True: 0, False: 33]
  ------------------
 1490|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      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|     33|    if (session->client) {
  ------------------
  |  Branch (1496:9): [True: 33, False: 0]
  ------------------
 1497|     33|        server_hash = session->in_hashbuf;
 1498|     33|        client_hash = session->out_hashbuf;
 1499|     33|    } else {
 1500|      0|        server_hash = session->out_hashbuf;
 1501|      0|        client_hash = session->in_hashbuf;
 1502|      0|    }
 1503|       |
 1504|     33|    rc = ssh_dh_get_next_server_publickey_blob(session, &server_pubkey_blob);
 1505|     33|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     33|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1505:9): [True: 0, False: 33]
  ------------------
 1506|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      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|     33|    if (server_pubkey_blob == NULL) {
  ------------------
  |  Branch (1512:9): [True: 0, False: 33]
  ------------------
 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);
  ------------------
  |  |  320|      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|     33|    rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|     33|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     33|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     33|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     33|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     33|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     33|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     33|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1525|     33|                         "dPdPS",
 1526|     33|                         ssh_buffer_get_len(client_hash),
 1527|     33|                         (size_t)ssh_buffer_get_len(client_hash),
 1528|     33|                         ssh_buffer_get(client_hash),
 1529|     33|                         ssh_buffer_get_len(server_hash),
 1530|     33|                         (size_t)ssh_buffer_get_len(server_hash),
 1531|     33|                         ssh_buffer_get(server_hash),
 1532|     33|                         server_pubkey_blob);
 1533|     33|    SSH_STRING_FREE(server_pubkey_blob);
  ------------------
  |  |  924|     33|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 33, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 33]
  |  |  ------------------
  ------------------
 1534|     33|    if (rc != SSH_OK){
  ------------------
  |  |  316|     33|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1534:9): [True: 0, False: 33]
  ------------------
 1535|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      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|     33|    switch(session->next_crypto->kex_type) {
 1542|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1542:5): [True: 0, False: 33]
  ------------------
 1543|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1543:5): [True: 0, False: 33]
  ------------------
 1544|      2|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1544:5): [True: 2, False: 31]
  ------------------
 1545|      2|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1545:5): [True: 0, False: 33]
  ------------------
 1546|      2|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1546:5): [True: 0, False: 33]
  ------------------
 1547|      2|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1547:5): [True: 0, False: 33]
  ------------------
 1548|     15|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1548:5): [True: 13, False: 20]
  ------------------
 1549|     15|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1550|     15|                                     DH_CLIENT_KEYPAIR, NULL, &client_pubkey);
  ------------------
  |  |   30|     15|#define DH_CLIENT_KEYPAIR 0
  ------------------
 1551|     15|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     15|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1551:13): [True: 0, False: 15]
  ------------------
 1552|      0|            goto error;
 1553|      0|        }
 1554|     15|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1555|     15|                                     DH_SERVER_KEYPAIR, NULL, &server_pubkey);
  ------------------
  |  |   31|     15|#define DH_SERVER_KEYPAIR 1
  ------------------
 1556|     15|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     15|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1556:13): [True: 0, False: 15]
  ------------------
 1557|      0|            goto error;
 1558|      0|        }
 1559|     15|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|     15|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     15|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     15|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     15|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     15|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     15|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     15|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1560|     15|                             "BB",
 1561|     15|                             client_pubkey,
 1562|     15|                             server_pubkey);
 1563|     15|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     15|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1563:13): [True: 0, False: 15]
  ------------------
 1564|      0|            ssh_set_error(session, SSH_FATAL, "Failed to pack DH pubkeys");
  ------------------
  |  |  313|      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|     15|        break;
 1572|     15|#ifdef WITH_GEX
 1573|     15|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (1573:5): [True: 0, False: 33]
  ------------------
 1574|      0|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1574:5): [True: 0, False: 33]
  ------------------
 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)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      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");
  ------------------
  |  |  313|      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: 33]
  ------------------
 1611|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1611:5): [True: 0, False: 33]
  ------------------
 1612|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1612:5): [True: 0, False: 33]
  ------------------
 1613|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1613:5): [True: 0, False: 33]
  ------------------
 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");
  ------------------
  |  |  283|      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)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      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");
  ------------------
  |  |  313|      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|      5|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1630:5): [True: 5, False: 28]
  ------------------
 1631|     18|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1631:5): [True: 13, False: 20]
  ------------------
 1632|     18|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1632:5): [True: 0, False: 33]
  ------------------
 1633|     18|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|     18|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     18|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     18|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     18|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     18|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     18|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     18|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1634|     18|                             "dPdP",
 1635|     18|                             CURVE25519_PUBKEY_SIZE,
 1636|     18|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1637|     18|                             session->next_crypto->curve25519_client_pubkey,
 1638|     18|                             CURVE25519_PUBKEY_SIZE,
 1639|     18|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1640|     18|                             session->next_crypto->curve25519_server_pubkey);
 1641|       |
 1642|     18|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     18|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1642:13): [True: 0, False: 18]
  ------------------
 1643|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      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|     18|        break;
 1649|     18|#endif /* HAVE_CURVE25519 */
 1650|     18|#ifdef HAVE_SNTRUP761
 1651|     18|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1651:5): [True: 0, False: 33]
  ------------------
 1652|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1652:5): [True: 0, False: 33]
  ------------------
 1653|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      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,
  ------------------
  |  |  313|      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|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1674:5): [True: 0, False: 33]
  ------------------
 1675|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1675:5): [True: 0, False: 33]
  ------------------
 1676|       |#ifdef HAVE_MLKEM1024
 1677|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1678|       |#endif
 1679|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      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)
  |  |  ------------------
  ------------------
 1680|      0|                             "SS",
 1681|      0|                             session->next_crypto->hybrid_client_init,
 1682|      0|                             session->next_crypto->hybrid_server_reply);
 1683|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1683:13): [True: 0, False: 0]
  ------------------
 1684|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      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|      0|        break;
 1690|      0|    default:
  ------------------
  |  Branch (1690:5): [True: 0, False: 33]
  ------------------
 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");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1694|      0|        goto error;
 1695|     33|    }
 1696|     33|    switch (session->next_crypto->kex_type) {
 1697|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1697:5): [True: 0, False: 33]
  ------------------
 1698|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1698:5): [True: 0, False: 33]
  ------------------
 1699|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1699:5): [True: 0, False: 33]
  ------------------
 1700|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1700:5): [True: 0, False: 33]
  ------------------
 1701|       |#ifdef HAVE_MLKEM1024
 1702|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1703|       |#endif
 1704|      0|        rc = ssh_buffer_pack(buf, "S", session->next_crypto->hybrid_shared_secret);
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      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)
  |  |  ------------------
  ------------------
 1705|      0|        break;
 1706|     33|    default:
  ------------------
  |  Branch (1706:5): [True: 33, False: 0]
  ------------------
 1707|     33|        rc = ssh_buffer_pack(buf, "B", session->next_crypto->shared_secret);
  ------------------
  |  |   50|     33|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     33|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     33|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     33|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     33|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     33|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     33|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1708|     33|        break;
 1709|     33|    }
 1710|     33|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     33|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1710:9): [True: 0, False: 33]
  ------------------
 1711|      0|        ssh_set_error(session, SSH_FATAL, "Failed to pack shared secret");
  ------------------
  |  |  313|      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|     33|    rc = SSH_ERROR;
  ------------------
  |  |  317|     33|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1721|     33|    switch (session->next_crypto->kex_type) {
 1722|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1722:5): [True: 0, False: 33]
  ------------------
 1723|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1723:5): [True: 0, False: 33]
  ------------------
 1724|      0|#ifdef WITH_GEX
 1725|      0|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (1725:5): [True: 0, False: 33]
  ------------------
 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);
  ------------------
  |  |  320|      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|      2|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1737:5): [True: 2, False: 31]
  ------------------
 1738|      2|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1738:5): [True: 0, False: 33]
  ------------------
 1739|      2|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (1739:5): [True: 0, False: 33]
  ------------------
 1740|      7|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1740:5): [True: 5, False: 28]
  ------------------
 1741|     20|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1741:5): [True: 13, False: 20]
  ------------------
 1742|     20|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1742:5): [True: 0, False: 33]
  ------------------
 1743|     20|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1743:5): [True: 0, False: 33]
  ------------------
 1744|     20|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1744:5): [True: 0, False: 33]
  ------------------
 1745|     20|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1745:5): [True: 0, False: 33]
  ------------------
 1746|     20|#ifdef WITH_GEX
 1747|     20|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1747:5): [True: 0, False: 33]
  ------------------
 1748|     20|#endif /* WITH_GEX */
 1749|     20|        session->next_crypto->digest_len = SHA256_DIGEST_LENGTH;
 1750|     20|        session->next_crypto->digest_type = SSH_KDF_SHA256;
 1751|     20|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1752|     20|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1752:13): [True: 0, False: 20]
  ------------------
 1753|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1754|      0|            goto error;
 1755|      0|        }
 1756|     20|        sha256(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
 1757|     20|                                     session->next_crypto->secret_hash);
 1758|     20|        break;
 1759|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1759:5): [True: 0, False: 33]
  ------------------
 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);
  ------------------
  |  |  320|      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: 33]
  ------------------
 1774|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1774:5): [True: 0, False: 33]
  ------------------
 1775|     13|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1775:5): [True: 13, False: 20]
  ------------------
 1776|     13|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1776:5): [True: 0, False: 33]
  ------------------
 1777|     13|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1777:5): [True: 0, False: 33]
  ------------------
 1778|     13|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1778:5): [True: 0, False: 33]
  ------------------
 1779|     13|        session->next_crypto->digest_len = SHA512_DIGEST_LENGTH;
 1780|     13|        session->next_crypto->digest_type = SSH_KDF_SHA512;
 1781|     13|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1782|     13|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1782:13): [True: 0, False: 13]
  ------------------
 1783|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1784|      0|            goto error;
 1785|      0|        }
 1786|     13|        sha512(ssh_buffer_get(buf),
 1787|     13|               ssh_buffer_get_len(buf),
 1788|     13|               session->next_crypto->secret_hash);
 1789|     13|        break;
 1790|      0|    default:
  ------------------
  |  Branch (1790:5): [True: 0, False: 33]
  ------------------
 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");
  ------------------
  |  |  313|      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|     33|    }
 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|     33|    if (!session->next_crypto->session_id) {
  ------------------
  |  Branch (1801:9): [True: 33, False: 0]
  ------------------
 1802|     33|        session->next_crypto->session_id = malloc(session->next_crypto->digest_len);
 1803|     33|        if (session->next_crypto->session_id == NULL) {
  ------------------
  |  Branch (1803:13): [True: 0, False: 33]
  ------------------
 1804|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      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|     33|        memcpy(session->next_crypto->session_id, session->next_crypto->secret_hash,
 1809|     33|                session->next_crypto->digest_len);
 1810|       |	/* Initial length is the same as secret hash */
 1811|     33|	session->next_crypto->session_id_len = session->next_crypto->digest_len;
 1812|     33|    }
 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|     33|    rc = SSH_OK;
  ------------------
  |  |  316|     33|#define SSH_OK 0     /* No error */
  ------------------
 1820|     33|error:
 1821|     33|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  966|     33|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 33, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 33]
  |  |  ------------------
  ------------------
 1822|     33|    SSH_BUFFER_FREE(client_hash);
  ------------------
  |  |  966|     33|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 33, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 33]
  |  |  ------------------
  ------------------
 1823|     33|    SSH_BUFFER_FREE(server_hash);
  ------------------
  |  |  966|     33|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 33, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 33]
  |  |  ------------------
  ------------------
 1824|       |
 1825|     33|    session->in_hashbuf = NULL;
 1826|     33|    session->out_hashbuf = NULL;
 1827|       |
 1828|     33|    SSH_STRING_FREE(num);
  ------------------
  |  |  924|     33|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 33]
  |  |  |  Branch (924:69): [Folded, False: 33]
  |  |  ------------------
  ------------------
 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|     33|    return rc;
 1835|     33|}
ssh_hashbufout_add_cookie:
 1838|    442|{
 1839|    442|    int rc;
 1840|       |
 1841|    442|    session->out_hashbuf = ssh_buffer_new();
 1842|    442|    if (session->out_hashbuf == NULL) {
  ------------------
  |  Branch (1842:9): [True: 0, False: 442]
  ------------------
 1843|      0|        return -1;
 1844|      0|    }
 1845|       |
 1846|    442|    rc = ssh_buffer_allocate_size(session->out_hashbuf,
 1847|    442|            sizeof(uint8_t) + 16);
 1848|    442|    if (rc < 0) {
  ------------------
  |  Branch (1848:9): [True: 0, False: 442]
  ------------------
 1849|      0|        ssh_buffer_reinit(session->out_hashbuf);
 1850|      0|        return -1;
 1851|      0|    }
 1852|       |
 1853|    442|    if (ssh_buffer_add_u8(session->out_hashbuf, 20) < 0) {
  ------------------
  |  Branch (1853:9): [True: 0, False: 442]
  ------------------
 1854|      0|        ssh_buffer_reinit(session->out_hashbuf);
 1855|      0|        return -1;
 1856|      0|    }
 1857|       |
 1858|    442|    if (session->server) {
  ------------------
  |  Branch (1858:9): [True: 0, False: 442]
  ------------------
 1859|      0|        if (ssh_buffer_add_data(session->out_hashbuf,
  ------------------
  |  Branch (1859:13): [True: 0, False: 0]
  ------------------
 1860|      0|                    session->next_crypto->server_kex.cookie, 16) < 0) {
 1861|      0|            ssh_buffer_reinit(session->out_hashbuf);
 1862|      0|            return -1;
 1863|      0|        }
 1864|    442|    } else {
 1865|    442|        if (ssh_buffer_add_data(session->out_hashbuf,
  ------------------
  |  Branch (1865:13): [True: 0, False: 442]
  ------------------
 1866|    442|                    session->next_crypto->client_kex.cookie, 16) < 0) {
 1867|      0|            ssh_buffer_reinit(session->out_hashbuf);
 1868|      0|            return -1;
 1869|      0|        }
 1870|    442|    }
 1871|       |
 1872|    442|    return 0;
 1873|    442|}
ssh_hashbufin_add_cookie:
 1876|    287|{
 1877|    287|    int rc;
 1878|       |
 1879|    287|    session->in_hashbuf = ssh_buffer_new();
 1880|    287|    if (session->in_hashbuf == NULL) {
  ------------------
  |  Branch (1880:9): [True: 0, False: 287]
  ------------------
 1881|      0|        return -1;
 1882|      0|    }
 1883|       |
 1884|    287|    rc = ssh_buffer_allocate_size(session->in_hashbuf,
 1885|    287|            sizeof(uint8_t) + 20 + 16);
 1886|    287|    if (rc < 0) {
  ------------------
  |  Branch (1886:9): [True: 0, False: 287]
  ------------------
 1887|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1888|      0|        return -1;
 1889|      0|    }
 1890|       |
 1891|    287|    if (ssh_buffer_add_u8(session->in_hashbuf, 20) < 0) {
  ------------------
  |  Branch (1891:9): [True: 0, False: 287]
  ------------------
 1892|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1893|      0|        return -1;
 1894|      0|    }
 1895|    287|    if (ssh_buffer_add_data(session->in_hashbuf,cookie, 16) < 0) {
  ------------------
  |  Branch (1895:9): [True: 0, False: 287]
  ------------------
 1896|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1897|      0|        return -1;
 1898|      0|    }
 1899|       |
 1900|    287|    return 0;
 1901|    287|}
ssh_generate_session_keys:
 1904|     33|{
 1905|     33|    ssh_string k_string = NULL;
 1906|     33|    struct ssh_crypto_struct *crypto = session->next_crypto;
 1907|     33|    unsigned char *key = NULL;
 1908|     33|    unsigned char *IV_cli_to_srv = NULL;
 1909|     33|    unsigned char *IV_srv_to_cli = NULL;
 1910|     33|    unsigned char *enckey_cli_to_srv = NULL;
 1911|     33|    unsigned char *enckey_srv_to_cli = NULL;
 1912|     33|    unsigned char *intkey_cli_to_srv = NULL;
 1913|     33|    unsigned char *intkey_srv_to_cli = NULL;
 1914|     33|    size_t key_len = 0;
 1915|     33|    size_t IV_len = 0;
 1916|     33|    size_t enckey_cli_to_srv_len = 0;
 1917|     33|    size_t enckey_srv_to_cli_len = 0;
 1918|     33|    size_t intkey_cli_to_srv_len = 0;
 1919|     33|    size_t intkey_srv_to_cli_len = 0;
 1920|     33|    int rc = -1;
 1921|       |
 1922|     33|    switch (session->next_crypto->kex_type) {
 1923|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1923:5): [True: 0, False: 33]
  ------------------
 1924|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1924:5): [True: 0, False: 33]
  ------------------
 1925|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1925:5): [True: 0, False: 33]
  ------------------
 1926|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1926:5): [True: 0, False: 33]
  ------------------
 1927|       |#ifdef HAVE_MLKEM1024
 1928|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1929|       |#endif
 1930|      0|        k_string = ssh_string_copy(crypto->hybrid_shared_secret);
 1931|      0|        break;
 1932|     33|    default:
  ------------------
  |  Branch (1932:5): [True: 33, False: 0]
  ------------------
 1933|     33|        k_string = ssh_make_bignum_string(crypto->shared_secret);
 1934|     33|        break;
 1935|     33|    }
 1936|     33|    if (k_string == NULL) {
  ------------------
  |  Branch (1936:9): [True: 0, False: 33]
  ------------------
 1937|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      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|     33|    key = (unsigned char *)k_string;
 1943|     33|    key_len = ssh_string_len(k_string) + 4;
 1944|       |
 1945|     33|    IV_len = crypto->digest_len;
 1946|     33|    if (session->client) {
  ------------------
  |  Branch (1946:9): [True: 33, False: 0]
  ------------------
 1947|     33|        enckey_cli_to_srv_len = crypto->out_cipher->keysize / 8;
 1948|     33|        enckey_srv_to_cli_len = crypto->in_cipher->keysize / 8;
 1949|     33|        intkey_cli_to_srv_len = hmac_digest_len(crypto->out_hmac);
 1950|     33|        intkey_srv_to_cli_len = hmac_digest_len(crypto->in_hmac);
 1951|     33|    } else {
 1952|      0|        enckey_cli_to_srv_len = crypto->in_cipher->keysize / 8;
 1953|      0|        enckey_srv_to_cli_len = crypto->out_cipher->keysize / 8;
 1954|      0|        intkey_cli_to_srv_len = hmac_digest_len(crypto->in_hmac);
 1955|      0|        intkey_srv_to_cli_len = hmac_digest_len(crypto->out_hmac);
 1956|      0|    }
 1957|       |
 1958|     33|    IV_cli_to_srv = malloc(IV_len);
 1959|     33|    IV_srv_to_cli = malloc(IV_len);
 1960|     33|    enckey_cli_to_srv = malloc(enckey_cli_to_srv_len);
 1961|     33|    enckey_srv_to_cli = malloc(enckey_srv_to_cli_len);
 1962|     33|    intkey_cli_to_srv = malloc(intkey_cli_to_srv_len);
 1963|     33|    intkey_srv_to_cli = malloc(intkey_srv_to_cli_len);
 1964|     33|    if (IV_cli_to_srv == NULL || IV_srv_to_cli == NULL ||
  ------------------
  |  Branch (1964:9): [True: 0, False: 33]
  |  Branch (1964:34): [True: 0, False: 33]
  ------------------
 1965|     33|        enckey_cli_to_srv == NULL || enckey_srv_to_cli == NULL ||
  ------------------
  |  Branch (1965:9): [True: 0, False: 33]
  |  Branch (1965:38): [True: 0, False: 33]
  ------------------
 1966|     33|        intkey_cli_to_srv == NULL || intkey_srv_to_cli == NULL) {
  ------------------
  |  Branch (1966:9): [True: 0, False: 33]
  |  Branch (1966:38): [True: 0, False: 33]
  ------------------
 1967|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1968|      0|        goto error;
 1969|      0|    }
 1970|       |
 1971|       |    /* IV */
 1972|     33|    rc = ssh_kdf(crypto, key, key_len, 'A', IV_cli_to_srv, IV_len);
 1973|     33|    if (rc < 0) {
  ------------------
  |  Branch (1973:9): [True: 0, False: 33]
  ------------------
 1974|      0|        goto error;
 1975|      0|    }
 1976|     33|    rc = ssh_kdf(crypto, key, key_len, 'B', IV_srv_to_cli, IV_len);
 1977|     33|    if (rc < 0) {
  ------------------
  |  Branch (1977:9): [True: 0, False: 33]
  ------------------
 1978|      0|        goto error;
 1979|      0|    }
 1980|       |    /* Encryption Key */
 1981|     33|    rc = ssh_kdf(crypto, key, key_len, 'C', enckey_cli_to_srv,
 1982|     33|                 enckey_cli_to_srv_len);
 1983|     33|    if (rc < 0) {
  ------------------
  |  Branch (1983:9): [True: 0, False: 33]
  ------------------
 1984|      0|        goto error;
 1985|      0|    }
 1986|     33|    rc = ssh_kdf(crypto, key, key_len, 'D', enckey_srv_to_cli,
 1987|     33|                 enckey_srv_to_cli_len);
 1988|     33|    if (rc < 0) {
  ------------------
  |  Branch (1988:9): [True: 0, False: 33]
  ------------------
 1989|      0|        goto error;
 1990|      0|    }
 1991|       |    /* Integrity Key */
 1992|     33|    rc = ssh_kdf(crypto, key, key_len, 'E', intkey_cli_to_srv,
 1993|     33|                 intkey_cli_to_srv_len);
 1994|     33|    if (rc < 0) {
  ------------------
  |  Branch (1994:9): [True: 0, False: 33]
  ------------------
 1995|      0|        goto error;
 1996|      0|    }
 1997|     33|    rc = ssh_kdf(crypto, key, key_len, 'F', intkey_srv_to_cli,
 1998|     33|                 intkey_srv_to_cli_len);
 1999|     33|    if (rc < 0) {
  ------------------
  |  Branch (1999:9): [True: 0, False: 33]
  ------------------
 2000|      0|        goto error;
 2001|      0|    }
 2002|       |
 2003|     33|    if (session->client) {
  ------------------
  |  Branch (2003:9): [True: 33, False: 0]
  ------------------
 2004|     33|        crypto->encryptIV = IV_cli_to_srv;
 2005|     33|        crypto->decryptIV = IV_srv_to_cli;
 2006|     33|        crypto->encryptkey = enckey_cli_to_srv;
 2007|     33|        crypto->decryptkey = enckey_srv_to_cli;
 2008|     33|        crypto->encryptMAC = intkey_cli_to_srv;
 2009|     33|        crypto->decryptMAC = intkey_srv_to_cli;
 2010|     33|    } else {
 2011|      0|        crypto->encryptIV = IV_srv_to_cli;
 2012|      0|        crypto->decryptIV = IV_cli_to_srv;
 2013|      0|        crypto->encryptkey = enckey_srv_to_cli;
 2014|      0|        crypto->decryptkey = enckey_cli_to_srv;
 2015|      0|        crypto->encryptMAC = intkey_srv_to_cli;
 2016|      0|        crypto->decryptMAC = intkey_cli_to_srv;
 2017|      0|    }
 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|     33|    rc = 0;
 2033|     33|error:
 2034|     33|    ssh_string_burn(k_string);
 2035|     33|    SSH_STRING_FREE(k_string);
  ------------------
  |  |  924|     33|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 33, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 33]
  |  |  ------------------
  ------------------
 2036|     33|    if (rc != 0) {
  ------------------
  |  Branch (2036:9): [True: 0, False: 33]
  ------------------
 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|     33|    return rc;
 2046|     33|}
ssh_kex_is_gss:
 2055|      3|{
 2056|      3|    switch (crypto->kex_type) {
 2057|      0|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (2057:5): [True: 0, False: 3]
  ------------------
 2058|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (2058:5): [True: 0, False: 3]
  ------------------
 2059|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (2059:5): [True: 0, False: 3]
  ------------------
 2060|      0|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (2060:5): [True: 0, False: 3]
  ------------------
 2061|      0|        return true;
 2062|      3|    default:
  ------------------
  |  Branch (2062:5): [True: 3, False: 0]
  ------------------
 2063|       |        return false;
 2064|      3|    }
 2065|      3|}
kex.c:cmp_first_kex_algo:
  361|    168|                              const char *server_str) {
  362|    168|    size_t client_kex_len;
  363|    168|    size_t server_kex_len;
  364|       |
  365|    168|    const char *colon = NULL;
  366|       |
  367|    168|    int is_wrong = 1;
  368|       |
  369|    168|    if (client_str == NULL || server_str == NULL) {
  ------------------
  |  Branch (369:9): [True: 0, False: 168]
  |  Branch (369:31): [True: 0, False: 168]
  ------------------
  370|      0|        return is_wrong;
  371|      0|    }
  372|       |
  373|    168|    colon = strchr(client_str, ',');
  374|    168|    if (colon == NULL) {
  ------------------
  |  Branch (374:9): [True: 0, False: 168]
  ------------------
  375|      0|        client_kex_len = strlen(client_str);
  376|    168|    } else {
  377|    168|        client_kex_len = colon - client_str;
  378|    168|    }
  379|       |
  380|    168|    colon = strchr(server_str, ',');
  381|    168|    if (colon == NULL) {
  ------------------
  |  Branch (381:9): [True: 3, False: 165]
  ------------------
  382|      3|        server_kex_len = strlen(server_str);
  383|    165|    } else {
  384|    165|        server_kex_len = colon - server_str;
  385|    165|    }
  386|       |
  387|    168|    if (client_kex_len != server_kex_len) {
  ------------------
  |  Branch (387:9): [True: 157, False: 11]
  ------------------
  388|    157|        return is_wrong;
  389|    157|    }
  390|       |
  391|     11|    is_wrong = (strncmp(client_str, server_str, client_kex_len) != 0);
  392|       |
  393|     11|    return is_wrong;
  394|    168|}
kex.c:ssh_find_aead_hmac:
  952|    416|{
  953|    416|    if (cipher == NULL) {
  ------------------
  |  Branch (953:9): [True: 0, False: 416]
  ------------------
  954|      0|        return NULL;
  955|    416|    } else if (strcmp(cipher, "chacha20-poly1305@openssh.com") == 0) {
  ------------------
  |  Branch (955:16): [True: 0, False: 416]
  ------------------
  956|      0|        return "aead-poly1305";
  957|    416|    } else if (strcmp(cipher, "aes256-gcm@openssh.com") == 0) {
  ------------------
  |  Branch (957:16): [True: 0, False: 416]
  ------------------
  958|      0|        return "aead-gcm";
  959|    416|    } else if (strcmp(cipher, "aes128-gcm@openssh.com") == 0) {
  ------------------
  |  Branch (959:16): [True: 0, False: 416]
  ------------------
  960|      0|        return "aead-gcm";
  961|      0|    }
  962|    416|    return NULL;
  963|    416|}
kex.c:kex_select_kex_type:
  967|    206|{
  968|    206|    if (strcmp(kex, "diffie-hellman-group1-sha1") == 0) {
  ------------------
  |  Branch (968:9): [True: 0, False: 206]
  ------------------
  969|      0|        return SSH_KEX_DH_GROUP1_SHA1;
  970|    206|    } else if (strncmp(kex, "gss-group14-sha256-", 19) == 0) {
  ------------------
  |  Branch (970:16): [True: 0, False: 206]
  ------------------
  971|      0|        return SSH_GSS_KEX_DH_GROUP14_SHA256;
  972|    206|    } else if (strncmp(kex, "gss-group16-sha512-", 19) == 0) {
  ------------------
  |  Branch (972:16): [True: 0, False: 206]
  ------------------
  973|      0|        return SSH_GSS_KEX_DH_GROUP16_SHA512;
  974|    206|    } else if (strncmp(kex, "gss-nistp256-sha256-", 20) == 0) {
  ------------------
  |  Branch (974:16): [True: 0, False: 206]
  ------------------
  975|      0|        return SSH_GSS_KEX_ECDH_NISTP256_SHA256;
  976|    206|    } else if (strncmp(kex, "gss-curve25519-sha256-", 22) == 0) {
  ------------------
  |  Branch (976:16): [True: 0, False: 206]
  ------------------
  977|      0|        return SSH_GSS_KEX_CURVE25519_SHA256;
  978|    206|    } else if (strcmp(kex, "diffie-hellman-group14-sha1") == 0) {
  ------------------
  |  Branch (978:16): [True: 0, False: 206]
  ------------------
  979|      0|        return SSH_KEX_DH_GROUP14_SHA1;
  980|    206|    } else if (strcmp(kex, "diffie-hellman-group14-sha256") == 0) {
  ------------------
  |  Branch (980:16): [True: 4, False: 202]
  ------------------
  981|      4|        return SSH_KEX_DH_GROUP14_SHA256;
  982|    202|    } else if (strcmp(kex, "diffie-hellman-group16-sha512") == 0) {
  ------------------
  |  Branch (982:16): [True: 2, False: 200]
  ------------------
  983|      2|        return SSH_KEX_DH_GROUP16_SHA512;
  984|    200|    } else if (strcmp(kex, "diffie-hellman-group18-sha512") == 0) {
  ------------------
  |  Branch (984:16): [True: 16, False: 184]
  ------------------
  985|     16|        return SSH_KEX_DH_GROUP18_SHA512;
  986|     16|#ifdef WITH_GEX
  987|    184|    } else if (strcmp(kex, "diffie-hellman-group-exchange-sha1") == 0) {
  ------------------
  |  Branch (987:16): [True: 0, False: 184]
  ------------------
  988|      0|        return SSH_KEX_DH_GEX_SHA1;
  989|    184|    } else if (strcmp(kex, "diffie-hellman-group-exchange-sha256") == 0) {
  ------------------
  |  Branch (989:16): [True: 7, False: 177]
  ------------------
  990|      7|        return SSH_KEX_DH_GEX_SHA256;
  991|      7|#endif /* WITH_GEX */
  992|    177|    } else if (strcmp(kex, "ecdh-sha2-nistp256") == 0) {
  ------------------
  |  Branch (992:16): [True: 4, False: 173]
  ------------------
  993|      4|        return SSH_KEX_ECDH_SHA2_NISTP256;
  994|    173|    } else if (strcmp(kex, "ecdh-sha2-nistp384") == 0) {
  ------------------
  |  Branch (994:16): [True: 1, False: 172]
  ------------------
  995|      1|        return SSH_KEX_ECDH_SHA2_NISTP384;
  996|    172|    } else if (strcmp(kex, "ecdh-sha2-nistp521") == 0) {
  ------------------
  |  Branch (996:16): [True: 1, False: 171]
  ------------------
  997|      1|        return SSH_KEX_ECDH_SHA2_NISTP521;
  998|    171|    } else if (strcmp(kex, "curve25519-sha256@libssh.org") == 0) {
  ------------------
  |  Branch (998:16): [True: 34, False: 137]
  ------------------
  999|     34|        return SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG;
 1000|    137|    } else if (strcmp(kex, "curve25519-sha256") == 0) {
  ------------------
  |  Branch (1000:16): [True: 7, False: 130]
  ------------------
 1001|      7|        return SSH_KEX_CURVE25519_SHA256;
 1002|    130|    } else if (strcmp(kex, "sntrup761x25519-sha512@openssh.com") == 0) {
  ------------------
  |  Branch (1002:16): [True: 6, False: 124]
  ------------------
 1003|      6|        return SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM;
 1004|    124|    } else if (strcmp(kex, "sntrup761x25519-sha512") == 0) {
  ------------------
  |  Branch (1004:16): [True: 20, False: 104]
  ------------------
 1005|     20|        return SSH_KEX_SNTRUP761X25519_SHA512;
 1006|    104|    } else if (strcmp(kex, "mlkem768x25519-sha256") == 0) {
  ------------------
  |  Branch (1006:16): [True: 0, False: 104]
  ------------------
 1007|      0|        return SSH_KEX_MLKEM768X25519_SHA256;
 1008|    104|    } else if (strcmp(kex, "mlkem768nistp256-sha256") == 0) {
  ------------------
  |  Branch (1008:16): [True: 104, False: 0]
  ------------------
 1009|    104|        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|    104|    }
 1015|       |    /* should not happen. We should be getting only valid names at this stage */
 1016|      0|    return 0;
 1017|    206|}
kex.c:revert_kex_callbacks:
 1026|    142|{
 1027|    142|    switch (session->next_crypto->kex_type) {
  ------------------
  |  Branch (1027:13): [True: 0, False: 142]
  ------------------
 1028|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1028:5): [True: 0, False: 142]
  ------------------
 1029|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1029:5): [True: 0, False: 142]
  ------------------
 1030|      0|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1030:5): [True: 0, False: 142]
  ------------------
 1031|      0|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1031:5): [True: 0, False: 142]
  ------------------
 1032|      0|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1032:5): [True: 0, False: 142]
  ------------------
 1033|      0|        ssh_client_dh_remove_callbacks(session);
 1034|      0|        break;
 1035|      0|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1035:5): [True: 0, False: 142]
  ------------------
 1036|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1036:5): [True: 0, False: 142]
  ------------------
 1037|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1037:5): [True: 0, False: 142]
  ------------------
 1038|      0|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1038:5): [True: 0, False: 142]
  ------------------
 1039|       |#ifdef WITH_GSSAPI
 1040|       |        ssh_client_gss_kex_remove_callbacks(session);
 1041|       |#endif /* WITH_GSSAPI */
 1042|      0|        break;
 1043|      0|#ifdef WITH_GEX
 1044|      0|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (1044:5): [True: 0, False: 142]
  ------------------
 1045|      0|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1045:5): [True: 0, False: 142]
  ------------------
 1046|      0|        ssh_client_dhgex_remove_callbacks(session);
 1047|      0|        break;
 1048|      0|#endif /* WITH_GEX */
 1049|      0|#ifdef HAVE_ECDH
 1050|      0|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (1050:5): [True: 0, False: 142]
  ------------------
 1051|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1051:5): [True: 0, False: 142]
  ------------------
 1052|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1052:5): [True: 0, False: 142]
  ------------------
 1053|      0|        ssh_client_ecdh_remove_callbacks(session);
 1054|      0|        break;
 1055|      0|#endif
 1056|      0|#ifdef HAVE_CURVE25519
 1057|      0|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1057:5): [True: 0, False: 142]
  ------------------
 1058|      0|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1058:5): [True: 0, False: 142]
  ------------------
 1059|      0|        ssh_client_curve25519_remove_callbacks(session);
 1060|      0|        break;
 1061|      0|#endif
 1062|      0|#ifdef HAVE_SNTRUP761
 1063|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1063:5): [True: 0, False: 142]
  ------------------
 1064|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1064:5): [True: 0, False: 142]
  ------------------
 1065|      0|        ssh_client_sntrup761x25519_remove_callbacks(session);
 1066|      0|        break;
 1067|      0|#endif
 1068|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1068:5): [True: 0, False: 142]
  ------------------
 1069|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1069:5): [True: 0, False: 142]
  ------------------
 1070|       |#ifdef HAVE_MLKEM1024
 1071|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1072|       |#endif
 1073|      0|        ssh_client_hybrid_mlkem_remove_callbacks(session);
 1074|      0|        break;
 1075|    142|    }
 1076|    142|}

ssh_known_hosts_get_algorithms_names:
  566|    442|{
  567|    442|    char methods_buffer[256 + 1] = {0};
  568|    442|    struct ssh_list *entry_list = NULL;
  569|    442|    struct ssh_iterator *it = NULL;
  570|    442|    char *host_port = NULL;
  571|    442|    size_t count;
  572|    442|    bool needcomma = false;
  573|    442|    char *names = NULL;
  574|       |
  575|    442|    int rc;
  576|       |
  577|    442|    if (session->opts.knownhosts == NULL ||
  ------------------
  |  Branch (577:9): [True: 0, False: 442]
  ------------------
  578|    442|        session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (578:9): [True: 0, False: 442]
  ------------------
  579|      0|        if (ssh_options_apply(session) < 0) {
  ------------------
  |  Branch (579:13): [True: 0, False: 0]
  ------------------
  580|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      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|    442|    host_port = ssh_session_get_host_port(session);
  589|    442|    if (host_port == NULL) {
  ------------------
  |  Branch (589:9): [True: 0, False: 442]
  ------------------
  590|      0|        return NULL;
  591|      0|    }
  592|       |
  593|    442|    rc = ssh_known_hosts_read_entries(host_port,
  594|    442|                                      session->opts.knownhosts,
  595|    442|                                      &entry_list);
  596|    442|    if (rc != 0) {
  ------------------
  |  Branch (596:9): [True: 0, False: 442]
  ------------------
  597|      0|        SAFE_FREE(host_port);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  598|      0|        ssh_knownhosts_entries_free(entry_list);
  599|      0|        return NULL;
  600|      0|    }
  601|       |
  602|    442|    rc = ssh_known_hosts_read_entries(host_port,
  603|    442|                                      session->opts.global_knownhosts,
  604|    442|                                      &entry_list);
  605|    442|    SAFE_FREE(host_port);
  ------------------
  |  |  375|    442|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 442, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 442]
  |  |  ------------------
  ------------------
  606|    442|    if (rc != 0) {
  ------------------
  |  Branch (606:9): [True: 0, False: 442]
  ------------------
  607|      0|        ssh_knownhosts_entries_free(entry_list);
  608|      0|        return NULL;
  609|      0|    }
  610|       |
  611|    442|    if (entry_list == NULL) {
  ------------------
  |  Branch (611:9): [True: 442, False: 0]
  ------------------
  612|    442|        return NULL;
  613|    442|    }
  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);
  ------------------
  |  |  120|      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|    442|{
  332|    442|    char *host_port = NULL;
  333|    442|    char *host = NULL;
  334|       |
  335|    442|    if (session->opts.host == NULL) {
  ------------------
  |  Branch (335:9): [True: 0, False: 442]
  ------------------
  336|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      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|    442|    host = ssh_lowercase(session->opts.host);
  345|    442|    if (host == NULL) {
  ------------------
  |  Branch (345:9): [True: 0, False: 442]
  ------------------
  346|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  347|      0|        return NULL;
  348|      0|    }
  349|       |
  350|    442|    if (session->opts.port == 0 || session->opts.port == 22) {
  ------------------
  |  Branch (350:9): [True: 0, False: 442]
  |  Branch (350:36): [True: 442, False: 0]
  ------------------
  351|    442|        host_port = host;
  352|    442|    } else {
  353|      0|        host_port = ssh_hostport(host, session->opts.port);
  354|      0|        SAFE_FREE(host);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  355|      0|        if (host_port == NULL) {
  ------------------
  |  Branch (355:13): [True: 0, False: 0]
  ------------------
  356|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  357|      0|            return NULL;
  358|      0|        }
  359|      0|    }
  360|       |
  361|    442|    return host_port;
  362|    442|}
knownhosts.c:ssh_known_hosts_read_entries:
  240|    884|{
  241|    884|    char line[MAX_LINE_SIZE];
  242|    884|    size_t lineno = 0;
  243|    884|    size_t len = 0;
  244|    884|    FILE *fp = NULL;
  245|    884|    int rc;
  246|       |
  247|    884|    fp = ssh_strict_fopen(filename, SSH_MAX_CONFIG_FILE_SIZE);
  ------------------
  |  |  530|    884|#define SSH_MAX_CONFIG_FILE_SIZE 16 * 1024 * 1024
  ------------------
  248|    884|    if (fp == NULL) {
  ------------------
  |  Branch (248:9): [True: 884, False: 0]
  ------------------
  249|    884|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  285|    884|    do {                                                            \
  |  |  286|    884|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  287|    884|        _ssh_log(priority,                                          \
  |  |  288|    884|                 __func__,                                          \
  |  |  289|    884|                 __VA_ARGS__,                                       \
  |  |  290|    884|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  522|    884|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  291|    884|    } while (0)
  |  |  ------------------
  |  |  |  Branch (291:14): [Folded, False: 884]
  |  |  ------------------
  ------------------
  250|    884|                         errno,
  251|    884|                         "Failed to open the known_hosts file '%s': %s",
  252|    884|                         filename);
  253|       |        /* The missing file is not an error here */
  254|    884|        return SSH_OK;
  ------------------
  |  |  316|    884|#define SSH_OK 0     /* No error */
  ------------------
  255|    884|    }
  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);
  ------------------
  |  |  120|      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_kdf:
  337|    198|{
  338|    198|    return sshkdf_derive_key(crypto, key, key_len,
  339|    198|                             key_type, output, requested_len);
  340|    198|}
ssh_get_ciphertab:
 1382|     99|{
 1383|     99|    return ssh_ciphertab;
 1384|     99|}
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,
  ------------------
  |  |  283|      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|}
pki_key_make_ecpoint_string:
 1621|    110|{
 1622|    110|    ssh_string s = NULL;
 1623|    110|    size_t len;
 1624|       |
 1625|    110|    len = EC_POINT_point2oct(g,
 1626|    110|                             p,
 1627|    110|                             POINT_CONVERSION_UNCOMPRESSED,
 1628|    110|                             NULL,
 1629|    110|                             0,
 1630|    110|                             NULL);
 1631|    110|    if (len == 0) {
  ------------------
  |  Branch (1631:9): [True: 0, False: 110]
  ------------------
 1632|      0|        return NULL;
 1633|      0|    }
 1634|       |
 1635|    110|    s = ssh_string_new(len);
 1636|    110|    if (s == NULL) {
  ------------------
  |  Branch (1636:9): [True: 0, False: 110]
  ------------------
 1637|      0|        return NULL;
 1638|      0|    }
 1639|       |
 1640|    110|    len = EC_POINT_point2oct(g,
 1641|    110|                             p,
 1642|    110|                             POINT_CONVERSION_UNCOMPRESSED,
 1643|    110|                             ssh_string_data(s),
 1644|    110|                             ssh_string_len(s),
 1645|    110|                             NULL);
 1646|    110|    if (len != ssh_string_len(s)) {
  ------------------
  |  Branch (1646:9): [True: 0, False: 110]
  ------------------
 1647|      0|        SSH_STRING_FREE(s);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1648|      0|        return NULL;
 1649|      0|    }
 1650|       |
 1651|    110|    return s;
 1652|    110|}
libcrypto.c:none_crypt:
 1217|    535|{
 1218|    535|    memcpy(out, in, len);
 1219|    535|}

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

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

sha256_init:
   97|    140|{
   98|    140|    int rc;
   99|    140|    SHA256CTX c = EVP_MD_CTX_new();
  100|    140|    if (c == NULL) {
  ------------------
  |  Branch (100:9): [True: 0, False: 140]
  ------------------
  101|      0|        return NULL;
  102|      0|    }
  103|    140|    rc = EVP_DigestInit_ex(c, EVP_sha256(), NULL);
  104|    140|    if (rc == 0) {
  ------------------
  |  Branch (104:9): [True: 0, False: 140]
  ------------------
  105|      0|        EVP_MD_CTX_free(c);
  106|       |        c = NULL;
  107|      0|    }
  108|    140|    return c;
  109|    140|}
sha256_update:
  119|    500|{
  120|    500|    int rc = EVP_DigestUpdate(c, data, len);
  121|    500|    if (rc != 1) {
  ------------------
  |  Branch (121:9): [True: 0, False: 500]
  ------------------
  122|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  123|      0|    }
  124|    500|    return SSH_OK;
  ------------------
  |  |  316|    500|#define SSH_OK 0     /* No error */
  ------------------
  125|    500|}
sha256_final:
  129|    140|{
  130|    140|    unsigned int mdlen = 0;
  131|    140|    int rc = EVP_DigestFinal(c, md, &mdlen);
  132|       |
  133|    140|    EVP_MD_CTX_free(c);
  134|    140|    if (rc != 1) {
  ------------------
  |  Branch (134:9): [True: 0, False: 140]
  ------------------
  135|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  136|      0|    }
  137|    140|    return SSH_OK;
  ------------------
  |  |  316|    140|#define SSH_OK 0     /* No error */
  ------------------
  138|    140|}
sha256:
  142|     20|{
  143|     20|    SHA256CTX c = sha256_init();
  144|     20|    int rc;
  145|       |
  146|     20|    if (c == NULL) {
  ------------------
  |  Branch (146:9): [True: 0, False: 20]
  ------------------
  147|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  148|      0|    }
  149|     20|    rc = sha256_update(c, digest, len);
  150|     20|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     20|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (150:9): [True: 0, False: 20]
  ------------------
  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|     20|    return sha256_final(hash, c);
  155|     20|}
sha512_init:
  221|    117|{
  222|    117|    int rc = 0;
  223|    117|    SHA512CTX c = EVP_MD_CTX_new();
  224|    117|    if (c == NULL) {
  ------------------
  |  Branch (224:9): [True: 0, False: 117]
  ------------------
  225|      0|        return NULL;
  226|      0|    }
  227|    117|    rc = EVP_DigestInit_ex(c, EVP_sha512(), NULL);
  228|    117|    if (rc == 0) {
  ------------------
  |  Branch (228:9): [True: 0, False: 117]
  ------------------
  229|      0|        EVP_MD_CTX_free(c);
  230|       |        c = NULL;
  231|      0|    }
  232|    117|    return c;
  233|    117|}
sha512_update:
  243|    351|{
  244|    351|    int rc = EVP_DigestUpdate(c, data, len);
  245|    351|    if (rc != 1) {
  ------------------
  |  Branch (245:9): [True: 0, False: 351]
  ------------------
  246|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  247|      0|    }
  248|    351|    return SSH_OK;
  ------------------
  |  |  316|    351|#define SSH_OK 0     /* No error */
  ------------------
  249|    351|}
sha512_final:
  253|    117|{
  254|    117|    unsigned int mdlen = 0;
  255|    117|    int rc = EVP_DigestFinal(c, md, &mdlen);
  256|       |
  257|    117|    EVP_MD_CTX_free(c);
  258|    117|    if (rc != 1) {
  ------------------
  |  Branch (258:9): [True: 0, False: 117]
  ------------------
  259|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  260|      0|    }
  261|    117|    return SSH_OK;
  ------------------
  |  |  316|    117|#define SSH_OK 0     /* No error */
  ------------------
  262|    117|}
sha512:
  266|     39|{
  267|     39|    SHA512CTX c = sha512_init();
  268|     39|    int rc;
  269|       |
  270|     39|    if (c == NULL) {
  ------------------
  |  Branch (270:9): [True: 0, False: 39]
  ------------------
  271|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  272|      0|    }
  273|     39|    rc = sha512_update(c, digest, len);
  274|     39|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     39|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (274:9): [True: 0, False: 39]
  ------------------
  275|      0|        EVP_MD_CTX_free(c);
  276|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  277|      0|    }
  278|     39|    return sha512_final(hash, c);
  279|     39|}

ssh_is_ipaddr_v4:
  430|  1.45k|{
  431|  1.45k|    int rc = -1;
  432|  1.45k|    struct in_addr dest;
  433|       |
  434|  1.45k|    rc = inet_pton(AF_INET, str, &dest);
  435|  1.45k|    if (rc > 0) {
  ------------------
  |  Branch (435:9): [True: 1.45k, False: 0]
  ------------------
  436|  1.45k|        return 1;
  437|  1.45k|    }
  438|       |
  439|      0|    return 0;
  440|  1.45k|}
ssh_is_ipaddr:
  450|  1.45k|{
  451|  1.45k|    int rc = -1;
  452|  1.45k|    char *s = strdup(str);
  453|       |
  454|  1.45k|    if (s == NULL) {
  ------------------
  |  Branch (454:9): [True: 0, False: 1.45k]
  ------------------
  455|      0|        return -1;
  456|      0|    }
  457|  1.45k|    if (strchr(s, ':')) {
  ------------------
  |  Branch (457:9): [True: 0, False: 1.45k]
  ------------------
  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.45k|    free(s);
  478|  1.45k|    return ssh_is_ipaddr_v4(str);
  479|  1.45k|}
ssh_get_user_home_dir:
  495|  2.43k|{
  496|  2.43k|    char *szPath = NULL;
  497|       |
  498|       |    /* If used previously, reuse cached value */
  499|  2.43k|    if (session != NULL && session->opts.homedir != NULL) {
  ------------------
  |  Branch (499:9): [True: 1.94k, False: 486]
  |  Branch (499:28): [True: 1.45k, False: 486]
  ------------------
  500|  1.45k|        return strdup(session->opts.homedir);
  501|  1.45k|    }
  502|       |
  503|    972|    szPath = ssh_get_user_home_dir_internal();
  504|    972|    if (szPath == NULL) {
  ------------------
  |  Branch (504:9): [True: 0, False: 972]
  ------------------
  505|      0|        return NULL;
  506|      0|    }
  507|       |
  508|    972|    if (session != NULL) {
  ------------------
  |  Branch (508:9): [True: 486, False: 486]
  ------------------
  509|       |        /* cache it:
  510|       |         * failure is not fatal -- at worst we will just not cache it */
  511|    486|        session->opts.homedir = strdup(szPath);
  512|    486|    }
  513|       |
  514|    972|    return szPath;
  515|    972|}
ssh_lowercase:
  526|    442|{
  527|    442|    char *new = NULL, *p = NULL;
  528|       |
  529|    442|    if (str == NULL) {
  ------------------
  |  Branch (529:9): [True: 0, False: 442]
  ------------------
  530|      0|        return NULL;
  531|      0|    }
  532|       |
  533|    442|    new = strdup(str);
  534|    442|    if (new == NULL) {
  ------------------
  |  Branch (534:9): [True: 0, False: 442]
  ------------------
  535|      0|        return NULL;
  536|      0|    }
  537|       |
  538|  4.42k|    for (p = new; *p; p++) {
  ------------------
  |  Branch (538:19): [True: 3.97k, False: 442]
  ------------------
  539|  3.97k|        *p = tolower(*p);
  ------------------
  |  Branch (539:14): [True: 0, False: 0]
  |  Branch (539:14): [True: 0, False: 0]
  |  Branch (539:14): [Folded, False: 3.97k]
  ------------------
  540|  3.97k|    }
  541|       |
  542|    442|    return new;
  543|    442|}
ssh_list_new:
  865|  2.38k|{
  866|  2.38k|    struct ssh_list *ret = malloc(sizeof(struct ssh_list));
  867|  2.38k|    if (ret == NULL) {
  ------------------
  |  Branch (867:9): [True: 0, False: 2.38k]
  ------------------
  868|      0|        return NULL;
  869|      0|    }
  870|  2.38k|    ret->root = ret->end = NULL;
  871|  2.38k|    return ret;
  872|  2.38k|}
ssh_list_free:
  882|  3.31k|{
  883|  3.31k|    struct ssh_iterator *ptr = NULL, *next = NULL;
  884|  3.31k|    if (!list)
  ------------------
  |  Branch (884:9): [True: 926, False: 2.38k]
  ------------------
  885|    926|        return;
  886|  2.38k|    ptr = list->root;
  887|  2.88k|    while (ptr) {
  ------------------
  |  Branch (887:12): [True: 503, False: 2.38k]
  ------------------
  888|    503|        next = ptr->next;
  889|    503|        SAFE_FREE(ptr);
  ------------------
  |  |  375|    503|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 503, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 503]
  |  |  ------------------
  ------------------
  890|    503|        ptr = next;
  891|    503|    }
  892|       |    SAFE_FREE(list);
  ------------------
  |  |  375|  2.38k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2.38k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 2.38k]
  |  |  ------------------
  ------------------
  893|  2.38k|}
ssh_list_get_iterator:
  903|  15.3k|{
  904|  15.3k|    if (!list)
  ------------------
  |  Branch (904:9): [True: 1.48k, False: 13.9k]
  ------------------
  905|  1.48k|        return NULL;
  906|  13.9k|    return list->root;
  907|  15.3k|}
ssh_list_find:
  918|    145|{
  919|    145|    struct ssh_iterator *it = NULL;
  920|       |
  921|    290|    for (it = ssh_list_get_iterator(list); it != NULL ; it = it->next)
  ------------------
  |  Branch (921:44): [True: 290, False: 0]
  ------------------
  922|    290|        if (it->data == value)
  ------------------
  |  Branch (922:13): [True: 145, False: 145]
  ------------------
  923|    145|            return it;
  924|      0|    return NULL;
  925|    145|}
ssh_list_append:
  969|  3.56k|{
  970|  3.56k|  struct ssh_iterator *iterator = NULL;
  971|       |
  972|  3.56k|  if (list == NULL) {
  ------------------
  |  Branch (972:7): [True: 0, False: 3.56k]
  ------------------
  973|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  974|      0|  }
  975|       |
  976|  3.56k|  iterator = ssh_iterator_new(data);
  977|  3.56k|  if (iterator == NULL) {
  ------------------
  |  Branch (977:7): [True: 0, False: 3.56k]
  ------------------
  978|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  979|      0|  }
  980|       |
  981|  3.56k|  if(!list->end){
  ------------------
  |  Branch (981:6): [True: 1.41k, False: 2.15k]
  ------------------
  982|       |    /* list is empty */
  983|  1.41k|    list->root=list->end=iterator;
  984|  2.15k|  } else {
  985|       |    /* put it on end of list */
  986|  2.15k|    list->end->next=iterator;
  987|  2.15k|    list->end=iterator;
  988|  2.15k|  }
  989|  3.56k|  return SSH_OK;
  ------------------
  |  |  316|  3.56k|#define SSH_OK 0     /* No error */
  ------------------
  990|  3.56k|}
ssh_list_remove:
 1032|    145|{
 1033|    145|    struct ssh_iterator *ptr = NULL, *prev = NULL;
 1034|       |
 1035|    145|    if (list == NULL) {
  ------------------
  |  Branch (1035:9): [True: 0, False: 145]
  ------------------
 1036|      0|        return;
 1037|      0|    }
 1038|       |
 1039|    145|    prev = NULL;
 1040|    145|    ptr = list->root;
 1041|    290|    while (ptr && ptr != iterator) {
  ------------------
  |  Branch (1041:12): [True: 290, False: 0]
  |  Branch (1041:19): [True: 145, False: 145]
  ------------------
 1042|    145|        prev = ptr;
 1043|    145|        ptr = ptr->next;
 1044|    145|    }
 1045|    145|    if (!ptr) {
  ------------------
  |  Branch (1045:9): [True: 0, False: 145]
  ------------------
 1046|       |        /* we did not find the element */
 1047|      0|        return;
 1048|      0|    }
 1049|       |    /* unlink it */
 1050|    145|    if (prev)
  ------------------
  |  Branch (1050:9): [True: 145, False: 0]
  ------------------
 1051|    145|        prev->next = ptr->next;
 1052|       |    /* if iterator was the head */
 1053|    145|    if (list->root == iterator)
  ------------------
  |  Branch (1053:9): [True: 0, False: 145]
  ------------------
 1054|      0|        list->root = iterator->next;
 1055|       |    /* if iterator was the tail */
 1056|    145|    if (list->end == iterator)
  ------------------
  |  Branch (1056:9): [True: 145, False: 0]
  ------------------
 1057|    145|        list->end = prev;
 1058|       |    SAFE_FREE(iterator);
  ------------------
  |  |  375|    145|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 145, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 145]
  |  |  ------------------
  ------------------
 1059|    145|}
_ssh_list_pop_head:
 1073|  6.75k|{
 1074|  6.75k|  struct ssh_iterator *iterator = NULL;
 1075|  6.75k|  const void *data = NULL;
 1076|       |
 1077|  6.75k|  if (list == NULL) {
  ------------------
  |  Branch (1077:7): [True: 1.41k, False: 5.34k]
  ------------------
 1078|  1.41k|      return NULL;
 1079|  1.41k|  }
 1080|       |
 1081|  5.34k|  iterator = list->root;
 1082|  5.34k|  if (iterator == NULL) {
  ------------------
  |  Branch (1082:7): [True: 2.43k, False: 2.91k]
  ------------------
 1083|  2.43k|      return NULL;
 1084|  2.43k|  }
 1085|  2.91k|  data=iterator->data;
 1086|  2.91k|  list->root=iterator->next;
 1087|  2.91k|  if(list->end==iterator)
  ------------------
  |  Branch (1087:6): [True: 972, False: 1.94k]
  ------------------
 1088|    972|    list->end=NULL;
 1089|       |  SAFE_FREE(iterator);
  ------------------
  |  |  375|  2.91k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2.91k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 2.91k]
  |  |  ------------------
  ------------------
 1090|  2.91k|  return data;
 1091|  5.34k|}
ssh_path_expand_tilde:
 1309|  2.43k|{
 1310|  2.43k|    char *h = NULL, *r = NULL;
 1311|  2.43k|    const char *p = NULL;
 1312|  2.43k|    size_t ld;
 1313|  2.43k|    size_t lh = 0;
 1314|  2.43k|    int add_slash = 0;
 1315|       |
 1316|  2.43k|    if (d[0] != '~') {
  ------------------
  |  Branch (1316:9): [True: 1.94k, False: 486]
  ------------------
 1317|  1.94k|        return strdup(d);
 1318|  1.94k|    }
 1319|    486|    d++;
 1320|       |
 1321|       |    /* handle ~user/path */
 1322|    486|    p = strchr(d, '/');
 1323|    486|    if (p != NULL && p > d) {
  ------------------
  |  Branch (1323:9): [True: 486, False: 0]
  |  Branch (1323:22): [True: 0, False: 486]
  ------------------
 1324|       |#ifdef _WIN32
 1325|       |        return strdup(d);
 1326|       |#else
 1327|      0|        struct passwd *pw = NULL;
 1328|      0|        size_t s = p - d;
 1329|      0|        char u[128];
 1330|       |
 1331|      0|        if (s >= sizeof(u)) {
  ------------------
  |  Branch (1331:13): [True: 0, False: 0]
  ------------------
 1332|      0|            return NULL;
 1333|      0|        }
 1334|      0|        memcpy(u, d, s);
 1335|      0|        u[s] = '\0';
 1336|      0|        pw = getpwnam(u);
 1337|      0|        if (pw == NULL) {
  ------------------
  |  Branch (1337:13): [True: 0, False: 0]
  ------------------
 1338|      0|            return NULL;
 1339|      0|        }
 1340|      0|        h = strdup(pw->pw_dir);
 1341|      0|#endif
 1342|    486|    } else {
 1343|    486|        p = (char *) d;
 1344|    486|        h = ssh_get_user_home_dir(NULL);
 1345|    486|    }
 1346|       |
 1347|    486|    if (h == NULL) {
  ------------------
  |  Branch (1347:9): [True: 0, False: 486]
  ------------------
 1348|      0|        return NULL;
 1349|      0|    }
 1350|    486|    lh = strlen(h);
 1351|       |
 1352|       |    /* Strip all leading slashes from the suffix path */
 1353|    972|    while (*p == '/') {
  ------------------
  |  Branch (1353:12): [True: 486, False: 486]
  ------------------
 1354|    486|        p++;
 1355|    486|    }
 1356|    486|    ld = strlen(p);
 1357|       |
 1358|       |    /* Does the home directory path end with a slash? */
 1359|    486|    add_slash = (lh > 0 && h[lh - 1] == '/') ? 0 : 1;
  ------------------
  |  Branch (1359:18): [True: 486, False: 0]
  |  Branch (1359:28): [True: 0, False: 486]
  ------------------
 1360|       |
 1361|    486|    r = malloc(lh + add_slash + ld + 1);
 1362|    486|    if (r == NULL) {
  ------------------
  |  Branch (1362:9): [True: 0, False: 486]
  ------------------
 1363|      0|        SAFE_FREE(h);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1364|      0|        return NULL;
 1365|      0|    }
 1366|       |
 1367|    486|    if (lh > 0) {
  ------------------
  |  Branch (1367:9): [True: 486, False: 0]
  ------------------
 1368|    486|        memcpy(r, h, lh);
 1369|    486|    }
 1370|    486|    SAFE_FREE(h);
  ------------------
  |  |  375|    486|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 486, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 486]
  |  |  ------------------
  ------------------
 1371|       |
 1372|    486|    if (add_slash) {
  ------------------
  |  Branch (1372:9): [True: 486, False: 0]
  ------------------
 1373|    486|        r[lh] = '/';
 1374|    486|    }
 1375|    486|    memcpy(r + lh + add_slash, p, ld + 1);
 1376|       |
 1377|    486|    return r;
 1378|    486|}
ssh_path_expand_escape:
 1715|  1.94k|{
 1716|  1.94k|    return ssh_path_expand_internal(session, s, false, true);
 1717|  1.94k|}
ssh_string_expand_escape:
 1720|    486|{
 1721|    486|    return ssh_path_expand_internal(session, s, false, false);
 1722|    486|}
ssh_analyze_banner:
 1755|    453|{
 1756|    453|    const char *banner = NULL;
 1757|    453|    const char *openssh = NULL;
 1758|    453|    const char *ios = NULL;
 1759|       |
 1760|    453|    if (server) {
  ------------------
  |  Branch (1760:9): [True: 0, False: 453]
  ------------------
 1761|      0|        banner = session->clientbanner;
 1762|    453|    } else {
 1763|    453|        banner = session->serverbanner;
 1764|    453|    }
 1765|       |
 1766|    453|    if (banner == NULL) {
  ------------------
  |  Branch (1766:9): [True: 0, False: 453]
  ------------------
 1767|      0|        ssh_set_error(session, SSH_FATAL, "Invalid banner");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1768|      0|        return -1;
 1769|      0|    }
 1770|       |
 1771|       |    /*
 1772|       |     * Typical banners e.g. are:
 1773|       |     *
 1774|       |     * SSH-1.5-openSSH_5.4
 1775|       |     * SSH-1.99-openSSH_3.0
 1776|       |     *
 1777|       |     * SSH-2.0-something
 1778|       |     * 012345678901234567890
 1779|       |     */
 1780|    453|    if (strlen(banner) < 6 ||
  ------------------
  |  Branch (1780:9): [True: 1, False: 452]
  ------------------
 1781|    452|        strncmp(banner, "SSH-", 4) != 0) {
  ------------------
  |  Branch (1781:9): [True: 0, False: 452]
  ------------------
 1782|      1|          ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1783|      1|          return -1;
 1784|      1|    }
 1785|       |
 1786|    452|    SSH_LOG(SSH_LOG_DEBUG, "Analyzing banner: %s", banner);
  ------------------
  |  |  283|    452|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1787|       |
 1788|    452|    switch (banner[4]) {
 1789|    428|        case '2':
  ------------------
  |  Branch (1789:9): [True: 428, False: 24]
  ------------------
 1790|    428|            break;
 1791|     23|        case '1':
  ------------------
  |  Branch (1791:9): [True: 23, False: 429]
  ------------------
 1792|     23|            if (strlen(banner) > 6) {
  ------------------
  |  Branch (1792:17): [True: 23, False: 0]
  ------------------
 1793|     23|                if (banner[6] == '9') {
  ------------------
  |  Branch (1793:21): [True: 14, False: 9]
  ------------------
 1794|     14|                    break;
 1795|     14|                }
 1796|     23|            }
 1797|      9|            FALL_THROUGH;
  ------------------
  |  |  496|      9|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1798|     10|        default:
  ------------------
  |  Branch (1798:9): [True: 1, False: 451]
  ------------------
 1799|     10|            ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
  ------------------
  |  |  313|     10|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1800|     10|            return -1;
 1801|    452|    }
 1802|       |
 1803|       |    /* Make a best-effort to extract OpenSSH version numbers. */
 1804|    442|    openssh = strstr(banner, "OpenSSH");
 1805|    442|    if (openssh != NULL) {
  ------------------
  |  Branch (1805:9): [True: 88, False: 354]
  ------------------
 1806|     88|        char *tmp = NULL;
 1807|     88|        unsigned long int major = 0UL;
 1808|     88|        unsigned long int minor = 0UL;
 1809|     88|        int off = 0;
 1810|       |
 1811|       |        /*
 1812|       |         * The banner is typical:
 1813|       |         * OpenSSH_5.4
 1814|       |         * 012345678901234567890
 1815|       |         */
 1816|     88|        if (strlen(openssh) > 9) {
  ------------------
  |  Branch (1816:13): [True: 81, False: 7]
  ------------------
 1817|     81|            errno = 0;
 1818|     81|            major = strtoul(openssh + 8, &tmp, 10);
 1819|     81|            if ((tmp == (openssh + 8)) ||
  ------------------
  |  Branch (1819:17): [True: 1, False: 80]
  ------------------
 1820|     80|                ((errno == ERANGE) && (major == ULONG_MAX)) ||
  ------------------
  |  Branch (1820:18): [True: 1, False: 79]
  |  Branch (1820:39): [True: 1, False: 0]
  ------------------
 1821|     79|                ((errno != 0) && (major == 0)) ||
  ------------------
  |  Branch (1821:18): [True: 0, False: 79]
  |  Branch (1821:34): [True: 0, False: 0]
  ------------------
 1822|     79|                ((major < 1) || (major > 100))) {
  ------------------
  |  Branch (1822:18): [True: 1, False: 78]
  |  Branch (1822:33): [True: 57, False: 21]
  ------------------
 1823|       |                /* invalid major */
 1824|     60|                errno = 0;
 1825|     60|                goto done;
 1826|     60|            }
 1827|       |
 1828|     81|            errno = 0;
 1829|     21|            off = major >= 10 ? 11 : 10;
  ------------------
  |  Branch (1829:19): [True: 12, False: 9]
  ------------------
 1830|     21|            minor = strtoul(openssh + off, &tmp, 10);
 1831|     21|            if ((tmp == (openssh + off)) ||
  ------------------
  |  Branch (1831:17): [True: 2, False: 19]
  ------------------
 1832|     19|                ((errno == ERANGE) && (major == ULONG_MAX)) ||
  ------------------
  |  Branch (1832:18): [True: 0, False: 19]
  |  Branch (1832:39): [True: 0, False: 0]
  ------------------
 1833|     19|                ((errno != 0) && (major == 0)) ||
  ------------------
  |  Branch (1833:18): [True: 0, False: 19]
  |  Branch (1833:34): [True: 0, False: 0]
  ------------------
 1834|     19|                (minor > 100)) {
  ------------------
  |  Branch (1834:17): [True: 16, False: 3]
  ------------------
 1835|       |                /* invalid minor */
 1836|     18|                errno = 0;
 1837|     18|                goto done;
 1838|     18|            }
 1839|       |
 1840|      3|            session->openssh = SSH_VERSION_INT(((int) major), ((int) minor), 0);
  ------------------
  |  |   25|      3|#define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
  ------------------
 1841|       |
 1842|      3|            SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      6|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 0, False: 3]
  |  |  ------------------
  ------------------
 1843|      3|                    "We are talking to an OpenSSH %s version: %lu.%lu (%x)",
 1844|      3|                    server ? "client" : "server",
 1845|      3|                    major, minor, session->openssh);
 1846|      3|        }
 1847|     88|    }
 1848|       |    /* Cisco devices have odd scp implementation which breaks */
 1849|    364|    ios = strstr(banner, "Cisco");
 1850|    364|    if (ios != NULL) {
  ------------------
  |  Branch (1850:9): [True: 2, False: 362]
  ------------------
 1851|      2|        session->flags |= SSH_SESSION_FLAG_SCP_QUOTING_BROKEN;
  ------------------
  |  |   95|      2|#define SSH_SESSION_FLAG_SCP_QUOTING_BROKEN 0x0040
  ------------------
 1852|      2|    }
 1853|       |
 1854|    442|done:
 1855|    442|    return 0;
 1856|    364|}
ssh_timestamp_init:
 1871|  6.79k|{
 1872|  6.79k|#ifdef HAVE_CLOCK_GETTIME
 1873|  6.79k|  struct timespec tp;
 1874|  6.79k|  clock_gettime(CLOCK, &tp);
  ------------------
  |  | 1860|  6.79k|#define CLOCK CLOCK_MONOTONIC
  ------------------
 1875|  6.79k|  ts->useconds = tp.tv_nsec / 1000;
 1876|       |#else
 1877|       |  struct timeval tp;
 1878|       |  gettimeofday(&tp, NULL);
 1879|       |  ts->useconds = tp.tv_usec;
 1880|       |#endif
 1881|  6.79k|  ts->seconds = tp.tv_sec;
 1882|  6.79k|}
ssh_make_milliseconds:
 1919|    486|{
 1920|    486|    unsigned long res;
 1921|       |
 1922|    486|    if (sec == (unsigned long)SSH_TIMEOUT_INFINITE) {
  ------------------
  |  |   99|    486|#define SSH_TIMEOUT_INFINITE -1
  ------------------
  |  Branch (1922:9): [True: 0, False: 486]
  ------------------
 1923|      0|        return SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|      0|#define SSH_TIMEOUT_INFINITE -1
  ------------------
 1924|      0|    }
 1925|    486|    if (sec > (unsigned long)INT_MAX / 1000) {
  ------------------
  |  Branch (1925:9): [True: 0, False: 486]
  ------------------
 1926|      0|        return INT_MAX;
 1927|      0|    }
 1928|       |
 1929|    486|    res = usec / 1000;
 1930|    486|    res += (sec * 1000);
 1931|    486|    if (res == 0) {
  ------------------
  |  Branch (1931:9): [True: 0, False: 486]
  ------------------
 1932|      0|        res = 10 * 1000; /* use a reasonable default value in case
 1933|       |                          * SSH_OPTIONS_TIMEOUT is not set in options. */
 1934|      0|    }
 1935|       |
 1936|    486|    if (res > INT_MAX) {
  ------------------
  |  Branch (1936:9): [True: 0, False: 486]
  ------------------
 1937|      0|        return INT_MAX;
 1938|    486|    } else {
 1939|    486|        return (int)res;
 1940|    486|    }
 1941|    486|}
ssh_timeout_elapsed:
 1954|  1.50k|{
 1955|  1.50k|    struct ssh_timestamp now;
 1956|       |
 1957|  1.50k|    switch(timeout) {
 1958|      0|        case -2: /*
  ------------------
  |  Branch (1958:9): [True: 0, False: 1.50k]
  ------------------
 1959|       |                  * -2 means user-defined timeout as available in
 1960|       |                  * session->timeout, session->timeout_usec.
 1961|       |                  */
 1962|      0|            SSH_LOG(SSH_LOG_DEBUG, "ssh_timeout_elapsed called with -2. this needs to "
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1963|      0|                            "be fixed. please set a breakpoint on misc.c:%d and "
 1964|      0|                            "fix the caller\n", __LINE__);
 1965|      0|            return 0;
 1966|      0|        case -1: /* -1 means infinite timeout */
  ------------------
  |  Branch (1966:9): [True: 0, False: 1.50k]
  ------------------
 1967|      0|            return 0;
 1968|      0|        case 0: /* 0 means no timeout */
  ------------------
  |  Branch (1968:9): [True: 0, False: 1.50k]
  ------------------
 1969|      0|            return 1;
 1970|  1.50k|        default:
  ------------------
  |  Branch (1970:9): [True: 1.50k, False: 0]
  ------------------
 1971|  1.50k|            break;
 1972|  1.50k|    }
 1973|       |
 1974|  1.50k|    ssh_timestamp_init(&now);
 1975|       |
 1976|  1.50k|    return (ssh_timestamp_difference(ts,&now) >= timeout);
 1977|  1.50k|}
ssh_timeout_update:
 1987|  3.15k|{
 1988|  3.15k|  struct ssh_timestamp now;
 1989|  3.15k|  int ms, ret;
 1990|  3.15k|  if (timeout <= 0) {
  ------------------
  |  Branch (1990:7): [True: 0, False: 3.15k]
  ------------------
 1991|      0|      return timeout;
 1992|      0|  }
 1993|  3.15k|  ssh_timestamp_init(&now);
 1994|  3.15k|  ms = ssh_timestamp_difference(ts,&now);
 1995|  3.15k|  if(ms < 0)
  ------------------
  |  Branch (1995:6): [True: 0, False: 3.15k]
  ------------------
 1996|      0|    ms = 0;
 1997|  3.15k|  ret = timeout - ms;
 1998|  3.15k|  return ret >= 0 ? ret: 0;
  ------------------
  |  Branch (1998:10): [True: 3.15k, False: 0]
  ------------------
 1999|  3.15k|}
ssh_strerror:
 2417|  1.76k|{
 2418|       |#if ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE)
 2419|       |    /* GNU extension on Linux */
 2420|       |    return strerror_r(err_num, buf, buflen);
 2421|       |#else
 2422|  1.76k|    int rv;
 2423|       |
 2424|       |#if defined(_WIN32)
 2425|       |    rv = strerror_s(buf, buflen, err_num);
 2426|       |#else
 2427|       |    /* POSIX version available for example on FreeBSD or in musl libc */
 2428|  1.76k|    rv = strerror_r(err_num, buf, buflen);
 2429|  1.76k|#endif /* _WIN32 */
 2430|       |
 2431|       |    /* make sure the buffer is initialized and terminated with NULL */
 2432|  1.76k|    if (-rv == ERANGE) {
  ------------------
  |  Branch (2432:9): [True: 0, False: 1.76k]
  ------------------
 2433|      0|        buf[0] = '\0';
 2434|      0|    }
 2435|  1.76k|    return buf;
 2436|  1.76k|#endif /* ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE) */
 2437|  1.76k|}
ssh_check_username_syntax:
 2627|    486|{
 2628|    486|    size_t username_len;
 2629|       |
 2630|    486|    if (username == NULL || *username == '-') {
  ------------------
  |  Branch (2630:9): [True: 0, False: 486]
  |  Branch (2630:29): [True: 0, False: 486]
  ------------------
 2631|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2632|      0|    }
 2633|       |
 2634|    486|    username_len = strlen(username);
 2635|    486|    if (username_len == 0 || username[username_len - 1] == '\\' ||
  ------------------
  |  Branch (2635:9): [True: 0, False: 486]
  |  Branch (2635:30): [True: 0, False: 486]
  ------------------
 2636|    486|        strpbrk(username, SSH_DANGEROUS_SHELL_CHARS) != NULL) {
  ------------------
  |  |  260|    486|#define SSH_DANGEROUS_SHELL_CHARS "'`\";&<>|(){}$\\,"
  ------------------
  |  Branch (2636:9): [True: 0, False: 486]
  ------------------
 2637|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2638|      0|    }
 2639|  2.91k|    for (size_t i = 0; i < username_len; i++) {
  ------------------
  |  Branch (2639:24): [True: 2.43k, False: 486]
  ------------------
 2640|  2.43k|        unsigned char c = (unsigned char)username[i];
 2641|  2.43k|        if (iscntrl(c) != 0 || (isspace(c) != 0 && username[i + 1] == '-')) {
  ------------------
  |  Branch (2641:13): [True: 0, False: 2.43k]
  |  Branch (2641:33): [True: 0, False: 2.43k]
  |  Branch (2641:52): [True: 0, False: 0]
  ------------------
 2642|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2643|      0|        }
 2644|  2.43k|    }
 2645|       |
 2646|    486|    return SSH_OK;
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
 2647|    486|}
ssh_proxyjumps_free:
 2659|    706|{
 2660|    706|    struct ssh_jump_info_struct *jump = NULL;
 2661|       |
 2662|    706|    for (jump =
 2663|    706|             ssh_list_pop_head(struct ssh_jump_info_struct *, proxy_jump_list);
  ------------------
  |  |  128|    706|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2664|    706|         jump != NULL;
  ------------------
  |  Branch (2664:10): [True: 0, False: 706]
  ------------------
 2665|    706|         jump = ssh_list_pop_head(struct ssh_jump_info_struct *,
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2666|    706|                                  proxy_jump_list)) {
 2667|      0|        SAFE_FREE(jump->hostname);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2668|      0|        SAFE_FREE(jump->username);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2669|       |        SAFE_FREE(jump);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2670|      0|    }
 2671|    706|}
ssh_strict_fopen:
 2705|    884|{
 2706|    884|    FILE *f = NULL;
 2707|    884|    struct stat sb;
 2708|    884|    int r, fd;
 2709|       |
 2710|       |    /* open first to avoid TOCTOU */
 2711|    884|    fd = open(filename, O_RDONLY);
 2712|    884|    if (fd == -1) {
  ------------------
  |  Branch (2712:9): [True: 884, False: 0]
  ------------------
 2713|    884|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  285|    884|    do {                                                            \
  |  |  286|    884|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  287|    884|        _ssh_log(priority,                                          \
  |  |  288|    884|                 __func__,                                          \
  |  |  289|    884|                 __VA_ARGS__,                                       \
  |  |  290|    884|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  522|    884|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  291|    884|    } while (0)
  |  |  ------------------
  |  |  |  Branch (291:14): [Folded, False: 884]
  |  |  ------------------
  ------------------
 2714|    884|                         errno,
 2715|    884|                         "Failed to open a file %s for reading: %s",
 2716|    884|                         filename);
 2717|    884|        return NULL;
 2718|    884|    }
 2719|       |
 2720|       |    /* Check the file is sensible for a configuration file */
 2721|      0|    r = fstat(fd, &sb);
 2722|      0|    if (r != 0) {
  ------------------
  |  Branch (2722:9): [True: 0, False: 0]
  ------------------
 2723|      0|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  285|      0|    do {                                                            \
  |  |  286|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  287|      0|        _ssh_log(priority,                                          \
  |  |  288|      0|                 __func__,                                          \
  |  |  289|      0|                 __VA_ARGS__,                                       \
  |  |  290|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  522|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  291|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (291:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2724|      0|                         errno,
 2725|      0|                         "Failed to stat %s: %s",
 2726|      0|                         filename);
 2727|      0|        close(fd);
 2728|      0|        return NULL;
 2729|      0|    }
 2730|      0|    if ((sb.st_mode & S_IFMT) != S_IFREG) {
  ------------------
  |  Branch (2730:9): [True: 0, False: 0]
  ------------------
 2731|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2732|      0|                "The file %s is not a regular file: skipping",
 2733|      0|                filename);
 2734|      0|        close(fd);
 2735|      0|        return NULL;
 2736|      0|    }
 2737|       |
 2738|      0|    if ((size_t)sb.st_size > max_file_size) {
  ------------------
  |  Branch (2738:9): [True: 0, False: 0]
  ------------------
 2739|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2740|      0|                "The file %s is too large (%jd MB > %zu MB): skipping",
 2741|      0|                filename,
 2742|      0|                (intmax_t)sb.st_size / 1024 / 1024,
 2743|      0|                max_file_size / 1024 / 1024);
 2744|      0|        close(fd);
 2745|      0|        return NULL;
 2746|      0|    }
 2747|       |
 2748|      0|    f = fdopen(fd, "r");
 2749|      0|    if (f == NULL) {
  ------------------
  |  Branch (2749:9): [True: 0, False: 0]
  ------------------
 2750|      0|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  285|      0|    do {                                                            \
  |  |  286|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  287|      0|        _ssh_log(priority,                                          \
  |  |  288|      0|                 __func__,                                          \
  |  |  289|      0|                 __VA_ARGS__,                                       \
  |  |  290|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  522|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  291|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (291:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2751|      0|                         errno,
 2752|      0|                         "Failed to open a file %s for reading: %s",
 2753|      0|                         filename);
 2754|      0|        close(fd);
 2755|      0|        return NULL;
 2756|      0|    }
 2757|       |
 2758|       |    /* the flcose() will close also the underlying fd */
 2759|      0|    return f;
 2760|      0|}
strlcpy:
 2771|  1.94k|{
 2772|  1.94k|    size_t len = strlen(src);
 2773|       |
 2774|  1.94k|    if (size != 0) {
  ------------------
  |  Branch (2774:9): [True: 1.94k, False: 0]
  ------------------
 2775|  1.94k|        size_t copy_len = (len >= size) ? size - 1 : len;
  ------------------
  |  Branch (2775:27): [True: 0, False: 1.94k]
  ------------------
 2776|       |
 2777|  1.94k|        memcpy(dst, src, copy_len);
 2778|  1.94k|        dst[copy_len] = '\0';
 2779|  1.94k|    }
 2780|       |
 2781|  1.94k|    return len;
 2782|  1.94k|}
ssh_normalize_loose_ip:
 2819|    972|{
 2820|    972|    struct in_addr addr;
 2821|    972|    char buf[INET_ADDRSTRLEN];
 2822|    972|    const char *p = NULL;
 2823|    972|    int rc;
 2824|    972|    int is_ip;
 2825|       |#ifdef _WIN32
 2826|       |    unsigned long ip;
 2827|       |    int is_broadcast;
 2828|       |#endif
 2829|       |
 2830|    972|    if (host == NULL || result == NULL) {
  ------------------
  |  Branch (2830:9): [True: 0, False: 972]
  |  Branch (2830:25): [True: 0, False: 972]
  ------------------
 2831|      0|        return -1;
 2832|      0|    }
 2833|       |
 2834|       |    /* We don't want to normalize stricter IP checks already handled by valid
 2835|       |     * IPv4/IPv6 */
 2836|    972|    is_ip = ssh_is_ipaddr(host);
 2837|    972|    if (is_ip) {
  ------------------
  |  Branch (2837:9): [True: 972, False: 0]
  ------------------
 2838|    972|        return 1; /* not a loose IP — already a strict address */
 2839|    972|    }
 2840|       |
 2841|       |#ifdef _WIN32
 2842|       |    ip = inet_addr(host);
 2843|       |    is_broadcast = strcmp(host, "255.255.255.255");
 2844|       |    if (ip == INADDR_NONE && is_broadcast != 0) {
 2845|       |        return 1; /* not a loose IP */
 2846|       |    }
 2847|       |    addr.S_un.S_addr = ip;
 2848|       |#else
 2849|      0|    rc = inet_aton(host, &addr);
 2850|      0|    if (rc == 0) {
  ------------------
  |  Branch (2850:9): [True: 0, False: 0]
  ------------------
 2851|      0|        return 1; /* not a loose IP */
 2852|      0|    }
 2853|      0|#endif
 2854|       |
 2855|      0|    p = inet_ntop(AF_INET, &addr, buf, sizeof(buf));
 2856|      0|    if (p == NULL) {
  ------------------
  |  Branch (2856:9): [True: 0, False: 0]
  ------------------
 2857|      0|        return -1;
 2858|      0|    }
 2859|       |
 2860|      0|    *result = strdup(p);
 2861|      0|    if (*result == NULL) {
  ------------------
  |  Branch (2861:9): [True: 0, False: 0]
  ------------------
 2862|      0|        return -1;
 2863|      0|    }
 2864|       |
 2865|      0|    return 0;
 2866|      0|}
misc.c:ssh_get_user_home_dir_internal:
  329|    972|{
  330|    972|    char *szPath = NULL;
  331|    972|    struct passwd pwd;
  332|    972|    struct passwd *pwdbuf = NULL;
  333|    972|    char buf[NSS_BUFLEN_PASSWD] = {0};
  334|    972|    int rc;
  335|       |
  336|    972|    rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
  337|    972|    if (rc != 0 || pwdbuf == NULL ) {
  ------------------
  |  Branch (337:9): [True: 0, False: 972]
  |  Branch (337:20): [True: 0, False: 972]
  ------------------
  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|    972|    szPath = strdup(pwd.pw_dir);
  347|       |
  348|    972|    return szPath;
  349|    972|}
misc.c:ssh_iterator_new:
  947|  3.56k|{
  948|  3.56k|    struct ssh_iterator *iterator = malloc(sizeof(struct ssh_iterator));
  949|       |
  950|  3.56k|    if (iterator == NULL) {
  ------------------
  |  Branch (950:9): [True: 0, False: 3.56k]
  ------------------
  951|      0|        return NULL;
  952|      0|    }
  953|  3.56k|    iterator->next = NULL;
  954|  3.56k|    iterator->data = data;
  955|  3.56k|    return iterator;
  956|  3.56k|}
misc.c:ssh_path_expand_internal:
 1492|  2.43k|{
 1493|  2.43k|    char *buf = NULL;
 1494|  2.43k|    char *r = NULL;
 1495|  2.43k|    char *x = NULL;
 1496|  2.43k|    const char *p = NULL;
 1497|  2.43k|    size_t i, l;
 1498|       |
 1499|  2.43k|    if (expand_tilde) {
  ------------------
  |  Branch (1499:9): [True: 1.94k, False: 486]
  ------------------
 1500|  1.94k|        r = ssh_path_expand_tilde(s);
 1501|  1.94k|    } else {
 1502|    486|        r = strdup(s);
 1503|    486|    }
 1504|  2.43k|    if (r == NULL) {
  ------------------
  |  Branch (1504:9): [True: 0, False: 2.43k]
  ------------------
 1505|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1506|      0|        return NULL;
 1507|      0|    }
 1508|       |
 1509|  2.43k|    if (strlen(r) > MAX_BUF_SIZE) {
  ------------------
  |  |  230|  2.43k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1509:9): [True: 0, False: 2.43k]
  ------------------
 1510|      0|        ssh_set_error(session, SSH_FATAL, "string to expand too long");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1511|      0|        free(r);
 1512|      0|        return NULL;
 1513|      0|    }
 1514|       |
 1515|  2.43k|    buf = malloc(MAX_BUF_SIZE);
  ------------------
  |  |  230|  2.43k|#define MAX_BUF_SIZE 4096
  ------------------
 1516|  2.43k|    if (buf == NULL) {
  ------------------
  |  Branch (1516:9): [True: 0, False: 2.43k]
  ------------------
 1517|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1518|      0|        free(r);
 1519|      0|        return NULL;
 1520|      0|    }
 1521|       |
 1522|  2.43k|    p = r;
 1523|  2.43k|    buf[0] = '\0';
 1524|       |
 1525|  35.4k|    for (i = 0; *p != '\0'; p++) {
  ------------------
  |  Branch (1525:17): [True: 33.0k, False: 2.43k]
  ------------------
 1526|  33.0k|        if (*p != '%') {
  ------------------
  |  Branch (1526:13): [True: 31.1k, False: 1.94k]
  ------------------
 1527|  31.1k|            buf[i] = *p;
 1528|  31.1k|            i++;
 1529|  31.1k|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|  31.1k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1529:17): [True: 0, False: 31.1k]
  ------------------
 1530|      0|                free(buf);
 1531|      0|                free(r);
 1532|      0|                return NULL;
 1533|      0|            }
 1534|  31.1k|            buf[i] = '\0';
 1535|  31.1k|            continue;
 1536|  31.1k|        }
 1537|       |
 1538|  1.94k|        p++;
 1539|  1.94k|        if (*p == '\0') {
  ------------------
  |  Branch (1539:13): [True: 0, False: 1.94k]
  ------------------
 1540|       |            /* HostName expansion rejects trailing '%' to match the parse-time
 1541|       |             * scan. Keep the general expansion path unchanged, where a
 1542|       |             * trailing '%' is truncated.
 1543|       |             */
 1544|      0|            if (hostname_lenient) {
  ------------------
  |  Branch (1544:17): [True: 0, False: 0]
  ------------------
 1545|      0|                ssh_set_error(session, SSH_FATAL, "Incomplete Hostname token");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1546|      0|                free(buf);
 1547|      0|                free(r);
 1548|      0|                return NULL;
 1549|      0|            }
 1550|      0|            break;
 1551|      0|        }
 1552|       |
 1553|  1.94k|        if (hostname_lenient && *p != '%' && *p != 'h') {
  ------------------
  |  Branch (1553:13): [True: 0, False: 1.94k]
  |  Branch (1553:33): [True: 0, False: 0]
  |  Branch (1553:46): [True: 0, False: 0]
  ------------------
 1554|      0|            buf[i] = '%';
 1555|      0|            i++;
 1556|      0|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|      0|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1556:17): [True: 0, False: 0]
  ------------------
 1557|      0|                ssh_set_error(session, SSH_FATAL, "String too long");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1558|      0|                free(buf);
 1559|      0|                free(r);
 1560|      0|                return NULL;
 1561|      0|            }
 1562|      0|            buf[i] = *p;
 1563|      0|            i++;
 1564|      0|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|      0|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1564:17): [True: 0, False: 0]
  ------------------
 1565|      0|                ssh_set_error(session, SSH_FATAL, "String too long");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1566|      0|                free(buf);
 1567|      0|                free(r);
 1568|      0|                return NULL;
 1569|      0|            }
 1570|      0|            buf[i] = '\0';
 1571|      0|            continue;
 1572|      0|        }
 1573|       |
 1574|  1.94k|        switch (*p) {
 1575|      0|        case '%':
  ------------------
  |  Branch (1575:9): [True: 0, False: 1.94k]
  ------------------
 1576|      0|            buf[i] = '%';
 1577|      0|            i++;
 1578|      0|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|      0|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1578:17): [True: 0, False: 0]
  ------------------
 1579|      0|                free(buf);
 1580|      0|                free(r);
 1581|      0|                return NULL;
 1582|      0|            }
 1583|      0|            buf[i] = '\0';
 1584|      0|            continue;
 1585|  1.94k|        case 'd':
  ------------------
  |  Branch (1585:9): [True: 1.94k, False: 0]
  ------------------
 1586|  1.94k|            x = ssh_get_user_home_dir(session);
 1587|  1.94k|            if (x == NULL) {
  ------------------
  |  Branch (1587:17): [True: 0, False: 1.94k]
  ------------------
 1588|      0|                ssh_set_error(session, SSH_FATAL, "Cannot expand homedir");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1589|      0|                free(buf);
 1590|      0|                free(r);
 1591|      0|                return NULL;
 1592|      0|            }
 1593|  1.94k|            break;
 1594|  1.94k|        case 'u':
  ------------------
  |  Branch (1594:9): [True: 0, False: 1.94k]
  ------------------
 1595|      0|            x = ssh_get_local_username();
 1596|      0|            break;
 1597|      0|        case 'l':
  ------------------
  |  Branch (1597:9): [True: 0, False: 1.94k]
  ------------------
 1598|      0|            x = ssh_get_local_hostname();
 1599|      0|            break;
 1600|      0|        case 'h':
  ------------------
  |  Branch (1600:9): [True: 0, False: 1.94k]
  ------------------
 1601|      0|            if (session->opts.host) {
  ------------------
  |  Branch (1601:17): [True: 0, False: 0]
  ------------------
 1602|      0|                x = strdup(session->opts.host);
 1603|      0|            } else if (session->opts.originalhost) {
  ------------------
  |  Branch (1603:24): [True: 0, False: 0]
  ------------------
 1604|      0|                x = strdup(session->opts.originalhost);
 1605|      0|            } else {
 1606|      0|                ssh_set_error(session, SSH_FATAL, "Cannot expand host");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1607|      0|                free(buf);
 1608|      0|                free(r);
 1609|      0|                return NULL;
 1610|      0|            }
 1611|      0|            break;
 1612|      0|        case 'n':
  ------------------
  |  Branch (1612:9): [True: 0, False: 1.94k]
  ------------------
 1613|      0|            if (session->opts.originalhost) {
  ------------------
  |  Branch (1613:17): [True: 0, False: 0]
  ------------------
 1614|      0|                x = strdup(session->opts.originalhost);
 1615|      0|            } else {
 1616|      0|                ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1617|      0|                              SSH_FATAL,
 1618|      0|                              "Cannot expand original host");
 1619|      0|                free(buf);
 1620|      0|                free(r);
 1621|      0|                return NULL;
 1622|      0|            }
 1623|      0|            break;
 1624|      0|        case 'r':
  ------------------
  |  Branch (1624:9): [True: 0, False: 1.94k]
  ------------------
 1625|      0|            if (session->opts.username) {
  ------------------
  |  Branch (1625:17): [True: 0, False: 0]
  ------------------
 1626|      0|                x = strdup(session->opts.username);
 1627|      0|            } else {
 1628|      0|                ssh_set_error(session, SSH_FATAL, "Cannot expand username");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1629|      0|                free(buf);
 1630|      0|                free(r);
 1631|      0|                return NULL;
 1632|      0|            }
 1633|      0|            break;
 1634|      0|        case 'p': {
  ------------------
  |  Branch (1634:9): [True: 0, False: 1.94k]
  ------------------
 1635|      0|            char tmp[6];
 1636|      0|            unsigned int port;
 1637|       |
 1638|      0|            ssh_options_get_port(session, &port);
 1639|      0|            snprintf(tmp, sizeof(tmp), "%u", port);
 1640|      0|            x = strdup(tmp);
 1641|      0|            break;
 1642|      0|        }
 1643|      0|        case 'j':
  ------------------
  |  Branch (1643:9): [True: 0, False: 1.94k]
  ------------------
 1644|      0|            if (session->opts.proxy_jumps_str != NULL) {
  ------------------
  |  Branch (1644:17): [True: 0, False: 0]
  ------------------
 1645|      0|                x = strdup(session->opts.proxy_jumps_str);
 1646|      0|            } else {
 1647|      0|                x = strdup("");
 1648|      0|            }
 1649|      0|            break;
 1650|      0|        case 'C':
  ------------------
  |  Branch (1650:9): [True: 0, False: 1.94k]
  ------------------
 1651|      0|            x = get_connection_hash(session);
 1652|      0|            break;
 1653|      0|        default:
  ------------------
  |  Branch (1653:9): [True: 0, False: 1.94k]
  ------------------
 1654|      0|            ssh_set_error(session, SSH_FATAL, "Wrong escape sequence detected");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1655|      0|            free(buf);
 1656|      0|            free(r);
 1657|      0|            return NULL;
 1658|  1.94k|        }
 1659|       |
 1660|  1.94k|        if (x == NULL) {
  ------------------
  |  Branch (1660:13): [True: 0, False: 1.94k]
  ------------------
 1661|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1662|      0|            free(buf);
 1663|      0|            free(r);
 1664|      0|            return NULL;
 1665|      0|        }
 1666|       |
 1667|  1.94k|        i += strlen(x);
 1668|  1.94k|        if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|  1.94k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1668:13): [True: 0, False: 1.94k]
  ------------------
 1669|      0|            ssh_set_error(session, SSH_FATAL, "String too long");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1670|      0|            free(buf);
 1671|      0|            free(x);
 1672|      0|            free(r);
 1673|      0|            return NULL;
 1674|      0|        }
 1675|  1.94k|        l = strlen(buf);
 1676|  1.94k|        strlcpy(buf + l, x, MAX_BUF_SIZE - l);
  ------------------
  |  |  230|  1.94k|#define MAX_BUF_SIZE 4096
  ------------------
 1677|  1.94k|        buf[i] = '\0';
 1678|  1.94k|        SAFE_FREE(x);
  ------------------
  |  |  375|  1.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.94k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.94k]
  |  |  ------------------
  ------------------
 1679|  1.94k|    }
 1680|       |
 1681|  2.43k|    free(r);
 1682|       |
 1683|       |    /* strip the unused space by realloc */
 1684|  2.43k|    x = realloc(buf, strlen(buf) + 1);
 1685|  2.43k|    if (x == NULL) {
  ------------------
  |  Branch (1685:9): [True: 0, False: 2.43k]
  ------------------
 1686|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1687|      0|        free(buf);
 1688|      0|    }
 1689|  2.43k|    return x;
 1690|  2.43k|}
misc.c:ssh_timestamp_difference:
 1896|  4.66k|{
 1897|  4.66k|    long seconds, usecs, msecs;
 1898|  4.66k|    seconds = new->seconds - old->seconds;
 1899|  4.66k|    usecs = new->useconds - old->useconds;
 1900|  4.66k|    if (usecs < 0){
  ------------------
  |  Branch (1900:9): [True: 58, False: 4.60k]
  ------------------
 1901|     58|        seconds--;
 1902|     58|        usecs += 1000000;
 1903|     58|    }
 1904|  4.66k|    msecs = seconds * 1000 + usecs/1000;
 1905|  4.66k|    return msecs;
 1906|  4.66k|}

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

ssh_mlkem_init:
   41|    104|{
   42|    104|    int ret = SSH_ERROR;
  ------------------
  |  |  317|    104|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   43|    104|    struct ssh_crypto_struct *crypto = session->next_crypto;
   44|    104|    const struct mlkem_type_info *mlkem_info = NULL;
   45|    104|    unsigned char rnd[LIBCRUX_ML_KEM_KEY_PAIR_PRNG_LEN];
   46|    104|    struct libcrux_mlkem768_keypair keypair;
   47|    104|    int err;
   48|       |
   49|    104|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
   50|    104|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (50:9): [True: 0, False: 104]
  ------------------
   51|      0|        SSH_LOG(SSH_LOG_WARNING, "Unknown ML-KEM type");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   52|      0|        goto cleanup;
   53|      0|    }
   54|       |
   55|    104|    err = ssh_get_random(rnd, sizeof(rnd), 0);
   56|    104|    if (err != 1) {
  ------------------
  |  Branch (56:9): [True: 0, False: 104]
  ------------------
   57|      0|        SSH_LOG(SSH_LOG_WARNING,
  ------------------
  |  |  283|      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|    104|    keypair = libcrux_ml_kem_mlkem768_portable_generate_key_pair(rnd);
   63|       |
   64|    104|    if (ssh_string_len(crypto->mlkem_client_pubkey) < mlkem_info->pubkey_size) {
  ------------------
  |  Branch (64:9): [True: 104, False: 0]
  ------------------
   65|    104|        SSH_STRING_FREE(crypto->mlkem_client_pubkey);
  ------------------
  |  |  924|    104|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 104]
  |  |  |  Branch (924:69): [Folded, False: 104]
  |  |  ------------------
  ------------------
   66|    104|    }
   67|    104|    if (crypto->mlkem_client_pubkey == NULL) {
  ------------------
  |  Branch (67:9): [True: 104, False: 0]
  ------------------
   68|    104|        crypto->mlkem_client_pubkey = ssh_string_new(mlkem_info->pubkey_size);
   69|    104|        if (crypto->mlkem_client_pubkey == NULL) {
  ------------------
  |  Branch (69:13): [True: 0, False: 104]
  ------------------
   70|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
   71|      0|            goto cleanup;
   72|      0|        }
   73|    104|    }
   74|    104|    err = ssh_string_fill(crypto->mlkem_client_pubkey,
   75|    104|                          keypair.pk.value,
   76|    104|                          mlkem_info->pubkey_size);
   77|    104|    if (err) {
  ------------------
  |  Branch (77:9): [True: 0, False: 104]
  ------------------
   78|      0|        SSH_LOG(SSH_LOG_WARNING,
  ------------------
  |  |  283|      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|    104|    if (crypto->mlkem_privkey == NULL) {
  ------------------
  |  Branch (83:9): [True: 104, False: 0]
  ------------------
   84|    104|        crypto->mlkem_privkey = malloc(mlkem_info->privkey_size);
   85|    104|        if (crypto->mlkem_privkey == NULL) {
  ------------------
  |  Branch (85:13): [True: 0, False: 104]
  ------------------
   86|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
   87|      0|            goto cleanup;
   88|      0|        }
   89|    104|    }
   90|    104|    memcpy(crypto->mlkem_privkey, keypair.sk.value, mlkem_info->privkey_size);
   91|    104|    crypto->mlkem_privkey_len = mlkem_info->privkey_size;
   92|       |
   93|    104|    ret = SSH_OK;
  ------------------
  |  |  316|    104|#define SSH_OK 0     /* No error */
  ------------------
   94|       |
   95|    104|cleanup:
   96|    104|    ssh_burn(&keypair, sizeof(keypair));
  ------------------
  |  |  390|    104|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
   97|    104|    ssh_burn(rnd, sizeof(rnd));
  ------------------
  |  |  390|    104|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
   98|    104|    return ret;
   99|    104|}

ssh_options_set_algo:
  468|  1.94k|{
  469|       |    /* When the list start with +,-,^ the filtration of unknown algorithms
  470|       |     * gets handled inside the helper functions, otherwise the list is taken
  471|       |     * as it is. */
  472|  1.94k|    char *p = (char *)list;
  473|       |
  474|  1.94k|    if (algo < SSH_COMP_C_S) {
  ------------------
  |  Branch (474:9): [True: 1.94k, False: 0]
  ------------------
  475|  1.94k|        if (list[0] == '+') {
  ------------------
  |  Branch (475:13): [True: 0, False: 1.94k]
  ------------------
  476|      0|            p = ssh_add_to_default_algos(algo, list+1);
  477|  1.94k|        } else if (list[0] == '-') {
  ------------------
  |  Branch (477:20): [True: 0, False: 1.94k]
  ------------------
  478|      0|            p = ssh_remove_from_default_algos(algo, list+1);
  479|  1.94k|        } else if (list[0] == '^') {
  ------------------
  |  Branch (479:20): [True: 0, False: 1.94k]
  ------------------
  480|      0|            p = ssh_prefix_default_algos(algo, list+1);
  481|      0|        }
  482|  1.94k|    }
  483|       |
  484|  1.94k|    if (p == list) {
  ------------------
  |  Branch (484:9): [True: 1.94k, False: 0]
  ------------------
  485|  1.94k|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|  1.94k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 1.94k]
  |  |  ------------------
  ------------------
  486|      0|            p = ssh_keep_fips_algos(algo, list);
  487|  1.94k|        } else {
  488|  1.94k|            p = ssh_keep_known_algos(algo, list);
  489|  1.94k|        }
  490|  1.94k|    }
  491|       |
  492|  1.94k|    if (p == NULL) {
  ------------------
  |  Branch (492:9): [True: 0, False: 1.94k]
  ------------------
  493|      0|        ssh_set_error(session, SSH_REQUEST_DENIED,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  494|      0|                "Setting method: no allowed algorithm for method \"%s\" (%s)",
  495|      0|                ssh_kex_get_description(algo), list);
  496|      0|        return -1;
  497|      0|    }
  498|       |
  499|  1.94k|    SAFE_FREE(*place);
  ------------------
  |  |  375|  1.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 1.94k]
  |  |  |  Branch (375:71): [Folded, False: 1.94k]
  |  |  ------------------
  ------------------
  500|  1.94k|    *place = p;
  501|       |
  502|  1.94k|    return 0;
  503|  1.94k|}
ssh_options_set:
 1219|  4.86k|{
 1220|  4.86k|    const char *v = NULL;
 1221|  4.86k|    char *p = NULL, *q = NULL;
 1222|  4.86k|    long int i;
 1223|  4.86k|    unsigned int u;
 1224|  4.86k|    int rc;
 1225|  4.86k|    char **wanted_methods = session->opts.wanted_methods;
 1226|  4.86k|    struct ssh_jump_callbacks_struct *j = NULL;
 1227|  4.86k|    enum ssh_config_opcode_e opcode;
 1228|       |
 1229|  4.86k|    if (session == NULL) {
  ------------------
  |  Branch (1229:9): [True: 0, False: 4.86k]
  ------------------
 1230|      0|        return -1;
 1231|      0|    }
 1232|       |
 1233|  4.86k|    switch (type) {
 1234|    486|        case SSH_OPTIONS_HOST:
  ------------------
  |  Branch (1234:9): [True: 486, False: 4.37k]
  ------------------
 1235|    486|            v = value;
 1236|    486|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1236:17): [True: 0, False: 486]
  |  Branch (1236:30): [True: 0, False: 486]
  ------------------
 1237|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1238|      0|                return -1;
 1239|    486|            } else if (session->opts.config_hostname_only) {
  ------------------
  |  Branch (1239:24): [True: 0, False: 486]
  ------------------
 1240|       |                /* HostName values are plain hostnames, not user@host URIs */
 1241|      0|                SAFE_FREE(session->opts.host);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1242|      0|                session->opts.host = strdup(value);
 1243|      0|                if (session->opts.host == NULL) {
  ------------------
  |  Branch (1243:21): [True: 0, False: 0]
  ------------------
 1244|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1245|      0|                    return -1;
 1246|      0|                }
 1247|    486|            } else {
 1248|    486|                char *username = NULL, *hostname = NULL;
 1249|    486|                char *strict_hostname = NULL;
 1250|    486|                char *normalized = NULL;
 1251|       |
 1252|       |                /* Non-strict parse: reject shell metacharacters */
 1253|    486|                rc = ssh_config_parse_uri(value,
 1254|    486|                                          &username,
 1255|    486|                                          &hostname,
 1256|    486|                                          NULL,
 1257|    486|                                          true,
 1258|    486|                                          false);
 1259|    486|                if (rc != SSH_OK || hostname == NULL) {
  ------------------
  |  |  316|    972|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1259:21): [True: 0, False: 486]
  |  Branch (1259:37): [True: 0, False: 486]
  ------------------
 1260|      0|                    SAFE_FREE(username);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1261|      0|                    SAFE_FREE(hostname);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1262|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1263|      0|                    return -1;
 1264|      0|                }
 1265|       |
 1266|       |                /* Non-strict passed: set username and originalhost */
 1267|    486|                if (username != NULL) {
  ------------------
  |  Branch (1267:21): [True: 0, False: 486]
  ------------------
 1268|      0|                    SAFE_FREE(session->opts.username);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1269|      0|                    session->opts.username = username;
 1270|      0|                }
 1271|    486|                SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  375|    486|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 486]
  |  |  |  Branch (375:71): [Folded, False: 486]
  |  |  ------------------
  ------------------
 1272|    486|                SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  375|    486|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 486]
  |  |  |  Branch (375:71): [Folded, False: 486]
  |  |  ------------------
  ------------------
 1273|    486|                session->opts.originalhost = hostname;
 1274|       |
 1275|       |                /* Strict parse: set host only if valid hostname or IP */
 1276|    486|                rc = ssh_normalize_loose_ip(value, &normalized);
 1277|    486|                if (rc == -1) {
  ------------------
  |  Branch (1277:21): [True: 0, False: 486]
  ------------------
 1278|       |                    /* Error */
 1279|      0|                    SAFE_FREE(username);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1280|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1281|      0|                    return -1;
 1282|      0|                }
 1283|    486|                rc = ssh_config_parse_uri(
 1284|    486|                    (normalized != NULL) ? normalized : value,
  ------------------
  |  Branch (1284:21): [True: 0, False: 486]
  ------------------
 1285|    486|                    NULL,
 1286|    486|                    &strict_hostname,
 1287|    486|                    NULL,
 1288|    486|                    true,
 1289|    486|                    true);
 1290|    486|                SAFE_FREE(normalized);
  ------------------
  |  |  375|    486|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 486]
  |  |  |  Branch (375:71): [Folded, False: 486]
  |  |  ------------------
  ------------------
 1291|       |
 1292|    486|                if (rc != SSH_OK || strict_hostname == NULL) {
  ------------------
  |  |  316|    972|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1292:21): [True: 0, False: 486]
  |  Branch (1292:37): [True: 0, False: 486]
  ------------------
 1293|      0|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1294|      0|                    SAFE_FREE(strict_hostname);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1295|    486|                } else {
 1296|    486|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  375|    486|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 486]
  |  |  |  Branch (375:71): [Folded, False: 486]
  |  |  ------------------
  ------------------
 1297|    486|                    session->opts.host = strict_hostname;
 1298|    486|                }
 1299|    486|            }
 1300|    486|            break;
 1301|    486|        case SSH_OPTIONS_PORT:
  ------------------
  |  Branch (1301:9): [True: 0, False: 4.86k]
  ------------------
 1302|      0|            if (value == NULL) {
  ------------------
  |  Branch (1302:17): [True: 0, False: 0]
  ------------------
 1303|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1304|      0|                return -1;
 1305|      0|            } else {
 1306|      0|                int *x = (int *) value;
 1307|      0|                if (*x <= 0 || *x > 65535) {
  ------------------
  |  Branch (1307:21): [True: 0, False: 0]
  |  Branch (1307:32): [True: 0, False: 0]
  ------------------
 1308|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1309|      0|                    return -1;
 1310|      0|                }
 1311|       |
 1312|      0|                session->opts.port = *x;
 1313|      0|            }
 1314|      0|            break;
 1315|      0|        case SSH_OPTIONS_PORT_STR:
  ------------------
  |  Branch (1315:9): [True: 0, False: 4.86k]
  ------------------
 1316|      0|            v = value;
 1317|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1317:17): [True: 0, False: 0]
  |  Branch (1317:30): [True: 0, False: 0]
  ------------------
 1318|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1319|      0|                return -1;
 1320|      0|            } else {
 1321|      0|                q = strdup(v);
 1322|      0|                if (q == NULL) {
  ------------------
  |  Branch (1322:21): [True: 0, False: 0]
  ------------------
 1323|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1324|      0|                    return -1;
 1325|      0|                }
 1326|      0|                i = strtol(q, &p, 10);
 1327|      0|                if (q == p || *p != '\0') {
  ------------------
  |  Branch (1327:21): [True: 0, False: 0]
  |  Branch (1327:31): [True: 0, False: 0]
  ------------------
 1328|      0|                    SSH_LOG(SSH_LOG_DEBUG, "No port number was parsed");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1329|      0|                    SAFE_FREE(q);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1330|      0|                    return -1;
 1331|      0|                }
 1332|      0|                SAFE_FREE(q);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1333|      0|                if (i <= 0 || i > 65535) {
  ------------------
  |  Branch (1333:21): [True: 0, False: 0]
  |  Branch (1333:31): [True: 0, False: 0]
  ------------------
 1334|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1335|      0|                    return -1;
 1336|      0|                }
 1337|       |
 1338|      0|                session->opts.port = i;
 1339|      0|            }
 1340|      0|            break;
 1341|    486|        case SSH_OPTIONS_FD:
  ------------------
  |  Branch (1341:9): [True: 486, False: 4.37k]
  ------------------
 1342|    486|            if (value == NULL) {
  ------------------
  |  Branch (1342:17): [True: 0, False: 486]
  ------------------
 1343|      0|                session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
 1344|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1345|      0|                return -1;
 1346|    486|            } else {
 1347|    486|                socket_t *x = (socket_t *) value;
 1348|    486|                if (*x < 0) {
  ------------------
  |  Branch (1348:21): [True: 0, False: 486]
  ------------------
 1349|      0|                    session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
 1350|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1351|      0|                    return -1;
 1352|      0|                }
 1353|       |
 1354|    486|                session->opts.fd = *x & 0xffff;
 1355|    486|            }
 1356|    486|            break;
 1357|    486|        case SSH_OPTIONS_BINDADDR:
  ------------------
  |  Branch (1357:9): [True: 0, False: 4.86k]
  ------------------
 1358|      0|            v = value;
 1359|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1359:17): [True: 0, False: 0]
  |  Branch (1359:30): [True: 0, False: 0]
  ------------------
 1360|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1361|      0|                return -1;
 1362|      0|            }
 1363|       |
 1364|      0|            q = strdup(v);
 1365|      0|            if (q == NULL) {
  ------------------
  |  Branch (1365:17): [True: 0, False: 0]
  ------------------
 1366|      0|                return -1;
 1367|      0|            }
 1368|      0|            SAFE_FREE(session->opts.bindaddr);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1369|      0|            session->opts.bindaddr = q;
 1370|      0|            break;
 1371|    486|        case SSH_OPTIONS_USER:
  ------------------
  |  Branch (1371:9): [True: 486, False: 4.37k]
  ------------------
 1372|    486|            v = value;
 1373|    486|            SAFE_FREE(session->opts.username);
  ------------------
  |  |  375|    486|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 486]
  |  |  |  Branch (375:71): [Folded, False: 486]
  |  |  ------------------
  ------------------
 1374|    486|            if (v == NULL) {
  ------------------
  |  Branch (1374:17): [True: 0, False: 486]
  ------------------
 1375|      0|                q = ssh_get_local_username();
 1376|      0|                if (q == NULL) {
  ------------------
  |  Branch (1376:21): [True: 0, False: 0]
  ------------------
 1377|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1378|      0|                    return -1;
 1379|      0|                }
 1380|      0|                session->opts.username = q;
 1381|    486|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1381:24): [True: 0, False: 486]
  ------------------
 1382|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1383|      0|                return -1;
 1384|    486|            } else { /* username provided */
 1385|    486|                session->opts.username = strdup(value);
 1386|    486|                if (session->opts.username == NULL) {
  ------------------
  |  Branch (1386:21): [True: 0, False: 486]
  ------------------
 1387|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1388|      0|                    return -1;
 1389|      0|                }
 1390|    486|                rc = ssh_check_username_syntax(session->opts.username);
 1391|    486|                if (rc != SSH_OK) {
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1391:21): [True: 0, False: 486]
  ------------------
 1392|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1393|      0|                    return -1;
 1394|      0|                }
 1395|    486|            }
 1396|    486|            break;
 1397|    486|        case SSH_OPTIONS_SSH_DIR:
  ------------------
  |  Branch (1397:9): [True: 486, False: 4.37k]
  ------------------
 1398|    486|            v = value;
 1399|    486|            SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  375|    486|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 486]
  |  |  |  Branch (375:71): [Folded, False: 486]
  |  |  ------------------
  ------------------
 1400|    486|            if (v == NULL) {
  ------------------
  |  Branch (1400:17): [True: 486, False: 0]
  ------------------
 1401|    486|                session->opts.sshdir = ssh_path_expand_tilde("~/.ssh");
 1402|    486|                if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (1402:21): [True: 0, False: 486]
  ------------------
 1403|      0|                    return -1;
 1404|      0|                }
 1405|    486|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1405:24): [True: 0, False: 0]
  ------------------
 1406|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1407|      0|                return -1;
 1408|      0|            } else {
 1409|      0|                session->opts.sshdir = ssh_path_expand_tilde(v);
 1410|      0|                if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (1410:21): [True: 0, False: 0]
  ------------------
 1411|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1412|      0|                    return -1;
 1413|      0|                }
 1414|      0|            }
 1415|    486|            break;
 1416|    486|        case SSH_OPTIONS_IDENTITY:
  ------------------
  |  Branch (1416:9): [True: 0, False: 4.86k]
  ------------------
 1417|      0|        case SSH_OPTIONS_ADD_IDENTITY: {
  ------------------
  |  Branch (1417:9): [True: 0, False: 4.86k]
  ------------------
 1418|      0|            struct ssh_iterator *id_it = NULL;
 1419|       |
 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);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1423|      0|                return -1;
 1424|      0|            }
 1425|      0|            q = strdup(v);
 1426|      0|            if (q == NULL) {
  ------------------
  |  Branch (1426:17): [True: 0, False: 0]
  ------------------
 1427|      0|                return -1;
 1428|      0|            }
 1429|       |            /* Deduplicate: skip if the same path is already in the list */
 1430|      0|            for (id_it = ssh_list_get_iterator(session->opts.identity_non_exp);
 1431|      0|                 id_it != NULL; id_it = id_it->next) {
  ------------------
  |  Branch (1431:18): [True: 0, False: 0]
  ------------------
 1432|      0|                int cmp = strcmp(ssh_iterator_value(char *, id_it), q);
  ------------------
  |  |  120|      0|  ((type)((iterator)->data))
  ------------------
 1433|      0|                if (cmp == 0) {
  ------------------
  |  Branch (1433:21): [True: 0, False: 0]
  ------------------
 1434|      0|                    free(q);
 1435|      0|                    return 0;
 1436|      0|                }
 1437|      0|            }
 1438|      0|            if (session->opts.exp_flags & SSH_OPT_EXP_FLAG_IDENTITY) {
  ------------------
  |  |  118|      0|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
  |  Branch (1438:17): [True: 0, False: 0]
  ------------------
 1439|      0|                rc = ssh_list_append(session->opts.identity_non_exp, q);
 1440|      0|            } else {
 1441|      0|                rc = ssh_list_prepend(session->opts.identity_non_exp, q);
 1442|      0|            }
 1443|      0|            if (rc < 0) {
  ------------------
  |  Branch (1443:17): [True: 0, False: 0]
  ------------------
 1444|      0|                free(q);
 1445|      0|                return -1;
 1446|      0|            }
 1447|      0|            break;
 1448|      0|        }
 1449|      0|        case SSH_OPTIONS_CERTIFICATE: {
  ------------------
  |  Branch (1449:9): [True: 0, False: 4.86k]
  ------------------
 1450|      0|            struct ssh_iterator *cert_it = NULL;
 1451|       |
 1452|      0|            v = value;
 1453|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1453:17): [True: 0, False: 0]
  |  Branch (1453:30): [True: 0, False: 0]
  ------------------
 1454|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1455|      0|                return -1;
 1456|      0|            }
 1457|      0|            q = strdup(v);
 1458|      0|            if (q == NULL) {
  ------------------
  |  Branch (1458:17): [True: 0, False: 0]
  ------------------
 1459|      0|                return -1;
 1460|      0|            }
 1461|       |            /* Allocate on first use (no longer pre-allocated in ssh_new()) */
 1462|      0|            if (session->opts.certificate_non_exp == NULL) {
  ------------------
  |  Branch (1462:17): [True: 0, False: 0]
  ------------------
 1463|      0|                session->opts.certificate_non_exp = ssh_list_new();
 1464|      0|                if (session->opts.certificate_non_exp == NULL) {
  ------------------
  |  Branch (1464:21): [True: 0, False: 0]
  ------------------
 1465|      0|                    free(q);
 1466|      0|                    return -1;
 1467|      0|                }
 1468|      0|            }
 1469|       |
 1470|       |            /* Deduplicate: skip if the same path is already in the list */
 1471|      0|            for (cert_it = ssh_list_get_iterator(session->opts.certificate_non_exp);
 1472|      0|                 cert_it != NULL; cert_it = cert_it->next) {
  ------------------
  |  Branch (1472:18): [True: 0, False: 0]
  ------------------
 1473|      0|                int cmp = strcmp(ssh_iterator_value(char *, cert_it), q);
  ------------------
  |  |  120|      0|  ((type)((iterator)->data))
  ------------------
 1474|      0|                if (cmp == 0) {
  ------------------
  |  Branch (1474:21): [True: 0, False: 0]
  ------------------
 1475|      0|                    free(q);
 1476|      0|                    return 0;
 1477|      0|                }
 1478|      0|            }
 1479|      0|            rc = ssh_list_append(session->opts.certificate_non_exp, q);
 1480|      0|            if (rc < 0) {
  ------------------
  |  Branch (1480:17): [True: 0, False: 0]
  ------------------
 1481|      0|                free(q);
 1482|      0|                return -1;
 1483|      0|            }
 1484|      0|            break;
 1485|      0|        }
 1486|      0|        case SSH_OPTIONS_KNOWNHOSTS:
  ------------------
  |  Branch (1486:9): [True: 0, False: 4.86k]
  ------------------
 1487|      0|            v = value;
 1488|      0|            SAFE_FREE(session->opts.knownhosts);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1489|      0|            if (v == NULL) {
  ------------------
  |  Branch (1489:17): [True: 0, False: 0]
  ------------------
 1490|       |                /* The default value will be set by the ssh_options_apply() */
 1491|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1491:24): [True: 0, False: 0]
  ------------------
 1492|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1493|      0|                return -1;
 1494|      0|            } else {
 1495|      0|                session->opts.knownhosts = strdup(v);
 1496|      0|                if (session->opts.knownhosts == NULL) {
  ------------------
  |  Branch (1496:21): [True: 0, False: 0]
  ------------------
 1497|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1498|      0|                    return -1;
 1499|      0|                }
 1500|      0|                session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_KNOWNHOSTS;
  ------------------
  |  |  115|      0|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
 1501|      0|            }
 1502|      0|            break;
 1503|      0|        case SSH_OPTIONS_GLOBAL_KNOWNHOSTS:
  ------------------
  |  Branch (1503:9): [True: 0, False: 4.86k]
  ------------------
 1504|      0|            v = value;
 1505|      0|            SAFE_FREE(session->opts.global_knownhosts);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1506|      0|            if (v == NULL) {
  ------------------
  |  Branch (1506:17): [True: 0, False: 0]
  ------------------
 1507|      0|                session->opts.global_knownhosts =
 1508|      0|                    strdup(GLOBAL_CONF_DIR "/ssh_known_hosts");
  ------------------
  |  |   13|      0|#define GLOBAL_CONF_DIR "/etc/ssh"
  ------------------
 1509|      0|                if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (1509:21): [True: 0, False: 0]
  ------------------
 1510|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1511|      0|                    return -1;
 1512|      0|                }
 1513|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1513:24): [True: 0, False: 0]
  ------------------
 1514|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1515|      0|                return -1;
 1516|      0|            } else {
 1517|      0|                session->opts.global_knownhosts = strdup(v);
 1518|      0|                if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (1518:21): [True: 0, False: 0]
  ------------------
 1519|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1520|      0|                    return -1;
 1521|      0|                }
 1522|      0|                session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS;
  ------------------
  |  |  116|      0|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
 1523|      0|            }
 1524|      0|            break;
 1525|    486|        case SSH_OPTIONS_TIMEOUT:
  ------------------
  |  Branch (1525:9): [True: 486, False: 4.37k]
  ------------------
 1526|    486|            if (value == NULL) {
  ------------------
  |  Branch (1526:17): [True: 0, False: 486]
  ------------------
 1527|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1528|      0|                return -1;
 1529|    486|            } else {
 1530|    486|                long *x = (long *) value;
 1531|    486|                if (*x < 0) {
  ------------------
  |  Branch (1531:21): [True: 0, False: 486]
  ------------------
 1532|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1533|      0|                    return -1;
 1534|      0|                }
 1535|       |
 1536|    486|                session->opts.timeout = *x & 0xffffffffU;
 1537|    486|            }
 1538|    486|            break;
 1539|    486|        case SSH_OPTIONS_TIMEOUT_USEC:
  ------------------
  |  Branch (1539:9): [True: 0, False: 4.86k]
  ------------------
 1540|      0|            if (value == NULL) {
  ------------------
  |  Branch (1540:17): [True: 0, False: 0]
  ------------------
 1541|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1542|      0|                return -1;
 1543|      0|            } else {
 1544|      0|                long *x = (long *) value;
 1545|      0|                if (*x < 0) {
  ------------------
  |  Branch (1545:21): [True: 0, False: 0]
  ------------------
 1546|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1547|      0|                    return -1;
 1548|      0|                }
 1549|       |
 1550|      0|                session->opts.timeout_usec = *x & 0xffffffffU;
 1551|      0|            }
 1552|      0|            break;
 1553|      0|        case SSH_OPTIONS_SSH1:
  ------------------
  |  Branch (1553:9): [True: 0, False: 4.86k]
  ------------------
 1554|      0|            break;
 1555|      0|        case SSH_OPTIONS_SSH2:
  ------------------
  |  Branch (1555:9): [True: 0, False: 4.86k]
  ------------------
 1556|      0|            break;
 1557|      0|        case SSH_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (1557:9): [True: 0, False: 4.86k]
  ------------------
 1558|      0|            if (value == NULL) {
  ------------------
  |  Branch (1558:17): [True: 0, False: 0]
  ------------------
 1559|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1560|      0|                return -1;
 1561|      0|            } else {
 1562|      0|                int *x = (int *) value;
 1563|      0|                if (*x < 0) {
  ------------------
  |  Branch (1563:21): [True: 0, False: 0]
  ------------------
 1564|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1565|      0|                    return -1;
 1566|      0|                }
 1567|       |
 1568|      0|                session->common.log_verbosity = *x & 0xffffU;
 1569|      0|                ssh_set_log_level(*x & 0xffffU);
 1570|      0|            }
 1571|      0|            break;
 1572|      0|        case SSH_OPTIONS_LOG_VERBOSITY_STR:
  ------------------
  |  Branch (1572:9): [True: 0, False: 4.86k]
  ------------------
 1573|      0|            v = value;
 1574|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1574:17): [True: 0, False: 0]
  |  Branch (1574:30): [True: 0, False: 0]
  ------------------
 1575|      0|                session->common.log_verbosity = 0;
 1576|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1577|      0|                return -1;
 1578|      0|            } else {
 1579|      0|                q = strdup(v);
 1580|      0|                if (q == NULL) {
  ------------------
  |  Branch (1580:21): [True: 0, False: 0]
  ------------------
 1581|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1582|      0|                    return -1;
 1583|      0|                }
 1584|      0|                i = strtol(q, &p, 10);
 1585|      0|                if (q == p) {
  ------------------
  |  Branch (1585:21): [True: 0, False: 0]
  ------------------
 1586|      0|                    SSH_LOG(SSH_LOG_DEBUG, "No log verbositiy was parsed");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1587|      0|                    SAFE_FREE(q);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1588|      0|                    return -1;
 1589|      0|                }
 1590|      0|                SAFE_FREE(q);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1591|      0|                if (i < 0) {
  ------------------
  |  Branch (1591:21): [True: 0, False: 0]
  ------------------
 1592|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1593|      0|                    return -1;
 1594|      0|                }
 1595|       |
 1596|      0|                session->common.log_verbosity = i & 0xffffU;
 1597|      0|                ssh_set_log_level(i & 0xffffU);
 1598|      0|            }
 1599|      0|            break;
 1600|    486|        case SSH_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (1600:9): [True: 486, False: 4.37k]
  ------------------
 1601|    486|            v = value;
 1602|    486|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1602:17): [True: 0, False: 486]
  |  Branch (1602:30): [True: 0, False: 486]
  ------------------
 1603|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1604|      0|                return -1;
 1605|    486|            } else {
 1606|    486|                rc = ssh_options_set_algo(session,
 1607|    486|                                          SSH_CRYPT_C_S,
 1608|    486|                                          v,
 1609|    486|                                          &wanted_methods[SSH_CRYPT_C_S]);
 1610|    486|                if (rc < 0)
  ------------------
  |  Branch (1610:21): [True: 0, False: 486]
  ------------------
 1611|      0|                    return -1;
 1612|    486|            }
 1613|    486|            break;
 1614|    486|        case SSH_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (1614:9): [True: 486, False: 4.37k]
  ------------------
 1615|    486|            v = value;
 1616|    486|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1616:17): [True: 0, False: 486]
  |  Branch (1616:30): [True: 0, False: 486]
  ------------------
 1617|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1618|      0|                return -1;
 1619|    486|            } else {
 1620|    486|                rc = ssh_options_set_algo(session,
 1621|    486|                                          SSH_CRYPT_S_C,
 1622|    486|                                          v,
 1623|    486|                                          &wanted_methods[SSH_CRYPT_S_C]);
 1624|    486|                if (rc < 0)
  ------------------
  |  Branch (1624:21): [True: 0, False: 486]
  ------------------
 1625|      0|                    return -1;
 1626|    486|            }
 1627|    486|            break;
 1628|    486|        case SSH_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (1628:9): [True: 0, False: 4.86k]
  ------------------
 1629|      0|            v = value;
 1630|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1630:17): [True: 0, False: 0]
  |  Branch (1630:30): [True: 0, False: 0]
  ------------------
 1631|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1632|      0|                return -1;
 1633|      0|            } else {
 1634|      0|                rc = ssh_options_set_algo(session,
 1635|      0|                                          SSH_KEX,
 1636|      0|                                          v,
 1637|      0|                                          &wanted_methods[SSH_KEX]);
 1638|      0|                if (rc < 0)
  ------------------
  |  Branch (1638:21): [True: 0, False: 0]
  ------------------
 1639|      0|                    return -1;
 1640|      0|            }
 1641|      0|            break;
 1642|      0|        case SSH_OPTIONS_HOSTKEYS:
  ------------------
  |  Branch (1642:9): [True: 0, False: 4.86k]
  ------------------
 1643|      0|            v = value;
 1644|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1644:17): [True: 0, False: 0]
  |  Branch (1644:30): [True: 0, False: 0]
  ------------------
 1645|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1646|      0|                return -1;
 1647|      0|            } else {
 1648|      0|                rc = ssh_options_set_algo(session,
 1649|      0|                                          SSH_HOSTKEYS,
 1650|      0|                                          v,
 1651|      0|                                          &wanted_methods[SSH_HOSTKEYS]);
 1652|      0|                if (rc < 0)
  ------------------
  |  Branch (1652:21): [True: 0, False: 0]
  ------------------
 1653|      0|                    return -1;
 1654|      0|            }
 1655|      0|            break;
 1656|      0|        case SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES:
  ------------------
  |  Branch (1656:9): [True: 0, False: 4.86k]
  ------------------
 1657|      0|            v = value;
 1658|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1658:17): [True: 0, False: 0]
  |  Branch (1658:30): [True: 0, False: 0]
  ------------------
 1659|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1660|      0|                return -1;
 1661|      0|            } else {
 1662|      0|                rc = ssh_options_set_algo(session,
 1663|      0|                                          SSH_HOSTKEYS,
 1664|      0|                                          v,
 1665|      0|                                          &session->opts.pubkey_accepted_types);
 1666|      0|                if (rc < 0)
  ------------------
  |  Branch (1666:21): [True: 0, False: 0]
  ------------------
 1667|      0|                    return -1;
 1668|      0|            }
 1669|      0|            break;
 1670|    486|        case SSH_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (1670:9): [True: 486, False: 4.37k]
  ------------------
 1671|    486|            v = value;
 1672|    486|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1672:17): [True: 0, False: 486]
  |  Branch (1672:30): [True: 0, False: 486]
  ------------------
 1673|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1674|      0|                return -1;
 1675|    486|            } else {
 1676|    486|                rc = ssh_options_set_algo(session,
 1677|    486|                                          SSH_MAC_C_S,
 1678|    486|                                          v,
 1679|    486|                                          &wanted_methods[SSH_MAC_C_S]);
 1680|    486|                if (rc < 0)
  ------------------
  |  Branch (1680:21): [True: 0, False: 486]
  ------------------
 1681|      0|                    return -1;
 1682|    486|            }
 1683|    486|            break;
 1684|    486|         case SSH_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (1684:10): [True: 486, False: 4.37k]
  ------------------
 1685|    486|            v = value;
 1686|    486|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1686:17): [True: 0, False: 486]
  |  Branch (1686:30): [True: 0, False: 486]
  ------------------
 1687|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1688|      0|                return -1;
 1689|    486|            } else {
 1690|    486|                rc = ssh_options_set_algo(session,
 1691|    486|                                          SSH_MAC_S_C,
 1692|    486|                                          v,
 1693|    486|                                          &wanted_methods[SSH_MAC_S_C]);
 1694|    486|                if (rc < 0)
  ------------------
  |  Branch (1694:21): [True: 0, False: 486]
  ------------------
 1695|      0|                    return -1;
 1696|    486|            }
 1697|    486|            break;
 1698|    486|        case SSH_OPTIONS_COMPRESSION_C_S:
  ------------------
  |  Branch (1698:9): [True: 0, False: 4.86k]
  ------------------
 1699|      0|            v = value;
 1700|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1700:17): [True: 0, False: 0]
  |  Branch (1700:30): [True: 0, False: 0]
  ------------------
 1701|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1702|      0|                return -1;
 1703|      0|            } else {
 1704|      0|                const char *tmp = v;
 1705|      0|                if (strcasecmp(value, "yes") == 0){
  ------------------
  |  Branch (1705:21): [True: 0, False: 0]
  ------------------
 1706|      0|                    tmp = "zlib@openssh.com,none";
 1707|      0|                } else if (strcasecmp(value, "no") == 0){
  ------------------
  |  Branch (1707:28): [True: 0, False: 0]
  ------------------
 1708|      0|                    tmp = "none,zlib@openssh.com";
 1709|      0|                }
 1710|      0|                rc = ssh_options_set_algo(session,
 1711|      0|                                          SSH_COMP_C_S,
 1712|      0|                                          tmp,
 1713|      0|                                          &wanted_methods[SSH_COMP_C_S]);
 1714|      0|                if (rc < 0)
  ------------------
  |  Branch (1714:21): [True: 0, False: 0]
  ------------------
 1715|      0|                    return -1;
 1716|      0|            }
 1717|      0|            break;
 1718|      0|        case SSH_OPTIONS_COMPRESSION_S_C:
  ------------------
  |  Branch (1718:9): [True: 0, False: 4.86k]
  ------------------
 1719|      0|            v = value;
 1720|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1720:17): [True: 0, False: 0]
  |  Branch (1720:30): [True: 0, False: 0]
  ------------------
 1721|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1722|      0|                return -1;
 1723|      0|            } else {
 1724|      0|                const char *tmp = v;
 1725|      0|                if (strcasecmp(value, "yes") == 0){
  ------------------
  |  Branch (1725:21): [True: 0, False: 0]
  ------------------
 1726|      0|                    tmp = "zlib@openssh.com,none";
 1727|      0|                } else if (strcasecmp(value, "no") == 0){
  ------------------
  |  Branch (1727:28): [True: 0, False: 0]
  ------------------
 1728|      0|                    tmp = "none,zlib@openssh.com";
 1729|      0|                }
 1730|       |
 1731|      0|                rc = ssh_options_set_algo(session,
 1732|      0|                                          SSH_COMP_S_C,
 1733|      0|                                          tmp,
 1734|      0|                                          &wanted_methods[SSH_COMP_S_C]);
 1735|      0|                if (rc < 0)
  ------------------
  |  Branch (1735:21): [True: 0, False: 0]
  ------------------
 1736|      0|                    return -1;
 1737|      0|            }
 1738|      0|            break;
 1739|      0|        case SSH_OPTIONS_COMPRESSION:
  ------------------
  |  Branch (1739:9): [True: 0, False: 4.86k]
  ------------------
 1740|      0|            v = value;
 1741|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1741:17): [True: 0, False: 0]
  |  Branch (1741:30): [True: 0, False: 0]
  ------------------
 1742|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1743|      0|                return -1;
 1744|      0|            }
 1745|      0|            if(ssh_options_set(session,SSH_OPTIONS_COMPRESSION_C_S, v) < 0)
  ------------------
  |  Branch (1745:16): [True: 0, False: 0]
  ------------------
 1746|      0|                return -1;
 1747|      0|            if(ssh_options_set(session,SSH_OPTIONS_COMPRESSION_S_C, v) < 0)
  ------------------
  |  Branch (1747:16): [True: 0, False: 0]
  ------------------
 1748|      0|                return -1;
 1749|      0|            break;
 1750|      0|        case SSH_OPTIONS_COMPRESSION_LEVEL:
  ------------------
  |  Branch (1750:9): [True: 0, False: 4.86k]
  ------------------
 1751|      0|            if (value == NULL) {
  ------------------
  |  Branch (1751:17): [True: 0, False: 0]
  ------------------
 1752|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1753|      0|                return -1;
 1754|      0|            } else {
 1755|      0|                int *x = (int *)value;
 1756|      0|                if (*x < 1 || *x > 9) {
  ------------------
  |  Branch (1756:21): [True: 0, False: 0]
  |  Branch (1756:31): [True: 0, False: 0]
  ------------------
 1757|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1758|      0|                    return -1;
 1759|      0|                }
 1760|      0|                session->opts.compressionlevel = *x & 0xff;
 1761|      0|            }
 1762|      0|            break;
 1763|      0|        case SSH_OPTIONS_STRICTHOSTKEYCHECK:
  ------------------
  |  Branch (1763:9): [True: 0, False: 4.86k]
  ------------------
 1764|      0|            if (value == NULL) {
  ------------------
  |  Branch (1764:17): [True: 0, False: 0]
  ------------------
 1765|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1766|      0|                return -1;
 1767|      0|            } else {
 1768|      0|                int *x = (int *) value;
 1769|      0|                int mode = *x;
 1770|       |
 1771|      0|                switch (mode) {
 1772|      0|                case SSH_STRICT_HOSTKEY_OFF:
  ------------------
  |  Branch (1772:17): [True: 0, False: 0]
  ------------------
 1773|      0|                case SSH_STRICT_HOSTKEY_YES:
  ------------------
  |  Branch (1773:17): [True: 0, False: 0]
  ------------------
 1774|      0|                case SSH_STRICT_HOSTKEY_ASK:
  ------------------
  |  Branch (1774:17): [True: 0, False: 0]
  ------------------
 1775|      0|                case SSH_STRICT_HOSTKEY_ACCEPT_NEW:
  ------------------
  |  Branch (1775:17): [True: 0, False: 0]
  ------------------
 1776|      0|                    session->opts.StrictHostKeyChecking = mode;
 1777|      0|                    break;
 1778|      0|                default:
  ------------------
  |  Branch (1778:17): [True: 0, False: 0]
  ------------------
 1779|       |                    /* Preserve the legacy low-byte "non-zero means yes"
 1780|       |                     * normalization.
 1781|       |                     */
 1782|      0|                    session->opts.StrictHostKeyChecking =
 1783|      0|                        (mode & 0xff) > 0 ? SSH_STRICT_HOSTKEY_YES
  ------------------
  |  Branch (1783:25): [True: 0, False: 0]
  ------------------
 1784|      0|                                          : SSH_STRICT_HOSTKEY_OFF;
 1785|      0|                    break;
 1786|      0|                }
 1787|      0|            }
 1788|      0|            break;
 1789|      0|        case SSH_OPTIONS_PROXYCOMMAND:
  ------------------
  |  Branch (1789:9): [True: 0, False: 4.86k]
  ------------------
 1790|      0|            v = value;
 1791|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1791:17): [True: 0, False: 0]
  |  Branch (1791:30): [True: 0, False: 0]
  ------------------
 1792|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1793|      0|                return -1;
 1794|      0|            } else {
 1795|      0|                SAFE_FREE(session->opts.ProxyCommand);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1796|       |                /* Setting the command to 'none' disables this option. */
 1797|      0|                rc = strcasecmp(v, "none");
 1798|      0|                if (rc != 0) {
  ------------------
  |  Branch (1798:21): [True: 0, False: 0]
  ------------------
 1799|      0|                    q = strdup(v);
 1800|      0|                    if (q == NULL) {
  ------------------
  |  Branch (1800:25): [True: 0, False: 0]
  ------------------
 1801|      0|                        return -1;
 1802|      0|                    }
 1803|      0|                    session->opts.ProxyCommand = q;
 1804|      0|                    session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_PROXYCOMMAND;
  ------------------
  |  |  117|      0|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
 1805|      0|                }
 1806|      0|            }
 1807|      0|            break;
 1808|      0|        case SSH_OPTIONS_PROXYJUMP:
  ------------------
  |  Branch (1808:9): [True: 0, False: 4.86k]
  ------------------
 1809|      0|            v = value;
 1810|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1810:17): [True: 0, False: 0]
  |  Branch (1810:30): [True: 0, False: 0]
  ------------------
 1811|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1812|      0|                return -1;
 1813|      0|            } else {
 1814|      0|                rc = ssh_config_parse_proxy_jump(session, v, true);
 1815|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1815:21): [True: 0, False: 0]
  ------------------
 1816|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1817|      0|                }
 1818|      0|            }
 1819|      0|            break;
 1820|      0|        case SSH_OPTIONS_PROXYJUMP_CB_LIST_APPEND:
  ------------------
  |  Branch (1820:9): [True: 0, False: 4.86k]
  ------------------
 1821|      0|            j = (struct ssh_jump_callbacks_struct *)value;
 1822|      0|            if (j == NULL) {
  ------------------
  |  Branch (1822:17): [True: 0, False: 0]
  ------------------
 1823|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1824|      0|                return -1;
 1825|      0|            } else {
 1826|       |                /* Allocate on first use (no longer pre-allocated in ssh_new()) */
 1827|      0|                if (session->opts.proxy_jumps_user_cb == NULL) {
  ------------------
  |  Branch (1827:21): [True: 0, False: 0]
  ------------------
 1828|      0|                    session->opts.proxy_jumps_user_cb = ssh_list_new();
 1829|      0|                    if (session->opts.proxy_jumps_user_cb == NULL) {
  ------------------
  |  Branch (1829:25): [True: 0, False: 0]
  ------------------
 1830|      0|                        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1831|      0|                        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1832|      0|                    }
 1833|      0|                }
 1834|      0|                rc = ssh_list_prepend(session->opts.proxy_jumps_user_cb, j);
 1835|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1835:21): [True: 0, False: 0]
  ------------------
 1836|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1837|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1838|      0|                }
 1839|      0|            }
 1840|      0|            break;
 1841|      0|        case SSH_OPTIONS_GSSAPI_SERVER_IDENTITY:
  ------------------
  |  Branch (1841:9): [True: 0, False: 4.86k]
  ------------------
 1842|      0|            v = value;
 1843|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1843:17): [True: 0, False: 0]
  |  Branch (1843:30): [True: 0, False: 0]
  ------------------
 1844|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1845|      0|                return -1;
 1846|      0|            } else {
 1847|      0|                SAFE_FREE(session->opts.gss_server_identity);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1848|      0|                session->opts.gss_server_identity = strdup(v);
 1849|      0|                if (session->opts.gss_server_identity == NULL) {
  ------------------
  |  Branch (1849:21): [True: 0, False: 0]
  ------------------
 1850|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1851|      0|                    return -1;
 1852|      0|                }
 1853|      0|            }
 1854|      0|            break;
 1855|      0|        case SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY:
  ------------------
  |  Branch (1855:9): [True: 0, False: 4.86k]
  ------------------
 1856|      0|            v = value;
 1857|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1857:17): [True: 0, False: 0]
  |  Branch (1857:30): [True: 0, False: 0]
  ------------------
 1858|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1859|      0|                return -1;
 1860|      0|            } else {
 1861|      0|                SAFE_FREE(session->opts.gss_client_identity);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1862|      0|                session->opts.gss_client_identity = strdup(v);
 1863|      0|                if (session->opts.gss_client_identity == NULL) {
  ------------------
  |  Branch (1863:21): [True: 0, False: 0]
  ------------------
 1864|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1865|      0|                    return -1;
 1866|      0|                }
 1867|      0|            }
 1868|      0|            break;
 1869|      0|        case SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS:
  ------------------
  |  Branch (1869:9): [True: 0, False: 4.86k]
  ------------------
 1870|      0|            if (value == NULL) {
  ------------------
  |  Branch (1870:17): [True: 0, False: 0]
  ------------------
 1871|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1872|      0|                return -1;
 1873|      0|            } else {
 1874|      0|                int x = *(int *)value;
 1875|       |
 1876|      0|                session->opts.gss_delegate_creds = (x & 0xff);
 1877|      0|            }
 1878|      0|            break;
 1879|       |#ifdef WITH_GSSAPI
 1880|       |        case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE:
 1881|       |            if (value == NULL) {
 1882|       |                ssh_set_error_invalid(session);
 1883|       |                return -1;
 1884|       |            } else {
 1885|       |                bool *x = (bool *)value;
 1886|       |                session->opts.gssapi_key_exchange = *x;
 1887|       |            }
 1888|       |            break;
 1889|       |        case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE_ALGS:
 1890|       |            v = value;
 1891|       |            if (v == NULL || v[0] == '\0') {
 1892|       |                ssh_set_error_invalid(session);
 1893|       |                return -1;
 1894|       |            } else {
 1895|       |                /* Check if algorithms are supported */
 1896|       |                char *ret =
 1897|       |                    ssh_find_all_matching(GSSAPI_KEY_EXCHANGE_SUPPORTED, v);
 1898|       |                if (ret == NULL) {
 1899|       |                    ssh_set_error(session,
 1900|       |                                  SSH_FATAL,
 1901|       |                                  "GSSAPI key exchange algorithms not "
 1902|       |                                  "supported or invalid");
 1903|       |                    return -1;
 1904|       |                }
 1905|       |                SAFE_FREE(session->opts.gssapi_key_exchange_algs);
 1906|       |                session->opts.gssapi_key_exchange_algs = ret;
 1907|       |            }
 1908|       |            break;
 1909|       |#endif
 1910|      0|        case SSH_OPTIONS_PASSWORD_AUTH:
  ------------------
  |  Branch (1910:9): [True: 0, False: 4.86k]
  ------------------
 1911|      0|        case SSH_OPTIONS_PUBKEY_AUTH:
  ------------------
  |  Branch (1911:9): [True: 0, False: 4.86k]
  ------------------
 1912|      0|        case SSH_OPTIONS_KBDINT_AUTH:
  ------------------
  |  Branch (1912:9): [True: 0, False: 4.86k]
  ------------------
 1913|      0|        case SSH_OPTIONS_GSSAPI_AUTH:
  ------------------
  |  Branch (1913:9): [True: 0, False: 4.86k]
  ------------------
 1914|      0|            if (value == NULL) {
  ------------------
  |  Branch (1914:17): [True: 0, False: 0]
  ------------------
 1915|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1916|      0|                return -1;
 1917|      0|            } else {
 1918|      0|                int x = *(int *)value;
 1919|      0|                u = type == SSH_OPTIONS_PASSWORD_AUTH ?
  ------------------
  |  Branch (1919:21): [True: 0, False: 0]
  ------------------
 1920|      0|                    SSH_OPT_FLAG_PASSWORD_AUTH:
  ------------------
  |  |  109|      0|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
 1921|      0|                    type == SSH_OPTIONS_PUBKEY_AUTH ?
  ------------------
  |  Branch (1921:21): [True: 0, False: 0]
  ------------------
 1922|      0|                        SSH_OPT_FLAG_PUBKEY_AUTH:
  ------------------
  |  |  110|      0|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
 1923|      0|                        type == SSH_OPTIONS_KBDINT_AUTH ?
  ------------------
  |  Branch (1923:25): [True: 0, False: 0]
  ------------------
 1924|      0|                            SSH_OPT_FLAG_KBDINT_AUTH:
  ------------------
  |  |  111|      0|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
 1925|      0|                            SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|      0|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
 1926|      0|                if (x != 0) {
  ------------------
  |  Branch (1926:21): [True: 0, False: 0]
  ------------------
 1927|      0|                    session->opts.flags |= u;
 1928|      0|                } else {
 1929|      0|                    session->opts.flags &= ~u;
 1930|      0|                }
 1931|      0|                if (type == SSH_OPTIONS_PUBKEY_AUTH) {
  ------------------
  |  Branch (1931:21): [True: 0, False: 0]
  ------------------
 1932|       |                    /*
 1933|       |                     * Keep the legacy enabled/disabled auth flag semantics in
 1934|       |                     * sync above while also storing the selected
 1935|       |                     * PubkeyAuthentication mode here.
 1936|       |                     */
 1937|      0|                    switch (x) {
 1938|      0|                    case SSH_PUBKEY_AUTH_NO:
  ------------------
  |  Branch (1938:21): [True: 0, False: 0]
  ------------------
 1939|      0|                    case SSH_PUBKEY_AUTH_ALL:
  ------------------
  |  Branch (1939:21): [True: 0, False: 0]
  ------------------
 1940|      0|                    case SSH_PUBKEY_AUTH_UNBOUND:
  ------------------
  |  Branch (1940:21): [True: 0, False: 0]
  ------------------
 1941|      0|                    case SSH_PUBKEY_AUTH_HOST_BOUND:
  ------------------
  |  Branch (1941:21): [True: 0, False: 0]
  ------------------
 1942|      0|                        session->opts.pubkey_auth = x;
 1943|      0|                        break;
 1944|      0|                    default:
  ------------------
  |  Branch (1944:21): [True: 0, False: 0]
  ------------------
 1945|       |                        /* Preserve the legacy non-zero "yes" normalization
 1946|       |                         * here so callers passing -1 still land on
 1947|       |                         * SSH_PUBKEY_AUTH_ALL.
 1948|       |                         */
 1949|      0|                        session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
 1950|      0|                        break;
 1951|      0|                    }
 1952|      0|                }
 1953|      0|            }
 1954|      0|            break;
 1955|      0|        case SSH_OPTIONS_NODELAY:
  ------------------
  |  Branch (1955:9): [True: 0, False: 4.86k]
  ------------------
 1956|      0|            if (value == NULL) {
  ------------------
  |  Branch (1956:17): [True: 0, False: 0]
  ------------------
 1957|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1958|      0|                return -1;
 1959|      0|            } else {
 1960|      0|                int *x = (int *) value;
 1961|      0|                session->opts.nodelay = (*x & 0xff) > 0 ? 1 : 0;
  ------------------
  |  Branch (1961:41): [True: 0, False: 0]
  ------------------
 1962|      0|            }
 1963|      0|            break;
 1964|    486|        case SSH_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (1964:9): [True: 486, False: 4.37k]
  ------------------
 1965|    486|            if (value == NULL) {
  ------------------
  |  Branch (1965:17): [True: 0, False: 486]
  ------------------
 1966|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1967|      0|                return -1;
 1968|    486|            } else {
 1969|    486|                bool *x = (bool *)value;
 1970|    486|                session->opts.config_processed = !(*x);
 1971|    486|            }
 1972|    486|            break;
 1973|    486|        case SSH_OPTIONS_REKEY_DATA:
  ------------------
  |  Branch (1973:9): [True: 0, False: 4.86k]
  ------------------
 1974|      0|            if (value == NULL) {
  ------------------
  |  Branch (1974:17): [True: 0, False: 0]
  ------------------
 1975|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1976|      0|                return -1;
 1977|      0|            } else {
 1978|      0|                uint64_t *x = (uint64_t *)value;
 1979|      0|                session->opts.rekey_data = *x;
 1980|      0|            }
 1981|      0|            break;
 1982|      0|        case SSH_OPTIONS_REKEY_TIME:
  ------------------
  |  Branch (1982:9): [True: 0, False: 4.86k]
  ------------------
 1983|      0|            if (value == NULL) {
  ------------------
  |  Branch (1983:17): [True: 0, False: 0]
  ------------------
 1984|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1985|      0|                return -1;
 1986|      0|            } else {
 1987|      0|                uint32_t *x = (uint32_t *)value;
 1988|      0|                if (*x > UINT32_MAX / 1000) {
  ------------------
  |  Branch (1988:21): [True: 0, False: 0]
  ------------------
 1989|      0|                    ssh_set_error(session, SSH_REQUEST_DENIED,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1990|      0|                                  "The provided value (%" PRIu32 ") for rekey"
 1991|      0|                                  " time is too large", *x);
 1992|      0|                    return -1;
 1993|      0|                }
 1994|      0|                session->opts.rekey_time = (*x) * 1000;
 1995|      0|            }
 1996|      0|            break;
 1997|      0|        case SSH_OPTIONS_RSA_MIN_SIZE:
  ------------------
  |  Branch (1997:9): [True: 0, False: 4.86k]
  ------------------
 1998|      0|            if (value == NULL) {
  ------------------
  |  Branch (1998:17): [True: 0, False: 0]
  ------------------
 1999|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2000|      0|                return -1;
 2001|      0|            } else {
 2002|      0|                int *x = (int *)value;
 2003|       |
 2004|      0|                if (*x < 0) {
  ------------------
  |  Branch (2004:21): [True: 0, False: 0]
  ------------------
 2005|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2006|      0|                    return -1;
 2007|      0|                }
 2008|       |
 2009|       |                /* (*x == 0) is allowed as it is used to revert to default */
 2010|       |
 2011|      0|                if (*x > 0 && *x < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|      0|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (2011:21): [True: 0, False: 0]
  |  Branch (2011:31): [True: 0, False: 0]
  ------------------
 2012|      0|                    ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 2013|      0|                                  SSH_REQUEST_DENIED,
 2014|      0|                                  "The provided value (%d) for minimal RSA key "
 2015|      0|                                  "size is too small. Use at least %d bits.",
 2016|      0|                                  *x,
 2017|      0|                                  RSA_MIN_KEY_SIZE);
 2018|      0|                    return -1;
 2019|      0|                }
 2020|      0|                session->opts.rsa_min_size = *x;
 2021|      0|            }
 2022|      0|            break;
 2023|      0|        case SSH_OPTIONS_IDENTITY_AGENT:
  ------------------
  |  Branch (2023:9): [True: 0, False: 4.86k]
  ------------------
 2024|      0|            v = value;
 2025|      0|            SAFE_FREE(session->opts.agent_socket);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2026|      0|            if (v == NULL) {
  ------------------
  |  Branch (2026:17): [True: 0, False: 0]
  ------------------
 2027|       |                /* The default value will be set by the ssh_options_apply() */
 2028|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (2028:24): [True: 0, False: 0]
  ------------------
 2029|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2030|      0|                return -1;
 2031|      0|            } else {
 2032|      0|                session->opts.agent_socket = ssh_path_expand_tilde(v);
 2033|      0|                if (session->opts.agent_socket == NULL) {
  ------------------
  |  Branch (2033:21): [True: 0, False: 0]
  ------------------
 2034|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2035|      0|                    return -1;
 2036|      0|                }
 2037|      0|            }
 2038|      0|            break;
 2039|      0|        case SSH_OPTIONS_IDENTITIES_ONLY:
  ------------------
  |  Branch (2039:9): [True: 0, False: 4.86k]
  ------------------
 2040|      0|            if (value == NULL) {
  ------------------
  |  Branch (2040:17): [True: 0, False: 0]
  ------------------
 2041|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2042|      0|                return -1;
 2043|      0|            } else {
 2044|      0|                bool *x = (bool *)value;
 2045|      0|                session->opts.identities_only = *x;
 2046|      0|            }
 2047|      0|            break;
 2048|      0|        case SSH_OPTIONS_CONTROL_MASTER:
  ------------------
  |  Branch (2048:9): [True: 0, False: 4.86k]
  ------------------
 2049|      0|            if (value == NULL) {
  ------------------
  |  Branch (2049:17): [True: 0, False: 0]
  ------------------
 2050|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2051|      0|                return -1;
 2052|      0|            } else {
 2053|      0|                int *x = (int *) value;
 2054|      0|                if (*x < SSH_CONTROL_MASTER_NO || *x > SSH_CONTROL_MASTER_AUTOASK) {
  ------------------
  |  Branch (2054:21): [True: 0, False: 0]
  |  Branch (2054:51): [True: 0, False: 0]
  ------------------
 2055|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2056|      0|                    return -1;
 2057|      0|                }
 2058|      0|                session->opts.control_master = *x;
 2059|      0|            }
 2060|      0|            break;
 2061|      0|        case SSH_OPTIONS_CONTROL_PATH:
  ------------------
  |  Branch (2061:9): [True: 0, False: 4.86k]
  ------------------
 2062|      0|            v = value;
 2063|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (2063:17): [True: 0, False: 0]
  |  Branch (2063:30): [True: 0, False: 0]
  ------------------
 2064|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2065|      0|                return -1;
 2066|      0|            } else {
 2067|      0|                SAFE_FREE(session->opts.control_path);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2068|      0|                rc = strcasecmp(v, "none");
 2069|      0|                if (rc != 0) {
  ------------------
  |  Branch (2069:21): [True: 0, False: 0]
  ------------------
 2070|      0|                    session->opts.control_path = ssh_path_expand_tilde(v);
 2071|      0|                    if (session->opts.control_path == NULL) {
  ------------------
  |  Branch (2071:25): [True: 0, False: 0]
  ------------------
 2072|      0|                        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2073|      0|                        return -1;
 2074|      0|                    }
 2075|      0|                    session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_CONTROL_PATH;
  ------------------
  |  |  119|      0|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
 2076|      0|                }
 2077|      0|            }
 2078|      0|            break;
 2079|      0|        case SSH_OPTIONS_PKI_CONTEXT:
  ------------------
  |  Branch (2079:9): [True: 0, False: 4.86k]
  ------------------
 2080|      0|            if (value == NULL) {
  ------------------
  |  Branch (2080:17): [True: 0, False: 0]
  ------------------
 2081|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2082|      0|                return -1;
 2083|      0|            }
 2084|       |
 2085|      0|            SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1059|      0|    do {                         \
  |  | 1060|      0|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1060:13): [True: 0, False: 0]
  |  |  ------------------
  |  | 1061|      0|            ssh_pki_ctx_free(x); \
  |  | 1062|      0|            x = NULL;            \
  |  | 1063|      0|        }                        \
  |  | 1064|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1064:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2086|       |
 2087|      0|            session->pki_context = ssh_pki_ctx_dup((const ssh_pki_ctx)value);
 2088|      0|            if (session->pki_context == NULL) {
  ------------------
  |  Branch (2088:17): [True: 0, False: 0]
  ------------------
 2089|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2090|      0|                return -1;
 2091|      0|            }
 2092|      0|            break;
 2093|      0|        case SSH_OPTIONS_ADDRESS_FAMILY:
  ------------------
  |  Branch (2093:9): [True: 0, False: 4.86k]
  ------------------
 2094|      0|            if (value == NULL) {
  ------------------
  |  Branch (2094:17): [True: 0, False: 0]
  ------------------
 2095|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2096|      0|                return -1;
 2097|      0|            } else {
 2098|      0|                int *x = (int *)value;
 2099|      0|                if (*x < SSH_ADDRESS_FAMILY_ANY ||
  ------------------
  |  Branch (2099:21): [True: 0, False: 0]
  ------------------
 2100|      0|                    *x > SSH_ADDRESS_FAMILY_INET6) {
  ------------------
  |  Branch (2100:21): [True: 0, False: 0]
  ------------------
 2101|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2102|      0|                    return -1;
 2103|      0|                }
 2104|      0|                session->opts.address_family = *x;
 2105|      0|            }
 2106|      0|            break;
 2107|      0|        case SSH_OPTIONS_BATCH_MODE:
  ------------------
  |  Branch (2107:9): [True: 0, False: 4.86k]
  ------------------
 2108|      0|            if (value == NULL) {
  ------------------
  |  Branch (2108:17): [True: 0, False: 0]
  ------------------
 2109|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2110|      0|                return -1;
 2111|      0|            } else {
 2112|      0|                bool *x = (bool *)value;
 2113|      0|                session->opts.batch_mode = *x;
 2114|      0|            }
 2115|      0|            break;
 2116|      0|        case SSH_OPTIONS_SERVER_ALIVE_INTERVAL:
  ------------------
  |  Branch (2116:9): [True: 0, False: 4.86k]
  ------------------
 2117|      0|            if (value == NULL) {
  ------------------
  |  Branch (2117:17): [True: 0, False: 0]
  ------------------
 2118|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2119|      0|                return -1;
 2120|      0|            } else {
 2121|      0|                int *x = (int *)value;
 2122|      0|                if (*x < 0) {
  ------------------
  |  Branch (2122:21): [True: 0, False: 0]
  ------------------
 2123|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2124|      0|                    return -1;
 2125|      0|                }
 2126|      0|                session->opts.server_alive_interval = *x;
 2127|      0|            }
 2128|      0|            break;
 2129|      0|        case SSH_OPTIONS_SERVER_ALIVE_COUNT_MAX:
  ------------------
  |  Branch (2129:9): [True: 0, False: 4.86k]
  ------------------
 2130|      0|            if (value == NULL) {
  ------------------
  |  Branch (2130:17): [True: 0, False: 0]
  ------------------
 2131|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2132|      0|                return -1;
 2133|      0|            } else {
 2134|      0|                int *x = (int *)value;
 2135|      0|                if (*x < 0) {
  ------------------
  |  Branch (2135:21): [True: 0, False: 0]
  ------------------
 2136|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2137|      0|                    return -1;
 2138|      0|                }
 2139|      0|                session->opts.server_alive_count_max = *x;
 2140|      0|            }
 2141|      0|            break;
 2142|      0|        case SSH_OPTIONS_ESCAPE_CHAR:
  ------------------
  |  Branch (2142:9): [True: 0, False: 4.86k]
  ------------------
 2143|      0|            if (value == NULL) {
  ------------------
  |  Branch (2143:17): [True: 0, False: 0]
  ------------------
 2144|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2145|      0|                return -1;
 2146|      0|            } else {
 2147|      0|                int *x = (int *)value;
 2148|      0|                if (*x == 0 || *x < -1 || *x > 255) {
  ------------------
  |  Branch (2148:21): [True: 0, False: 0]
  |  Branch (2148:32): [True: 0, False: 0]
  |  Branch (2148:43): [True: 0, False: 0]
  ------------------
 2149|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2150|      0|                    return -1;
 2151|      0|                }
 2152|      0|                session->opts.escape_char = *x;
 2153|      0|            }
 2154|      0|            break;
 2155|      0|        case SSH_OPTIONS_LOCAL_FORWARD:
  ------------------
  |  Branch (2155:9): [True: 0, False: 4.86k]
  ------------------
 2156|      0|            v = value;
 2157|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (2157:17): [True: 0, False: 0]
  |  Branch (2157:30): [True: 0, False: 0]
  ------------------
 2158|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2159|      0|                return -1;
 2160|      0|            }
 2161|      0|            q = strdup(v);
 2162|      0|            if (q == NULL) {
  ------------------
  |  Branch (2162:17): [True: 0, False: 0]
  ------------------
 2163|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2164|      0|                return -1;
 2165|      0|            }
 2166|       |            /* Allocate on first use (no longer pre-allocated in ssh_new()) */
 2167|      0|            if (session->opts.local_forward == NULL) {
  ------------------
  |  Branch (2167:17): [True: 0, False: 0]
  ------------------
 2168|      0|                session->opts.local_forward = ssh_list_new();
 2169|      0|                if (session->opts.local_forward == NULL) {
  ------------------
  |  Branch (2169:21): [True: 0, False: 0]
  ------------------
 2170|      0|                    free(q);
 2171|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2172|      0|                    return -1;
 2173|      0|                }
 2174|      0|            }
 2175|      0|            rc = ssh_list_append(session->opts.local_forward, q);
 2176|      0|            if (rc < 0) {
  ------------------
  |  Branch (2176:17): [True: 0, False: 0]
  ------------------
 2177|      0|                free(q);
 2178|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2179|      0|                return -1;
 2180|      0|            }
 2181|      0|            break;
 2182|      0|        case SSH_OPTIONS_REMOTE_FORWARD:
  ------------------
  |  Branch (2182:9): [True: 0, False: 4.86k]
  ------------------
 2183|      0|            v = value;
 2184|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (2184:17): [True: 0, False: 0]
  |  Branch (2184:30): [True: 0, False: 0]
  ------------------
 2185|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2186|      0|                return -1;
 2187|      0|            }
 2188|      0|            q = strdup(v);
 2189|      0|            if (q == NULL) {
  ------------------
  |  Branch (2189:17): [True: 0, False: 0]
  ------------------
 2190|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2191|      0|                return -1;
 2192|      0|            }
 2193|       |            /* Lazy allocation: allocate list on first use */
 2194|      0|            if (session->opts.remote_forward == NULL) {
  ------------------
  |  Branch (2194:17): [True: 0, False: 0]
  ------------------
 2195|      0|                session->opts.remote_forward = ssh_list_new();
 2196|      0|                if (session->opts.remote_forward == NULL) {
  ------------------
  |  Branch (2196:21): [True: 0, False: 0]
  ------------------
 2197|      0|                    free(q);
 2198|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2199|      0|                    return -1;
 2200|      0|                }
 2201|      0|            }
 2202|      0|            rc = ssh_list_append(session->opts.remote_forward, q);
 2203|      0|            if (rc < 0) {
  ------------------
  |  Branch (2203:17): [True: 0, False: 0]
  ------------------
 2204|      0|                free(q);
 2205|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2206|      0|                return -1;
 2207|      0|            }
 2208|      0|            break;
 2209|      0|        case SSH_OPTIONS_PREFERRED_AUTHENTICATIONS:
  ------------------
  |  Branch (2209:9): [True: 0, False: 4.86k]
  ------------------
 2210|      0|            v = value;
 2211|      0|            SAFE_FREE(session->opts.preferred_authentications);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2212|      0|            if (v != NULL) {
  ------------------
  |  Branch (2212:17): [True: 0, False: 0]
  ------------------
 2213|      0|                if (v[0] == '\0') {
  ------------------
  |  Branch (2213:21): [True: 0, False: 0]
  ------------------
 2214|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2215|      0|                    return -1;
 2216|      0|                }
 2217|      0|                session->opts.preferred_authentications = strdup(v);
 2218|      0|                if (session->opts.preferred_authentications == NULL) {
  ------------------
  |  Branch (2218:21): [True: 0, False: 0]
  ------------------
 2219|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2220|      0|                    return -1;
 2221|      0|                }
 2222|      0|            }
 2223|      0|            break;
 2224|      0|        case SSH_OPTIONS_NUMBER_OF_PASSWORD_PROMPTS:
  ------------------
  |  Branch (2224:9): [True: 0, False: 4.86k]
  ------------------
 2225|      0|            if (value == NULL) {
  ------------------
  |  Branch (2225:17): [True: 0, False: 0]
  ------------------
 2226|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2227|      0|                return -1;
 2228|      0|            } else {
 2229|      0|                int *x = (int *)value;
 2230|      0|                if (*x <= 0) {
  ------------------
  |  Branch (2230:21): [True: 0, False: 0]
  ------------------
 2231|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2232|      0|                    return -1;
 2233|      0|                }
 2234|      0|                session->opts.number_of_password_prompts = *x;
 2235|      0|            }
 2236|      0|            break;
 2237|      0|        case SSH_OPTIONS_REQUEST_TTY:
  ------------------
  |  Branch (2237:9): [True: 0, False: 4.86k]
  ------------------
 2238|      0|            if (value == NULL) {
  ------------------
  |  Branch (2238:17): [True: 0, False: 0]
  ------------------
 2239|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2240|      0|                return -1;
 2241|      0|            } else {
 2242|      0|                int *x = (int *)value;
 2243|      0|                if (*x < SSH_REQUEST_TTY_NO || *x > SSH_REQUEST_TTY_FORCE) {
  ------------------
  |  Branch (2243:21): [True: 0, False: 0]
  |  Branch (2243:48): [True: 0, False: 0]
  ------------------
 2244|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2245|      0|                    return -1;
 2246|      0|                }
 2247|      0|                session->opts.request_tty = *x;
 2248|      0|            }
 2249|      0|            break;
 2250|      0|        case SSH_OPTIONS_SEND_ENV:
  ------------------
  |  Branch (2250:9): [True: 0, False: 4.86k]
  ------------------
 2251|      0|            v = value;
 2252|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (2252:17): [True: 0, False: 0]
  |  Branch (2252:30): [True: 0, False: 0]
  ------------------
 2253|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2254|      0|                return -1;
 2255|      0|            }
 2256|       |            /* A leading '-' removes the pattern from the list */
 2257|      0|            if (v[0] == '-') {
  ------------------
  |  Branch (2257:17): [True: 0, False: 0]
  ------------------
 2258|      0|                const char *pattern = NULL;
 2259|      0|                const char *env_value = NULL;
 2260|      0|                struct ssh_iterator *it = NULL;
 2261|      0|                struct ssh_iterator *next = NULL;
 2262|      0|                int cmp = 0;
 2263|       |
 2264|      0|                pattern = v + 1;
 2265|      0|                if (pattern[0] == '\0') {
  ------------------
  |  Branch (2265:21): [True: 0, False: 0]
  ------------------
 2266|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2267|      0|                    return -1;
 2268|      0|                }
 2269|      0|                it = ssh_list_get_iterator(session->opts.send_env);
 2270|      0|                while (it != NULL) {
  ------------------
  |  Branch (2270:24): [True: 0, False: 0]
  ------------------
 2271|      0|                    env_value = ssh_iterator_value(const char *, it);
  ------------------
  |  |  120|      0|  ((type)((iterator)->data))
  ------------------
 2272|      0|                    cmp = strcmp(env_value, pattern);
 2273|      0|                    next = it->next;
 2274|      0|                    if (cmp == 0) {
  ------------------
  |  Branch (2274:25): [True: 0, False: 0]
  ------------------
 2275|      0|                        free((void *)env_value);
 2276|      0|                        ssh_list_remove(session->opts.send_env, it);
 2277|      0|                    }
 2278|      0|                    it = next;
 2279|      0|                }
 2280|      0|                rc = SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2281|      0|            } else {
 2282|      0|                q = strdup(v);
 2283|      0|                if (q == NULL) {
  ------------------
  |  Branch (2283:21): [True: 0, False: 0]
  ------------------
 2284|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2285|      0|                    return -1;
 2286|      0|                }
 2287|       |                /* Allocate on first use (no longer pre-allocated in ssh_new()) */
 2288|      0|                if (session->opts.send_env == NULL) {
  ------------------
  |  Branch (2288:21): [True: 0, False: 0]
  ------------------
 2289|      0|                    session->opts.send_env = ssh_list_new();
 2290|      0|                    if (session->opts.send_env == NULL) {
  ------------------
  |  Branch (2290:25): [True: 0, False: 0]
  ------------------
 2291|      0|                        free(q);
 2292|      0|                        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2293|      0|                        return -1;
 2294|      0|                    }
 2295|      0|                }
 2296|      0|                rc = ssh_list_append(session->opts.send_env, q);
 2297|      0|                if (rc < 0) {
  ------------------
  |  Branch (2297:21): [True: 0, False: 0]
  ------------------
 2298|      0|                    free(q);
 2299|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2300|      0|                    return -1;
 2301|      0|                }
 2302|      0|            }
 2303|      0|            break;
 2304|      0|        case SSH_OPTIONS_EXIT_ON_FORWARD_FAILURE:
  ------------------
  |  Branch (2304:9): [True: 0, False: 4.86k]
  ------------------
 2305|      0|            if (value == NULL) {
  ------------------
  |  Branch (2305:17): [True: 0, False: 0]
  ------------------
 2306|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2307|      0|                return -1;
 2308|      0|            } else {
 2309|      0|                bool *x = (bool *)value;
 2310|      0|                session->opts.exit_on_forward_failure = *x;
 2311|      0|            }
 2312|      0|            break;
 2313|      0|        case SSH_OPTIONS_FORWARD_AGENT:
  ------------------
  |  Branch (2313:9): [True: 0, False: 4.86k]
  ------------------
 2314|      0|            if (value == NULL) {
  ------------------
  |  Branch (2314:17): [True: 0, False: 0]
  ------------------
 2315|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2316|      0|                return -1;
 2317|      0|            } else {
 2318|      0|                bool *x = (bool *)value;
 2319|      0|                session->opts.forward_agent = *x;
 2320|      0|            }
 2321|      0|            break;
 2322|      0|        case SSH_OPTIONS_FORWARD_AGENT_SOCK_PATH:
  ------------------
  |  Branch (2322:9): [True: 0, False: 4.86k]
  ------------------
 2323|      0|            v = value;
 2324|      0|            SAFE_FREE(session->opts.forward_agent_sock_path);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2325|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (2325:17): [True: 0, False: 0]
  |  Branch (2325:30): [True: 0, False: 0]
  ------------------
 2326|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2327|      0|                return -1;
 2328|      0|            } else {
 2329|      0|                session->opts.forward_agent_sock_path =
 2330|      0|                    ssh_path_expand_tilde(v);
 2331|      0|                if (session->opts.forward_agent_sock_path == NULL) {
  ------------------
  |  Branch (2331:21): [True: 0, False: 0]
  ------------------
 2332|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2333|      0|                    return -1;
 2334|      0|                }
 2335|      0|            }
 2336|      0|            break;
 2337|      0|        case SSH_OPTIONS_GATEWAY_PORTS:
  ------------------
  |  Branch (2337:9): [True: 0, False: 4.86k]
  ------------------
 2338|      0|            if (value == NULL) {
  ------------------
  |  Branch (2338:17): [True: 0, False: 0]
  ------------------
 2339|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 2340|      0|                return -1;
 2341|      0|            } else {
 2342|      0|                bool *x = (bool *)value;
 2343|      0|                session->opts.gateway_ports = *x;
 2344|      0|            }
 2345|      0|            break;
 2346|      0|        default:
  ------------------
  |  Branch (2346:9): [True: 0, False: 4.86k]
  ------------------
 2347|      0|            ssh_set_error(session, SSH_REQUEST_DENIED, "Unknown ssh option %d", type);
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 2348|      0|            return -1;
 2349|      0|            break;
 2350|  4.86k|    }
 2351|       |
 2352|       |    /*
 2353|       |     * The option was set successfully. Mark config-backed options as
 2354|       |     * explicitly set so that later processing of OpenSSH configuration files
 2355|       |     * keeps the application's value (issue #365). Options that map to
 2356|       |     * SOC_UNKNOWN are intentionally left unmarked.
 2357|       |     */
 2358|  4.86k|    opcode = ssh_opt_type_to_opcode(type);
 2359|  4.86k|    if (opcode != SOC_UNKNOWN) {
  ------------------
  |  Branch (2359:9): [True: 2.91k, False: 1.94k]
  ------------------
 2360|  2.91k|        session->opts.options_seen[opcode] = 1;
 2361|  2.91k|    }
 2362|       |
 2363|  4.86k|    return 0;
 2364|  4.86k|}
ssh_options_apply:
 3212|    486|{
 3213|    486|    char *tmp = NULL;
 3214|    486|    int rc;
 3215|       |
 3216|    486|    if (session->opts.host != NULL) {
  ------------------
  |  Branch (3216:9): [True: 486, False: 0]
  ------------------
 3217|    486|        char *normalized_host = NULL;
 3218|    486|        rc = ssh_normalize_loose_ip(session->opts.host, &normalized_host);
 3219|    486|        if (rc == -1) {
  ------------------
  |  Branch (3219:13): [True: 0, False: 486]
  ------------------
 3220|       |            /* Error (e.g. NULL input or OOM) — leave host as it is */
 3221|    486|        } else if (rc == 0) {
  ------------------
  |  Branch (3221:20): [True: 0, False: 486]
  ------------------
 3222|       |            /* Was a loose IP — use the normalized dotted-quad form */
 3223|      0|            SAFE_FREE(session->opts.host);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3224|      0|            session->opts.host = normalized_host;
 3225|    486|        } else {
 3226|       |            /* rc == 1: not a loose IP — lowercase if it's not a strict IP */
 3227|    486|            bool requires_lowercase = ssh_host_requires_lowercase(session->opts.host);
 3228|    486|            if (requires_lowercase) {
  ------------------
  |  Branch (3228:17): [True: 0, False: 486]
  ------------------
 3229|      0|                char *lower = ssh_lowercase(session->opts.host);
 3230|      0|                if (lower != NULL) {
  ------------------
  |  Branch (3230:21): [True: 0, False: 0]
  ------------------
 3231|      0|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3232|      0|                    session->opts.host = lower;
 3233|      0|                }
 3234|      0|            }
 3235|    486|        }
 3236|    486|    }
 3237|       |
 3238|    486|    if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (3238:9): [True: 486, False: 0]
  ------------------
 3239|    486|        rc = ssh_options_set(session, SSH_OPTIONS_SSH_DIR, NULL);
 3240|    486|        if (rc < 0) {
  ------------------
  |  Branch (3240:13): [True: 0, False: 486]
  ------------------
 3241|      0|            return -1;
 3242|      0|        }
 3243|    486|    }
 3244|       |
 3245|    486|    if (session->opts.username == NULL) {
  ------------------
  |  Branch (3245:9): [True: 0, False: 486]
  ------------------
 3246|      0|        rc = ssh_options_set(session, SSH_OPTIONS_USER, NULL);
 3247|      0|        if (rc < 0) {
  ------------------
  |  Branch (3247:13): [True: 0, False: 0]
  ------------------
 3248|      0|            return -1;
 3249|      0|        }
 3250|      0|    }
 3251|       |
 3252|    486|    if (session->opts.config_hostname != NULL) {
  ------------------
  |  Branch (3252:9): [True: 0, False: 486]
  ------------------
 3253|      0|        char *saved_host = NULL;
 3254|       |
 3255|      0|        tmp = ssh_path_expand_hostname(session, session->opts.config_hostname);
 3256|      0|        if (tmp == NULL) {
  ------------------
  |  Branch (3256:13): [True: 0, False: 0]
  ------------------
 3257|      0|            return -1;
 3258|      0|        }
 3259|      0|        if (session->opts.host != NULL) {
  ------------------
  |  Branch (3259:13): [True: 0, False: 0]
  ------------------
 3260|      0|            saved_host = strdup(session->opts.host);
 3261|      0|            if (saved_host == NULL) {
  ------------------
  |  Branch (3261:17): [True: 0, False: 0]
  ------------------
 3262|      0|                free(tmp);
 3263|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 3264|      0|                return -1;
 3265|      0|            }
 3266|      0|        }
 3267|      0|        session->opts.config_hostname_only = true;
 3268|      0|        rc = ssh_options_set(session, SSH_OPTIONS_HOST, tmp);
 3269|      0|        session->opts.config_hostname_only = false;
 3270|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3270:13): [True: 0, False: 0]
  ------------------
 3271|       |            /* If HostName expansion leaves a literal '%', keep the current
 3272|       |             * host instead of treating the deferred HostName as fatal.
 3273|       |             */
 3274|      0|            if (strchr(tmp, '%') == NULL) {
  ------------------
  |  Branch (3274:17): [True: 0, False: 0]
  ------------------
 3275|      0|                SAFE_FREE(saved_host);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3276|      0|                free(tmp);
 3277|      0|                return -1;
 3278|      0|            }
 3279|      0|            SSH_LOG(SSH_LOG_WARN,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3280|      0|                    "HostName %s contains unknown expansion tokens and could "
 3281|      0|                    "not be applied; falling back to current host",
 3282|      0|                    tmp);
 3283|      0|            SAFE_FREE(session->opts.host);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3284|      0|            session->opts.host = saved_host;
 3285|      0|            saved_host = NULL;
 3286|      0|        }
 3287|      0|        SAFE_FREE(saved_host);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3288|      0|        free(tmp);
 3289|      0|        SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3290|      0|    }
 3291|       |
 3292|       |    /* Expand percent tokens in the username at apply time, matching OpenSSH
 3293|       |     * which defers User expansion to after all options are resolved.
 3294|       |     */
 3295|    486|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_USERNAME) == 0 &&
  ------------------
  |  |  120|    486|#define SSH_OPT_EXP_FLAG_USERNAME 0x20
  ------------------
  |  Branch (3295:9): [True: 486, False: 0]
  ------------------
 3296|    486|        session->opts.username != NULL) {
  ------------------
  |  Branch (3296:9): [True: 486, False: 0]
  ------------------
 3297|    486|        tmp = ssh_string_expand_escape(session, session->opts.username);
 3298|    486|        if (tmp != NULL) {
  ------------------
  |  Branch (3298:13): [True: 486, False: 0]
  ------------------
 3299|    486|            free(session->opts.username);
 3300|    486|            session->opts.username = tmp;
 3301|    486|            tmp = NULL;
 3302|    486|        }
 3303|       |        /* On failure, keep the raw string — best-effort expansion */
 3304|    486|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_USERNAME;
  ------------------
  |  |  120|    486|#define SSH_OPT_EXP_FLAG_USERNAME 0x20
  ------------------
 3305|    486|    }
 3306|       |
 3307|    486|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_KNOWNHOSTS) == 0) {
  ------------------
  |  |  115|    486|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
  |  Branch (3307:9): [True: 486, False: 0]
  ------------------
 3308|    486|        if (session->opts.knownhosts == NULL) {
  ------------------
  |  Branch (3308:13): [True: 486, False: 0]
  ------------------
 3309|    486|            tmp = ssh_path_expand_escape(session, "%d/.ssh/known_hosts");
 3310|    486|        } else {
 3311|      0|            tmp = ssh_path_expand_escape(session, session->opts.knownhosts);
 3312|      0|        }
 3313|    486|        if (tmp == NULL) {
  ------------------
  |  Branch (3313:13): [True: 0, False: 486]
  ------------------
 3314|      0|            return -1;
 3315|      0|        }
 3316|    486|        free(session->opts.knownhosts);
 3317|    486|        session->opts.knownhosts = tmp;
 3318|    486|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_KNOWNHOSTS;
  ------------------
  |  |  115|    486|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
 3319|    486|    }
 3320|       |
 3321|    486|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS) == 0) {
  ------------------
  |  |  116|    486|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
  |  Branch (3321:9): [True: 486, False: 0]
  ------------------
 3322|    486|        if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (3322:13): [True: 486, False: 0]
  ------------------
 3323|    486|            tmp = strdup(GLOBAL_CONF_DIR "/ssh_known_hosts");
  ------------------
  |  |   13|    486|#define GLOBAL_CONF_DIR "/etc/ssh"
  ------------------
 3324|    486|        } else {
 3325|      0|            tmp = ssh_path_expand_escape(session,
 3326|      0|                                         session->opts.global_knownhosts);
 3327|      0|        }
 3328|    486|        if (tmp == NULL) {
  ------------------
  |  Branch (3328:13): [True: 0, False: 486]
  ------------------
 3329|      0|            return -1;
 3330|      0|        }
 3331|    486|        free(session->opts.global_knownhosts);
 3332|    486|        session->opts.global_knownhosts = tmp;
 3333|    486|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS;
  ------------------
  |  |  116|    486|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
 3334|    486|    }
 3335|       |
 3336|       |
 3337|    486|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_PROXYCOMMAND) == 0) {
  ------------------
  |  |  117|    486|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
  |  Branch (3337:9): [True: 486, False: 0]
  ------------------
 3338|    486|        if (session->opts.ProxyCommand != NULL) {
  ------------------
  |  Branch (3338:13): [True: 0, False: 486]
  ------------------
 3339|      0|            char *p = NULL;
 3340|      0|            size_t plen = strlen(session->opts.ProxyCommand) +
 3341|      0|                          5 /* strlen("exec ") */;
 3342|       |
 3343|      0|            if (strncmp(session->opts.ProxyCommand, "exec ", 5) != 0) {
  ------------------
  |  Branch (3343:17): [True: 0, False: 0]
  ------------------
 3344|      0|                p = malloc(plen + 1 /* \0 */);
 3345|      0|                if (p == NULL) {
  ------------------
  |  Branch (3345:21): [True: 0, False: 0]
  ------------------
 3346|      0|                    return -1;
 3347|      0|                }
 3348|       |
 3349|      0|                rc = snprintf(p, plen + 1, "exec %s", session->opts.ProxyCommand);
 3350|      0|                if ((size_t)rc != plen) {
  ------------------
  |  Branch (3350:21): [True: 0, False: 0]
  ------------------
 3351|      0|                    free(p);
 3352|      0|                    return -1;
 3353|      0|                }
 3354|      0|                tmp = ssh_path_expand_escape(session, p);
 3355|      0|                free(p);
 3356|      0|            } else {
 3357|      0|                tmp = ssh_path_expand_escape(session,
 3358|      0|                                             session->opts.ProxyCommand);
 3359|      0|            }
 3360|       |
 3361|      0|            if (tmp == NULL) {
  ------------------
  |  Branch (3361:17): [True: 0, False: 0]
  ------------------
 3362|      0|                return -1;
 3363|      0|            }
 3364|      0|            free(session->opts.ProxyCommand);
 3365|      0|            session->opts.ProxyCommand = tmp;
 3366|      0|            session->opts.exp_flags |= SSH_OPT_EXP_FLAG_PROXYCOMMAND;
  ------------------
  |  |  117|      0|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
 3367|      0|        }
 3368|    486|    }
 3369|       |
 3370|    486|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_CONTROL_PATH) == 0) {
  ------------------
  |  |  119|    486|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
  |  Branch (3370:9): [True: 486, False: 0]
  ------------------
 3371|    486|        if (session->opts.control_path != NULL) {
  ------------------
  |  Branch (3371:13): [True: 0, False: 486]
  ------------------
 3372|      0|            tmp = ssh_path_expand_escape(session, session->opts.control_path);
 3373|      0|            if (tmp == NULL) {
  ------------------
  |  Branch (3373:17): [True: 0, False: 0]
  ------------------
 3374|      0|                return -1;
 3375|      0|            }
 3376|      0|            free(session->opts.control_path);
 3377|      0|            session->opts.control_path = tmp;
 3378|      0|            session->opts.exp_flags |= SSH_OPT_EXP_FLAG_CONTROL_PATH;
  ------------------
  |  |  119|      0|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
 3379|      0|        }
 3380|    486|    }
 3381|       |
 3382|       |    /* Allocate on first use (no longer pre-allocated in ssh_new()) */
 3383|    486|    if (session->opts.identity == NULL) {
  ------------------
  |  Branch (3383:9): [True: 486, False: 0]
  ------------------
 3384|    486|        session->opts.identity = ssh_list_new();
 3385|    486|        if (session->opts.identity == NULL) {
  ------------------
  |  Branch (3385:13): [True: 0, False: 486]
  ------------------
 3386|      0|            return -1;
 3387|      0|        }
 3388|    486|    }
 3389|       |
 3390|    486|    for (tmp = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  128|    486|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 3391|  1.94k|         tmp != NULL;
  ------------------
  |  Branch (3391:10): [True: 1.45k, False: 486]
  ------------------
 3392|  1.45k|         tmp = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  128|  1.45k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 3393|  1.45k|        char *id = tmp;
 3394|  1.45k|        if (strncmp(id, "pkcs11:", 6) != 0) {
  ------------------
  |  Branch (3394:13): [True: 1.45k, False: 0]
  ------------------
 3395|       |            /* PKCS#11 URIs are using percent-encoding so we can not mix
 3396|       |             * it with ssh expansion of ssh escape characters.
 3397|       |             */
 3398|  1.45k|            tmp = ssh_path_expand_escape(session, id);
 3399|  1.45k|            free(id);
 3400|  1.45k|            if (tmp == NULL) {
  ------------------
  |  Branch (3400:17): [True: 0, False: 1.45k]
  ------------------
 3401|      0|                return -1;
 3402|      0|            }
 3403|  1.45k|        }
 3404|       |
 3405|       |        /* use append to keep the order at first call and use prepend
 3406|       |         * to put anything that comes on the nth calls to the beginning */
 3407|  1.45k|        if (session->opts.exp_flags & SSH_OPT_EXP_FLAG_IDENTITY) {
  ------------------
  |  |  118|  1.45k|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
  |  Branch (3407:13): [True: 0, False: 1.45k]
  ------------------
 3408|      0|            rc = ssh_list_prepend(session->opts.identity, tmp);
 3409|  1.45k|        } else {
 3410|  1.45k|            rc = ssh_list_append(session->opts.identity, tmp);
 3411|  1.45k|        }
 3412|  1.45k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.45k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3412:13): [True: 0, False: 1.45k]
  ------------------
 3413|      0|            free(tmp);
 3414|      0|            return -1;
 3415|      0|        }
 3416|  1.45k|    }
 3417|    486|    session->opts.exp_flags |= SSH_OPT_EXP_FLAG_IDENTITY;
  ------------------
  |  |  118|    486|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
 3418|       |
 3419|       |    /* Allocate on first use (no longer pre-allocated in ssh_new()) */
 3420|    486|    if (session->opts.certificate == NULL) {
  ------------------
  |  Branch (3420:9): [True: 486, False: 0]
  ------------------
 3421|    486|        session->opts.certificate = ssh_list_new();
 3422|    486|        if (session->opts.certificate == NULL) {
  ------------------
  |  Branch (3422:13): [True: 0, False: 486]
  ------------------
 3423|      0|            return -1;
 3424|      0|        }
 3425|    486|    }
 3426|       |
 3427|    486|    for (tmp = ssh_list_pop_head(char *, session->opts.certificate_non_exp);
  ------------------
  |  |  128|    486|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 3428|    486|         tmp != NULL;
  ------------------
  |  Branch (3428:10): [True: 0, False: 486]
  ------------------
 3429|    486|         tmp = ssh_list_pop_head(char *, session->opts.certificate_non_exp)) {
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 3430|      0|        char *id = tmp;
 3431|       |
 3432|      0|        tmp = ssh_path_expand_escape(session, id);
 3433|      0|        free(id);
 3434|      0|        if (tmp == NULL) {
  ------------------
  |  Branch (3434:13): [True: 0, False: 0]
  ------------------
 3435|      0|            return -1;
 3436|      0|        }
 3437|       |
 3438|      0|        rc = ssh_list_append(session->opts.certificate, tmp);
 3439|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3439:13): [True: 0, False: 0]
  ------------------
 3440|      0|            free(tmp);
 3441|      0|            return -1;
 3442|      0|        }
 3443|      0|    }
 3444|       |
 3445|       |#ifdef WITH_GSSAPI
 3446|       |    if (session->opts.gssapi_key_exchange) {
 3447|       |        rc = ssh_gssapi_check_client_config(session);
 3448|       |        if (rc != SSH_OK) {
 3449|       |            SSH_LOG(SSH_LOG_WARN, "Disabled GSSAPI key exchange");
 3450|       |            session->opts.gssapi_key_exchange = false;
 3451|       |        }
 3452|       |    }
 3453|       |#endif
 3454|       |
 3455|    486|    return 0;
 3456|    486|}
options.c:ssh_opt_type_to_opcode:
  520|  4.86k|{
  521|  4.86k|    switch (type) {
  ------------------
  |  Branch (521:13): [True: 4.86k, False: 0]
  ------------------
  522|      0|    case SSH_OPTIONS_PORT:
  ------------------
  |  Branch (522:5): [True: 0, False: 4.86k]
  ------------------
  523|      0|    case SSH_OPTIONS_PORT_STR:
  ------------------
  |  Branch (523:5): [True: 0, False: 4.86k]
  ------------------
  524|      0|        return SOC_PORT;
  525|    486|    case SSH_OPTIONS_USER:
  ------------------
  |  Branch (525:5): [True: 486, False: 4.37k]
  ------------------
  526|    486|        return SOC_USERNAME;
  527|      0|    case SSH_OPTIONS_KNOWNHOSTS:
  ------------------
  |  Branch (527:5): [True: 0, False: 4.86k]
  ------------------
  528|      0|        return SOC_KNOWNHOSTS;
  529|      0|    case SSH_OPTIONS_GLOBAL_KNOWNHOSTS:
  ------------------
  |  Branch (529:5): [True: 0, False: 4.86k]
  ------------------
  530|      0|        return SOC_GLOBALKNOWNHOSTSFILE;
  531|    486|    case SSH_OPTIONS_TIMEOUT:
  ------------------
  |  Branch (531:5): [True: 486, False: 4.37k]
  ------------------
  532|    486|        return SOC_TIMEOUT;
  533|    486|    case SSH_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (533:5): [True: 486, False: 4.37k]
  ------------------
  534|    972|    case SSH_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (534:5): [True: 486, False: 4.37k]
  ------------------
  535|    972|        return SOC_CIPHERS;
  536|      0|    case SSH_OPTIONS_COMPRESSION:
  ------------------
  |  Branch (536:5): [True: 0, False: 4.86k]
  ------------------
  537|      0|    case SSH_OPTIONS_COMPRESSION_C_S:
  ------------------
  |  Branch (537:5): [True: 0, False: 4.86k]
  ------------------
  538|      0|    case SSH_OPTIONS_COMPRESSION_S_C:
  ------------------
  |  Branch (538:5): [True: 0, False: 4.86k]
  ------------------
  539|      0|        return SOC_COMPRESSION;
  540|      0|    case SSH_OPTIONS_PROXYCOMMAND:
  ------------------
  |  Branch (540:5): [True: 0, False: 4.86k]
  ------------------
  541|      0|        return SOC_PROXYCOMMAND;
  542|      0|    case SSH_OPTIONS_PROXYJUMP:
  ------------------
  |  Branch (542:5): [True: 0, False: 4.86k]
  ------------------
  543|      0|        return SOC_PROXYJUMP;
  544|      0|    case SSH_OPTIONS_BINDADDR:
  ------------------
  |  Branch (544:5): [True: 0, False: 4.86k]
  ------------------
  545|      0|        return SOC_BINDADDRESS;
  546|      0|    case SSH_OPTIONS_STRICTHOSTKEYCHECK:
  ------------------
  |  Branch (546:5): [True: 0, False: 4.86k]
  ------------------
  547|      0|        return SOC_STRICTHOSTKEYCHECK;
  548|      0|    case SSH_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (548:5): [True: 0, False: 4.86k]
  ------------------
  549|      0|        return SOC_KEXALGORITHMS;
  550|      0|    case SSH_OPTIONS_HOSTKEYS:
  ------------------
  |  Branch (550:5): [True: 0, False: 4.86k]
  ------------------
  551|      0|        return SOC_HOSTKEYALGORITHMS;
  552|      0|    case SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES:
  ------------------
  |  Branch (552:5): [True: 0, False: 4.86k]
  ------------------
  553|      0|        return SOC_PUBKEYACCEPTEDKEYTYPES;
  554|    486|    case SSH_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (554:5): [True: 486, False: 4.37k]
  ------------------
  555|    972|    case SSH_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (555:5): [True: 486, False: 4.37k]
  ------------------
  556|    972|        return SOC_MACS;
  557|      0|    case SSH_OPTIONS_GSSAPI_SERVER_IDENTITY:
  ------------------
  |  Branch (557:5): [True: 0, False: 4.86k]
  ------------------
  558|      0|        return SOC_GSSAPISERVERIDENTITY;
  559|      0|    case SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY:
  ------------------
  |  Branch (559:5): [True: 0, False: 4.86k]
  ------------------
  560|      0|        return SOC_GSSAPICLIENTIDENTITY;
  561|      0|    case SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS:
  ------------------
  |  Branch (561:5): [True: 0, False: 4.86k]
  ------------------
  562|      0|        return SOC_GSSAPIDELEGATECREDENTIALS;
  563|      0|    case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE:
  ------------------
  |  Branch (563:5): [True: 0, False: 4.86k]
  ------------------
  564|      0|        return SOC_GSSAPIKEYEXCHANGE;
  565|      0|    case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE_ALGS:
  ------------------
  |  Branch (565:5): [True: 0, False: 4.86k]
  ------------------
  566|      0|        return SOC_GSSAPIKEXALGORITHMS;
  567|      0|    case SSH_OPTIONS_PASSWORD_AUTH:
  ------------------
  |  Branch (567:5): [True: 0, False: 4.86k]
  ------------------
  568|      0|        return SOC_PASSWORDAUTHENTICATION;
  569|      0|    case SSH_OPTIONS_PUBKEY_AUTH:
  ------------------
  |  Branch (569:5): [True: 0, False: 4.86k]
  ------------------
  570|      0|        return SOC_PUBKEYAUTHENTICATION;
  571|      0|    case SSH_OPTIONS_KBDINT_AUTH:
  ------------------
  |  Branch (571:5): [True: 0, False: 4.86k]
  ------------------
  572|      0|        return SOC_KBDINTERACTIVEAUTHENTICATION;
  573|      0|    case SSH_OPTIONS_GSSAPI_AUTH:
  ------------------
  |  Branch (573:5): [True: 0, False: 4.86k]
  ------------------
  574|      0|        return SOC_GSSAPIAUTHENTICATION;
  575|      0|    case SSH_OPTIONS_PREFERRED_AUTHENTICATIONS:
  ------------------
  |  Branch (575:5): [True: 0, False: 4.86k]
  ------------------
  576|      0|        return SOC_PREFERRED_AUTHENTICATIONS;
  577|      0|    case SSH_OPTIONS_REKEY_DATA:
  ------------------
  |  Branch (577:5): [True: 0, False: 4.86k]
  ------------------
  578|      0|    case SSH_OPTIONS_REKEY_TIME:
  ------------------
  |  Branch (578:5): [True: 0, False: 4.86k]
  ------------------
  579|      0|        return SOC_REKEYLIMIT;
  580|      0|    case SSH_OPTIONS_RSA_MIN_SIZE:
  ------------------
  |  Branch (580:5): [True: 0, False: 4.86k]
  ------------------
  581|      0|        return SOC_REQUIRED_RSA_SIZE;
  582|      0|    case SSH_OPTIONS_IDENTITY_AGENT:
  ------------------
  |  Branch (582:5): [True: 0, False: 4.86k]
  ------------------
  583|      0|        return SOC_IDENTITYAGENT;
  584|      0|    case SSH_OPTIONS_IDENTITIES_ONLY:
  ------------------
  |  Branch (584:5): [True: 0, False: 4.86k]
  ------------------
  585|      0|        return SOC_IDENTITIESONLY;
  586|      0|    case SSH_OPTIONS_CONTROL_MASTER:
  ------------------
  |  Branch (586:5): [True: 0, False: 4.86k]
  ------------------
  587|      0|        return SOC_CONTROLMASTER;
  588|      0|    case SSH_OPTIONS_CONTROL_PATH:
  ------------------
  |  Branch (588:5): [True: 0, False: 4.86k]
  ------------------
  589|      0|        return SOC_CONTROLPATH;
  590|      0|    case SSH_OPTIONS_ADDRESS_FAMILY:
  ------------------
  |  Branch (590:5): [True: 0, False: 4.86k]
  ------------------
  591|      0|        return SOC_ADDRESSFAMILY;
  592|      0|    case SSH_OPTIONS_SERVER_ALIVE_INTERVAL:
  ------------------
  |  Branch (592:5): [True: 0, False: 4.86k]
  ------------------
  593|      0|        return SOC_SERVERALIVEINTERVAL;
  594|      0|    case SSH_OPTIONS_SERVER_ALIVE_COUNT_MAX:
  ------------------
  |  Branch (594:5): [True: 0, False: 4.86k]
  ------------------
  595|      0|        return SOC_SERVERALIVECOUNTMAX;
  596|      0|    case SSH_OPTIONS_BATCH_MODE:
  ------------------
  |  Branch (596:5): [True: 0, False: 4.86k]
  ------------------
  597|      0|        return SOC_BATCHMODE;
  598|      0|    case SSH_OPTIONS_NUMBER_OF_PASSWORD_PROMPTS:
  ------------------
  |  Branch (598:5): [True: 0, False: 4.86k]
  ------------------
  599|      0|        return SOC_NUMBER_OF_PASSWORD_PROMPTS;
  600|      0|    case SSH_OPTIONS_REQUEST_TTY:
  ------------------
  |  Branch (600:5): [True: 0, False: 4.86k]
  ------------------
  601|      0|        return SOC_REQUEST_TTY;
  602|      0|    case SSH_OPTIONS_ESCAPE_CHAR:
  ------------------
  |  Branch (602:5): [True: 0, False: 4.86k]
  ------------------
  603|      0|        return SOC_ESCAPE_CHAR;
  604|      0|    case SSH_OPTIONS_EXIT_ON_FORWARD_FAILURE:
  ------------------
  |  Branch (604:5): [True: 0, False: 4.86k]
  ------------------
  605|      0|        return SOC_EXIT_ON_FORWARD_FAILURE;
  606|      0|    case SSH_OPTIONS_FORWARD_AGENT:
  ------------------
  |  Branch (606:5): [True: 0, False: 4.86k]
  ------------------
  607|      0|    case SSH_OPTIONS_FORWARD_AGENT_SOCK_PATH:
  ------------------
  |  Branch (607:5): [True: 0, False: 4.86k]
  ------------------
  608|      0|        return SOC_FORWARD_AGENT;
  609|      0|    case SSH_OPTIONS_GATEWAY_PORTS:
  ------------------
  |  Branch (609:5): [True: 0, False: 4.86k]
  ------------------
  610|      0|        return SOC_GATEWAY_PORTS;
  611|       |    /*
  612|       |     * Accumulative options append to a list instead of replacing a value, so
  613|       |     * the "first value wins" precedence between config and the application does
  614|       |     * not apply to them.
  615|       |     */
  616|      0|    case SSH_OPTIONS_IDENTITY:
  ------------------
  |  Branch (616:5): [True: 0, False: 4.86k]
  ------------------
  617|      0|    case SSH_OPTIONS_ADD_IDENTITY:
  ------------------
  |  Branch (617:5): [True: 0, False: 4.86k]
  ------------------
  618|      0|    case SSH_OPTIONS_CERTIFICATE:
  ------------------
  |  Branch (618:5): [True: 0, False: 4.86k]
  ------------------
  619|      0|    case SSH_OPTIONS_PROXYJUMP_CB_LIST_APPEND:
  ------------------
  |  Branch (619:5): [True: 0, False: 4.86k]
  ------------------
  620|      0|    case SSH_OPTIONS_LOCAL_FORWARD:
  ------------------
  |  Branch (620:5): [True: 0, False: 4.86k]
  ------------------
  621|      0|    case SSH_OPTIONS_REMOTE_FORWARD:
  ------------------
  |  Branch (621:5): [True: 0, False: 4.86k]
  ------------------
  622|      0|    case SSH_OPTIONS_SEND_ENV:
  ------------------
  |  Branch (622:5): [True: 0, False: 4.86k]
  ------------------
  623|       |    /*
  624|       |     * SSH_OPTIONS_HOST carries the destination as given by the application,
  625|       |     * which is OpenSSH's "host" (the Host/Match lookup key), not its
  626|       |     * "hostname". Config HostName resolves that key to the real hostname and
  627|       |     * must keep doing so. HostName has its own "first value wins" precedence
  628|       |     * between config entries, enforced independently via seen[SOC_HOSTNAME]
  629|       |     * while parsing the configuration.
  630|       |     */
  631|    486|    case SSH_OPTIONS_HOST:
  ------------------
  |  Branch (631:5): [True: 486, False: 4.37k]
  ------------------
  632|       |    /*
  633|       |     * Operational settings that applications and frameworks routinely set on
  634|       |     * their own, independent of the connection configuration. OpenSSH's config
  635|       |     * parser notably does not let a previously-set value suppress LogLevel, so
  636|       |     * we follow it and leave log verbosity unprotected.
  637|       |     */
  638|    486|    case SSH_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (638:5): [True: 0, False: 4.86k]
  ------------------
  639|    486|    case SSH_OPTIONS_LOG_VERBOSITY_STR:
  ------------------
  |  Branch (639:5): [True: 0, False: 4.86k]
  ------------------
  640|       |    /*
  641|       |     * Options with no OpenSSH ssh_config equivalent (or that are never applied
  642|       |     * from a config file), so there is no config value that could override the
  643|       |     * application's choice.
  644|       |     */
  645|    972|    case SSH_OPTIONS_FD:
  ------------------
  |  Branch (645:5): [True: 486, False: 4.37k]
  ------------------
  646|  1.45k|    case SSH_OPTIONS_SSH_DIR:
  ------------------
  |  Branch (646:5): [True: 486, False: 4.37k]
  ------------------
  647|  1.45k|    case SSH_OPTIONS_SSH1:
  ------------------
  |  Branch (647:5): [True: 0, False: 4.86k]
  ------------------
  648|  1.45k|    case SSH_OPTIONS_SSH2:
  ------------------
  |  Branch (648:5): [True: 0, False: 4.86k]
  ------------------
  649|  1.45k|    case SSH_OPTIONS_TIMEOUT_USEC:
  ------------------
  |  Branch (649:5): [True: 0, False: 4.86k]
  ------------------
  650|  1.45k|    case SSH_OPTIONS_COMPRESSION_LEVEL:
  ------------------
  |  Branch (650:5): [True: 0, False: 4.86k]
  ------------------
  651|  1.45k|    case SSH_OPTIONS_NODELAY:
  ------------------
  |  Branch (651:5): [True: 0, False: 4.86k]
  ------------------
  652|  1.94k|    case SSH_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (652:5): [True: 486, False: 4.37k]
  ------------------
  653|  1.94k|    case SSH_OPTIONS_PKI_CONTEXT:
  ------------------
  |  Branch (653:5): [True: 0, False: 4.86k]
  ------------------
  654|       |    /*
  655|       |     * Getter-only options: ssh_options_set() rejects them, so they never reach
  656|       |     * the marking step. Listed to keep the switch exhaustive.
  657|       |     */
  658|  1.94k|    case SSH_OPTIONS_NEXT_IDENTITY:
  ------------------
  |  Branch (658:5): [True: 0, False: 4.86k]
  ------------------
  659|  1.94k|    case SSH_OPTIONS_NEXT_LOCAL_FORWARD:
  ------------------
  |  Branch (659:5): [True: 0, False: 4.86k]
  ------------------
  660|  1.94k|    case SSH_OPTIONS_NEXT_REMOTE_FORWARD:
  ------------------
  |  Branch (660:5): [True: 0, False: 4.86k]
  ------------------
  661|  1.94k|    case SSH_OPTIONS_NEXT_SEND_ENV:
  ------------------
  |  Branch (661:5): [True: 0, False: 4.86k]
  ------------------
  662|  1.94k|        return SOC_UNKNOWN;
  663|  4.86k|    }
  664|       |
  665|      0|    return SOC_UNKNOWN;
  666|  4.86k|}
options.c:ssh_host_requires_lowercase:
 3194|    486|static bool ssh_host_requires_lowercase(const char *host) {
 3195|    486|    if (strchr(host, '%') != NULL || strchr(host, ':') != NULL ||
  ------------------
  |  Branch (3195:9): [True: 0, False: 486]
  |  Branch (3195:38): [True: 0, False: 486]
  ------------------
 3196|    486|        strspn(host, "0123456789.") == strlen(host)) {
  ------------------
  |  Branch (3196:9): [True: 486, False: 0]
  ------------------
 3197|    486|        return false;
 3198|    486|    }
 3199|      0|    return !ssh_is_ipaddr(host);
 3200|    486|}

ssh_packet_get_current_crypto:
 1159|  97.6k|{
 1160|  97.6k|    struct ssh_crypto_struct *crypto = NULL;
 1161|       |
 1162|  97.6k|    if (session == NULL) {
  ------------------
  |  Branch (1162:9): [True: 0, False: 97.6k]
  ------------------
 1163|      0|        return NULL;
 1164|      0|    }
 1165|       |
 1166|  97.6k|    if (session->current_crypto != NULL &&
  ------------------
  |  Branch (1166:9): [True: 0, False: 97.6k]
  ------------------
 1167|      0|        session->current_crypto->used & direction) {
  ------------------
  |  Branch (1167:9): [True: 0, False: 0]
  ------------------
 1168|      0|        crypto = session->current_crypto;
 1169|  97.6k|    } else if (session->next_crypto != NULL &&
  ------------------
  |  Branch (1169:16): [True: 97.6k, False: 0]
  ------------------
 1170|  97.6k|               session->next_crypto->used & direction) {
  ------------------
  |  Branch (1170:16): [True: 1.07k, False: 96.6k]
  ------------------
 1171|  1.07k|        crypto = session->next_crypto;
 1172|  96.6k|    } else {
 1173|  96.6k|        return NULL;
 1174|  96.6k|    }
 1175|       |
 1176|  1.07k|    switch (direction) {
  ------------------
  |  Branch (1176:13): [True: 1.07k, False: 0]
  ------------------
 1177|      0|    case SSH_DIRECTION_IN:
  ------------------
  |  Branch (1177:5): [True: 0, False: 1.07k]
  ------------------
 1178|      0|        if (crypto->in_cipher != NULL) {
  ------------------
  |  Branch (1178:13): [True: 0, False: 0]
  ------------------
 1179|      0|            return crypto;
 1180|      0|        }
 1181|      0|        break;
 1182|  1.07k|    case SSH_DIRECTION_OUT:
  ------------------
  |  Branch (1182:5): [True: 1.07k, False: 0]
  ------------------
 1183|  1.07k|        if (crypto->out_cipher != NULL) {
  ------------------
  |  Branch (1183:13): [True: 1.07k, False: 0]
  ------------------
 1184|  1.07k|            return crypto;
 1185|  1.07k|        }
 1186|      0|        break;
 1187|      0|    case SSH_DIRECTION_BOTH:
  ------------------
  |  Branch (1187:5): [True: 0, False: 1.07k]
  ------------------
 1188|      0|        if (crypto->in_cipher != NULL &&
  ------------------
  |  Branch (1188:13): [True: 0, False: 0]
  ------------------
 1189|      0|            crypto->out_cipher != NULL) {
  ------------------
  |  Branch (1189:13): [True: 0, False: 0]
  ------------------
 1190|      0|            return crypto;
 1191|      0|        }
 1192|  1.07k|    }
 1193|       |
 1194|      0|    return NULL;
 1195|  1.07k|}
ssh_packet_socket_callback:
 1287|  31.2k|{
 1288|  31.2k|    ssh_session session = (ssh_session)user;
 1289|  31.2k|    uint32_t blocksize = 8;
 1290|  31.2k|    uint32_t lenfield_blocksize = 8;
 1291|  31.2k|    size_t current_macsize = 0;
 1292|  31.2k|    uint8_t *ptr = NULL;
 1293|  31.2k|    ssize_t to_be_read;
 1294|  31.2k|    int rc;
 1295|  31.2k|    uint8_t *cleartext_packet = NULL;
 1296|  31.2k|    uint8_t *packet_second_block = NULL;
 1297|  31.2k|    uint8_t *mac = NULL;
 1298|  31.2k|    size_t packet_remaining, packet_offset;
 1299|  31.2k|    uint32_t packet_len, compsize, payloadsize;
 1300|  31.2k|    uint8_t padding;
 1301|  31.2k|    size_t processed = 0; /* number of bytes processed from the callback */
 1302|  31.2k|    enum ssh_packet_filter_result_e filter_result;
 1303|  31.2k|    struct ssh_crypto_struct *crypto = NULL;
 1304|  31.2k|    bool etm = false;
 1305|  31.2k|    uint32_t etm_packet_offset = 0;
 1306|  31.2k|    bool ok;
 1307|       |
 1308|  31.2k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
 1309|  31.2k|    if (crypto != NULL) {
  ------------------
  |  Branch (1309:9): [True: 0, False: 31.2k]
  ------------------
 1310|      0|        current_macsize = hmac_digest_len(crypto->in_hmac);
 1311|      0|        blocksize = crypto->in_cipher->blocksize;
 1312|      0|        lenfield_blocksize = crypto->in_cipher->lenfield_blocksize;
 1313|      0|        etm = crypto->in_hmac_etm;
 1314|      0|    }
 1315|       |
 1316|  31.2k|    if (etm) {
  ------------------
  |  Branch (1316:9): [True: 0, False: 31.2k]
  ------------------
 1317|       |        /* In EtM mode packet size is unencrypted. This means
 1318|       |         * we need to use this offset and set the block size
 1319|       |         * that is part of the encrypted part to 0.
 1320|       |         */
 1321|      0|        etm_packet_offset = sizeof(uint32_t);
 1322|      0|        lenfield_blocksize = 0;
 1323|  31.2k|    } else if (lenfield_blocksize == 0) {
  ------------------
  |  Branch (1323:16): [True: 0, False: 31.2k]
  ------------------
 1324|      0|        lenfield_blocksize = blocksize;
 1325|      0|    }
 1326|  31.2k|    if (data == NULL) {
  ------------------
  |  Branch (1326:9): [True: 0, False: 31.2k]
  ------------------
 1327|      0|        goto error;
 1328|      0|    }
 1329|       |
 1330|  31.2k|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (1330:9): [True: 333, False: 30.8k]
  ------------------
 1331|    333|        goto error;
 1332|    333|    }
 1333|       |#ifdef DEBUG_PACKET
 1334|       |    SSH_LOG(SSH_LOG_PACKET,
 1335|       |            "rcv packet cb (len=%zu, state=%s)",
 1336|       |            receivedlen,
 1337|       |            session->packet_state == PACKET_STATE_INIT ?
 1338|       |                "INIT" :
 1339|       |                session->packet_state == PACKET_STATE_SIZEREAD ?
 1340|       |                    "SIZE_READ" :
 1341|       |                    session->packet_state == PACKET_STATE_PROCESSING ?
 1342|       |                    "PROCESSING" : "unknown");
 1343|       |#endif
 1344|  30.8k|    switch (session->packet_state) {
  ------------------
  |  Branch (1344:13): [True: 30.8k, False: 0]
  ------------------
 1345|  30.5k|        case PACKET_STATE_INIT:
  ------------------
  |  Branch (1345:9): [True: 30.5k, False: 327]
  ------------------
 1346|  30.5k|            if (receivedlen < lenfield_blocksize + etm_packet_offset) {
  ------------------
  |  Branch (1346:17): [True: 123, False: 30.4k]
  ------------------
 1347|       |                /*
 1348|       |                 * We didn't receive enough data to read either at least one
 1349|       |                 * block size or the unencrypted length in EtM mode.
 1350|       |                 */
 1351|       |#ifdef DEBUG_PACKET
 1352|       |                SSH_LOG(SSH_LOG_PACKET,
 1353|       |                        "Waiting for more data (%zu < %u)",
 1354|       |                        receivedlen,
 1355|       |                        lenfield_blocksize);
 1356|       |#endif
 1357|    123|                return 0;
 1358|    123|            }
 1359|       |
 1360|  30.4k|            session->in_packet = (struct packet_struct) {
 1361|  30.4k|                .type = 0,
 1362|  30.4k|            };
 1363|       |
 1364|  30.4k|            if (session->in_buffer) {
  ------------------
  |  Branch (1364:17): [True: 30.4k, False: 0]
  ------------------
 1365|  30.4k|                rc = ssh_buffer_reinit(session->in_buffer);
 1366|  30.4k|                if (rc < 0) {
  ------------------
  |  Branch (1366:21): [True: 0, False: 30.4k]
  ------------------
 1367|      0|                    goto error;
 1368|      0|                }
 1369|  30.4k|            } else {
 1370|      0|                session->in_buffer = ssh_buffer_new();
 1371|      0|                if (session->in_buffer == NULL) {
  ------------------
  |  Branch (1371:21): [True: 0, False: 0]
  ------------------
 1372|      0|                    goto error;
 1373|      0|                }
 1374|      0|            }
 1375|       |
 1376|  30.4k|            if (!etm) {
  ------------------
  |  Branch (1376:17): [True: 30.4k, False: 0]
  ------------------
 1377|  30.4k|                ptr = ssh_buffer_allocate(session->in_buffer,
 1378|  30.4k|                                          lenfield_blocksize);
 1379|  30.4k|                if (ptr == NULL) {
  ------------------
  |  Branch (1379:21): [True: 0, False: 30.4k]
  ------------------
 1380|      0|                    goto error;
 1381|      0|                }
 1382|  30.4k|                packet_len = ssh_packet_decrypt_len(session, ptr,
 1383|  30.4k|                                                    (uint8_t *)data);
 1384|  30.4k|                to_be_read = packet_len - lenfield_blocksize + sizeof(uint32_t);
 1385|  30.4k|            } else {
 1386|       |                /* Length is unencrypted in case of Encrypt-then-MAC */
 1387|      0|                packet_len = PULL_BE_U32(data, 0);
  ------------------
  |  |   75|      0|    ((((uint32_t)PULL_BE_U16(data, pos)) << 16) | (uint32_t)(PULL_BE_U16(data, (pos) + 2)))
  |  |  ------------------
  |  |  |  |   72|      0|    ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|      0|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|      0|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|      0|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|      0|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   ((((uint32_t)PULL_BE_U16(data, pos)) << 16) | (uint32_t)(PULL_BE_U16(data, (pos) + 2)))
  |  |  ------------------
  |  |  |  |   72|      0|    ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|      0|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|      0|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   ((((uint16_t)(PULL_BE_U8(data, pos))) << 8) | (uint16_t)PULL_BE_U8(data, (pos) + 1))
  |  |  |  |  ------------------
  |  |  |  |  |  |   69|      0|    (_DATA_BYTE_CONST(data, pos))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   28|      0|    ((uint8_t)(((const uint8_t *)(data))[(pos)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1388|      0|                to_be_read = packet_len - etm_packet_offset;
 1389|      0|            }
 1390|       |
 1391|  30.4k|            processed += lenfield_blocksize + etm_packet_offset;
 1392|  30.4k|            if (packet_len > MAX_PACKET_LEN) {
  ------------------
  |  |  216|  30.4k|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (1392:17): [True: 78, False: 30.3k]
  ------------------
 1393|     78|                ssh_set_error(session,
  ------------------
  |  |  313|     78|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1394|     78|                              SSH_FATAL,
 1395|     78|                              "read_packet(): Packet len too high(%" PRIu32 " %.4" PRIx32 ")",
 1396|     78|                              packet_len, packet_len);
 1397|     78|                goto error;
 1398|     78|            }
 1399|  30.3k|            if (to_be_read < 0) {
  ------------------
  |  Branch (1399:17): [True: 0, False: 30.3k]
  ------------------
 1400|       |                /* remote sshd sends invalid sizes? */
 1401|      0|                ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1402|      0|                              SSH_FATAL,
 1403|      0|                              "Given numbers of bytes left to be read < 0 (%zd)!",
 1404|      0|                              to_be_read);
 1405|      0|                goto error;
 1406|      0|            }
 1407|       |
 1408|  30.3k|            session->in_packet.len = packet_len;
 1409|  30.3k|            session->packet_state = PACKET_STATE_SIZEREAD;
 1410|  30.3k|            FALL_THROUGH;
  ------------------
  |  |  496|  30.3k|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1411|  30.6k|        case PACKET_STATE_SIZEREAD:
  ------------------
  |  Branch (1411:9): [True: 327, False: 30.5k]
  ------------------
 1412|  30.6k|            packet_len = session->in_packet.len;
 1413|  30.6k|            packet_offset = processed = lenfield_blocksize + etm_packet_offset;
 1414|  30.6k|            to_be_read = packet_len + sizeof(uint32_t) + current_macsize;
 1415|       |            /* if to_be_read is zero, the whole packet was blocksize bytes. */
 1416|  30.6k|            if (to_be_read != 0) {
  ------------------
  |  Branch (1416:17): [True: 30.6k, False: 0]
  ------------------
 1417|  30.6k|                if (receivedlen < (unsigned long)to_be_read) {
  ------------------
  |  Branch (1417:21): [True: 370, False: 30.3k]
  ------------------
 1418|       |                    /* give up, not enough data in buffer */
 1419|    370|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|    370|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1420|    370|                            "packet: partial packet (read len) "
 1421|    370|                            "[len=%" PRIu32 ", receivedlen=%zu, to_be_read=%zd]",
 1422|    370|                            packet_len,
 1423|    370|                            receivedlen,
 1424|    370|                            to_be_read);
 1425|    370|                    return 0;
 1426|    370|                }
 1427|       |
 1428|  30.3k|                packet_second_block = (uint8_t*)data + packet_offset;
 1429|  30.3k|                processed = to_be_read - current_macsize;
 1430|  30.3k|            }
 1431|       |
 1432|  30.3k|            if (packet_offset - sizeof(uint32_t) > (size_t)packet_len) {
  ------------------
  |  Branch (1432:17): [True: 6, False: 30.3k]
  ------------------
 1433|      6|                ssh_set_error(session,
  ------------------
  |  |  313|      6|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1434|      6|                              SSH_FATAL,
 1435|      6|                              "Invalid packet length %" PRIu32 ", required %zu",
 1436|      6|                              packet_len,
 1437|      6|                              packet_offset + sizeof(uint32_t));
 1438|      6|                goto error;
 1439|      6|            }
 1440|       |
 1441|       |            /* remaining encrypted bytes from the packet, MAC not included */
 1442|  30.3k|            packet_remaining = packet_len - (packet_offset - sizeof(uint32_t));
 1443|  30.3k|            cleartext_packet = ssh_buffer_allocate(session->in_buffer,
 1444|  30.3k|                                                   (uint32_t)packet_remaining);
 1445|  30.3k|            if (cleartext_packet == NULL) {
  ------------------
  |  Branch (1445:17): [True: 0, False: 30.3k]
  ------------------
 1446|      0|                goto error;
 1447|      0|            }
 1448|       |
 1449|  30.3k|            if (packet_second_block != NULL) {
  ------------------
  |  Branch (1449:17): [True: 30.3k, False: 0]
  ------------------
 1450|  30.3k|                if (crypto != NULL) {
  ------------------
  |  Branch (1450:21): [True: 0, False: 30.3k]
  ------------------
 1451|      0|                    mac = packet_second_block + packet_remaining;
 1452|       |
 1453|      0|                    if (crypto->in_hmac != SSH_HMAC_NONE && etm) {
  ------------------
  |  Branch (1453:25): [True: 0, False: 0]
  |  Branch (1453:61): [True: 0, False: 0]
  ------------------
 1454|      0|                        rc = ssh_packet_hmac_verify(session,
 1455|      0|                                                    data,
 1456|      0|                                                    processed,
 1457|      0|                                                    mac,
 1458|      0|                                                    crypto->in_hmac);
 1459|      0|                        if (rc < 0) {
  ------------------
  |  Branch (1459:29): [True: 0, False: 0]
  ------------------
 1460|      0|                            ssh_set_error(session, SSH_FATAL, "HMAC error");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1461|      0|                            goto error;
 1462|      0|                        }
 1463|      0|                    }
 1464|       |                    /*
 1465|       |                     * Decrypt the packet. In case of EtM mode, the length is
 1466|       |                     * already known as it's unencrypted. In the other case,
 1467|       |                     * lenfield_blocksize bytes already have been decrypted.
 1468|       |                     */
 1469|      0|                    if (packet_remaining > 0) {
  ------------------
  |  Branch (1469:25): [True: 0, False: 0]
  ------------------
 1470|      0|                        rc = ssh_packet_decrypt(session,
 1471|      0|                                                cleartext_packet,
 1472|      0|                                                (uint8_t *)data,
 1473|      0|                                                packet_offset,
 1474|      0|                                                processed - packet_offset);
 1475|      0|                        if (rc < 0) {
  ------------------
  |  Branch (1475:29): [True: 0, False: 0]
  ------------------
 1476|      0|                            ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1477|      0|                                          SSH_FATAL,
 1478|      0|                                          "Decryption error");
 1479|      0|                            goto error;
 1480|      0|                        }
 1481|      0|                    }
 1482|       |
 1483|      0|                    if (crypto->in_hmac != SSH_HMAC_NONE && !etm) {
  ------------------
  |  Branch (1483:25): [True: 0, False: 0]
  |  Branch (1483:61): [True: 0, False: 0]
  ------------------
 1484|      0|                        ssh_buffer in = session->in_buffer;
 1485|      0|                        rc = ssh_packet_hmac_verify(session,
 1486|      0|                                                    ssh_buffer_get(in),
 1487|      0|                                                    ssh_buffer_get_len(in),
 1488|      0|                                                    mac,
 1489|      0|                                                    crypto->in_hmac);
 1490|      0|                        if (rc < 0) {
  ------------------
  |  Branch (1490:29): [True: 0, False: 0]
  ------------------
 1491|      0|                            ssh_set_error(session, SSH_FATAL, "HMAC error");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1492|      0|                            goto error;
 1493|      0|                        }
 1494|      0|                    }
 1495|      0|                    processed += current_macsize;
 1496|  30.3k|                } else {
 1497|  30.3k|                    memcpy(cleartext_packet,
 1498|  30.3k|                           packet_second_block,
 1499|  30.3k|                           packet_remaining);
 1500|  30.3k|                }
 1501|  30.3k|            }
 1502|       |
 1503|  30.3k|#ifdef WITH_PCAP
 1504|  30.3k|            if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1504:17): [True: 0, False: 30.3k]
  ------------------
 1505|      0|                ssh_pcap_context_write(session->pcap_ctx,
 1506|      0|                                       SSH_PCAP_DIR_IN,
 1507|      0|                                       ssh_buffer_get(session->in_buffer),
 1508|      0|                                       ssh_buffer_get_len(session->in_buffer),
 1509|      0|                                       ssh_buffer_get_len(session->in_buffer));
 1510|      0|            }
 1511|  30.3k|#endif
 1512|       |
 1513|  30.3k|            if (!etm) {
  ------------------
  |  Branch (1513:17): [True: 30.3k, False: 0]
  ------------------
 1514|       |                /* skip the size field which has been processed before */
 1515|  30.3k|                ssh_buffer_pass_bytes(session->in_buffer, sizeof(uint32_t));
 1516|  30.3k|            }
 1517|       |
 1518|  30.3k|            rc = ssh_buffer_get_u8(session->in_buffer, &padding);
 1519|  30.3k|            if (rc == 0) {
  ------------------
  |  Branch (1519:17): [True: 0, False: 30.3k]
  ------------------
 1520|      0|                ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1521|      0|                              SSH_FATAL,
 1522|      0|                              "Packet too short to read padding");
 1523|      0|                goto error;
 1524|      0|            }
 1525|       |
 1526|  30.3k|            if (padding > ssh_buffer_get_len(session->in_buffer)) {
  ------------------
  |  Branch (1526:17): [True: 3, False: 30.2k]
  ------------------
 1527|      3|                ssh_set_error(session,
  ------------------
  |  |  313|      3|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1528|      3|                              SSH_FATAL,
 1529|      3|                              "Invalid padding: %d (%" PRIu32 " left)",
 1530|      3|                              padding,
 1531|      3|                              ssh_buffer_get_len(session->in_buffer));
 1532|      3|                goto error;
 1533|      3|            }
 1534|  30.2k|            ssh_buffer_pass_bytes_end(session->in_buffer, padding);
 1535|  30.2k|            compsize = ssh_buffer_get_len(session->in_buffer);
 1536|       |
 1537|  30.2k|            if (crypto && crypto->do_compress_in &&
  ------------------
  |  Branch (1537:17): [True: 0, False: 30.2k]
  |  Branch (1537:27): [True: 0, False: 0]
  ------------------
 1538|      0|                ssh_buffer_get_len(session->in_buffer) > 0) {
  ------------------
  |  Branch (1538:17): [True: 0, False: 0]
  ------------------
 1539|      0|                rc = decompress_buffer(session, session->in_buffer,
 1540|      0|                                       MAX_PACKET_LEN);
  ------------------
  |  |  216|      0|#define MAX_PACKET_LEN 262144
  ------------------
 1541|      0|                if (rc < 0) {
  ------------------
  |  Branch (1541:21): [True: 0, False: 0]
  ------------------
 1542|      0|                    goto error;
 1543|      0|                }
 1544|      0|            }
 1545|  30.2k|            payloadsize = ssh_buffer_get_len(session->in_buffer);
 1546|  30.2k|            if (session->recv_seq == UINT32_MAX) {
  ------------------
  |  Branch (1546:17): [True: 0, False: 30.2k]
  ------------------
 1547|       |                /* Overflowing sequence numbers is always fishy */
 1548|      0|                if (crypto == NULL) {
  ------------------
  |  Branch (1548:21): [True: 0, False: 0]
  ------------------
 1549|       |                    /* don't allow sequence number overflow when unencrypted */
 1550|      0|                    ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1551|      0|                                  SSH_FATAL,
 1552|      0|                                  "Incoming sequence number overflow");
 1553|      0|                    goto error;
 1554|      0|                } else {
 1555|      0|                    SSH_LOG(SSH_LOG_WARNING,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1556|      0|                            "Incoming sequence number overflow");
 1557|      0|                }
 1558|      0|            }
 1559|  30.2k|            session->recv_seq++;
 1560|  30.2k|            if (crypto != NULL) {
  ------------------
  |  Branch (1560:17): [True: 0, False: 30.2k]
  ------------------
 1561|      0|                struct ssh_cipher_struct *cipher = NULL;
 1562|       |
 1563|      0|                cipher = crypto->in_cipher;
 1564|      0|                cipher->packets++;
 1565|      0|                cipher->blocks += payloadsize / cipher->blocksize;
 1566|      0|            }
 1567|  30.2k|            if (session->raw_counter != NULL) {
  ------------------
  |  Branch (1567:17): [True: 0, False: 30.2k]
  ------------------
 1568|      0|                session->raw_counter->in_bytes += payloadsize;
 1569|      0|                session->raw_counter->in_packets++;
 1570|      0|            }
 1571|       |
 1572|       |            /*
 1573|       |             * We don't want to rewrite a new packet while still executing the
 1574|       |             * packet callbacks
 1575|       |             */
 1576|  30.2k|            session->packet_state = PACKET_STATE_PROCESSING;
 1577|  30.2k|            ssh_packet_parse_type(session);
 1578|  30.2k|            SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|  30.2k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1579|  30.2k|                    "packet: read type %hhd [len=%" PRIu32 ",padding=%hhd,"
 1580|  30.2k|                    "comp=%" PRIu32 ",payload=%" PRIu32 "]",
 1581|  30.2k|                    session->in_packet.type, packet_len, padding, compsize,
 1582|  30.2k|                    payloadsize);
 1583|  30.2k|            if (crypto == NULL) {
  ------------------
  |  Branch (1583:17): [True: 30.2k, False: 0]
  ------------------
 1584|       |                /* In strict kex, only a few packets are allowed. Taint the session
 1585|       |                 * if we received packets that are normally allowed but to be
 1586|       |                 * refused if we are in strict kex when KEX is over.
 1587|       |                 */
 1588|  30.2k|                uint8_t type = session->in_packet.type;
 1589|       |
 1590|  30.2k|                if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   12|  60.5k|#define SSH2_MSG_KEXINIT	 20
  ------------------
                              if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   13|  60.3k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (1590:21): [True: 30.0k, False: 290]
  |  Branch (1590:49): [True: 29.9k, False: 15]
  ------------------
 1591|  29.9k|                    (type < SSH2_MSG_KEXDH_INIT ||
  ------------------
  |  |   15|  59.9k|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (1591:22): [True: 20.4k, False: 9.53k]
  ------------------
 1592|  29.5k|                     type > SSH2_MSG_KEX_DH_GEX_REQUEST)) {
  ------------------
  |  |   26|  9.53k|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (1592:22): [True: 9.07k, False: 457]
  ------------------
 1593|  29.5k|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|  29.5k|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1594|  29.5k|                }
 1595|  30.2k|            }
 1596|       |            /* Check if the packet is expected */
 1597|  30.2k|            filter_result = ssh_packet_incoming_filter(session);
 1598|       |
 1599|  30.2k|            switch (filter_result) {
  ------------------
  |  Branch (1599:21): [True: 30.2k, False: 0]
  ------------------
 1600|  13.7k|            case SSH_PACKET_ALLOWED:
  ------------------
  |  Branch (1600:13): [True: 13.7k, False: 16.5k]
  ------------------
 1601|       |                /* Execute callbacks */
 1602|  13.7k|                ssh_packet_process(session, session->in_packet.type);
 1603|  13.7k|                break;
 1604|     27|            case SSH_PACKET_DENIED:
  ------------------
  |  Branch (1604:13): [True: 27, False: 30.2k]
  ------------------
 1605|     27|                ssh_set_error(session,
  ------------------
  |  |  313|     27|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1606|     27|                              SSH_FATAL,
 1607|     27|                              "Packet filter: rejected packet (type %d)",
 1608|     27|                              session->in_packet.type);
 1609|     27|                goto error;
 1610|  16.5k|            case SSH_PACKET_UNKNOWN:
  ------------------
  |  Branch (1610:13): [True: 16.5k, False: 13.7k]
  ------------------
 1611|  16.5k|                if (crypto == NULL) {
  ------------------
  |  Branch (1611:21): [True: 16.5k, False: 0]
  ------------------
 1612|  16.5k|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|  16.5k|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1613|  16.5k|                }
 1614|  16.5k|                ssh_packet_send_unimplemented(session, session->recv_seq - 1);
 1615|  16.5k|                break;
 1616|  30.2k|            }
 1617|       |
 1618|  30.2k|            session->packet_state = PACKET_STATE_INIT;
 1619|  30.2k|            if (processed < receivedlen) {
  ------------------
  |  Branch (1619:17): [True: 30.2k, False: 54]
  ------------------
 1620|  30.2k|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|  30.2k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1621|  30.2k|                        "packet: %zu bytes still remaining in socket buffer "
 1622|  30.2k|                        "after processing",
 1623|  30.2k|                        receivedlen-processed);
 1624|  30.2k|            }
 1625|       |
 1626|  30.2k|            ok = ssh_packet_need_rekey(session, 0);
 1627|  30.2k|            if (ok) {
  ------------------
  |  Branch (1627:17): [True: 0, False: 30.2k]
  ------------------
 1628|      0|                SSH_LOG(SSH_LOG_PACKET, "Incoming packet triggered rekey");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1629|      0|                rc = ssh_send_rekex(session);
 1630|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1630:21): [True: 0, False: 0]
  ------------------
 1631|      0|                    SSH_LOG(SSH_LOG_PACKET, "Rekey failed: rc = %d", rc);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1632|      0|                    goto error;
 1633|      0|                }
 1634|      0|            }
 1635|       |
 1636|  30.2k|            return processed;
 1637|      0|        case PACKET_STATE_PROCESSING:
  ------------------
  |  Branch (1637:9): [True: 0, False: 30.8k]
  ------------------
 1638|      0|            SSH_LOG(SSH_LOG_PACKET, "Nested packet processing. Delaying.");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1639|      0|            return 0;
 1640|  30.8k|    }
 1641|       |
 1642|      0|    ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1643|      0|                  SSH_FATAL,
 1644|      0|                  "Invalid state into packet_read2(): %d",
 1645|      0|                  session->packet_state);
 1646|       |
 1647|    447|error:
 1648|    447|    session->session_state = SSH_SESSION_STATE_ERROR;
 1649|    447|    SSH_LOG(SSH_LOG_PACKET, "Packet: processed %zu bytes", processed);
  ------------------
  |  |  283|    447|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1650|    447|    return processed;
 1651|      0|}
ssh_packet_register_socket_callback:
 1678|    442|{
 1679|    442|    struct ssh_socket_callbacks_struct *callbacks = &session->socket_callbacks;
 1680|       |
 1681|    442|    callbacks->data = ssh_packet_socket_callback;
 1682|       |    callbacks->connected = NULL;
 1683|    442|    callbacks->controlflow = ssh_packet_socket_controlflow_callback;
 1684|    442|    callbacks->userdata = session;
 1685|    442|    ssh_socket_set_callbacks(s, callbacks);
 1686|    442|}
ssh_packet_set_callbacks:
 1693|    648|{
 1694|    648|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1694:9): [True: 442, False: 206]
  ------------------
 1695|    442|        session->packet_callbacks = ssh_list_new();
 1696|    442|        if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1696:13): [True: 0, False: 442]
  ------------------
 1697|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1698|      0|            return;
 1699|      0|        }
 1700|    442|    }
 1701|    648|    ssh_list_append(session->packet_callbacks, callbacks);
 1702|    648|}
ssh_packet_remove_callbacks:
 1709|    145|{
 1710|    145|    struct ssh_iterator *it = NULL;
 1711|       |
 1712|    145|    it = ssh_list_find(session->packet_callbacks, callbacks);
 1713|    145|    if (it != NULL) {
  ------------------
  |  Branch (1713:9): [True: 145, False: 0]
  ------------------
 1714|    145|        ssh_list_remove(session->packet_callbacks, it);
 1715|    145|    }
 1716|    145|}
ssh_packet_set_default_callbacks:
 1722|    442|{
 1723|    442|    struct ssh_packet_callbacks_struct *c = &session->default_packet_callbacks;
 1724|       |
 1725|    442|    c->start = 1;
 1726|    442|    c->n_callbacks = sizeof(default_packet_handlers) / sizeof(ssh_packet_callback);
 1727|    442|    c->user = session;
 1728|    442|    c->callbacks = default_packet_handlers;
 1729|    442|    ssh_packet_set_callbacks(session, c);
 1730|    442|}
ssh_packet_process:
 1737|  13.7k|{
 1738|  13.7k|    struct ssh_iterator *i = NULL;
 1739|  13.7k|    int rc = SSH_PACKET_NOT_USED;
  ------------------
  |  |  641|  13.7k|#define SSH_PACKET_NOT_USED 2
  ------------------
 1740|  13.7k|    ssh_packet_callbacks cb;
 1741|       |
 1742|  13.7k|    SSH_LOG(SSH_LOG_PACKET, "Dispatching handler for packet type %d", type);
  ------------------
  |  |  283|  13.7k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1743|  13.7k|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1743:9): [True: 0, False: 13.7k]
  ------------------
 1744|      0|        SSH_LOG(SSH_LOG_RARE, "Packet callback is not initialized !");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1745|      0|        return;
 1746|      0|    }
 1747|       |
 1748|  13.7k|    i = ssh_list_get_iterator(session->packet_callbacks);
 1749|  14.4k|    while (i != NULL) {
  ------------------
  |  Branch (1749:12): [True: 14.1k, False: 301]
  ------------------
 1750|  14.1k|        cb = ssh_iterator_value(ssh_packet_callbacks, i);
  ------------------
  |  |  120|  14.1k|  ((type)((iterator)->data))
  ------------------
 1751|  14.1k|        i = i->next;
 1752|       |
 1753|  14.1k|        if (!cb) {
  ------------------
  |  Branch (1753:13): [True: 0, False: 14.1k]
  ------------------
 1754|      0|            continue;
 1755|      0|        }
 1756|       |
 1757|  14.1k|        if (cb->start > type) {
  ------------------
  |  Branch (1757:13): [True: 0, False: 14.1k]
  ------------------
 1758|      0|            continue;
 1759|      0|        }
 1760|       |
 1761|  14.1k|        if (cb->start + cb->n_callbacks <= type) {
  ------------------
  |  Branch (1761:13): [True: 301, False: 13.8k]
  ------------------
 1762|    301|            continue;
 1763|    301|        }
 1764|       |
 1765|  13.8k|        if (cb->callbacks[type - cb->start] == NULL) {
  ------------------
  |  Branch (1765:13): [True: 453, False: 13.4k]
  ------------------
 1766|    453|            continue;
 1767|    453|        }
 1768|       |
 1769|  13.4k|        rc = cb->callbacks[type - cb->start](session, type, session->in_buffer,
 1770|  13.4k|                                             cb->user);
 1771|  13.4k|        if (rc == SSH_PACKET_USED) {
  ------------------
  |  |  638|  13.4k|#define SSH_PACKET_USED 1
  ------------------
  |  Branch (1771:13): [True: 13.4k, False: 0]
  ------------------
 1772|  13.4k|            break;
 1773|  13.4k|        }
 1774|  13.4k|    }
 1775|       |
 1776|  13.7k|    if (rc == SSH_PACKET_NOT_USED) {
  ------------------
  |  |  641|  13.7k|#define SSH_PACKET_NOT_USED 2
  ------------------
  |  Branch (1776:9): [True: 301, False: 13.4k]
  ------------------
 1777|    301|        SSH_LOG(SSH_LOG_RARE, "Couldn't do anything with packet type %d", type);
  ------------------
  |  |  283|    301|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1778|    301|        rc = ssh_packet_send_unimplemented(session, session->recv_seq - 1);
 1779|    301|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    301|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1779:13): [True: 0, False: 301]
  ------------------
 1780|      0|            SSH_LOG(SSH_LOG_RARE, "Failed to send unimplemented: %s",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1781|      0|                    ssh_get_error(session));
 1782|      0|        }
 1783|    301|        if (session->current_crypto == NULL) {
  ------------------
  |  Branch (1783:13): [True: 301, False: 0]
  ------------------
 1784|    301|            session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|    301|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1785|    301|        }
 1786|    301|    }
 1787|  13.7k|}
ssh_packet_send_newkeys:
 1795|     33|{
 1796|     33|    int rc;
 1797|       |
 1798|       |    /* Send the MSG_NEWKEYS */
 1799|     33|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS);
  ------------------
  |  |   13|     33|#define SSH2_MSG_NEWKEYS 21
  ------------------
 1800|     33|    if (rc < 0) {
  ------------------
  |  Branch (1800:9): [True: 0, False: 33]
  ------------------
 1801|      0|        return rc;
 1802|      0|    }
 1803|       |
 1804|     33|    rc = ssh_packet_send(session);
 1805|     33|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     33|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1805:9): [True: 0, False: 33]
  ------------------
 1806|      0|        return rc;
 1807|      0|    }
 1808|     33|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_NEWKEYS sent");
  ------------------
  |  |  283|     33|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1809|     33|    return rc;
 1810|     33|}
ssh_packet_send_unimplemented:
 1818|  16.8k|int ssh_packet_send_unimplemented(ssh_session session, uint32_t seqnum){
 1819|  16.8k|    int rc;
 1820|       |
 1821|  16.8k|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|  16.8k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|  16.8k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|  16.8k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|  16.8k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|  16.8k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|  16.8k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  16.8k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1822|  16.8k|                         "bd",
 1823|  16.8k|                         SSH2_MSG_UNIMPLEMENTED,
 1824|  16.8k|                         seqnum);
 1825|  16.8k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  16.8k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1825:9): [True: 0, False: 16.8k]
  ------------------
 1826|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1827|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1828|      0|    }
 1829|  16.8k|    rc = ssh_packet_send(session);
 1830|       |
 1831|  16.8k|    return rc;
 1832|  16.8k|}
ssh_packet_unimplemented:
 1837|    153|SSH_PACKET_CALLBACK(ssh_packet_unimplemented){
 1838|    153|    uint32_t seq;
 1839|    153|    int rc;
 1840|       |
 1841|    153|    (void)session; /* unused */
 1842|    153|    (void)type;
 1843|    153|    (void)user;
 1844|       |
 1845|    153|    rc = ssh_buffer_unpack(packet, "d", &seq);
  ------------------
  |  |   60|    153|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    153|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    153|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    153|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    153|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    153|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    153|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1846|    153|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    153|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1846:9): [True: 84, False: 69]
  ------------------
 1847|     84|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|     84|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1848|     84|                "Could not unpack SSH_MSG_UNIMPLEMENTED packet");
 1849|     84|        return SSH_PACKET_USED;
  ------------------
  |  |  638|     84|#define SSH_PACKET_USED 1
  ------------------
 1850|     84|    }
 1851|       |
 1852|     69|    SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  283|     69|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1853|     69|            "Received SSH_MSG_UNIMPLEMENTED (sequence number %" PRIu32 ")",seq);
 1854|       |
 1855|     69|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     69|#define SSH_PACKET_USED 1
  ------------------
 1856|    153|}
ssh_packet_parse_type:
 1862|  30.2k|{
 1863|  30.2k|    session->in_packet = (struct packet_struct) {
 1864|  30.2k|        .type = 0,
 1865|  30.2k|    };
 1866|       |
 1867|  30.2k|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (1867:9): [True: 0, False: 30.2k]
  ------------------
 1868|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1869|      0|    }
 1870|       |
 1871|  30.2k|    if (ssh_buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) {
  ------------------
  |  Branch (1871:9): [True: 7.34k, False: 22.9k]
  ------------------
 1872|  7.34k|        ssh_set_error(session, SSH_FATAL, "Packet too short to read type");
  ------------------
  |  |  313|  7.34k|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1873|  7.34k|        return SSH_ERROR;
  ------------------
  |  |  317|  7.34k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1874|  7.34k|    }
 1875|       |
 1876|  22.9k|    session->in_packet.valid = 1;
 1877|       |
 1878|  22.9k|    return SSH_OK;
  ------------------
  |  |  316|  22.9k|#define SSH_OK 0     /* No error */
  ------------------
 1879|  30.2k|}
ssh_packet_send:
 2067|  18.0k|{
 2068|  18.0k|    uint32_t payloadsize;
 2069|  18.0k|    uint8_t type, *payload;
 2070|  18.0k|    bool need_rekey, in_rekey;
 2071|  18.0k|    int rc;
 2072|       |
 2073|  18.0k|    if (session->socket == NULL || !ssh_socket_is_open(session->socket)) {
  ------------------
  |  Branch (2073:9): [True: 0, False: 18.0k]
  |  Branch (2073:36): [True: 0, False: 18.0k]
  ------------------
 2074|      0|        ssh_buffer_reinit(session->out_buffer);
 2075|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2076|      0|    }
 2077|       |
 2078|  18.0k|    payloadsize = ssh_buffer_get_len(session->out_buffer);
 2079|  18.0k|    if (payloadsize < 1) {
  ------------------
  |  Branch (2079:9): [True: 0, False: 18.0k]
  ------------------
 2080|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2081|      0|    }
 2082|       |
 2083|  18.0k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 2084|  18.0k|    type = payload[0]; /* type is the first byte of the packet now */
 2085|  18.0k|    need_rekey = ssh_packet_need_rekey(session, payloadsize);
 2086|  18.0k|    in_rekey = ssh_packet_in_rekey(session);
 2087|       |
 2088|       |    /* The rekey is triggered here. After that, only the key exchange
 2089|       |     * packets can be sent, until we send our NEWKEYS.
 2090|       |     */
 2091|  18.0k|    if (need_rekey || (in_rekey && !ssh_packet_is_kex(type))) {
  ------------------
  |  Branch (2091:9): [True: 0, False: 18.0k]
  |  Branch (2091:24): [True: 0, False: 18.0k]
  |  Branch (2091:36): [True: 0, False: 0]
  ------------------
 2092|      0|        if (need_rekey) {
  ------------------
  |  Branch (2092:13): [True: 0, False: 0]
  ------------------
 2093|      0|            SSH_LOG(SSH_LOG_PACKET, "Outgoing packet triggered rekey");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2094|      0|        }
 2095|       |        /* Queue the current packet -- we will send it after the rekey */
 2096|      0|        SSH_LOG(SSH_LOG_PACKET, "Queuing packet type %d", type);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2097|      0|        rc = ssh_list_append(session->out_queue, session->out_buffer);
 2098|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2098:13): [True: 0, False: 0]
  ------------------
 2099|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2100|      0|        }
 2101|      0|        session->out_buffer = ssh_buffer_new();
 2102|      0|        if (session->out_buffer == NULL) {
  ------------------
  |  Branch (2102:13): [True: 0, False: 0]
  ------------------
 2103|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2104|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2105|      0|        }
 2106|       |
 2107|      0|        if (need_rekey) {
  ------------------
  |  Branch (2107:13): [True: 0, False: 0]
  ------------------
 2108|       |            /* Send the KEXINIT packet instead.
 2109|       |             * This recursively calls the packet_send(), but it should
 2110|       |             * not get into rekeying again.
 2111|       |             * After that we need to handle the key exchange responses
 2112|       |             * up to the point where we can send the rest of the queue.
 2113|       |             */
 2114|      0|            return ssh_send_rekex(session);
 2115|      0|        }
 2116|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2117|      0|    }
 2118|       |
 2119|       |    /* Send the packet normally */
 2120|  18.0k|    rc = packet_send2(session);
 2121|       |
 2122|       |    /* We finished the key exchange so we can try to send our queue now */
 2123|  18.0k|    if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |  316|  36.0k|#define SSH_OK 0     /* No error */
  ------------------
                  if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  18.0k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2123:9): [True: 18.0k, False: 0]
  |  Branch (2123:25): [True: 33, False: 17.9k]
  ------------------
 2124|     33|        struct ssh_iterator *it = NULL;
 2125|       |
 2126|     33|        if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|     33|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (2126:13): [True: 2, False: 31]
  ------------------
 2127|       |            /* reset packet sequence number when running in strict kex mode */
 2128|      2|            session->send_seq = 0;
 2129|      2|        }
 2130|     33|        for (it = ssh_list_get_iterator(session->out_queue);
 2131|     33|             it != NULL;
  ------------------
  |  Branch (2131:14): [True: 0, False: 33]
  ------------------
 2132|     33|             it = ssh_list_get_iterator(session->out_queue)) {
 2133|      0|            struct ssh_buffer_struct *next_buffer = NULL;
 2134|       |
 2135|       |            /* Peek only -- do not remove from queue yet */
 2136|      0|            next_buffer = ssh_iterator_value(struct ssh_buffer_struct *, it);
  ------------------
  |  |  120|      0|  ((type)((iterator)->data))
  ------------------
 2137|      0|            payloadsize = ssh_buffer_get_len(next_buffer);
 2138|      0|            if (ssh_packet_need_rekey(session, payloadsize)) {
  ------------------
  |  Branch (2138:17): [True: 0, False: 0]
  ------------------
 2139|       |                /* Sigh ... we still can not send this packet. Repeat. */
 2140|      0|                SSH_LOG(SSH_LOG_PACKET, "Queued packet triggered rekey");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2141|      0|                return ssh_send_rekex(session);
 2142|      0|            }
 2143|      0|            SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2144|      0|            session->out_buffer = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2145|      0|                                                    session->out_queue);
 2146|      0|            payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 2147|      0|            type = payload[0];
 2148|      0|            SSH_LOG(SSH_LOG_PACKET, "Dequeue packet type %d", type);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2149|      0|            rc = packet_send2(session);
 2150|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2150:17): [True: 0, False: 0]
  ------------------
 2151|      0|                return rc;
 2152|      0|            }
 2153|      0|        }
 2154|     33|    }
 2155|       |
 2156|  18.0k|    return rc;
 2157|  18.0k|}
ssh_packet_set_newkeys:
 2272|     33|{
 2273|     33|    struct ssh_cipher_struct *in_cipher = NULL, *out_cipher = NULL;
 2274|     33|    int rc;
 2275|       |
 2276|     33|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|    132|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 0, False: 33]
  |  |  |  Branch (283:34): [True: 33, False: 0]
  |  |  ------------------
  ------------------
 2277|     33|            "called, direction =%s%s",
 2278|     33|            direction & SSH_DIRECTION_IN ? " IN " : "",
 2279|     33|            direction & SSH_DIRECTION_OUT ? " OUT " : "");
 2280|       |
 2281|     33|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2281:9): [True: 0, False: 33]
  ------------------
 2282|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2283|      0|    }
 2284|       |
 2285|     33|    session->next_crypto->used |= direction;
 2286|     33|    if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2286:9): [True: 0, False: 33]
  ------------------
 2287|      0|        if (session->current_crypto->used & direction) {
  ------------------
  |  Branch (2287:13): [True: 0, False: 0]
  ------------------
 2288|      0|            SSH_LOG(SSH_LOG_TRACE, "This direction isn't used anymore.");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2289|      0|        }
 2290|       |        /* Mark the current requested direction unused */
 2291|      0|        session->current_crypto->used &= ~direction;
 2292|      0|    }
 2293|       |
 2294|       |    /* Both sides switched: do the actual switch now */
 2295|     33|    if (session->next_crypto->used == SSH_DIRECTION_BOTH) {
  ------------------
  |  Branch (2295:9): [True: 0, False: 33]
  ------------------
 2296|      0|        size_t session_id_len;
 2297|       |
 2298|      0|        if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2298:13): [True: 0, False: 0]
  ------------------
 2299|      0|            crypto_free(session->current_crypto);
 2300|      0|            session->current_crypto = NULL;
 2301|      0|        }
 2302|       |
 2303|      0|        session->current_crypto = session->next_crypto;
 2304|      0|        session->current_crypto->used = SSH_DIRECTION_BOTH;
 2305|       |
 2306|       |        /* Initialize the next_crypto structure */
 2307|      0|        session->next_crypto = crypto_new();
 2308|      0|        if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2308:13): [True: 0, False: 0]
  ------------------
 2309|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2310|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2311|      0|        }
 2312|       |
 2313|      0|        session_id_len = session->current_crypto->session_id_len;
 2314|      0|        session->next_crypto->session_id = malloc(session_id_len);
 2315|      0|        if (session->next_crypto->session_id == NULL) {
  ------------------
  |  Branch (2315:13): [True: 0, False: 0]
  ------------------
 2316|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2317|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2318|      0|        }
 2319|       |
 2320|      0|        memcpy(session->next_crypto->session_id,
 2321|      0|               session->current_crypto->session_id,
 2322|      0|               session_id_len);
 2323|      0|        session->next_crypto->session_id_len = session_id_len;
 2324|       |
 2325|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2326|      0|    }
 2327|       |
 2328|       |    /* Initialize common structures so the next context can be used in
 2329|       |     * either direction */
 2330|     33|    if (session->client) {
  ------------------
  |  Branch (2330:9): [True: 33, False: 0]
  ------------------
 2331|       |        /* The server has this part already done */
 2332|     33|        rc = ssh_make_sessionid(session);
 2333|     33|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     33|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2333:13): [True: 0, False: 33]
  ------------------
 2334|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2335|      0|        }
 2336|       |
 2337|       |        /*
 2338|       |         * Set the cryptographic functions for the next crypto
 2339|       |         * (it is needed for ssh_generate_session_keys for key lengths)
 2340|       |         */
 2341|     33|        rc = crypt_set_algorithms_client(session);
 2342|     33|        if (rc < 0) {
  ------------------
  |  Branch (2342:13): [True: 0, False: 33]
  ------------------
 2343|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2344|      0|        }
 2345|     33|    }
 2346|       |
 2347|     33|    if (ssh_generate_session_keys(session) < 0) {
  ------------------
  |  Branch (2347:9): [True: 0, False: 33]
  ------------------
 2348|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2349|      0|    }
 2350|       |
 2351|     33|    in_cipher = session->next_crypto->in_cipher;
 2352|     33|    out_cipher = session->next_crypto->out_cipher;
 2353|     33|    if (in_cipher == NULL || out_cipher == NULL) {
  ------------------
  |  Branch (2353:9): [True: 0, False: 33]
  |  Branch (2353:30): [True: 0, False: 33]
  ------------------
 2354|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2355|      0|    }
 2356|       |
 2357|       |    /* Initialize rekeying states */
 2358|     33|    ssh_init_rekey_state(session, out_cipher);
 2359|     33|    ssh_init_rekey_state(session, in_cipher);
 2360|     33|    if (session->opts.rekey_time != 0) {
  ------------------
  |  Branch (2360:9): [True: 0, False: 33]
  ------------------
 2361|      0|        ssh_timestamp_init(&session->last_rekey_time);
 2362|      0|        SSH_LOG(SSH_LOG_DEBUG, "Set rekey after %" PRIu32 " seconds",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2363|      0|                session->opts.rekey_time/1000);
 2364|      0|    }
 2365|       |
 2366|     33|    if (in_cipher->set_decrypt_key) {
  ------------------
  |  Branch (2366:9): [True: 0, False: 33]
  ------------------
 2367|       |        /* Initialize the encryption and decryption keys in next_crypto */
 2368|      0|        rc = in_cipher->set_decrypt_key(in_cipher,
 2369|      0|                                        session->next_crypto->decryptkey,
 2370|      0|                                        session->next_crypto->decryptIV);
 2371|      0|        if (rc < 0) {
  ------------------
  |  Branch (2371:13): [True: 0, False: 0]
  ------------------
 2372|       |            /* On error, make sure it is not used */
 2373|      0|            session->next_crypto->used = 0;
 2374|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2375|      0|        }
 2376|      0|    }
 2377|       |
 2378|     33|    if (out_cipher->set_encrypt_key) {
  ------------------
  |  Branch (2378:9): [True: 0, False: 33]
  ------------------
 2379|      0|        rc = out_cipher->set_encrypt_key(out_cipher,
 2380|      0|                                         session->next_crypto->encryptkey,
 2381|      0|                                         session->next_crypto->encryptIV);
 2382|      0|        if (rc < 0) {
  ------------------
  |  Branch (2382:13): [True: 0, False: 0]
  ------------------
 2383|       |            /* On error, make sure it is not used */
 2384|      0|            session->next_crypto->used = 0;
 2385|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2386|      0|        }
 2387|      0|    }
 2388|       |
 2389|     33|    return SSH_OK;
  ------------------
  |  |  316|     33|#define SSH_OK 0     /* No error */
  ------------------
 2390|     33|}
packet.c:ssh_packet_incoming_filter:
  143|  30.2k|{
  144|  30.2k|    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|  30.2k|    switch(session->in_packet.type) {
  152|      3|    case SSH2_MSG_DISCONNECT:                         // 1
  ------------------
  |  |    4|      3|#define SSH2_MSG_DISCONNECT 1
  ------------------
  |  Branch (152:5): [True: 3, False: 30.2k]
  ------------------
  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|      3|        rc = SSH_PACKET_ALLOWED;
  164|      3|        break;
  165|     41|    case SSH2_MSG_IGNORE:                             // 2
  ------------------
  |  |    5|     41|#define SSH2_MSG_IGNORE	 2
  ------------------
  |  Branch (165:5): [True: 41, False: 30.2k]
  ------------------
  166|       |        /*
  167|       |         * States required:
  168|       |         * - None
  169|       |         *
  170|       |         * Transitions:
  171|       |         * - None
  172|       |         * */
  173|       |
  174|       |        /* Always allowed */
  175|     41|        rc = SSH_PACKET_ALLOWED;
  176|     41|        break;
  177|    153|    case SSH2_MSG_UNIMPLEMENTED:                      // 3
  ------------------
  |  |    6|    153|#define SSH2_MSG_UNIMPLEMENTED 3
  ------------------
  |  Branch (177:5): [True: 153, False: 30.1k]
  ------------------
  178|       |        /*
  179|       |         * States required:
  180|       |         * - None
  181|       |         *
  182|       |         * Transitions:
  183|       |         * - None
  184|       |         * */
  185|       |
  186|       |        /* Always allowed */
  187|    153|        rc = SSH_PACKET_ALLOWED;
  188|    153|        break;
  189|  12.7k|    case SSH2_MSG_DEBUG:                              // 4
  ------------------
  |  |    7|  12.7k|#define SSH2_MSG_DEBUG	4
  ------------------
  |  Branch (189:5): [True: 12.7k, False: 17.5k]
  ------------------
  190|       |        /*
  191|       |         * States required:
  192|       |         * - None
  193|       |         *
  194|       |         * Transitions:
  195|       |         * - None
  196|       |         * */
  197|       |
  198|       |        /* Always allowed */
  199|  12.7k|        rc = SSH_PACKET_ALLOWED;
  200|  12.7k|        break;
  201|      1|    case SSH2_MSG_SERVICE_REQUEST:                    // 5
  ------------------
  |  |    8|      1|#define SSH2_MSG_SERVICE_REQUEST	5
  ------------------
  |  Branch (201:5): [True: 1, False: 30.2k]
  ------------------
  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|      1|        if (session->client) {
  ------------------
  |  Branch (215:13): [True: 1, False: 0]
  ------------------
  216|      1|            rc = SSH_PACKET_DENIED;
  217|      1|            break;
  218|      1|        }
  219|       |
  220|      0|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (220:13): [True: 0, False: 0]
  ------------------
  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|      0|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (227:13): [True: 0, False: 0]
  ------------------
  228|      0|            rc = SSH_PACKET_DENIED;
  229|      0|            break;
  230|      0|        }
  231|       |
  232|      0|        rc = SSH_PACKET_ALLOWED;
  233|      0|        break;
  234|      0|    case SSH2_MSG_SERVICE_ACCEPT:                     // 6
  ------------------
  |  |    9|      0|#define SSH2_MSG_SERVICE_ACCEPT 6
  ------------------
  |  Branch (234:5): [True: 0, False: 30.2k]
  ------------------
  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|      0|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (246:13): [True: 0, False: 0]
  ------------------
  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|      0|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (253:13): [True: 0, False: 0]
  ------------------
  254|      0|            rc = SSH_PACKET_DENIED;
  255|      0|            break;
  256|      0|        }
  257|       |
  258|       |        /* TODO check if only auth service can be requested */
  259|      0|        if (session->auth.service_state != SSH_AUTH_SERVICE_SENT) {
  ------------------
  |  Branch (259:13): [True: 0, False: 0]
  ------------------
  260|      0|            rc = SSH_PACKET_DENIED;
  261|      0|            break;
  262|      0|        }
  263|       |
  264|      0|        rc = SSH_PACKET_ALLOWED;
  265|      0|        break;
  266|      0|    case SSH2_MSG_EXT_INFO:                           // 7
  ------------------
  |  |   10|      0|#define SSH2_MSG_EXT_INFO 7
  ------------------
  |  Branch (266:5): [True: 0, False: 30.2k]
  ------------------
  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|      0|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (278:13): [True: 0, False: 0]
  ------------------
  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|      0|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (285:13): [True: 0, False: 0]
  ------------------
  286|      0|            rc = SSH_PACKET_DENIED;
  287|      0|            break;
  288|      0|        }
  289|       |
  290|      0|        rc = SSH_PACKET_ALLOWED;
  291|      0|        break;
  292|    290|    case SSH2_MSG_KEXINIT:                            // 20
  ------------------
  |  |   12|    290|#define SSH2_MSG_KEXINIT	 20
  ------------------
  |  Branch (292:5): [True: 290, False: 30.0k]
  ------------------
  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|    290|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATED) &&
  ------------------
  |  Branch (310:13): [True: 290, False: 0]
  ------------------
  311|    290|            (session->session_state != SSH_SESSION_STATE_INITIAL_KEX))
  ------------------
  |  Branch (311:13): [True: 2, False: 288]
  ------------------
  312|      2|        {
  313|      2|            rc = SSH_PACKET_DENIED;
  314|      2|            break;
  315|      2|        }
  316|       |
  317|    288|        if ((session->dh_handshake_state != DH_STATE_INIT) &&
  ------------------
  |  Branch (317:13): [True: 0, False: 288]
  ------------------
  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|    288|        rc = SSH_PACKET_ALLOWED;
  327|    288|        break;
  328|     15|    case SSH2_MSG_NEWKEYS:                            // 21
  ------------------
  |  |   13|     15|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (328:5): [True: 15, False: 30.2k]
  ------------------
  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|     15|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (342:13): [True: 0, False: 15]
  ------------------
  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|     15|        if (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (348:13): [True: 0, False: 15]
  ------------------
  349|      0|            rc = SSH_PACKET_DENIED;
  350|      0|            break;
  351|      0|        }
  352|       |
  353|     15|        rc = SSH_PACKET_ALLOWED;
  354|     15|        break;
  355|      0|    case SSH2_MSG_KEXDH_INIT:                         // 30
  ------------------
  |  |   15|      0|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (355:5): [True: 0, False: 30.2k]
  ------------------
  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|      0|        if (session->client) {
  ------------------
  |  Branch (373:13): [True: 0, False: 0]
  ------------------
  374|      0|            rc = SSH_PACKET_DENIED;
  375|      0|            break;
  376|      0|        }
  377|       |
  378|      0|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (378:13): [True: 0, False: 0]
  ------------------
  379|      0|            rc = SSH_PACKET_DENIED;
  380|      0|            break;
  381|      0|        }
  382|       |
  383|       |        /* Only allowed if dh_handshake_state is in initial state */
  384|      0|        if (session->dh_handshake_state != DH_STATE_INIT) {
  ------------------
  |  Branch (384:13): [True: 0, False: 0]
  ------------------
  385|      0|            rc = SSH_PACKET_DENIED;
  386|      0|            break;
  387|      0|        }
  388|       |
  389|      0|        rc = SSH_PACKET_ALLOWED;
  390|      0|        break;
  391|    151|    case SSH2_MSG_KEXDH_REPLY:                        // 31
  ------------------
  |  |   16|    151|#define SSH2_MSG_KEXDH_REPLY 31
  ------------------
  |  Branch (391:5): [True: 151, False: 30.1k]
  ------------------
  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|    151|        if (session->server) {
  ------------------
  |  Branch (408:13): [True: 0, False: 151]
  ------------------
  409|      0|            rc = SSH_PACKET_DENIED;
  410|      0|            break;
  411|      0|        }
  412|       |
  413|    151|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (413:13): [True: 0, False: 151]
  ------------------
  414|      0|            rc = SSH_PACKET_DENIED;
  415|      0|            break;
  416|      0|        }
  417|       |
  418|    151|        if (session->dh_handshake_state != DH_STATE_INIT_SENT &&
  ------------------
  |  Branch (418:13): [True: 7, False: 144]
  ------------------
  419|      7|            session->dh_handshake_state != DH_STATE_REQUEST_SENT) {
  ------------------
  |  Branch (419:13): [True: 0, False: 7]
  ------------------
  420|      0|            rc = SSH_PACKET_DENIED;
  421|      0|            break;
  422|      0|        }
  423|       |
  424|    151|        rc = SSH_PACKET_ALLOWED;
  425|    151|        break;
  426|      3|    case SSH2_MSG_KEX_DH_GEX_INIT:                    // 32
  ------------------
  |  |   24|      3|#define SSH2_MSG_KEX_DH_GEX_INIT 32
  ------------------
  |  Branch (426:5): [True: 3, False: 30.2k]
  ------------------
  427|       |      // SSH2_MSG_KEXGSS_COMPLETE:                    // 32
  428|      3|        if (ssh_kex_is_gss(session->next_crypto)) {
  ------------------
  |  Branch (428:13): [True: 0, False: 3]
  ------------------
  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|      3|        } 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|      3|            if (session->client) {
  ------------------
  |  Branch (472:17): [True: 3, False: 0]
  ------------------
  473|      3|                rc = SSH_PACKET_DENIED;
  474|      3|                break;
  475|      3|            }
  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|    303|    case SSH2_MSG_KEX_DH_GEX_REPLY:                   // 33
  ------------------
  |  |   25|    303|#define SSH2_MSG_KEX_DH_GEX_REPLY 33
  ------------------
  |  Branch (490:5): [True: 303, False: 29.9k]
  ------------------
  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|    303|        if (session->server) {
  ------------------
  |  Branch (503:13): [True: 0, False: 303]
  ------------------
  504|      0|            rc = SSH_PACKET_DENIED;
  505|      0|            break;
  506|      0|        }
  507|       |
  508|    303|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (508:13): [True: 1, False: 302]
  ------------------
  509|      1|            rc = SSH_PACKET_DENIED;
  510|      1|            break;
  511|      1|        }
  512|       |
  513|    302|        if (session->dh_handshake_state != DH_STATE_INIT_SENT) {
  ------------------
  |  Branch (513:13): [True: 0, False: 302]
  ------------------
  514|      0|            rc = SSH_PACKET_DENIED;
  515|      0|            break;
  516|      0|        }
  517|       |
  518|    302|        rc = SSH_PACKET_ALLOWED;
  519|    302|        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: 30.2k]
  ------------------
  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|      1|    case SSH2_MSG_USERAUTH_REQUEST:                   // 50
  ------------------
  |  |   36|      1|#define SSH2_MSG_USERAUTH_REQUEST 50
  ------------------
  |  Branch (553:5): [True: 1, False: 30.2k]
  ------------------
  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|      1|        if (session->client) {
  ------------------
  |  Branch (567:13): [True: 1, False: 0]
  ------------------
  568|      1|            rc = SSH_PACKET_DENIED;
  569|      1|            break;
  570|      1|        }
  571|       |
  572|      0|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (572:13): [True: 0, False: 0]
  ------------------
  573|      0|            rc = SSH_PACKET_DENIED;
  574|      0|            break;
  575|      0|        }
  576|       |
  577|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (577:13): [True: 0, False: 0]
  ------------------
  578|      0|            rc = SSH_PACKET_DENIED;
  579|      0|            break;
  580|      0|        }
  581|       |
  582|      0|        rc = SSH_PACKET_ALLOWED;
  583|      0|        break;
  584|      0|    case SSH2_MSG_USERAUTH_FAILURE:                   // 51
  ------------------
  |  |   37|      0|#define SSH2_MSG_USERAUTH_FAILURE 51
  ------------------
  |  Branch (584:5): [True: 0, False: 30.2k]
  ------------------
  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|      1|    case SSH2_MSG_USERAUTH_SUCCESS:                   // 52
  ------------------
  |  |   38|      1|#define SSH2_MSG_USERAUTH_SUCCESS 52
  ------------------
  |  Branch (622:5): [True: 1, False: 30.2k]
  ------------------
  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|      1|        if (session->server) {
  ------------------
  |  Branch (642:13): [True: 0, False: 1]
  ------------------
  643|      0|            rc = SSH_PACKET_DENIED;
  644|      0|            break;
  645|      0|        }
  646|       |
  647|      1|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (647:13): [True: 1, False: 0]
  ------------------
  648|      1|            rc = SSH_PACKET_DENIED;
  649|      1|            break;
  650|      1|        }
  651|       |
  652|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (652:13): [True: 0, False: 0]
  ------------------
  653|      0|            rc = SSH_PACKET_DENIED;
  654|      0|            break;
  655|      0|        }
  656|       |
  657|      0|        if ((session->auth.state != SSH_AUTH_STATE_KBDINT_SENT) &&
  ------------------
  |  Branch (657:13): [True: 0, False: 0]
  ------------------
  658|      0|            (session->auth.state != SSH_AUTH_STATE_PUBKEY_AUTH_SENT) &&
  ------------------
  |  Branch (658:13): [True: 0, False: 0]
  ------------------
  659|      0|            (session->auth.state != SSH_AUTH_STATE_PASSWORD_AUTH_SENT) &&
  ------------------
  |  Branch (659:13): [True: 0, False: 0]
  ------------------
  660|      0|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_MIC_SENT) &&
  ------------------
  |  Branch (660:13): [True: 0, False: 0]
  ------------------
  661|      0|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_KEYEX_MIC_SENT) &&
  ------------------
  |  Branch (661:13): [True: 0, False: 0]
  ------------------
  662|      0|            (session->auth.state != SSH_AUTH_STATE_AUTH_NONE_SENT)) {
  ------------------
  |  Branch (662:13): [True: 0, False: 0]
  ------------------
  663|      0|            rc = SSH_PACKET_DENIED;
  664|      0|            break;
  665|      0|        }
  666|       |
  667|      0|        rc = SSH_PACKET_ALLOWED;
  668|      0|        break;
  669|      1|    case SSH2_MSG_USERAUTH_BANNER:                    // 53
  ------------------
  |  |   39|      1|#define SSH2_MSG_USERAUTH_BANNER 53
  ------------------
  |  Branch (669:5): [True: 1, False: 30.2k]
  ------------------
  670|       |        /*
  671|       |         * States required:
  672|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  673|       |         *
  674|       |         * Transitions:
  675|       |         * - None
  676|       |         * */
  677|       |
  678|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (678:13): [True: 1, False: 0]
  ------------------
  679|      1|            rc = SSH_PACKET_DENIED;
  680|      1|            break;
  681|      1|        }
  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: 30.2k]
  ------------------
  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|      1|    case SSH2_MSG_USERAUTH_INFO_RESPONSE:             // 61
  ------------------
  |  |   44|      1|#define SSH2_MSG_USERAUTH_INFO_RESPONSE 61
  ------------------
  |  Branch (725:5): [True: 1, False: 30.2k]
  ------------------
  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|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (739:13): [True: 1, False: 0]
  ------------------
  740|      1|            rc = SSH_PACKET_DENIED;
  741|      1|            break;
  742|      1|        }
  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|      1|    case SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE:  // 63
  ------------------
  |  |   46|      1|#define SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE 63
  ------------------
  |  Branch (753:5): [True: 1, False: 30.2k]
  ------------------
  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|      1|        rc = SSH_PACKET_DENIED;
  784|      1|        break;
  785|      0|#endif  /* WITH_GSSAPI */
  786|      2|    case SSH2_MSG_USERAUTH_GSSAPI_ERROR:              // 64
  ------------------
  |  |   47|      2|#define SSH2_MSG_USERAUTH_GSSAPI_ERROR 64
  ------------------
  |  Branch (786:5): [True: 2, False: 30.2k]
  ------------------
  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|      2|        rc = SSH_PACKET_DENIED;
  809|      2|        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: 30.2k]
  ------------------
  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: 30.2k]
  ------------------
  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: 30.2k]
  ------------------
  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|      2|    case SSH2_MSG_REQUEST_SUCCESS:                    // 81
  ------------------
  |  |   52|      2|#define SSH2_MSG_REQUEST_SUCCESS 81
  ------------------
  |  Branch (889:5): [True: 2, False: 30.2k]
  ------------------
  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|      2|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (901:13): [True: 2, False: 0]
  ------------------
  902|      2|            rc = SSH_PACKET_DENIED;
  903|      2|            break;
  904|      2|        }
  905|       |
  906|      0|        rc = SSH_PACKET_ALLOWED;
  907|      0|        break;
  908|      1|    case SSH2_MSG_REQUEST_FAILURE:                    // 82
  ------------------
  |  |   53|      1|#define SSH2_MSG_REQUEST_FAILURE 82
  ------------------
  |  Branch (908:5): [True: 1, False: 30.2k]
  ------------------
  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|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (920:13): [True: 1, False: 0]
  ------------------
  921|      1|            rc = SSH_PACKET_DENIED;
  922|      1|            break;
  923|      1|        }
  924|       |
  925|      0|        rc = SSH_PACKET_ALLOWED;
  926|      0|        break;
  927|      0|    case SSH2_MSG_CHANNEL_OPEN:                       // 90
  ------------------
  |  |   54|      0|#define SSH2_MSG_CHANNEL_OPEN 90
  ------------------
  |  Branch (927:5): [True: 0, False: 30.2k]
  ------------------
  928|       |        /*
  929|       |         * States required:
  930|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  931|       |         *
  932|       |         * Transitions:
  933|       |         * - None
  934|       |         * */
  935|       |
  936|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (936:13): [True: 0, False: 0]
  ------------------
  937|      0|            rc = SSH_PACKET_DENIED;
  938|      0|            break;
  939|      0|        }
  940|       |
  941|      0|        rc = SSH_PACKET_ALLOWED;
  942|      0|        break;
  943|      1|    case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION:          // 91
  ------------------
  |  |   55|      1|#define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
  ------------------
  |  Branch (943:5): [True: 1, False: 30.2k]
  ------------------
  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|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (953:13): [True: 1, False: 0]
  ------------------
  954|      1|            rc = SSH_PACKET_DENIED;
  955|      1|            break;
  956|      1|        }
  957|       |
  958|      0|        rc = SSH_PACKET_ALLOWED;
  959|      0|        break;
  960|      1|    case SSH2_MSG_CHANNEL_OPEN_FAILURE:               // 92
  ------------------
  |  |   56|      1|#define SSH2_MSG_CHANNEL_OPEN_FAILURE 92
  ------------------
  |  Branch (960:5): [True: 1, False: 30.2k]
  ------------------
  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|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (969:13): [True: 1, False: 0]
  ------------------
  970|      1|            rc = SSH_PACKET_DENIED;
  971|      1|            break;
  972|      1|        }
  973|       |
  974|      0|        rc = SSH_PACKET_ALLOWED;
  975|      0|        break;
  976|      1|    case SSH2_MSG_CHANNEL_WINDOW_ADJUST:              // 93
  ------------------
  |  |   57|      1|#define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93
  ------------------
  |  Branch (976:5): [True: 1, False: 30.2k]
  ------------------
  977|       |        /*
  978|       |         * States required:
  979|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  980|       |         *
  981|       |         * Transitions:
  982|       |         * - None
  983|       |         * */
  984|       |
  985|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (985:13): [True: 1, False: 0]
  ------------------
  986|      1|            rc = SSH_PACKET_DENIED;
  987|      1|            break;
  988|      1|        }
  989|       |
  990|      0|        rc = SSH_PACKET_ALLOWED;
  991|      0|        break;
  992|      1|    case SSH2_MSG_CHANNEL_DATA:                       // 94
  ------------------
  |  |   58|      1|#define SSH2_MSG_CHANNEL_DATA 94
  ------------------
  |  Branch (992:5): [True: 1, False: 30.2k]
  ------------------
  993|       |        /*
  994|       |         * States required:
  995|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  996|       |         *
  997|       |         * Transitions:
  998|       |         * - None
  999|       |         * */
 1000|       |
 1001|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1001:13): [True: 1, False: 0]
  ------------------
 1002|      1|            rc = SSH_PACKET_DENIED;
 1003|      1|            break;
 1004|      1|        }
 1005|       |
 1006|      0|        rc = SSH_PACKET_ALLOWED;
 1007|      0|        break;
 1008|      1|    case SSH2_MSG_CHANNEL_EXTENDED_DATA:              // 95
  ------------------
  |  |   59|      1|#define SSH2_MSG_CHANNEL_EXTENDED_DATA 95
  ------------------
  |  Branch (1008:5): [True: 1, False: 30.2k]
  ------------------
 1009|       |        /*
 1010|       |         * States required:
 1011|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1012|       |         *
 1013|       |         * Transitions:
 1014|       |         * - None
 1015|       |         * */
 1016|       |
 1017|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1017:13): [True: 1, False: 0]
  ------------------
 1018|      1|            rc = SSH_PACKET_DENIED;
 1019|      1|            break;
 1020|      1|        }
 1021|       |
 1022|      0|        rc = SSH_PACKET_ALLOWED;
 1023|      0|        break;
 1024|      1|    case SSH2_MSG_CHANNEL_EOF:                        // 96
  ------------------
  |  |   60|      1|#define SSH2_MSG_CHANNEL_EOF	96
  ------------------
  |  Branch (1024:5): [True: 1, False: 30.2k]
  ------------------
 1025|       |        /*
 1026|       |         * States required:
 1027|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1028|       |         *
 1029|       |         * Transitions:
 1030|       |         * - None
 1031|       |         * */
 1032|       |
 1033|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1033:13): [True: 1, False: 0]
  ------------------
 1034|      1|            rc = SSH_PACKET_DENIED;
 1035|      1|            break;
 1036|      1|        }
 1037|       |
 1038|      0|        rc = SSH_PACKET_ALLOWED;
 1039|      0|        break;
 1040|      0|    case SSH2_MSG_CHANNEL_CLOSE:                      // 97
  ------------------
  |  |   61|      0|#define SSH2_MSG_CHANNEL_CLOSE 97
  ------------------
  |  Branch (1040:5): [True: 0, False: 30.2k]
  ------------------
 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|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1050:13): [True: 0, False: 0]
  ------------------
 1051|      0|            rc = SSH_PACKET_DENIED;
 1052|      0|            break;
 1053|      0|        }
 1054|       |
 1055|      0|        rc = SSH_PACKET_ALLOWED;
 1056|      0|        break;
 1057|      1|    case SSH2_MSG_CHANNEL_REQUEST:                    // 98
  ------------------
  |  |   62|      1|#define SSH2_MSG_CHANNEL_REQUEST 98
  ------------------
  |  Branch (1057:5): [True: 1, False: 30.2k]
  ------------------
 1058|       |        /*
 1059|       |         * States required:
 1060|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1061|       |         *
 1062|       |         * Transitions:
 1063|       |         * - Depends on the request
 1064|       |         * */
 1065|       |
 1066|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1066:13): [True: 1, False: 0]
  ------------------
 1067|      1|            rc = SSH_PACKET_DENIED;
 1068|      1|            break;
 1069|      1|        }
 1070|       |
 1071|      0|        rc = SSH_PACKET_ALLOWED;
 1072|      0|        break;
 1073|      1|    case SSH2_MSG_CHANNEL_SUCCESS:                    // 99
  ------------------
  |  |   63|      1|#define SSH2_MSG_CHANNEL_SUCCESS 99
  ------------------
  |  Branch (1073:5): [True: 1, False: 30.2k]
  ------------------
 1074|       |        /*
 1075|       |         * States required:
 1076|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1077|       |         *
 1078|       |         * Transitions:
 1079|       |         * - From channel->request_state == SSH_CHANNEL_REQ_STATE_PENDING
 1080|       |         * - To   channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED
 1081|       |         *
 1082|       |         * If not in a pending state, message is ignored in the callback handler.
 1083|       |         * */
 1084|       |
 1085|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1085:13): [True: 1, False: 0]
  ------------------
 1086|      1|            rc = SSH_PACKET_DENIED;
 1087|      1|            break;
 1088|      1|        }
 1089|       |
 1090|      0|        rc = SSH_PACKET_ALLOWED;
 1091|      0|        break;
 1092|      2|    case SSH2_MSG_CHANNEL_FAILURE:                    // 100
  ------------------
  |  |   64|      2|#define SSH2_MSG_CHANNEL_FAILURE 100
  ------------------
  |  Branch (1092:5): [True: 2, False: 30.2k]
  ------------------
 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|      2|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1104:13): [True: 2, False: 0]
  ------------------
 1105|      2|            rc = SSH_PACKET_DENIED;
 1106|      2|            break;
 1107|      2|        }
 1108|       |
 1109|      0|        rc = SSH_PACKET_ALLOWED;
 1110|      0|        break;
 1111|      2|    case SSH2_MSG_PING: // 192
  ------------------
  |  |   69|      2|#define SSH2_MSG_PING 192
  ------------------
  |  Branch (1111:5): [True: 2, False: 30.2k]
  ------------------
 1112|      4|    case SSH2_MSG_PONG: // 193
  ------------------
  |  |   70|      4|#define SSH2_MSG_PONG 193
  ------------------
  |  Branch (1112:5): [True: 2, False: 30.2k]
  ------------------
 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|      4|        rc = SSH_PACKET_ALLOWED;
 1128|      4|        break;
 1129|  16.5k|    default:
  ------------------
  |  Branch (1129:5): [True: 16.5k, False: 13.7k]
  ------------------
 1130|       |        /* Unknown message, do not filter */
 1131|  16.5k|        rc = SSH_PACKET_UNKNOWN;
 1132|  16.5k|        goto end;
 1133|  30.2k|    }
 1134|       |
 1135|  30.2k|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|  30.2k|    return rc;
 1149|  30.2k|}
packet.c:ssh_packet_need_rekey:
 1201|  48.2k|{
 1202|  48.2k|    bool data_rekey_needed = false;
 1203|  48.2k|    struct ssh_crypto_struct *crypto = NULL;
 1204|  48.2k|    struct ssh_cipher_struct *out_cipher = NULL, *in_cipher = NULL;
 1205|  48.2k|    uint32_t next_blocks;
 1206|       |
 1207|       |    /* We can safely rekey only in authenticated state */
 1208|  48.2k|    if ((session->flags & SSH_SESSION_FLAG_AUTHENTICATED) == 0) {
  ------------------
  |  |   78|  48.2k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (1208:9): [True: 48.2k, False: 0]
  ------------------
 1209|  48.2k|        return false;
 1210|  48.2k|    }
 1211|       |
 1212|       |    /* Do not rekey if the rekey/key-exchange is in progress */
 1213|      0|    if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (1213:9): [True: 0, False: 0]
  ------------------
 1214|      0|        return false;
 1215|      0|    }
 1216|       |
 1217|      0|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_BOTH);
 1218|      0|    if (crypto == NULL) {
  ------------------
  |  Branch (1218:9): [True: 0, False: 0]
  ------------------
 1219|      0|        return false;
 1220|      0|    }
 1221|       |
 1222|      0|    out_cipher = crypto->out_cipher;
 1223|      0|    in_cipher = crypto->in_cipher;
 1224|       |
 1225|       |    /* Make sure we can send at least something for very small limits */
 1226|      0|    if ((out_cipher->packets == 0) && (in_cipher->packets == 0)) {
  ------------------
  |  Branch (1226:9): [True: 0, False: 0]
  |  Branch (1226:39): [True: 0, False: 0]
  ------------------
 1227|      0|        return false;
 1228|      0|    }
 1229|       |
 1230|       |    /* Time based rekeying */
 1231|      0|    if (session->opts.rekey_time != 0 &&
  ------------------
  |  Branch (1231:9): [True: 0, False: 0]
  ------------------
 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|      0|    if (out_cipher->packets > MAX_PACKETS ||
  ------------------
  |  | 1197|      0|#define MAX_PACKETS    (1UL<<31)
  ------------------
  |  Branch (1240:9): [True: 0, False: 0]
  ------------------
 1241|      0|        in_cipher->packets > MAX_PACKETS) {
  ------------------
  |  | 1197|      0|#define MAX_PACKETS    (1UL<<31)
  ------------------
  |  Branch (1241:9): [True: 0, False: 0]
  ------------------
 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|      0|    next_blocks = payloadsize / out_cipher->blocksize;
 1251|      0|    data_rekey_needed = (out_cipher->max_blocks != 0 &&
  ------------------
  |  Branch (1251:26): [True: 0, False: 0]
  ------------------
 1252|      0|                         out_cipher->blocks + next_blocks > out_cipher->max_blocks) ||
  ------------------
  |  Branch (1252:26): [True: 0, False: 0]
  ------------------
 1253|      0|                         (in_cipher->max_blocks != 0 &&
  ------------------
  |  Branch (1253:27): [True: 0, False: 0]
  ------------------
 1254|      0|                         in_cipher->blocks + next_blocks > in_cipher->max_blocks);
  ------------------
  |  Branch (1254:26): [True: 0, False: 0]
  ------------------
 1255|       |
 1256|      0|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1257|      0|            "rekey: [data_rekey_needed=%d, out_blocks=%" PRIu64 ", in_blocks=%" PRIu64 "]",
 1258|      0|            data_rekey_needed,
 1259|      0|            out_cipher->blocks + next_blocks,
 1260|      0|            in_cipher->blocks + next_blocks);
 1261|       |
 1262|      0|    return data_rekey_needed;
 1263|      0|}
packet.c:ssh_packet_socket_controlflow_callback:
 1654|    293|{
 1655|    293|    ssh_session session = userdata;
 1656|    293|    struct ssh_iterator *it = NULL;
 1657|    293|    ssh_channel channel = NULL;
 1658|       |
 1659|    293|    if (code == SSH_SOCKET_FLOW_WRITEWONTBLOCK) {
  ------------------
  |  |  519|    293|#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
  ------------------
  |  Branch (1659:9): [True: 293, False: 0]
  ------------------
 1660|    293|        SSH_LOG(SSH_LOG_TRACE, "sending channel_write_wontblock callback");
  ------------------
  |  |  283|    293|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1661|       |
 1662|       |        /* the out pipe is empty so we can forward this to channels */
 1663|    293|        it = ssh_list_get_iterator(session->channels);
 1664|    293|        while (it != NULL) {
  ------------------
  |  Branch (1664:16): [True: 0, False: 293]
  ------------------
 1665|      0|            channel = ssh_iterator_value(ssh_channel, it);
  ------------------
  |  |  120|      0|  ((type)((iterator)->data))
  ------------------
 1666|       |            ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  567|      0|    do {                                                      \
  |  |  568|      0|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  569|      0|        cbtype cb;                                            \
  |  |  570|      0|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (570:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  571|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  120|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  572|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  551|      0|  )
  |  |  ------------------
  |  |  573|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  574|      0|            i = i->next;                                      \
  |  |  575|      0|        }                                                     \
  |  |  576|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (576:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1667|      0|                                       ssh_channel_callbacks,
 1668|      0|                                       channel_write_wontblock_function,
 1669|      0|                                       session,
 1670|      0|                                       channel,
 1671|      0|                                       channel->remote_window);
 1672|      0|            it = it->next;
 1673|      0|        }
 1674|    293|    }
 1675|    293|}
packet.c:ssh_packet_in_rekey:
 2056|  18.0k|{
 2057|       |    /* We know we are rekeying if we are authenticated and the DH
 2058|       |     * status is not finished, but we only queue packets until we've
 2059|       |     * sent our NEWKEYS.
 2060|       |     */
 2061|  18.0k|    return (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) &&
  ------------------
  |  |   78|  18.0k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (2061:12): [True: 0, False: 18.0k]
  ------------------
 2062|      0|           (session->dh_handshake_state != DH_STATE_FINISHED) &&
  ------------------
  |  Branch (2062:12): [True: 0, False: 0]
  ------------------
 2063|      0|           (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT);
  ------------------
  |  Branch (2063:12): [True: 0, False: 0]
  ------------------
 2064|  18.0k|}
packet.c:packet_send2:
 1896|  18.0k|{
 1897|  18.0k|    unsigned int blocksize = 8;
 1898|  18.0k|    unsigned int lenfield_blocksize = 0;
 1899|  18.0k|    enum ssh_hmac_e hmac_type;
 1900|  18.0k|    uint32_t currentlen = ssh_buffer_get_len(session->out_buffer);
 1901|  18.0k|    struct ssh_crypto_struct *crypto = NULL;
 1902|  18.0k|    unsigned char *hmac = NULL;
 1903|  18.0k|    uint8_t padding_data[32] = { 0 };
 1904|  18.0k|    uint8_t padding_size;
 1905|  18.0k|    uint32_t finallen, payloadsize, compsize;
 1906|  18.0k|    uint8_t header[5] = {0};
 1907|  18.0k|    uint8_t type, *payload;
 1908|  18.0k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  18.0k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1909|  18.0k|    bool etm = false;
 1910|  18.0k|    int etm_packet_offset = 0;
 1911|       |
 1912|  18.0k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
 1913|  18.0k|    if (crypto) {
  ------------------
  |  Branch (1913:9): [True: 535, False: 17.4k]
  ------------------
 1914|    535|        blocksize = crypto->out_cipher->blocksize;
 1915|    535|        lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
 1916|    535|        hmac_type = crypto->out_hmac;
 1917|    535|        etm = crypto->out_hmac_etm;
 1918|  17.4k|    } else {
 1919|  17.4k|        hmac_type = session->next_crypto->out_hmac;
 1920|  17.4k|    }
 1921|       |
 1922|  18.0k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 1923|  18.0k|    type = payload[0]; /* type is the first byte of the packet now */
 1924|       |
 1925|  18.0k|    payloadsize = currentlen;
 1926|  18.0k|    if (etm) {
  ------------------
  |  Branch (1926:9): [True: 0, False: 18.0k]
  ------------------
 1927|      0|        etm_packet_offset = sizeof(uint32_t);
 1928|      0|        lenfield_blocksize = 0;
 1929|      0|    }
 1930|       |
 1931|  18.0k|    if (crypto != NULL && crypto->do_compress_out &&
  ------------------
  |  Branch (1931:9): [True: 535, False: 17.4k]
  |  Branch (1931:27): [True: 0, False: 535]
  ------------------
 1932|      0|        ssh_buffer_get_len(session->out_buffer) > 0) {
  ------------------
  |  Branch (1932:9): [True: 0, False: 0]
  ------------------
 1933|      0|        rc = compress_buffer(session,session->out_buffer);
 1934|      0|        if (rc < 0) {
  ------------------
  |  Branch (1934:13): [True: 0, False: 0]
  ------------------
 1935|      0|            goto error;
 1936|      0|        }
 1937|      0|        currentlen = ssh_buffer_get_len(session->out_buffer);
 1938|      0|    }
 1939|  18.0k|    compsize = currentlen;
 1940|       |    /* compressed payload + packet len (4) + padding_size len (1) */
 1941|       |    /* totallen - lenfield_blocksize - etm_packet_offset must be equal to 0 (mod blocksize) */
 1942|  18.0k|    padding_size = (blocksize - ((blocksize - lenfield_blocksize - etm_packet_offset + currentlen + 5) % blocksize));
 1943|  18.0k|    if (padding_size < 4) {
  ------------------
  |  Branch (1943:9): [True: 35, False: 17.9k]
  ------------------
 1944|     35|        padding_size += blocksize;
 1945|     35|    }
 1946|       |
 1947|  18.0k|    if (crypto != NULL) {
  ------------------
  |  Branch (1947:9): [True: 535, False: 17.4k]
  ------------------
 1948|    535|        int ok;
 1949|       |
 1950|    535|        ok = ssh_get_random(padding_data, padding_size, 0);
 1951|    535|        if (!ok) {
  ------------------
  |  Branch (1951:13): [True: 0, False: 535]
  ------------------
 1952|      0|            ssh_set_error(session, SSH_FATAL, "PRNG error");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1953|      0|            goto error;
 1954|      0|        }
 1955|    535|    }
 1956|       |
 1957|  18.0k|    finallen = currentlen - etm_packet_offset + padding_size + 1;
 1958|       |
 1959|  18.0k|    PUSH_BE_U32(header, 0, finallen);
  ------------------
  |  |   89|  18.0k|    (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|  18.0k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  18.0k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  18.0k|    (((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|  18.0k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  18.0k|    (((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|  18.0k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  18.0k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  18.0k|    (((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|  18.0k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  18.0k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1960|  18.0k|    PUSH_BE_U8(header, 4, padding_size);
  ------------------
  |  |   83|  18.0k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  ------------------
  |  |  |  |   31|  18.0k|    (((uint8_t *)(data))[(pos)])
  |  |  ------------------
  ------------------
 1961|       |
 1962|  18.0k|    rc = ssh_buffer_prepend_data(session->out_buffer,
 1963|  18.0k|                                 header,
 1964|  18.0k|                                 sizeof(header));
 1965|  18.0k|    if (rc < 0) {
  ------------------
  |  Branch (1965:9): [True: 0, False: 18.0k]
  ------------------
 1966|      0|        goto error;
 1967|      0|    }
 1968|       |
 1969|  18.0k|    rc = ssh_buffer_add_data(session->out_buffer, padding_data, padding_size);
 1970|  18.0k|    if (rc < 0) {
  ------------------
  |  Branch (1970:9): [True: 0, False: 18.0k]
  ------------------
 1971|      0|        goto error;
 1972|      0|    }
 1973|       |
 1974|  18.0k|#ifdef WITH_PCAP
 1975|  18.0k|    if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1975:9): [True: 0, False: 18.0k]
  ------------------
 1976|      0|        ssh_pcap_context_write(session->pcap_ctx,
 1977|      0|                               SSH_PCAP_DIR_OUT,
 1978|      0|                               ssh_buffer_get(session->out_buffer),
 1979|      0|                               ssh_buffer_get_len(session->out_buffer),
 1980|      0|                               ssh_buffer_get_len(session->out_buffer));
 1981|      0|    }
 1982|  18.0k|#endif
 1983|       |
 1984|  18.0k|    hmac = ssh_packet_encrypt(session,
 1985|  18.0k|                              ssh_buffer_get(session->out_buffer),
 1986|  18.0k|                              ssh_buffer_get_len(session->out_buffer));
 1987|       |    /* XXX This returns null before switching on crypto, with none MAC
 1988|       |     * and on various errors.
 1989|       |     * We should distinguish between these cases to avoid hiding errors. */
 1990|  18.0k|    if (hmac != NULL) {
  ------------------
  |  Branch (1990:9): [True: 535, False: 17.4k]
  ------------------
 1991|    535|        rc = ssh_buffer_add_data(session->out_buffer,
 1992|    535|                                 hmac,
 1993|    535|                                 (uint32_t)hmac_digest_len(hmac_type));
 1994|    535|        if (rc < 0) {
  ------------------
  |  Branch (1994:13): [True: 0, False: 535]
  ------------------
 1995|      0|            goto error;
 1996|      0|        }
 1997|    535|    }
 1998|       |
 1999|  18.0k|    rc = ssh_packet_write(session);
 2000|  18.0k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  18.0k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (2000:9): [True: 0, False: 18.0k]
  ------------------
 2001|      0|        goto error;
 2002|      0|    }
 2003|  18.0k|    session->send_seq++;
 2004|  18.0k|    if (crypto != NULL) {
  ------------------
  |  Branch (2004:9): [True: 535, False: 17.4k]
  ------------------
 2005|    535|        struct ssh_cipher_struct *cipher = NULL;
 2006|       |
 2007|    535|        cipher = crypto->out_cipher;
 2008|    535|        cipher->packets++;
 2009|    535|        cipher->blocks += payloadsize / cipher->blocksize;
 2010|    535|    }
 2011|  18.0k|    if (session->raw_counter != NULL) {
  ------------------
  |  Branch (2011:9): [True: 0, False: 18.0k]
  ------------------
 2012|      0|        session->raw_counter->out_bytes += payloadsize;
 2013|      0|        session->raw_counter->out_packets++;
 2014|      0|    }
 2015|       |
 2016|  18.0k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|  18.0k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2017|  18.0k|            "packet: wrote [type=%u, len=%" PRIu32 ", padding_size=%hhd, comp=%" PRIu32 ", "
 2018|  18.0k|            "payload=%" PRIu32 "]",
 2019|  18.0k|            type,
 2020|  18.0k|            finallen,
 2021|  18.0k|            padding_size,
 2022|  18.0k|            compsize,
 2023|  18.0k|            payloadsize);
 2024|       |
 2025|  18.0k|    rc = ssh_buffer_reinit(session->out_buffer);
 2026|  18.0k|    if (rc < 0) {
  ------------------
  |  Branch (2026:9): [True: 0, False: 18.0k]
  ------------------
 2027|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2028|      0|        goto error;
 2029|      0|    }
 2030|       |
 2031|       |    /* We sent the NEWKEYS so any further packet needs to be encrypted
 2032|       |     * with the new keys. We can not switch both directions (need to decrypt
 2033|       |     * peer NEWKEYS) and we do not want to wait for the peer NEWKEYS
 2034|       |     * too, so we will switch only the OUT direction now.
 2035|       |     */
 2036|  18.0k|    if (type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  18.0k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2036:9): [True: 33, False: 17.9k]
  ------------------
 2037|     33|        rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_OUT);
 2038|     33|    }
 2039|  18.0k|error:
 2040|  18.0k|    return rc; /* SSH_OK, AGAIN or ERROR */
 2041|  18.0k|}
packet.c:ssh_packet_write:
 1885|  18.0k|static int ssh_packet_write(ssh_session session) {
 1886|  18.0k|  int rc = SSH_ERROR;
  ------------------
  |  |  317|  18.0k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1887|       |
 1888|  18.0k|  rc=ssh_socket_write(session->socket,
 1889|  18.0k|      ssh_buffer_get(session->out_buffer),
 1890|  18.0k|      ssh_buffer_get_len(session->out_buffer));
 1891|       |
 1892|  18.0k|  return rc;
 1893|  18.0k|}
packet.c:ssh_init_rekey_state:
 2241|     66|{
 2242|       |    /* Reset the counters: should be NOOP */
 2243|     66|    cipher->packets = 0;
 2244|     66|    cipher->blocks = 0;
 2245|       |
 2246|       |    /* Default rekey limits for ciphers as specified in RFC4344, Section 3.2 */
 2247|     66|    if (cipher->blocksize >= 16) {
  ------------------
  |  Branch (2247:9): [True: 0, False: 66]
  ------------------
 2248|       |        /* For larger block size (L bits) use maximum of 2**(L/4) blocks */
 2249|      0|        cipher->max_blocks = (uint64_t)1 << (cipher->blocksize*2);
 2250|     66|    } else {
 2251|       |        /* For smaller blocks use limit of 1 GB as recommended in RFC4253 */
 2252|     66|        cipher->max_blocks = ((uint64_t)1 << 30) / cipher->blocksize;
 2253|     66|    }
 2254|       |    /* If we have limit provided by user, use the smaller one */
 2255|     66|    if (session->opts.rekey_data != 0) {
  ------------------
  |  Branch (2255:9): [True: 0, False: 66]
  ------------------
 2256|      0|        cipher->max_blocks = MIN(cipher->max_blocks,
  ------------------
  |  |  367|      0|#define MIN(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (367:19): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 2257|      0|                                 session->opts.rekey_data / cipher->blocksize);
 2258|      0|    }
 2259|       |
 2260|     66|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|     66|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2261|     66|            "Set rekey after %" PRIu64 " blocks",
 2262|     66|            cipher->max_blocks);
 2263|     66|}

ssh_packet_disconnect_callback:
   53|      3|{
   54|      3|    int rc;
   55|      3|    uint32_t code = 0;
   56|      3|    char *error = NULL;
   57|      3|    ssh_string error_s = NULL;
   58|       |
   59|      3|    (void)user;
   60|      3|    (void)type;
   61|       |
   62|      3|    rc = ssh_buffer_get_u32(packet, &code);
   63|      3|    if (rc != 0) {
  ------------------
  |  Branch (63:9): [True: 2, False: 1]
  ------------------
   64|      2|        code = ntohl(code);
   65|      2|    }
   66|       |
   67|      3|    error_s = ssh_buffer_get_ssh_string(packet);
   68|      3|    if (error_s != NULL) {
  ------------------
  |  Branch (68:9): [True: 0, False: 3]
  ------------------
   69|      0|        error = ssh_string_to_char(error_s);
   70|      0|        SSH_STRING_FREE(error_s);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
   71|      0|    }
   72|       |
   73|      3|    if (error != NULL) {
  ------------------
  |  Branch (73:9): [True: 0, False: 3]
  ------------------
   74|      0|        session->peer_discon_msg = strdup(error);
   75|      0|    }
   76|       |
   77|      3|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      6|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 0, False: 3]
  |  |  ------------------
  ------------------
   78|      3|            "Received SSH_MSG_DISCONNECT %" PRIu32 ":%s",
   79|      3|            code,
   80|      3|            error != NULL ? error : "no error");
   81|      3|    ssh_set_error(session,
  ------------------
  |  |  313|      6|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (313:43): [True: 0, False: 3]
  |  |  ------------------
  ------------------
   82|      3|                  SSH_FATAL,
   83|      3|                  "Received SSH_MSG_DISCONNECT: %" PRIu32 ":%s",
   84|      3|                  code,
   85|      3|                  error != NULL ? error : "no error");
   86|      3|    SAFE_FREE(error);
  ------------------
  |  |  375|      3|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 3]
  |  |  |  Branch (375:71): [Folded, False: 3]
  |  |  ------------------
  ------------------
   87|       |
   88|      3|    ssh_session_socket_close(session);
   89|       |    /* correctly handle disconnect during authorization */
   90|      3|    session->auth.state = SSH_AUTH_STATE_FAILED;
   91|       |
   92|       |    /* TODO: handle a graceful disconnect */
   93|      3|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      3|#define SSH_PACKET_USED 1
  ------------------
   94|      3|}
ssh_packet_ignore_callback:
  102|     41|{
  103|     41|    (void)session; /* unused */
  104|     41|    (void)user;
  105|     41|    (void)type;
  106|     41|    (void)packet;
  107|       |
  108|     41|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_IGNORE packet");
  ------------------
  |  |  283|     41|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  109|       |
  110|     41|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     41|#define SSH_PACKET_USED 1
  ------------------
  111|     41|}
ssh_packet_debug_callback:
  119|  12.7k|{
  120|  12.7k|    uint8_t always_display = -1;
  121|  12.7k|    char *message = NULL;
  122|  12.7k|    int rc;
  123|       |
  124|  12.7k|    (void)session; /* unused */
  125|  12.7k|    (void)type;
  126|  12.7k|    (void)user;
  127|       |
  128|  12.7k|    rc = ssh_buffer_unpack(packet, "bs", &always_display, &message);
  ------------------
  |  |   60|  12.7k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|  12.7k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|  12.7k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|  12.7k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|  12.7k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|  12.7k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  12.7k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  129|  12.7k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  12.7k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (129:9): [True: 11.0k, False: 1.70k]
  ------------------
  130|  11.0k|        SSH_LOG(SSH_LOG_PACKET, "Error reading debug message");
  ------------------
  |  |  283|  11.0k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  131|  11.0k|        return SSH_PACKET_USED;
  ------------------
  |  |  638|  11.0k|#define SSH_PACKET_USED 1
  ------------------
  132|  11.0k|    }
  133|  1.70k|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|  3.41k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 1.70k, False: 2]
  |  |  ------------------
  ------------------
  134|  1.70k|            "Received SSH_MSG_DEBUG packet with message %s%s",
  135|  1.70k|            message,
  136|  1.70k|            always_display != 0 ? " (always display)" : "");
  137|  1.70k|    SAFE_FREE(message);
  ------------------
  |  |  375|  1.70k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.70k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.70k]
  |  |  ------------------
  ------------------
  138|       |
  139|  1.70k|    return SSH_PACKET_USED;
  ------------------
  |  |  638|  1.70k|#define SSH_PACKET_USED 1
  ------------------
  140|  12.7k|}
ssh_packet_newkeys:
  143|     15|{
  144|     15|    ssh_string sig_blob = NULL;
  145|     15|    ssh_signature sig = NULL;
  146|     15|    int rc;
  147|       |
  148|     15|    (void)packet;
  149|     15|    (void)user;
  150|     15|    (void)type;
  151|       |
  152|     15|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_NEWKEYS");
  ------------------
  |  |  283|     15|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  153|       |
  154|     15|    if (session->session_state != SSH_SESSION_STATE_DH ||
  ------------------
  |  Branch (154:9): [True: 0, False: 15]
  ------------------
  155|     15|        session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (155:9): [True: 0, False: 15]
  ------------------
  156|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      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|     15|    if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|     15|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (164:9): [True: 1, False: 14]
  ------------------
  165|       |        /* reset packet sequence number when running in strict kex mode */
  166|      1|        session->recv_seq = 0;
  167|       |        /* Check that we aren't tainted */
  168|      1|        if (session->flags & SSH_SESSION_FLAG_KEX_TAINTED) {
  ------------------
  |  |   92|      1|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
  |  Branch (168:13): [True: 0, False: 1]
  ------------------
  169|      0|            ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  170|      0|                          SSH_FATAL,
  171|      0|                          "Received unexpected packets in strict KEX mode.");
  172|      0|            goto error;
  173|      0|        }
  174|      1|    }
  175|       |
  176|     15|    if (session->server) {
  ------------------
  |  Branch (176:9): [True: 0, False: 15]
  ------------------
  177|       |        /* server things are done in server.c */
  178|      0|        session->dh_handshake_state=DH_STATE_FINISHED;
  179|     15|    } 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|     15|        {
  218|     15|            ssh_key server_key = NULL;
  219|       |
  220|       |            /* client */
  221|       |
  222|       |            /* Verify the host's signature. FIXME do it sooner */
  223|     15|            sig_blob = session->next_crypto->dh_server_signature;
  224|     15|            session->next_crypto->dh_server_signature = NULL;
  225|       |
  226|       |            /* get the server public key */
  227|     15|            server_key = ssh_dh_get_next_server_publickey(session);
  228|     15|            if (server_key == NULL) {
  ------------------
  |  Branch (228:17): [True: 0, False: 15]
  ------------------
  229|      0|                goto error;
  230|      0|            }
  231|       |
  232|     15|            rc = ssh_pki_import_signature_blob(sig_blob, server_key, &sig);
  233|     15|            ssh_string_burn(sig_blob);
  234|     15|            SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  924|     15|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 15, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 15]
  |  |  ------------------
  ------------------
  235|     15|            if (rc != SSH_OK) {
  ------------------
  |  |  316|     15|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (235:17): [True: 13, False: 2]
  ------------------
  236|     13|                goto error;
  237|     13|            }
  238|       |
  239|       |            /* Check if signature from server matches user preferences */
  240|      2|            if (session->opts.wanted_methods[SSH_HOSTKEYS]) {
  ------------------
  |  Branch (240:17): [True: 0, False: 2]
  ------------------
  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(
  ------------------
  |  |  313|      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|      2|            rc = ssh_pki_signature_verify(session,
  256|      2|                                          sig,
  257|      2|                                          server_key,
  258|      2|                                          session->next_crypto->secret_hash,
  259|      2|                                          session->next_crypto->digest_len);
  260|      2|            SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|      2|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 2]
  |  |  ------------------
  ------------------
  261|      2|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (261:17): [True: 2, False: 0]
  ------------------
  262|      2|                ssh_set_error(session,
  ------------------
  |  |  313|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  263|      2|                              SSH_FATAL,
  264|      2|                              "Failed to verify server hostkey signature");
  265|      2|                goto error;
  266|      2|            }
  267|      2|        }
  268|      0|        SSH_LOG(SSH_LOG_DEBUG, "Signature verified and valid");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  269|       |
  270|       |        /* When receiving this packet, we switch on the incoming crypto. */
  271|      0|        rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_IN);
  272|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (272:13): [True: 0, False: 0]
  ------------------
  273|      0|            goto error;
  274|      0|        }
  275|      0|    }
  276|      0|    session->dh_handshake_state = DH_STATE_FINISHED;
  277|      0|    session->ssh_connection_callback(session);
  278|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  279|       |
  280|     15|error:
  281|       |#ifdef WITH_GSSAPI
  282|       |    SSH_STRING_FREE(session->gssapi_key_exchange_mic);
  283|       |#endif
  284|     15|    SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|     15|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 15]
  |  |  ------------------
  ------------------
  285|     15|    ssh_string_burn(sig_blob);
  286|     15|    SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  924|     15|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 15]
  |  |  |  Branch (924:69): [Folded, False: 15]
  |  |  ------------------
  ------------------
  287|     15|    session->session_state = SSH_SESSION_STATE_ERROR;
  288|     15|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     15|#define SSH_PACKET_USED 1
  ------------------
  289|     15|}
ssh_packet_ping:
  388|      2|{
  389|      2|    int rc;
  390|      2|    ssh_string payload = NULL;
  391|       |
  392|      2|    (void)type;
  393|      2|    (void)user;
  394|       |
  395|      2|    SSH_LOG(SSH_LOG_PACKET, "Received SSH2_MSG_PING");
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  396|       |
  397|       |    /* Drop PING before the initial key exchange completes. During rekeying,
  398|       |     * ssh_packet_send() queues the PONG response automatically via out_queue.
  399|       |     */
  400|      2|    if (!(session->flags & SSH_SESSION_FLAG_AUTHENTICATED) &&
  ------------------
  |  |   78|      2|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (400:9): [True: 2, False: 0]
  ------------------
  401|      2|        session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (401:9): [True: 2, False: 0]
  ------------------
  402|      2|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  403|      2|                "Ignoring PING before initial key exchange is complete");
  404|      2|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      2|#define SSH_PACKET_USED 1
  ------------------
  405|      2|    }
  406|       |
  407|      0|    payload = ssh_buffer_get_ssh_string(packet);
  408|      0|    if (payload == NULL) {
  ------------------
  |  Branch (408:9): [True: 0, False: 0]
  ------------------
  409|      0|        SSH_LOG(SSH_LOG_PACKET, "SSH2_MSG_PING: missing string payload");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  410|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  411|      0|                      SSH_FATAL,
  412|      0|                      "SSH2_MSG_PING: missing string payload");
  413|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  414|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  415|      0|    }
  416|       |
  417|      0|    if (ssh_buffer_get_len(packet) != 0) {
  ------------------
  |  Branch (417:9): [True: 0, False: 0]
  ------------------
  418|      0|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  419|      0|                "SSH2_MSG_PING: unexpected trailing data after payload");
  420|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  421|      0|                      SSH_FATAL,
  422|      0|                      "SSH2_MSG_PING: unexpected trailing data after payload");
  423|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  424|      0|        SSH_STRING_FREE(payload);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  425|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  426|      0|    }
  427|       |
  428|      0|    rc = ssh_buffer_pack(session->out_buffer, "bS", SSH2_MSG_PONG, payload);
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      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)
  |  |  ------------------
  ------------------
  429|      0|    SSH_STRING_FREE(payload);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  430|      0|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (430:9): [True: 0, False: 0]
  ------------------
  431|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  432|      0|        ssh_buffer_reinit(session->out_buffer);
  433|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  434|      0|    }
  435|       |
  436|      0|    rc = ssh_packet_send(session);
  437|      0|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (437:9): [True: 0, False: 0]
  ------------------
  438|      0|        SSH_LOG(SSH_LOG_PACKET, "Failed to send SSH2_MSG_PONG");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  439|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  440|      0|    }
  441|       |
  442|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  443|      0|}
ssh_packet_pong:
  454|      2|{
  455|      2|    const void *payload_data = NULL;
  456|      2|    ssh_string payload = NULL;
  457|      2|    size_t payload_len = 0;
  458|       |
  459|      2|    (void)type;
  460|      2|    (void)user;
  461|       |
  462|      2|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH2_MSG_PONG");
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  463|       |
  464|      2|    if (session->pending_pings == 0) {
  ------------------
  |  Branch (464:9): [True: 2, False: 0]
  ------------------
  465|      2|        SSH_LOG(SSH_LOG_PACKET, "Received unsolicited SSH2_MSG_PONG");
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  466|      2|        ssh_set_error(session, SSH_FATAL, "Received unsolicited SSH2_MSG_PONG");
  ------------------
  |  |  313|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  467|      2|        session->session_state = SSH_SESSION_STATE_ERROR;
  468|      2|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      2|#define SSH_PACKET_USED 1
  ------------------
  469|      2|    }
  470|       |
  471|      0|    payload = ssh_buffer_get_ssh_string(packet);
  472|      0|    if (payload == NULL) {
  ------------------
  |  Branch (472:9): [True: 0, False: 0]
  ------------------
  473|      0|        SSH_LOG(SSH_LOG_PACKET, "SSH2_MSG_PONG: missing string payload");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  474|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  475|      0|                      SSH_FATAL,
  476|      0|                      "SSH2_MSG_PONG: missing string payload");
  477|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  478|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  479|      0|    }
  480|       |
  481|      0|    if (ssh_buffer_get_len(packet) != 0) {
  ------------------
  |  Branch (481:9): [True: 0, False: 0]
  ------------------
  482|      0|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  483|      0|                "SSH2_MSG_PONG: unexpected trailing data after payload");
  484|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  485|      0|                      SSH_FATAL,
  486|      0|                      "SSH2_MSG_PONG: unexpected trailing data after payload");
  487|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  488|      0|        SSH_STRING_FREE(payload);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  489|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  490|      0|    }
  491|       |
  492|      0|    payload_data = ssh_string_data(payload);
  493|      0|    payload_len = ssh_string_len(payload);
  494|       |
  495|       |    /* If user provided a high-level PONG callback, decode and invoke it. */
  496|      0|    if (ssh_callbacks_exists(session->common.callbacks, pong_function)) {
  ------------------
  |  |  548|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  549|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  ------------------
  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  Branch (549:18): [True: 0, False: 0]
  |  |  ------------------
  |  |  550|      0|  ((p)-> c != NULL) \
  |  |  ------------------
  |  |  |  Branch (550:3): [True: 0, False: 0]
  |  |  ------------------
  |  |  551|      0|  )
  ------------------
  497|      0|        session->common.callbacks->pong_function(
  498|      0|            session,
  499|      0|            payload_data,
  500|      0|            payload_len,
  501|      0|            session->common.callbacks->userdata);
  502|      0|    }
  503|       |
  504|      0|    SSH_STRING_FREE(payload);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  505|      0|    session->pending_pings--;
  506|       |
  507|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  508|      0|}

ssh_packet_decrypt_len:
   55|  30.4k|{
   56|  30.4k|    struct ssh_crypto_struct *crypto = NULL;
   57|  30.4k|    uint32_t decrypted;
   58|  30.4k|    int rc;
   59|       |
   60|  30.4k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
   61|  30.4k|    if (crypto != NULL) {
  ------------------
  |  Branch (61:9): [True: 0, False: 30.4k]
  ------------------
   62|      0|        if (crypto->in_cipher->aead_decrypt_length != NULL) {
  ------------------
  |  Branch (62:13): [True: 0, False: 0]
  ------------------
   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|      0|        } else {
   68|      0|            rc = ssh_packet_decrypt(
   69|      0|                    session,
   70|      0|                    destination,
   71|      0|                    source,
   72|      0|                    0,
   73|      0|                    crypto->in_cipher->blocksize);
   74|      0|        }
   75|      0|        if (rc < 0) {
  ------------------
  |  Branch (75:13): [True: 0, False: 0]
  ------------------
   76|      0|            return 0;
   77|      0|        }
   78|  30.4k|    } else {
   79|  30.4k|        memcpy(destination, source, 8);
   80|  30.4k|    }
   81|  30.4k|    memcpy(&decrypted,destination,sizeof(decrypted));
   82|       |
   83|       |    return ntohl(decrypted);
   84|  30.4k|}
ssh_packet_encrypt:
  134|  18.0k|{
  135|  18.0k|  struct ssh_crypto_struct *crypto = NULL;
  136|  18.0k|  struct ssh_cipher_struct *cipher = NULL;
  137|  18.0k|  HMACCTX ctx = NULL;
  138|  18.0k|  char *out = NULL;
  139|  18.0k|  int etm_packet_offset = 0, rc;
  140|  18.0k|  unsigned int blocksize;
  141|  18.0k|  size_t finallen = DIGEST_MAX_LEN;
  ------------------
  |  |   56|  18.0k|#define DIGEST_MAX_LEN 64
  ------------------
  142|  18.0k|  uint32_t seq, lenfield_blocksize;
  143|  18.0k|  enum ssh_hmac_e type;
  144|  18.0k|  bool etm;
  145|       |
  146|  18.0k|  assert(len);
  ------------------
  |  Branch (146:3): [True: 0, False: 18.0k]
  |  Branch (146:3): [True: 18.0k, False: 0]
  ------------------
  147|       |
  148|  18.0k|  crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
  149|  18.0k|  if (crypto == NULL) {
  ------------------
  |  Branch (149:7): [True: 17.4k, False: 535]
  ------------------
  150|  17.4k|      return NULL; /* nothing to do here */
  151|  17.4k|  }
  152|       |
  153|    535|  blocksize = crypto->out_cipher->blocksize;
  154|    535|  lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
  155|       |
  156|    535|  type = crypto->out_hmac;
  157|    535|  etm = crypto->out_hmac_etm;
  158|       |
  159|    535|  if (etm) {
  ------------------
  |  Branch (159:7): [True: 0, False: 535]
  ------------------
  160|      0|      etm_packet_offset = sizeof(uint32_t);
  161|      0|  }
  162|       |
  163|    535|  if ((len - lenfield_blocksize - etm_packet_offset) % blocksize != 0) {
  ------------------
  |  Branch (163:7): [True: 0, False: 535]
  ------------------
  164|      0|      ssh_set_error(session, SSH_FATAL, "Cryptographic functions must be set"
  ------------------
  |  |  313|      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|    535|  out = calloc(1, len);
  169|    535|  if (out == NULL) {
  ------------------
  |  Branch (169:7): [True: 0, False: 535]
  ------------------
  170|      0|    return NULL;
  171|      0|  }
  172|       |
  173|    535|  seq = ntohl(session->send_seq);
  174|    535|  cipher = crypto->out_cipher;
  175|       |
  176|    535|  if (cipher->aead_encrypt != NULL) {
  ------------------
  |  Branch (176:7): [True: 0, False: 535]
  ------------------
  177|      0|      cipher->aead_encrypt(cipher, data, out, len,
  178|      0|            crypto->hmacbuf, session->send_seq);
  179|      0|      memcpy(data, out, len);
  180|    535|  } else {
  181|    535|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (181:11): [True: 0, False: 535]
  ------------------
  182|      0|          ctx = hmac_init(crypto->encryptMAC, hmac_digest_len(type), type);
  183|      0|          if (ctx == NULL) {
  ------------------
  |  Branch (183:15): [True: 0, False: 0]
  ------------------
  184|      0|              SAFE_FREE(out);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  185|      0|              return NULL;
  186|      0|          }
  187|       |
  188|      0|          if (!etm) {
  ------------------
  |  Branch (188:15): [True: 0, False: 0]
  ------------------
  189|      0|              rc = hmac_update(ctx, (unsigned char *)&seq, sizeof(uint32_t));
  190|      0|              if (rc != 1) {
  ------------------
  |  Branch (190:19): [True: 0, False: 0]
  ------------------
  191|      0|                  SAFE_FREE(out);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  192|      0|                  return NULL;
  193|      0|              }
  194|      0|              rc = hmac_update(ctx, data, len);
  195|      0|              if (rc != 1) {
  ------------------
  |  Branch (195:19): [True: 0, False: 0]
  ------------------
  196|      0|                  SAFE_FREE(out);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  197|      0|                  return NULL;
  198|      0|              }
  199|      0|              rc = hmac_final(ctx, crypto->hmacbuf, &finallen);
  200|      0|              if (rc != 1) {
  ------------------
  |  Branch (200:19): [True: 0, False: 0]
  ------------------
  201|      0|                  SAFE_FREE(out);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  202|      0|                  return NULL;
  203|      0|              }
  204|      0|          }
  205|      0|      }
  206|       |
  207|    535|      cipher->encrypt(cipher, (uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  208|    535|      memcpy((uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  209|       |
  210|    535|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (210:11): [True: 0, False: 535]
  ------------------
  211|      0|          if (etm) {
  ------------------
  |  Branch (211:15): [True: 0, False: 0]
  ------------------
  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);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375: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);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375: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);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375: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|      0|      }
  237|    535|  }
  238|    535|  ssh_burn(out, len);
  ------------------
  |  |  390|    535|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  239|    535|  SAFE_FREE(out);
  ------------------
  |  |  375|    535|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 535, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 535]
  |  |  ------------------
  ------------------
  240|       |
  241|    535|  return crypto->hmacbuf;
  242|    535|}

ssh_key_new:
  113|     56|{
  114|     56|    ssh_key ptr = malloc (sizeof (struct ssh_key_struct));
  115|     56|    if (ptr == NULL) {
  ------------------
  |  Branch (115:9): [True: 0, False: 56]
  ------------------
  116|      0|        return NULL;
  117|      0|    }
  118|     56|    ZERO_STRUCTP(ptr);
  ------------------
  |  |  381|     56|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (381:34): [True: 56, False: 0]
  |  |  |  Branch (381:85): [Folded, False: 56]
  |  |  ------------------
  ------------------
  119|     56|    return ptr;
  120|     56|}
ssh_key_clean:
  222|     56|{
  223|     56|    if (key == NULL)
  ------------------
  |  Branch (223:9): [True: 0, False: 56]
  ------------------
  224|      0|        return;
  225|       |
  226|     56|    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|     56|    if (key->cert != NULL) {
  ------------------
  |  Branch (235:9): [True: 3, False: 53]
  ------------------
  236|      3|        SSH_BUFFER_FREE(key->cert);
  ------------------
  |  |  966|      3|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 3, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 3]
  |  |  ------------------
  ------------------
  237|      3|    }
  238|     56|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|     56|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 3, False: 53]
  |  |  |  Branch (153:38): [True: 1, False: 52]
  |  |  ------------------
  |  |  154|     56|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 3, False: 49]
  |  |  ------------------
  |  |  155|     56|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 49]
  |  |  ------------------
  ------------------
  239|      7|        ssh_string_burn(key->sk_application);
  240|      7|        ssh_string_free(key->sk_application);
  241|      7|        ssh_string_burn(key->sk_key_handle);
  242|      7|        ssh_string_free(key->sk_key_handle);
  243|      7|        ssh_string_burn(key->sk_reserved);
  244|      7|        ssh_string_free(key->sk_reserved);
  245|      7|        ssh_string_burn(key->sk_user_id);
  246|      7|        ssh_string_free(key->sk_user_id);
  247|      7|        key->sk_flags = 0;
  248|      7|    }
  249|     56|    key->cert_type = SSH_KEYTYPE_UNKNOWN;
  250|     56|    key->flags = SSH_KEY_FLAG_EMPTY;
  ------------------
  |  |   53|     56|#define SSH_KEY_FLAG_EMPTY   0x0
  ------------------
  251|     56|    key->type = SSH_KEYTYPE_UNKNOWN;
  252|     56|    key->ecdsa_nid = 0;
  253|       |    key->type_c = NULL;
  254|     56|}
ssh_key_free:
  261|  3.22k|{
  262|  3.22k|    if (key) {
  ------------------
  |  Branch (262:9): [True: 56, False: 3.16k]
  ------------------
  263|     56|        ssh_key_clean(key);
  264|       |        SAFE_FREE(key);
  ------------------
  |  |  375|     56|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 56, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 56]
  |  |  ------------------
  ------------------
  265|     56|    }
  266|  3.22k|}
ssh_key_type:
  280|      2|{
  281|      2|    if (key == NULL) {
  ------------------
  |  Branch (281:9): [True: 0, False: 2]
  ------------------
  282|      0|        return SSH_KEYTYPE_UNKNOWN;
  283|      0|    }
  284|      2|    return key->type;
  285|      2|}
ssh_key_signature_to_char:
  367|      2|{
  368|      2|    switch (type) {
  369|      2|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (369:5): [True: 2, False: 0]
  ------------------
  370|      2|        switch (hash_type) {
  371|      0|        case SSH_DIGEST_SHA256:
  ------------------
  |  Branch (371:9): [True: 0, False: 2]
  ------------------
  372|      0|            return "rsa-sha2-256";
  373|      2|        case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (373:9): [True: 2, False: 0]
  ------------------
  374|      2|            return "rsa-sha2-512";
  375|      0|        case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (375:9): [True: 0, False: 2]
  ------------------
  376|      0|        case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (376:9): [True: 0, False: 2]
  ------------------
  377|      0|            return "ssh-rsa";
  378|      0|        default:
  ------------------
  |  Branch (378:9): [True: 0, False: 2]
  ------------------
  379|      0|            return NULL;
  380|      2|        }
  381|      0|        break;
  382|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (382:5): [True: 0, False: 2]
  ------------------
  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|      0|    default:
  ------------------
  |  Branch (395:5): [True: 0, False: 2]
  ------------------
  396|      0|        return ssh_key_type_to_char(type);
  397|      2|    }
  398|       |
  399|       |    /* We should never reach this */
  400|      0|    return NULL;
  401|      2|}
ssh_key_type_to_char:
  410|     70|const char *ssh_key_type_to_char(enum ssh_keytypes_e type) {
  411|     70|  switch (type) {
  ------------------
  |  Branch (411:11): [True: 70, False: 0]
  ------------------
  412|     41|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (412:5): [True: 41, False: 29]
  ------------------
  413|     41|      return "ssh-rsa";
  414|      0|    case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (414:5): [True: 0, False: 70]
  ------------------
  415|      0|      return "ssh-ecdsa"; /* deprecated. invalid value */
  416|      3|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (416:5): [True: 3, False: 67]
  ------------------
  417|      3|      return "ecdsa-sha2-nistp256";
  418|      1|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (418:5): [True: 1, False: 69]
  ------------------
  419|      1|      return "ecdsa-sha2-nistp384";
  420|      1|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (420:5): [True: 1, False: 69]
  ------------------
  421|      1|      return "ecdsa-sha2-nistp521";
  422|      3|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (422:5): [True: 3, False: 67]
  ------------------
  423|      3|      return "ssh-ed25519";
  424|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (424:5): [True: 0, False: 70]
  ------------------
  425|      0|      return "ssh-rsa-cert-v01@openssh.com";
  426|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (426:5): [True: 0, False: 70]
  ------------------
  427|      0|      return "ecdsa-sha2-nistp256-cert-v01@openssh.com";
  428|      0|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (428:5): [True: 0, False: 70]
  ------------------
  429|      0|      return "ecdsa-sha2-nistp384-cert-v01@openssh.com";
  430|      0|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (430:5): [True: 0, False: 70]
  ------------------
  431|      0|      return "ecdsa-sha2-nistp521-cert-v01@openssh.com";
  432|      2|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (432:5): [True: 2, False: 68]
  ------------------
  433|      2|      return "ssh-ed25519-cert-v01@openssh.com";
  434|      9|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (434:5): [True: 9, False: 61]
  ------------------
  435|      9|      return "sk-ecdsa-sha2-nistp256@openssh.com";
  436|      1|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (436:5): [True: 1, False: 69]
  ------------------
  437|      1|      return "sk-ssh-ed25519@openssh.com";
  438|      7|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (438:5): [True: 7, False: 63]
  ------------------
  439|      7|      return "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com";
  440|      2|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (440:5): [True: 2, False: 68]
  ------------------
  441|      2|      return "sk-ssh-ed25519-cert-v01@openssh.com";
  442|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (442:5): [True: 0, False: 70]
  ------------------
  443|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (443:5): [True: 0, False: 70]
  ------------------
  444|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (444:5): [True: 0, False: 70]
  ------------------
  445|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (445:5): [True: 0, False: 70]
  ------------------
  446|      0|      return NULL;
  447|     70|  }
  448|       |
  449|       |  /* We should never reach this */
  450|      0|  return NULL;
  451|     70|}
ssh_key_type_and_hash_from_signature_name:
  472|     15|{
  473|     15|    size_t len;
  474|       |
  475|     15|    if (name == NULL || type == NULL || hash_type == NULL) {
  ------------------
  |  Branch (475:9): [True: 0, False: 15]
  |  Branch (475:25): [True: 0, False: 15]
  |  Branch (475:41): [True: 0, False: 15]
  ------------------
  476|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  477|      0|    }
  478|       |
  479|     15|    len = strlen(name);
  480|       |
  481|     15|    if (len == 7 && strcmp(name, "ssh-rsa") == 0) {
  ------------------
  |  Branch (481:9): [True: 1, False: 14]
  |  Branch (481:21): [True: 0, False: 1]
  ------------------
  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|     15|    if (len == 11 && strcmp(name, "ssh-ed25519") == 0) {
  ------------------
  |  Branch (487:9): [True: 0, False: 15]
  |  Branch (487:22): [True: 0, False: 0]
  ------------------
  488|      0|        *type = SSH_KEYTYPE_ED25519;
  489|      0|        *hash_type = SSH_DIGEST_AUTO;
  490|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  491|      0|    }
  492|       |
  493|     15|    if (len == 12) {
  ------------------
  |  Branch (493:9): [True: 5, False: 10]
  ------------------
  494|      5|        if (strcmp(name, "rsa-sha2-256") == 0) {
  ------------------
  |  Branch (494:13): [True: 0, False: 5]
  ------------------
  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|      5|        if (strcmp(name, "rsa-sha2-512") == 0) {
  ------------------
  |  Branch (499:13): [True: 2, False: 3]
  ------------------
  500|      2|            *type = SSH_KEYTYPE_RSA;
  501|      2|            *hash_type = SSH_DIGEST_SHA512;
  502|      2|            return SSH_OK;
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
  503|      2|        }
  504|      5|    }
  505|       |
  506|     13|    if (len == 19) {
  ------------------
  |  Branch (506:9): [True: 1, False: 12]
  ------------------
  507|      1|        if (strcmp(name, "ecdsa-sha2-nistp256") == 0) {
  ------------------
  |  Branch (507:13): [True: 0, False: 1]
  ------------------
  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|      1|        if (strcmp(name, "ecdsa-sha2-nistp384") == 0) {
  ------------------
  |  Branch (512:13): [True: 0, False: 1]
  ------------------
  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|      1|        if (strcmp(name, "ecdsa-sha2-nistp521") == 0) {
  ------------------
  |  Branch (518:13): [True: 0, False: 1]
  ------------------
  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|      1|    }
  524|       |
  525|     13|    if (len == 26 && strcmp(name, "sk-ssh-ed25519@openssh.com") == 0) {
  ------------------
  |  Branch (525:9): [True: 0, False: 13]
  |  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|     13|    if (len == 28 && strcmp(name, "ssh-rsa-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (531:9): [True: 1, False: 12]
  |  Branch (531:22): [True: 0, False: 1]
  ------------------
  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|     13|    if (len == 32 && strcmp(name, "ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (537:9): [True: 1, False: 12]
  |  Branch (537:22): [True: 0, False: 1]
  ------------------
  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|     13|    if (len == 33) {
  ------------------
  |  Branch (543:9): [True: 2, False: 11]
  ------------------
  544|      2|        if (strcmp(name, "rsa-sha2-256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (544:13): [True: 1, False: 1]
  ------------------
  545|      1|            *type = SSH_KEYTYPE_RSA_CERT01;
  546|      1|            *hash_type = SSH_DIGEST_SHA256;
  547|      1|            return SSH_OK;
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  548|      1|        }
  549|      1|        if (strcmp(name, "rsa-sha2-512-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (549:13): [True: 1, False: 0]
  ------------------
  550|      1|            *type = SSH_KEYTYPE_RSA_CERT01;
  551|      1|            *hash_type = SSH_DIGEST_SHA512;
  552|      1|            return SSH_OK;
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  553|      1|        }
  554|      1|    }
  555|       |
  556|     11|    if (len == 34 && strcmp(name, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (556:9): [True: 1, False: 10]
  |  Branch (556:22): [True: 0, False: 1]
  ------------------
  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|     11|    if (len == 40) {
  ------------------
  |  Branch (562:9): [True: 0, False: 11]
  ------------------
  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|     11|    SSH_LOG(SSH_LOG_TRACE, "Unknown signature name %s", name);
  ------------------
  |  |  283|     11|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  581|     11|    return SSH_ERROR;
  ------------------
  |  |  317|     11|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  582|     11|}
ssh_key_size_allowed_rsa:
  624|      2|{
  625|      2|    int key_size = ssh_key_size(key);
  626|       |
  627|      2|    if (min_size < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|      2|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (627:9): [True: 2, False: 0]
  ------------------
  628|      2|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|      2|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 2]
  |  |  ------------------
  ------------------
  629|      0|            min_size = RSA_MIN_FIPS_KEY_SIZE;
  ------------------
  |  |   50|      0|#define RSA_MIN_FIPS_KEY_SIZE 2048
  ------------------
  630|      2|        } else {
  631|      2|            min_size = RSA_MIN_KEY_SIZE;
  ------------------
  |  |   49|      2|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  632|      2|        }
  633|      2|    }
  634|      2|    return (key_size >= min_size);
  635|      2|}
ssh_key_size_allowed:
  646|      2|{
  647|      2|    int min_size = 0;
  648|       |
  649|      2|    switch (ssh_key_type(key)) {
  650|      2|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (650:5): [True: 2, False: 0]
  ------------------
  651|      2|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (651:5): [True: 0, False: 2]
  ------------------
  652|      2|        min_size = session->opts.rsa_min_size;
  653|      2|        return ssh_key_size_allowed_rsa(min_size, key);
  654|      0|    default:
  ------------------
  |  Branch (654:5): [True: 0, False: 2]
  ------------------
  655|       |        return true;
  656|      2|    }
  657|      2|}
ssh_key_type_from_name:
  808|    138|{
  809|    138|    if (name == NULL) {
  ------------------
  |  Branch (809:9): [True: 0, False: 138]
  ------------------
  810|      0|        return SSH_KEYTYPE_UNKNOWN;
  811|      0|    }
  812|       |
  813|    138|    if (strcmp(name, "rsa") == 0) {
  ------------------
  |  Branch (813:9): [True: 0, False: 138]
  ------------------
  814|      0|        return SSH_KEYTYPE_RSA;
  815|    138|    } else if (strcmp(name, "ssh-rsa") == 0) {
  ------------------
  |  Branch (815:16): [True: 41, False: 97]
  ------------------
  816|     41|        return SSH_KEYTYPE_RSA;
  817|     97|    } else if (strcmp(name, "ssh-ecdsa") == 0
  ------------------
  |  Branch (817:16): [True: 0, False: 97]
  ------------------
  818|     97|            || strcmp(name, "ecdsa") == 0
  ------------------
  |  Branch (818:16): [True: 2, False: 95]
  ------------------
  819|     95|            || strcmp(name, "ecdsa-sha2-nistp256") == 0) {
  ------------------
  |  Branch (819:16): [True: 1, False: 94]
  ------------------
  820|      3|        return SSH_KEYTYPE_ECDSA_P256;
  821|     94|    } else if (strcmp(name, "ecdsa-sha2-nistp384") == 0) {
  ------------------
  |  Branch (821:16): [True: 1, False: 93]
  ------------------
  822|      1|        return SSH_KEYTYPE_ECDSA_P384;
  823|     93|    } else if (strcmp(name, "ecdsa-sha2-nistp521") == 0) {
  ------------------
  |  Branch (823:16): [True: 1, False: 92]
  ------------------
  824|      1|        return SSH_KEYTYPE_ECDSA_P521;
  825|     92|    } else if (strcmp(name, "ssh-ed25519") == 0){
  ------------------
  |  Branch (825:16): [True: 1, False: 91]
  ------------------
  826|      1|        return SSH_KEYTYPE_ED25519;
  827|     91|    } else if (strcmp(name, "ssh-rsa-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (827:16): [True: 0, False: 91]
  ------------------
  828|      0|        return SSH_KEYTYPE_RSA_CERT01;
  829|     91|    } else if (strcmp(name, "ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (829:16): [True: 0, False: 91]
  ------------------
  830|      0|        return SSH_KEYTYPE_ECDSA_P256_CERT01;
  831|     91|    } else if (strcmp(name, "ecdsa-sha2-nistp384-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (831:16): [True: 0, False: 91]
  ------------------
  832|      0|        return SSH_KEYTYPE_ECDSA_P384_CERT01;
  833|     91|    } else if (strcmp(name, "ecdsa-sha2-nistp521-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (833:16): [True: 0, False: 91]
  ------------------
  834|      0|        return SSH_KEYTYPE_ECDSA_P521_CERT01;
  835|     91|    } else if (strcmp(name, "ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (835:16): [True: 2, False: 89]
  ------------------
  836|      2|        return SSH_KEYTYPE_ED25519_CERT01;
  837|     89|    } else if(strcmp(name, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (837:15): [True: 0, False: 89]
  ------------------
  838|      0|        return SSH_KEYTYPE_SK_ECDSA;
  839|     89|    } else if(strcmp(name, "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (839:15): [True: 7, False: 82]
  ------------------
  840|      7|        return SSH_KEYTYPE_SK_ECDSA_CERT01;
  841|     82|    } else if(strcmp(name, "sk-ssh-ed25519@openssh.com") == 0) {
  ------------------
  |  Branch (841:15): [True: 0, False: 82]
  ------------------
  842|      0|        return SSH_KEYTYPE_SK_ED25519;
  843|     82|    } else if(strcmp(name, "sk-ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (843:15): [True: 2, False: 80]
  ------------------
  844|      2|        return SSH_KEYTYPE_SK_ED25519_CERT01;
  845|      2|    }
  846|       |
  847|     80|    return SSH_KEYTYPE_UNKNOWN;
  848|    138|}
ssh_key_type_plain:
  858|      6|{
  859|      6|    switch (type) {
  860|      0|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (860:9): [True: 0, False: 6]
  ------------------
  861|      0|            return SSH_KEYTYPE_RSA;
  862|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (862:9): [True: 0, False: 6]
  ------------------
  863|      0|            return SSH_KEYTYPE_ECDSA_P256;
  864|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (864:9): [True: 0, False: 6]
  ------------------
  865|      0|            return SSH_KEYTYPE_ECDSA_P384;
  866|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (866:9): [True: 0, False: 6]
  ------------------
  867|      0|            return SSH_KEYTYPE_ECDSA_P521;
  868|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (868:9): [True: 0, False: 6]
  ------------------
  869|      0|            return SSH_KEYTYPE_ED25519;
  870|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (870:9): [True: 0, False: 6]
  ------------------
  871|      0|            return SSH_KEYTYPE_SK_ECDSA;
  872|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (872:9): [True: 0, False: 6]
  ------------------
  873|      0|            return SSH_KEYTYPE_SK_ED25519;
  874|      6|        default:
  ------------------
  |  Branch (874:9): [True: 6, False: 0]
  ------------------
  875|      6|            return type;
  876|      6|    }
  877|      6|}
ssh_key_is_private:
  902|      2|int ssh_key_is_private(const ssh_key k) {
  903|      2|    if (k == NULL) {
  ------------------
  |  Branch (903:9): [True: 0, False: 2]
  ------------------
  904|      0|        return 0;
  905|      0|    }
  906|       |
  907|      2|    return (k->flags & SSH_KEY_FLAG_PRIVATE) == SSH_KEY_FLAG_PRIVATE;
  ------------------
  |  |   55|      2|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
                  return (k->flags & SSH_KEY_FLAG_PRIVATE) == SSH_KEY_FLAG_PRIVATE;
  ------------------
  |  |   55|      2|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
  908|      2|}
ssh_signature_new:
  997|      2|{
  998|      2|    struct ssh_signature_struct *sig = NULL;
  999|       |
 1000|      2|    sig = calloc(1, sizeof(struct ssh_signature_struct));
 1001|      2|    if (sig == NULL) {
  ------------------
  |  Branch (1001:9): [True: 0, False: 2]
  ------------------
 1002|      0|        return NULL;
 1003|      0|    }
 1004|       |
 1005|      2|    return sig;
 1006|      2|}
ssh_signature_free:
 1009|     17|{
 1010|     17|    if (sig == NULL) {
  ------------------
  |  Branch (1010:9): [True: 15, False: 2]
  ------------------
 1011|     15|        return;
 1012|     15|    }
 1013|       |
 1014|      2|    switch(sig->type) {
  ------------------
  |  Branch (1014:12): [True: 2, False: 0]
  ------------------
 1015|      2|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1015:9): [True: 2, False: 0]
  ------------------
 1016|       |#ifdef HAVE_LIBMBEDCRYPTO
 1017|       |            SAFE_FREE(sig->rsa_sig);
 1018|       |#endif /* HAVE_LIBMBEDCRYPTO */
 1019|      2|            break;
 1020|      0|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1020:9): [True: 0, False: 2]
  ------------------
 1021|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1021:9): [True: 0, False: 2]
  ------------------
 1022|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1022:9): [True: 0, False: 2]
  ------------------
 1023|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1023:9): [True: 0, False: 2]
  ------------------
 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|      0|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1031:9): [True: 0, False: 2]
  ------------------
 1032|      0|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1032:9): [True: 0, False: 2]
  ------------------
 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|      0|            break;
 1038|      0|        case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (1038:9): [True: 0, False: 2]
  ------------------
 1039|      0|        case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (1039:9): [True: 0, False: 2]
  ------------------
 1040|      0|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1040:9): [True: 0, False: 2]
  ------------------
 1041|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1041:9): [True: 0, False: 2]
  ------------------
 1042|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1042:9): [True: 0, False: 2]
  ------------------
 1043|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1043:9): [True: 0, False: 2]
  ------------------
 1044|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1044:9): [True: 0, False: 2]
  ------------------
 1045|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1045:9): [True: 0, False: 2]
  ------------------
 1046|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1046:9): [True: 0, False: 2]
  ------------------
 1047|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1047:9): [True: 0, False: 2]
  ------------------
 1048|      0|        case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (1048:9): [True: 0, False: 2]
  ------------------
 1049|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1049:9): [True: 0, False: 2]
  ------------------
 1050|      0|            break;
 1051|      2|    }
 1052|       |
 1053|       |    /* Explicitly zero the signature content before free */
 1054|      2|    ssh_string_burn(sig->raw_sig);
 1055|      2|    SSH_STRING_FREE(sig->raw_sig);
  ------------------
  |  |  924|      2|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 2, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 2]
  |  |  ------------------
  ------------------
 1056|       |    SAFE_FREE(sig);
  ------------------
  |  |  375|      2|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 2]
  |  |  ------------------
  ------------------
 1057|      2|}
ssh_pki_import_pubkey_blob:
 2027|    140|{
 2028|    140|    ssh_buffer buffer = NULL;
 2029|    140|    ssh_string type_s = NULL;
 2030|    140|    enum ssh_keytypes_e type;
 2031|    140|    int rc;
 2032|       |
 2033|    140|    if (key_blob == NULL || pkey == NULL) {
  ------------------
  |  Branch (2033:9): [True: 0, False: 140]
  |  Branch (2033:29): [True: 0, False: 140]
  ------------------
 2034|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2035|      0|    }
 2036|       |
 2037|    140|    buffer = ssh_buffer_new();
 2038|    140|    if (buffer == NULL) {
  ------------------
  |  Branch (2038:9): [True: 0, False: 140]
  ------------------
 2039|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  283|      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|    140|    rc = ssh_buffer_add_data(buffer,
 2044|    140|                             ssh_string_data(key_blob),
 2045|    140|                             (uint32_t)ssh_string_len(key_blob));
 2046|    140|    if (rc < 0) {
  ------------------
  |  Branch (2046:9): [True: 0, False: 140]
  ------------------
 2047|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2048|      0|        goto fail;
 2049|      0|    }
 2050|       |
 2051|    140|    type_s = ssh_buffer_get_ssh_string(buffer);
 2052|    140|    if (type_s == NULL) {
  ------------------
  |  Branch (2052:9): [True: 2, False: 138]
  ------------------
 2053|      2|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2054|      2|        goto fail;
 2055|      2|    }
 2056|       |
 2057|    138|    type = ssh_key_type_from_name(ssh_string_get_char(type_s));
 2058|    138|    if (type == SSH_KEYTYPE_UNKNOWN) {
  ------------------
  |  Branch (2058:9): [True: 80, False: 58]
  ------------------
 2059|     80|        SSH_LOG(SSH_LOG_TRACE, "Unknown key type found!");
  ------------------
  |  |  283|     80|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2060|     80|        goto fail;
 2061|     80|    }
 2062|     58|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  924|     58|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 58, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 58]
  |  |  ------------------
  ------------------
 2063|       |
 2064|     58|    if (is_cert_type(type)) {
  ------------------
  |  |  146|     58|    ((kt) == SSH_KEYTYPE_RSA_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (146:6): [True: 0, False: 58]
  |  |  ------------------
  |  |  147|     58|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (147:6): [True: 7, False: 51]
  |  |  ------------------
  |  |  148|     58|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (148:6): [True: 2, False: 49]
  |  |  ------------------
  |  |  149|     58|    ((kt) >= SSH_KEYTYPE_ECDSA_P256_CERT01 &&\
  |  |  ------------------
  |  |  |  Branch (149:6): [True: 2, False: 47]
  |  |  ------------------
  |  |  150|     49|     (kt) <= SSH_KEYTYPE_ED25519_CERT01))
  |  |  ------------------
  |  |  |  Branch (150:6): [True: 2, False: 0]
  |  |  ------------------
  ------------------
 2065|     11|        rc = pki_import_cert_buffer(buffer, type, pkey);
 2066|     47|    } else {
 2067|     47|        rc = pki_import_pubkey_buffer(buffer, type, pkey);
 2068|     47|    }
 2069|       |
 2070|     58|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  966|     58|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 58, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 58]
  |  |  ------------------
  ------------------
 2071|       |
 2072|     58|    return rc;
 2073|     82|fail:
 2074|     82|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  966|     82|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 82, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 82]
  |  |  ------------------
  ------------------
 2075|     82|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  924|     82|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 80, False: 2]
  |  |  |  Branch (924:69): [Folded, False: 82]
  |  |  ------------------
  ------------------
 2076|       |
 2077|     82|    return SSH_ERROR;
  ------------------
  |  |  317|     82|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2078|    138|}
ssh_pki_export_pubkey_blob:
 2666|     33|{
 2667|     33|    ssh_string blob = NULL;
 2668|       |
 2669|     33|    if (key == NULL) {
  ------------------
  |  Branch (2669:9): [True: 0, False: 33]
  ------------------
 2670|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2671|      0|    }
 2672|       |
 2673|     33|    blob = pki_key_to_blob(key, SSH_KEY_PUBLIC);
 2674|     33|    if (blob == NULL) {
  ------------------
  |  Branch (2674:9): [True: 0, False: 33]
  ------------------
 2675|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2676|      0|    }
 2677|       |
 2678|     33|    *pblob = blob;
 2679|     33|    return SSH_OK;
  ------------------
  |  |  316|     33|#define SSH_OK 0     /* No error */
  ------------------
 2680|     33|}
ssh_pki_import_signature_blob:
 2947|     15|{
 2948|     15|    ssh_signature sig = NULL;
 2949|     15|    enum ssh_keytypes_e type;
 2950|     15|    enum ssh_digest_e hash_type;
 2951|     15|    ssh_string algorithm = NULL, blob = NULL;
 2952|     15|    ssh_buffer buf = NULL;
 2953|     15|    const char *alg = NULL;
 2954|     15|    uint8_t flags = 0;
 2955|     15|    uint32_t counter = 0;
 2956|     15|    int rc;
 2957|       |
 2958|     15|    if (sig_blob == NULL || psig == NULL) {
  ------------------
  |  Branch (2958:9): [True: 0, False: 15]
  |  Branch (2958:29): [True: 0, False: 15]
  ------------------
 2959|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2960|      0|    }
 2961|       |
 2962|     15|    buf = ssh_buffer_new();
 2963|     15|    if (buf == NULL) {
  ------------------
  |  Branch (2963:9): [True: 0, False: 15]
  ------------------
 2964|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2965|      0|    }
 2966|       |
 2967|     15|    rc = ssh_buffer_add_data(buf,
 2968|     15|                             ssh_string_data(sig_blob),
 2969|     15|                             (uint32_t)ssh_string_len(sig_blob));
 2970|     15|    if (rc < 0) {
  ------------------
  |  Branch (2970:9): [True: 0, False: 15]
  ------------------
 2971|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2972|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2973|      0|    }
 2974|       |
 2975|     15|    algorithm = ssh_buffer_get_ssh_string(buf);
 2976|     15|    if (algorithm == NULL) {
  ------------------
  |  Branch (2976:9): [True: 0, False: 15]
  ------------------
 2977|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2978|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2979|      0|    }
 2980|       |
 2981|     15|    alg = ssh_string_get_char(algorithm);
 2982|     15|    rc = ssh_key_type_and_hash_from_signature_name(alg, &type, &hash_type);
 2983|     15|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     15|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2983:9): [True: 11, False: 4]
  ------------------
 2984|     11|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  966|     11|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 11, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 11]
  |  |  ------------------
  ------------------
 2985|     11|        SSH_STRING_FREE(algorithm);
  ------------------
  |  |  924|     11|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 11, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 11]
  |  |  ------------------
  ------------------
 2986|     11|        return SSH_ERROR;
  ------------------
  |  |  317|     11|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2987|     11|    }
 2988|      4|    SSH_STRING_FREE(algorithm);
  ------------------
  |  |  924|      4|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 4, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 4]
  |  |  ------------------
  ------------------
 2989|       |
 2990|      4|    blob = ssh_buffer_get_ssh_string(buf);
 2991|      4|    if (blob == NULL) {
  ------------------
  |  Branch (2991:9): [True: 0, False: 4]
  ------------------
 2992|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2993|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2994|      0|    }
 2995|       |
 2996|      4|    if (type == SSH_KEYTYPE_SK_ECDSA ||
  ------------------
  |  Branch (2996:9): [True: 0, False: 4]
  ------------------
 2997|      4|        type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (2997:9): [True: 0, False: 4]
  ------------------
 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)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      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);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3001|      0|            SSH_STRING_FREE(blob);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3002|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3003|      0|        }
 3004|      0|    }
 3005|      4|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  966|      4|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 4, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 4]
  |  |  ------------------
  ------------------
 3006|       |
 3007|      4|    sig = pki_signature_from_blob(pubkey, blob, type, hash_type);
 3008|      4|    SSH_STRING_FREE(blob);
  ------------------
  |  |  924|      4|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 4, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 4]
  |  |  ------------------
  ------------------
 3009|      4|    if (sig == NULL) {
  ------------------
  |  Branch (3009:9): [True: 2, False: 2]
  ------------------
 3010|      2|        return SSH_ERROR;
  ------------------
  |  |  317|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3011|      2|    }
 3012|       |
 3013|       |    /* Set SK specific values */
 3014|      2|    sig->sk_flags = flags;
 3015|      2|    sig->sk_counter = counter;
 3016|       |
 3017|      2|    *psig = sig;
 3018|      2|    return SSH_OK;
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
 3019|      4|}
pki_key_check_hash_compatible:
 3034|      4|{
 3035|      4|    if (key == NULL) {
  ------------------
  |  Branch (3035:9): [True: 0, False: 4]
  ------------------
 3036|      0|        SSH_LOG(SSH_LOG_TRACE, "Null pointer provided as key to "
  ------------------
  |  |  283|      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|      4|    switch(key->type) {
  ------------------
  |  Branch (3041:12): [True: 4, False: 0]
  ------------------
 3042|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (3042:5): [True: 0, False: 4]
  ------------------
 3043|      4|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (3043:5): [True: 4, False: 0]
  ------------------
 3044|      4|        if (hash_type == SSH_DIGEST_SHA1) {
  ------------------
  |  Branch (3044:13): [True: 0, False: 4]
  ------------------
 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");
  ------------------
  |  |  283|      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|      4|        if (hash_type == SSH_DIGEST_SHA256 ||
  ------------------
  |  Branch (3053:13): [True: 0, False: 4]
  ------------------
 3054|      4|            hash_type == SSH_DIGEST_SHA512)
  ------------------
  |  Branch (3054:13): [True: 4, False: 0]
  ------------------
 3055|      4|        {
 3056|      4|            return SSH_OK;
  ------------------
  |  |  316|      4|#define SSH_OK 0     /* No error */
  ------------------
 3057|      4|        }
 3058|      0|        break;
 3059|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (3059:5): [True: 0, False: 4]
  ------------------
 3060|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (3060:5): [True: 0, False: 4]
  ------------------
 3061|      0|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (3061:5): [True: 0, False: 4]
  ------------------
 3062|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (3062:5): [True: 0, False: 4]
  ------------------
 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: 4]
  ------------------
 3068|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (3068:5): [True: 0, False: 4]
  ------------------
 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: 4]
  ------------------
 3074|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (3074:5): [True: 0, False: 4]
  ------------------
 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: 4]
  ------------------
 3080|      0|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (3080:5): [True: 0, False: 4]
  ------------------
 3081|      0|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (3081:5): [True: 0, False: 4]
  ------------------
 3082|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (3082:5): [True: 0, False: 4]
  ------------------
 3083|      0|        if (hash_type == SSH_DIGEST_AUTO) {
  ------------------
  |  Branch (3083:13): [True: 0, False: 0]
  ------------------
 3084|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 3085|      0|        }
 3086|      0|        break;
 3087|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (3087:5): [True: 0, False: 4]
  ------------------
 3088|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (3088:5): [True: 0, False: 4]
  ------------------
 3089|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (3089:5): [True: 0, False: 4]
  ------------------
 3090|      0|    case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (3090:5): [True: 0, False: 4]
  ------------------
 3091|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (3091:5): [True: 0, False: 4]
  ------------------
 3092|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown key type %d", key->type);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3093|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3094|      4|    }
 3095|       |
 3096|      0|    SSH_LOG(SSH_LOG_TRACE, "Key type %d incompatible with hash type  %d",
  ------------------
  |  |  283|      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|      4|}
ssh_pki_signature_verify:
 3190|      2|{
 3191|      2|    int rc;
 3192|      2|    bool allowed;
 3193|      2|    enum ssh_keytypes_e key_type;
 3194|       |
 3195|      2|    if (session == NULL || sig == NULL || key == NULL || input == NULL) {
  ------------------
  |  Branch (3195:9): [True: 0, False: 2]
  |  Branch (3195:28): [True: 0, False: 2]
  |  Branch (3195:43): [True: 0, False: 2]
  |  Branch (3195:58): [True: 0, False: 2]
  ------------------
 3196|      0|        SSH_LOG(SSH_LOG_TRACE, "Bad parameter(s) provided to %s()", __func__);
  ------------------
  |  |  283|      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|      2|    key_type = ssh_key_type_plain(key->type);
 3200|       |
 3201|      2|    SSH_LOG(SSH_LOG_FUNCTIONS,
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3202|      2|            "Going to verify a %s type signature",
 3203|      2|            sig->type_c);
 3204|       |
 3205|      2|    if (key_type != sig->type) {
  ------------------
  |  Branch (3205:9): [True: 0, False: 2]
  ------------------
 3206|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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|      2|    allowed = ssh_key_size_allowed(session, key);
 3213|      2|    if (!allowed) {
  ------------------
  |  Branch (3213:9): [True: 0, False: 2]
  ------------------
 3214|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      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|      2|    rc = pki_key_check_hash_compatible(key, sig->hash_type);
 3224|      2|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3224:9): [True: 0, False: 2]
  ------------------
 3225|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3226|      0|    }
 3227|       |
 3228|      2|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|      2|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 0, False: 2]
  |  |  |  Branch (153:38): [True: 0, False: 2]
  |  |  ------------------
  |  |  154|      2|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 2]
  |  |  ------------------
  |  |  155|      2|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 2]
  |  |  ------------------
  ------------------
 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);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3245|      0|        return rc;
 3246|      0|    }
 3247|       |
 3248|      2|    return pki_verify_data_signature(sig, key, input, input_len);
 3249|      2|}
pki.c:pki_import_cert_buffer:
 1877|     11|{
 1878|     11|    ssh_buffer cert = NULL;
 1879|     11|    ssh_string tmp_s = NULL;
 1880|     11|    const char *type_c = NULL;
 1881|     11|    ssh_key key = NULL;
 1882|     11|    int rc;
 1883|       |
 1884|       |    /*
 1885|       |     * The cert blob starts with the key type as an ssh_string, but this
 1886|       |     * string has been read out of the buffer to identify the key type.
 1887|       |     * Simply add it again as first element before copying the rest.
 1888|       |     */
 1889|     11|    cert = ssh_buffer_new();
 1890|     11|    if (cert == NULL) {
  ------------------
  |  Branch (1890:9): [True: 0, False: 11]
  ------------------
 1891|      0|        goto fail;
 1892|      0|    }
 1893|     11|    type_c = ssh_key_type_to_char(type);
 1894|     11|    tmp_s = ssh_string_from_char(type_c);
 1895|     11|    if (tmp_s == NULL) {
  ------------------
  |  Branch (1895:9): [True: 0, False: 11]
  ------------------
 1896|      0|        goto fail;
 1897|      0|    }
 1898|     11|    rc = ssh_buffer_add_ssh_string(cert, tmp_s);
 1899|     11|    SSH_STRING_FREE(tmp_s);
  ------------------
  |  |  924|     11|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 11, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 11]
  |  |  ------------------
  ------------------
 1900|     11|    if (rc != 0) {
  ------------------
  |  Branch (1900:9): [True: 0, False: 11]
  ------------------
 1901|      0|        goto fail;
 1902|      0|    }
 1903|     11|    rc = ssh_buffer_add_buffer(cert, buffer);
 1904|     11|    if (rc != 0) {
  ------------------
  |  Branch (1904:9): [True: 0, False: 11]
  ------------------
 1905|      0|        goto fail;
 1906|      0|    }
 1907|       |
 1908|       |    /*
 1909|       |     * After the key type, comes an ssh_string nonce. Just after this comes the
 1910|       |     * cert public key, which can be parsed out of the buffer.
 1911|       |     */
 1912|     11|    tmp_s = ssh_buffer_get_ssh_string(buffer);
 1913|     11|    if (tmp_s == NULL) {
  ------------------
  |  Branch (1913:9): [True: 2, False: 9]
  ------------------
 1914|      2|        goto fail;
 1915|      2|    }
 1916|      9|    SSH_STRING_FREE(tmp_s);
  ------------------
  |  |  924|      9|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 9, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 9]
  |  |  ------------------
  ------------------
 1917|       |
 1918|      9|    switch (type) {
 1919|      0|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1919:9): [True: 0, False: 9]
  ------------------
 1920|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_RSA, &key);
 1921|      0|            break;
 1922|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1922:9): [True: 0, False: 9]
  ------------------
 1923|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ECDSA_P256, &key);
 1924|      0|            break;
 1925|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1925:9): [True: 0, False: 9]
  ------------------
 1926|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ECDSA_P384, &key);
 1927|      0|            break;
 1928|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1928:9): [True: 0, False: 9]
  ------------------
 1929|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ECDSA_P521, &key);
 1930|      0|            break;
 1931|      2|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1931:9): [True: 2, False: 7]
  ------------------
 1932|      2|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ED25519, &key);
 1933|      2|            break;
 1934|      6|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1934:9): [True: 6, False: 3]
  ------------------
 1935|      6|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_SK_ECDSA, &key);
 1936|      6|            break;
 1937|      1|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1937:9): [True: 1, False: 8]
  ------------------
 1938|      1|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_SK_ED25519, &key);
 1939|      1|            break;
 1940|      0|        default:
  ------------------
  |  Branch (1940:9): [True: 0, False: 9]
  ------------------
 1941|      0|            key = ssh_key_new();
 1942|      9|    }
 1943|      9|    if (rc != 0 || key == NULL) {
  ------------------
  |  Branch (1943:9): [True: 6, False: 3]
  |  Branch (1943:20): [True: 0, False: 3]
  ------------------
 1944|      6|        goto fail;
 1945|      6|    }
 1946|       |
 1947|      3|    key->type = type;
 1948|      3|    key->type_c = type_c;
 1949|      3|    key->cert = cert;
 1950|       |
 1951|      3|    *pkey = key;
 1952|      3|    return SSH_OK;
  ------------------
  |  |  316|      3|#define SSH_OK 0     /* No error */
  ------------------
 1953|       |
 1954|      8|fail:
 1955|      8|    ssh_key_free(key);
 1956|      8|    SSH_BUFFER_FREE(cert);
  ------------------
  |  |  966|      8|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 8, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 8]
  |  |  ------------------
  ------------------
 1957|      8|    return SSH_ERROR;
  ------------------
  |  |  317|      8|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1958|      9|}
pki.c:pki_import_pubkey_buffer:
 1736|     56|{
 1737|     56|    ssh_key key = NULL;
 1738|     56|    int rc;
 1739|       |
 1740|     56|    key = ssh_key_new();
 1741|     56|    if (key == NULL) {
  ------------------
  |  Branch (1741:9): [True: 0, False: 56]
  ------------------
 1742|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1743|      0|    }
 1744|       |
 1745|     56|    key->type = type;
 1746|     56|    key->type_c = ssh_key_type_to_char(type);
 1747|     56|    key->flags = SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   54|     56|#define SSH_KEY_FLAG_PUBLIC  0x0001
  ------------------
 1748|       |
 1749|     56|    switch (type) {
 1750|     41|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1750:9): [True: 41, False: 15]
  ------------------
 1751|     41|            {
 1752|     41|                ssh_string e = NULL;
 1753|     41|                ssh_string n = NULL;
 1754|       |
 1755|     41|                rc = ssh_buffer_unpack(buffer, "SS", &e, &n);
  ------------------
  |  |   60|     41|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     41|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     41|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     41|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     41|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     41|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     41|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1756|     41|                if (rc != SSH_OK) {
  ------------------
  |  |  316|     41|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1756:21): [True: 2, False: 39]
  ------------------
 1757|      2|                    SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1758|      2|                    goto fail;
 1759|      2|                }
 1760|       |
 1761|     39|                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|     39|                ssh_string_burn(e);
 1767|     39|                SSH_STRING_FREE(e);
  ------------------
  |  |  924|     39|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 39, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 39]
  |  |  ------------------
  ------------------
 1768|     39|                ssh_string_burn(n);
 1769|     39|                SSH_STRING_FREE(n);
  ------------------
  |  |  924|     39|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 39, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 39]
  |  |  ------------------
  ------------------
 1770|     39|                if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     39|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1770:21): [True: 0, False: 39]
  ------------------
 1771|      0|                    SSH_LOG(SSH_LOG_TRACE, "Failed to build RSA public key");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1772|      0|                    goto fail;
 1773|      0|                }
 1774|     39|            }
 1775|     39|            break;
 1776|     39|#ifdef HAVE_ECC
 1777|     39|        case SSH_KEYTYPE_ECDSA: /* deprecated */
  ------------------
  |  Branch (1777:9): [True: 0, False: 56]
  ------------------
 1778|      3|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1778:9): [True: 3, False: 53]
  ------------------
 1779|      4|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1779:9): [True: 1, False: 55]
  ------------------
 1780|      5|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1780:9): [True: 1, False: 55]
  ------------------
 1781|     11|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1781:9): [True: 6, False: 50]
  ------------------
 1782|     11|            {
 1783|     11|                ssh_string e = NULL;
 1784|     11|                ssh_string i = NULL;
 1785|     11|                int nid;
 1786|       |
 1787|     11|                rc = ssh_buffer_unpack(buffer, "SS", &i, &e);
  ------------------
  |  |   60|     11|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     11|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     11|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     11|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     11|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     11|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     11|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1788|     11|                if (rc != SSH_OK) {
  ------------------
  |  |  316|     11|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1788:21): [True: 5, False: 6]
  ------------------
 1789|      5|                    SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  283|      5|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1790|      5|                    goto fail;
 1791|      5|                }
 1792|       |
 1793|      6|                nid = pki_key_ecdsa_nid_from_name(ssh_string_get_char(i));
 1794|      6|                SSH_STRING_FREE(i);
  ------------------
  |  |  924|      6|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 6, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 6]
  |  |  ------------------
  ------------------
 1795|      6|                if (nid == -1) {
  ------------------
  |  Branch (1795:21): [True: 2, False: 4]
  ------------------
 1796|      2|                    ssh_string_burn(e);
 1797|      2|                    SSH_STRING_FREE(e);
  ------------------
  |  |  924|      2|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 2, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 2]
  |  |  ------------------
  ------------------
 1798|      2|                    goto fail;
 1799|      2|                }
 1800|       |
 1801|      4|                rc = pki_pubkey_build_ecdsa(key, nid, e);
 1802|      4|                ssh_string_burn(e);
 1803|      4|                SSH_STRING_FREE(e);
  ------------------
  |  |  924|      4|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 4, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 4]
  |  |  ------------------
  ------------------
 1804|      4|                if (rc < 0) {
  ------------------
  |  Branch (1804:21): [True: 1, False: 3]
  ------------------
 1805|      1|                    SSH_LOG(SSH_LOG_TRACE, "Failed to build ECDSA public key");
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1806|      1|                    goto fail;
 1807|      1|                }
 1808|       |
 1809|       |                /* Unpack SK specific parameters */
 1810|      3|                if (type == SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1810:21): [True: 3, False: 0]
  ------------------
 1811|      3|                    ssh_string application = ssh_buffer_get_ssh_string(buffer);
 1812|      3|                    if (application == NULL) {
  ------------------
  |  Branch (1812:25): [True: 0, False: 3]
  ------------------
 1813|      0|                        SSH_LOG(SSH_LOG_TRACE, "SK Unpack error");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1814|      0|                        goto fail;
 1815|      0|                    }
 1816|      3|                    key->sk_application = application;
 1817|      3|                    key->type_c = ssh_key_type_to_char(key->type);
 1818|      3|                }
 1819|      3|            }
 1820|      3|            break;
 1821|      3|#endif /* HAVE_ECC */
 1822|      3|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1822:9): [True: 3, False: 53]
  ------------------
 1823|      4|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1823:9): [True: 1, False: 55]
  ------------------
 1824|      4|        {
 1825|      4|            ssh_string pubkey = ssh_buffer_get_ssh_string(buffer);
 1826|       |
 1827|      4|            if (ssh_string_len(pubkey) != ED25519_KEY_LEN) {
  ------------------
  |  |   44|      4|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1827:17): [True: 2, False: 2]
  ------------------
 1828|      2|                SSH_LOG(SSH_LOG_TRACE, "Invalid public key length");
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1829|      2|                ssh_string_burn(pubkey);
 1830|      2|                SSH_STRING_FREE(pubkey);
  ------------------
  |  |  924|      2|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 1, False: 1]
  |  |  |  Branch (924:69): [Folded, False: 2]
  |  |  ------------------
  ------------------
 1831|      2|                goto fail;
 1832|      2|            }
 1833|       |
 1834|      2|            rc = pki_pubkey_build_ed25519(key, pubkey);
 1835|      2|            ssh_string_burn(pubkey);
 1836|      2|            SSH_STRING_FREE(pubkey);
  ------------------
  |  |  924|      2|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 2, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 2]
  |  |  ------------------
  ------------------
 1837|      2|            if (rc < 0) {
  ------------------
  |  Branch (1837:17): [True: 0, False: 2]
  ------------------
 1838|      0|                SSH_LOG(SSH_LOG_TRACE, "Failed to build ED25519 public key");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1839|      0|                goto fail;
 1840|      0|            }
 1841|       |
 1842|      2|            if (type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1842:17): [True: 1, False: 1]
  ------------------
 1843|      1|                ssh_string application = ssh_buffer_get_ssh_string(buffer);
 1844|      1|                if (application == NULL) {
  ------------------
  |  Branch (1844:21): [True: 1, False: 0]
  ------------------
 1845|      1|                    SSH_LOG(SSH_LOG_TRACE, "SK Unpack error");
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1846|      1|                    goto fail;
 1847|      1|                }
 1848|      0|                key->sk_application = application;
 1849|      0|            }
 1850|      2|        }
 1851|      1|        break;
 1852|      1|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1852:9): [True: 0, False: 56]
  ------------------
 1853|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1853:9): [True: 0, False: 56]
  ------------------
 1854|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1854:9): [True: 0, False: 56]
  ------------------
 1855|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1855:9): [True: 0, False: 56]
  ------------------
 1856|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1856:9): [True: 0, False: 56]
  ------------------
 1857|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1857:9): [True: 0, False: 56]
  ------------------
 1858|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1858:9): [True: 0, False: 56]
  ------------------
 1859|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1859:9): [True: 0, False: 56]
  ------------------
 1860|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1860:9): [True: 0, False: 56]
  ------------------
 1861|      0|        default:
  ------------------
  |  Branch (1861:9): [True: 0, False: 56]
  ------------------
 1862|      0|            SSH_LOG(SSH_LOG_TRACE, "Unknown public key type %d", type);
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1863|      0|            goto fail;
 1864|     56|    }
 1865|       |
 1866|     43|    *pkey = key;
 1867|     43|    return SSH_OK;
  ------------------
  |  |  316|     43|#define SSH_OK 0     /* No error */
  ------------------
 1868|     13|fail:
 1869|     13|    ssh_key_free(key);
 1870|       |
 1871|     13|    return SSH_ERROR;
  ------------------
  |  |  317|     13|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1872|     56|}

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

pki_key_clean:
   96|     56|{
   97|     56|    if (key == NULL)
  ------------------
  |  Branch (97:9): [True: 0, False: 56]
  ------------------
   98|      0|        return;
   99|     56|    EVP_PKEY_free(key->key);
  100|       |    key->key = NULL;
  101|     56|}
pki_key_ecdsa_nid_from_name:
  194|      6|{
  195|      6|    if (strcmp(name, "nistp256") == 0) {
  ------------------
  |  Branch (195:9): [True: 4, False: 2]
  ------------------
  196|      4|        return NID_X9_62_prime256v1;
  197|      4|    } else if (strcmp(name, "nistp384") == 0) {
  ------------------
  |  Branch (197:16): [True: 0, False: 2]
  ------------------
  198|      0|        return NID_secp384r1;
  199|      2|    } else if (strcmp(name, "nistp521") == 0) {
  ------------------
  |  Branch (199:16): [True: 0, False: 2]
  ------------------
  200|      0|        return NID_secp521r1;
  201|      0|    }
  202|       |
  203|      2|    return -1;
  204|      6|}
pki_pubkey_build_ecdsa:
  330|      4|{
  331|      4|    int rc;
  332|      4|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  333|      4|    EC_POINT *p = NULL;
  334|      4|    const EC_GROUP *g = NULL;
  335|      4|    EC_KEY *ecdsa = NULL;
  336|      4|    int ok;
  337|       |#else
  338|       |    const char *group_name = OSSL_EC_curve_nid2name(nid);
  339|       |    OSSL_PARAM_BLD *param_bld = NULL;
  340|       |#endif /* OPENSSL_VERSION_NUMBER */
  341|       |
  342|      4|    key->ecdsa_nid = nid;
  343|       |
  344|      4|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  345|      4|    ecdsa = EC_KEY_new_by_curve_name(key->ecdsa_nid);
  346|      4|    if (ecdsa == NULL) {
  ------------------
  |  Branch (346:9): [True: 0, False: 4]
  ------------------
  347|      0|        return -1;
  348|      0|    }
  349|       |
  350|      4|    g = EC_KEY_get0_group(ecdsa);
  351|       |
  352|      4|    p = EC_POINT_new(g);
  353|      4|    if (p == NULL) {
  ------------------
  |  Branch (353:9): [True: 0, False: 4]
  ------------------
  354|      0|        EC_KEY_free(ecdsa);
  355|      0|        return -1;
  356|      0|    }
  357|       |
  358|      4|    ok = EC_POINT_oct2point(g,
  359|      4|                            p,
  360|      4|                            ssh_string_data(e),
  361|      4|                            ssh_string_len(e),
  362|      4|                            NULL);
  363|      4|    if (!ok) {
  ------------------
  |  Branch (363:9): [True: 1, False: 3]
  ------------------
  364|      1|        EC_KEY_free(ecdsa);
  365|      1|        EC_POINT_free(p);
  366|      1|        return -1;
  367|      1|    }
  368|       |
  369|       |    /* EC_KEY_set_public_key duplicates p */
  370|      3|    ok = EC_KEY_set_public_key(ecdsa, p);
  371|      3|    EC_POINT_free(p);
  372|      3|    if (!ok) {
  ------------------
  |  Branch (372:9): [True: 0, False: 3]
  ------------------
  373|      0|        EC_KEY_free(ecdsa);
  374|      0|        return -1;
  375|      0|    }
  376|       |
  377|      3|    key->key = EVP_PKEY_new();
  378|      3|    if (key->key == NULL) {
  ------------------
  |  Branch (378:9): [True: 0, False: 3]
  ------------------
  379|      0|        EC_KEY_free(ecdsa);
  380|      0|        return -1;
  381|      0|    }
  382|       |
  383|      3|    rc = EVP_PKEY_assign_EC_KEY(key->key, ecdsa);
  384|      3|    if (rc != 1) {
  ------------------
  |  Branch (384:9): [True: 0, False: 3]
  ------------------
  385|      0|        EC_KEY_free(ecdsa);
  386|      0|        return -1;
  387|      0|    }
  388|       |
  389|      3|    return 0;
  390|       |#else
  391|       |    param_bld = OSSL_PARAM_BLD_new();
  392|       |    if (param_bld == NULL)
  393|       |        goto err;
  394|       |
  395|       |    rc = OSSL_PARAM_BLD_push_utf8_string(param_bld, OSSL_PKEY_PARAM_GROUP_NAME,
  396|       |                                         group_name, strlen(group_name));
  397|       |    if (rc != 1)
  398|       |        goto err;
  399|       |    rc = OSSL_PARAM_BLD_push_octet_string(param_bld, OSSL_PKEY_PARAM_PUB_KEY,
  400|       |                                          ssh_string_data(e), ssh_string_len(e));
  401|       |    if (rc != 1)
  402|       |        goto err;
  403|       |
  404|       |    rc = evp_build_pkey("EC", param_bld, &(key->key), EVP_PKEY_PUBLIC_KEY);
  405|       |    OSSL_PARAM_BLD_free(param_bld);
  406|       |
  407|       |    return rc;
  408|       |err:
  409|       |    OSSL_PARAM_BLD_free(param_bld);
  410|       |    return -1;
  411|       |#endif /* OPENSSL_VERSION_NUMBER */
  412|      3|}
pki_pubkey_build_ed25519:
  444|      2|{
  445|      2|    EVP_PKEY *pkey = NULL;
  446|       |
  447|      2|    if (ssh_string_len(pubkey) != ED25519_KEY_LEN) {
  ------------------
  |  |   44|      2|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (447:9): [True: 0, False: 2]
  ------------------
  448|      0|        SSH_LOG(SSH_LOG_TRACE, "Invalid ed25519 key len");
  ------------------
  |  |  283|      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|      2|    if (ssh_fips_mode()) {
  ------------------
  |  |  115|      2|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 2]
  |  |  ------------------
  ------------------
  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,
  ------------------
  |  |  283|      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|      2|    pkey = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519,
  468|      2|                                       NULL,
  469|      2|                                       (const uint8_t *)ssh_string_data(pubkey),
  470|      2|                                       ED25519_KEY_LEN);
  ------------------
  |  |   44|      2|#define ED25519_KEY_LEN 32
  ------------------
  471|      2|    if (pkey == NULL) {
  ------------------
  |  Branch (471:9): [True: 0, False: 2]
  ------------------
  472|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      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|      2|    key->key = pkey;
  479|       |
  480|      2|    return SSH_OK;
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
  481|      2|}
pki_pubkey_build_rsa:
 1415|     39|                         ssh_string n) {
 1416|     39|    int rc;
 1417|     39|    BIGNUM *be = NULL, *bn = NULL;
 1418|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1419|       |    OSSL_PARAM_BLD *param_bld = OSSL_PARAM_BLD_new();
 1420|       |    if (param_bld == NULL) {
 1421|       |        return SSH_ERROR;
 1422|       |    }
 1423|       |#else
 1424|     39|    RSA *key_rsa = RSA_new();
 1425|     39|    if (key_rsa == NULL) {
  ------------------
  |  Branch (1425:9): [True: 0, False: 39]
  ------------------
 1426|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1427|      0|    }
 1428|     39|#endif /* OPENSSL_VERSION_NUMBER */
 1429|       |
 1430|     39|    be = ssh_make_string_bn(e);
 1431|     39|    if (be == NULL) {
  ------------------
  |  Branch (1431:9): [True: 0, False: 39]
  ------------------
 1432|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1433|      0|        goto fail;
 1434|      0|    }
 1435|     39|    bn = ssh_make_string_bn(n);
 1436|     39|    if (bn == NULL) {
  ------------------
  |  Branch (1436:9): [True: 0, False: 39]
  ------------------
 1437|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1438|      0|        goto fail;
 1439|      0|    }
 1440|       |
 1441|     39|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1442|     39|    rc = RSA_set0_key(key_rsa, bn, be, NULL);
 1443|     39|    if (rc == 0) {
  ------------------
  |  Branch (1443:9): [True: 0, False: 39]
  ------------------
 1444|      0|        goto fail;
 1445|      0|    }
 1446|       |    /* Memory management of bn and be is transferred to RSA object */
 1447|     39|    bn = NULL;
 1448|     39|    be = NULL;
 1449|       |
 1450|     39|    key->key = EVP_PKEY_new();
 1451|     39|    if (key->key == NULL) {
  ------------------
  |  Branch (1451:9): [True: 0, False: 39]
  ------------------
 1452|      0|        goto fail;
 1453|      0|    }
 1454|       |
 1455|     39|    rc = EVP_PKEY_assign_RSA(key->key, key_rsa);
 1456|     39|    if (rc != 1) {
  ------------------
  |  Branch (1456:9): [True: 0, False: 39]
  ------------------
 1457|      0|        goto fail;
 1458|      0|    }
 1459|       |
 1460|     39|    return SSH_OK;
  ------------------
  |  |  316|     39|#define SSH_OK 0     /* No error */
  ------------------
 1461|       |#else
 1462|       |    rc = OSSL_PARAM_BLD_push_BN(param_bld, OSSL_PKEY_PARAM_RSA_N, bn);
 1463|       |    if (rc != 1) {
 1464|       |        rc = SSH_ERROR;
 1465|       |        goto fail;
 1466|       |    }
 1467|       |    rc = OSSL_PARAM_BLD_push_BN(param_bld, OSSL_PKEY_PARAM_RSA_E, be);
 1468|       |    if (rc != 1) {
 1469|       |        rc = SSH_ERROR;
 1470|       |        goto fail;
 1471|       |    }
 1472|       |
 1473|       |    rc = evp_build_pkey("RSA", param_bld, &(key->key), EVP_PKEY_PUBLIC_KEY);
 1474|       |#endif /* OPENSSL_VERSION_NUMBER */
 1475|       |
 1476|      0|fail:
 1477|      0|    bignum_safe_free(bn);
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
 1478|      0|    bignum_safe_free(be);
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
 1479|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1480|      0|    RSA_free(key_rsa);
 1481|       |
 1482|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1483|       |#else
 1484|       |    OSSL_PARAM_BLD_free(param_bld);
 1485|       |
 1486|       |    return rc;
 1487|       |#endif /* OPENSSL_VERSION_NUMBER */
 1488|     39|}
pki_key_to_blob:
 1491|     33|{
 1492|     33|    ssh_buffer buffer = NULL;
 1493|     33|    ssh_string type_s = NULL;
 1494|     33|    ssh_string str = NULL;
 1495|     33|    ssh_string e = NULL;
 1496|     33|    ssh_string n = NULL;
 1497|     33|    ssh_string p = NULL;
 1498|     33|    ssh_string g = NULL;
 1499|     33|    ssh_string q = NULL;
 1500|     33|    ssh_string d = NULL;
 1501|     33|    ssh_string iqmp = NULL;
 1502|     33|    int rc;
 1503|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1504|       |    BIGNUM *bp = NULL, *bq = NULL, *bg = NULL, *bpub_key = NULL,
 1505|       |           *bn = NULL, *be = NULL,
 1506|       |           *bd = NULL, *biqmp = NULL;
 1507|       |    OSSL_PARAM *params = NULL;
 1508|       |#endif /* OPENSSL_VERSION_NUMBER */
 1509|     33|    uint8_t *ed25519_pubkey = NULL;
 1510|     33|    uint8_t *ed25519_privkey = NULL;
 1511|     33|    size_t key_len = 0;
 1512|       |
 1513|     33|    buffer = ssh_buffer_new();
 1514|     33|    if (buffer == NULL) {
  ------------------
  |  Branch (1514:9): [True: 0, False: 33]
  ------------------
 1515|      0|        return NULL;
 1516|      0|    }
 1517|       |    /* The buffer will contain sensitive information. Make sure it is erased */
 1518|     33|    ssh_buffer_set_secure(buffer);
 1519|       |
 1520|     33|    if (key->cert != NULL) {
  ------------------
  |  Branch (1520:9): [True: 0, False: 33]
  ------------------
 1521|      0|        rc = ssh_buffer_add_buffer(buffer, key->cert);
 1522|      0|        if (rc < 0) {
  ------------------
  |  Branch (1522:13): [True: 0, False: 0]
  ------------------
 1523|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1524|      0|            return NULL;
 1525|      0|        }
 1526|      0|        goto makestring;
 1527|      0|    }
 1528|       |
 1529|     33|    type_s = ssh_string_from_char(key->type_c);
 1530|     33|    if (type_s == NULL) {
  ------------------
  |  Branch (1530:9): [True: 0, False: 33]
  ------------------
 1531|      0|        SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1532|      0|        return NULL;
 1533|      0|    }
 1534|       |
 1535|     33|    rc = ssh_buffer_add_ssh_string(buffer, type_s);
 1536|     33|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  924|     33|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 33, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 33]
  |  |  ------------------
  ------------------
 1537|     33|    if (rc < 0) {
  ------------------
  |  Branch (1537:9): [True: 0, False: 33]
  ------------------
 1538|      0|        SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1539|      0|        return NULL;
 1540|      0|    }
 1541|       |
 1542|     33|    switch (key->type) {
 1543|     33|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1543:5): [True: 33, False: 0]
  ------------------
 1544|     33|    case SSH_KEYTYPE_RSA1: {
  ------------------
  |  Branch (1544:5): [True: 0, False: 33]
  ------------------
 1545|     33|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1546|     33|        const BIGNUM *be = NULL, *bn = NULL;
 1547|     33|        const RSA *key_rsa = EVP_PKEY_get0_RSA(key->key);
 1548|     33|        RSA_get0_key(key_rsa, &bn, &be, NULL);
 1549|       |#else
 1550|       |        const OSSL_PARAM *out_param = NULL;
 1551|       |        rc = EVP_PKEY_todata(key->key, EVP_PKEY_PUBLIC_KEY, &params);
 1552|       |        if (rc != 1) {
 1553|       |            goto fail;
 1554|       |        }
 1555|       |        out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_E);
 1556|       |        if (out_param == NULL) {
 1557|       |            SSH_LOG(SSH_LOG_TRACE, "RSA: No param E has been found");
 1558|       |            goto fail;
 1559|       |        }
 1560|       |        rc = OSSL_PARAM_get_BN(out_param, &be);
 1561|       |        if (rc != 1) {
 1562|       |            goto fail;
 1563|       |        }
 1564|       |        out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_N);
 1565|       |        if (out_param == NULL) {
 1566|       |            SSH_LOG(SSH_LOG_TRACE, "RSA: No param N has been found");
 1567|       |            goto fail;
 1568|       |        }
 1569|       |        rc = OSSL_PARAM_get_BN(out_param, &bn);
 1570|       |        if (rc != 1) {
 1571|       |            goto fail;
 1572|       |        }
 1573|       |#endif /* OPENSSL_VERSION_NUMBER */
 1574|     33|        e = ssh_make_bignum_string((BIGNUM *)be);
 1575|     33|        if (e == NULL) {
  ------------------
  |  Branch (1575:13): [True: 0, False: 33]
  ------------------
 1576|      0|            goto fail;
 1577|      0|        }
 1578|       |
 1579|     33|        n = ssh_make_bignum_string((BIGNUM *)bn);
 1580|     33|        if (n == NULL) {
  ------------------
  |  Branch (1580:13): [True: 0, False: 33]
  ------------------
 1581|      0|            goto fail;
 1582|      0|        }
 1583|       |
 1584|     33|        if (type == SSH_KEY_PUBLIC) {
  ------------------
  |  Branch (1584:13): [True: 33, False: 0]
  ------------------
 1585|       |            /* The N and E parts are swapped in the public key export ! */
 1586|     33|            rc = ssh_buffer_add_ssh_string(buffer, e);
 1587|     33|            if (rc < 0) {
  ------------------
  |  Branch (1587:17): [True: 0, False: 33]
  ------------------
 1588|      0|                goto fail;
 1589|      0|            }
 1590|     33|            rc = ssh_buffer_add_ssh_string(buffer, n);
 1591|     33|            if (rc < 0) {
  ------------------
  |  Branch (1591:17): [True: 0, False: 33]
  ------------------
 1592|      0|                goto fail;
 1593|      0|            }
 1594|     33|        } else if (type == SSH_KEY_PRIVATE) {
  ------------------
  |  Branch (1594:20): [True: 0, False: 0]
  ------------------
 1595|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1596|      0|            const BIGNUM *bd, *biqmp, *bp, *bq;
 1597|      0|            RSA_get0_key(key_rsa, NULL, NULL, &bd);
 1598|      0|            RSA_get0_factors(key_rsa, &bp, &bq);
 1599|      0|            RSA_get0_crt_params(key_rsa, NULL, NULL, &biqmp);
 1600|       |#else
 1601|       |            OSSL_PARAM_free(params);
 1602|       |            rc = EVP_PKEY_todata(key->key, EVP_PKEY_KEYPAIR, &params);
 1603|       |            if (rc != 1) {
 1604|       |                goto fail;
 1605|       |            }
 1606|       |
 1607|       |            out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_D);
 1608|       |            if (out_param == NULL) {
 1609|       |                SSH_LOG(SSH_LOG_TRACE, "RSA: No param D has been found");
 1610|       |                goto fail;
 1611|       |            }
 1612|       |            rc = OSSL_PARAM_get_BN(out_param, &bd);
 1613|       |            if (rc != 1) {
 1614|       |                goto fail;
 1615|       |            }
 1616|       |
 1617|       |            out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_FACTOR1);
 1618|       |            if (out_param == NULL) {
 1619|       |                SSH_LOG(SSH_LOG_TRACE, "RSA: No param P has been found");
 1620|       |                goto fail;
 1621|       |            }
 1622|       |            rc = OSSL_PARAM_get_BN(out_param, &bp);
 1623|       |            if (rc != 1) {
 1624|       |                goto fail;
 1625|       |            }
 1626|       |
 1627|       |            out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_FACTOR2);
 1628|       |            if (out_param == NULL) {
 1629|       |                SSH_LOG(SSH_LOG_TRACE, "RSA: No param Q has been found");
 1630|       |                goto fail;
 1631|       |            }
 1632|       |            rc = OSSL_PARAM_get_BN(out_param, &bq);
 1633|       |            if (rc != 1) {
 1634|       |                goto fail;
 1635|       |            }
 1636|       |
 1637|       |            out_param = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_COEFFICIENT1);
 1638|       |            if (out_param == NULL) {
 1639|       |                SSH_LOG(SSH_LOG_TRACE, "RSA: No param IQMP has been found");
 1640|       |                goto fail;
 1641|       |            }
 1642|       |            rc = OSSL_PARAM_get_BN(out_param, &biqmp);
 1643|       |            if (rc != 1) {
 1644|       |                goto fail;
 1645|       |            }
 1646|       |#endif /* OPENSSL_VERSION_NUMBER */
 1647|      0|            rc = ssh_buffer_add_ssh_string(buffer, n);
 1648|      0|            if (rc < 0) {
  ------------------
  |  Branch (1648:17): [True: 0, False: 0]
  ------------------
 1649|      0|                goto fail;
 1650|      0|            }
 1651|      0|            rc = ssh_buffer_add_ssh_string(buffer, e);
 1652|      0|            if (rc < 0) {
  ------------------
  |  Branch (1652:17): [True: 0, False: 0]
  ------------------
 1653|      0|                goto fail;
 1654|      0|            }
 1655|       |
 1656|      0|            d = ssh_make_bignum_string((BIGNUM *)bd);
 1657|      0|            if (d == NULL) {
  ------------------
  |  Branch (1657:17): [True: 0, False: 0]
  ------------------
 1658|      0|                goto fail;
 1659|      0|            }
 1660|       |
 1661|      0|            iqmp = ssh_make_bignum_string((BIGNUM *)biqmp);
 1662|      0|            if (iqmp == NULL) {
  ------------------
  |  Branch (1662:17): [True: 0, False: 0]
  ------------------
 1663|      0|                goto fail;
 1664|      0|            }
 1665|       |
 1666|      0|            p = ssh_make_bignum_string((BIGNUM *)bp);
 1667|      0|            if (p == NULL) {
  ------------------
  |  Branch (1667:17): [True: 0, False: 0]
  ------------------
 1668|      0|                goto fail;
 1669|      0|            }
 1670|       |
 1671|      0|            q = ssh_make_bignum_string((BIGNUM *)bq);
 1672|      0|            if (q == NULL) {
  ------------------
  |  Branch (1672:17): [True: 0, False: 0]
  ------------------
 1673|      0|                goto fail;
 1674|      0|            }
 1675|       |
 1676|      0|            rc = ssh_buffer_add_ssh_string(buffer, d);
 1677|      0|            if (rc < 0) {
  ------------------
  |  Branch (1677:17): [True: 0, False: 0]
  ------------------
 1678|      0|                goto fail;
 1679|      0|            }
 1680|      0|            rc = ssh_buffer_add_ssh_string(buffer, iqmp);
 1681|      0|            if (rc < 0) {
  ------------------
  |  Branch (1681:17): [True: 0, False: 0]
  ------------------
 1682|      0|                goto fail;
 1683|      0|            }
 1684|      0|            rc = ssh_buffer_add_ssh_string(buffer, p);
 1685|      0|            if (rc < 0) {
  ------------------
  |  Branch (1685:17): [True: 0, False: 0]
  ------------------
 1686|      0|                goto fail;
 1687|      0|            }
 1688|      0|            rc = ssh_buffer_add_ssh_string(buffer, q);
 1689|      0|            if (rc < 0) {
  ------------------
  |  Branch (1689:17): [True: 0, False: 0]
  ------------------
 1690|      0|                goto fail;
 1691|      0|            }
 1692|       |
 1693|      0|            ssh_string_burn(d);
 1694|      0|            SSH_STRING_FREE(d);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1695|      0|            ssh_string_burn(iqmp);
 1696|      0|            SSH_STRING_FREE(iqmp);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1697|      0|            ssh_string_burn(p);
 1698|      0|            SSH_STRING_FREE(p);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1699|      0|            ssh_string_burn(q);
 1700|      0|            SSH_STRING_FREE(q);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1701|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1702|       |            bignum_safe_free(bd);
 1703|       |            bignum_safe_free(biqmp);
 1704|       |            bignum_safe_free(bp);
 1705|       |            bignum_safe_free(bq);
 1706|       |#endif /* OPENSSL_VERSION_NUMBER */
 1707|      0|        }
 1708|     33|        ssh_string_burn(e);
 1709|     33|        SSH_STRING_FREE(e);
  ------------------
  |  |  924|     33|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 33, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 33]
  |  |  ------------------
  ------------------
 1710|     33|        ssh_string_burn(n);
 1711|     33|        SSH_STRING_FREE(n);
  ------------------
  |  |  924|     33|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 33, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 33]
  |  |  ------------------
  ------------------
 1712|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1713|       |        bignum_safe_free(bn);
 1714|       |        bignum_safe_free(be);
 1715|       |        OSSL_PARAM_free(params);
 1716|       |        params = NULL;
 1717|       |#endif /* OPENSSL_VERSION_NUMBER */
 1718|     33|        break;
 1719|     33|    }
 1720|      0|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1720:5): [True: 0, False: 33]
  ------------------
 1721|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1721:5): [True: 0, False: 33]
  ------------------
 1722|      0|        rc = EVP_PKEY_get_raw_public_key(key->key, NULL, &key_len);
 1723|      0|        if (rc != 1) {
  ------------------
  |  Branch (1723:13): [True: 0, False: 0]
  ------------------
 1724|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1725|      0|                    "Failed to get ed25519 raw public key length: %s",
 1726|      0|                    ERR_error_string(ERR_get_error(), NULL));
 1727|      0|            goto fail;
 1728|      0|        }
 1729|       |
 1730|      0|        if (key_len != ED25519_KEY_LEN) {
  ------------------
  |  |   44|      0|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1730:13): [True: 0, False: 0]
  ------------------
 1731|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1732|      0|                    "Unexpected length of private key %zu. Expected %d.",
 1733|      0|                    key_len,
 1734|      0|                    ED25519_KEY_LEN);
 1735|      0|            goto fail;
 1736|      0|        }
 1737|       |
 1738|      0|        ed25519_pubkey = malloc(key_len);
 1739|      0|        if (ed25519_pubkey == NULL) {
  ------------------
  |  Branch (1739:13): [True: 0, False: 0]
  ------------------
 1740|      0|            SSH_LOG(SSH_LOG_TRACE, "Out of memory");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1741|      0|            goto fail;
 1742|      0|        }
 1743|       |
 1744|      0|        rc = EVP_PKEY_get_raw_public_key(key->key,
 1745|      0|                                         (uint8_t *)ed25519_pubkey,
 1746|      0|                                         &key_len);
 1747|      0|        if (rc != 1) {
  ------------------
  |  Branch (1747:13): [True: 0, False: 0]
  ------------------
 1748|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1749|      0|                    "Failed to get ed25519 raw public key:  %s",
 1750|      0|                    ERR_error_string(ERR_get_error(), NULL));
 1751|      0|            goto fail;
 1752|      0|        }
 1753|       |
 1754|      0|        rc = ssh_buffer_pack(buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      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)
  |  |  ------------------
  ------------------
 1755|      0|                             "dP",
 1756|      0|                             (uint32_t)ED25519_KEY_LEN,
 1757|      0|                             (size_t)ED25519_KEY_LEN,
 1758|      0|                             ed25519_pubkey);
 1759|      0|        if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1759:13): [True: 0, False: 0]
  ------------------
 1760|      0|            goto fail;
 1761|      0|        }
 1762|       |
 1763|      0|        if (type == SSH_KEY_PRIVATE && key->type == SSH_KEYTYPE_ED25519) {
  ------------------
  |  Branch (1763:13): [True: 0, False: 0]
  |  Branch (1763:40): [True: 0, False: 0]
  ------------------
 1764|      0|            key_len = 0;
 1765|      0|            rc = EVP_PKEY_get_raw_private_key(key->key, NULL, &key_len);
 1766|      0|            if (rc != 1) {
  ------------------
  |  Branch (1766:17): [True: 0, False: 0]
  ------------------
 1767|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1768|      0|                        "Failed to get ed25519 raw private key length: %s",
 1769|      0|                        ERR_error_string(ERR_get_error(), NULL));
 1770|      0|                goto fail;
 1771|      0|            }
 1772|       |
 1773|      0|            if (key_len != ED25519_KEY_LEN) {
  ------------------
  |  |   44|      0|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1773:17): [True: 0, False: 0]
  ------------------
 1774|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1775|      0|                        "Unexpected length of private key %zu. Expected %d.",
 1776|      0|                        key_len,
 1777|      0|                        ED25519_KEY_LEN);
 1778|      0|                goto fail;
 1779|      0|            }
 1780|       |
 1781|      0|            ed25519_privkey = malloc(key_len);
 1782|      0|            if (ed25519_privkey == NULL) {
  ------------------
  |  Branch (1782:17): [True: 0, False: 0]
  ------------------
 1783|      0|                SSH_LOG(SSH_LOG_TRACE, "Out of memory");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1784|      0|                goto fail;
 1785|      0|            }
 1786|       |
 1787|      0|            rc = EVP_PKEY_get_raw_private_key(key->key,
 1788|      0|                                              ed25519_privkey,
 1789|      0|                                              &key_len);
 1790|      0|            if (rc != 1) {
  ------------------
  |  Branch (1790:17): [True: 0, False: 0]
  ------------------
 1791|      0|                SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1792|      0|                        "Failed to get ed25519 raw private key: %s",
 1793|      0|                        ERR_error_string(ERR_get_error(), NULL));
 1794|      0|                goto fail;
 1795|      0|            }
 1796|       |
 1797|      0|            rc = ssh_buffer_pack(buffer,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      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)
  |  |  ------------------
  ------------------
 1798|      0|                                 "dPP",
 1799|      0|                                 (uint32_t)(2 * ED25519_KEY_LEN),
 1800|      0|                                 (size_t)ED25519_KEY_LEN,
 1801|      0|                                 ed25519_privkey,
 1802|      0|                                 (size_t)ED25519_KEY_LEN,
 1803|      0|                                 ed25519_pubkey);
 1804|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1804:17): [True: 0, False: 0]
  ------------------
 1805|      0|                goto fail;
 1806|      0|            }
 1807|      0|            ssh_burn(ed25519_privkey, ED25519_KEY_LEN);
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 1808|      0|            SAFE_FREE(ed25519_privkey);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1809|      0|        } else if (type == SSH_KEY_PRIVATE &&
  ------------------
  |  Branch (1809:20): [True: 0, False: 0]
  ------------------
 1810|      0|                   key->type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1810:20): [True: 0, False: 0]
  ------------------
 1811|       |
 1812|      0|            rc = pki_buffer_pack_sk_priv_data(buffer, key);
 1813|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1813:17): [True: 0, False: 0]
  ------------------
 1814|      0|                goto fail;
 1815|      0|            }
 1816|      0|        } else if (type == SSH_KEY_PUBLIC &&
  ------------------
  |  Branch (1816:20): [True: 0, False: 0]
  ------------------
 1817|      0|                   key->type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1817:20): [True: 0, False: 0]
  ------------------
 1818|       |            /* public key can contain certificate sk information */
 1819|      0|            rc = ssh_buffer_add_ssh_string(buffer, key->sk_application);
 1820|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1820:17): [True: 0, False: 0]
  ------------------
 1821|      0|                goto fail;
 1822|      0|            }
 1823|      0|        }
 1824|       |
 1825|      0|        SAFE_FREE(ed25519_pubkey);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1826|      0|        break;
 1827|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1827:5): [True: 0, False: 33]
  ------------------
 1828|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1828:5): [True: 0, False: 33]
  ------------------
 1829|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1829:5): [True: 0, False: 33]
  ------------------
 1830|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1830:5): [True: 0, False: 33]
  ------------------
 1831|      0|#ifdef HAVE_OPENSSL_ECC
 1832|      0|    {
 1833|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1834|       |        EC_GROUP *group = NULL;
 1835|       |        EC_POINT *point = NULL;
 1836|       |        const void *pubkey = NULL;
 1837|       |        size_t pubkey_len;
 1838|       |        OSSL_PARAM *locate_param = NULL;
 1839|       |#else
 1840|      0|        const EC_GROUP *group = NULL;
 1841|      0|        const EC_POINT *point = NULL;
 1842|      0|        const BIGNUM *exp = NULL;
 1843|      0|        EC_KEY *ec = NULL;
 1844|      0|#endif /* OPENSSL_VERSION_NUMBER */
 1845|       |
 1846|      0|        type_s = ssh_string_from_char(pki_key_ecdsa_nid_to_char(key->ecdsa_nid));
 1847|      0|        if (type_s == NULL) {
  ------------------
  |  Branch (1847:13): [True: 0, False: 0]
  ------------------
 1848|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1849|      0|            return NULL;
 1850|      0|        }
 1851|       |
 1852|      0|        rc = ssh_buffer_add_ssh_string(buffer, type_s);
 1853|      0|        SSH_STRING_FREE(type_s);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1854|      0|        if (rc < 0) {
  ------------------
  |  Branch (1854:13): [True: 0, False: 0]
  ------------------
 1855|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1856|      0|            return NULL;
 1857|      0|        }
 1858|       |
 1859|      0|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1860|      0|        ec = EVP_PKEY_get0_EC_KEY(key->key);
 1861|      0|        if (ec == NULL) {
  ------------------
  |  Branch (1861:13): [True: 0, False: 0]
  ------------------
 1862|      0|            goto fail;
 1863|      0|        }
 1864|       |#ifdef WITH_PKCS11_URI
 1865|       |        if (ssh_key_is_private(key) && !EC_KEY_get0_public_key(ec)) {
 1866|       |            SSH_LOG(SSH_LOG_TRACE,
 1867|       |                    "It is mandatory to have separate"
 1868|       |                    " public ECDSA key objects in the PKCS #11 device."
 1869|       |                    " Unlike RSA, ECDSA public keys cannot be derived"
 1870|       |                    " from their private keys.");
 1871|       |            goto fail;
 1872|       |        }
 1873|       |#endif /* WITH_PKCS11_URI */
 1874|      0|        group = EC_KEY_get0_group(ec);
 1875|      0|        point = EC_KEY_get0_public_key(ec);
 1876|      0|        if (group == NULL || point == NULL) {
  ------------------
  |  Branch (1876:13): [True: 0, False: 0]
  |  Branch (1876:30): [True: 0, False: 0]
  ------------------
 1877|      0|            goto fail;
 1878|      0|        }
 1879|      0|        e = pki_key_make_ecpoint_string(group, point);
 1880|       |#else
 1881|       |        rc = EVP_PKEY_todata(key->key, EVP_PKEY_PUBLIC_KEY, &params);
 1882|       |        if (rc < 0) {
 1883|       |            goto fail;
 1884|       |        }
 1885|       |
 1886|       |        locate_param = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_PUB_KEY);
 1887|       |#ifdef WITH_PKCS11_URI
 1888|       |        if (ssh_key_is_private(key) && !locate_param) {
 1889|       |            SSH_LOG(SSH_LOG_TRACE,
 1890|       |                    "It is mandatory to have separate"
 1891|       |                    " public ECDSA key objects in the PKCS #11 device."
 1892|       |                    " Unlike RSA, ECDSA public keys cannot be derived"
 1893|       |                    " from their private keys.");
 1894|       |            goto fail;
 1895|       |        }
 1896|       |#endif /* WITH_PKCS11_URI */
 1897|       |
 1898|       |        rc = OSSL_PARAM_get_octet_string_ptr(locate_param, &pubkey, &pubkey_len);
 1899|       |        if (rc != 1) {
 1900|       |            goto fail;
 1901|       |        }
 1902|       |        /* Convert the data to low-level representation */
 1903|       |        group = EC_GROUP_new_by_curve_name_ex(NULL, NULL, key->ecdsa_nid);
 1904|       |        point = EC_POINT_new(group);
 1905|       |        rc = EC_POINT_oct2point(group, point, pubkey, pubkey_len, NULL);
 1906|       |        if (group == NULL || point == NULL || rc != 1) {
 1907|       |            EC_GROUP_free(group);
 1908|       |            EC_POINT_free(point);
 1909|       |            goto fail;
 1910|       |        }
 1911|       |
 1912|       |        e = pki_key_make_ecpoint_string(group, point);
 1913|       |        EC_GROUP_free(group);
 1914|       |        EC_POINT_free(point);
 1915|       |#endif /* OPENSSL_VERSION_NUMBER */
 1916|      0|        if (e == NULL) {
  ------------------
  |  Branch (1916:13): [True: 0, False: 0]
  ------------------
 1917|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1918|      0|            return NULL;
 1919|      0|        }
 1920|       |
 1921|      0|        rc = ssh_buffer_add_ssh_string(buffer, e);
 1922|      0|        if (rc < 0) {
  ------------------
  |  Branch (1922:13): [True: 0, False: 0]
  ------------------
 1923|      0|            goto fail;
 1924|      0|        }
 1925|       |
 1926|      0|        ssh_string_burn(e);
 1927|      0|        SSH_STRING_FREE(e);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1928|      0|        e = NULL;
 1929|       |
 1930|      0|        if (type == SSH_KEY_PRIVATE && key->type != SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1930:13): [True: 0, False: 0]
  |  Branch (1930:40): [True: 0, False: 0]
  ------------------
 1931|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1932|       |            OSSL_PARAM_free(params);
 1933|       |            rc = EVP_PKEY_todata(key->key, EVP_PKEY_KEYPAIR, &params);
 1934|       |            if (rc < 0) {
 1935|       |                goto fail;
 1936|       |            }
 1937|       |
 1938|       |            locate_param = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_PRIV_KEY);
 1939|       |            rc = OSSL_PARAM_get_BN(locate_param, &bd);
 1940|       |            if (rc != 1) {
 1941|       |                goto fail;
 1942|       |            }
 1943|       |            d = ssh_make_bignum_string((BIGNUM *)bd);
 1944|       |            if (d == NULL) {
 1945|       |                goto fail;
 1946|       |            }
 1947|       |            if (ssh_buffer_add_ssh_string(buffer, d) < 0) {
 1948|       |                goto fail;
 1949|       |            }
 1950|       |#else
 1951|      0|            exp = EC_KEY_get0_private_key(ec);
 1952|      0|            if (exp == NULL) {
  ------------------
  |  Branch (1952:17): [True: 0, False: 0]
  ------------------
 1953|      0|                goto fail;
 1954|      0|            }
 1955|      0|            d = ssh_make_bignum_string((BIGNUM *)exp);
 1956|      0|            if (d == NULL) {
  ------------------
  |  Branch (1956:17): [True: 0, False: 0]
  ------------------
 1957|      0|                goto fail;
 1958|      0|            }
 1959|      0|            rc = ssh_buffer_add_ssh_string(buffer, d);
 1960|      0|            if (rc < 0) {
  ------------------
  |  Branch (1960:17): [True: 0, False: 0]
  ------------------
 1961|      0|                goto fail;
 1962|      0|            }
 1963|      0|#endif /* OPENSSL_VERSION_NUMBER */
 1964|      0|            ssh_string_burn(d);
 1965|      0|            SSH_STRING_FREE(d);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1966|      0|            d = NULL;
 1967|      0|        } else if (type == SSH_KEY_PRIVATE &&
  ------------------
  |  Branch (1967:20): [True: 0, False: 0]
  ------------------
 1968|      0|                   key->type == SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1968:20): [True: 0, False: 0]
  ------------------
 1969|       |
 1970|      0|            rc = pki_buffer_pack_sk_priv_data(buffer, key);
 1971|      0|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1971:17): [True: 0, False: 0]
  ------------------
 1972|      0|                goto fail;
 1973|      0|            }
 1974|      0|        } else if (type == SSH_KEY_PUBLIC &&
  ------------------
  |  Branch (1974:20): [True: 0, False: 0]
  ------------------
 1975|      0|                   key->type == SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1975:20): [True: 0, False: 0]
  ------------------
 1976|       |            /* public key can contain certificate sk information */
 1977|      0|            rc = ssh_buffer_add_ssh_string(buffer, key->sk_application);
 1978|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1978:17): [True: 0, False: 0]
  ------------------
 1979|      0|                goto fail;
 1980|      0|            }
 1981|      0|        }
 1982|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 1983|       |        bignum_safe_free(bd);
 1984|       |        OSSL_PARAM_free(params);
 1985|       |        params = NULL;
 1986|       |#endif /* OPENSSL_VERSION_NUMBER */
 1987|      0|        break;
 1988|      0|    }
 1989|      0|#endif /* HAVE_OPENSSL_ECC */
 1990|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1990:5): [True: 0, False: 33]
  ------------------
 1991|      0|    default:
  ------------------
  |  Branch (1991:5): [True: 0, False: 33]
  ------------------
 1992|      0|        goto fail;
 1993|     33|    }
 1994|       |
 1995|     33|makestring:
 1996|     33|    str = ssh_string_new(ssh_buffer_get_len(buffer));
 1997|     33|    if (str == NULL) {
  ------------------
  |  Branch (1997:9): [True: 0, False: 33]
  ------------------
 1998|      0|        goto fail;
 1999|      0|    }
 2000|       |
 2001|     33|    rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
 2002|     33|    if (rc < 0) {
  ------------------
  |  Branch (2002:9): [True: 0, False: 33]
  ------------------
 2003|      0|        goto fail;
 2004|      0|    }
 2005|     33|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  966|     33|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 33, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 33]
  |  |  ------------------
  ------------------
 2006|       |
 2007|     33|    return str;
 2008|      0|fail:
 2009|      0|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2010|      0|    ssh_string_burn(str);
 2011|      0|    SSH_STRING_FREE(str);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2012|      0|    ssh_string_burn(e);
 2013|      0|    SSH_STRING_FREE(e);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2014|      0|    ssh_string_burn(p);
 2015|      0|    SSH_STRING_FREE(p);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2016|      0|    ssh_string_burn(g);
 2017|      0|    SSH_STRING_FREE(g);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2018|      0|    ssh_string_burn(q);
 2019|      0|    SSH_STRING_FREE(q);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2020|      0|    ssh_string_burn(n);
 2021|      0|    SSH_STRING_FREE(n);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2022|      0|    ssh_string_burn(d);
 2023|      0|    SSH_STRING_FREE(d);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2024|      0|    ssh_string_burn(iqmp);
 2025|      0|    SSH_STRING_FREE(iqmp);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2026|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
 2027|       |    bignum_safe_free(bp);
 2028|       |    bignum_safe_free(bq);
 2029|       |    bignum_safe_free(bg);
 2030|       |    bignum_safe_free(bpub_key);
 2031|       |    bignum_safe_free(bn);
 2032|       |    bignum_safe_free(be);
 2033|       |    bignum_safe_free(bd);
 2034|       |    bignum_safe_free(biqmp);
 2035|       |    OSSL_PARAM_free(params);
 2036|       |#endif /* OPENSSL_VERSION_NUMBER */
 2037|      0|    free(ed25519_pubkey);
 2038|      0|    if (ed25519_privkey) {
  ------------------
  |  Branch (2038:9): [True: 0, False: 0]
  ------------------
 2039|      0|        ssh_burn(ed25519_privkey, ED25519_KEY_LEN);
  ------------------
  |  |  390|      0|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 2040|      0|        free(ed25519_privkey);
 2041|      0|    }
 2042|       |
 2043|       |    return NULL;
 2044|     33|}
pki_signature_from_blob:
 2391|      4|{
 2392|      4|    ssh_signature sig;
 2393|      4|    int rc;
 2394|       |
 2395|      4|    if (ssh_key_type_plain(pubkey->type) != type) {
  ------------------
  |  Branch (2395:9): [True: 2, False: 2]
  ------------------
 2396|      2|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2397|      2|                "Incompatible public key provided (%d) expecting (%d)",
 2398|      2|                type,
 2399|      2|                pubkey->type);
 2400|      2|        return NULL;
 2401|      2|    }
 2402|       |
 2403|      2|    sig = ssh_signature_new();
 2404|      2|    if (sig == NULL) {
  ------------------
  |  Branch (2404:9): [True: 0, False: 2]
  ------------------
 2405|      0|        return NULL;
 2406|      0|    }
 2407|       |
 2408|      2|    sig->type = type;
 2409|      2|    sig->type_c = ssh_key_signature_to_char(type, hash_type);
 2410|      2|    sig->hash_type = hash_type;
 2411|       |
 2412|      2|    switch(type) {
 2413|      2|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2413:9): [True: 2, False: 0]
  ------------------
 2414|      2|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2414:9): [True: 0, False: 2]
  ------------------
 2415|      2|            rc = pki_signature_from_rsa_blob(pubkey, sig_blob, sig);
 2416|      2|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2416:17): [True: 0, False: 2]
  ------------------
 2417|      0|                goto error;
 2418|      0|            }
 2419|      2|            break;
 2420|      2|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2420:9): [True: 0, False: 2]
  ------------------
 2421|      0|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2421:9): [True: 0, False: 2]
  ------------------
 2422|      0|            rc = pki_signature_from_ed25519_blob(sig, sig_blob);
 2423|      0|            if (rc != SSH_OK){
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2423:17): [True: 0, False: 0]
  ------------------
 2424|      0|                goto error;
 2425|      0|            }
 2426|      0|            break;
 2427|      0|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2427:9): [True: 0, False: 2]
  ------------------
 2428|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2428:9): [True: 0, False: 2]
  ------------------
 2429|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2429:9): [True: 0, False: 2]
  ------------------
 2430|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2430:9): [True: 0, False: 2]
  ------------------
 2431|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2431:9): [True: 0, False: 2]
  ------------------
 2432|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2432:9): [True: 0, False: 2]
  ------------------
 2433|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2433:9): [True: 0, False: 2]
  ------------------
 2434|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2434:9): [True: 0, False: 2]
  ------------------
 2435|      0|#ifdef HAVE_OPENSSL_ECC
 2436|      0|            rc = pki_signature_from_ecdsa_blob(pubkey, sig_blob, sig);
 2437|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2437:17): [True: 0, False: 0]
  ------------------
 2438|      0|                goto error;
 2439|      0|            }
 2440|      0|            break;
 2441|      0|#endif
 2442|      0|        default:
  ------------------
  |  Branch (2442:9): [True: 0, False: 2]
  ------------------
 2443|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2443:9): [True: 0, False: 2]
  ------------------
 2444|      0|            SSH_LOG(SSH_LOG_TRACE, "Unknown signature type");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2445|      0|            goto error;
 2446|      2|    }
 2447|       |
 2448|      2|    return sig;
 2449|       |
 2450|      0|error:
 2451|      0|    ssh_signature_free(sig);
 2452|       |    return NULL;
 2453|      2|}
pki_verify_data_signature:
 2674|      2|{
 2675|      2|    const EVP_MD *md = NULL;
 2676|      2|    EVP_MD_CTX *ctx = NULL;
 2677|      2|    EVP_PKEY *pkey = NULL;
 2678|       |
 2679|      2|    unsigned char *raw_sig_data = NULL;
 2680|      2|    size_t raw_sig_len;
 2681|       |
 2682|       |    /* Function return code
 2683|       |     * Do not change this variable throughout the function until the signature
 2684|       |     * is successfully verified!
 2685|       |     */
 2686|      2|    int rc = SSH_ERROR;
  ------------------
  |  |  317|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2687|      2|    int ok;
 2688|       |
 2689|      2|    if (pubkey == NULL || ssh_key_is_private(pubkey) || input == NULL ||
  ------------------
  |  Branch (2689:9): [True: 0, False: 2]
  |  Branch (2689:27): [True: 0, False: 2]
  |  Branch (2689:57): [True: 0, False: 2]
  ------------------
 2690|      2|        signature == NULL || signature->raw_sig == NULL)
  ------------------
  |  Branch (2690:9): [True: 0, False: 2]
  |  Branch (2690:30): [True: 0, False: 2]
  ------------------
 2691|      0|    {
 2692|      0|        SSH_LOG(SSH_LOG_TRACE, "Bad parameter provided to "
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2693|      0|                               "pki_verify_data_signature()");
 2694|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2695|      0|    }
 2696|       |
 2697|       |    /* Check if public key and hash type are compatible */
 2698|      2|    ok = pki_key_check_hash_compatible(pubkey, signature->hash_type);
 2699|      2|    if (ok != SSH_OK) {
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2699:9): [True: 0, False: 2]
  ------------------
 2700|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2701|      0|    }
 2702|       |
 2703|       |    /* Get the signature to be verified */
 2704|      2|    raw_sig_data = ssh_string_data(signature->raw_sig);
 2705|      2|    raw_sig_len = ssh_string_len(signature->raw_sig);
 2706|      2|    if (raw_sig_data == NULL) {
  ------------------
  |  Branch (2706:9): [True: 0, False: 2]
  ------------------
 2707|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2708|      0|    }
 2709|       |
 2710|       |    /* Set hash algorithm to be used */
 2711|      2|    md = pki_digest_to_md(signature->hash_type);
 2712|      2|    if (md == NULL) {
  ------------------
  |  Branch (2712:9): [True: 0, False: 2]
  ------------------
 2713|      0|        if (signature->hash_type != SSH_DIGEST_AUTO) {
  ------------------
  |  Branch (2713:13): [True: 0, False: 0]
  ------------------
 2714|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2715|      0|        }
 2716|      0|    }
 2717|       |
 2718|       |    /* Setup public key EVP_PKEY */
 2719|      2|    pkey = pki_key_to_pkey(pubkey);
 2720|      2|    if (pkey == NULL) {
  ------------------
  |  Branch (2720:9): [True: 0, False: 2]
  ------------------
 2721|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2722|      0|    }
 2723|       |
 2724|       |    /* Create the context */
 2725|      2|    ctx = EVP_MD_CTX_new();
 2726|      2|    if (ctx == NULL) {
  ------------------
  |  Branch (2726:9): [True: 0, False: 2]
  ------------------
 2727|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2728|      0|                "Failed to create EVP_MD_CTX: %s",
 2729|      0|                ERR_error_string(ERR_get_error(), NULL));
 2730|      0|        goto out;
 2731|      0|    }
 2732|       |
 2733|       |    /* Verify the signature */
 2734|      2|    ok = EVP_DigestVerifyInit(ctx, NULL, md, NULL, pkey);
 2735|      2|    if (ok != 1){
  ------------------
  |  Branch (2735:9): [True: 0, False: 2]
  ------------------
 2736|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2737|      0|                "EVP_DigestVerifyInit() failed: %s",
 2738|      0|                ERR_error_string(ERR_get_error(), NULL));
 2739|      0|        goto out;
 2740|      0|    }
 2741|       |
 2742|      2|    ok = EVP_DigestVerify(ctx, raw_sig_data, raw_sig_len, input, input_len);
 2743|      2|    if (ok != 1) {
  ------------------
  |  Branch (2743:9): [True: 2, False: 0]
  ------------------
 2744|      2|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2745|      2|                "Signature invalid: %s",
 2746|      2|                ERR_error_string(ERR_get_error(), NULL));
 2747|      2|        goto out;
 2748|      2|    }
 2749|       |
 2750|      0|    SSH_LOG(SSH_LOG_TRACE, "Signature valid");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2751|      0|    rc = SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2752|       |
 2753|      2|out:
 2754|      2|    EVP_MD_CTX_free(ctx);
 2755|      2|    EVP_PKEY_free(pkey);
 2756|      2|    return rc;
 2757|      0|}
ssh_key_size:
 2760|      2|{
 2761|      2|    int bits = 0;
 2762|      2|    EVP_PKEY *pkey = NULL;
 2763|       |
 2764|      2|    switch (key->type) {
 2765|      2|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2765:5): [True: 2, False: 0]
  ------------------
 2766|      2|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (2766:5): [True: 0, False: 2]
  ------------------
 2767|      2|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2767:5): [True: 0, False: 2]
  ------------------
 2768|      2|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2768:5): [True: 0, False: 2]
  ------------------
 2769|      2|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2769:5): [True: 0, False: 2]
  ------------------
 2770|      2|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2770:5): [True: 0, False: 2]
  ------------------
 2771|      2|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2771:5): [True: 0, False: 2]
  ------------------
 2772|      2|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2772:5): [True: 0, False: 2]
  ------------------
 2773|      2|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2773:5): [True: 0, False: 2]
  ------------------
 2774|      2|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2774:5): [True: 0, False: 2]
  ------------------
 2775|      2|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2775:5): [True: 0, False: 2]
  ------------------
 2776|      2|        pkey = pki_key_to_pkey(key);
 2777|      2|        if (pkey == NULL) {
  ------------------
  |  Branch (2777:13): [True: 0, False: 2]
  ------------------
 2778|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2779|      0|        }
 2780|      2|        bits = EVP_PKEY_bits(pkey);
 2781|      2|        EVP_PKEY_free(pkey);
 2782|      2|        return bits;
 2783|      0|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2783:5): [True: 0, False: 2]
  ------------------
 2784|      0|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (2784:5): [True: 0, False: 2]
  ------------------
 2785|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2785:5): [True: 0, False: 2]
  ------------------
 2786|      0|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (2786:5): [True: 0, False: 2]
  ------------------
 2787|       |        /* ed25519 keys have fixed size */
 2788|      0|        return 255;
 2789|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (2789:5): [True: 0, False: 2]
  ------------------
 2790|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (2790:5): [True: 0, False: 2]
  ------------------
 2791|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2791:5): [True: 0, False: 2]
  ------------------
 2792|      0|    default:
  ------------------
  |  Branch (2792:5): [True: 0, False: 2]
  ------------------
 2793|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2794|      2|    }
 2795|      2|}
pki_crypto.c:pki_signature_from_rsa_blob:
 2169|      2|{
 2170|      2|    size_t pad_len = 0;
 2171|      2|    char *blob_orig = NULL;
 2172|      2|    char *blob_padded_data = NULL;
 2173|      2|    ssh_string sig_blob_padded = NULL;
 2174|       |
 2175|      2|    size_t rsalen = 0;
 2176|      2|    size_t len = ssh_string_len(sig_blob);
 2177|       |
 2178|      2|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 2179|      2|    const RSA *rsa = EVP_PKEY_get0_RSA(pubkey->key);
 2180|       |
 2181|      2|    if (rsa == NULL) {
  ------------------
  |  Branch (2181:9): [True: 0, False: 2]
  ------------------
 2182|      0|        SSH_LOG(SSH_LOG_TRACE, "RSA field NULL");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2183|      0|        goto errout;
 2184|      0|    }
 2185|       |
 2186|      2|    rsalen = RSA_size(rsa);
 2187|       |#else
 2188|       |    if (EVP_PKEY_get_base_id(pubkey->key) != EVP_PKEY_RSA) {
 2189|       |        SSH_LOG(SSH_LOG_TRACE, "Key has no RSA pubkey");
 2190|       |        goto errout;
 2191|       |    }
 2192|       |
 2193|       |    rsalen = EVP_PKEY_size(pubkey->key);
 2194|       |#endif /* OPENSSL_VERSION_NUMBER */
 2195|      2|    if (len > rsalen) {
  ------------------
  |  Branch (2195:9): [True: 0, False: 2]
  ------------------
 2196|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2197|      0|                "Signature is too big: %lu > %lu",
 2198|      0|                (unsigned long)len,
 2199|      0|                (unsigned long)rsalen);
 2200|      0|        goto errout;
 2201|      0|    }
 2202|       |
 2203|       |#ifdef DEBUG_CRYPTO
 2204|       |    SSH_LOG(SSH_LOG_DEBUG, "RSA signature len: %lu", (unsigned long)len);
 2205|       |    ssh_log_hexdump("RSA signature", ssh_string_data(sig_blob), len);
 2206|       |#endif /* DEBUG_CRYPTO */
 2207|       |
 2208|      2|    if (len == rsalen) {
  ------------------
  |  Branch (2208:9): [True: 1, False: 1]
  ------------------
 2209|      1|        sig->raw_sig = ssh_string_copy(sig_blob);
 2210|      1|    } else {
 2211|       |        /* pad the blob to the expected rsalen size */
 2212|      1|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2213|      1|                "RSA signature len %lu < %lu",
 2214|      1|                (unsigned long)len,
 2215|      1|                (unsigned long)rsalen);
 2216|       |
 2217|      1|        pad_len = rsalen - len;
 2218|       |
 2219|      1|        sig_blob_padded = ssh_string_new(rsalen);
 2220|      1|        if (sig_blob_padded == NULL) {
  ------------------
  |  Branch (2220:13): [True: 0, False: 1]
  ------------------
 2221|      0|            goto errout;
 2222|      0|        }
 2223|       |
 2224|      1|        blob_padded_data = (char *) ssh_string_data(sig_blob_padded);
 2225|      1|        blob_orig = (char *) ssh_string_data(sig_blob);
 2226|       |
 2227|      1|        if (blob_padded_data == NULL || blob_orig == NULL) {
  ------------------
  |  Branch (2227:13): [True: 0, False: 1]
  |  Branch (2227:41): [True: 0, False: 1]
  ------------------
 2228|      0|            goto errout;
 2229|      0|        }
 2230|       |
 2231|       |        /* front-pad the buffer with zeroes */
 2232|      1|        ssh_burn(blob_padded_data, pad_len);
  ------------------
  |  |  390|      1|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 2233|       |        /* fill the rest with the actual signature blob */
 2234|      1|        memcpy(blob_padded_data + pad_len, blob_orig, len);
 2235|       |
 2236|      1|        sig->raw_sig = sig_blob_padded;
 2237|      1|    }
 2238|       |
 2239|      2|    return SSH_OK;
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
 2240|       |
 2241|      0|errout:
 2242|      0|    SSH_STRING_FREE(sig_blob_padded);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2243|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2244|      2|}
pki_crypto.c:pki_digest_to_md:
 2456|      2|{
 2457|      2|    const EVP_MD *md = NULL;
 2458|       |
 2459|      2|    switch (hash_type) {
 2460|      0|    case SSH_DIGEST_SHA256:
  ------------------
  |  Branch (2460:5): [True: 0, False: 2]
  ------------------
 2461|      0|        md = EVP_sha256();
 2462|      0|        break;
 2463|      0|    case SSH_DIGEST_SHA384:
  ------------------
  |  Branch (2463:5): [True: 0, False: 2]
  ------------------
 2464|      0|        md = EVP_sha384();
 2465|      0|        break;
 2466|      2|    case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (2466:5): [True: 2, False: 0]
  ------------------
 2467|      2|        md = EVP_sha512();
 2468|      2|        break;
 2469|      0|    case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (2469:5): [True: 0, False: 2]
  ------------------
 2470|      0|        md = EVP_sha1();
 2471|      0|        break;
 2472|      0|    case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (2472:5): [True: 0, False: 2]
  ------------------
 2473|      0|        md = NULL;
 2474|      0|        break;
 2475|      0|    default:
  ------------------
  |  Branch (2475:5): [True: 0, False: 2]
  ------------------
 2476|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown hash algorithm for type: %d",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2477|      0|                hash_type);
 2478|      0|        return NULL;
 2479|      2|    }
 2480|       |
 2481|      2|    return md;
 2482|      2|}
pki_crypto.c:pki_key_to_pkey:
 2485|      4|{
 2486|      4|    EVP_PKEY *pkey = NULL;
 2487|      4|    int rc = 0;
 2488|       |
 2489|      4|    switch (key->type) {
 2490|      4|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2490:5): [True: 4, False: 0]
  ------------------
 2491|      4|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2491:5): [True: 0, False: 4]
  ------------------
 2492|      4|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (2492:5): [True: 0, False: 4]
  ------------------
 2493|      4|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2493:5): [True: 0, False: 4]
  ------------------
 2494|      4|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2494:5): [True: 0, False: 4]
  ------------------
 2495|      4|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2495:5): [True: 0, False: 4]
  ------------------
 2496|      4|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2496:5): [True: 0, False: 4]
  ------------------
 2497|      4|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2497:5): [True: 0, False: 4]
  ------------------
 2498|      4|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2498:5): [True: 0, False: 4]
  ------------------
 2499|      4|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2499:5): [True: 0, False: 4]
  ------------------
 2500|      4|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2500:5): [True: 0, False: 4]
  ------------------
 2501|      4|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2501:5): [True: 0, False: 4]
  ------------------
 2502|      4|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (2502:5): [True: 0, False: 4]
  ------------------
 2503|      4|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2503:5): [True: 0, False: 4]
  ------------------
 2504|      4|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (2504:5): [True: 0, False: 4]
  ------------------
 2505|      4|        if (key->key == NULL) {
  ------------------
  |  Branch (2505:13): [True: 0, False: 4]
  ------------------
 2506|      0|            SSH_LOG(SSH_LOG_TRACE, "NULL key->key");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2507|      0|            goto error;
 2508|      0|        }
 2509|      4|        rc = EVP_PKEY_up_ref(key->key);
 2510|      4|        if (rc != 1) {
  ------------------
  |  Branch (2510:13): [True: 0, False: 4]
  ------------------
 2511|      0|            SSH_LOG(SSH_LOG_TRACE, "Failed to reference EVP_PKEY");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2512|      0|            return NULL;
 2513|      0|        }
 2514|      4|        pkey = key->key;
 2515|      4|        break;
 2516|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2516:5): [True: 0, False: 4]
  ------------------
 2517|      0|    default:
  ------------------
  |  Branch (2517:5): [True: 0, False: 4]
  ------------------
 2518|      0|        SSH_LOG(SSH_LOG_TRACE, "Unknown private key algorithm for type: %d",
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2519|      0|                key->type);
 2520|      0|        goto error;
 2521|      4|    }
 2522|       |
 2523|      4|    return pkey;
 2524|       |
 2525|      0|error:
 2526|      0|    EVP_PKEY_free(pkey);
 2527|       |    return NULL;
 2528|      4|}

ssh_poll_init:
   91|      2|{
   92|      2|    return;
   93|      2|}
ssh_poll:
  115|  1.64k|{
  116|  1.64k|    return poll((struct pollfd *)fds, nfds, timeout);
  117|  1.64k|}
ssh_poll_new:
  396|    486|{
  397|    486|    ssh_poll_handle p = NULL;
  398|       |
  399|    486|    p = malloc(sizeof(struct ssh_poll_handle_struct));
  400|    486|    if (p == NULL) {
  ------------------
  |  Branch (400:9): [True: 0, False: 486]
  ------------------
  401|      0|        return NULL;
  402|      0|    }
  403|    486|    ZERO_STRUCTP(p);
  ------------------
  |  |  381|    486|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (381:34): [True: 486, False: 0]
  |  |  |  Branch (381:85): [Folded, False: 486]
  |  |  ------------------
  ------------------
  404|       |
  405|    486|    p->x.fd = fd;
  406|    486|    p->events = events;
  407|    486|    p->cb = cb;
  408|    486|    p->cb_data = userdata;
  409|       |
  410|    486|    return p;
  411|    486|}
ssh_poll_free:
  420|    486|{
  421|    486|    if (p->ctx != NULL) {
  ------------------
  |  Branch (421:9): [True: 486, False: 0]
  ------------------
  422|    486|        ssh_poll_ctx_remove(p->ctx, p);
  423|    486|        p->ctx = NULL;
  424|    486|    }
  425|       |    SAFE_FREE(p);
  ------------------
  |  |  375|    486|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 486, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 486]
  |  |  ------------------
  ------------------
  426|    486|}
ssh_poll_get_ctx:
  436|  1.64k|{
  437|  1.64k|    return p->ctx;
  438|  1.64k|}
ssh_poll_get_events:
  448|  20.8k|{
  449|  20.8k|    return p->events;
  450|  20.8k|}
ssh_poll_set_events:
  461|  21.7k|{
  462|  21.7k|    p->events = events;
  463|  21.7k|    if (p->ctx != NULL) {
  ------------------
  |  Branch (463:9): [True: 20.8k, False: 972]
  ------------------
  464|  20.8k|        if (!ssh_poll_is_locked(p)) {
  ------------------
  |  Branch (464:13): [True: 1.50k, False: 19.3k]
  ------------------
  465|  1.50k|            p->ctx->pollfds[p->x.idx].events = events;
  466|  19.3k|        } else if (!(p->ctx->pollfds[p->x.idx].events & POLLOUT)) {
  ------------------
  |  Branch (466:20): [True: 1.16k, False: 18.1k]
  ------------------
  467|       |            /* if locked, allow only setting POLLOUT to prevent recursive
  468|       |             * callbacks */
  469|       |            p->ctx->pollfds[p->x.idx].events = events & POLLOUT;
  470|  1.16k|        }
  471|  20.8k|    }
  472|  21.7k|}
ssh_poll_add_events:
  498|  20.6k|{
  499|  20.6k|    ssh_poll_set_events(p, ssh_poll_get_events(p) | events);
  500|  20.6k|}
ssh_poll_remove_events:
  510|    140|{
  511|    140|    ssh_poll_set_events(p, ssh_poll_get_events(p) & ~events);
  512|    140|}
ssh_poll_ctx_new:
  560|    486|{
  561|    486|    ssh_poll_ctx ctx;
  562|       |
  563|    486|    ctx = malloc(sizeof(struct ssh_poll_ctx_struct));
  564|    486|    if (ctx == NULL) {
  ------------------
  |  Branch (564:9): [True: 0, False: 486]
  ------------------
  565|      0|        return NULL;
  566|      0|    }
  567|    486|    ZERO_STRUCTP(ctx);
  ------------------
  |  |  381|    486|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (381:34): [True: 486, False: 0]
  |  |  |  Branch (381:85): [Folded, False: 486]
  |  |  ------------------
  ------------------
  568|       |
  569|    486|    if (chunk_size == 0) {
  ------------------
  |  Branch (569:9): [True: 0, False: 486]
  ------------------
  570|      0|        chunk_size = SSH_POLL_CTX_CHUNK;
  ------------------
  |  |   43|      0|#define SSH_POLL_CTX_CHUNK			5
  ------------------
  571|      0|    }
  572|       |
  573|    486|    ctx->chunk_size = chunk_size;
  574|       |
  575|    486|    return ctx;
  576|    486|}
ssh_poll_ctx_free:
  584|    486|{
  585|    486|    if (ctx->polls_allocated > 0) {
  ------------------
  |  Branch (585:9): [True: 486, False: 0]
  ------------------
  586|    486|        while (ctx->polls_used > 0) {
  ------------------
  |  Branch (586:16): [True: 0, False: 486]
  ------------------
  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|    486|        SAFE_FREE(ctx->pollptrs);
  ------------------
  |  |  375|    486|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 486, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 486]
  |  |  ------------------
  ------------------
  596|    486|        SAFE_FREE(ctx->pollfds);
  ------------------
  |  |  375|    486|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 486, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 486]
  |  |  ------------------
  ------------------
  597|    486|    }
  598|       |
  599|       |    SAFE_FREE(ctx);
  ------------------
  |  |  375|    486|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 486, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 486]
  |  |  ------------------
  ------------------
  600|    486|}
ssh_poll_ctx_add:
  647|    486|{
  648|    486|    socket_t fd;
  649|       |
  650|    486|    if (p->ctx != NULL) {
  ------------------
  |  Branch (650:9): [True: 0, False: 486]
  ------------------
  651|       |        /* already attached to a context */
  652|      0|        return -1;
  653|      0|    }
  654|       |
  655|    486|    if (ctx->polls_used == ctx->polls_allocated &&
  ------------------
  |  Branch (655:9): [True: 486, False: 0]
  ------------------
  656|    486|        ssh_poll_ctx_resize(ctx, ctx->polls_allocated + ctx->chunk_size) < 0) {
  ------------------
  |  Branch (656:9): [True: 0, False: 486]
  ------------------
  657|      0|        return -1;
  658|      0|    }
  659|       |
  660|    486|    fd = p->x.fd;
  661|    486|    p->x.idx = ctx->polls_used++;
  662|    486|    ctx->pollptrs[p->x.idx] = p;
  663|    486|    ctx->pollfds[p->x.idx].fd = fd;
  664|    486|    ctx->pollfds[p->x.idx].events = p->events;
  665|    486|    ctx->pollfds[p->x.idx].revents = 0;
  666|    486|    p->ctx = ctx;
  667|       |
  668|    486|    return 0;
  669|    486|}
ssh_poll_ctx_remove:
  697|    486|{
  698|    486|    size_t i;
  699|       |
  700|    486|    i = p->x.idx;
  701|    486|    p->x.fd = ctx->pollfds[i].fd;
  702|    486|    p->ctx = NULL;
  703|       |
  704|    486|    ctx->polls_used--;
  705|       |
  706|       |    /* fill the empty poll slot with the last one */
  707|    486|    if (ctx->polls_used > 0 && ctx->polls_used != i) {
  ------------------
  |  Branch (707:9): [True: 0, False: 486]
  |  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|    486|    if (ctx->polls_allocated - ctx->polls_used > ctx->chunk_size) {
  ------------------
  |  Branch (714:9): [True: 0, False: 486]
  ------------------
  715|      0|        ssh_poll_ctx_resize(ctx, ctx->polls_allocated - ctx->chunk_size);
  716|      0|    }
  717|    486|}
ssh_poll_is_locked:
  726|  22.4k|{
  727|  22.4k|    if (p == NULL) {
  ------------------
  |  Branch (727:9): [True: 0, False: 22.4k]
  ------------------
  728|      0|        return false;
  729|      0|    }
  730|  22.4k|    return p->lock_cnt > 0;
  731|  22.4k|}
ssh_poll_ctx_dopoll:
  750|  1.64k|{
  751|  1.64k|    int rc;
  752|  1.64k|    size_t i, used;
  753|  1.64k|    ssh_poll_handle p = NULL;
  754|  1.64k|    socket_t fd;
  755|  1.64k|    int revents;
  756|  1.64k|    struct ssh_timestamp ts;
  757|       |
  758|  1.64k|    if (ctx->polls_used == 0) {
  ------------------
  |  Branch (758:9): [True: 0, False: 1.64k]
  ------------------
  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|  3.29k|    for (i = 0; i < ctx->polls_used; i++) {
  ------------------
  |  Branch (765:17): [True: 1.64k, False: 1.64k]
  ------------------
  766|       |        /* The lock allows only POLLOUT events: drop the rest */
  767|  1.64k|        if (ssh_poll_is_locked(ctx->pollptrs[i])) {
  ------------------
  |  Branch (767:13): [True: 0, False: 1.64k]
  ------------------
  768|      0|            ctx->pollfds[i].events &= POLLOUT;
  769|      0|        }
  770|  1.64k|    }
  771|  1.64k|    ssh_timestamp_init(&ts);
  772|  1.64k|    do {
  773|  1.64k|        int tm = ssh_timeout_update(&ts, timeout);
  774|  1.64k|        rc = ssh_poll(ctx->pollfds, ctx->polls_used, tm);
  775|  1.64k|    } while (rc == -1 && errno == EINTR);
  ------------------
  |  Branch (775:14): [True: 0, False: 1.64k]
  |  Branch (775:26): [True: 0, False: 0]
  ------------------
  776|       |
  777|  1.64k|    if (rc < 0) {
  ------------------
  |  Branch (777:9): [True: 0, False: 1.64k]
  ------------------
  778|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  779|      0|    }
  780|  1.64k|    if (rc == 0) {
  ------------------
  |  Branch (780:9): [True: 0, False: 1.64k]
  ------------------
  781|      0|        return SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  782|      0|    }
  783|       |
  784|  1.64k|    used = ctx->polls_used;
  785|  3.15k|    for (i = 0; i < used && rc > 0; ) {
  ------------------
  |  Branch (785:17): [True: 1.64k, False: 1.50k]
  |  Branch (785:29): [True: 1.64k, False: 0]
  ------------------
  786|  1.64k|        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|  1.64k|        if (ctx->pollptrs[i]->lock_cnt > 2) {
  ------------------
  |  Branch (791:13): [True: 0, False: 1.64k]
  ------------------
  792|      0|            revents &= POLLOUT;
  793|      0|        }
  794|  1.64k|        if (revents == 0) {
  ------------------
  |  Branch (794:13): [True: 0, False: 1.64k]
  ------------------
  795|      0|            i++;
  796|  1.64k|        } else {
  797|  1.64k|            int ret;
  798|       |
  799|  1.64k|            p = ctx->pollptrs[i];
  800|  1.64k|            fd = ctx->pollfds[i].fd;
  801|       |            /* avoid having any event caught during callback */
  802|  1.64k|            ctx->pollfds[i].events = 0;
  803|  1.64k|            p->lock_cnt++;
  804|  1.64k|            if (p->cb && (ret = p->cb(p, fd, revents, p->cb_data)) < 0) {
  ------------------
  |  Branch (804:17): [True: 1.64k, False: 0]
  |  Branch (804:26): [True: 140, False: 1.50k]
  ------------------
  805|    140|                if (ret == -2) {
  ------------------
  |  Branch (805:21): [True: 140, False: 0]
  ------------------
  806|    140|                    return -1;
  807|    140|                }
  808|       |                /* the poll was removed, reload the used counter and start again
  809|       |                 */
  810|      0|                used = ctx->polls_used;
  811|      0|                i = 0;
  812|  1.50k|            } else {
  813|  1.50k|                ctx->pollfds[i].revents = 0;
  814|  1.50k|                ctx->pollfds[i].events = p->events;
  815|  1.50k|                p->lock_cnt--;
  816|  1.50k|                i++;
  817|  1.50k|            }
  818|       |
  819|  1.50k|            rc--;
  820|  1.50k|        }
  821|  1.64k|    }
  822|       |
  823|  1.50k|    return rc;
  824|  1.64k|}
ssh_poll_get_default_ctx:
  834|    486|{
  835|    486|    if (session->default_poll_ctx != NULL) {
  ------------------
  |  Branch (835:9): [True: 0, False: 486]
  ------------------
  836|      0|        return session->default_poll_ctx;
  837|      0|    }
  838|       |    /* 2 is enough for the default one */
  839|    486|    session->default_poll_ctx = ssh_poll_ctx_new(2);
  840|    486|    return session->default_poll_ctx;
  841|    486|}
poll.c:ssh_poll_ctx_resize:
  603|    486|{
  604|    486|    ssh_poll_handle *pollptrs = NULL;
  605|    486|    ssh_pollfd_t *pollfds = NULL;
  606|       |
  607|    486|    pollptrs = realloc(ctx->pollptrs, sizeof(ssh_poll_handle) * new_size);
  608|    486|    if (pollptrs == NULL) {
  ------------------
  |  Branch (608:9): [True: 0, False: 486]
  ------------------
  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|    486|    ctx->pollptrs = pollptrs;
  613|       |
  614|    486|    pollfds = realloc(ctx->pollfds, sizeof(ssh_pollfd_t) * new_size);
  615|    486|    if (pollfds == NULL) {
  ------------------
  |  Branch (615:9): [True: 0, False: 486]
  ------------------
  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);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375: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|    486|    ctx->pollfds = pollfds;
  633|    486|    ctx->polls_allocated = new_size;
  634|       |
  635|    486|    return SSH_OK;
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  636|    486|}

ssh_new:
   66|    941|{
   67|    941|    ssh_session session = NULL;
   68|    941|    char *id = NULL;
   69|    941|    int rc;
   70|       |
   71|    941|    session = calloc(1, sizeof (struct ssh_session_struct));
   72|    941|    if (session == NULL) {
  ------------------
  |  Branch (72:9): [True: 235, False: 706]
  ------------------
   73|    235|        return NULL;
   74|    235|    }
   75|       |
   76|    706|    session->next_crypto = crypto_new();
   77|    706|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (77:9): [True: 107, False: 599]
  ------------------
   78|    107|        goto err;
   79|    107|    }
   80|       |
   81|    599|    session->socket = ssh_socket_new(session);
   82|    599|    if (session->socket == NULL) {
  ------------------
  |  Branch (82:9): [True: 106, False: 493]
  ------------------
   83|    106|        goto err;
   84|    106|    }
   85|       |
   86|    493|    session->out_buffer = ssh_buffer_new();
   87|    493|    if (session->out_buffer == NULL) {
  ------------------
  |  Branch (87:9): [True: 7, False: 486]
  ------------------
   88|      7|        goto err;
   89|      7|    }
   90|       |
   91|    486|    session->in_buffer = ssh_buffer_new();
   92|    486|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (92:9): [True: 0, False: 486]
  ------------------
   93|      0|        goto err;
   94|      0|    }
   95|       |
   96|    486|    session->out_queue = ssh_list_new();
   97|    486|    if (session->out_queue == NULL) {
  ------------------
  |  Branch (97:9): [True: 0, False: 486]
  ------------------
   98|      0|        goto err;
   99|      0|    }
  100|       |
  101|    486|    session->alive = 0;
  102|    486|    session->auth.supported_methods = 0;
  103|    486|    ssh_set_blocking(session, 1);
  104|    486|    session->maxchannel = FIRST_CHANNEL;
  ------------------
  |  |   49|    486|#define FIRST_CHANNEL 42 // why not ? it helps to find bugs.
  ------------------
  105|    486|    session->proxy_root = true;
  106|       |
  107|    486|    session->agent = ssh_agent_new(session);
  108|    486|    if (session->agent == NULL) {
  ------------------
  |  Branch (108:9): [True: 0, False: 486]
  ------------------
  109|      0|        goto err;
  110|      0|    }
  111|       |
  112|       |    /* Initialise a default PKI context */
  113|    486|    session->pki_context = ssh_pki_ctx_new();
  114|    486|    if (session->pki_context == NULL) {
  ------------------
  |  Branch (114:9): [True: 0, False: 486]
  ------------------
  115|      0|        goto err;
  116|      0|    }
  117|       |
  118|       |    /* OPTIONS */
  119|    486|    session->opts.StrictHostKeyChecking = SSH_STRICT_HOSTKEY_ASK;
  120|    486|    session->opts.port = 22;
  121|    486|    session->opts.fd = -1;
  122|    486|    session->opts.compressionlevel = 7;
  123|    486|    session->opts.nodelay = 0;
  124|    486|    session->opts.identities_only = false;
  125|    486|    session->opts.server_alive_interval = 0;
  126|    486|    session->opts.server_alive_count_max = 3;
  127|    486|    session->opts.batch_mode = false;
  128|    486|    session->opts.gateway_ports = false;
  129|    486|    session->opts.control_master = SSH_CONTROL_MASTER_NO;
  130|       |
  131|    486|    session->opts.flags = SSH_OPT_FLAG_PASSWORD_AUTH |
  ------------------
  |  |  109|    486|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
  132|    486|                          SSH_OPT_FLAG_PUBKEY_AUTH |
  ------------------
  |  |  110|    486|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
  133|    486|                          SSH_OPT_FLAG_KBDINT_AUTH |
  ------------------
  |  |  111|    486|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
  134|    486|                          SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|    486|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
  135|    486|    session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
  136|       |
  137|    486|    session->opts.exp_flags = 0;
  138|       |
  139|       |#ifdef WITH_GSSAPI
  140|       |    session->opts.gssapi_key_exchange_algs =
  141|       |        strdup(GSSAPI_KEY_EXCHANGE_SUPPORTED);
  142|       |    if (session->opts.gssapi_key_exchange_algs == NULL) {
  143|       |        goto err;
  144|       |    }
  145|       |#endif /* WITH_GSSAPI */
  146|       |
  147|       |    /* Lazy allocation for identity_non_exp before populating the defaults */
  148|    486|    if (session->opts.identity_non_exp == NULL) {
  ------------------
  |  Branch (148:9): [True: 486, False: 0]
  ------------------
  149|    486|        session->opts.identity_non_exp = ssh_list_new();
  150|    486|        if (session->opts.identity_non_exp == NULL) {
  ------------------
  |  Branch (150:13): [True: 0, False: 486]
  ------------------
  151|      0|            goto err;
  152|      0|        }
  153|    486|    }
  154|       |
  155|    486|    id = strdup("%d/.ssh/id_ed25519");
  156|    486|    if (id == NULL) {
  ------------------
  |  Branch (156:9): [True: 0, False: 486]
  ------------------
  157|      0|        goto err;
  158|      0|    }
  159|       |
  160|    486|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  161|    486|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    486|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (161:9): [True: 0, False: 486]
  ------------------
  162|      0|        goto err;
  163|      0|    }
  164|       |
  165|    486|#ifdef HAVE_ECC
  166|    486|    id = strdup("%d/.ssh/id_ecdsa");
  167|    486|    if (id == NULL) {
  ------------------
  |  Branch (167:9): [True: 0, False: 486]
  ------------------
  168|      0|        goto err;
  169|      0|    }
  170|    486|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  171|    486|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    486|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (171:9): [True: 0, False: 486]
  ------------------
  172|      0|        goto err;
  173|      0|    }
  174|    486|#endif
  175|       |
  176|    486|    id = strdup("%d/.ssh/id_rsa");
  177|    486|    if (id == NULL) {
  ------------------
  |  Branch (177:9): [True: 0, False: 486]
  ------------------
  178|      0|        goto err;
  179|      0|    }
  180|    486|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  181|    486|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    486|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (181:9): [True: 0, False: 486]
  ------------------
  182|      0|        goto err;
  183|      0|    }
  184|       |
  185|       |#ifdef WITH_FIDO2
  186|       |    /* Add security key identities */
  187|       |    id = strdup("%d/.ssh/id_ed25519_sk");
  188|       |    if (id == NULL) {
  189|       |        goto err;
  190|       |    }
  191|       |    rc = ssh_list_append(session->opts.identity_non_exp, id);
  192|       |    if (rc == SSH_ERROR) {
  193|       |        goto err;
  194|       |    }
  195|       |
  196|       |#ifdef HAVE_ECC
  197|       |    id = strdup("%d/.ssh/id_ecdsa_sk");
  198|       |    if (id == NULL) {
  199|       |        goto err;
  200|       |    }
  201|       |    rc = ssh_list_append(session->opts.identity_non_exp, id);
  202|       |    if (rc == SSH_ERROR) {
  203|       |        goto err;
  204|       |    }
  205|       |#endif /* HAVE_ECC */
  206|       |#endif /* WITH_FIDO2 */
  207|       |
  208|       |    /* Explicitly initialize states */
  209|    486|    session->session_state = SSH_SESSION_STATE_NONE;
  210|    486|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  211|    486|    session->packet_state = PACKET_STATE_INIT;
  212|    486|    session->dh_handshake_state = DH_STATE_INIT;
  213|    486|    session->global_req_state = SSH_CHANNEL_REQ_STATE_NONE;
  214|       |
  215|    486|    session->auth.state = SSH_AUTH_STATE_NONE;
  216|    486|    session->auth.service_state = SSH_AUTH_SERVICE_NONE;
  217|       |
  218|    486|    return session;
  219|       |
  220|    220|err:
  221|    220|    free(id);
  222|    220|    ssh_free(session);
  223|       |    return NULL;
  224|    486|}
ssh_free:
  235|  1.16k|{
  236|  1.16k|  int i;
  237|  1.16k|  struct ssh_iterator *it = NULL;
  238|  1.16k|  struct ssh_buffer_struct *b = NULL;
  239|       |
  240|  1.16k|  if (session == NULL) {
  ------------------
  |  Branch (240:7): [True: 455, False: 706]
  ------------------
  241|    455|    return;
  242|    455|  }
  243|       |
  244|       |  /*
  245|       |   * Delete all channels
  246|       |   *
  247|       |   * This needs the first thing we clean up cause if there is still an open
  248|       |   * channel we call ssh_channel_close() first. So we need a working socket
  249|       |   * and poll context for it.
  250|       |   */
  251|    706|  for (it = ssh_list_get_iterator(session->channels);
  252|    706|       it != NULL;
  ------------------
  |  Branch (252:8): [True: 0, False: 706]
  ------------------
  253|    706|       it = ssh_list_get_iterator(session->channels)) {
  254|      0|      ssh_channel_do_free(ssh_iterator_value(ssh_channel,it));
  ------------------
  |  |  120|      0|  ((type)((iterator)->data))
  ------------------
  255|      0|      ssh_list_remove(session->channels, it);
  256|      0|  }
  257|    706|  ssh_list_free(session->channels);
  258|    706|  session->channels = NULL;
  259|       |
  260|    706|#ifdef WITH_PCAP
  261|    706|  if (session->pcap_ctx) {
  ------------------
  |  Branch (261:7): [True: 0, False: 706]
  ------------------
  262|      0|      ssh_pcap_context_free(session->pcap_ctx);
  263|      0|      session->pcap_ctx = NULL;
  264|      0|  }
  265|    706|#endif
  266|       |
  267|    706|  ssh_socket_free(session->socket);
  268|    706|  session->socket = NULL;
  269|       |
  270|    706|  if (session->default_poll_ctx) {
  ------------------
  |  Branch (270:7): [True: 486, False: 220]
  ------------------
  271|    486|      ssh_poll_ctx_free(session->default_poll_ctx);
  272|    486|  }
  273|       |
  274|    706|  SSH_BUFFER_FREE(session->in_buffer);
  ------------------
  |  |  966|    706|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 486, False: 220]
  |  |  |  Branch (966:69): [Folded, False: 706]
  |  |  ------------------
  ------------------
  275|    706|  SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  966|    706|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 486, False: 220]
  |  |  |  Branch (966:69): [Folded, False: 706]
  |  |  ------------------
  ------------------
  276|    706|  session->in_buffer = session->out_buffer = NULL;
  277|       |
  278|    706|  if (session->in_hashbuf != NULL) {
  ------------------
  |  Branch (278:7): [True: 254, False: 452]
  ------------------
  279|    254|      SSH_BUFFER_FREE(session->in_hashbuf);
  ------------------
  |  |  966|    254|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 254, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 254]
  |  |  ------------------
  ------------------
  280|    254|  }
  281|    706|  if (session->out_hashbuf != NULL) {
  ------------------
  |  Branch (281:7): [True: 409, False: 297]
  ------------------
  282|    409|      SSH_BUFFER_FREE(session->out_hashbuf);
  ------------------
  |  |  966|    409|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 409, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 409]
  |  |  ------------------
  ------------------
  283|    409|  }
  284|       |
  285|    706|  crypto_free(session->current_crypto);
  286|    706|  crypto_free(session->next_crypto);
  287|       |
  288|    706|  ssh_agent_free(session->agent);
  289|       |
  290|    706|  SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1059|    706|    do {                         \
  |  | 1060|    706|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1060:13): [True: 486, False: 220]
  |  |  ------------------
  |  | 1061|    486|            ssh_pki_ctx_free(x); \
  |  | 1062|    486|            x = NULL;            \
  |  | 1063|    486|        }                        \
  |  | 1064|    706|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1064:14): [Folded, False: 706]
  |  |  ------------------
  ------------------
  291|       |
  292|    706|  ssh_key_free(session->srv.rsa_key);
  293|    706|  session->srv.rsa_key = NULL;
  294|    706|  ssh_key_free(session->srv.ecdsa_key);
  295|    706|  session->srv.ecdsa_key = NULL;
  296|    706|  ssh_key_free(session->srv.ed25519_key);
  297|    706|  session->srv.ed25519_key = NULL;
  298|       |
  299|    706|  if (session->ssh_message_list) {
  ------------------
  |  Branch (299:7): [True: 0, False: 706]
  ------------------
  300|      0|      ssh_message msg;
  301|       |
  302|      0|      for (msg = ssh_list_pop_head(ssh_message, session->ssh_message_list);
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  303|      0|           msg != NULL;
  ------------------
  |  Branch (303:12): [True: 0, False: 0]
  ------------------
  304|      0|           msg = ssh_list_pop_head(ssh_message, session->ssh_message_list)) {
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  305|      0|          ssh_message_free(msg);
  306|      0|      }
  307|      0|      ssh_list_free(session->ssh_message_list);
  308|      0|  }
  309|       |
  310|    706|  if (session->kbdint != NULL) {
  ------------------
  |  Branch (310:7): [True: 0, False: 706]
  ------------------
  311|      0|    ssh_kbdint_free(session->kbdint);
  312|      0|  }
  313|       |
  314|    706|  if (session->packet_callbacks) {
  ------------------
  |  Branch (314:7): [True: 0, False: 706]
  ------------------
  315|      0|    ssh_list_free(session->packet_callbacks);
  316|      0|  }
  317|       |
  318|       |#ifdef WITH_GSSAPI
  319|       |    ssh_gssapi_free(session);
  320|       |    SAFE_FREE(session->opts.gssapi_key_exchange_algs);
  321|       |#endif
  322|       |
  323|       |  /* options */
  324|    706|  if (session->opts.identity) {
  ------------------
  |  Branch (324:7): [True: 486, False: 220]
  ------------------
  325|    486|      char *id = NULL;
  326|       |
  327|    486|      for (id = ssh_list_pop_head(char *, session->opts.identity);
  ------------------
  |  |  128|    486|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  328|  1.94k|           id != NULL;
  ------------------
  |  Branch (328:12): [True: 1.45k, False: 486]
  ------------------
  329|  1.45k|           id = ssh_list_pop_head(char *, session->opts.identity)) {
  ------------------
  |  |  128|  1.45k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  330|  1.45k|          SAFE_FREE(id);
  ------------------
  |  |  375|  1.45k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.45k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.45k]
  |  |  ------------------
  ------------------
  331|  1.45k|      }
  332|    486|      ssh_list_free(session->opts.identity);
  333|    486|  }
  334|       |
  335|    706|  if (session->opts.identity_non_exp) {
  ------------------
  |  Branch (335:7): [True: 486, False: 220]
  ------------------
  336|    486|      char *id = NULL;
  337|       |
  338|    486|      for (id = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  128|    486|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  339|    486|           id != NULL;
  ------------------
  |  Branch (339:12): [True: 0, False: 486]
  ------------------
  340|    486|           id = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  341|      0|          SAFE_FREE(id);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  342|      0|      }
  343|    486|      ssh_list_free(session->opts.identity_non_exp);
  344|    486|  }
  345|       |
  346|    706|    if (session->opts.certificate) {
  ------------------
  |  Branch (346:9): [True: 486, False: 220]
  ------------------
  347|    486|        char *cert = NULL;
  348|       |
  349|    486|        for (cert = ssh_list_pop_head(char *, session->opts.certificate);
  ------------------
  |  |  128|    486|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  350|    486|             cert != NULL;
  ------------------
  |  Branch (350:14): [True: 0, False: 486]
  ------------------
  351|    486|             cert = ssh_list_pop_head(char *, session->opts.certificate)) {
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  352|      0|            SAFE_FREE(cert);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  353|      0|        }
  354|    486|        ssh_list_free(session->opts.certificate);
  355|    486|    }
  356|       |
  357|    706|    if (session->opts.certificate_non_exp) {
  ------------------
  |  Branch (357:9): [True: 0, False: 706]
  ------------------
  358|      0|        char *cert = NULL;
  359|       |
  360|      0|        for (cert = ssh_list_pop_head(char *, session->opts.certificate_non_exp);
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  361|      0|             cert != NULL;
  ------------------
  |  Branch (361:14): [True: 0, False: 0]
  ------------------
  362|      0|             cert = ssh_list_pop_head(char *, session->opts.certificate_non_exp)) {
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  363|      0|            SAFE_FREE(cert);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  364|      0|        }
  365|      0|        ssh_list_free(session->opts.certificate_non_exp);
  366|      0|    }
  367|       |
  368|    706|    ssh_proxyjumps_free(session->opts.proxy_jumps);
  369|    706|    SSH_LIST_FREE(session->opts.proxy_jumps);
  ------------------
  |  |  131|    706|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (131:14): [True: 0, False: 706]
  |  |  |  Branch (131:69): [Folded, False: 706]
  |  |  ------------------
  ------------------
  370|    706|    SSH_LIST_FREE(session->opts.proxy_jumps_user_cb);
  ------------------
  |  |  131|    706|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (131:14): [True: 0, False: 706]
  |  |  |  Branch (131:69): [Folded, False: 706]
  |  |  ------------------
  ------------------
  371|    706|    SAFE_FREE(session->opts.proxy_jumps_str);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  372|       |
  373|    706|    if (session->opts.send_env) {
  ------------------
  |  Branch (373:9): [True: 0, False: 706]
  ------------------
  374|      0|        char *pattern = NULL;
  375|       |
  376|      0|        for (pattern = ssh_list_pop_head(char *, session->opts.send_env);
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  377|      0|             pattern != NULL;
  ------------------
  |  Branch (377:14): [True: 0, False: 0]
  ------------------
  378|      0|             pattern = ssh_list_pop_head(char *, session->opts.send_env)) {
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  379|      0|            SAFE_FREE(pattern);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  380|      0|        }
  381|      0|        ssh_list_free(session->opts.send_env);
  382|      0|    }
  383|       |
  384|    706|    while ((b = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  128|    706|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  |  Branch (384:12): [True: 0, False: 706]
  ------------------
  385|    706|                                  session->out_queue)) != NULL) {
  386|      0|        SSH_BUFFER_FREE(b);
  ------------------
  |  |  966|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 0, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  387|      0|    }
  388|    706|    ssh_list_free(session->out_queue);
  389|       |
  390|    706|  ssh_agent_state_free(session->agent_state);
  391|    706|  session->agent_state = NULL;
  392|       |
  393|    706|  SAFE_FREE(session->auth.auto_state);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  394|    706|  SAFE_FREE(session->serverbanner);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  395|    706|  SAFE_FREE(session->clientbanner);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  396|    706|  SAFE_FREE(session->banner);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  397|    706|  SAFE_FREE(session->disconnect_message);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  398|    706|  SAFE_FREE(session->peer_discon_msg);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  399|       |
  400|    706|  SAFE_FREE(session->opts.agent_socket);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  401|    706|  SAFE_FREE(session->opts.bindaddr);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  402|    706|  SAFE_FREE(session->opts.username);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 486, False: 220]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  403|    706|  SAFE_FREE(session->opts.host);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 486, False: 220]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  404|    706|  SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 486, False: 220]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  405|    706|  SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  406|    706|  SAFE_FREE(session->opts.tag);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  407|    706|  SAFE_FREE(session->opts.homedir);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 486, False: 220]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  408|    706|  SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 486, False: 220]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  409|    706|  SAFE_FREE(session->opts.knownhosts);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 486, False: 220]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  410|    706|  SAFE_FREE(session->opts.global_knownhosts);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 486, False: 220]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  411|    706|  SAFE_FREE(session->opts.ProxyCommand);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  412|    706|  SAFE_FREE(session->opts.gss_server_identity);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  413|    706|  SAFE_FREE(session->opts.gss_client_identity);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  414|    706|  SAFE_FREE(session->opts.pubkey_accepted_types);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  415|    706|  SAFE_FREE(session->opts.control_path);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  416|    706|  SAFE_FREE(session->opts.preferred_authentications);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  417|    706|  SAFE_FREE(session->opts.forward_agent_sock_path);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  418|       |
  419|    706|  if (session->opts.local_forward) {
  ------------------
  |  Branch (419:7): [True: 0, False: 706]
  ------------------
  420|      0|      char *entry = NULL;
  421|       |
  422|      0|      for (entry = ssh_list_pop_head(char *, session->opts.local_forward);
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  423|      0|           entry != NULL;
  ------------------
  |  Branch (423:12): [True: 0, False: 0]
  ------------------
  424|      0|           entry = ssh_list_pop_head(char *, session->opts.local_forward)) {
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  425|      0|          SAFE_FREE(entry);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  426|      0|      }
  427|      0|      ssh_list_free(session->opts.local_forward);
  428|      0|  }
  429|       |
  430|    706|  if (session->opts.remote_forward) {
  ------------------
  |  Branch (430:7): [True: 0, False: 706]
  ------------------
  431|      0|      char *entry = NULL;
  432|       |
  433|      0|      for (entry = ssh_list_pop_head(char *, session->opts.remote_forward);
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  434|      0|           entry != NULL;
  ------------------
  |  Branch (434:12): [True: 0, False: 0]
  ------------------
  435|      0|           entry = ssh_list_pop_head(char *, session->opts.remote_forward)) {
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  436|      0|          SAFE_FREE(entry);
  ------------------
  |  |  375|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  437|      0|      }
  438|      0|      ssh_list_free(session->opts.remote_forward);
  439|      0|  }
  440|       |
  441|  7.76k|  for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  7.76k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (441:15): [True: 7.06k, False: 706]
  ------------------
  442|  7.06k|      if (session->opts.wanted_methods[i]) {
  ------------------
  |  Branch (442:11): [True: 1.94k, False: 5.11k]
  ------------------
  443|  1.94k|          SAFE_FREE(session->opts.wanted_methods[i]);
  ------------------
  |  |  375|  1.94k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.94k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.94k]
  |  |  ------------------
  ------------------
  444|  1.94k|      }
  445|  7.06k|  }
  446|       |
  447|    706|  SAFE_FREE(session->server_opts.custombanner);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  448|    706|  SAFE_FREE(session->server_opts.moduli_file);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 706]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  449|       |
  450|    706|  _ssh_remove_legacy_log_cb();
  451|       |
  452|       |  /* burn connection, it could contain sensitive data */
  453|    706|  ssh_burn(session, sizeof(struct ssh_session_struct));
  ------------------
  |  |  390|    706|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  454|       |  SAFE_FREE(session);
  ------------------
  |  |  375|    706|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 706, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 706]
  |  |  ------------------
  ------------------
  455|    706|}
ssh_session_socket_close:
  635|    701|{
  636|    701|    if (session->opts.fd == SSH_INVALID_SOCKET) {
  ------------------
  |  |  124|    701|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  |  Branch (636:9): [True: 0, False: 701]
  ------------------
  637|      0|        ssh_socket_close(session->socket);
  638|      0|    }
  639|    701|    session->alive = 0;
  640|    701|    session->session_state = SSH_SESSION_STATE_ERROR;
  641|    701|}
ssh_set_blocking:
  669|    486|{
  670|    486|    if (session == NULL) {
  ------------------
  |  Branch (670:9): [True: 0, False: 486]
  ------------------
  671|      0|        return;
  672|      0|    }
  673|    486|    session->flags &= ~SSH_SESSION_FLAG_BLOCKING;
  ------------------
  |  |   75|    486|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  674|    486|    session->flags |= blocking ? SSH_SESSION_FLAG_BLOCKING : 0;
  ------------------
  |  |   75|    486|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (674:23): [True: 486, False: 0]
  ------------------
  675|    486|}
ssh_is_blocking:
  684|    972|{
  685|    972|    return (session->flags & SSH_SESSION_FLAG_BLOCKING) ? 1 : 0;
  ------------------
  |  |   75|    972|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (685:12): [True: 972, False: 0]
  ------------------
  686|    972|}
ssh_set_fd_towrite:
  778|    486|void ssh_set_fd_towrite(ssh_session session) {
  779|    486|  if (session == NULL) {
  ------------------
  |  Branch (779:7): [True: 0, False: 486]
  ------------------
  780|      0|    return;
  781|      0|  }
  782|       |
  783|    486|  ssh_socket_set_write_wontblock(session->socket);
  784|    486|}
ssh_handle_packets:
  821|  1.64k|{
  822|  1.64k|    ssh_poll_handle spoll = NULL;
  823|  1.64k|    ssh_poll_ctx ctx = NULL;
  824|  1.64k|    int tm = timeout;
  825|  1.64k|    int rc;
  826|       |
  827|  1.64k|    if (session == NULL || session->socket == NULL) {
  ------------------
  |  Branch (827:9): [True: 0, False: 1.64k]
  |  Branch (827:28): [True: 0, False: 1.64k]
  ------------------
  828|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  829|      0|    }
  830|       |
  831|  1.64k|    spoll = ssh_socket_get_poll_handle(session->socket);
  832|  1.64k|    if (spoll == NULL) {
  ------------------
  |  Branch (832:9): [True: 0, False: 1.64k]
  ------------------
  833|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  834|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  835|      0|    }
  836|  1.64k|    ssh_poll_add_events(spoll, POLLIN);
  837|  1.64k|    ctx = ssh_poll_get_ctx(spoll);
  838|       |
  839|  1.64k|    if (ctx == NULL) {
  ------------------
  |  Branch (839:9): [True: 486, False: 1.16k]
  ------------------
  840|    486|        ctx = ssh_poll_get_default_ctx(session);
  841|    486|        if (ctx == NULL) {
  ------------------
  |  Branch (841:13): [True: 0, False: 486]
  ------------------
  842|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  843|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  844|      0|        }
  845|    486|        rc = ssh_poll_ctx_add(ctx, spoll);
  846|    486|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (846:13): [True: 0, False: 486]
  ------------------
  847|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  848|      0|        }
  849|    486|    }
  850|       |
  851|  1.64k|    if (timeout == SSH_TIMEOUT_USER) {
  ------------------
  |  |  101|  1.64k|#define SSH_TIMEOUT_USER -2
  ------------------
  |  Branch (851:9): [True: 0, False: 1.64k]
  ------------------
  852|      0|        if (ssh_is_blocking(session)) {
  ------------------
  |  Branch (852:13): [True: 0, False: 0]
  ------------------
  853|      0|            tm = ssh_make_milliseconds(session->opts.timeout,
  854|      0|                                       session->opts.timeout_usec);
  855|      0|        } else {
  856|      0|            tm = 0;
  857|      0|        }
  858|      0|    }
  859|  1.64k|    rc = ssh_poll_ctx_dopoll(ctx, tm);
  860|  1.64k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  1.64k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (860:9): [True: 140, False: 1.50k]
  ------------------
  861|    140|        session->session_state = SSH_SESSION_STATE_ERROR;
  862|    140|    }
  863|       |
  864|  1.64k|    return rc;
  865|  1.64k|}
ssh_handle_packets_termination:
  898|    486|{
  899|    486|    struct ssh_timestamp ts;
  900|    486|    int timeout_ms = SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|    486|#define SSH_TIMEOUT_INFINITE -1
  ------------------
  901|    486|    int tm;
  902|    486|    int ret = SSH_OK;
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  903|       |
  904|       |    /* If a timeout has been provided, use it */
  905|    486|    if (timeout >= 0) {
  ------------------
  |  Branch (905:9): [True: 486, False: 0]
  ------------------
  906|    486|        timeout_ms = timeout;
  907|    486|    } else {
  908|      0|        if (ssh_is_blocking(session)) {
  ------------------
  |  Branch (908:13): [True: 0, False: 0]
  ------------------
  909|      0|            if (timeout == SSH_TIMEOUT_USER || timeout == SSH_TIMEOUT_DEFAULT) {
  ------------------
  |  |  101|      0|#define SSH_TIMEOUT_USER -2
  ------------------
                          if (timeout == SSH_TIMEOUT_USER || timeout == SSH_TIMEOUT_DEFAULT) {
  ------------------
  |  |  103|      0|#define SSH_TIMEOUT_DEFAULT -3
  ------------------
  |  Branch (909:17): [True: 0, False: 0]
  |  Branch (909:48): [True: 0, False: 0]
  ------------------
  910|      0|                if (session->opts.timeout > 0 ||
  ------------------
  |  Branch (910:21): [True: 0, False: 0]
  ------------------
  911|      0|                    session->opts.timeout_usec > 0) {
  ------------------
  |  Branch (911:21): [True: 0, False: 0]
  ------------------
  912|      0|                    timeout_ms =
  913|      0|                        ssh_make_milliseconds(session->opts.timeout,
  914|      0|                                              session->opts.timeout_usec);
  915|      0|                }
  916|      0|            }
  917|      0|        } else {
  918|      0|            timeout_ms = SSH_TIMEOUT_NONBLOCKING;
  ------------------
  |  |  105|      0|#define SSH_TIMEOUT_NONBLOCKING 0
  ------------------
  919|      0|        }
  920|      0|    }
  921|       |
  922|       |    /* avoid unnecessary syscall for the SSH_TIMEOUT_NONBLOCKING case */
  923|    486|    if (timeout_ms != SSH_TIMEOUT_NONBLOCKING) {
  ------------------
  |  |  105|    486|#define SSH_TIMEOUT_NONBLOCKING 0
  ------------------
  |  Branch (923:9): [True: 486, False: 0]
  ------------------
  924|    486|        ssh_timestamp_init(&ts);
  925|    486|    }
  926|       |
  927|    486|    tm = timeout_ms;
  928|  1.99k|    while(!fct(user)) {
  ------------------
  |  Branch (928:11): [True: 1.64k, False: 346]
  ------------------
  929|  1.64k|        ret = ssh_handle_packets(session, tm);
  930|  1.64k|        if (ret == SSH_ERROR) {
  ------------------
  |  |  317|  1.64k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (930:13): [True: 140, False: 1.50k]
  ------------------
  931|    140|            break;
  932|    140|        }
  933|  1.50k|        if (ssh_timeout_elapsed(&ts, timeout_ms)) {
  ------------------
  |  Branch (933:13): [True: 0, False: 1.50k]
  ------------------
  934|      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 (934:19): [True: 0, False: 0]
  ------------------
  935|      0|            break;
  936|      0|        }
  937|       |
  938|  1.50k|        tm = ssh_timeout_update(&ts, timeout_ms);
  939|  1.50k|    }
  940|       |
  941|    486|    return ret;
  942|    486|}
ssh_socket_exception_callback:
 1053|    140|void ssh_socket_exception_callback(int code, int errno_code, void *user){
 1054|    140|    ssh_session session = (ssh_session)user;
 1055|       |
 1056|    140|    SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  283|    140|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1057|    140|            "Socket exception callback: %d (%d)",
 1058|    140|            code,
 1059|    140|            errno_code);
 1060|    140|    session->session_state = SSH_SESSION_STATE_ERROR;
 1061|    140|    if (errno_code == 0 && code == SSH_SOCKET_EXCEPTION_EOF) {
  ------------------
  |  |  521|    140|#define SSH_SOCKET_EXCEPTION_EOF 	     1
  ------------------
  |  Branch (1061:9): [True: 140, False: 0]
  |  Branch (1061:28): [True: 140, False: 0]
  ------------------
 1062|    140|        ssh_set_error(session, SSH_FATAL, "Socket error: disconnected");
  ------------------
  |  |  313|    140|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1063|       |#ifdef _WIN32
 1064|       |    } else if (errno_code == WSAENETDOWN) {
 1065|       |        ssh_set_error(session, SSH_FATAL, "Socket error: network down");
 1066|       |    } else if (errno_code == WSAENETUNREACH) {
 1067|       |        ssh_set_error(session, SSH_FATAL, "Socket error: network unreachable");
 1068|       |    } else if (errno_code == WSAENETRESET) {
 1069|       |        ssh_set_error(session, SSH_FATAL, "Socket error: network reset");
 1070|       |    } else if (errno_code == WSAECONNABORTED) {
 1071|       |        ssh_set_error(session, SSH_FATAL, "Socket error: connection aborted");
 1072|       |    } else if (errno_code == WSAECONNRESET) {
 1073|       |        ssh_set_error(session,
 1074|       |                      SSH_FATAL,
 1075|       |                      "Socket error: connection reset by peer");
 1076|       |    } else if (errno_code == WSAETIMEDOUT) {
 1077|       |        ssh_set_error(session, SSH_FATAL, "Socket error: connection timed out");
 1078|       |    } else if (errno_code == WSAECONNREFUSED) {
 1079|       |        ssh_set_error(session, SSH_FATAL, "Socket error: connection refused");
 1080|       |    } else if (errno_code == WSAEHOSTUNREACH) {
 1081|       |        ssh_set_error(session, SSH_FATAL, "Socket error: host unreachable");
 1082|       |#endif
 1083|    140|    } else {
 1084|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};
 1085|      0|        ssh_set_error(session,
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1086|      0|                      SSH_FATAL,
 1087|      0|                      "Socket error: %s",
 1088|      0|                      ssh_strerror(errno_code, err_msg, SSH_ERRNO_MSG_MAX));
 1089|      0|    }
 1090|       |
 1091|    140|    session->ssh_connection_callback(session);
 1092|    140|}

ssh_client_sntrup761x25519_init:
  105|     26|{
  106|     26|    int rc;
  107|       |
  108|     26|    rc = ssh_sntrup761x25519_init(session);
  109|     26|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     26|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (109:9): [True: 0, False: 26]
  ------------------
  110|      0|        return rc;
  111|      0|    }
  112|       |
  113|     26|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|     26|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     26|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     26|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     26|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     26|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     26|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     26|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  114|     26|                         "bdPP",
  115|     26|                         SSH2_MSG_KEX_ECDH_INIT,
  116|     26|                         CURVE25519_PUBKEY_SIZE + SNTRUP761_PUBLICKEY_SIZE,
  117|     26|                         (size_t)SNTRUP761_PUBLICKEY_SIZE,
  118|     26|                         session->next_crypto->sntrup761_client_pubkey,
  119|     26|                         (size_t)CURVE25519_PUBKEY_SIZE,
  120|     26|                         session->next_crypto->curve25519_client_pubkey);
  121|     26|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     26|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (121:9): [True: 0, False: 26]
  ------------------
  122|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  123|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  124|      0|    }
  125|       |
  126|       |    /* register the packet callbacks */
  127|     26|    ssh_packet_set_callbacks(session, &ssh_sntrup761x25519_client_callbacks);
  128|     26|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  129|     26|    rc = ssh_packet_send(session);
  130|       |
  131|     26|    return rc;
  132|     26|}
ssh_client_sntrup761x25519_remove_callbacks:
  135|     16|{
  136|     16|    ssh_packet_remove_callbacks(session, &ssh_sntrup761x25519_client_callbacks);
  137|     16|}
sntrup761.c:ssh_sntrup761x25519_init:
   62|     26|{
   63|     26|    int rc;
   64|       |
   65|     26|    rc = ssh_curve25519_init(session);
   66|     26|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     26|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (66:9): [True: 0, False: 26]
  ------------------
   67|      0|        return rc;
   68|      0|    }
   69|       |
   70|     26|    if (!session->server) {
  ------------------
  |  Branch (70:9): [True: 26, False: 0]
  ------------------
   71|       |#ifdef HAVE_LIBGCRYPT
   72|       |        gcry_error_t err;
   73|       |
   74|       |        err = gcry_kem_keypair(GCRY_KEM_SNTRUP761,
   75|       |                               session->next_crypto->sntrup761_client_pubkey,
   76|       |                               SNTRUP761_PUBLICKEY_SIZE,
   77|       |                               session->next_crypto->sntrup761_privkey,
   78|       |                               SNTRUP761_SECRETKEY_SIZE);
   79|       |        if (err) {
   80|       |            SSH_LOG(SSH_LOG_TRACE,
   81|       |                    "Failed to generate sntrup761 key: %s",
   82|       |                    gpg_strerror(err));
   83|       |            return SSH_ERROR;
   84|       |        }
   85|       |#else
   86|     26|        sntrup761_keypair(session->next_crypto->sntrup761_client_pubkey,
   87|     26|                          session->next_crypto->sntrup761_privkey,
   88|     26|                          &rc,
   89|     26|                          crypto_random);
   90|     26|        if (rc != 1) {
  ------------------
  |  Branch (90:13): [True: 0, False: 26]
  ------------------
   91|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
   92|      0|                    "Failed to generate sntrup761 key: PRNG failure");
   93|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   94|      0|        }
   95|     26|#endif /* HAVE_LIBGCRYPT */
   96|     26|    }
   97|       |
   98|     26|    return SSH_OK;
  ------------------
  |  |  316|     26|#define SSH_OK 0     /* No error */
  ------------------
   99|     26|}
sntrup761.c:crypto_random:
   41|  39.5k|{
   42|  39.5k|    int *err = ctx;
   43|  39.5k|    *err = ssh_get_random(dst, length, 1);
   44|  39.5k|}
sntrup761.c:ssh_packet_client_sntrup761x25519_reply:
  248|     16|{
  249|     16|    ssh_string q_s_string = NULL;
  250|     16|    ssh_string pubkey_blob = NULL;
  251|     16|    ssh_string signature = NULL;
  252|     16|    int rc;
  253|     16|    (void)type;
  254|     16|    (void)user;
  255|       |
  256|     16|    ssh_client_sntrup761x25519_remove_callbacks(session);
  257|       |
  258|     16|    pubkey_blob = ssh_buffer_get_ssh_string(packet);
  259|     16|    if (pubkey_blob == NULL) {
  ------------------
  |  Branch (259:9): [True: 3, False: 13]
  ------------------
  260|      3|        ssh_set_error(session, SSH_FATAL, "No public key in packet");
  ------------------
  |  |  313|      3|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  261|      3|        goto error;
  262|      3|    }
  263|       |
  264|     13|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  265|     13|    SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  924|     13|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 13, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 13]
  |  |  ------------------
  ------------------
  266|     13|    if (rc != 0) {
  ------------------
  |  Branch (266:9): [True: 12, False: 1]
  ------------------
  267|     12|        ssh_set_error(session, SSH_FATAL, "Failed to import next public key");
  ------------------
  |  |  313|     12|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  268|     12|        goto error;
  269|     12|    }
  270|       |
  271|      1|    q_s_string = ssh_buffer_get_ssh_string(packet);
  272|      1|    if (q_s_string == NULL) {
  ------------------
  |  Branch (272:9): [True: 0, False: 1]
  ------------------
  273|      0|        ssh_set_error(session, SSH_FATAL, "No sntrup761x25519 Q_S in packet");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  274|      0|        goto error;
  275|      0|    }
  276|      1|    if (ssh_string_len(q_s_string) != (SNTRUP761_CIPHERTEXT_SIZE + CURVE25519_PUBKEY_SIZE)) {
  ------------------
  |  |   51|      1|#define SNTRUP761_CIPHERTEXT_SIZE 1039
  ------------------
                  if (ssh_string_len(q_s_string) != (SNTRUP761_CIPHERTEXT_SIZE + CURVE25519_PUBKEY_SIZE)) {
  ------------------
  |  |   40|      1|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  |  Branch (276:9): [True: 1, False: 0]
  ------------------
  277|      1|        ssh_set_error(session,
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  278|      1|                      SSH_FATAL,
  279|      1|                      "Incorrect size for server sntrup761x25519 ciphertext+key: %d",
  280|      1|                      (int)ssh_string_len(q_s_string));
  281|      1|        SSH_STRING_FREE(q_s_string);
  ------------------
  |  |  924|      1|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 1, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
  282|      1|        goto error;
  283|      1|    }
  284|      0|    memcpy(session->next_crypto->sntrup761_ciphertext,
  285|      0|           ssh_string_data(q_s_string),
  286|      0|           SNTRUP761_CIPHERTEXT_SIZE);
  ------------------
  |  |   51|      0|#define SNTRUP761_CIPHERTEXT_SIZE 1039
  ------------------
  287|      0|    memcpy(session->next_crypto->curve25519_server_pubkey,
  288|      0|           (char *)ssh_string_data(q_s_string) + SNTRUP761_CIPHERTEXT_SIZE,
  ------------------
  |  |   51|      0|#define SNTRUP761_CIPHERTEXT_SIZE 1039
  ------------------
  289|      0|           CURVE25519_PUBKEY_SIZE);
  ------------------
  |  |   40|      0|#define CURVE25519_PUBKEY_SIZE 32
  ------------------
  290|      0|    SSH_STRING_FREE(q_s_string);
  ------------------
  |  |  924|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  291|       |
  292|      0|    signature = ssh_buffer_get_ssh_string(packet);
  293|      0|    if (signature == NULL) {
  ------------------
  |  Branch (293:9): [True: 0, False: 0]
  ------------------
  294|      0|        ssh_set_error(session, SSH_FATAL, "No signature in packet");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  295|      0|        goto error;
  296|      0|    }
  297|      0|    session->next_crypto->dh_server_signature = signature;
  298|      0|    signature = NULL; /* ownership changed */
  299|       |    /* TODO: verify signature now instead of waiting for NEWKEYS */
  300|      0|    if (ssh_sntrup761x25519_build_k(session) < 0) {
  ------------------
  |  Branch (300:9): [True: 0, False: 0]
  ------------------
  301|      0|        ssh_set_error(session, SSH_FATAL, "Cannot build k number");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  302|      0|        goto error;
  303|      0|    }
  304|       |
  305|       |    /* Send the MSG_NEWKEYS */
  306|      0|    if (ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS) < 0) {
  ------------------
  |  |   13|      0|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (306:9): [True: 0, False: 0]
  ------------------
  307|      0|        goto error;
  308|      0|    }
  309|       |
  310|      0|    rc = ssh_packet_send(session);
  311|      0|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (311:9): [True: 0, False: 0]
  ------------------
  312|      0|        goto error;
  313|      0|    }
  314|       |
  315|      0|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_NEWKEYS sent");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  316|      0|    session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  317|       |
  318|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      0|#define SSH_PACKET_USED 1
  ------------------
  319|       |
  320|     16|error:
  321|     16|    session->session_state = SSH_SESSION_STATE_ERROR;
  322|     16|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     16|#define SSH_PACKET_USED 1
  ------------------
  323|      0|}

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

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

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

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

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

ssh_get_hmactab:
   74|     33|struct ssh_hmac_struct *ssh_get_hmactab(void) {
   75|     33|  return ssh_hmac_tab;
   76|     33|}
hmac_digest_len:
   78|    601|size_t hmac_digest_len(enum ssh_hmac_e type) {
   79|    601|  switch(type) {
   80|      0|    case SSH_HMAC_SHA1:
  ------------------
  |  Branch (80:5): [True: 0, False: 601]
  ------------------
   81|      0|      return SHA_DIGEST_LEN;
  ------------------
  |  |   44|      0|#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
  ------------------
   82|      0|    case SSH_HMAC_SHA256:
  ------------------
  |  Branch (82:5): [True: 0, False: 601]
  ------------------
   83|      0|      return SHA256_DIGEST_LEN;
  ------------------
  |  |   45|      0|#define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
  ------------------
   84|      0|    case SSH_HMAC_SHA512:
  ------------------
  |  Branch (84:5): [True: 0, False: 601]
  ------------------
   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: 601]
  ------------------
   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: 601]
  ------------------
   89|      0|      return POLY1305_TAGLEN;
  ------------------
  |  |   37|      0|#define POLY1305_TAGLEN 16
  ------------------
   90|      0|    case SSH_HMAC_AEAD_GCM:
  ------------------
  |  Branch (90:5): [True: 0, False: 601]
  ------------------
   91|      0|      return AES_GCM_TAGLEN;
  ------------------
  |  |   58|      0|#define AES_GCM_TAGLEN 16
  ------------------
   92|    601|    default:
  ------------------
  |  Branch (92:5): [True: 601, False: 0]
  ------------------
   93|    601|      return 0;
   94|    601|  }
   95|    601|}
ssh_cipher_clear:
  124|  2.17k|void ssh_cipher_clear(struct ssh_cipher_struct *cipher){
  125|       |#ifdef HAVE_LIBGCRYPT
  126|       |    unsigned int i;
  127|       |#endif
  128|       |
  129|  2.17k|    if (cipher == NULL) {
  ------------------
  |  Branch (129:9): [True: 2.10k, False: 66]
  ------------------
  130|  2.10k|        return;
  131|  2.10k|    }
  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|     66|    if (cipher->cleanup != NULL) {
  ------------------
  |  Branch (142:9): [True: 0, False: 66]
  ------------------
  143|      0|        cipher->cleanup(cipher);
  144|      0|    }
  145|     66|}
crypto_new:
  153|  1.19k|{
  154|  1.19k|    struct ssh_crypto_struct *crypto = NULL;
  155|       |
  156|  1.19k|    crypto = calloc(1, sizeof(struct ssh_crypto_struct));
  157|  1.19k|    if (crypto == NULL) {
  ------------------
  |  Branch (157:9): [True: 107, False: 1.08k]
  ------------------
  158|    107|        return NULL;
  159|    107|    }
  160|  1.08k|    return crypto;
  161|  1.19k|}
crypto_free:
  164|  1.89k|{
  165|  1.89k|    size_t i;
  166|       |
  167|  1.89k|    if (crypto == NULL) {
  ------------------
  |  Branch (167:9): [True: 813, False: 1.08k]
  ------------------
  168|    813|        return;
  169|    813|    }
  170|       |
  171|  1.08k|    ssh_key_free(crypto->server_pubkey);
  172|       |
  173|  1.08k|    ssh_dh_cleanup(crypto);
  174|  1.08k|    bignum_safe_free(crypto->shared_secret);
  ------------------
  |  |   71|  1.08k|#define bignum_safe_free(num) do { \
  |  |   72|  1.08k|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 33, False: 1.05k]
  |  |  ------------------
  |  |   73|     33|        BN_clear_free((num)); \
  |  |   74|     33|        (num)=NULL; \
  |  |   75|     33|    } \
  |  |   76|  1.08k|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 1.08k]
  |  |  ------------------
  ------------------
  175|  1.08k|#ifdef HAVE_ECDH
  176|  1.08k|    SAFE_FREE(crypto->ecdh_client_pubkey);
  ------------------
  |  |  375|  1.08k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 110, False: 975]
  |  |  |  Branch (375:71): [Folded, False: 1.08k]
  |  |  ------------------
  ------------------
  177|  1.08k|    SAFE_FREE(crypto->ecdh_server_pubkey);
  ------------------
  |  |  375|  1.08k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2, False: 1.08k]
  |  |  |  Branch (375:71): [Folded, False: 1.08k]
  |  |  ------------------
  ------------------
  178|  1.08k|    if (crypto->ecdh_privkey != NULL) {
  ------------------
  |  Branch (178:9): [True: 110, False: 975]
  ------------------
  179|    110|#ifdef HAVE_OPENSSL_ECC
  180|    110|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  181|    110|        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|    110|        crypto->ecdh_privkey = NULL;
  192|    110|    }
  193|  1.08k|#endif
  194|  1.08k|#ifdef HAVE_LIBCRYPTO
  195|  1.08k|    EVP_PKEY_free(crypto->curve25519_privkey);
  196|       |#elif defined(HAVE_GCRYPT_CURVE25519)
  197|       |    gcry_sexp_release(crypto->curve25519_privkey);
  198|       |#endif
  199|  1.08k|    SAFE_FREE(crypto->dh_server_signature);
  ------------------
  |  |  375|  1.08k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 21, False: 1.06k]
  |  |  |  Branch (375:71): [Folded, False: 1.08k]
  |  |  ------------------
  ------------------
  200|  1.08k|    if (crypto->session_id != NULL) {
  ------------------
  |  Branch (200:9): [True: 33, False: 1.05k]
  ------------------
  201|     33|        ssh_burn(crypto->session_id, crypto->session_id_len);
  ------------------
  |  |  390|     33|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  202|     33|        SAFE_FREE(crypto->session_id);
  ------------------
  |  |  375|     33|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 33, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 33]
  |  |  ------------------
  ------------------
  203|     33|    }
  204|  1.08k|    if (crypto->secret_hash != NULL) {
  ------------------
  |  Branch (204:9): [True: 33, False: 1.05k]
  ------------------
  205|     33|        ssh_burn(crypto->secret_hash, crypto->digest_len);
  ------------------
  |  |  390|     33|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  206|     33|        SAFE_FREE(crypto->secret_hash);
  ------------------
  |  |  375|     33|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 33, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 33]
  |  |  ------------------
  ------------------
  207|     33|    }
  208|  1.08k|    compress_cleanup(crypto);
  209|  1.08k|    SAFE_FREE(crypto->encryptIV);
  ------------------
  |  |  375|  1.08k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 33, False: 1.05k]
  |  |  |  Branch (375:71): [Folded, False: 1.08k]
  |  |  ------------------
  ------------------
  210|  1.08k|    SAFE_FREE(crypto->decryptIV);
  ------------------
  |  |  375|  1.08k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 33, False: 1.05k]
  |  |  |  Branch (375:71): [Folded, False: 1.08k]
  |  |  ------------------
  ------------------
  211|  1.08k|    SAFE_FREE(crypto->encryptMAC);
  ------------------
  |  |  375|  1.08k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 33, False: 1.05k]
  |  |  |  Branch (375:71): [Folded, False: 1.08k]
  |  |  ------------------
  ------------------
  212|  1.08k|    SAFE_FREE(crypto->decryptMAC);
  ------------------
  |  |  375|  1.08k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 33, False: 1.05k]
  |  |  |  Branch (375:71): [Folded, False: 1.08k]
  |  |  ------------------
  ------------------
  213|  1.08k|    if (crypto->encryptkey != NULL) {
  ------------------
  |  Branch (213:9): [True: 33, False: 1.05k]
  ------------------
  214|     33|        ssh_burn(crypto->encryptkey, crypto->out_cipher->keysize / 8);
  ------------------
  |  |  390|     33|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  215|     33|        SAFE_FREE(crypto->encryptkey);
  ------------------
  |  |  375|     33|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 33, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 33]
  |  |  ------------------
  ------------------
  216|     33|    }
  217|  1.08k|    if (crypto->decryptkey != NULL) {
  ------------------
  |  Branch (217:9): [True: 33, False: 1.05k]
  ------------------
  218|     33|        ssh_burn(crypto->decryptkey, crypto->in_cipher->keysize / 8);
  ------------------
  |  |  390|     33|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  219|     33|        SAFE_FREE(crypto->decryptkey);
  ------------------
  |  |  375|     33|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 33, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 33]
  |  |  ------------------
  ------------------
  220|     33|    }
  221|       |
  222|  1.08k|    cipher_free(crypto->in_cipher);
  223|  1.08k|    cipher_free(crypto->out_cipher);
  224|       |
  225|  11.9k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  11.9k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (225:17): [True: 10.8k, False: 1.08k]
  ------------------
  226|  10.8k|        SAFE_FREE(crypto->client_kex.methods[i]);
  ------------------
  |  |  375|  10.8k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 4.42k, False: 6.43k]
  |  |  |  Branch (375:71): [Folded, False: 10.8k]
  |  |  ------------------
  ------------------
  227|  10.8k|        SAFE_FREE(crypto->server_kex.methods[i]);
  ------------------
  |  |  375|  10.8k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2.67k, False: 8.18k]
  |  |  |  Branch (375:71): [Folded, False: 10.8k]
  |  |  ------------------
  ------------------
  228|  10.8k|        SAFE_FREE(crypto->kex_methods[i]);
  ------------------
  |  |  375|  10.8k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2.08k, False: 8.77k]
  |  |  |  Branch (375:71): [Folded, False: 10.8k]
  |  |  ------------------
  ------------------
  229|  10.8k|    }
  230|       |
  231|       |#ifdef HAVE_OPENSSL_MLKEM
  232|       |    EVP_PKEY_free(crypto->mlkem_privkey);
  233|       |#else
  234|  1.08k|    if (crypto->mlkem_privkey != NULL) {
  ------------------
  |  Branch (234:9): [True: 104, False: 981]
  ------------------
  235|    104|        ssh_burn(crypto->mlkem_privkey, crypto->mlkem_privkey_len);
  ------------------
  |  |  390|    104|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  236|    104|        SAFE_FREE(crypto->mlkem_privkey);
  ------------------
  |  |  375|    104|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 104, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 104]
  |  |  ------------------
  ------------------
  237|    104|        crypto->mlkem_privkey_len = 0;
  238|    104|    }
  239|  1.08k|#endif
  240|  1.08k|    ssh_string_burn(crypto->hybrid_shared_secret);
  241|  1.08k|    ssh_string_free(crypto->mlkem_client_pubkey);
  242|  1.08k|    ssh_string_free(crypto->mlkem_ciphertext);
  243|  1.08k|    ssh_string_free(crypto->hybrid_client_init);
  244|  1.08k|    ssh_string_free(crypto->hybrid_server_reply);
  245|  1.08k|    ssh_string_free(crypto->hybrid_shared_secret);
  246|       |
  247|  1.08k|    ssh_burn(crypto, sizeof(struct ssh_crypto_struct));
  ------------------
  |  |  390|  1.08k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  248|       |
  249|       |    SAFE_FREE(crypto);
  ------------------
  |  |  375|  1.08k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.08k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.08k]
  |  |  ------------------
  ------------------
  250|  1.08k|}
crypt_set_algorithms_client:
  429|     33|{
  430|     33|    return crypt_set_algorithms2(session);
  431|     33|}
wrapper.c:cipher_free:
  147|  2.17k|static void cipher_free(struct ssh_cipher_struct *cipher) {
  148|  2.17k|  ssh_cipher_clear(cipher);
  149|       |  SAFE_FREE(cipher);
  ------------------
  |  |  375|  2.17k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 66, False: 2.10k]
  |  |  |  Branch (375:71): [Folded, False: 2.17k]
  |  |  ------------------
  ------------------
  150|  2.17k|}
wrapper.c:crypt_set_algorithms2:
  275|     33|{
  276|     33|    const char *wanted = NULL;
  277|     33|    const char *method = NULL;
  278|     33|    struct ssh_cipher_struct *ssh_ciphertab=ssh_get_ciphertab();
  279|     33|    struct ssh_hmac_struct *ssh_hmactab=ssh_get_hmactab();
  280|     33|    uint8_t i = 0;
  281|     33|    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|     33|    wanted = session->next_crypto->kex_methods[SSH_CRYPT_C_S];
  290|    363|    for (i = 0; i < 64 && ssh_ciphertab[i].name != NULL; ++i) {
  ------------------
  |  Branch (290:17): [True: 363, False: 0]
  |  Branch (290:27): [True: 363, False: 0]
  ------------------
  291|    363|        cmp = strcmp(wanted, ssh_ciphertab[i].name);
  292|    363|        if (cmp == 0) {
  ------------------
  |  Branch (292:13): [True: 33, False: 330]
  ------------------
  293|     33|            break;
  294|     33|        }
  295|    363|    }
  296|       |
  297|     33|    if (ssh_ciphertab[i].name == NULL) {
  ------------------
  |  Branch (297:9): [True: 0, False: 33]
  ------------------
  298|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      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|     33|    SSH_LOG(SSH_LOG_PACKET, "Set output algorithm to %s", wanted);
  ------------------
  |  |  283|     33|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  304|       |
  305|     33|    session->next_crypto->out_cipher = cipher_new(i);
  306|     33|    if (session->next_crypto->out_cipher == NULL) {
  ------------------
  |  Branch (306:9): [True: 0, False: 33]
  ------------------
  307|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      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|     33|    if (session->next_crypto->out_cipher->aead_encrypt != NULL) {
  ------------------
  |  Branch (311:9): [True: 0, False: 33]
  ------------------
  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|     33|    } else {
  319|       |        /*
  320|       |         * We must scan the kex entries to find hmac algorithms and set their
  321|       |         * appropriate structure.
  322|       |         */
  323|       |
  324|       |        /* out */
  325|     33|        wanted = session->next_crypto->kex_methods[SSH_MAC_C_S];
  326|     33|    }
  327|       |
  328|    363|    for (i = 0; ssh_hmactab[i].name != NULL; i++) {
  ------------------
  |  Branch (328:17): [True: 363, False: 0]
  ------------------
  329|    363|        cmp = strcmp(wanted, ssh_hmactab[i].name);
  330|    363|        if (cmp == 0) {
  ------------------
  |  Branch (330:13): [True: 33, False: 330]
  ------------------
  331|     33|            break;
  332|     33|        }
  333|    363|    }
  334|       |
  335|     33|    if (ssh_hmactab[i].name == NULL) {
  ------------------
  |  Branch (335:9): [True: 0, False: 33]
  ------------------
  336|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      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|     33|    SSH_LOG(SSH_LOG_PACKET, "Set HMAC output algorithm to %s", wanted);
  ------------------
  |  |  283|     33|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  342|       |
  343|     33|    session->next_crypto->out_hmac = ssh_hmactab[i].hmac_type;
  344|     33|    session->next_crypto->out_hmac_etm = ssh_hmactab[i].etm;
  345|       |
  346|       |    /* in */
  347|     33|    wanted = session->next_crypto->kex_methods[SSH_CRYPT_S_C];
  348|       |
  349|    363|    for (i = 0; ssh_ciphertab[i].name != NULL; i++) {
  ------------------
  |  Branch (349:17): [True: 363, False: 0]
  ------------------
  350|    363|        cmp = strcmp(wanted, ssh_ciphertab[i].name);
  351|    363|        if (cmp == 0) {
  ------------------
  |  Branch (351:13): [True: 33, False: 330]
  ------------------
  352|     33|            break;
  353|     33|        }
  354|    363|    }
  355|       |
  356|     33|    if (ssh_ciphertab[i].name == NULL) {
  ------------------
  |  Branch (356:9): [True: 0, False: 33]
  ------------------
  357|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      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|     33|    SSH_LOG(SSH_LOG_PACKET, "Set input algorithm to %s", wanted);
  ------------------
  |  |  283|     33|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  363|       |
  364|     33|    session->next_crypto->in_cipher = cipher_new(i);
  365|     33|    if (session->next_crypto->in_cipher == NULL) {
  ------------------
  |  Branch (365:9): [True: 0, False: 33]
  ------------------
  366|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      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|     33|    if (session->next_crypto->in_cipher->aead_encrypt != NULL){
  ------------------
  |  Branch (370:9): [True: 0, False: 33]
  ------------------
  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|     33|    } else {
  378|       |        /* we must scan the kex entries to find hmac algorithms and set their appropriate structure */
  379|     33|        wanted = session->next_crypto->kex_methods[SSH_MAC_S_C];
  380|     33|    }
  381|       |
  382|    363|    for (i = 0; ssh_hmactab[i].name != NULL; i++) {
  ------------------
  |  Branch (382:17): [True: 363, False: 0]
  ------------------
  383|    363|        cmp = strcmp(wanted, ssh_hmactab[i].name);
  384|    363|        if (cmp == 0) {
  ------------------
  |  Branch (384:13): [True: 33, False: 330]
  ------------------
  385|     33|            break;
  386|     33|        }
  387|    363|    }
  388|       |
  389|     33|    if (ssh_hmactab[i].name == NULL) {
  ------------------
  |  Branch (389:9): [True: 0, False: 33]
  ------------------
  390|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|      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|     33|    SSH_LOG(SSH_LOG_PACKET, "Set HMAC input algorithm to %s", wanted);
  ------------------
  |  |  283|     33|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  396|       |
  397|     33|    session->next_crypto->in_hmac = ssh_hmactab[i].hmac_type;
  398|     33|    session->next_crypto->in_hmac_etm = ssh_hmactab[i].etm;
  399|       |
  400|       |    /* compression: client */
  401|     33|    method = session->next_crypto->kex_methods[SSH_COMP_C_S];
  402|     33|    cmp = strcmp(method, "zlib");
  403|     33|    if (cmp == 0) {
  ------------------
  |  Branch (403:9): [True: 0, False: 33]
  ------------------
  404|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling C->S compression");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  405|      0|        compression_enable(session, SSH_DIRECTION_OUT, false);
  406|      0|    }
  407|     33|    cmp = strcmp(method, "zlib@openssh.com");
  408|     33|    if (cmp == 0) {
  ------------------
  |  Branch (408:9): [True: 0, False: 33]
  ------------------
  409|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling C->S delayed compression");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  410|      0|        compression_enable(session, SSH_DIRECTION_OUT, true);
  411|      0|    }
  412|       |
  413|     33|    method = session->next_crypto->kex_methods[SSH_COMP_S_C];
  414|     33|    cmp = strcmp(method, "zlib");
  415|     33|    if (cmp == 0) {
  ------------------
  |  Branch (415:9): [True: 0, False: 33]
  ------------------
  416|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling S->C compression");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  417|      0|        compression_enable(session, SSH_DIRECTION_IN, false);
  418|      0|    }
  419|     33|    cmp = strcmp(method, "zlib@openssh.com");
  420|     33|    if (cmp == 0) {
  ------------------
  |  Branch (420:9): [True: 0, False: 33]
  ------------------
  421|      0|        SSH_LOG(SSH_LOG_PACKET, "enabling S->C delayed compression");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  422|      0|        compression_enable(session, SSH_DIRECTION_IN, true);
  423|      0|    }
  424|       |
  425|     33|    return SSH_OK;
  ------------------
  |  |  316|     33|#define SSH_OK 0     /* No error */
  ------------------
  426|     33|}
wrapper.c:cipher_new:
  110|     66|static struct ssh_cipher_struct *cipher_new(uint8_t offset) {
  111|     66|  struct ssh_cipher_struct *cipher = NULL;
  112|       |
  113|     66|  cipher = malloc(sizeof(struct ssh_cipher_struct));
  114|     66|  if (cipher == NULL) {
  ------------------
  |  Branch (114:7): [True: 0, False: 66]
  ------------------
  115|      0|    return NULL;
  116|      0|  }
  117|       |
  118|       |  /* note the memcpy will copy the pointers : so, you shouldn't free them */
  119|     66|  memcpy(cipher, &ssh_get_ciphertab()[offset], sizeof(*cipher));
  120|       |
  121|     66|  return cipher;
  122|     66|}

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: 0, False: 2]
  ------------------
  130|      0|        nalloc_random_bitmask = false;
  131|      0|        nalloc_bitmask = 0;
  132|      0|        return;
  133|      0|    }
  134|       |
  135|      2|    char *verbose = getenv("NALLOC_VERBOSE");
  136|      2|    if (verbose) {
  ------------------
  |  Branch (136:9): [True: 0, False: 2]
  ------------------
  137|       |        nalloc_verbose = true;
  138|      0|    }
  139|      2|}
recv:
  289|  1.16k|{
  290|  1.16k|    if (nalloc_fail(count, "recv")) {
  ------------------
  |  Branch (290:9): [True: 0, False: 1.16k]
  ------------------
  291|      0|        errno = EIO;
  292|      0|        return -1;
  293|      0|    }
  294|  1.16k|    return nalloc_recv(fd, buf, count, flags);
  ------------------
  |  |  265|  1.16k|#define nalloc_recv(f, b, s, x) __recv(f, b, s, x)
  ------------------
  295|  1.16k|}
send:
  298|  2.04k|{
  299|  2.04k|    if (nalloc_fail(count, "send")) {
  ------------------
  |  Branch (299:9): [True: 0, False: 2.04k]
  ------------------
  300|      0|        errno = EIO;
  301|      0|        return -1;
  302|      0|    }
  303|  2.04k|    return nalloc_send(fd, buf, count, flags);
  ------------------
  |  |  266|  2.04k|#define nalloc_send(f, b, s, x) __send(f, b, s, x)
  ------------------
  304|  2.04k|}
calloc:
  307|  37.5k|{
  308|  37.5k|    if (nalloc_fail(size, "calloc")) {
  ------------------
  |  Branch (308:9): [True: 438, False: 37.1k]
  ------------------
  309|    438|        errno = ENOMEM;
  310|    438|        return NULL;
  311|    438|    }
  312|  37.1k|    return nalloc_calloc(nmemb, size);
  ------------------
  |  |  259|  37.1k|#define nalloc_calloc(s, n)          __libc_calloc(s, n)
  ------------------
  313|  37.5k|}
malloc:
  316|   200k|{
  317|   200k|    if (nalloc_fail(size, "malloc")) {
  ------------------
  |  Branch (317:9): [True: 0, False: 200k]
  ------------------
  318|      0|        errno = ENOMEM;
  319|      0|        return NULL;
  320|      0|    }
  321|   200k|    return nalloc_malloc(size);
  ------------------
  |  |  258|   200k|#define nalloc_malloc(s)             __libc_malloc(s)
  ------------------
  322|   200k|}
realloc:
  325|  12.2k|{
  326|  12.2k|    if (nalloc_fail(size, "realloc")) {
  ------------------
  |  Branch (326:9): [True: 17, False: 12.2k]
  ------------------
  327|     17|        errno = ENOMEM;
  328|     17|        return NULL;
  329|     17|    }
  330|  12.2k|    return nalloc_realloc(ptr, size);
  ------------------
  |  |  260|  12.2k|#define nalloc_realloc(p, s)         __libc_realloc(p, s)
  ------------------
  331|  12.2k|}
ssh_client_fuzzer.c:nalloc_fail:
  194|   253k|{
  195|       |    // do not fail before thread init
  196|   253k|    if (nalloc_runs == 0) {
  ------------------
  |  Branch (196:9): [True: 8.69k, False: 244k]
  ------------------
  197|  8.69k|        return false;
  198|  8.69k|    }
  199|   244k|    if (__sync_fetch_and_add(&nalloc_running, 1) != 1) {
  ------------------
  |  Branch (199:9): [True: 5.65k, False: 239k]
  ------------------
  200|       |        // do not fail allocations outside of fuzzer input
  201|       |        // and do not fail inside of this function
  202|  5.65k|        __sync_fetch_and_sub(&nalloc_running, 1);
  203|  5.65k|        return false;
  204|  5.65k|    }
  205|   239k|    nalloc_random_update((uint8_t)size);
  206|   239k|    if (size >= 0x100) {
  ------------------
  |  Branch (206:9): [True: 139k, False: 99.2k]
  ------------------
  207|   139k|        nalloc_random_update((uint8_t)(size >> 8));
  208|   139k|        if (size >= 0x10000) {
  ------------------
  |  Branch (208:13): [True: 46, False: 139k]
  ------------------
  209|     46|            nalloc_random_update((uint8_t)(size >> 16));
  210|       |            // bigger may already fail or oom
  211|     46|        }
  212|   139k|    }
  213|   239k|    if (((nalloc_random_state ^ nalloc_magic) & nalloc_bitmask) == 0) {
  ------------------
  |  Branch (213:9): [True: 455, False: 238k]
  ------------------
  214|    455|        if (nalloc_backtrace_exclude(size, op)) {
  ------------------
  |  Branch (214:13): [True: 0, False: 455]
  ------------------
  215|      0|            __sync_fetch_and_sub(&nalloc_running, 1);
  216|      0|            return false;
  217|      0|        }
  218|    455|        __sync_fetch_and_sub(&nalloc_running, 1);
  219|    455|        return true;
  220|    455|    }
  221|   238k|    __sync_fetch_and_sub(&nalloc_running, 1);
  222|       |    return false;
  223|   239k|}
ssh_client_fuzzer.c:nalloc_random_update:
  143|  8.94M|{
  144|  8.94M|    nalloc_random_state =
  145|  8.94M|        ((uint32_t)((uint32_t)nalloc_random_state << 8)) ^
  146|  8.94M|        nalloc_crc32_table[((nalloc_random_state >> 24) ^ b) & 0xFF];
  147|  8.94M|}
ssh_client_fuzzer.c:nalloc_backtrace_exclude:
  181|    455|{
  182|    455|    if (nalloc_verbose) {
  ------------------
  |  Branch (182:9): [True: 0, False: 455]
  ------------------
  183|      0|        fprintf(stderr, "failed %s(%zu) \n", op, size);
  184|       |#ifdef NALLOC_ASAN
  185|       |        __sanitizer_print_stack_trace();
  186|       |#endif
  187|      0|    }
  188|       |
  189|       |    return false;
  190|    455|}
ssh_client_fuzzer.c:nalloc_start:
  151|    941|{
  152|    941|    if (nalloc_random_bitmask) {
  ------------------
  |  Branch (152:9): [True: 941, False: 0]
  ------------------
  153|    941|        if (nalloc_random_state & 0x10) {
  ------------------
  |  Branch (153:13): [True: 486, False: 455]
  ------------------
  154|    486|            nalloc_bitmask = 0xFFFFFFFF;
  155|    486|        } else {
  156|    455|            nalloc_bitmask = 1 << (5 + (nalloc_random_state & 0xF));
  157|    455|        }
  158|    941|    } else if (nalloc_bitmask == 0) {
  ------------------
  |  Branch (158:16): [True: 0, False: 0]
  ------------------
  159|       |        // nalloc disabled
  160|      0|        return 2;
  161|      0|    }
  162|    941|    nalloc_random_state = 0;
  163|  8.56M|    for (size_t i = 0; i < size; i++) {
  ------------------
  |  Branch (163:24): [True: 8.56M, False: 941]
  ------------------
  164|  8.56M|        nalloc_random_update(data[i]);
  165|  8.56M|    }
  166|    941|    if (__sync_fetch_and_add(&nalloc_running, 1)) {
  ------------------
  |  Branch (166:9): [True: 0, False: 941]
  ------------------
  167|      0|        __sync_fetch_and_sub(&nalloc_running, 1);
  168|      0|        return 0;
  169|      0|    }
  170|    941|    nalloc_runs++;
  171|    941|    return 1;
  172|    941|}
ssh_client_fuzzer.c:nalloc_end:
  176|    941|{
  177|    941|    __sync_fetch_and_sub(&nalloc_running, 1);
  178|    941|}

LLVMFuzzerInitialize:
   35|      2|{
   36|      2|    (void)argc;
   37|       |
   38|      2|    nalloc_init(*argv[0]);
   39|       |
   40|      2|    ssh_init();
   41|       |
   42|      2|    atexit(_fuzz_finalize);
   43|       |
   44|      2|    return 0;
   45|      2|}
LLVMFuzzerTestOneInput:
  108|    944|{
  109|    944|    ssh_session session = NULL;
  110|    944|    ssh_channel channel = NULL;
  111|    944|    const char *env = NULL;
  112|    944|    int socket_fds[2] = {-1, -1};
  113|    944|    ssize_t nwritten;
  114|    944|    bool no = false;
  115|    944|    int rc;
  116|    944|    long timeout = 1; /* use short timeout to avoid timeouts during fuzzing */
  117|       |
  118|       |    /* This is the maximum that can be handled by the socket buffer before the
  119|       |     * other side will read some data. Other option would be feeding the socket
  120|       |     * from different thread which would not mind if it would be blocked, but I
  121|       |     * believe all the important inputs should fit into this size */
  122|    944|    if (size > 219264) {
  ------------------
  |  Branch (122:9): [True: 3, False: 941]
  ------------------
  123|      3|        return -1;
  124|      3|    }
  125|       |
  126|       |    /* Set up the socket to send data */
  127|    941|    rc = socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds);
  128|    941|    assert(rc == 0);
  ------------------
  |  Branch (128:5): [True: 0, False: 941]
  |  Branch (128:5): [True: 941, False: 0]
  ------------------
  129|       |
  130|    941|    nwritten = send(socket_fds[1], data, size, 0);
  131|    941|    assert((size_t)nwritten == size);
  ------------------
  |  Branch (131:5): [True: 0, False: 941]
  |  Branch (131:5): [True: 941, False: 0]
  ------------------
  132|       |
  133|    941|    rc = shutdown(socket_fds[1], SHUT_WR);
  134|    941|    assert(rc == 0);
  ------------------
  |  Branch (134:5): [True: 0, False: 941]
  |  Branch (134:5): [True: 941, False: 0]
  ------------------
  135|       |
  136|    941|    assert(nalloc_start(data, size) > 0);
  ------------------
  |  Branch (136:5): [True: 0, False: 941]
  |  Branch (136:5): [True: 941, False: 0]
  ------------------
  137|       |
  138|    941|    session = ssh_new();
  139|    941|    if (session == NULL) {
  ------------------
  |  Branch (139:9): [True: 455, False: 486]
  ------------------
  140|    455|        goto out;
  141|    455|    }
  142|       |
  143|    486|    env = getenv("LIBSSH_VERBOSITY");
  144|    486|    if (env != NULL && strlen(env) > 0) {
  ------------------
  |  Branch (144:9): [True: 0, False: 486]
  |  Branch (144:24): [True: 0, False: 0]
  ------------------
  145|      0|        ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY_STR, env);
  146|      0|    }
  147|    486|    rc = ssh_options_set(session, SSH_OPTIONS_FD, &socket_fds[0]);
  148|    486|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (148:9): [True: 0, False: 486]
  ------------------
  149|      0|        goto out;
  150|      0|    }
  151|    486|    rc = ssh_options_set(session, SSH_OPTIONS_HOST, "127.0.0.1");
  152|    486|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (152:9): [True: 0, False: 486]
  ------------------
  153|      0|        goto out;
  154|      0|    }
  155|    486|    rc = ssh_options_set(session, SSH_OPTIONS_USER, "alice");
  156|    486|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (156:9): [True: 0, False: 486]
  ------------------
  157|      0|        goto out;
  158|      0|    }
  159|    486|    rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_C_S, "none");
  160|    486|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (160:9): [True: 0, False: 486]
  ------------------
  161|      0|        goto out;
  162|      0|    }
  163|    486|    rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_S_C, "none");
  164|    486|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (164:9): [True: 0, False: 486]
  ------------------
  165|      0|        goto out;
  166|      0|    }
  167|    486|    rc = ssh_options_set(session, SSH_OPTIONS_HMAC_C_S, "none");
  168|    486|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (168:9): [True: 0, False: 486]
  ------------------
  169|      0|        goto out;
  170|      0|    }
  171|    486|    rc = ssh_options_set(session, SSH_OPTIONS_HMAC_S_C, "none");
  172|    486|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (172:9): [True: 0, False: 486]
  ------------------
  173|      0|        goto out;
  174|      0|    }
  175|    486|    rc = ssh_options_set(session, SSH_OPTIONS_PROCESS_CONFIG, &no);
  176|    486|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (176:9): [True: 0, False: 486]
  ------------------
  177|      0|        goto out;
  178|      0|    }
  179|    486|    rc = ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &timeout);
  180|    486|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (180:9): [True: 0, False: 486]
  ------------------
  181|      0|        goto out;
  182|      0|    }
  183|       |
  184|    486|    ssh_callbacks_init(&cb);
  ------------------
  |  |  535|    486|#define ssh_callbacks_init(p) do {\
  |  |  536|    486|	(p)->size=sizeof(*(p)); \
  |  |  537|    486|} while(0);
  |  |  ------------------
  |  |  |  Branch (537:9): [Folded, False: 486]
  |  |  ------------------
  ------------------
  185|    486|    ssh_set_callbacks(session, &cb);
  186|       |
  187|    486|    rc = ssh_connect(session);
  188|    486|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    486|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (188:9): [True: 486, False: 0]
  ------------------
  189|    486|        goto out;
  190|    486|    }
  191|       |
  192|      0|    rc = ssh_userauth_none(session, NULL);
  193|      0|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (193:9): [True: 0, False: 0]
  ------------------
  194|      0|        goto out;
  195|      0|    }
  196|       |
  197|      0|    channel = ssh_channel_new(session);
  198|      0|    if (channel == NULL) {
  ------------------
  |  Branch (198:9): [True: 0, False: 0]
  ------------------
  199|      0|        goto out;
  200|      0|    }
  201|       |
  202|      0|    rc = ssh_channel_open_session(channel);
  203|      0|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (203:9): [True: 0, False: 0]
  ------------------
  204|      0|        goto out;
  205|      0|    }
  206|       |
  207|      0|    rc = ssh_channel_request_exec(channel, "ls");
  208|      0|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (208:9): [True: 0, False: 0]
  ------------------
  209|      0|        goto out;
  210|      0|    }
  211|       |
  212|      0|    select_loop(session, channel);
  213|       |
  214|    941|out:
  215|    941|    ssh_channel_free(channel);
  216|    941|    ssh_disconnect(session);
  217|    941|    ssh_free(session);
  218|       |
  219|    941|    close(socket_fds[0]);
  220|    941|    close(socket_fds[1]);
  221|       |
  222|    941|    nalloc_end();
  223|    941|    return 0;
  224|      0|}
ssh_client_fuzzer.c:_fuzz_finalize:
   30|      2|{
   31|      2|    ssh_finalize();
   32|      2|}

