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

ssh_agent_state_free:
 1148|    826|{
 1149|    826|    struct ssh_agent_state_struct *state = data;
 1150|       |
 1151|    826|    if (state) {
  ------------------
  |  Branch (1151:9): [True: 0, False: 826]
  ------------------
 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|    826|}

ssh_make_bignum_string:
   69|    271|{
   70|    271|    return make_bignum_string(num, 0);
   71|    271|}
ssh_make_string_bn:
   79|    150|{
   80|    150|    bignum bn = NULL;
   81|    150|    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|    150|    bignum_bin2bn(string->data, (int)len, &bn);
  ------------------
  |  |   79|    150|    do {                                     \
  |  |   80|    150|        (*dest) = BN_new();                  \
  |  |   81|    150|        if ((*dest) != NULL) {               \
  |  |  ------------------
  |  |  |  Branch (81:13): [True: 150, False: 0]
  |  |  ------------------
  |  |   82|    150|            BN_bin2bn(data,datalen,(*dest)); \
  |  |   83|    150|        }                                    \
  |  |   84|    150|    } while(0)
  |  |  ------------------
  |  |  |  Branch (84:13): [Folded, False: 150]
  |  |  ------------------
  ------------------
   91|       |
   92|    150|    return bn;
   93|    150|}
bignum.c:make_bignum_string:
   31|    271|{
   32|    271|    ssh_string ptr = NULL;
   33|    271|    size_t pad = 0;
   34|    271|    size_t len = bignum_num_bytes(num);
  ------------------
  |  |   98|    271|#define bignum_num_bytes(num) (size_t)BN_num_bytes(num)
  ------------------
   35|    271|    size_t bits = bignum_num_bits(num);
  ------------------
  |  |   99|    271|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
   36|       |
   37|    271|    if (pad_to_len == 0) {
  ------------------
  |  Branch (37:9): [True: 271, False: 0]
  ------------------
   38|       |        /* If the first bit is set we have a negative number */
   39|    271|        if (!(bits % 8) && bignum_is_bit_set(num, bits - 1)) {
  ------------------
  |  |  100|    114|#define bignum_is_bit_set(num,bit) BN_is_bit_set(num, (int)bit)
  |  |  ------------------
  |  |  |  Branch (100:36): [True: 108, False: 6]
  |  |  ------------------
  ------------------
  |  Branch (39:13): [True: 114, False: 157]
  ------------------
   40|    108|            pad++;
   41|    108|        }
   42|    271|    } 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|    271|    ptr = ssh_string_new(len + pad);
   54|    271|    if (ptr == NULL) {
  ------------------
  |  Branch (54:9): [True: 0, False: 271]
  ------------------
   55|      0|        return NULL;
   56|      0|    }
   57|       |
   58|       |    /* We have a negative number so we need a leading zero */
   59|    271|    if (pad) {
  ------------------
  |  Branch (59:9): [True: 108, False: 163]
  ------------------
   60|    108|        memset(ptr->data, 0, pad);
   61|    108|    }
   62|       |
   63|    271|    bignum_bn2bin(num, len, ptr->data + pad);
  ------------------
  |  |  101|    271|#define bignum_bn2bin(num,len, ptr) BN_bn2bin(num, ptr)
  ------------------
   64|       |
   65|    271|    return ptr;
   66|    271|}

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

_ssh_remove_legacy_log_cb:
   49|    826|{
   50|    826|    if (ssh_get_log_callback() == ssh_legacy_log_callback) {
  ------------------
  |  Branch (50:9): [True: 0, False: 826]
  ------------------
   51|      0|        _ssh_reset_log_cb();
   52|       |        ssh_set_log_userdata(NULL);
   53|      0|    }
   54|    826|}
ssh_set_callbacks:
   57|    572|{
   58|    572|    if (session == NULL || cb == NULL) {
  ------------------
  |  Branch (58:9): [True: 0, False: 572]
  |  Branch (58:28): [True: 0, False: 572]
  ------------------
   59|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   60|      0|    }
   61|       |
   62|    572|    if (!is_callback_valid(session, cb)) {
  ------------------
  |  |   31|    572|    (cb->size > 0 || cb->size <= 1024 * sizeof(void *))
  |  |  ------------------
  |  |  |  Branch (31:6): [True: 572, 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|    572|    };
   68|    572|    session->common.callbacks = cb;
   69|       |
   70|       |    /* LEGACY */
   71|    572|    if (ssh_get_log_callback() == NULL && cb->log_function) {
  ------------------
  |  Branch (71:9): [True: 572, False: 0]
  |  Branch (71:43): [True: 0, False: 572]
  ------------------
   72|      0|        ssh_set_log_callback(ssh_legacy_log_callback);
   73|      0|        ssh_set_log_userdata(session);
   74|      0|    }
   75|       |
   76|    572|    return 0;
   77|    572|}

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

ssh_config_parse_uri:
  237|  1.14k|{
  238|  1.14k|    const char *endp = NULL;
  239|  1.14k|    long port_n;
  240|  1.14k|    int rc;
  241|       |
  242|       |    /* Sanitize inputs */
  243|  1.14k|    if (username != NULL) {
  ------------------
  |  Branch (243:9): [True: 572, False: 572]
  ------------------
  244|    572|        *username = NULL;
  245|    572|    }
  246|  1.14k|    if (hostname != NULL) {
  ------------------
  |  Branch (246:9): [True: 1.14k, False: 0]
  ------------------
  247|  1.14k|        *hostname = NULL;
  248|  1.14k|    }
  249|  1.14k|    if (port != NULL) {
  ------------------
  |  Branch (249:9): [True: 0, False: 1.14k]
  ------------------
  250|      0|        *port = NULL;
  251|      0|    }
  252|       |
  253|       |    /* Username part (optional) */
  254|  1.14k|    endp = strrchr(tok, '@');
  255|  1.14k|    if (endp != NULL) {
  ------------------
  |  Branch (255:9): [True: 0, False: 1.14k]
  ------------------
  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|  1.14k|    if (*tok == '[') {
  ------------------
  |  Branch (279:9): [True: 0, False: 1.14k]
  ------------------
  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|  1.14k|    } else if (!ignore_port) {
  ------------------
  |  Branch (286:16): [True: 0, False: 1.14k]
  ------------------
  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|  1.14k|    } else {
  294|       |        /* If no port is requested, expand to the end of line
  295|       |         * (to accommodate the IPv6 addresses) */
  296|  1.14k|        endp = strchr(tok, '\0');
  297|  1.14k|    }
  298|  1.14k|    if (tok == endp) {
  ------------------
  |  Branch (298:9): [True: 0, False: 1.14k]
  ------------------
  299|       |        /* Zero-length hostnames are not valid */
  300|      0|        goto error;
  301|      0|    }
  302|  1.14k|    if (hostname != NULL) {
  ------------------
  |  Branch (302:9): [True: 1.14k, False: 0]
  ------------------
  303|  1.14k|        *hostname = strndup(tok, endp - tok);
  304|  1.14k|        if (*hostname == NULL) {
  ------------------
  |  Branch (304:13): [True: 0, False: 1.14k]
  ------------------
  305|      0|            goto error;
  306|      0|        }
  307|  1.14k|        if (strict) {
  ------------------
  |  Branch (307:13): [True: 572, False: 572]
  ------------------
  308|       |            /* if not an ip, check syntax */
  309|    572|            rc = ssh_is_ipaddr(*hostname);
  310|    572|            if (rc == 0) {
  ------------------
  |  Branch (310:17): [True: 0, False: 572]
  ------------------
  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|    572|        } 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|    572|            const char *c = NULL;
  321|    572|            if ((*hostname)[0] == '-') {
  ------------------
  |  Branch (321:17): [True: 0, False: 572]
  ------------------
  322|      0|                goto error;
  323|      0|            }
  324|  5.72k|            for (c = *hostname; *c != '\0'; c++) {
  ------------------
  |  Branch (324:33): [True: 5.14k, False: 572]
  ------------------
  325|  5.14k|                const char *is_meta = strchr(SSH_DANGEROUS_SHELL_CHARS, *c);
  ------------------
  |  |  260|  5.14k|#define SSH_DANGEROUS_SHELL_CHARS "'`\";&<>|(){}$\\,"
  ------------------
  326|  5.14k|                int is_space = isspace((unsigned char)*c);
  327|  5.14k|                int is_ctrl = iscntrl((unsigned char)*c);
  328|  5.14k|                if (is_meta != NULL || is_space || is_ctrl) {
  ------------------
  |  Branch (328:21): [True: 0, False: 5.14k]
  |  Branch (328:40): [True: 0, False: 5.14k]
  |  Branch (328:52): [True: 0, False: 5.14k]
  ------------------
  329|      0|                    goto error;
  330|      0|                }
  331|  5.14k|            }
  332|    572|        }
  333|  1.14k|    }
  334|       |    /* Skip also the closing bracket */
  335|  1.14k|    if (*endp == ']') {
  ------------------
  |  Branch (335:9): [True: 0, False: 1.14k]
  ------------------
  336|      0|        endp++;
  337|      0|    }
  338|       |
  339|       |    /* Port (optional) */
  340|  1.14k|    if (*endp != '\0') {
  ------------------
  |  Branch (340:9): [True: 0, False: 1.14k]
  ------------------
  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|  1.14k|    return SSH_OK;
  ------------------
  |  |  316|  1.14k|#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|  1.14k|}

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

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

ssh_client_dhgex_init:
   65|      8|{
   66|      8|    int rc;
   67|       |
   68|      8|    rc = ssh_dh_init_common(session->next_crypto);
   69|      8|    if (rc != SSH_OK){
  ------------------
  |  |  316|      8|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (69:9): [True: 0, False: 8]
  ------------------
   70|      0|        goto error;
   71|      0|    }
   72|       |
   73|      8|    session->next_crypto->dh_pmin = DH_PMIN;
  ------------------
  |  |   41|      8|#define DH_PMIN 2048
  ------------------
   74|      8|    session->next_crypto->dh_pn = DH_PREQ;
  ------------------
  |  |   42|      8|#define DH_PREQ 2048
  ------------------
   75|      8|    session->next_crypto->dh_pmax = DH_PMAX;
  ------------------
  |  |   43|      8|#define DH_PMAX 8192
  ------------------
   76|       |    /* Minimum group size, preferred group size, maximum group size */
   77|      8|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      8|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      8|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      8|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      8|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      8|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      8|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      8|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
   78|      8|                         "bddd",
   79|      8|                         SSH2_MSG_KEX_DH_GEX_REQUEST,
   80|      8|                         session->next_crypto->dh_pmin,
   81|      8|                         session->next_crypto->dh_pn,
   82|      8|                         session->next_crypto->dh_pmax);
   83|      8|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      8|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (83:9): [True: 0, False: 8]
  ------------------
   84|      0|        goto error;
   85|      0|    }
   86|       |
   87|       |    /* register the packet callbacks */
   88|      8|    ssh_packet_set_callbacks(session, &ssh_dhgex_client_callbacks);
   89|      8|    session->dh_handshake_state = DH_STATE_REQUEST_SENT;
   90|      8|    rc = ssh_packet_send(session);
   91|      8|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      8|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (91:9): [True: 0, False: 8]
  ------------------
   92|      0|        goto error;
   93|      0|    }
   94|      8|    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|      8|}
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: 1, False: 6]
  ------------------
  137|      1|        ssh_set_error(session, SSH_FATAL, "Invalid DH_GEX_GROUP packet");
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  138|      1|        goto error;
  139|      1|    }
  140|       |    /* basic checks */
  141|      6|    if (ssh_fips_mode() &&
  ------------------
  |  |  115|     12|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 6]
  |  |  ------------------
  ------------------
  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|      6|    rc = bignum_set_word(one, 1);
  ------------------
  |  |   77|      6|#define bignum_set_word(bn,n) BN_set_word(bn,n)
  ------------------
  149|      6|    if (rc != 1) {
  ------------------
  |  Branch (149:9): [True: 0, False: 6]
  ------------------
  150|      0|        goto error;
  151|      0|    }
  152|      6|    blen = bignum_num_bits(modulus);
  ------------------
  |  |   99|      6|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
  153|      6|    if (blen < DH_PMIN || blen > DH_PMAX) {
  ------------------
  |  |   41|     12|#define DH_PMIN 2048
  ------------------
                  if (blen < DH_PMIN || blen > DH_PMAX) {
  ------------------
  |  |   43|      5|#define DH_PMAX 8192
  ------------------
  |  Branch (153:9): [True: 1, False: 5]
  |  Branch (153:27): [True: 0, False: 5]
  ------------------
  154|      1|        ssh_set_error(session,
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  155|      1|                SSH_FATAL,
  156|      1|                "Invalid dh group parameter p: %d not in [%d:%d]",
  157|      1|                blen,
  158|      1|                DH_PMIN,
  159|      1|                DH_PMAX);
  160|      1|        goto error;
  161|      1|    }
  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: 3, False: 2]
  ------------------
  168|       |        /* p must be a prime and therefore not divisible by 2 */
  169|      3|        ssh_set_error(session, SSH_FATAL, "Invalid dh group parameter p");
  ------------------
  |  |  313|      3|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  170|      3|        goto error;
  171|      3|    }
  172|      2|    bignum_sub(pmin1, modulus, one);
  ------------------
  |  |   96|      2|#define bignum_sub(dest, a, b) BN_sub(dest, a, b)
  ------------------
  173|      2|    if (bignum_cmp(generator, one) <= 0 ||
  ------------------
  |  |  102|      2|#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
  ------------------
  |  Branch (173:9): [True: 1, False: 1]
  ------------------
  174|      1|        bignum_cmp(generator, pmin1) > 0) {
  ------------------
  |  |  102|      1|#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
  ------------------
  |  Branch (174:9): [True: 0, False: 1]
  ------------------
  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|      1|    rc = ssh_dh_set_parameters(session->next_crypto->dh_ctx,
  182|      1|                               modulus, generator);
  183|      1|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (183:9): [True: 0, False: 1]
  ------------------
  184|      0|        goto error;
  185|      0|    }
  186|      1|#ifdef HAVE_LIBCRYPTO
  187|      1|    bignum_safe_free(modulus);
  ------------------
  |  |   71|      1|#define bignum_safe_free(num) do { \
  |  |   72|      1|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 1, False: 0]
  |  |  ------------------
  |  |   73|      1|        BN_clear_free((num)); \
  |  |   74|      1|        (num)=NULL; \
  |  |   75|      1|    } \
  |  |   76|      1|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 1]
  |  |  ------------------
  ------------------
  188|      1|    bignum_safe_free(generator);
  ------------------
  |  |   71|      1|#define bignum_safe_free(num) do { \
  |  |   72|      1|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 1, False: 0]
  |  |  ------------------
  |  |   73|      1|        BN_clear_free((num)); \
  |  |   74|      1|        (num)=NULL; \
  |  |   75|      1|    } \
  |  |   76|      1|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 1]
  |  |  ------------------
  ------------------
  189|      1|#endif
  190|      1|    modulus = NULL;
  191|      1|    generator = NULL;
  192|       |
  193|       |    /* compute and send DH public parameter */
  194|      1|    rc = ssh_dh_keypair_gen_keys(session->next_crypto->dh_ctx,
  195|      1|                                 DH_CLIENT_KEYPAIR);
  ------------------
  |  |   30|      1|#define DH_CLIENT_KEYPAIR 0
  ------------------
  196|      1|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (196:9): [True: 0, False: 1]
  ------------------
  197|      0|        goto error;
  198|      0|    }
  199|       |
  200|      1|    rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
  201|      1|                                 DH_CLIENT_KEYPAIR, NULL, &pubkey);
  ------------------
  |  |   30|      1|#define DH_CLIENT_KEYPAIR 0
  ------------------
  202|      1|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (202:9): [True: 0, False: 1]
  ------------------
  203|      0|        goto error;
  204|      0|    }
  205|       |
  206|      1|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      1|    _ssh_buffer_pack((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_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      1|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  207|      1|                         "bB",
  208|      1|                         SSH2_MSG_KEX_DH_GEX_INIT,
  209|      1|                         pubkey);
  210|      1|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (210:9): [True: 0, False: 1]
  ------------------
  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|      1|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  218|       |
  219|      1|    rc = ssh_packet_send(session);
  220|      1|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (220:9): [True: 0, False: 1]
  ------------------
  221|      0|        goto error;
  222|      0|    }
  223|       |
  224|      1|    bignum_safe_free(one);
  ------------------
  |  |   71|      1|#define bignum_safe_free(num) do { \
  |  |   72|      1|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 1, False: 0]
  |  |  ------------------
  |  |   73|      1|        BN_clear_free((num)); \
  |  |   74|      1|        (num)=NULL; \
  |  |   75|      1|    } \
  |  |   76|      1|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 1]
  |  |  ------------------
  ------------------
  225|      1|    bignum_safe_free(pmin1);
  ------------------
  |  |   71|      1|#define bignum_safe_free(num) do { \
  |  |   72|      1|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 1, False: 0]
  |  |  ------------------
  |  |   73|      1|        BN_clear_free((num)); \
  |  |   74|      1|        (num)=NULL; \
  |  |   75|      1|    } \
  |  |   76|      1|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 1]
  |  |  ------------------
  ------------------
  226|      1|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      1|#define SSH_PACKET_USED 1
  ------------------
  227|       |
  228|      6|error:
  229|      6|    bignum_safe_free(modulus);
  ------------------
  |  |   71|      6|#define bignum_safe_free(num) do { \
  |  |   72|      6|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 5, False: 1]
  |  |  ------------------
  |  |   73|      5|        BN_clear_free((num)); \
  |  |   74|      5|        (num)=NULL; \
  |  |   75|      5|    } \
  |  |   76|      6|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 6]
  |  |  ------------------
  ------------------
  230|      6|    bignum_safe_free(generator);
  ------------------
  |  |   71|      6|#define bignum_safe_free(num) do { \
  |  |   72|      6|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 5, False: 1]
  |  |  ------------------
  |  |   73|      5|        BN_clear_free((num)); \
  |  |   74|      5|        (num)=NULL; \
  |  |   75|      5|    } \
  |  |   76|      6|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 6]
  |  |  ------------------
  ------------------
  231|      6|    bignum_safe_free(one);
  ------------------
  |  |   71|      6|#define bignum_safe_free(num) do { \
  |  |   72|      6|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 6, False: 0]
  |  |  ------------------
  |  |   73|      6|        BN_clear_free((num)); \
  |  |   74|      6|        (num)=NULL; \
  |  |   75|      6|    } \
  |  |   76|      6|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 6]
  |  |  ------------------
  ------------------
  232|      6|    bignum_safe_free(pmin1);
  ------------------
  |  |   71|      6|#define bignum_safe_free(num) do { \
  |  |   72|      6|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 6, False: 0]
  |  |  ------------------
  |  |   73|      6|        BN_clear_free((num)); \
  |  |   74|      6|        (num)=NULL; \
  |  |   75|      6|    } \
  |  |   76|      6|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 6]
  |  |  ------------------
  ------------------
  233|       |#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
  234|       |    bignum_safe_free(pubkey);
  235|       |#endif /* OPENSSL_VERSION_NUMBER */
  236|      6|    ssh_dh_cleanup(session->next_crypto);
  237|      6|    session->session_state = SSH_SESSION_STATE_ERROR;
  238|       |
  239|      6|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      6|#define SSH_PACKET_USED 1
  ------------------
  240|      1|}
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|    166|{
  296|    166|    return ssh_pki_import_pubkey_blob(pubkey_blob,
  297|    166|                                      &session->next_crypto->server_pubkey);
  298|       |
  299|    166|}
ssh_client_dh_init:
  317|     28|int ssh_client_dh_init(ssh_session session){
  318|     28|  struct ssh_crypto_struct *crypto = session->next_crypto;
  319|     28|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
  320|     28|  const_bignum pubkey;
  321|       |#else
  322|       |  bignum pubkey = NULL;
  323|       |#endif /* OPENSSL_VERSION_NUMBER */
  324|     28|  int rc;
  325|       |
  326|     28|  rc = ssh_dh_init_common(crypto);
  327|     28|  if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     28|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (327:7): [True: 0, False: 28]
  ------------------
  328|      0|    goto error;
  329|      0|  }
  330|       |
  331|     28|  rc = ssh_dh_keypair_gen_keys(crypto->dh_ctx, DH_CLIENT_KEYPAIR);
  ------------------
  |  |   30|     28|#define DH_CLIENT_KEYPAIR 0
  ------------------
  332|     28|  if (rc == SSH_ERROR){
  ------------------
  |  |  317|     28|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (332:7): [True: 0, False: 28]
  ------------------
  333|      0|      goto error;
  334|      0|  }
  335|     28|  rc = ssh_dh_keypair_get_keys(crypto->dh_ctx, DH_CLIENT_KEYPAIR,
  ------------------
  |  |   30|     28|#define DH_CLIENT_KEYPAIR 0
  ------------------
  336|     28|                               NULL, &pubkey);
  337|     28|  if (rc != SSH_OK) {
  ------------------
  |  |  316|     28|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (337:7): [True: 0, False: 28]
  ------------------
  338|      0|    goto error;
  339|      0|  }
  340|     28|  rc = ssh_buffer_pack(session->out_buffer, "bB", SSH2_MSG_KEXDH_INIT, pubkey);
  ------------------
  |  |   50|     28|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     28|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     28|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     28|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     28|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     28|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     28|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  341|     28|  if (rc != SSH_OK) {
  ------------------
  |  |  316|     28|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (341:7): [True: 0, False: 28]
  ------------------
  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|     28|  ssh_packet_set_callbacks(session, &ssh_dh_client_callbacks);
  350|     28|  session->dh_handshake_state = DH_STATE_INIT_SENT;
  351|       |
  352|     28|  rc = ssh_packet_send(session);
  353|     28|  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|     28|}
ssh_client_dh_remove_callbacks:
  363|     24|{
  364|     24|    ssh_packet_remove_callbacks(session, &ssh_dh_client_callbacks);
  365|     24|}
ssh_dh_get_next_server_publickey:
  676|     89|{
  677|     89|    return session->next_crypto->server_pubkey;
  678|     89|}
ssh_dh_get_next_server_publickey_blob:
  683|     54|{
  684|     54|    const ssh_key pubkey = ssh_dh_get_next_server_publickey(session);
  685|       |
  686|     54|    return ssh_pki_export_pubkey_blob(pubkey, pubkey_blob);
  687|     54|}
dh.c:ssh_packet_client_dh_reply:
  367|     24|SSH_PACKET_CALLBACK(ssh_packet_client_dh_reply){
  368|     24|  struct ssh_crypto_struct *crypto=session->next_crypto;
  369|     24|  ssh_string pubkey_blob = NULL;
  370|     24|  bignum server_pubkey;
  371|     24|  int rc;
  372|       |
  373|     24|  (void)type;
  374|     24|  (void)user;
  375|       |
  376|     24|  ssh_client_dh_remove_callbacks(session);
  377|       |
  378|     24|  rc = ssh_buffer_unpack(packet, "SBS", &pubkey_blob, &server_pubkey,
  ------------------
  |  |   60|     24|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     24|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     24|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     24|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     24|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     24|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     24|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  379|     24|          &crypto->dh_server_signature);
  380|     24|  if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     24|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (380:7): [True: 4, False: 20]
  ------------------
  381|      4|      goto error;
  382|      4|  }
  383|     20|  rc = ssh_dh_keypair_set_keys(crypto->dh_ctx, DH_SERVER_KEYPAIR,
  ------------------
  |  |   31|     20|#define DH_SERVER_KEYPAIR 1
  ------------------
  384|     20|                               NULL, server_pubkey);
  385|     20|  if (rc != SSH_OK) {
  ------------------
  |  |  316|     20|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (385:7): [True: 0, False: 20]
  ------------------
  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|     20|  rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  391|     20|  SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  924|     20|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 20, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 20]
  |  |  ------------------
  ------------------
  392|     20|  if (rc != 0) {
  ------------------
  |  Branch (392:7): [True: 2, False: 18]
  ------------------
  393|      2|      goto error;
  394|      2|  }
  395|       |
  396|     18|  rc = ssh_dh_compute_shared_secret(session->next_crypto->dh_ctx,
  397|     18|                                    DH_CLIENT_KEYPAIR, DH_SERVER_KEYPAIR,
  ------------------
  |  |   30|     18|#define DH_CLIENT_KEYPAIR 0
  ------------------
                                                  DH_CLIENT_KEYPAIR, DH_SERVER_KEYPAIR,
  ------------------
  |  |   31|     18|#define DH_SERVER_KEYPAIR 1
  ------------------
  398|     18|                                    &session->next_crypto->shared_secret);
  399|     18|  ssh_dh_debug_crypto(session->next_crypto);
  400|     18|  if (rc == SSH_ERROR){
  ------------------
  |  |  317|     18|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (400:7): [True: 1, False: 17]
  ------------------
  401|      1|    ssh_set_error(session, SSH_FATAL, "Could not generate shared secret");
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  402|      1|    goto error;
  403|      1|  }
  404|       |
  405|       |  /* Send the MSG_NEWKEYS */
  406|     17|  rc = ssh_packet_send_newkeys(session);
  407|     17|  if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     17|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (407:7): [True: 0, False: 17]
  ------------------
  408|      0|    goto error;
  409|      0|  }
  410|     17|  session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  411|     17|  return SSH_PACKET_USED;
  ------------------
  |  |  638|     17|#define SSH_PACKET_USED 1
  ------------------
  412|      7|error:
  413|      7|  ssh_dh_cleanup(session->next_crypto);
  414|      7|  session->session_state=SSH_SESSION_STATE_ERROR;
  415|      7|  return SSH_PACKET_USED;
  ------------------
  |  |  638|      7|#define SSH_PACKET_USED 1
  ------------------
  416|     17|}

ssh_dh_debug_crypto:
   56|     18|{
   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|     18|    (void)c; /* UNUSED_PARAM */
   83|     18|#endif /* DEBUG_CRYPTO */
   84|     18|}
ssh_dh_keypair_get_keys:
   89|     81|{
   90|     81|    if (((peer != DH_CLIENT_KEYPAIR) && (peer != DH_SERVER_KEYPAIR)) ||
  ------------------
  |  |   30|     81|#define DH_CLIENT_KEYPAIR 0
  ------------------
                  if (((peer != DH_CLIENT_KEYPAIR) && (peer != DH_SERVER_KEYPAIR)) ||
  ------------------
  |  |   31|     35|#define DH_SERVER_KEYPAIR 1
  ------------------
  |  Branch (90:10): [True: 35, False: 46]
  |  Branch (90:41): [True: 0, False: 35]
  ------------------
   91|     81|        ((priv == NULL) && (pub == NULL)) || (ctx == NULL) ||
  ------------------
  |  Branch (91:10): [True: 81, False: 0]
  |  Branch (91:28): [True: 0, False: 81]
  |  Branch (91:46): [True: 0, False: 81]
  ------------------
   92|     81|        (ctx->keypair[peer] == NULL)) {
  ------------------
  |  Branch (92:9): [True: 0, False: 81]
  ------------------
   93|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
   94|      0|    }
   95|       |
   96|     81|    DH_get0_key(ctx->keypair[peer], pub, priv);
   97|       |
   98|     81|    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: 81]
  |  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|     81|    if (pub && (*pub == NULL || bignum_num_bits(*pub) == 0)) {
  ------------------
  |  |   99|     81|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
  |  Branch (101:9): [True: 81, False: 0]
  |  Branch (101:17): [True: 0, False: 81]
  |  Branch (101:33): [True: 0, False: 81]
  ------------------
  102|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  103|      0|    }
  104|       |
  105|     81|    return SSH_OK;
  ------------------
  |  |  316|     81|#define SSH_OK 0     /* No error */
  ------------------
  106|     81|}
ssh_dh_keypair_set_keys:
  158|     20|{
  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|     20|    if (((peer != DH_CLIENT_KEYPAIR) && (peer != DH_SERVER_KEYPAIR)) ||
  ------------------
  |  |   30|     20|#define DH_CLIENT_KEYPAIR 0
  ------------------
                  if (((peer != DH_CLIENT_KEYPAIR) && (peer != DH_SERVER_KEYPAIR)) ||
  ------------------
  |  |   31|     20|#define DH_SERVER_KEYPAIR 1
  ------------------
  |  Branch (166:10): [True: 20, False: 0]
  |  Branch (166:41): [True: 0, False: 20]
  ------------------
  167|     20|        ((priv == NULL) && (pub == NULL)) || (ctx == NULL) ||
  ------------------
  |  Branch (167:10): [True: 20, False: 0]
  |  Branch (167:28): [True: 0, False: 20]
  |  Branch (167:46): [True: 0, False: 20]
  ------------------
  168|     20|        (ctx->keypair[peer] == NULL)) {
  ------------------
  |  Branch (168:9): [True: 0, False: 20]
  ------------------
  169|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  170|      0|    }
  171|       |
  172|     20|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  173|     20|    (void)DH_set0_key(ctx->keypair[peer], pub, priv);
  174|       |
  175|     20|    return SSH_OK;
  ------------------
  |  |  316|     20|#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|     20|}
ssh_dh_set_parameters:
  286|     29|{
  287|     29|    size_t i;
  288|     29|    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|     29|    if ((ctx == NULL) || (modulus == NULL) || (generator == NULL)) {
  ------------------
  |  Branch (295:9): [True: 0, False: 29]
  |  Branch (295:26): [True: 0, False: 29]
  |  Branch (295:47): [True: 0, False: 29]
  ------------------
  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|     87|    for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (303:17): [True: 58, False: 29]
  ------------------
  304|     58|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  305|     58|        bignum p = NULL;
  306|     58|        bignum g = NULL;
  307|       |
  308|       |        /* when setting modulus or generator,
  309|       |         * make sure to invalidate existing keys */
  310|     58|        DH_free(ctx->keypair[i]);
  311|     58|        ctx->keypair[i] = DH_new();
  312|     58|        if (ctx->keypair[i] == NULL) {
  ------------------
  |  Branch (312:13): [True: 0, False: 58]
  ------------------
  313|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  314|      0|            goto done;
  315|      0|        }
  316|       |
  317|     58|        p = BN_dup(modulus);
  318|     58|        g = BN_dup(generator);
  319|     58|        rc = DH_set0_pqg(ctx->keypair[i], p, NULL, g);
  320|     58|        if (rc != 1) {
  ------------------
  |  Branch (320:13): [True: 0, False: 58]
  ------------------
  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|     58|    }
  376|       |
  377|     29|    rc = SSH_OK;
  ------------------
  |  |  316|     29|#define SSH_OK 0     /* No error */
  ------------------
  378|     29|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  379|     29|done:
  380|     29|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     29|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (380:9): [True: 0, False: 29]
  ------------------
  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|     29|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     29|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (393:9): [True: 0, False: 29]
  ------------------
  394|      0|        ctx->keypair[0] = NULL;
  395|      0|        ctx->keypair[1] = NULL;
  396|      0|    }
  397|       |
  398|     29|    return rc;
  399|     29|}
ssh_dh_init_common:
  406|     36|{
  407|     36|    struct dh_ctx *ctx = NULL;
  408|     36|    int rc;
  409|       |
  410|       |    /* Cleanup any previously allocated dh_ctx */
  411|     36|    if (crypto->dh_ctx != NULL) {
  ------------------
  |  Branch (411:9): [True: 0, False: 36]
  ------------------
  412|      0|        ssh_dh_cleanup(crypto);
  413|      0|    }
  414|       |
  415|     36|    ctx = calloc(1, sizeof(*ctx));
  416|     36|    if (ctx == NULL) {
  ------------------
  |  Branch (416:9): [True: 0, False: 36]
  ------------------
  417|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  418|      0|    }
  419|     36|    crypto->dh_ctx = ctx;
  420|       |
  421|     36|    switch (crypto->kex_type) {
  422|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (422:5): [True: 0, False: 36]
  ------------------
  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: 36]
  ------------------
  426|      5|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (426:5): [True: 5, False: 31]
  ------------------
  427|      5|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (427:5): [True: 0, False: 36]
  ------------------
  428|      5|        rc = ssh_dh_set_parameters(ctx, ssh_dh_group14, ssh_dh_generator);
  429|      5|        break;
  430|      6|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (430:5): [True: 6, False: 30]
  ------------------
  431|      6|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (431:5): [True: 0, False: 36]
  ------------------
  432|      6|        rc = ssh_dh_set_parameters(ctx, ssh_dh_group16, ssh_dh_generator);
  433|      6|        break;
  434|     17|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (434:5): [True: 17, False: 19]
  ------------------
  435|     17|        rc = ssh_dh_set_parameters(ctx, ssh_dh_group18, ssh_dh_generator);
  436|     17|        break;
  437|      8|    default:
  ------------------
  |  Branch (437:5): [True: 8, False: 28]
  ------------------
  438|      8|        rc = SSH_OK;
  ------------------
  |  |  316|      8|#define SSH_OK 0     /* No error */
  ------------------
  439|      8|        break;
  440|     36|    }
  441|       |
  442|     36|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     36|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (442:9): [True: 0, False: 36]
  ------------------
  443|      0|        ssh_dh_cleanup(crypto);
  444|      0|    }
  445|     36|    return rc;
  446|     36|}
ssh_dh_cleanup:
  449|  1.28k|{
  450|  1.28k|    if (crypto->dh_ctx != NULL) {
  ------------------
  |  Branch (450:9): [True: 36, False: 1.24k]
  ------------------
  451|     36|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  452|     36|        DH_free(crypto->dh_ctx->keypair[0]);
  453|     36|        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|     36|        free(crypto->dh_ctx);
  459|       |        crypto->dh_ctx = NULL;
  460|     36|    }
  461|  1.28k|}
ssh_dh_keypair_gen_keys:
  474|     29|{
  475|     29|    int rc;
  476|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  477|       |    EVP_PKEY_CTX *evp_ctx = NULL;
  478|       |#endif
  479|       |
  480|     29|    if ((dh_ctx == NULL) || (dh_ctx->keypair[peer] == NULL)) {
  ------------------
  |  Branch (480:9): [True: 0, False: 29]
  |  Branch (480:29): [True: 0, False: 29]
  ------------------
  481|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  482|      0|    }
  483|       |
  484|     29|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  485|     29|    rc = DH_generate_key(dh_ctx->keypair[peer]);
  486|     29|    if (rc != 1) {
  ------------------
  |  Branch (486:9): [True: 0, False: 29]
  ------------------
  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|     29|    return SSH_OK;
  ------------------
  |  |  316|     29|#define SSH_OK 0     /* No error */
  ------------------
  514|     29|}
ssh_dh_compute_shared_secret:
  529|     18|{
  530|     18|    unsigned char *kstring = NULL;
  531|     18|    int rc;
  532|     18|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  533|     18|    const_bignum pub_key = NULL;
  534|     18|    int klen;
  535|       |#else
  536|       |    size_t klen;
  537|       |    EVP_PKEY_CTX *evp_ctx = NULL;
  538|       |#endif /* OPENSSL_VERSION_NUMBER */
  539|       |
  540|     18|    if ((dh_ctx == NULL) ||
  ------------------
  |  Branch (540:9): [True: 0, False: 18]
  ------------------
  541|     18|        (dh_ctx->keypair[local] == NULL) ||
  ------------------
  |  Branch (541:9): [True: 0, False: 18]
  ------------------
  542|     18|        (dh_ctx->keypair[remote] == NULL)) {
  ------------------
  |  Branch (542:9): [True: 0, False: 18]
  ------------------
  543|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  544|      0|    }
  545|       |
  546|     18|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  547|     18|    kstring = malloc(DH_size(dh_ctx->keypair[local]));
  548|     18|    if (kstring == NULL) {
  ------------------
  |  Branch (548:9): [True: 0, False: 18]
  ------------------
  549|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  550|      0|        goto done;
  551|      0|    }
  552|       |
  553|     18|    rc = ssh_dh_keypair_get_keys(dh_ctx, remote, NULL, &pub_key);
  554|     18|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     18|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (554:9): [True: 0, False: 18]
  ------------------
  555|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  556|      0|        goto done;
  557|      0|    }
  558|       |
  559|     18|    klen = DH_compute_key(kstring, pub_key, dh_ctx->keypair[local]);
  560|     18|    if (klen == -1) {
  ------------------
  |  Branch (560:9): [True: 1, False: 17]
  ------------------
  561|      1|        rc = SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  562|      1|        goto done;
  563|      1|    }
  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|     17|    *dest = BN_bin2bn(kstring, (int)klen, NULL);
  603|     17|    if (*dest == NULL) {
  ------------------
  |  Branch (603:9): [True: 0, False: 17]
  ------------------
  604|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  605|      0|        goto done;
  606|      0|    }
  607|       |
  608|     17|    rc = SSH_OK;
  ------------------
  |  |  316|     17|#define SSH_OK 0     /* No error */
  ------------------
  609|     18|done:
  610|       |#if OPENSSL_VERSION_NUMBER >= 0x30000000L
  611|       |    EVP_PKEY_CTX_free(evp_ctx);
  612|       |#endif
  613|     18|    free(kstring);
  614|     18|    return rc;
  615|     17|}

ssh_client_ecdh_remove_callbacks:
   47|      8|{
   48|      8|    ssh_packet_remove_callbacks(session, &ssh_ecdh_client_callbacks);
   49|      8|}
ecdh.c:ssh_packet_client_ecdh_reply:
   55|      8|SSH_PACKET_CALLBACK(ssh_packet_client_ecdh_reply){
   56|      8|  ssh_string q_s_string = NULL;
   57|      8|  ssh_string pubkey_blob = NULL;
   58|      8|  ssh_string signature = NULL;
   59|      8|  int rc;
   60|      8|  (void)type;
   61|      8|  (void)user;
   62|       |
   63|      8|  ssh_client_ecdh_remove_callbacks(session);
   64|      8|  pubkey_blob = ssh_buffer_get_ssh_string(packet);
   65|      8|  if (pubkey_blob == NULL) {
  ------------------
  |  Branch (65:7): [True: 0, False: 8]
  ------------------
   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|      8|  rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
   71|      8|  SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  924|      8|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 8, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 8]
  |  |  ------------------
  ------------------
   72|      8|  if (rc != 0) {
  ------------------
  |  Branch (72:7): [True: 5, False: 3]
  ------------------
   73|      5|      goto error;
   74|      5|  }
   75|       |
   76|      3|  q_s_string = ssh_buffer_get_ssh_string(packet);
   77|      3|  if (q_s_string == NULL) {
  ------------------
  |  Branch (77:7): [True: 2, False: 1]
  ------------------
   78|      2|    ssh_set_error(session,SSH_FATAL, "No Q_S ECC point in packet");
  ------------------
  |  |  313|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   79|      2|    goto error;
   80|      2|  }
   81|      1|  session->next_crypto->ecdh_server_pubkey = q_s_string;
   82|      1|  signature = ssh_buffer_get_ssh_string(packet);
   83|      1|  if (signature == NULL) {
  ------------------
  |  Branch (83:7): [True: 0, False: 1]
  ------------------
   84|      0|    ssh_set_error(session, SSH_FATAL, "No signature in packet");
  ------------------
  |  |  313|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
   85|      0|    goto error;
   86|      0|  }
   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|      8|error:
  105|      8|  session->session_state=SSH_SESSION_STATE_ERROR;
  106|      8|  return SSH_PACKET_USED;
  ------------------
  |  |  638|      8|#define SSH_PACKET_USED 1
  ------------------
  107|      0|}

ssh_ecdh_init:
  235|    128|{
  236|    128|    ssh_string pubkey = NULL;
  237|    128|    ssh_string *pubkey_loc = NULL;
  238|       |
  239|    128|    pubkey = ssh_ecdh_generate(session);
  240|    128|    if (pubkey == NULL) {
  ------------------
  |  Branch (240:9): [True: 0, False: 128]
  ------------------
  241|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  242|      0|    }
  243|       |
  244|    128|    if (session->server) {
  ------------------
  |  Branch (244:9): [True: 0, False: 128]
  ------------------
  245|      0|        pubkey_loc = &session->next_crypto->ecdh_server_pubkey;
  246|    128|    } else {
  247|    128|        pubkey_loc = &session->next_crypto->ecdh_client_pubkey;
  248|    128|    }
  249|       |
  250|    128|    ssh_string_free(*pubkey_loc);
  251|    128|    *pubkey_loc = pubkey;
  252|       |
  253|    128|    return SSH_OK;
  ------------------
  |  |  316|    128|#define SSH_OK 0     /* No error */
  ------------------
  254|    128|}
ssh_client_ecdh_init:
  260|     14|{
  261|     14|    int rc;
  262|       |
  263|     14|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_KEX_ECDH_INIT);
  ------------------
  |  |   17|     14|#define SSH2_MSG_KEX_ECDH_INIT 30
  ------------------
  264|     14|    if (rc < 0) {
  ------------------
  |  Branch (264:9): [True: 0, False: 14]
  ------------------
  265|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  266|      0|    }
  267|       |
  268|     14|    rc = ssh_ecdh_init(session);
  269|     14|    if (rc < 0) {
  ------------------
  |  Branch (269:9): [True: 0, False: 14]
  ------------------
  270|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  271|      0|    }
  272|       |
  273|     14|    rc = ssh_buffer_add_ssh_string(session->out_buffer,
  274|     14|                                   session->next_crypto->ecdh_client_pubkey);
  275|     14|    if (rc < 0) {
  ------------------
  |  Branch (275:9): [True: 0, False: 14]
  ------------------
  276|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  277|      0|    }
  278|       |
  279|       |    /* register the packet callbacks */
  280|     14|    ssh_packet_set_callbacks(session, &ssh_ecdh_client_callbacks);
  281|     14|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  282|       |
  283|     14|    rc = ssh_packet_send(session);
  284|       |
  285|     14|    return rc;
  286|     14|}
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|    128|{
   81|    128|    ssh_string pubkey_string = NULL;
   82|    128|#if OPENSSL_VERSION_NUMBER < 0x30000000L
   83|    128|    const EC_POINT *point = NULL;
   84|    128|    const EC_GROUP *group = NULL;
   85|    128|    EC_KEY *key = NULL;
   86|    128|    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|    128|    int rc;
   99|       |
  100|    128|    curve = ecdh_kex_type_to_curve(session->next_crypto->kex_type);
  101|    128|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  102|    128|    if (curve == SSH_ERROR) {
  ------------------
  |  |  317|    128|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (102:9): [True: 0, False: 128]
  ------------------
  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|    128|    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|    128|    if (key == NULL) {
  ------------------
  |  Branch (116:9): [True: 0, False: 128]
  ------------------
  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|    128|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  122|    128|    group = EC_KEY_get0_group(key);
  123|    128|    if (group == NULL) {
  ------------------
  |  Branch (123:9): [True: 0, False: 128]
  ------------------
  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|    128|    rc = EC_KEY_generate_key(key);
  130|    128|    if (rc != 1) {
  ------------------
  |  Branch (130:9): [True: 0, False: 128]
  ------------------
  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|    128|    point = EC_KEY_get0_public_key(key);
  137|    128|    if (point == NULL) {
  ------------------
  |  Branch (137:9): [True: 0, False: 128]
  ------------------
  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|    128|    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|    128|    if (pubkey_string == NULL) {
  ------------------
  |  Branch (207:9): [True: 0, False: 128]
  ------------------
  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|    128|    if (session->next_crypto->ecdh_privkey != NULL) {
  ------------------
  |  Branch (218:9): [True: 0, False: 128]
  ------------------
  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|    128|    session->next_crypto->ecdh_privkey = key;
  228|    128|    return pubkey_string;
  229|    128|}
ecdh_crypto.c:ecdh_kex_type_to_curve:
   50|    128|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|    128|    switch (kex_type) {
   55|      7|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (55:5): [True: 7, False: 121]
  ------------------
   56|    121|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (56:5): [True: 114, False: 14]
  ------------------
   57|    121|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (57:5): [True: 0, False: 128]
  ------------------
   58|    121|        return NISTP256;
  ------------------
  |  |   34|    121|#define NISTP256 NID_X9_62_prime256v1
  ------------------
   59|      1|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (59:5): [True: 1, False: 127]
  ------------------
   60|       |#if HAVE_MLKEM1024
   61|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
   62|       |#endif
   63|      1|        return NISTP384;
  ------------------
  |  |   35|      1|#define NISTP384 NID_secp384r1
  ------------------
   64|      6|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (64:5): [True: 6, False: 122]
  ------------------
   65|      6|        return NISTP521;
  ------------------
  |  |   36|      6|#define NISTP521 NID_secp521r1
  ------------------
   66|      0|    default:
  ------------------
  |  Branch (66:5): [True: 0, False: 128]
  ------------------
   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|    128|    }
   73|    128|}

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

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

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

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

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

ssh_client_hybrid_mlkem_init:
  201|    115|{
  202|    115|    struct ssh_crypto_struct *crypto = session->next_crypto;
  203|    115|    ssh_buffer client_init_buffer = NULL;
  204|    115|    int rc, ret = SSH_ERROR;
  ------------------
  |  |  317|    115|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  205|       |
  206|    115|    SSH_LOG(SSH_LOG_TRACE, "Initializing hybrid ML-KEM key exchange");
  ------------------
  |  |  283|    115|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  207|       |
  208|       |    /* Prepare a buffer to concatenate ML-KEM + ECDH public keys */
  209|    115|    client_init_buffer = ssh_buffer_new();
  210|    115|    if (client_init_buffer == NULL) {
  ------------------
  |  Branch (210:9): [True: 0, False: 115]
  ------------------
  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|    115|    rc = ssh_mlkem_init(session);
  217|    115|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    115|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (217:9): [True: 0, False: 115]
  ------------------
  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|    115|    switch (crypto->kex_type) {
  230|      1|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (230:5): [True: 1, False: 114]
  ------------------
  231|      1|        rc = ssh_curve25519_init(session);
  232|      1|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (232:13): [True: 0, False: 1]
  ------------------
  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|      1|        rc = ssh_buffer_pack(client_init_buffer,
  ------------------
  |  |   50|      1|    _ssh_buffer_pack((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_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      1|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  244|      1|                             "PP",
  245|      1|                             ssh_string_len(crypto->mlkem_client_pubkey),
  246|      1|                             ssh_string_data(crypto->mlkem_client_pubkey),
  247|      1|                             (size_t)CURVE25519_PUBKEY_SIZE,
  248|      1|                             crypto->curve25519_client_pubkey);
  249|      1|        break;
  250|    114|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (250:5): [True: 114, False: 1]
  ------------------
  251|       |#ifdef HAVE_MLKEM1024
  252|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  253|       |#endif
  254|    114|        rc = ssh_ecdh_init(session);
  255|    114|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    114|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (255:13): [True: 0, False: 114]
  ------------------
  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|    114|        rc = ssh_buffer_pack(client_init_buffer,
  ------------------
  |  |   50|    114|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    114|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    114|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    114|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    114|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    114|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    114|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  267|    114|                             "PP",
  268|    114|                             ssh_string_len(crypto->mlkem_client_pubkey),
  269|    114|                             ssh_string_data(crypto->mlkem_client_pubkey),
  270|    114|                             ssh_string_len(crypto->ecdh_client_pubkey),
  271|    114|                             ssh_string_data(crypto->ecdh_client_pubkey));
  272|       |
  273|    114|        break;
  274|      0|    default:
  ------------------
  |  Branch (274:5): [True: 0, False: 115]
  ------------------
  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|    115|    }
  278|    115|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    115|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (278:9): [True: 0, False: 115]
  ------------------
  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|    115|    ssh_string_free(crypto->hybrid_client_init);
  285|    115|    crypto->hybrid_client_init = ssh_string_new(ssh_buffer_get_len(client_init_buffer));
  286|    115|    if (crypto->hybrid_client_init == NULL) {
  ------------------
  |  Branch (286:9): [True: 0, False: 115]
  ------------------
  287|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  288|      0|        goto cleanup;
  289|      0|    }
  290|       |
  291|    115|    rc = ssh_string_fill(crypto->hybrid_client_init,
  292|    115|                         ssh_buffer_get(client_init_buffer),
  293|    115|                         ssh_buffer_get_len(client_init_buffer));
  294|    115|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    115|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (294:9): [True: 0, False: 115]
  ------------------
  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|    115|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    115|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    115|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    115|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    115|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    115|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    115|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    115|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  300|    115|                         "bS",
  301|    115|                         SSH2_MSG_KEX_HYBRID_INIT,
  302|    115|                         crypto->hybrid_client_init);
  303|    115|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    115|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (303:9): [True: 0, False: 115]
  ------------------
  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|    115|    ssh_packet_set_callbacks(session, &ssh_hybrid_mlkem_client_callbacks);
  309|    115|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  310|       |
  311|    115|    rc = ssh_packet_send(session);
  312|    115|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    115|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (312:9): [True: 0, False: 115]
  ------------------
  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|    115|    ret = SSH_OK;
  ------------------
  |  |  316|    115|#define SSH_OK 0     /* No error */
  ------------------
  318|       |
  319|    115|cleanup:
  320|    115|    ssh_buffer_free(client_init_buffer);
  321|    115|    return ret;
  322|    115|}
ssh_client_hybrid_mlkem_remove_callbacks:
  531|     48|{
  532|     48|    ssh_packet_remove_callbacks(session, &ssh_hybrid_mlkem_client_callbacks);
  533|     48|}
hybrid_mlkem.c:ssh_packet_client_hybrid_mlkem_reply:
  325|     48|{
  326|     48|    struct ssh_crypto_struct *crypto = session->next_crypto;
  327|     48|    const struct mlkem_type_info *mlkem_info = NULL;
  328|     48|    ssh_string pubkey_blob = NULL;
  329|     48|    ssh_string signature = NULL;
  330|     48|    ssh_mlkem_shared_secret mlkem_shared_secret;
  331|     48|    ssh_string ecdh_shared_secret = NULL;
  332|     48|    ssh_buffer server_reply_buffer = NULL;
  333|     48|    size_t read_len;
  334|     48|    size_t ecdh_server_pubkey_size;
  335|     48|    int rc;
  336|     48|    (void)type;
  337|     48|    (void)user;
  338|       |
  339|     48|    SSH_LOG(SSH_LOG_TRACE, "Received ML-KEM hybrid server reply");
  ------------------
  |  |  283|     48|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  340|       |
  341|     48|    ssh_client_hybrid_mlkem_remove_callbacks(session);
  342|       |
  343|     48|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
  344|     48|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (344:9): [True: 0, False: 48]
  ------------------
  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|     48|    pubkey_blob = ssh_buffer_get_ssh_string(packet);
  351|     48|    if (pubkey_blob == NULL) {
  ------------------
  |  Branch (351:9): [True: 1, False: 47]
  ------------------
  352|      1|        ssh_set_error(session, SSH_FATAL, "No public key in packet");
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  353|      1|        session->session_state = SSH_SESSION_STATE_ERROR;
  354|      1|        goto cleanup;
  355|      1|    }
  356|       |
  357|     47|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  358|     47|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     47|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (358:9): [True: 45, False: 2]
  ------------------
  359|     45|        ssh_set_error(session, SSH_FATAL, "Failed to import public key");
  ------------------
  |  |  313|     45|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  360|     45|        session->session_state = SSH_SESSION_STATE_ERROR;
  361|     45|        goto cleanup;
  362|     45|    }
  363|       |
  364|       |    /* Get server reply containing ML-KEM ciphertext + ECDH public key */
  365|      2|    ssh_string_free(crypto->hybrid_server_reply);
  366|      2|    crypto->hybrid_server_reply = ssh_buffer_get_ssh_string(packet);
  367|      2|    if (crypto->hybrid_server_reply == NULL) {
  ------------------
  |  Branch (367:9): [True: 1, False: 1]
  ------------------
  368|      1|        ssh_set_error(session, SSH_FATAL, "No server reply in packet");
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  369|      1|        session->session_state = SSH_SESSION_STATE_ERROR;
  370|      1|        goto cleanup;
  371|      1|    }
  372|       |
  373|      1|    server_reply_buffer = ssh_buffer_new();
  374|      1|    if (server_reply_buffer == NULL) {
  ------------------
  |  Branch (374:9): [True: 0, False: 1]
  ------------------
  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|      1|    rc = ssh_buffer_add_data(server_reply_buffer,
  381|      1|                             ssh_string_data(crypto->hybrid_server_reply),
  382|      1|                             ssh_string_len(crypto->hybrid_server_reply));
  383|      1|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (383:9): [True: 0, False: 1]
  ------------------
  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|      1|    ssh_string_free(crypto->mlkem_ciphertext);
  391|      1|    crypto->mlkem_ciphertext = ssh_string_new(mlkem_info->ciphertext_size);
  392|      1|    if (crypto->mlkem_ciphertext == NULL) {
  ------------------
  |  Branch (392:9): [True: 0, False: 1]
  ------------------
  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|      1|    read_len = ssh_buffer_get_data(server_reply_buffer,
  399|      1|                                   ssh_string_data(crypto->mlkem_ciphertext),
  400|      1|                                   mlkem_info->ciphertext_size);
  401|      1|    if (read_len != mlkem_info->ciphertext_size) {
  ------------------
  |  Branch (401:9): [True: 1, False: 0]
  ------------------
  402|      1|        ssh_set_error(session,
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  403|      1|                      SSH_FATAL,
  404|      1|                      "Could not read ML-KEM ciphertext from "
  405|      1|                      "the server reply buffer, buffer too short");
  406|      1|        session->session_state = SSH_SESSION_STATE_ERROR;
  407|      1|        goto cleanup;
  408|      1|    }
  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|     48|cleanup:
  522|     48|    ssh_burn(mlkem_shared_secret, sizeof(mlkem_shared_secret));
  ------------------
  |  |  390|     48|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  523|     48|    ssh_string_burn(ecdh_shared_secret);
  524|     48|    ssh_string_free(ecdh_shared_secret);
  525|     48|    ssh_string_free(pubkey_blob);
  526|     48|    ssh_buffer_free(server_reply_buffer);
  527|     48|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     48|#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|    572|bool is_ssh_initialized(void) {
  285|       |
  286|    572|    bool is_initialized = false;
  287|       |
  288|    572|    ssh_mutex_lock(&ssh_init_mutex);
  289|    572|    is_initialized = _ssh_initialized > 0;
  290|    572|    ssh_mutex_unlock(&ssh_init_mutex);
  291|       |
  292|    572|    return is_initialized;
  293|    572|}
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|    324|{
  159|       |    /* Can't use VLAs with Visual Studio, so allocate the biggest
  160|       |     * digest buffer we can possibly need */
  161|    324|    unsigned char digest[DIGEST_MAX_LEN];
  162|    324|    size_t output_len = crypto->digest_len;
  163|    324|    ssh_mac_ctx ctx;
  164|    324|    int rc;
  165|       |
  166|    324|    if (DIGEST_MAX_LEN < crypto->digest_len) {
  ------------------
  |  |   56|    324|#define DIGEST_MAX_LEN 64
  ------------------
  |  Branch (166:9): [True: 0, False: 324]
  ------------------
  167|      0|        return -1;
  168|      0|    }
  169|       |
  170|    324|    ctx = ssh_mac_ctx_init(crypto->digest_type);
  171|    324|    if (ctx == NULL) {
  ------------------
  |  Branch (171:9): [True: 0, False: 324]
  ------------------
  172|      0|        return -1;
  173|      0|    }
  174|       |
  175|    324|    rc = ssh_mac_update(ctx, key, key_len);
  176|    324|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    324|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (176:9): [True: 0, False: 324]
  ------------------
  177|      0|        ssh_mac_ctx_free(ctx);
  178|      0|        return -1;
  179|      0|    }
  180|    324|    rc = ssh_mac_update(ctx, crypto->secret_hash, crypto->digest_len);
  181|    324|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    324|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (181:9): [True: 0, False: 324]
  ------------------
  182|      0|        ssh_mac_ctx_free(ctx);
  183|      0|        return -1;
  184|      0|    }
  185|    324|    rc = ssh_mac_update(ctx, &key_type, 1);
  186|    324|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    324|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (186:9): [True: 0, False: 324]
  ------------------
  187|      0|        ssh_mac_ctx_free(ctx);
  188|      0|        return -1;
  189|      0|    }
  190|    324|    rc = ssh_mac_update(ctx, crypto->session_id, crypto->session_id_len);
  191|    324|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    324|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (191:9): [True: 0, False: 324]
  ------------------
  192|      0|        ssh_mac_ctx_free(ctx);
  193|      0|        return -1;
  194|      0|    }
  195|    324|    rc = ssh_mac_final(digest, ctx);
  196|    324|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    324|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (196:9): [True: 0, False: 324]
  ------------------
  197|      0|        return -1;
  198|      0|    }
  199|       |
  200|    324|    if (requested_len < output_len) {
  ------------------
  |  Branch (200:9): [True: 216, False: 108]
  ------------------
  201|    216|        output_len = requested_len;
  202|    216|    }
  203|    324|    memcpy(output, digest, output_len);
  204|       |
  205|    324|    while (requested_len > output_len) {
  ------------------
  |  Branch (205:12): [True: 0, False: 324]
  ------------------
  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|    324|    return 0;
  238|    324|}
kdf.c:ssh_mac_ctx_init:
   54|    324|{
   55|    324|    ssh_mac_ctx ctx = malloc(sizeof(struct ssh_mac_ctx_struct));
   56|    324|    if (ctx == NULL) {
  ------------------
  |  Branch (56:9): [True: 0, False: 324]
  ------------------
   57|      0|        return NULL;
   58|      0|    }
   59|       |
   60|    324|    ctx->digest_type = type;
   61|    324|    switch (type) {
  ------------------
  |  Branch (61:13): [True: 324, False: 0]
  ------------------
   62|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (62:5): [True: 0, False: 324]
  ------------------
   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|    222|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (68:5): [True: 222, False: 102]
  ------------------
   69|    222|        ctx->ctx.sha256_ctx = sha256_init();
   70|    222|        if (ctx->ctx.sha256_ctx == NULL) {
  ------------------
  |  Branch (70:13): [True: 0, False: 222]
  ------------------
   71|      0|            goto err;
   72|      0|        }
   73|    222|        return ctx;
   74|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (74:5): [True: 0, False: 324]
  ------------------
   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|    102|    case SSH_KDF_SHA512:
  ------------------
  |  Branch (80:5): [True: 102, False: 222]
  ------------------
   81|    102|        ctx->ctx.sha512_ctx = sha512_init();
   82|    102|        if (ctx->ctx.sha512_ctx == NULL) {
  ------------------
  |  Branch (82:13): [True: 0, False: 102]
  ------------------
   83|      0|            goto err;
   84|      0|        }
   85|    102|        return ctx;
   86|    324|    }
   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|    324|}
kdf.c:ssh_mac_update:
  116|  1.29k|{
  117|  1.29k|    switch (ctx->digest_type) {
  ------------------
  |  Branch (117:13): [True: 1.29k, False: 0]
  ------------------
  118|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (118:5): [True: 0, False: 1.29k]
  ------------------
  119|      0|        return sha1_update(ctx->ctx.sha1_ctx, data, len);
  120|    888|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (120:5): [True: 888, False: 408]
  ------------------
  121|    888|        return sha256_update(ctx->ctx.sha256_ctx, data, len);
  122|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (122:5): [True: 0, False: 1.29k]
  ------------------
  123|      0|        return sha384_update(ctx->ctx.sha384_ctx, data, len);
  124|    408|    case SSH_KDF_SHA512:
  ------------------
  |  Branch (124:5): [True: 408, False: 888]
  ------------------
  125|    408|        return sha512_update(ctx->ctx.sha512_ctx, data, len);
  126|  1.29k|    }
  127|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  128|  1.29k|}
kdf.c:ssh_mac_final:
  131|    324|{
  132|    324|    int rc = SSH_ERROR;
  ------------------
  |  |  317|    324|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  133|       |
  134|    324|    switch (ctx->digest_type) {
  ------------------
  |  Branch (134:13): [True: 324, False: 0]
  ------------------
  135|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (135:5): [True: 0, False: 324]
  ------------------
  136|      0|        rc = sha1_final(md, ctx->ctx.sha1_ctx);
  137|      0|        break;
  138|    222|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (138:5): [True: 222, False: 102]
  ------------------
  139|    222|        rc = sha256_final(md, ctx->ctx.sha256_ctx);
  140|    222|        break;
  141|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (141:5): [True: 0, False: 324]
  ------------------
  142|      0|        rc = sha384_final(md, ctx->ctx.sha384_ctx);
  143|      0|        break;
  144|    102|    case SSH_KDF_SHA512:
  ------------------
  |  Branch (144:5): [True: 102, False: 222]
  ------------------
  145|    102|        rc = sha512_final(md, ctx->ctx.sha512_ctx);
  146|    102|        break;
  147|    324|    }
  148|    324|    SAFE_FREE(ctx);
  ------------------
  |  |  375|    324|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 324, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 324]
  |  |  ------------------
  ------------------
  149|    324|    return rc;
  150|    324|}

ssh_kex_get_default_methods:
  300|    501|{
  301|    501|    if (type >= SSH_KEX_METHODS) {
  ------------------
  |  |   27|    501|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (301:9): [True: 0, False: 501]
  ------------------
  302|      0|        return NULL;
  303|      0|    }
  304|       |
  305|    501|    return default_methods[type];
  306|    501|}
ssh_packet_kexinit:
  397|    350|{
  398|    350|    int i, ok;
  399|    350|    struct ssh_crypto_struct *crypto = session->next_crypto;
  400|    350|    int server_kex = session->server;
  401|    350|    ssh_string str = NULL;
  402|    350|    char *strings[SSH_KEX_METHODS] = {0};
  403|    350|    int rc = SSH_ERROR;
  ------------------
  |  |  317|    350|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  404|    350|    size_t len;
  405|       |
  406|    350|    uint8_t first_kex_packet_follows = 0;
  407|    350|    uint32_t kexinit_reserved = 0;
  408|       |
  409|    350|    (void)type;
  410|    350|    (void)user;
  411|       |
  412|    350|    SSH_LOG(SSH_LOG_TRACE, "KEXINIT received");
  ------------------
  |  |  283|    350|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  413|       |
  414|    350|    if (session->session_state == SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (414:9): [True: 0, False: 350]
  ------------------
  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|    350|    } else if (session->session_state != SSH_SESSION_STATE_INITIAL_KEX) {
  ------------------
  |  Branch (429:16): [True: 0, False: 350]
  ------------------
  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|    350|    if (server_kex) {
  ------------------
  |  Branch (435:9): [True: 0, False: 350]
  ------------------
  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|    350|    } else {
  457|    350|        len = ssh_buffer_get_data(packet, crypto->server_kex.cookie, 16);
  458|    350|        if (len != 16) {
  ------------------
  |  Branch (458:13): [True: 1, False: 349]
  ------------------
  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|    349|        ok = ssh_hashbufin_add_cookie(session, crypto->server_kex.cookie);
  465|    349|        if (ok < 0) {
  ------------------
  |  Branch (465:13): [True: 0, False: 349]
  ------------------
  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|    349|        ok = ssh_set_client_kex(session);
  472|    349|        if (ok == SSH_ERROR) {
  ------------------
  |  |  317|    349|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (472:13): [True: 0, False: 349]
  ------------------
  473|      0|            goto error;
  474|      0|        }
  475|    349|    }
  476|       |
  477|  3.65k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.65k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (477:17): [True: 3.32k, False: 325]
  ------------------
  478|  3.32k|        str = ssh_buffer_get_ssh_string(packet);
  479|  3.32k|        if (str == NULL) {
  ------------------
  |  Branch (479:13): [True: 24, False: 3.30k]
  ------------------
  480|     24|          goto error;
  481|     24|        }
  482|       |
  483|  3.30k|        rc = ssh_buffer_add_ssh_string(session->in_hashbuf, str);
  484|  3.30k|        if (rc < 0) {
  ------------------
  |  Branch (484:13): [True: 0, False: 3.30k]
  ------------------
  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|  3.30k|        strings[i] = ssh_string_to_char(str);
  491|  3.30k|        if (strings[i] == NULL) {
  ------------------
  |  Branch (491:13): [True: 0, False: 3.30k]
  ------------------
  492|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  493|      0|            goto error;
  494|      0|        }
  495|  3.30k|        SSH_STRING_FREE(str);
  ------------------
  |  |  924|  3.30k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 3.30k, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 3.30k]
  |  |  ------------------
  ------------------
  496|  3.30k|        str = NULL;
  497|  3.30k|    }
  498|       |
  499|       |    /* copy the peer kex info into an array of strings */
  500|    325|    if (server_kex) {
  ------------------
  |  Branch (500:9): [True: 0, False: 325]
  ------------------
  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|    325|    } else { /* client */
  507|  3.57k|        for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.57k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (507:21): [True: 3.25k, False: 325]
  ------------------
  508|  3.25k|            crypto->server_kex.methods[i] = strings[i];
  509|  3.25k|        }
  510|    325|    }
  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|    325|    rc = ssh_buffer_get_u8(packet, &first_kex_packet_follows);
  524|    325|    if (rc != 1) {
  ------------------
  |  Branch (524:9): [True: 0, False: 325]
  ------------------
  525|      0|        goto error;
  526|      0|    }
  527|       |
  528|    325|    rc = ssh_buffer_add_u8(session->in_hashbuf, first_kex_packet_follows);
  529|    325|    if (rc < 0) {
  ------------------
  |  Branch (529:9): [True: 0, False: 325]
  ------------------
  530|      0|        goto error;
  531|      0|    }
  532|       |
  533|    325|    rc = ssh_buffer_add_u32(session->in_hashbuf, kexinit_reserved);
  534|    325|    if (rc < 0) {
  ------------------
  |  Branch (534:9): [True: 0, False: 325]
  ------------------
  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|    325|    if (first_kex_packet_follows || session->send_first_kex_follows) {
  ------------------
  |  Branch (544:9): [True: 203, False: 122]
  |  Branch (544:37): [True: 0, False: 122]
  ------------------
  545|    203|        char **client_methods = crypto->client_kex.methods;
  546|    203|        char **server_methods = crypto->server_kex.methods;
  547|    203|        session->first_kex_follows_guess_wrong =
  548|    203|            cmp_first_kex_algo(client_methods[SSH_KEX],
  ------------------
  |  Branch (548:13): [True: 199, False: 4]
  ------------------
  549|    203|                               server_methods[SSH_KEX]) ||
  550|      4|            cmp_first_kex_algo(client_methods[SSH_HOSTKEYS],
  ------------------
  |  Branch (550:13): [True: 3, False: 1]
  ------------------
  551|      4|                               server_methods[SSH_HOSTKEYS]);
  552|    203|            SSH_LOG(SSH_LOG_DEBUG, "The initial guess was %s.",
  ------------------
  |  |  283|    406|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 202, False: 1]
  |  |  ------------------
  ------------------
  553|    203|                    session->first_kex_follows_guess_wrong ? "wrong" : "right");
  554|    203|    }
  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|    325|    if (server_kex) {
  ------------------
  |  Branch (560:9): [True: 0, False: 325]
  ------------------
  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|    325|    } else {
  568|       |        /* client kex */
  569|    325|        ok = match_group(crypto->server_kex.methods[SSH_KEX],
  570|    325|                         KEX_STRICT_SERVER);
  ------------------
  |  |  197|    325|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  571|    325|        if (ok) {
  ------------------
  |  Branch (571:13): [True: 12, False: 313]
  ------------------
  572|     12|            SSH_LOG(SSH_LOG_DEBUG, "Server supports strict kex, enabling.");
  ------------------
  |  |  283|     12|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  573|     12|            session->flags |= SSH_SESSION_FLAG_KEX_STRICT;
  ------------------
  |  |   90|     12|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  574|     12|        }
  575|    325|    }
  576|    325|#ifdef WITH_SERVER
  577|    325|    if (server_kex) {
  ------------------
  |  Branch (577:9): [True: 0, False: 325]
  ------------------
  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|    325|#endif /* WITH_SERVER */
  652|       |
  653|       |    /* Note, that his overwrites authenticated state in case of rekeying */
  654|    325|    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|    325|    if (session->send_first_kex_follows == false) {
  ------------------
  |  Branch (658:9): [True: 325, False: 0]
  ------------------
  659|    325|        session->dh_handshake_state = DH_STATE_INIT;
  660|    325|    }
  661|    325|    session->ssh_connection_callback(session);
  662|    325|    return SSH_PACKET_USED;
  ------------------
  |  |  638|    325|#define SSH_PACKET_USED 1
  ------------------
  663|       |
  664|     25|error:
  665|     25|    SSH_STRING_FREE(str);
  ------------------
  |  |  924|     25|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 25]
  |  |  |  Branch (924:69): [Folded, False: 25]
  |  |  ------------------
  ------------------
  666|    275|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|    275|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (666:17): [True: 250, False: 25]
  ------------------
  667|    250|        if (server_kex) {
  ------------------
  |  Branch (667:13): [True: 0, False: 250]
  ------------------
  668|      0|#ifdef WITH_SERVER
  669|      0|            session->next_crypto->client_kex.methods[i] = NULL;
  670|      0|#endif /* WITH_SERVER */
  671|    250|        } else { /* client */
  672|    250|            session->next_crypto->server_kex.methods[i] = NULL;
  673|    250|        }
  674|    250|        SAFE_FREE(strings[i]);
  ------------------
  |  |  375|    250|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 52, False: 198]
  |  |  |  Branch (375:71): [Folded, False: 250]
  |  |  ------------------
  ------------------
  675|    250|    }
  676|       |
  677|     25|    session->session_state = SSH_SESSION_STATE_ERROR;
  678|       |
  679|     25|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     25|#define SSH_PACKET_USED 1
  ------------------
  680|    325|}
ssh_list_kex:
  682|    826|void ssh_list_kex(struct ssh_kex_struct *kex) {
  683|    826|  int i = 0;
  684|       |
  685|       |#ifdef DEBUG_CRYPTO
  686|       |  ssh_log_hexdump("session cookie", kex->cookie, 16);
  687|       |#endif
  688|       |
  689|  9.08k|  for(i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  9.08k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (689:14): [True: 8.26k, False: 826]
  ------------------
  690|  8.26k|    if (kex->methods[i] == NULL) {
  ------------------
  |  Branch (690:9): [True: 0, False: 8.26k]
  ------------------
  691|      0|      continue;
  692|      0|    }
  693|  8.26k|    SSH_LOG(SSH_LOG_FUNCTIONS, "%s: %s",
  ------------------
  |  |  283|  8.26k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  694|  8.26k|        ssh_kex_descriptions[i], kex->methods[i]);
  695|  8.26k|  }
  696|    826|}
ssh_client_select_hostkeys:
  708|    501|{
  709|    501|    const char *wanted = NULL;
  710|    501|    char *wanted_without_certs = NULL;
  711|    501|    char *known_hosts_algorithms = NULL;
  712|    501|    char *known_hosts_ordered = NULL;
  713|    501|    char *new_hostkeys = NULL;
  714|    501|    char *fips_hostkeys = NULL;
  715|       |
  716|    501|    wanted = session->opts.wanted_methods[SSH_HOSTKEYS];
  717|    501|    if (wanted == NULL) {
  ------------------
  |  Branch (717:9): [True: 501, False: 0]
  ------------------
  718|    501|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|    501|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 501]
  |  |  ------------------
  ------------------
  719|      0|            wanted = ssh_kex_get_fips_methods(SSH_HOSTKEYS);
  720|    501|        } else {
  721|    501|            wanted = ssh_kex_get_default_methods(SSH_HOSTKEYS);
  722|    501|        }
  723|    501|    }
  724|       |
  725|       |    /* This removes the certificate types, unsupported for now */
  726|    501|    wanted_without_certs = ssh_find_all_matching(HOSTKEYS, wanted);
  ------------------
  |  |  142|    501|#define HOSTKEYS "ssh-ed25519," \
  |  |  143|    501|                 EC_HOSTKEYS \
  |  |  144|    501|                 "sk-ssh-ed25519@openssh.com," \
  |  |  145|    501|                 EC_SK_HOSTKEYS \
  |  |  146|    501|                 "rsa-sha2-512," \
  |  |  147|    501|                 "rsa-sha2-256," \
  |  |  148|    501|                 "ssh-rsa"
  ------------------
  727|    501|    if (wanted_without_certs == NULL) {
  ------------------
  |  Branch (727:9): [True: 0, False: 501]
  ------------------
  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|    501|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|    501|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  735|    501|            "Order of wanted host keys: \"%s\"",
  736|    501|            wanted_without_certs);
  737|       |
  738|    501|    known_hosts_algorithms = ssh_known_hosts_get_algorithms_names(session);
  739|    501|    if (known_hosts_algorithms == NULL) {
  ------------------
  |  Branch (739:9): [True: 501, False: 0]
  ------------------
  740|    501|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|    501|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  741|    501|                "No key found in known_hosts; "
  742|    501|                "changing host key method to \"%s\"",
  743|    501|                wanted_without_certs);
  744|       |
  745|    501|        return wanted_without_certs;
  746|    501|    }
  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|    850|{
  802|    850|    struct ssh_kex_struct *client = &session->next_crypto->client_kex;
  803|    850|    const char *wanted = NULL;
  804|    850|    int ok;
  805|    850|    int i;
  806|    850|    bool gssapi_null_alg = false;
  807|    850|    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|    850|    if (client->methods[0] != NULL) {
  ------------------
  |  Branch (811:9): [True: 349, False: 501]
  ------------------
  812|    349|        return SSH_OK;
  ------------------
  |  |  316|    349|#define SSH_OK 0     /* No error */
  ------------------
  813|    349|    }
  814|       |
  815|    501|    ok = ssh_get_random(client->cookie, 16, 0);
  816|    501|    if (!ok) {
  ------------------
  |  Branch (816:9): [True: 0, False: 501]
  ------------------
  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|  5.51k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  5.51k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (859:17): [True: 5.01k, False: 501]
  ------------------
  860|  5.01k|        if (i == SSH_HOSTKEYS) {
  ------------------
  |  Branch (860:13): [True: 501, False: 4.50k]
  ------------------
  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|    501|            client->methods[i] = ssh_client_select_hostkeys(session);
  865|    501|            if (client->methods[i] == NULL) {
  ------------------
  |  Branch (865:17): [True: 0, False: 501]
  ------------------
  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|    501|            if (gssapi_null_alg) {
  ------------------
  |  Branch (869:17): [True: 0, False: 501]
  ------------------
  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|    501|            continue;
  880|    501|        }
  881|       |
  882|  4.50k|        wanted = session->opts.wanted_methods[i];
  883|  4.50k|        if (wanted == NULL) {
  ------------------
  |  Branch (883:13): [True: 2.50k, False: 2.00k]
  ------------------
  884|  2.50k|            if (ssh_fips_mode()) {
  ------------------
  |  |  115|  2.50k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 2.50k]
  |  |  ------------------
  ------------------
  885|      0|                wanted = fips_methods[i];
  886|  2.50k|            } else {
  887|  2.50k|                wanted = default_methods[i];
  888|  2.50k|            }
  889|  2.50k|        }
  890|  4.50k|        client->methods[i] = strdup(wanted);
  891|  4.50k|        if (client->methods[i] == NULL) {
  ------------------
  |  Branch (891:13): [True: 0, False: 4.50k]
  ------------------
  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|  4.50k|    }
  896|       |
  897|       |    /* For rekeying, skip the extension negotiation */
  898|    501|    if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) {
  ------------------
  |  |   78|    501|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (898:9): [True: 0, False: 501]
  ------------------
  899|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  900|      0|    }
  901|       |
  902|    501|    ok = ssh_kex_append_extensions(session, client);
  903|    501|    if (ok != SSH_OK){
  ------------------
  |  |  316|    501|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (903:9): [True: 0, False: 501]
  ------------------
  904|      0|        return ok;
  905|      0|    }
  906|       |
  907|    501|    return SSH_OK;
  ------------------
  |  |  316|    501|#define SSH_OK 0     /* No error */
  ------------------
  908|    501|}
ssh_kex_append_extensions:
  911|    501|{
  912|    501|    char *kex = NULL;
  913|    501|    char *kex_tmp = NULL;
  914|    501|    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|    501|    kex = pkex->methods[SSH_KEX];
  920|    501|    len = strlen(kex);
  921|    501|    if (session->server) {
  ------------------
  |  Branch (921:9): [True: 0, False: 501]
  ------------------
  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|    501|    } else {
  925|       |        /* Comma, comma, nul byte */
  926|    501|        kex_len = len + 1 + strlen(KEX_EXTENSION_CLIENT) + 1 +
  ------------------
  |  |  194|    501|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  927|    501|                  strlen(KEX_STRICT_CLIENT) + 1;
  ------------------
  |  |  196|    501|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  928|    501|    }
  929|    501|    if (kex_len >= MAX_PACKET_LEN) {
  ------------------
  |  |  216|    501|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (929:9): [True: 0, False: 501]
  ------------------
  930|       |        /* Overflow */
  931|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  932|      0|    }
  933|    501|    kex_tmp = realloc(kex, kex_len);
  934|    501|    if (kex_tmp == NULL) {
  ------------------
  |  Branch (934:9): [True: 0, False: 501]
  ------------------
  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|    501|    if (session->server){
  ------------------
  |  Branch (938:9): [True: 0, False: 501]
  ------------------
  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|    501|    } else {
  941|    501|        snprintf(kex_tmp + len,
  942|    501|                 kex_len - len,
  943|    501|                 ",%s,%s",
  944|    501|                 KEX_EXTENSION_CLIENT,
  ------------------
  |  |  194|    501|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  945|    501|                 KEX_STRICT_CLIENT);
  ------------------
  |  |  196|    501|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  946|    501|    }
  947|    501|    pkex->methods[SSH_KEX] = kex_tmp;
  948|    501|    return SSH_OK;
  ------------------
  |  |  316|    501|#define SSH_OK 0     /* No error */
  ------------------
  949|    501|}
ssh_kex_select_methods:
 1082|    325|{
 1083|    325|    struct ssh_crypto_struct *crypto = session->next_crypto;
 1084|    325|    struct ssh_kex_struct *server = &crypto->server_kex;
 1085|    325|    struct ssh_kex_struct *client = &crypto->client_kex;
 1086|    325|    char *ext_start = NULL;
 1087|    325|    const char *aead_hmac = NULL;
 1088|    325|    enum ssh_key_exchange_e kex_type;
 1089|    325|    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|    325|    if (session->client) {
  ------------------
  |  Branch (1093:9): [True: 325, False: 0]
  ------------------
 1094|    325|        ext_start = strstr(client->methods[SSH_KEX], "," KEX_EXTENSION_CLIENT);
  ------------------
  |  |  194|    325|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
 1095|    325|        if (ext_start != NULL) {
  ------------------
  |  Branch (1095:13): [True: 325, False: 0]
  ------------------
 1096|    325|            ext_start[0] = '\0';
 1097|    325|        }
 1098|    325|    }
 1099|    325|    if (session->server) {
  ------------------
  |  Branch (1099:9): [True: 0, False: 325]
  ------------------
 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|  3.15k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.15k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (1106:17): [True: 2.87k, False: 279]
  ------------------
 1107|  2.87k|        crypto->kex_methods[i] = ssh_find_matching(server->methods[i],
 1108|  2.87k|                                                   client->methods[i]);
 1109|       |
 1110|  2.87k|        if (i == SSH_MAC_C_S || i == SSH_MAC_S_C) {
  ------------------
  |  Branch (1110:13): [True: 285, False: 2.59k]
  |  Branch (1110:33): [True: 284, False: 2.30k]
  ------------------
 1111|    569|            aead_hmac = ssh_find_aead_hmac(crypto->kex_methods[i - 2]);
 1112|    569|            if (aead_hmac) {
  ------------------
  |  Branch (1112:17): [True: 0, False: 569]
  ------------------
 1113|      0|                free(crypto->kex_methods[i]);
 1114|      0|                crypto->kex_methods[i] = strdup(aead_hmac);
 1115|      0|            }
 1116|    569|        }
 1117|  2.87k|        if (crypto->kex_methods[i] == NULL && i < SSH_LANG_C_S) {
  ------------------
  |  Branch (1117:13): [True: 78, False: 2.80k]
  |  Branch (1117:47): [True: 46, False: 32]
  ------------------
 1118|     46|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  313|     46|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1119|     46|                          "kex error : no match for method %s: server [%s], "
 1120|     46|                          "client [%s]", ssh_kex_descriptions[i],
 1121|     46|                          server->methods[i], client->methods[i]);
 1122|     46|            return SSH_ERROR;
  ------------------
  |  |  317|     46|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1123|  2.83k|        } else if ((i >= SSH_LANG_C_S) && (crypto->kex_methods[i] == NULL)) {
  ------------------
  |  Branch (1123:20): [True: 558, False: 2.27k]
  |  Branch (1123:43): [True: 32, False: 526]
  ------------------
 1124|       |            /* we can safely do that for languages */
 1125|     32|            crypto->kex_methods[i] = strdup("");
 1126|     32|        }
 1127|  2.87k|    }
 1128|       |
 1129|       |    /* We can not set this value directly as the old value is needed to revert
 1130|       |     * callbacks if we are client */
 1131|    279|    kex_type = kex_select_kex_type(crypto->kex_methods[SSH_KEX]);
 1132|    279|    if (session->client && session->first_kex_follows_guess_wrong) {
  ------------------
  |  Branch (1132:9): [True: 279, False: 0]
  |  Branch (1132:28): [True: 184, False: 95]
  ------------------
 1133|    184|        SSH_LOG(SSH_LOG_DEBUG, "Our guess was wrong. Restarting the KEX");
  ------------------
  |  |  283|    184|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1134|       |        /* We need to remove the wrong callbacks and start kex again */
 1135|    184|        revert_kex_callbacks(session);
 1136|    184|        session->dh_handshake_state = DH_STATE_INIT;
 1137|    184|        session->first_kex_follows_guess_wrong = false;
 1138|    184|    }
 1139|    279|    crypto->kex_type = kex_type;
 1140|       |
 1141|    279|    SSH_LOG(SSH_LOG_DEBUG, "Negotiated %s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
  ------------------
  |  |  283|    279|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1142|    279|            session->next_crypto->kex_methods[SSH_KEX],
 1143|    279|            session->next_crypto->kex_methods[SSH_HOSTKEYS],
 1144|    279|            session->next_crypto->kex_methods[SSH_CRYPT_C_S],
 1145|    279|            session->next_crypto->kex_methods[SSH_CRYPT_S_C],
 1146|    279|            session->next_crypto->kex_methods[SSH_MAC_C_S],
 1147|    279|            session->next_crypto->kex_methods[SSH_MAC_S_C],
 1148|    279|            session->next_crypto->kex_methods[SSH_COMP_C_S],
 1149|    279|            session->next_crypto->kex_methods[SSH_COMP_S_C],
 1150|    279|            session->next_crypto->kex_methods[SSH_LANG_C_S],
 1151|    279|            session->next_crypto->kex_methods[SSH_LANG_S_C]
 1152|    279|    );
 1153|    279|    return SSH_OK;
  ------------------
  |  |  316|    279|#define SSH_OK 0     /* No error */
  ------------------
 1154|    325|}
ssh_send_kex:
 1159|    501|{
 1160|    501|    struct ssh_kex_struct *kex = (session->server ?
  ------------------
  |  Branch (1160:35): [True: 0, False: 501]
  ------------------
 1161|      0|        &session->next_crypto->server_kex :
 1162|    501|        &session->next_crypto->client_kex);
 1163|    501|    ssh_string str = NULL;
 1164|    501|    int i;
 1165|    501|    int rc;
 1166|    501|    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|    501|    if (session->client &&
  ------------------
  |  Branch (1170:9): [True: 501, False: 0]
  ------------------
 1171|    501|        session->session_state != SSH_SESSION_STATE_KEXINIT_RECEIVED &&
  ------------------
  |  Branch (1171:9): [True: 501, False: 0]
  ------------------
 1172|    501|        session->send_first_kex_follows) {
  ------------------
  |  Branch (1172:9): [True: 0, False: 501]
  ------------------
 1173|      0|        first_kex_packet_follows = 1;
 1174|      0|    }
 1175|       |
 1176|    501|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|    501|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1177|    501|            "Sending KEXINIT packet, first_kex_packet_follows = %d",
 1178|    501|            first_kex_packet_follows);
 1179|       |
 1180|    501|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    501|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    501|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    501|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    501|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    501|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    501|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    501|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1181|    501|                         "bP",
 1182|    501|                         SSH2_MSG_KEXINIT,
 1183|    501|                         (size_t)16,
 1184|    501|                         kex->cookie); /* cookie */
 1185|    501|    if (rc != SSH_OK)
  ------------------
  |  |  316|    501|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1185:9): [True: 0, False: 501]
  ------------------
 1186|      0|        goto error;
 1187|    501|    if (ssh_hashbufout_add_cookie(session) < 0) {
  ------------------
  |  Branch (1187:9): [True: 0, False: 501]
  ------------------
 1188|      0|        goto error;
 1189|      0|    }
 1190|       |
 1191|    501|    ssh_list_kex(kex);
 1192|       |
 1193|  5.51k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  5.51k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (1193:17): [True: 5.01k, False: 501]
  ------------------
 1194|  5.01k|        str = ssh_string_from_char(kex->methods[i]);
 1195|  5.01k|        if (str == NULL) {
  ------------------
  |  Branch (1195:13): [True: 0, False: 5.01k]
  ------------------
 1196|      0|            goto error;
 1197|      0|        }
 1198|       |
 1199|  5.01k|        rc = ssh_buffer_add_ssh_string(session->out_hashbuf, str);
 1200|  5.01k|        if (rc < 0) {
  ------------------
  |  Branch (1200:13): [True: 0, False: 5.01k]
  ------------------
 1201|      0|            goto error;
 1202|      0|        }
 1203|  5.01k|        rc = ssh_buffer_add_ssh_string(session->out_buffer, str);
 1204|  5.01k|        if (rc < 0) {
  ------------------
  |  Branch (1204:13): [True: 0, False: 5.01k]
  ------------------
 1205|      0|            goto error;
 1206|      0|        }
 1207|  5.01k|        SSH_STRING_FREE(str);
  ------------------
  |  |  924|  5.01k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 5.01k, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 5.01k]
  |  |  ------------------
  ------------------
 1208|  5.01k|        str = NULL;
 1209|  5.01k|    }
 1210|       |
 1211|    501|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    501|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    501|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    501|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    501|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    501|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    501|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    501|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1212|    501|                         "bd",
 1213|    501|                         first_kex_packet_follows,
 1214|    501|                         0);
 1215|    501|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    501|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1215:9): [True: 0, False: 501]
  ------------------
 1216|      0|        goto error;
 1217|      0|    }
 1218|       |
 1219|       |    /* Prepare also the first_kex_packet_follows and reserved to 0 */
 1220|    501|    rc = ssh_buffer_add_u8(session->out_hashbuf, first_kex_packet_follows);
 1221|    501|    if (rc < 0) {
  ------------------
  |  Branch (1221:9): [True: 0, False: 501]
  ------------------
 1222|      0|        goto error;
 1223|      0|    }
 1224|    501|    rc = ssh_buffer_add_u32(session->out_hashbuf, 0);
 1225|    501|    if (rc < 0) {
  ------------------
  |  Branch (1225:9): [True: 0, False: 501]
  ------------------
 1226|      0|        goto error;
 1227|      0|    }
 1228|       |
 1229|    501|    rc = ssh_packet_send(session);
 1230|    501|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    501|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1230:9): [True: 0, False: 501]
  ------------------
 1231|      0|        return -1;
 1232|      0|    }
 1233|       |
 1234|    501|    session->flags |= SSH_SESSION_FLAG_KEXINIT_SENT;
  ------------------
  |  |   86|    501|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
 1235|    501|    SSH_LOG(SSH_LOG_PACKET, "SSH_MSG_KEXINIT sent");
  ------------------
  |  |  283|    501|    _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|    501|    if (first_kex_packet_follows == 1) {
  ------------------
  |  Branch (1239:9): [True: 0, False: 501]
  ------------------
 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|    501|    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|    501|}
ssh_keep_known_algos:
 1324|  2.28k|{
 1325|  2.28k|    if (algo > SSH_LANG_S_C) {
  ------------------
  |  Branch (1325:9): [True: 0, False: 2.28k]
  ------------------
 1326|      0|        return NULL;
 1327|      0|    }
 1328|       |
 1329|  2.28k|    return ssh_find_all_matching(supported_methods[algo], list);
 1330|  2.28k|}
ssh_make_sessionid:
 1459|     54|{
 1460|     54|    ssh_string num = NULL;
 1461|     54|    ssh_buffer server_hash = NULL;
 1462|     54|    ssh_buffer client_hash = NULL;
 1463|     54|    ssh_buffer buf = NULL;
 1464|     54|    ssh_string server_pubkey_blob = NULL;
 1465|     54|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
 1466|     54|    const_bignum client_pubkey, server_pubkey;
 1467|       |#else
 1468|       |    bignum client_pubkey = NULL, server_pubkey = NULL;
 1469|       |#endif /* OPENSSL_VERSION_NUMBER */
 1470|     54|#ifdef WITH_GEX
 1471|     54|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
 1472|     54|    const_bignum modulus, generator;
 1473|       |#else
 1474|       |    bignum modulus = NULL, generator = NULL;
 1475|       |#endif /* OPENSSL_VERSION_NUMBER */
 1476|     54|#endif /* WITH_GEX */
 1477|     54|    int rc = SSH_ERROR;
  ------------------
  |  |  317|     54|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1478|       |
 1479|     54|    buf = ssh_buffer_new();
 1480|     54|    if (buf == NULL) {
  ------------------
  |  Branch (1480:9): [True: 0, False: 54]
  ------------------
 1481|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1482|      0|        return rc;
 1483|      0|    }
 1484|       |
 1485|     54|    rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|     54|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     54|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     54|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     54|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     54|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     54|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     54|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1486|     54|                         "ss",
 1487|     54|                         session->clientbanner,
 1488|     54|                         session->serverbanner);
 1489|     54|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     54|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1489:9): [True: 0, False: 54]
  ------------------
 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|     54|    if (session->client) {
  ------------------
  |  Branch (1496:9): [True: 54, False: 0]
  ------------------
 1497|     54|        server_hash = session->in_hashbuf;
 1498|     54|        client_hash = session->out_hashbuf;
 1499|     54|    } else {
 1500|      0|        server_hash = session->out_hashbuf;
 1501|      0|        client_hash = session->in_hashbuf;
 1502|      0|    }
 1503|       |
 1504|     54|    rc = ssh_dh_get_next_server_publickey_blob(session, &server_pubkey_blob);
 1505|     54|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     54|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1505:9): [True: 0, False: 54]
  ------------------
 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|     54|    if (server_pubkey_blob == NULL) {
  ------------------
  |  Branch (1512:9): [True: 0, False: 54]
  ------------------
 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|     54|    rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|     54|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     54|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     54|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     54|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     54|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     54|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     54|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1525|     54|                         "dPdPS",
 1526|     54|                         ssh_buffer_get_len(client_hash),
 1527|     54|                         (size_t)ssh_buffer_get_len(client_hash),
 1528|     54|                         ssh_buffer_get(client_hash),
 1529|     54|                         ssh_buffer_get_len(server_hash),
 1530|     54|                         (size_t)ssh_buffer_get_len(server_hash),
 1531|     54|                         ssh_buffer_get(server_hash),
 1532|     54|                         server_pubkey_blob);
 1533|     54|    SSH_STRING_FREE(server_pubkey_blob);
  ------------------
  |  |  924|     54|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 54, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 54]
  |  |  ------------------
  ------------------
 1534|     54|    if (rc != SSH_OK){
  ------------------
  |  |  316|     54|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1534:9): [True: 0, False: 54]
  ------------------
 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|     54|    switch(session->next_crypto->kex_type) {
 1542|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1542:5): [True: 0, False: 54]
  ------------------
 1543|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1543:5): [True: 0, False: 54]
  ------------------
 1544|      0|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1544:5): [True: 0, False: 54]
  ------------------
 1545|      0|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1545:5): [True: 0, False: 54]
  ------------------
 1546|      3|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1546:5): [True: 3, False: 51]
  ------------------
 1547|      3|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1547:5): [True: 0, False: 54]
  ------------------
 1548|     17|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1548:5): [True: 14, False: 40]
  ------------------
 1549|     17|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1550|     17|                                     DH_CLIENT_KEYPAIR, NULL, &client_pubkey);
  ------------------
  |  |   30|     17|#define DH_CLIENT_KEYPAIR 0
  ------------------
 1551|     17|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     17|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1551:13): [True: 0, False: 17]
  ------------------
 1552|      0|            goto error;
 1553|      0|        }
 1554|     17|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1555|     17|                                     DH_SERVER_KEYPAIR, NULL, &server_pubkey);
  ------------------
  |  |   31|     17|#define DH_SERVER_KEYPAIR 1
  ------------------
 1556|     17|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     17|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1556:13): [True: 0, False: 17]
  ------------------
 1557|      0|            goto error;
 1558|      0|        }
 1559|     17|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|     17|    _ssh_buffer_pack((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_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     17|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1560|     17|                             "BB",
 1561|     17|                             client_pubkey,
 1562|     17|                             server_pubkey);
 1563|     17|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     17|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1563:13): [True: 0, False: 17]
  ------------------
 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|     17|        break;
 1572|     17|#ifdef WITH_GEX
 1573|     17|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (1573:5): [True: 0, False: 54]
  ------------------
 1574|      0|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1574:5): [True: 0, False: 54]
  ------------------
 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: 54]
  ------------------
 1611|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1611:5): [True: 0, False: 54]
  ------------------
 1612|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1612:5): [True: 0, False: 54]
  ------------------
 1613|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1613:5): [True: 0, False: 54]
  ------------------
 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|      6|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1630:5): [True: 6, False: 48]
  ------------------
 1631|     37|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1631:5): [True: 31, False: 23]
  ------------------
 1632|     37|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1632:5): [True: 0, False: 54]
  ------------------
 1633|     37|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|     37|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     37|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     37|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     37|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     37|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     37|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     37|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1634|     37|                             "dPdP",
 1635|     37|                             CURVE25519_PUBKEY_SIZE,
 1636|     37|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1637|     37|                             session->next_crypto->curve25519_client_pubkey,
 1638|     37|                             CURVE25519_PUBKEY_SIZE,
 1639|     37|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1640|     37|                             session->next_crypto->curve25519_server_pubkey);
 1641|       |
 1642|     37|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     37|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1642:13): [True: 0, False: 37]
  ------------------
 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|     37|        break;
 1649|     37|#endif /* HAVE_CURVE25519 */
 1650|     37|#ifdef HAVE_SNTRUP761
 1651|     37|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1651:5): [True: 0, False: 54]
  ------------------
 1652|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1652:5): [True: 0, False: 54]
  ------------------
 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: 54]
  ------------------
 1675|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1675:5): [True: 0, False: 54]
  ------------------
 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: 54]
  ------------------
 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|     54|    }
 1696|     54|    switch (session->next_crypto->kex_type) {
 1697|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1697:5): [True: 0, False: 54]
  ------------------
 1698|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1698:5): [True: 0, False: 54]
  ------------------
 1699|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1699:5): [True: 0, False: 54]
  ------------------
 1700|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1700:5): [True: 0, False: 54]
  ------------------
 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|     54|    default:
  ------------------
  |  Branch (1706:5): [True: 54, False: 0]
  ------------------
 1707|     54|        rc = ssh_buffer_pack(buf, "B", session->next_crypto->shared_secret);
  ------------------
  |  |   50|     54|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     54|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     54|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     54|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     54|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     54|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     54|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1708|     54|        break;
 1709|     54|    }
 1710|     54|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     54|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1710:9): [True: 0, False: 54]
  ------------------
 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|     54|    rc = SSH_ERROR;
  ------------------
  |  |  317|     54|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1721|     54|    switch (session->next_crypto->kex_type) {
 1722|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1722:5): [True: 0, False: 54]
  ------------------
 1723|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1723:5): [True: 0, False: 54]
  ------------------
 1724|      0|#ifdef WITH_GEX
 1725|      0|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (1725:5): [True: 0, False: 54]
  ------------------
 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|      0|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1737:5): [True: 0, False: 54]
  ------------------
 1738|      0|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1738:5): [True: 0, False: 54]
  ------------------
 1739|      0|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (1739:5): [True: 0, False: 54]
  ------------------
 1740|      6|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1740:5): [True: 6, False: 48]
  ------------------
 1741|     37|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1741:5): [True: 31, False: 23]
  ------------------
 1742|     37|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1742:5): [True: 0, False: 54]
  ------------------
 1743|     37|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1743:5): [True: 0, False: 54]
  ------------------
 1744|     37|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1744:5): [True: 0, False: 54]
  ------------------
 1745|     37|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1745:5): [True: 0, False: 54]
  ------------------
 1746|     37|#ifdef WITH_GEX
 1747|     37|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1747:5): [True: 0, False: 54]
  ------------------
 1748|     37|#endif /* WITH_GEX */
 1749|     37|        session->next_crypto->digest_len = SHA256_DIGEST_LENGTH;
 1750|     37|        session->next_crypto->digest_type = SSH_KDF_SHA256;
 1751|     37|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1752|     37|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1752:13): [True: 0, False: 37]
  ------------------
 1753|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1754|      0|            goto error;
 1755|      0|        }
 1756|     37|        sha256(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
 1757|     37|                                     session->next_crypto->secret_hash);
 1758|     37|        break;
 1759|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1759:5): [True: 0, False: 54]
  ------------------
 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|      3|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1773:5): [True: 3, False: 51]
  ------------------
 1774|      3|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1774:5): [True: 0, False: 54]
  ------------------
 1775|     17|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1775:5): [True: 14, False: 40]
  ------------------
 1776|     17|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1776:5): [True: 0, False: 54]
  ------------------
 1777|     17|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1777:5): [True: 0, False: 54]
  ------------------
 1778|     17|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1778:5): [True: 0, False: 54]
  ------------------
 1779|     17|        session->next_crypto->digest_len = SHA512_DIGEST_LENGTH;
 1780|     17|        session->next_crypto->digest_type = SSH_KDF_SHA512;
 1781|     17|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1782|     17|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1782:13): [True: 0, False: 17]
  ------------------
 1783|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1784|      0|            goto error;
 1785|      0|        }
 1786|     17|        sha512(ssh_buffer_get(buf),
 1787|     17|               ssh_buffer_get_len(buf),
 1788|     17|               session->next_crypto->secret_hash);
 1789|     17|        break;
 1790|      0|    default:
  ------------------
  |  Branch (1790:5): [True: 0, False: 54]
  ------------------
 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|     54|    }
 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|     54|    if (!session->next_crypto->session_id) {
  ------------------
  |  Branch (1801:9): [True: 54, False: 0]
  ------------------
 1802|     54|        session->next_crypto->session_id = malloc(session->next_crypto->digest_len);
 1803|     54|        if (session->next_crypto->session_id == NULL) {
  ------------------
  |  Branch (1803:13): [True: 0, False: 54]
  ------------------
 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|     54|        memcpy(session->next_crypto->session_id, session->next_crypto->secret_hash,
 1809|     54|                session->next_crypto->digest_len);
 1810|       |	/* Initial length is the same as secret hash */
 1811|     54|	session->next_crypto->session_id_len = session->next_crypto->digest_len;
 1812|     54|    }
 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|     54|    rc = SSH_OK;
  ------------------
  |  |  316|     54|#define SSH_OK 0     /* No error */
  ------------------
 1820|     54|error:
 1821|     54|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  966|     54|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 54, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 54]
  |  |  ------------------
  ------------------
 1822|     54|    SSH_BUFFER_FREE(client_hash);
  ------------------
  |  |  966|     54|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 54, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 54]
  |  |  ------------------
  ------------------
 1823|     54|    SSH_BUFFER_FREE(server_hash);
  ------------------
  |  |  966|     54|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 54, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 54]
  |  |  ------------------
  ------------------
 1824|       |
 1825|     54|    session->in_hashbuf = NULL;
 1826|     54|    session->out_hashbuf = NULL;
 1827|       |
 1828|     54|    SSH_STRING_FREE(num);
  ------------------
  |  |  924|     54|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 54]
  |  |  |  Branch (924:69): [Folded, False: 54]
  |  |  ------------------
  ------------------
 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|     54|    return rc;
 1835|     54|}
ssh_hashbufout_add_cookie:
 1838|    501|{
 1839|    501|    int rc;
 1840|       |
 1841|    501|    session->out_hashbuf = ssh_buffer_new();
 1842|    501|    if (session->out_hashbuf == NULL) {
  ------------------
  |  Branch (1842:9): [True: 0, False: 501]
  ------------------
 1843|      0|        return -1;
 1844|      0|    }
 1845|       |
 1846|    501|    rc = ssh_buffer_allocate_size(session->out_hashbuf,
 1847|    501|            sizeof(uint8_t) + 16);
 1848|    501|    if (rc < 0) {
  ------------------
  |  Branch (1848:9): [True: 0, False: 501]
  ------------------
 1849|      0|        ssh_buffer_reinit(session->out_hashbuf);
 1850|      0|        return -1;
 1851|      0|    }
 1852|       |
 1853|    501|    if (ssh_buffer_add_u8(session->out_hashbuf, 20) < 0) {
  ------------------
  |  Branch (1853:9): [True: 0, False: 501]
  ------------------
 1854|      0|        ssh_buffer_reinit(session->out_hashbuf);
 1855|      0|        return -1;
 1856|      0|    }
 1857|       |
 1858|    501|    if (session->server) {
  ------------------
  |  Branch (1858:9): [True: 0, False: 501]
  ------------------
 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|    501|    } else {
 1865|    501|        if (ssh_buffer_add_data(session->out_hashbuf,
  ------------------
  |  Branch (1865:13): [True: 0, False: 501]
  ------------------
 1866|    501|                    session->next_crypto->client_kex.cookie, 16) < 0) {
 1867|      0|            ssh_buffer_reinit(session->out_hashbuf);
 1868|      0|            return -1;
 1869|      0|        }
 1870|    501|    }
 1871|       |
 1872|    501|    return 0;
 1873|    501|}
ssh_hashbufin_add_cookie:
 1876|    349|{
 1877|    349|    int rc;
 1878|       |
 1879|    349|    session->in_hashbuf = ssh_buffer_new();
 1880|    349|    if (session->in_hashbuf == NULL) {
  ------------------
  |  Branch (1880:9): [True: 0, False: 349]
  ------------------
 1881|      0|        return -1;
 1882|      0|    }
 1883|       |
 1884|    349|    rc = ssh_buffer_allocate_size(session->in_hashbuf,
 1885|    349|            sizeof(uint8_t) + 20 + 16);
 1886|    349|    if (rc < 0) {
  ------------------
  |  Branch (1886:9): [True: 0, False: 349]
  ------------------
 1887|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1888|      0|        return -1;
 1889|      0|    }
 1890|       |
 1891|    349|    if (ssh_buffer_add_u8(session->in_hashbuf, 20) < 0) {
  ------------------
  |  Branch (1891:9): [True: 0, False: 349]
  ------------------
 1892|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1893|      0|        return -1;
 1894|      0|    }
 1895|    349|    if (ssh_buffer_add_data(session->in_hashbuf,cookie, 16) < 0) {
  ------------------
  |  Branch (1895:9): [True: 0, False: 349]
  ------------------
 1896|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1897|      0|        return -1;
 1898|      0|    }
 1899|       |
 1900|    349|    return 0;
 1901|    349|}
ssh_generate_session_keys:
 1904|     54|{
 1905|     54|    ssh_string k_string = NULL;
 1906|     54|    struct ssh_crypto_struct *crypto = session->next_crypto;
 1907|     54|    unsigned char *key = NULL;
 1908|     54|    unsigned char *IV_cli_to_srv = NULL;
 1909|     54|    unsigned char *IV_srv_to_cli = NULL;
 1910|     54|    unsigned char *enckey_cli_to_srv = NULL;
 1911|     54|    unsigned char *enckey_srv_to_cli = NULL;
 1912|     54|    unsigned char *intkey_cli_to_srv = NULL;
 1913|     54|    unsigned char *intkey_srv_to_cli = NULL;
 1914|     54|    size_t key_len = 0;
 1915|     54|    size_t IV_len = 0;
 1916|     54|    size_t enckey_cli_to_srv_len = 0;
 1917|     54|    size_t enckey_srv_to_cli_len = 0;
 1918|     54|    size_t intkey_cli_to_srv_len = 0;
 1919|     54|    size_t intkey_srv_to_cli_len = 0;
 1920|     54|    int rc = -1;
 1921|       |
 1922|     54|    switch (session->next_crypto->kex_type) {
 1923|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1923:5): [True: 0, False: 54]
  ------------------
 1924|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1924:5): [True: 0, False: 54]
  ------------------
 1925|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1925:5): [True: 0, False: 54]
  ------------------
 1926|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1926:5): [True: 0, False: 54]
  ------------------
 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|     54|    default:
  ------------------
  |  Branch (1932:5): [True: 54, False: 0]
  ------------------
 1933|     54|        k_string = ssh_make_bignum_string(crypto->shared_secret);
 1934|     54|        break;
 1935|     54|    }
 1936|     54|    if (k_string == NULL) {
  ------------------
  |  Branch (1936:9): [True: 0, False: 54]
  ------------------
 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|     54|    key = (unsigned char *)k_string;
 1943|     54|    key_len = ssh_string_len(k_string) + 4;
 1944|       |
 1945|     54|    IV_len = crypto->digest_len;
 1946|     54|    if (session->client) {
  ------------------
  |  Branch (1946:9): [True: 54, False: 0]
  ------------------
 1947|     54|        enckey_cli_to_srv_len = crypto->out_cipher->keysize / 8;
 1948|     54|        enckey_srv_to_cli_len = crypto->in_cipher->keysize / 8;
 1949|     54|        intkey_cli_to_srv_len = hmac_digest_len(crypto->out_hmac);
 1950|     54|        intkey_srv_to_cli_len = hmac_digest_len(crypto->in_hmac);
 1951|     54|    } 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|     54|    IV_cli_to_srv = malloc(IV_len);
 1959|     54|    IV_srv_to_cli = malloc(IV_len);
 1960|     54|    enckey_cli_to_srv = malloc(enckey_cli_to_srv_len);
 1961|     54|    enckey_srv_to_cli = malloc(enckey_srv_to_cli_len);
 1962|     54|    intkey_cli_to_srv = malloc(intkey_cli_to_srv_len);
 1963|     54|    intkey_srv_to_cli = malloc(intkey_srv_to_cli_len);
 1964|     54|    if (IV_cli_to_srv == NULL || IV_srv_to_cli == NULL ||
  ------------------
  |  Branch (1964:9): [True: 0, False: 54]
  |  Branch (1964:34): [True: 0, False: 54]
  ------------------
 1965|     54|        enckey_cli_to_srv == NULL || enckey_srv_to_cli == NULL ||
  ------------------
  |  Branch (1965:9): [True: 0, False: 54]
  |  Branch (1965:38): [True: 0, False: 54]
  ------------------
 1966|     54|        intkey_cli_to_srv == NULL || intkey_srv_to_cli == NULL) {
  ------------------
  |  Branch (1966:9): [True: 0, False: 54]
  |  Branch (1966:38): [True: 0, False: 54]
  ------------------
 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|     54|    rc = ssh_kdf(crypto, key, key_len, 'A', IV_cli_to_srv, IV_len);
 1973|     54|    if (rc < 0) {
  ------------------
  |  Branch (1973:9): [True: 0, False: 54]
  ------------------
 1974|      0|        goto error;
 1975|      0|    }
 1976|     54|    rc = ssh_kdf(crypto, key, key_len, 'B', IV_srv_to_cli, IV_len);
 1977|     54|    if (rc < 0) {
  ------------------
  |  Branch (1977:9): [True: 0, False: 54]
  ------------------
 1978|      0|        goto error;
 1979|      0|    }
 1980|       |    /* Encryption Key */
 1981|     54|    rc = ssh_kdf(crypto, key, key_len, 'C', enckey_cli_to_srv,
 1982|     54|                 enckey_cli_to_srv_len);
 1983|     54|    if (rc < 0) {
  ------------------
  |  Branch (1983:9): [True: 0, False: 54]
  ------------------
 1984|      0|        goto error;
 1985|      0|    }
 1986|     54|    rc = ssh_kdf(crypto, key, key_len, 'D', enckey_srv_to_cli,
 1987|     54|                 enckey_srv_to_cli_len);
 1988|     54|    if (rc < 0) {
  ------------------
  |  Branch (1988:9): [True: 0, False: 54]
  ------------------
 1989|      0|        goto error;
 1990|      0|    }
 1991|       |    /* Integrity Key */
 1992|     54|    rc = ssh_kdf(crypto, key, key_len, 'E', intkey_cli_to_srv,
 1993|     54|                 intkey_cli_to_srv_len);
 1994|     54|    if (rc < 0) {
  ------------------
  |  Branch (1994:9): [True: 0, False: 54]
  ------------------
 1995|      0|        goto error;
 1996|      0|    }
 1997|     54|    rc = ssh_kdf(crypto, key, key_len, 'F', intkey_srv_to_cli,
 1998|     54|                 intkey_srv_to_cli_len);
 1999|     54|    if (rc < 0) {
  ------------------
  |  Branch (1999:9): [True: 0, False: 54]
  ------------------
 2000|      0|        goto error;
 2001|      0|    }
 2002|       |
 2003|     54|    if (session->client) {
  ------------------
  |  Branch (2003:9): [True: 54, False: 0]
  ------------------
 2004|     54|        crypto->encryptIV = IV_cli_to_srv;
 2005|     54|        crypto->decryptIV = IV_srv_to_cli;
 2006|     54|        crypto->encryptkey = enckey_cli_to_srv;
 2007|     54|        crypto->decryptkey = enckey_srv_to_cli;
 2008|     54|        crypto->encryptMAC = intkey_cli_to_srv;
 2009|     54|        crypto->decryptMAC = intkey_srv_to_cli;
 2010|     54|    } 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|     54|    rc = 0;
 2033|     54|error:
 2034|     54|    ssh_string_burn(k_string);
 2035|     54|    SSH_STRING_FREE(k_string);
  ------------------
  |  |  924|     54|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 54, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 54]
  |  |  ------------------
  ------------------
 2036|     54|    if (rc != 0) {
  ------------------
  |  Branch (2036:9): [True: 0, False: 54]
  ------------------
 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|     54|    return rc;
 2046|     54|}
ssh_kex_is_gss:
 2055|      2|{
 2056|      2|    switch (crypto->kex_type) {
 2057|      0|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (2057:5): [True: 0, False: 2]
  ------------------
 2058|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (2058:5): [True: 0, False: 2]
  ------------------
 2059|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (2059:5): [True: 0, False: 2]
  ------------------
 2060|      0|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (2060:5): [True: 0, False: 2]
  ------------------
 2061|      0|        return true;
 2062|      2|    default:
  ------------------
  |  Branch (2062:5): [True: 2, False: 0]
  ------------------
 2063|       |        return false;
 2064|      2|    }
 2065|      2|}
kex.c:cmp_first_kex_algo:
  361|    207|                              const char *server_str) {
  362|    207|    size_t client_kex_len;
  363|    207|    size_t server_kex_len;
  364|       |
  365|    207|    const char *colon = NULL;
  366|       |
  367|    207|    int is_wrong = 1;
  368|       |
  369|    207|    if (client_str == NULL || server_str == NULL) {
  ------------------
  |  Branch (369:9): [True: 0, False: 207]
  |  Branch (369:31): [True: 0, False: 207]
  ------------------
  370|      0|        return is_wrong;
  371|      0|    }
  372|       |
  373|    207|    colon = strchr(client_str, ',');
  374|    207|    if (colon == NULL) {
  ------------------
  |  Branch (374:9): [True: 0, False: 207]
  ------------------
  375|      0|        client_kex_len = strlen(client_str);
  376|    207|    } else {
  377|    207|        client_kex_len = colon - client_str;
  378|    207|    }
  379|       |
  380|    207|    colon = strchr(server_str, ',');
  381|    207|    if (colon == NULL) {
  ------------------
  |  Branch (381:9): [True: 8, False: 199]
  ------------------
  382|      8|        server_kex_len = strlen(server_str);
  383|    199|    } else {
  384|    199|        server_kex_len = colon - server_str;
  385|    199|    }
  386|       |
  387|    207|    if (client_kex_len != server_kex_len) {
  ------------------
  |  Branch (387:9): [True: 199, False: 8]
  ------------------
  388|    199|        return is_wrong;
  389|    199|    }
  390|       |
  391|      8|    is_wrong = (strncmp(client_str, server_str, client_kex_len) != 0);
  392|       |
  393|      8|    return is_wrong;
  394|    207|}
kex.c:ssh_find_aead_hmac:
  952|    569|{
  953|    569|    if (cipher == NULL) {
  ------------------
  |  Branch (953:9): [True: 0, False: 569]
  ------------------
  954|      0|        return NULL;
  955|    569|    } else if (strcmp(cipher, "chacha20-poly1305@openssh.com") == 0) {
  ------------------
  |  Branch (955:16): [True: 0, False: 569]
  ------------------
  956|      0|        return "aead-poly1305";
  957|    569|    } else if (strcmp(cipher, "aes256-gcm@openssh.com") == 0) {
  ------------------
  |  Branch (957:16): [True: 0, False: 569]
  ------------------
  958|      0|        return "aead-gcm";
  959|    569|    } else if (strcmp(cipher, "aes128-gcm@openssh.com") == 0) {
  ------------------
  |  Branch (959:16): [True: 0, False: 569]
  ------------------
  960|      0|        return "aead-gcm";
  961|      0|    }
  962|    569|    return NULL;
  963|    569|}
kex.c:kex_select_kex_type:
  967|    279|{
  968|    279|    if (strcmp(kex, "diffie-hellman-group1-sha1") == 0) {
  ------------------
  |  Branch (968:9): [True: 0, False: 279]
  ------------------
  969|      0|        return SSH_KEX_DH_GROUP1_SHA1;
  970|    279|    } else if (strncmp(kex, "gss-group14-sha256-", 19) == 0) {
  ------------------
  |  Branch (970:16): [True: 0, False: 279]
  ------------------
  971|      0|        return SSH_GSS_KEX_DH_GROUP14_SHA256;
  972|    279|    } else if (strncmp(kex, "gss-group16-sha512-", 19) == 0) {
  ------------------
  |  Branch (972:16): [True: 0, False: 279]
  ------------------
  973|      0|        return SSH_GSS_KEX_DH_GROUP16_SHA512;
  974|    279|    } else if (strncmp(kex, "gss-nistp256-sha256-", 20) == 0) {
  ------------------
  |  Branch (974:16): [True: 0, False: 279]
  ------------------
  975|      0|        return SSH_GSS_KEX_ECDH_NISTP256_SHA256;
  976|    279|    } else if (strncmp(kex, "gss-curve25519-sha256-", 22) == 0) {
  ------------------
  |  Branch (976:16): [True: 0, False: 279]
  ------------------
  977|      0|        return SSH_GSS_KEX_CURVE25519_SHA256;
  978|    279|    } else if (strcmp(kex, "diffie-hellman-group14-sha1") == 0) {
  ------------------
  |  Branch (978:16): [True: 0, False: 279]
  ------------------
  979|      0|        return SSH_KEX_DH_GROUP14_SHA1;
  980|    279|    } else if (strcmp(kex, "diffie-hellman-group14-sha256") == 0) {
  ------------------
  |  Branch (980:16): [True: 5, False: 274]
  ------------------
  981|      5|        return SSH_KEX_DH_GROUP14_SHA256;
  982|    274|    } else if (strcmp(kex, "diffie-hellman-group16-sha512") == 0) {
  ------------------
  |  Branch (982:16): [True: 6, False: 268]
  ------------------
  983|      6|        return SSH_KEX_DH_GROUP16_SHA512;
  984|    268|    } else if (strcmp(kex, "diffie-hellman-group18-sha512") == 0) {
  ------------------
  |  Branch (984:16): [True: 17, False: 251]
  ------------------
  985|     17|        return SSH_KEX_DH_GROUP18_SHA512;
  986|     17|#ifdef WITH_GEX
  987|    251|    } else if (strcmp(kex, "diffie-hellman-group-exchange-sha1") == 0) {
  ------------------
  |  Branch (987:16): [True: 0, False: 251]
  ------------------
  988|      0|        return SSH_KEX_DH_GEX_SHA1;
  989|    251|    } else if (strcmp(kex, "diffie-hellman-group-exchange-sha256") == 0) {
  ------------------
  |  Branch (989:16): [True: 8, False: 243]
  ------------------
  990|      8|        return SSH_KEX_DH_GEX_SHA256;
  991|      8|#endif /* WITH_GEX */
  992|    243|    } else if (strcmp(kex, "ecdh-sha2-nistp256") == 0) {
  ------------------
  |  Branch (992:16): [True: 7, False: 236]
  ------------------
  993|      7|        return SSH_KEX_ECDH_SHA2_NISTP256;
  994|    236|    } else if (strcmp(kex, "ecdh-sha2-nistp384") == 0) {
  ------------------
  |  Branch (994:16): [True: 1, False: 235]
  ------------------
  995|      1|        return SSH_KEX_ECDH_SHA2_NISTP384;
  996|    235|    } else if (strcmp(kex, "ecdh-sha2-nistp521") == 0) {
  ------------------
  |  Branch (996:16): [True: 6, False: 229]
  ------------------
  997|      6|        return SSH_KEX_ECDH_SHA2_NISTP521;
  998|    229|    } else if (strcmp(kex, "curve25519-sha256@libssh.org") == 0) {
  ------------------
  |  Branch (998:16): [True: 68, False: 161]
  ------------------
  999|     68|        return SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG;
 1000|    161|    } else if (strcmp(kex, "curve25519-sha256") == 0) {
  ------------------
  |  Branch (1000:16): [True: 8, False: 153]
  ------------------
 1001|      8|        return SSH_KEX_CURVE25519_SHA256;
 1002|    153|    } else if (strcmp(kex, "sntrup761x25519-sha512@openssh.com") == 0) {
  ------------------
  |  Branch (1002:16): [True: 21, False: 132]
  ------------------
 1003|     21|        return SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM;
 1004|    132|    } else if (strcmp(kex, "sntrup761x25519-sha512") == 0) {
  ------------------
  |  Branch (1004:16): [True: 17, False: 115]
  ------------------
 1005|     17|        return SSH_KEX_SNTRUP761X25519_SHA512;
 1006|    115|    } else if (strcmp(kex, "mlkem768x25519-sha256") == 0) {
  ------------------
  |  Branch (1006:16): [True: 1, False: 114]
  ------------------
 1007|      1|        return SSH_KEX_MLKEM768X25519_SHA256;
 1008|    114|    } else if (strcmp(kex, "mlkem768nistp256-sha256") == 0) {
  ------------------
  |  Branch (1008:16): [True: 114, False: 0]
  ------------------
 1009|    114|        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|    114|    }
 1015|       |    /* should not happen. We should be getting only valid names at this stage */
 1016|      0|    return 0;
 1017|    279|}
kex.c:revert_kex_callbacks:
 1026|    184|{
 1027|    184|    switch (session->next_crypto->kex_type) {
  ------------------
  |  Branch (1027:13): [True: 0, False: 184]
  ------------------
 1028|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1028:5): [True: 0, False: 184]
  ------------------
 1029|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1029:5): [True: 0, False: 184]
  ------------------
 1030|      0|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1030:5): [True: 0, False: 184]
  ------------------
 1031|      0|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1031:5): [True: 0, False: 184]
  ------------------
 1032|      0|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1032:5): [True: 0, False: 184]
  ------------------
 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: 184]
  ------------------
 1036|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1036:5): [True: 0, False: 184]
  ------------------
 1037|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1037:5): [True: 0, False: 184]
  ------------------
 1038|      0|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1038:5): [True: 0, False: 184]
  ------------------
 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: 184]
  ------------------
 1045|      0|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1045:5): [True: 0, False: 184]
  ------------------
 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: 184]
  ------------------
 1051|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1051:5): [True: 0, False: 184]
  ------------------
 1052|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1052:5): [True: 0, False: 184]
  ------------------
 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: 184]
  ------------------
 1058|      0|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1058:5): [True: 0, False: 184]
  ------------------
 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: 184]
  ------------------
 1064|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1064:5): [True: 0, False: 184]
  ------------------
 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: 184]
  ------------------
 1069|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1069:5): [True: 0, False: 184]
  ------------------
 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|    184|    }
 1076|    184|}

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

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

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

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

ssh_is_ipaddr_v4:
  430|  1.71k|{
  431|  1.71k|    int rc = -1;
  432|  1.71k|    struct in_addr dest;
  433|       |
  434|  1.71k|    rc = inet_pton(AF_INET, str, &dest);
  435|  1.71k|    if (rc > 0) {
  ------------------
  |  Branch (435:9): [True: 1.71k, False: 0]
  ------------------
  436|  1.71k|        return 1;
  437|  1.71k|    }
  438|       |
  439|      0|    return 0;
  440|  1.71k|}
ssh_is_ipaddr:
  450|  1.71k|{
  451|  1.71k|    int rc = -1;
  452|  1.71k|    char *s = strdup(str);
  453|       |
  454|  1.71k|    if (s == NULL) {
  ------------------
  |  Branch (454:9): [True: 0, False: 1.71k]
  ------------------
  455|      0|        return -1;
  456|      0|    }
  457|  1.71k|    if (strchr(s, ':')) {
  ------------------
  |  Branch (457:9): [True: 0, False: 1.71k]
  ------------------
  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.71k|    free(s);
  478|  1.71k|    return ssh_is_ipaddr_v4(str);
  479|  1.71k|}
ssh_get_user_home_dir:
  495|  2.86k|{
  496|  2.86k|    char *szPath = NULL;
  497|       |
  498|       |    /* If used previously, reuse cached value */
  499|  2.86k|    if (session != NULL && session->opts.homedir != NULL) {
  ------------------
  |  Branch (499:9): [True: 2.28k, False: 572]
  |  Branch (499:28): [True: 1.71k, False: 572]
  ------------------
  500|  1.71k|        return strdup(session->opts.homedir);
  501|  1.71k|    }
  502|       |
  503|  1.14k|    szPath = ssh_get_user_home_dir_internal();
  504|  1.14k|    if (szPath == NULL) {
  ------------------
  |  Branch (504:9): [True: 0, False: 1.14k]
  ------------------
  505|      0|        return NULL;
  506|      0|    }
  507|       |
  508|  1.14k|    if (session != NULL) {
  ------------------
  |  Branch (508:9): [True: 572, False: 572]
  ------------------
  509|       |        /* cache it:
  510|       |         * failure is not fatal -- at worst we will just not cache it */
  511|    572|        session->opts.homedir = strdup(szPath);
  512|    572|    }
  513|       |
  514|  1.14k|    return szPath;
  515|  1.14k|}
ssh_lowercase:
  526|    501|{
  527|    501|    char *new = NULL, *p = NULL;
  528|       |
  529|    501|    if (str == NULL) {
  ------------------
  |  Branch (529:9): [True: 0, False: 501]
  ------------------
  530|      0|        return NULL;
  531|      0|    }
  532|       |
  533|    501|    new = strdup(str);
  534|    501|    if (new == NULL) {
  ------------------
  |  Branch (534:9): [True: 0, False: 501]
  ------------------
  535|      0|        return NULL;
  536|      0|    }
  537|       |
  538|  5.01k|    for (p = new; *p; p++) {
  ------------------
  |  Branch (538:19): [True: 4.50k, False: 501]
  ------------------
  539|  4.50k|        *p = tolower(*p);
  ------------------
  |  Branch (539:14): [True: 0, False: 0]
  |  Branch (539:14): [True: 0, False: 0]
  |  Branch (539:14): [Folded, False: 4.50k]
  ------------------
  540|  4.50k|    }
  541|       |
  542|    501|    return new;
  543|    501|}
ssh_list_new:
  865|  2.79k|{
  866|  2.79k|    struct ssh_list *ret = malloc(sizeof(struct ssh_list));
  867|  2.79k|    if (ret == NULL) {
  ------------------
  |  Branch (867:9): [True: 0, False: 2.79k]
  ------------------
  868|      0|        return NULL;
  869|      0|    }
  870|  2.79k|    ret->root = ret->end = NULL;
  871|  2.79k|    return ret;
  872|  2.79k|}
ssh_list_free:
  882|  3.86k|{
  883|  3.86k|    struct ssh_iterator *ptr = NULL, *next = NULL;
  884|  3.86k|    if (!list)
  ------------------
  |  Branch (884:9): [True: 1.07k, False: 2.79k]
  ------------------
  885|  1.07k|        return;
  886|  2.79k|    ptr = list->root;
  887|  3.39k|    while (ptr) {
  ------------------
  |  Branch (887:12): [True: 606, False: 2.79k]
  ------------------
  888|    606|        next = ptr->next;
  889|    606|        SAFE_FREE(ptr);
  ------------------
  |  |  375|    606|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 606, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 606]
  |  |  ------------------
  ------------------
  890|    606|        ptr = next;
  891|    606|    }
  892|       |    SAFE_FREE(list);
  ------------------
  |  |  375|  2.79k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2.79k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 2.79k]
  |  |  ------------------
  ------------------
  893|  2.79k|}
ssh_list_get_iterator:
  903|  31.3k|{
  904|  31.3k|    if (!list)
  ------------------
  |  Branch (904:9): [True: 1.87k, False: 29.4k]
  ------------------
  905|  1.87k|        return NULL;
  906|  29.4k|    return list->root;
  907|  31.3k|}
ssh_list_find:
  918|    174|{
  919|    174|    struct ssh_iterator *it = NULL;
  920|       |
  921|    348|    for (it = ssh_list_get_iterator(list); it != NULL ; it = it->next)
  ------------------
  |  Branch (921:44): [True: 348, False: 0]
  ------------------
  922|    348|        if (it->data == value)
  ------------------
  |  Branch (922:13): [True: 174, False: 174]
  ------------------
  923|    174|            return it;
  924|      0|    return NULL;
  925|    174|}
ssh_list_append:
  969|  4.21k|{
  970|  4.21k|  struct ssh_iterator *iterator = NULL;
  971|       |
  972|  4.21k|  if (list == NULL) {
  ------------------
  |  Branch (972:7): [True: 0, False: 4.21k]
  ------------------
  973|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  974|      0|  }
  975|       |
  976|  4.21k|  iterator = ssh_iterator_new(data);
  977|  4.21k|  if (iterator == NULL) {
  ------------------
  |  Branch (977:7): [True: 0, False: 4.21k]
  ------------------
  978|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  979|      0|  }
  980|       |
  981|  4.21k|  if(!list->end){
  ------------------
  |  Branch (981:6): [True: 1.64k, False: 2.56k]
  ------------------
  982|       |    /* list is empty */
  983|  1.64k|    list->root=list->end=iterator;
  984|  2.56k|  } else {
  985|       |    /* put it on end of list */
  986|  2.56k|    list->end->next=iterator;
  987|  2.56k|    list->end=iterator;
  988|  2.56k|  }
  989|  4.21k|  return SSH_OK;
  ------------------
  |  |  316|  4.21k|#define SSH_OK 0     /* No error */
  ------------------
  990|  4.21k|}
ssh_list_remove:
 1032|    174|{
 1033|    174|    struct ssh_iterator *ptr = NULL, *prev = NULL;
 1034|       |
 1035|    174|    if (list == NULL) {
  ------------------
  |  Branch (1035:9): [True: 0, False: 174]
  ------------------
 1036|      0|        return;
 1037|      0|    }
 1038|       |
 1039|    174|    prev = NULL;
 1040|    174|    ptr = list->root;
 1041|    348|    while (ptr && ptr != iterator) {
  ------------------
  |  Branch (1041:12): [True: 348, False: 0]
  |  Branch (1041:19): [True: 174, False: 174]
  ------------------
 1042|    174|        prev = ptr;
 1043|    174|        ptr = ptr->next;
 1044|    174|    }
 1045|    174|    if (!ptr) {
  ------------------
  |  Branch (1045:9): [True: 0, False: 174]
  ------------------
 1046|       |        /* we did not find the element */
 1047|      0|        return;
 1048|      0|    }
 1049|       |    /* unlink it */
 1050|    174|    if (prev)
  ------------------
  |  Branch (1050:9): [True: 174, False: 0]
  ------------------
 1051|    174|        prev->next = ptr->next;
 1052|       |    /* if iterator was the head */
 1053|    174|    if (list->root == iterator)
  ------------------
  |  Branch (1053:9): [True: 0, False: 174]
  ------------------
 1054|      0|        list->root = iterator->next;
 1055|       |    /* if iterator was the tail */
 1056|    174|    if (list->end == iterator)
  ------------------
  |  Branch (1056:9): [True: 174, False: 0]
  ------------------
 1057|    174|        list->end = prev;
 1058|       |    SAFE_FREE(iterator);
  ------------------
  |  |  375|    174|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 174, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 174]
  |  |  ------------------
  ------------------
 1059|    174|}
_ssh_list_pop_head:
 1073|  7.94k|{
 1074|  7.94k|  struct ssh_iterator *iterator = NULL;
 1075|  7.94k|  const void *data = NULL;
 1076|       |
 1077|  7.94k|  if (list == NULL) {
  ------------------
  |  Branch (1077:7): [True: 1.65k, False: 6.29k]
  ------------------
 1078|  1.65k|      return NULL;
 1079|  1.65k|  }
 1080|       |
 1081|  6.29k|  iterator = list->root;
 1082|  6.29k|  if (iterator == NULL) {
  ------------------
  |  Branch (1082:7): [True: 2.86k, False: 3.43k]
  ------------------
 1083|  2.86k|      return NULL;
 1084|  2.86k|  }
 1085|  3.43k|  data=iterator->data;
 1086|  3.43k|  list->root=iterator->next;
 1087|  3.43k|  if(list->end==iterator)
  ------------------
  |  Branch (1087:6): [True: 1.14k, False: 2.28k]
  ------------------
 1088|  1.14k|    list->end=NULL;
 1089|       |  SAFE_FREE(iterator);
  ------------------
  |  |  375|  3.43k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 3.43k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 3.43k]
  |  |  ------------------
  ------------------
 1090|  3.43k|  return data;
 1091|  6.29k|}
ssh_path_expand_tilde:
 1309|  2.86k|{
 1310|  2.86k|    char *h = NULL, *r = NULL;
 1311|  2.86k|    const char *p = NULL;
 1312|  2.86k|    size_t ld;
 1313|  2.86k|    size_t lh = 0;
 1314|  2.86k|    int add_slash = 0;
 1315|       |
 1316|  2.86k|    if (d[0] != '~') {
  ------------------
  |  Branch (1316:9): [True: 2.28k, False: 572]
  ------------------
 1317|  2.28k|        return strdup(d);
 1318|  2.28k|    }
 1319|    572|    d++;
 1320|       |
 1321|       |    /* handle ~user/path */
 1322|    572|    p = strchr(d, '/');
 1323|    572|    if (p != NULL && p > d) {
  ------------------
  |  Branch (1323:9): [True: 572, False: 0]
  |  Branch (1323:22): [True: 0, False: 572]
  ------------------
 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|    572|    } else {
 1343|    572|        p = (char *) d;
 1344|    572|        h = ssh_get_user_home_dir(NULL);
 1345|    572|    }
 1346|       |
 1347|    572|    if (h == NULL) {
  ------------------
  |  Branch (1347:9): [True: 0, False: 572]
  ------------------
 1348|      0|        return NULL;
 1349|      0|    }
 1350|    572|    lh = strlen(h);
 1351|       |
 1352|       |    /* Strip all leading slashes from the suffix path */
 1353|  1.14k|    while (*p == '/') {
  ------------------
  |  Branch (1353:12): [True: 572, False: 572]
  ------------------
 1354|    572|        p++;
 1355|    572|    }
 1356|    572|    ld = strlen(p);
 1357|       |
 1358|       |    /* Does the home directory path end with a slash? */
 1359|    572|    add_slash = (lh > 0 && h[lh - 1] == '/') ? 0 : 1;
  ------------------
  |  Branch (1359:18): [True: 572, False: 0]
  |  Branch (1359:28): [True: 0, False: 572]
  ------------------
 1360|       |
 1361|    572|    r = malloc(lh + add_slash + ld + 1);
 1362|    572|    if (r == NULL) {
  ------------------
  |  Branch (1362:9): [True: 0, False: 572]
  ------------------
 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|    572|    if (lh > 0) {
  ------------------
  |  Branch (1367:9): [True: 572, False: 0]
  ------------------
 1368|    572|        memcpy(r, h, lh);
 1369|    572|    }
 1370|    572|    SAFE_FREE(h);
  ------------------
  |  |  375|    572|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 572, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 572]
  |  |  ------------------
  ------------------
 1371|       |
 1372|    572|    if (add_slash) {
  ------------------
  |  Branch (1372:9): [True: 572, False: 0]
  ------------------
 1373|    572|        r[lh] = '/';
 1374|    572|    }
 1375|    572|    memcpy(r + lh + add_slash, p, ld + 1);
 1376|       |
 1377|    572|    return r;
 1378|    572|}
ssh_path_expand_escape:
 1715|  2.28k|{
 1716|  2.28k|    return ssh_path_expand_internal(session, s, false, true);
 1717|  2.28k|}
ssh_string_expand_escape:
 1720|    572|{
 1721|    572|    return ssh_path_expand_internal(session, s, false, false);
 1722|    572|}
ssh_analyze_banner:
 1755|    512|{
 1756|    512|    const char *banner = NULL;
 1757|    512|    const char *openssh = NULL;
 1758|    512|    const char *ios = NULL;
 1759|       |
 1760|    512|    if (server) {
  ------------------
  |  Branch (1760:9): [True: 0, False: 512]
  ------------------
 1761|      0|        banner = session->clientbanner;
 1762|    512|    } else {
 1763|    512|        banner = session->serverbanner;
 1764|    512|    }
 1765|       |
 1766|    512|    if (banner == NULL) {
  ------------------
  |  Branch (1766:9): [True: 0, False: 512]
  ------------------
 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|    512|    if (strlen(banner) < 6 ||
  ------------------
  |  Branch (1780:9): [True: 1, False: 511]
  ------------------
 1781|    511|        strncmp(banner, "SSH-", 4) != 0) {
  ------------------
  |  Branch (1781:9): [True: 0, False: 511]
  ------------------
 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|    511|    SSH_LOG(SSH_LOG_DEBUG, "Analyzing banner: %s", banner);
  ------------------
  |  |  283|    511|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1787|       |
 1788|    511|    switch (banner[4]) {
 1789|    489|        case '2':
  ------------------
  |  Branch (1789:9): [True: 489, False: 22]
  ------------------
 1790|    489|            break;
 1791|     21|        case '1':
  ------------------
  |  Branch (1791:9): [True: 21, False: 490]
  ------------------
 1792|     21|            if (strlen(banner) > 6) {
  ------------------
  |  Branch (1792:17): [True: 19, False: 2]
  ------------------
 1793|     19|                if (banner[6] == '9') {
  ------------------
  |  Branch (1793:21): [True: 12, False: 7]
  ------------------
 1794|     12|                    break;
 1795|     12|                }
 1796|     19|            }
 1797|      9|            FALL_THROUGH;
  ------------------
  |  |  496|      9|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1798|     10|        default:
  ------------------
  |  Branch (1798:9): [True: 1, False: 510]
  ------------------
 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|    511|    }
 1802|       |
 1803|       |    /* Make a best-effort to extract OpenSSH version numbers. */
 1804|    501|    openssh = strstr(banner, "OpenSSH");
 1805|    501|    if (openssh != NULL) {
  ------------------
  |  Branch (1805:9): [True: 76, False: 425]
  ------------------
 1806|     76|        char *tmp = NULL;
 1807|     76|        unsigned long int major = 0UL;
 1808|     76|        unsigned long int minor = 0UL;
 1809|     76|        int off = 0;
 1810|       |
 1811|       |        /*
 1812|       |         * The banner is typical:
 1813|       |         * OpenSSH_5.4
 1814|       |         * 012345678901234567890
 1815|       |         */
 1816|     76|        if (strlen(openssh) > 9) {
  ------------------
  |  Branch (1816:13): [True: 75, False: 1]
  ------------------
 1817|     75|            errno = 0;
 1818|     75|            major = strtoul(openssh + 8, &tmp, 10);
 1819|     75|            if ((tmp == (openssh + 8)) ||
  ------------------
  |  Branch (1819:17): [True: 2, False: 73]
  ------------------
 1820|     73|                ((errno == ERANGE) && (major == ULONG_MAX)) ||
  ------------------
  |  Branch (1820:18): [True: 1, False: 72]
  |  Branch (1820:39): [True: 1, False: 0]
  ------------------
 1821|     72|                ((errno != 0) && (major == 0)) ||
  ------------------
  |  Branch (1821:18): [True: 0, False: 72]
  |  Branch (1821:34): [True: 0, False: 0]
  ------------------
 1822|     72|                ((major < 1) || (major > 100))) {
  ------------------
  |  Branch (1822:18): [True: 1, False: 71]
  |  Branch (1822:33): [True: 41, False: 30]
  ------------------
 1823|       |                /* invalid major */
 1824|     45|                errno = 0;
 1825|     45|                goto done;
 1826|     45|            }
 1827|       |
 1828|     75|            errno = 0;
 1829|     30|            off = major >= 10 ? 11 : 10;
  ------------------
  |  Branch (1829:19): [True: 17, False: 13]
  ------------------
 1830|     30|            minor = strtoul(openssh + off, &tmp, 10);
 1831|     30|            if ((tmp == (openssh + off)) ||
  ------------------
  |  Branch (1831:17): [True: 2, False: 28]
  ------------------
 1832|     28|                ((errno == ERANGE) && (major == ULONG_MAX)) ||
  ------------------
  |  Branch (1832:18): [True: 0, False: 28]
  |  Branch (1832:39): [True: 0, False: 0]
  ------------------
 1833|     28|                ((errno != 0) && (major == 0)) ||
  ------------------
  |  Branch (1833:18): [True: 0, False: 28]
  |  Branch (1833:34): [True: 0, False: 0]
  ------------------
 1834|     28|                (minor > 100)) {
  ------------------
  |  Branch (1834:17): [True: 26, False: 2]
  ------------------
 1835|       |                /* invalid minor */
 1836|     28|                errno = 0;
 1837|     28|                goto done;
 1838|     28|            }
 1839|       |
 1840|      2|            session->openssh = SSH_VERSION_INT(((int) major), ((int) minor), 0);
  ------------------
  |  |   25|      2|#define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
  ------------------
 1841|       |
 1842|      2|            SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      4|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 0, False: 2]
  |  |  ------------------
  ------------------
 1843|      2|                    "We are talking to an OpenSSH %s version: %lu.%lu (%x)",
 1844|      2|                    server ? "client" : "server",
 1845|      2|                    major, minor, session->openssh);
 1846|      2|        }
 1847|     76|    }
 1848|       |    /* Cisco devices have odd scp implementation which breaks */
 1849|    428|    ios = strstr(banner, "Cisco");
 1850|    428|    if (ios != NULL) {
  ------------------
  |  Branch (1850:9): [True: 2, False: 426]
  ------------------
 1851|      2|        session->flags |= SSH_SESSION_FLAG_SCP_QUOTING_BROKEN;
  ------------------
  |  |   95|      2|#define SSH_SESSION_FLAG_SCP_QUOTING_BROKEN 0x0040
  ------------------
 1852|      2|    }
 1853|       |
 1854|    501|done:
 1855|    501|    return 0;
 1856|    428|}
ssh_timestamp_init:
 1871|  8.99k|{
 1872|  8.99k|#ifdef HAVE_CLOCK_GETTIME
 1873|  8.99k|  struct timespec tp;
 1874|  8.99k|  clock_gettime(CLOCK, &tp);
  ------------------
  |  | 1860|  8.99k|#define CLOCK CLOCK_MONOTONIC
  ------------------
 1875|  8.99k|  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|  8.99k|  ts->seconds = tp.tv_sec;
 1882|  8.99k|}
ssh_make_milliseconds:
 1919|    572|{
 1920|    572|    unsigned long res;
 1921|       |
 1922|    572|    if (sec == (unsigned long)SSH_TIMEOUT_INFINITE) {
  ------------------
  |  |   99|    572|#define SSH_TIMEOUT_INFINITE -1
  ------------------
  |  Branch (1922:9): [True: 0, False: 572]
  ------------------
 1923|      0|        return SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|      0|#define SSH_TIMEOUT_INFINITE -1
  ------------------
 1924|      0|    }
 1925|    572|    if (sec > (unsigned long)INT_MAX / 1000) {
  ------------------
  |  Branch (1925:9): [True: 0, False: 572]
  ------------------
 1926|      0|        return INT_MAX;
 1927|      0|    }
 1928|       |
 1929|    572|    res = usec / 1000;
 1930|    572|    res += (sec * 1000);
 1931|    572|    if (res == 0) {
  ------------------
  |  Branch (1931:9): [True: 0, False: 572]
  ------------------
 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|    572|    if (res > INT_MAX) {
  ------------------
  |  Branch (1936:9): [True: 0, False: 572]
  ------------------
 1937|      0|        return INT_MAX;
 1938|    572|    } else {
 1939|    572|        return (int)res;
 1940|    572|    }
 1941|    572|}
ssh_timeout_elapsed:
 1954|  2.00k|{
 1955|  2.00k|    struct ssh_timestamp now;
 1956|       |
 1957|  2.00k|    switch(timeout) {
 1958|      0|        case -2: /*
  ------------------
  |  Branch (1958:9): [True: 0, False: 2.00k]
  ------------------
 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: 2.00k]
  ------------------
 1967|      0|            return 0;
 1968|      0|        case 0: /* 0 means no timeout */
  ------------------
  |  Branch (1968:9): [True: 0, False: 2.00k]
  ------------------
 1969|      0|            return 1;
 1970|  2.00k|        default:
  ------------------
  |  Branch (1970:9): [True: 2.00k, False: 0]
  ------------------
 1971|  2.00k|            break;
 1972|  2.00k|    }
 1973|       |
 1974|  2.00k|    ssh_timestamp_init(&now);
 1975|       |
 1976|  2.00k|    return (ssh_timestamp_difference(ts,&now) >= timeout);
 1977|  2.00k|}
ssh_timeout_update:
 1987|  4.21k|{
 1988|  4.21k|  struct ssh_timestamp now;
 1989|  4.21k|  int ms, ret;
 1990|  4.21k|  if (timeout <= 0) {
  ------------------
  |  Branch (1990:7): [True: 0, False: 4.21k]
  ------------------
 1991|      0|      return timeout;
 1992|      0|  }
 1993|  4.21k|  ssh_timestamp_init(&now);
 1994|  4.21k|  ms = ssh_timestamp_difference(ts,&now);
 1995|  4.21k|  if(ms < 0)
  ------------------
  |  Branch (1995:6): [True: 0, False: 4.21k]
  ------------------
 1996|      0|    ms = 0;
 1997|  4.21k|  ret = timeout - ms;
 1998|  4.21k|  return ret >= 0 ? ret: 0;
  ------------------
  |  Branch (1998:10): [True: 4.21k, False: 0]
  ------------------
 1999|  4.21k|}
ssh_strerror:
 2417|  2.00k|{
 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|  2.00k|    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|  2.00k|    rv = strerror_r(err_num, buf, buflen);
 2429|  2.00k|#endif /* _WIN32 */
 2430|       |
 2431|       |    /* make sure the buffer is initialized and terminated with NULL */
 2432|  2.00k|    if (-rv == ERANGE) {
  ------------------
  |  Branch (2432:9): [True: 0, False: 2.00k]
  ------------------
 2433|      0|        buf[0] = '\0';
 2434|      0|    }
 2435|  2.00k|    return buf;
 2436|  2.00k|#endif /* ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE) */
 2437|  2.00k|}
ssh_check_username_syntax:
 2627|    572|{
 2628|    572|    size_t username_len;
 2629|       |
 2630|    572|    if (username == NULL || *username == '-') {
  ------------------
  |  Branch (2630:9): [True: 0, False: 572]
  |  Branch (2630:29): [True: 0, False: 572]
  ------------------
 2631|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2632|      0|    }
 2633|       |
 2634|    572|    username_len = strlen(username);
 2635|    572|    if (username_len == 0 || username[username_len - 1] == '\\' ||
  ------------------
  |  Branch (2635:9): [True: 0, False: 572]
  |  Branch (2635:30): [True: 0, False: 572]
  ------------------
 2636|    572|        strpbrk(username, SSH_DANGEROUS_SHELL_CHARS) != NULL) {
  ------------------
  |  |  260|    572|#define SSH_DANGEROUS_SHELL_CHARS "'`\";&<>|(){}$\\,"
  ------------------
  |  Branch (2636:9): [True: 0, False: 572]
  ------------------
 2637|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2638|      0|    }
 2639|  3.43k|    for (size_t i = 0; i < username_len; i++) {
  ------------------
  |  Branch (2639:24): [True: 2.86k, False: 572]
  ------------------
 2640|  2.86k|        unsigned char c = (unsigned char)username[i];
 2641|  2.86k|        if (iscntrl(c) != 0 || (isspace(c) != 0 && username[i + 1] == '-')) {
  ------------------
  |  Branch (2641:13): [True: 0, False: 2.86k]
  |  Branch (2641:33): [True: 0, False: 2.86k]
  |  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.86k|    }
 2645|       |
 2646|    572|    return SSH_OK;
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
 2647|    572|}
ssh_proxyjumps_free:
 2659|    826|{
 2660|    826|    struct ssh_jump_info_struct *jump = NULL;
 2661|       |
 2662|    826|    for (jump =
 2663|    826|             ssh_list_pop_head(struct ssh_jump_info_struct *, proxy_jump_list);
  ------------------
  |  |  128|    826|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2664|    826|         jump != NULL;
  ------------------
  |  Branch (2664:10): [True: 0, False: 826]
  ------------------
 2665|    826|         jump = ssh_list_pop_head(struct ssh_jump_info_struct *,
  ------------------
  |  |  128|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2666|    826|                                  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|    826|}
ssh_strict_fopen:
 2705|  1.00k|{
 2706|  1.00k|    FILE *f = NULL;
 2707|  1.00k|    struct stat sb;
 2708|  1.00k|    int r, fd;
 2709|       |
 2710|       |    /* open first to avoid TOCTOU */
 2711|  1.00k|    fd = open(filename, O_RDONLY);
 2712|  1.00k|    if (fd == -1) {
  ------------------
  |  Branch (2712:9): [True: 1.00k, False: 0]
  ------------------
 2713|  1.00k|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  285|  1.00k|    do {                                                            \
  |  |  286|  1.00k|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  287|  1.00k|        _ssh_log(priority,                                          \
  |  |  288|  1.00k|                 __func__,                                          \
  |  |  289|  1.00k|                 __VA_ARGS__,                                       \
  |  |  290|  1.00k|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  522|  1.00k|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  291|  1.00k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (291:14): [Folded, False: 1.00k]
  |  |  ------------------
  ------------------
 2714|  1.00k|                         errno,
 2715|  1.00k|                         "Failed to open a file %s for reading: %s",
 2716|  1.00k|                         filename);
 2717|  1.00k|        return NULL;
 2718|  1.00k|    }
 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|  2.28k|{
 2772|  2.28k|    size_t len = strlen(src);
 2773|       |
 2774|  2.28k|    if (size != 0) {
  ------------------
  |  Branch (2774:9): [True: 2.28k, False: 0]
  ------------------
 2775|  2.28k|        size_t copy_len = (len >= size) ? size - 1 : len;
  ------------------
  |  Branch (2775:27): [True: 0, False: 2.28k]
  ------------------
 2776|       |
 2777|  2.28k|        memcpy(dst, src, copy_len);
 2778|  2.28k|        dst[copy_len] = '\0';
 2779|  2.28k|    }
 2780|       |
 2781|  2.28k|    return len;
 2782|  2.28k|}
ssh_normalize_loose_ip:
 2819|  1.14k|{
 2820|  1.14k|    struct in_addr addr;
 2821|  1.14k|    char buf[INET_ADDRSTRLEN];
 2822|  1.14k|    const char *p = NULL;
 2823|  1.14k|    int rc;
 2824|  1.14k|    int is_ip;
 2825|       |#ifdef _WIN32
 2826|       |    unsigned long ip;
 2827|       |    int is_broadcast;
 2828|       |#endif
 2829|       |
 2830|  1.14k|    if (host == NULL || result == NULL) {
  ------------------
  |  Branch (2830:9): [True: 0, False: 1.14k]
  |  Branch (2830:25): [True: 0, False: 1.14k]
  ------------------
 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|  1.14k|    is_ip = ssh_is_ipaddr(host);
 2837|  1.14k|    if (is_ip) {
  ------------------
  |  Branch (2837:9): [True: 1.14k, False: 0]
  ------------------
 2838|  1.14k|        return 1; /* not a loose IP — already a strict address */
 2839|  1.14k|    }
 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|  1.14k|{
  330|  1.14k|    char *szPath = NULL;
  331|  1.14k|    struct passwd pwd;
  332|  1.14k|    struct passwd *pwdbuf = NULL;
  333|  1.14k|    char buf[NSS_BUFLEN_PASSWD] = {0};
  334|  1.14k|    int rc;
  335|       |
  336|  1.14k|    rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
  337|  1.14k|    if (rc != 0 || pwdbuf == NULL ) {
  ------------------
  |  Branch (337:9): [True: 0, False: 1.14k]
  |  Branch (337:20): [True: 0, False: 1.14k]
  ------------------
  338|      0|        szPath = getenv("HOME");
  339|      0|        if (szPath == NULL) {
  ------------------
  |  Branch (339:13): [True: 0, False: 0]
  ------------------
  340|      0|            return NULL;
  341|      0|        }
  342|      0|        snprintf(buf, sizeof(buf), "%s", szPath);
  343|      0|        return strdup(buf);
  344|      0|    }
  345|       |
  346|  1.14k|    szPath = strdup(pwd.pw_dir);
  347|       |
  348|  1.14k|    return szPath;
  349|  1.14k|}
misc.c:ssh_iterator_new:
  947|  4.21k|{
  948|  4.21k|    struct ssh_iterator *iterator = malloc(sizeof(struct ssh_iterator));
  949|       |
  950|  4.21k|    if (iterator == NULL) {
  ------------------
  |  Branch (950:9): [True: 0, False: 4.21k]
  ------------------
  951|      0|        return NULL;
  952|      0|    }
  953|  4.21k|    iterator->next = NULL;
  954|  4.21k|    iterator->data = data;
  955|  4.21k|    return iterator;
  956|  4.21k|}
misc.c:ssh_path_expand_internal:
 1492|  2.86k|{
 1493|  2.86k|    char *buf = NULL;
 1494|  2.86k|    char *r = NULL;
 1495|  2.86k|    char *x = NULL;
 1496|  2.86k|    const char *p = NULL;
 1497|  2.86k|    size_t i, l;
 1498|       |
 1499|  2.86k|    if (expand_tilde) {
  ------------------
  |  Branch (1499:9): [True: 2.28k, False: 572]
  ------------------
 1500|  2.28k|        r = ssh_path_expand_tilde(s);
 1501|  2.28k|    } else {
 1502|    572|        r = strdup(s);
 1503|    572|    }
 1504|  2.86k|    if (r == NULL) {
  ------------------
  |  Branch (1504:9): [True: 0, False: 2.86k]
  ------------------
 1505|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1506|      0|        return NULL;
 1507|      0|    }
 1508|       |
 1509|  2.86k|    if (strlen(r) > MAX_BUF_SIZE) {
  ------------------
  |  |  230|  2.86k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1509:9): [True: 0, False: 2.86k]
  ------------------
 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.86k|    buf = malloc(MAX_BUF_SIZE);
  ------------------
  |  |  230|  2.86k|#define MAX_BUF_SIZE 4096
  ------------------
 1516|  2.86k|    if (buf == NULL) {
  ------------------
  |  Branch (1516:9): [True: 0, False: 2.86k]
  ------------------
 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.86k|    p = r;
 1523|  2.86k|    buf[0] = '\0';
 1524|       |
 1525|  41.7k|    for (i = 0; *p != '\0'; p++) {
  ------------------
  |  Branch (1525:17): [True: 38.8k, False: 2.86k]
  ------------------
 1526|  38.8k|        if (*p != '%') {
  ------------------
  |  Branch (1526:13): [True: 36.6k, False: 2.28k]
  ------------------
 1527|  36.6k|            buf[i] = *p;
 1528|  36.6k|            i++;
 1529|  36.6k|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|  36.6k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1529:17): [True: 0, False: 36.6k]
  ------------------
 1530|      0|                free(buf);
 1531|      0|                free(r);
 1532|      0|                return NULL;
 1533|      0|            }
 1534|  36.6k|            buf[i] = '\0';
 1535|  36.6k|            continue;
 1536|  36.6k|        }
 1537|       |
 1538|  2.28k|        p++;
 1539|  2.28k|        if (*p == '\0') {
  ------------------
  |  Branch (1539:13): [True: 0, False: 2.28k]
  ------------------
 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|  2.28k|        if (hostname_lenient && *p != '%' && *p != 'h') {
  ------------------
  |  Branch (1553:13): [True: 0, False: 2.28k]
  |  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|  2.28k|        switch (*p) {
 1575|      0|        case '%':
  ------------------
  |  Branch (1575:9): [True: 0, False: 2.28k]
  ------------------
 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|  2.28k|        case 'd':
  ------------------
  |  Branch (1585:9): [True: 2.28k, False: 0]
  ------------------
 1586|  2.28k|            x = ssh_get_user_home_dir(session);
 1587|  2.28k|            if (x == NULL) {
  ------------------
  |  Branch (1587:17): [True: 0, False: 2.28k]
  ------------------
 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|  2.28k|            break;
 1594|  2.28k|        case 'u':
  ------------------
  |  Branch (1594:9): [True: 0, False: 2.28k]
  ------------------
 1595|      0|            x = ssh_get_local_username();
 1596|      0|            break;
 1597|      0|        case 'l':
  ------------------
  |  Branch (1597:9): [True: 0, False: 2.28k]
  ------------------
 1598|      0|            x = ssh_get_local_hostname();
 1599|      0|            break;
 1600|      0|        case 'h':
  ------------------
  |  Branch (1600:9): [True: 0, False: 2.28k]
  ------------------
 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: 2.28k]
  ------------------
 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: 2.28k]
  ------------------
 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: 2.28k]
  ------------------
 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: 2.28k]
  ------------------
 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: 2.28k]
  ------------------
 1651|      0|            x = get_connection_hash(session);
 1652|      0|            break;
 1653|      0|        default:
  ------------------
  |  Branch (1653:9): [True: 0, False: 2.28k]
  ------------------
 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|  2.28k|        }
 1659|       |
 1660|  2.28k|        if (x == NULL) {
  ------------------
  |  Branch (1660:13): [True: 0, False: 2.28k]
  ------------------
 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|  2.28k|        i += strlen(x);
 1668|  2.28k|        if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|  2.28k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1668:13): [True: 0, False: 2.28k]
  ------------------
 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|  2.28k|        l = strlen(buf);
 1676|  2.28k|        strlcpy(buf + l, x, MAX_BUF_SIZE - l);
  ------------------
  |  |  230|  2.28k|#define MAX_BUF_SIZE 4096
  ------------------
 1677|  2.28k|        buf[i] = '\0';
 1678|  2.28k|        SAFE_FREE(x);
  ------------------
  |  |  375|  2.28k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2.28k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 2.28k]
  |  |  ------------------
  ------------------
 1679|  2.28k|    }
 1680|       |
 1681|  2.86k|    free(r);
 1682|       |
 1683|       |    /* strip the unused space by realloc */
 1684|  2.86k|    x = realloc(buf, strlen(buf) + 1);
 1685|  2.86k|    if (x == NULL) {
  ------------------
  |  Branch (1685:9): [True: 0, False: 2.86k]
  ------------------
 1686|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1687|      0|        free(buf);
 1688|      0|    }
 1689|  2.86k|    return x;
 1690|  2.86k|}
misc.c:ssh_timestamp_difference:
 1896|  6.21k|{
 1897|  6.21k|    long seconds, usecs, msecs;
 1898|  6.21k|    seconds = new->seconds - old->seconds;
 1899|  6.21k|    usecs = new->useconds - old->useconds;
 1900|  6.21k|    if (usecs < 0){
  ------------------
  |  Branch (1900:9): [True: 56, False: 6.16k]
  ------------------
 1901|     56|        seconds--;
 1902|     56|        usecs += 1000000;
 1903|     56|    }
 1904|  6.21k|    msecs = seconds * 1000 + usecs/1000;
 1905|  6.21k|    return msecs;
 1906|  6.21k|}

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

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

ssh_options_set_algo:
  468|  2.28k|{
  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|  2.28k|    char *p = (char *)list;
  473|       |
  474|  2.28k|    if (algo < SSH_COMP_C_S) {
  ------------------
  |  Branch (474:9): [True: 2.28k, False: 0]
  ------------------
  475|  2.28k|        if (list[0] == '+') {
  ------------------
  |  Branch (475:13): [True: 0, False: 2.28k]
  ------------------
  476|      0|            p = ssh_add_to_default_algos(algo, list+1);
  477|  2.28k|        } else if (list[0] == '-') {
  ------------------
  |  Branch (477:20): [True: 0, False: 2.28k]
  ------------------
  478|      0|            p = ssh_remove_from_default_algos(algo, list+1);
  479|  2.28k|        } else if (list[0] == '^') {
  ------------------
  |  Branch (479:20): [True: 0, False: 2.28k]
  ------------------
  480|      0|            p = ssh_prefix_default_algos(algo, list+1);
  481|      0|        }
  482|  2.28k|    }
  483|       |
  484|  2.28k|    if (p == list) {
  ------------------
  |  Branch (484:9): [True: 2.28k, False: 0]
  ------------------
  485|  2.28k|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|  2.28k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 2.28k]
  |  |  ------------------
  ------------------
  486|      0|            p = ssh_keep_fips_algos(algo, list);
  487|  2.28k|        } else {
  488|  2.28k|            p = ssh_keep_known_algos(algo, list);
  489|  2.28k|        }
  490|  2.28k|    }
  491|       |
  492|  2.28k|    if (p == NULL) {
  ------------------
  |  Branch (492:9): [True: 0, False: 2.28k]
  ------------------
  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|  2.28k|    SAFE_FREE(*place);
  ------------------
  |  |  375|  2.28k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 2.28k]
  |  |  |  Branch (375:71): [Folded, False: 2.28k]
  |  |  ------------------
  ------------------
  500|  2.28k|    *place = p;
  501|       |
  502|  2.28k|    return 0;
  503|  2.28k|}
ssh_options_set:
 1219|  5.72k|{
 1220|  5.72k|    const char *v = NULL;
 1221|  5.72k|    char *p = NULL, *q = NULL;
 1222|  5.72k|    long int i;
 1223|  5.72k|    unsigned int u;
 1224|  5.72k|    int rc;
 1225|  5.72k|    char **wanted_methods = session->opts.wanted_methods;
 1226|  5.72k|    struct ssh_jump_callbacks_struct *j = NULL;
 1227|  5.72k|    enum ssh_config_opcode_e opcode;
 1228|       |
 1229|  5.72k|    if (session == NULL) {
  ------------------
  |  Branch (1229:9): [True: 0, False: 5.72k]
  ------------------
 1230|      0|        return -1;
 1231|      0|    }
 1232|       |
 1233|  5.72k|    switch (type) {
 1234|    572|        case SSH_OPTIONS_HOST:
  ------------------
  |  Branch (1234:9): [True: 572, False: 5.14k]
  ------------------
 1235|    572|            v = value;
 1236|    572|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1236:17): [True: 0, False: 572]
  |  Branch (1236:30): [True: 0, False: 572]
  ------------------
 1237|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1238|      0|                return -1;
 1239|    572|            } else if (session->opts.config_hostname_only) {
  ------------------
  |  Branch (1239:24): [True: 0, False: 572]
  ------------------
 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|    572|            } else {
 1248|    572|                char *username = NULL, *hostname = NULL;
 1249|    572|                char *strict_hostname = NULL;
 1250|    572|                char *normalized = NULL;
 1251|       |
 1252|       |                /* Non-strict parse: reject shell metacharacters */
 1253|    572|                rc = ssh_config_parse_uri(value,
 1254|    572|                                          &username,
 1255|    572|                                          &hostname,
 1256|    572|                                          NULL,
 1257|    572|                                          true,
 1258|    572|                                          false);
 1259|    572|                if (rc != SSH_OK || hostname == NULL) {
  ------------------
  |  |  316|  1.14k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1259:21): [True: 0, False: 572]
  |  Branch (1259:37): [True: 0, False: 572]
  ------------------
 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|    572|                if (username != NULL) {
  ------------------
  |  Branch (1267:21): [True: 0, False: 572]
  ------------------
 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|    572|                SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  375|    572|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 572]
  |  |  |  Branch (375:71): [Folded, False: 572]
  |  |  ------------------
  ------------------
 1272|    572|                SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  375|    572|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 572]
  |  |  |  Branch (375:71): [Folded, False: 572]
  |  |  ------------------
  ------------------
 1273|    572|                session->opts.originalhost = hostname;
 1274|       |
 1275|       |                /* Strict parse: set host only if valid hostname or IP */
 1276|    572|                rc = ssh_normalize_loose_ip(value, &normalized);
 1277|    572|                if (rc == -1) {
  ------------------
  |  Branch (1277:21): [True: 0, False: 572]
  ------------------
 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|    572|                rc = ssh_config_parse_uri(
 1284|    572|                    (normalized != NULL) ? normalized : value,
  ------------------
  |  Branch (1284:21): [True: 0, False: 572]
  ------------------
 1285|    572|                    NULL,
 1286|    572|                    &strict_hostname,
 1287|    572|                    NULL,
 1288|    572|                    true,
 1289|    572|                    true);
 1290|    572|                SAFE_FREE(normalized);
  ------------------
  |  |  375|    572|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 572]
  |  |  |  Branch (375:71): [Folded, False: 572]
  |  |  ------------------
  ------------------
 1291|       |
 1292|    572|                if (rc != SSH_OK || strict_hostname == NULL) {
  ------------------
  |  |  316|  1.14k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1292:21): [True: 0, False: 572]
  |  Branch (1292:37): [True: 0, False: 572]
  ------------------
 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|    572|                } else {
 1296|    572|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  375|    572|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 572]
  |  |  |  Branch (375:71): [Folded, False: 572]
  |  |  ------------------
  ------------------
 1297|    572|                    session->opts.host = strict_hostname;
 1298|    572|                }
 1299|    572|            }
 1300|    572|            break;
 1301|    572|        case SSH_OPTIONS_PORT:
  ------------------
  |  Branch (1301:9): [True: 0, False: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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|    572|        case SSH_OPTIONS_FD:
  ------------------
  |  Branch (1341:9): [True: 572, False: 5.14k]
  ------------------
 1342|    572|            if (value == NULL) {
  ------------------
  |  Branch (1342:17): [True: 0, False: 572]
  ------------------
 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|    572|            } else {
 1347|    572|                socket_t *x = (socket_t *) value;
 1348|    572|                if (*x < 0) {
  ------------------
  |  Branch (1348:21): [True: 0, False: 572]
  ------------------
 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|    572|                session->opts.fd = *x & 0xffff;
 1355|    572|            }
 1356|    572|            break;
 1357|    572|        case SSH_OPTIONS_BINDADDR:
  ------------------
  |  Branch (1357:9): [True: 0, False: 5.72k]
  ------------------
 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|    572|        case SSH_OPTIONS_USER:
  ------------------
  |  Branch (1371:9): [True: 572, False: 5.14k]
  ------------------
 1372|    572|            v = value;
 1373|    572|            SAFE_FREE(session->opts.username);
  ------------------
  |  |  375|    572|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 572]
  |  |  |  Branch (375:71): [Folded, False: 572]
  |  |  ------------------
  ------------------
 1374|    572|            if (v == NULL) {
  ------------------
  |  Branch (1374:17): [True: 0, False: 572]
  ------------------
 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|    572|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1381:24): [True: 0, False: 572]
  ------------------
 1382|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1383|      0|                return -1;
 1384|    572|            } else { /* username provided */
 1385|    572|                session->opts.username = strdup(value);
 1386|    572|                if (session->opts.username == NULL) {
  ------------------
  |  Branch (1386:21): [True: 0, False: 572]
  ------------------
 1387|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1388|      0|                    return -1;
 1389|      0|                }
 1390|    572|                rc = ssh_check_username_syntax(session->opts.username);
 1391|    572|                if (rc != SSH_OK) {
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1391:21): [True: 0, False: 572]
  ------------------
 1392|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1393|      0|                    return -1;
 1394|      0|                }
 1395|    572|            }
 1396|    572|            break;
 1397|    572|        case SSH_OPTIONS_SSH_DIR:
  ------------------
  |  Branch (1397:9): [True: 572, False: 5.14k]
  ------------------
 1398|    572|            v = value;
 1399|    572|            SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  375|    572|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 572]
  |  |  |  Branch (375:71): [Folded, False: 572]
  |  |  ------------------
  ------------------
 1400|    572|            if (v == NULL) {
  ------------------
  |  Branch (1400:17): [True: 572, False: 0]
  ------------------
 1401|    572|                session->opts.sshdir = ssh_path_expand_tilde("~/.ssh");
 1402|    572|                if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (1402:21): [True: 0, False: 572]
  ------------------
 1403|      0|                    return -1;
 1404|      0|                }
 1405|    572|            } 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|    572|            break;
 1416|    572|        case SSH_OPTIONS_IDENTITY:
  ------------------
  |  Branch (1416:9): [True: 0, False: 5.72k]
  ------------------
 1417|      0|        case SSH_OPTIONS_ADD_IDENTITY: {
  ------------------
  |  Branch (1417:9): [True: 0, False: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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|    572|        case SSH_OPTIONS_TIMEOUT:
  ------------------
  |  Branch (1525:9): [True: 572, False: 5.14k]
  ------------------
 1526|    572|            if (value == NULL) {
  ------------------
  |  Branch (1526:17): [True: 0, False: 572]
  ------------------
 1527|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1528|      0|                return -1;
 1529|    572|            } else {
 1530|    572|                long *x = (long *) value;
 1531|    572|                if (*x < 0) {
  ------------------
  |  Branch (1531:21): [True: 0, False: 572]
  ------------------
 1532|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1533|      0|                    return -1;
 1534|      0|                }
 1535|       |
 1536|    572|                session->opts.timeout = *x & 0xffffffffU;
 1537|    572|            }
 1538|    572|            break;
 1539|    572|        case SSH_OPTIONS_TIMEOUT_USEC:
  ------------------
  |  Branch (1539:9): [True: 0, False: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 1554|      0|            break;
 1555|      0|        case SSH_OPTIONS_SSH2:
  ------------------
  |  Branch (1555:9): [True: 0, False: 5.72k]
  ------------------
 1556|      0|            break;
 1557|      0|        case SSH_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (1557:9): [True: 0, False: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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|    572|        case SSH_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (1600:9): [True: 572, False: 5.14k]
  ------------------
 1601|    572|            v = value;
 1602|    572|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1602:17): [True: 0, False: 572]
  |  Branch (1602:30): [True: 0, False: 572]
  ------------------
 1603|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1604|      0|                return -1;
 1605|    572|            } else {
 1606|    572|                rc = ssh_options_set_algo(session,
 1607|    572|                                          SSH_CRYPT_C_S,
 1608|    572|                                          v,
 1609|    572|                                          &wanted_methods[SSH_CRYPT_C_S]);
 1610|    572|                if (rc < 0)
  ------------------
  |  Branch (1610:21): [True: 0, False: 572]
  ------------------
 1611|      0|                    return -1;
 1612|    572|            }
 1613|    572|            break;
 1614|    572|        case SSH_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (1614:9): [True: 572, False: 5.14k]
  ------------------
 1615|    572|            v = value;
 1616|    572|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1616:17): [True: 0, False: 572]
  |  Branch (1616:30): [True: 0, False: 572]
  ------------------
 1617|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1618|      0|                return -1;
 1619|    572|            } else {
 1620|    572|                rc = ssh_options_set_algo(session,
 1621|    572|                                          SSH_CRYPT_S_C,
 1622|    572|                                          v,
 1623|    572|                                          &wanted_methods[SSH_CRYPT_S_C]);
 1624|    572|                if (rc < 0)
  ------------------
  |  Branch (1624:21): [True: 0, False: 572]
  ------------------
 1625|      0|                    return -1;
 1626|    572|            }
 1627|    572|            break;
 1628|    572|        case SSH_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (1628:9): [True: 0, False: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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|    572|        case SSH_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (1670:9): [True: 572, False: 5.14k]
  ------------------
 1671|    572|            v = value;
 1672|    572|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1672:17): [True: 0, False: 572]
  |  Branch (1672:30): [True: 0, False: 572]
  ------------------
 1673|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1674|      0|                return -1;
 1675|    572|            } else {
 1676|    572|                rc = ssh_options_set_algo(session,
 1677|    572|                                          SSH_MAC_C_S,
 1678|    572|                                          v,
 1679|    572|                                          &wanted_methods[SSH_MAC_C_S]);
 1680|    572|                if (rc < 0)
  ------------------
  |  Branch (1680:21): [True: 0, False: 572]
  ------------------
 1681|      0|                    return -1;
 1682|    572|            }
 1683|    572|            break;
 1684|    572|         case SSH_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (1684:10): [True: 572, False: 5.14k]
  ------------------
 1685|    572|            v = value;
 1686|    572|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1686:17): [True: 0, False: 572]
  |  Branch (1686:30): [True: 0, False: 572]
  ------------------
 1687|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1688|      0|                return -1;
 1689|    572|            } else {
 1690|    572|                rc = ssh_options_set_algo(session,
 1691|    572|                                          SSH_MAC_S_C,
 1692|    572|                                          v,
 1693|    572|                                          &wanted_methods[SSH_MAC_S_C]);
 1694|    572|                if (rc < 0)
  ------------------
  |  Branch (1694:21): [True: 0, False: 572]
  ------------------
 1695|      0|                    return -1;
 1696|    572|            }
 1697|    572|            break;
 1698|    572|        case SSH_OPTIONS_COMPRESSION_C_S:
  ------------------
  |  Branch (1698:9): [True: 0, False: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 1911|      0|        case SSH_OPTIONS_PUBKEY_AUTH:
  ------------------
  |  Branch (1911:9): [True: 0, False: 5.72k]
  ------------------
 1912|      0|        case SSH_OPTIONS_KBDINT_AUTH:
  ------------------
  |  Branch (1912:9): [True: 0, False: 5.72k]
  ------------------
 1913|      0|        case SSH_OPTIONS_GSSAPI_AUTH:
  ------------------
  |  Branch (1913:9): [True: 0, False: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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|    572|        case SSH_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (1964:9): [True: 572, False: 5.14k]
  ------------------
 1965|    572|            if (value == NULL) {
  ------------------
  |  Branch (1965:17): [True: 0, False: 572]
  ------------------
 1966|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  324|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1967|      0|                return -1;
 1968|    572|            } else {
 1969|    572|                bool *x = (bool *)value;
 1970|    572|                session->opts.config_processed = !(*x);
 1971|    572|            }
 1972|    572|            break;
 1973|    572|        case SSH_OPTIONS_REKEY_DATA:
  ------------------
  |  Branch (1973:9): [True: 0, False: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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: 5.72k]
  ------------------
 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|  5.72k|    }
 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|  5.72k|    opcode = ssh_opt_type_to_opcode(type);
 2359|  5.72k|    if (opcode != SOC_UNKNOWN) {
  ------------------
  |  Branch (2359:9): [True: 3.43k, False: 2.28k]
  ------------------
 2360|  3.43k|        session->opts.options_seen[opcode] = 1;
 2361|  3.43k|    }
 2362|       |
 2363|  5.72k|    return 0;
 2364|  5.72k|}
ssh_options_apply:
 3212|    572|{
 3213|    572|    char *tmp = NULL;
 3214|    572|    int rc;
 3215|       |
 3216|    572|    if (session->opts.host != NULL) {
  ------------------
  |  Branch (3216:9): [True: 572, False: 0]
  ------------------
 3217|    572|        char *normalized_host = NULL;
 3218|    572|        rc = ssh_normalize_loose_ip(session->opts.host, &normalized_host);
 3219|    572|        if (rc == -1) {
  ------------------
  |  Branch (3219:13): [True: 0, False: 572]
  ------------------
 3220|       |            /* Error (e.g. NULL input or OOM) — leave host as it is */
 3221|    572|        } else if (rc == 0) {
  ------------------
  |  Branch (3221:20): [True: 0, False: 572]
  ------------------
 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|    572|        } else {
 3226|       |            /* rc == 1: not a loose IP — lowercase if it's not a strict IP */
 3227|    572|            bool requires_lowercase = ssh_host_requires_lowercase(session->opts.host);
 3228|    572|            if (requires_lowercase) {
  ------------------
  |  Branch (3228:17): [True: 0, False: 572]
  ------------------
 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|    572|        }
 3236|    572|    }
 3237|       |
 3238|    572|    if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (3238:9): [True: 572, False: 0]
  ------------------
 3239|    572|        rc = ssh_options_set(session, SSH_OPTIONS_SSH_DIR, NULL);
 3240|    572|        if (rc < 0) {
  ------------------
  |  Branch (3240:13): [True: 0, False: 572]
  ------------------
 3241|      0|            return -1;
 3242|      0|        }
 3243|    572|    }
 3244|       |
 3245|    572|    if (session->opts.username == NULL) {
  ------------------
  |  Branch (3245:9): [True: 0, False: 572]
  ------------------
 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|    572|    if (session->opts.config_hostname != NULL) {
  ------------------
  |  Branch (3252:9): [True: 0, False: 572]
  ------------------
 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|    572|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_USERNAME) == 0 &&
  ------------------
  |  |  120|    572|#define SSH_OPT_EXP_FLAG_USERNAME 0x20
  ------------------
  |  Branch (3295:9): [True: 572, False: 0]
  ------------------
 3296|    572|        session->opts.username != NULL) {
  ------------------
  |  Branch (3296:9): [True: 572, False: 0]
  ------------------
 3297|    572|        tmp = ssh_string_expand_escape(session, session->opts.username);
 3298|    572|        if (tmp != NULL) {
  ------------------
  |  Branch (3298:13): [True: 572, False: 0]
  ------------------
 3299|    572|            free(session->opts.username);
 3300|    572|            session->opts.username = tmp;
 3301|    572|            tmp = NULL;
 3302|    572|        }
 3303|       |        /* On failure, keep the raw string — best-effort expansion */
 3304|    572|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_USERNAME;
  ------------------
  |  |  120|    572|#define SSH_OPT_EXP_FLAG_USERNAME 0x20
  ------------------
 3305|    572|    }
 3306|       |
 3307|    572|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_KNOWNHOSTS) == 0) {
  ------------------
  |  |  115|    572|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
  |  Branch (3307:9): [True: 572, False: 0]
  ------------------
 3308|    572|        if (session->opts.knownhosts == NULL) {
  ------------------
  |  Branch (3308:13): [True: 572, False: 0]
  ------------------
 3309|    572|            tmp = ssh_path_expand_escape(session, "%d/.ssh/known_hosts");
 3310|    572|        } else {
 3311|      0|            tmp = ssh_path_expand_escape(session, session->opts.knownhosts);
 3312|      0|        }
 3313|    572|        if (tmp == NULL) {
  ------------------
  |  Branch (3313:13): [True: 0, False: 572]
  ------------------
 3314|      0|            return -1;
 3315|      0|        }
 3316|    572|        free(session->opts.knownhosts);
 3317|    572|        session->opts.knownhosts = tmp;
 3318|    572|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_KNOWNHOSTS;
  ------------------
  |  |  115|    572|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
 3319|    572|    }
 3320|       |
 3321|    572|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS) == 0) {
  ------------------
  |  |  116|    572|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
  |  Branch (3321:9): [True: 572, False: 0]
  ------------------
 3322|    572|        if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (3322:13): [True: 572, False: 0]
  ------------------
 3323|    572|            tmp = strdup(GLOBAL_CONF_DIR "/ssh_known_hosts");
  ------------------
  |  |   13|    572|#define GLOBAL_CONF_DIR "/etc/ssh"
  ------------------
 3324|    572|        } else {
 3325|      0|            tmp = ssh_path_expand_escape(session,
 3326|      0|                                         session->opts.global_knownhosts);
 3327|      0|        }
 3328|    572|        if (tmp == NULL) {
  ------------------
  |  Branch (3328:13): [True: 0, False: 572]
  ------------------
 3329|      0|            return -1;
 3330|      0|        }
 3331|    572|        free(session->opts.global_knownhosts);
 3332|    572|        session->opts.global_knownhosts = tmp;
 3333|    572|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS;
  ------------------
  |  |  116|    572|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
 3334|    572|    }
 3335|       |
 3336|       |
 3337|    572|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_PROXYCOMMAND) == 0) {
  ------------------
  |  |  117|    572|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
  |  Branch (3337:9): [True: 572, False: 0]
  ------------------
 3338|    572|        if (session->opts.ProxyCommand != NULL) {
  ------------------
  |  Branch (3338:13): [True: 0, False: 572]
  ------------------
 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|    572|    }
 3369|       |
 3370|    572|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_CONTROL_PATH) == 0) {
  ------------------
  |  |  119|    572|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
  |  Branch (3370:9): [True: 572, False: 0]
  ------------------
 3371|    572|        if (session->opts.control_path != NULL) {
  ------------------
  |  Branch (3371:13): [True: 0, False: 572]
  ------------------
 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|    572|    }
 3381|       |
 3382|       |    /* Allocate on first use (no longer pre-allocated in ssh_new()) */
 3383|    572|    if (session->opts.identity == NULL) {
  ------------------
  |  Branch (3383:9): [True: 572, False: 0]
  ------------------
 3384|    572|        session->opts.identity = ssh_list_new();
 3385|    572|        if (session->opts.identity == NULL) {
  ------------------
  |  Branch (3385:13): [True: 0, False: 572]
  ------------------
 3386|      0|            return -1;
 3387|      0|        }
 3388|    572|    }
 3389|       |
 3390|    572|    for (tmp = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  128|    572|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 3391|  2.28k|         tmp != NULL;
  ------------------
  |  Branch (3391:10): [True: 1.71k, False: 572]
  ------------------
 3392|  1.71k|         tmp = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  128|  1.71k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 3393|  1.71k|        char *id = tmp;
 3394|  1.71k|        if (strncmp(id, "pkcs11:", 6) != 0) {
  ------------------
  |  Branch (3394:13): [True: 1.71k, 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.71k|            tmp = ssh_path_expand_escape(session, id);
 3399|  1.71k|            free(id);
 3400|  1.71k|            if (tmp == NULL) {
  ------------------
  |  Branch (3400:17): [True: 0, False: 1.71k]
  ------------------
 3401|      0|                return -1;
 3402|      0|            }
 3403|  1.71k|        }
 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.71k|        if (session->opts.exp_flags & SSH_OPT_EXP_FLAG_IDENTITY) {
  ------------------
  |  |  118|  1.71k|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
  |  Branch (3407:13): [True: 0, False: 1.71k]
  ------------------
 3408|      0|            rc = ssh_list_prepend(session->opts.identity, tmp);
 3409|  1.71k|        } else {
 3410|  1.71k|            rc = ssh_list_append(session->opts.identity, tmp);
 3411|  1.71k|        }
 3412|  1.71k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.71k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3412:13): [True: 0, False: 1.71k]
  ------------------
 3413|      0|            free(tmp);
 3414|      0|            return -1;
 3415|      0|        }
 3416|  1.71k|    }
 3417|    572|    session->opts.exp_flags |= SSH_OPT_EXP_FLAG_IDENTITY;
  ------------------
  |  |  118|    572|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
 3418|       |
 3419|       |    /* Allocate on first use (no longer pre-allocated in ssh_new()) */
 3420|    572|    if (session->opts.certificate == NULL) {
  ------------------
  |  Branch (3420:9): [True: 572, False: 0]
  ------------------
 3421|    572|        session->opts.certificate = ssh_list_new();
 3422|    572|        if (session->opts.certificate == NULL) {
  ------------------
  |  Branch (3422:13): [True: 0, False: 572]
  ------------------
 3423|      0|            return -1;
 3424|      0|        }
 3425|    572|    }
 3426|       |
 3427|    572|    for (tmp = ssh_list_pop_head(char *, session->opts.certificate_non_exp);
  ------------------
  |  |  128|    572|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 3428|    572|         tmp != NULL;
  ------------------
  |  Branch (3428:10): [True: 0, False: 572]
  ------------------
 3429|    572|         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|    572|    return 0;
 3456|    572|}
options.c:ssh_opt_type_to_opcode:
  520|  5.72k|{
  521|  5.72k|    switch (type) {
  ------------------
  |  Branch (521:13): [True: 5.72k, False: 0]
  ------------------
  522|      0|    case SSH_OPTIONS_PORT:
  ------------------
  |  Branch (522:5): [True: 0, False: 5.72k]
  ------------------
  523|      0|    case SSH_OPTIONS_PORT_STR:
  ------------------
  |  Branch (523:5): [True: 0, False: 5.72k]
  ------------------
  524|      0|        return SOC_PORT;
  525|    572|    case SSH_OPTIONS_USER:
  ------------------
  |  Branch (525:5): [True: 572, False: 5.14k]
  ------------------
  526|    572|        return SOC_USERNAME;
  527|      0|    case SSH_OPTIONS_KNOWNHOSTS:
  ------------------
  |  Branch (527:5): [True: 0, False: 5.72k]
  ------------------
  528|      0|        return SOC_KNOWNHOSTS;
  529|      0|    case SSH_OPTIONS_GLOBAL_KNOWNHOSTS:
  ------------------
  |  Branch (529:5): [True: 0, False: 5.72k]
  ------------------
  530|      0|        return SOC_GLOBALKNOWNHOSTSFILE;
  531|    572|    case SSH_OPTIONS_TIMEOUT:
  ------------------
  |  Branch (531:5): [True: 572, False: 5.14k]
  ------------------
  532|    572|        return SOC_TIMEOUT;
  533|    572|    case SSH_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (533:5): [True: 572, False: 5.14k]
  ------------------
  534|  1.14k|    case SSH_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (534:5): [True: 572, False: 5.14k]
  ------------------
  535|  1.14k|        return SOC_CIPHERS;
  536|      0|    case SSH_OPTIONS_COMPRESSION:
  ------------------
  |  Branch (536:5): [True: 0, False: 5.72k]
  ------------------
  537|      0|    case SSH_OPTIONS_COMPRESSION_C_S:
  ------------------
  |  Branch (537:5): [True: 0, False: 5.72k]
  ------------------
  538|      0|    case SSH_OPTIONS_COMPRESSION_S_C:
  ------------------
  |  Branch (538:5): [True: 0, False: 5.72k]
  ------------------
  539|      0|        return SOC_COMPRESSION;
  540|      0|    case SSH_OPTIONS_PROXYCOMMAND:
  ------------------
  |  Branch (540:5): [True: 0, False: 5.72k]
  ------------------
  541|      0|        return SOC_PROXYCOMMAND;
  542|      0|    case SSH_OPTIONS_PROXYJUMP:
  ------------------
  |  Branch (542:5): [True: 0, False: 5.72k]
  ------------------
  543|      0|        return SOC_PROXYJUMP;
  544|      0|    case SSH_OPTIONS_BINDADDR:
  ------------------
  |  Branch (544:5): [True: 0, False: 5.72k]
  ------------------
  545|      0|        return SOC_BINDADDRESS;
  546|      0|    case SSH_OPTIONS_STRICTHOSTKEYCHECK:
  ------------------
  |  Branch (546:5): [True: 0, False: 5.72k]
  ------------------
  547|      0|        return SOC_STRICTHOSTKEYCHECK;
  548|      0|    case SSH_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (548:5): [True: 0, False: 5.72k]
  ------------------
  549|      0|        return SOC_KEXALGORITHMS;
  550|      0|    case SSH_OPTIONS_HOSTKEYS:
  ------------------
  |  Branch (550:5): [True: 0, False: 5.72k]
  ------------------
  551|      0|        return SOC_HOSTKEYALGORITHMS;
  552|      0|    case SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES:
  ------------------
  |  Branch (552:5): [True: 0, False: 5.72k]
  ------------------
  553|      0|        return SOC_PUBKEYACCEPTEDKEYTYPES;
  554|    572|    case SSH_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (554:5): [True: 572, False: 5.14k]
  ------------------
  555|  1.14k|    case SSH_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (555:5): [True: 572, False: 5.14k]
  ------------------
  556|  1.14k|        return SOC_MACS;
  557|      0|    case SSH_OPTIONS_GSSAPI_SERVER_IDENTITY:
  ------------------
  |  Branch (557:5): [True: 0, False: 5.72k]
  ------------------
  558|      0|        return SOC_GSSAPISERVERIDENTITY;
  559|      0|    case SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY:
  ------------------
  |  Branch (559:5): [True: 0, False: 5.72k]
  ------------------
  560|      0|        return SOC_GSSAPICLIENTIDENTITY;
  561|      0|    case SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS:
  ------------------
  |  Branch (561:5): [True: 0, False: 5.72k]
  ------------------
  562|      0|        return SOC_GSSAPIDELEGATECREDENTIALS;
  563|      0|    case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE:
  ------------------
  |  Branch (563:5): [True: 0, False: 5.72k]
  ------------------
  564|      0|        return SOC_GSSAPIKEYEXCHANGE;
  565|      0|    case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE_ALGS:
  ------------------
  |  Branch (565:5): [True: 0, False: 5.72k]
  ------------------
  566|      0|        return SOC_GSSAPIKEXALGORITHMS;
  567|      0|    case SSH_OPTIONS_PASSWORD_AUTH:
  ------------------
  |  Branch (567:5): [True: 0, False: 5.72k]
  ------------------
  568|      0|        return SOC_PASSWORDAUTHENTICATION;
  569|      0|    case SSH_OPTIONS_PUBKEY_AUTH:
  ------------------
  |  Branch (569:5): [True: 0, False: 5.72k]
  ------------------
  570|      0|        return SOC_PUBKEYAUTHENTICATION;
  571|      0|    case SSH_OPTIONS_KBDINT_AUTH:
  ------------------
  |  Branch (571:5): [True: 0, False: 5.72k]
  ------------------
  572|      0|        return SOC_KBDINTERACTIVEAUTHENTICATION;
  573|      0|    case SSH_OPTIONS_GSSAPI_AUTH:
  ------------------
  |  Branch (573:5): [True: 0, False: 5.72k]
  ------------------
  574|      0|        return SOC_GSSAPIAUTHENTICATION;
  575|      0|    case SSH_OPTIONS_PREFERRED_AUTHENTICATIONS:
  ------------------
  |  Branch (575:5): [True: 0, False: 5.72k]
  ------------------
  576|      0|        return SOC_PREFERRED_AUTHENTICATIONS;
  577|      0|    case SSH_OPTIONS_REKEY_DATA:
  ------------------
  |  Branch (577:5): [True: 0, False: 5.72k]
  ------------------
  578|      0|    case SSH_OPTIONS_REKEY_TIME:
  ------------------
  |  Branch (578:5): [True: 0, False: 5.72k]
  ------------------
  579|      0|        return SOC_REKEYLIMIT;
  580|      0|    case SSH_OPTIONS_RSA_MIN_SIZE:
  ------------------
  |  Branch (580:5): [True: 0, False: 5.72k]
  ------------------
  581|      0|        return SOC_REQUIRED_RSA_SIZE;
  582|      0|    case SSH_OPTIONS_IDENTITY_AGENT:
  ------------------
  |  Branch (582:5): [True: 0, False: 5.72k]
  ------------------
  583|      0|        return SOC_IDENTITYAGENT;
  584|      0|    case SSH_OPTIONS_IDENTITIES_ONLY:
  ------------------
  |  Branch (584:5): [True: 0, False: 5.72k]
  ------------------
  585|      0|        return SOC_IDENTITIESONLY;
  586|      0|    case SSH_OPTIONS_CONTROL_MASTER:
  ------------------
  |  Branch (586:5): [True: 0, False: 5.72k]
  ------------------
  587|      0|        return SOC_CONTROLMASTER;
  588|      0|    case SSH_OPTIONS_CONTROL_PATH:
  ------------------
  |  Branch (588:5): [True: 0, False: 5.72k]
  ------------------
  589|      0|        return SOC_CONTROLPATH;
  590|      0|    case SSH_OPTIONS_ADDRESS_FAMILY:
  ------------------
  |  Branch (590:5): [True: 0, False: 5.72k]
  ------------------
  591|      0|        return SOC_ADDRESSFAMILY;
  592|      0|    case SSH_OPTIONS_SERVER_ALIVE_INTERVAL:
  ------------------
  |  Branch (592:5): [True: 0, False: 5.72k]
  ------------------
  593|      0|        return SOC_SERVERALIVEINTERVAL;
  594|      0|    case SSH_OPTIONS_SERVER_ALIVE_COUNT_MAX:
  ------------------
  |  Branch (594:5): [True: 0, False: 5.72k]
  ------------------
  595|      0|        return SOC_SERVERALIVECOUNTMAX;
  596|      0|    case SSH_OPTIONS_BATCH_MODE:
  ------------------
  |  Branch (596:5): [True: 0, False: 5.72k]
  ------------------
  597|      0|        return SOC_BATCHMODE;
  598|      0|    case SSH_OPTIONS_NUMBER_OF_PASSWORD_PROMPTS:
  ------------------
  |  Branch (598:5): [True: 0, False: 5.72k]
  ------------------
  599|      0|        return SOC_NUMBER_OF_PASSWORD_PROMPTS;
  600|      0|    case SSH_OPTIONS_REQUEST_TTY:
  ------------------
  |  Branch (600:5): [True: 0, False: 5.72k]
  ------------------
  601|      0|        return SOC_REQUEST_TTY;
  602|      0|    case SSH_OPTIONS_ESCAPE_CHAR:
  ------------------
  |  Branch (602:5): [True: 0, False: 5.72k]
  ------------------
  603|      0|        return SOC_ESCAPE_CHAR;
  604|      0|    case SSH_OPTIONS_EXIT_ON_FORWARD_FAILURE:
  ------------------
  |  Branch (604:5): [True: 0, False: 5.72k]
  ------------------
  605|      0|        return SOC_EXIT_ON_FORWARD_FAILURE;
  606|      0|    case SSH_OPTIONS_FORWARD_AGENT:
  ------------------
  |  Branch (606:5): [True: 0, False: 5.72k]
  ------------------
  607|      0|    case SSH_OPTIONS_FORWARD_AGENT_SOCK_PATH:
  ------------------
  |  Branch (607:5): [True: 0, False: 5.72k]
  ------------------
  608|      0|        return SOC_FORWARD_AGENT;
  609|      0|    case SSH_OPTIONS_GATEWAY_PORTS:
  ------------------
  |  Branch (609:5): [True: 0, False: 5.72k]
  ------------------
  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: 5.72k]
  ------------------
  617|      0|    case SSH_OPTIONS_ADD_IDENTITY:
  ------------------
  |  Branch (617:5): [True: 0, False: 5.72k]
  ------------------
  618|      0|    case SSH_OPTIONS_CERTIFICATE:
  ------------------
  |  Branch (618:5): [True: 0, False: 5.72k]
  ------------------
  619|      0|    case SSH_OPTIONS_PROXYJUMP_CB_LIST_APPEND:
  ------------------
  |  Branch (619:5): [True: 0, False: 5.72k]
  ------------------
  620|      0|    case SSH_OPTIONS_LOCAL_FORWARD:
  ------------------
  |  Branch (620:5): [True: 0, False: 5.72k]
  ------------------
  621|      0|    case SSH_OPTIONS_REMOTE_FORWARD:
  ------------------
  |  Branch (621:5): [True: 0, False: 5.72k]
  ------------------
  622|      0|    case SSH_OPTIONS_SEND_ENV:
  ------------------
  |  Branch (622:5): [True: 0, False: 5.72k]
  ------------------
  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|    572|    case SSH_OPTIONS_HOST:
  ------------------
  |  Branch (631:5): [True: 572, False: 5.14k]
  ------------------
  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|    572|    case SSH_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (638:5): [True: 0, False: 5.72k]
  ------------------
  639|    572|    case SSH_OPTIONS_LOG_VERBOSITY_STR:
  ------------------
  |  Branch (639:5): [True: 0, False: 5.72k]
  ------------------
  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|  1.14k|    case SSH_OPTIONS_FD:
  ------------------
  |  Branch (645:5): [True: 572, False: 5.14k]
  ------------------
  646|  1.71k|    case SSH_OPTIONS_SSH_DIR:
  ------------------
  |  Branch (646:5): [True: 572, False: 5.14k]
  ------------------
  647|  1.71k|    case SSH_OPTIONS_SSH1:
  ------------------
  |  Branch (647:5): [True: 0, False: 5.72k]
  ------------------
  648|  1.71k|    case SSH_OPTIONS_SSH2:
  ------------------
  |  Branch (648:5): [True: 0, False: 5.72k]
  ------------------
  649|  1.71k|    case SSH_OPTIONS_TIMEOUT_USEC:
  ------------------
  |  Branch (649:5): [True: 0, False: 5.72k]
  ------------------
  650|  1.71k|    case SSH_OPTIONS_COMPRESSION_LEVEL:
  ------------------
  |  Branch (650:5): [True: 0, False: 5.72k]
  ------------------
  651|  1.71k|    case SSH_OPTIONS_NODELAY:
  ------------------
  |  Branch (651:5): [True: 0, False: 5.72k]
  ------------------
  652|  2.28k|    case SSH_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (652:5): [True: 572, False: 5.14k]
  ------------------
  653|  2.28k|    case SSH_OPTIONS_PKI_CONTEXT:
  ------------------
  |  Branch (653:5): [True: 0, False: 5.72k]
  ------------------
  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|  2.28k|    case SSH_OPTIONS_NEXT_IDENTITY:
  ------------------
  |  Branch (658:5): [True: 0, False: 5.72k]
  ------------------
  659|  2.28k|    case SSH_OPTIONS_NEXT_LOCAL_FORWARD:
  ------------------
  |  Branch (659:5): [True: 0, False: 5.72k]
  ------------------
  660|  2.28k|    case SSH_OPTIONS_NEXT_REMOTE_FORWARD:
  ------------------
  |  Branch (660:5): [True: 0, False: 5.72k]
  ------------------
  661|  2.28k|    case SSH_OPTIONS_NEXT_SEND_ENV:
  ------------------
  |  Branch (661:5): [True: 0, False: 5.72k]
  ------------------
  662|  2.28k|        return SOC_UNKNOWN;
  663|  5.72k|    }
  664|       |
  665|      0|    return SOC_UNKNOWN;
  666|  5.72k|}
options.c:ssh_host_requires_lowercase:
 3194|    572|static bool ssh_host_requires_lowercase(const char *host) {
 3195|    572|    if (strchr(host, '%') != NULL || strchr(host, ':') != NULL ||
  ------------------
  |  Branch (3195:9): [True: 0, False: 572]
  |  Branch (3195:38): [True: 0, False: 572]
  ------------------
 3196|    572|        strspn(host, "0123456789.") == strlen(host)) {
  ------------------
  |  Branch (3196:9): [True: 572, False: 0]
  ------------------
 3197|    572|        return false;
 3198|    572|    }
 3199|      0|    return !ssh_is_ipaddr(host);
 3200|    572|}

ssh_packet_get_current_crypto:
 1159|   197k|{
 1160|   197k|    struct ssh_crypto_struct *crypto = NULL;
 1161|       |
 1162|   197k|    if (session == NULL) {
  ------------------
  |  Branch (1162:9): [True: 0, False: 197k]
  ------------------
 1163|      0|        return NULL;
 1164|      0|    }
 1165|       |
 1166|   197k|    if (session->current_crypto != NULL &&
  ------------------
  |  Branch (1166:9): [True: 0, False: 197k]
  ------------------
 1167|      0|        session->current_crypto->used & direction) {
  ------------------
  |  Branch (1167:9): [True: 0, False: 0]
  ------------------
 1168|      0|        crypto = session->current_crypto;
 1169|   197k|    } else if (session->next_crypto != NULL &&
  ------------------
  |  Branch (1169:16): [True: 197k, False: 0]
  ------------------
 1170|   197k|               session->next_crypto->used & direction) {
  ------------------
  |  Branch (1170:16): [True: 1.18k, False: 196k]
  ------------------
 1171|  1.18k|        crypto = session->next_crypto;
 1172|   196k|    } else {
 1173|   196k|        return NULL;
 1174|   196k|    }
 1175|       |
 1176|  1.18k|    switch (direction) {
  ------------------
  |  Branch (1176:13): [True: 1.18k, False: 0]
  ------------------
 1177|      0|    case SSH_DIRECTION_IN:
  ------------------
  |  Branch (1177:5): [True: 0, False: 1.18k]
  ------------------
 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.18k|    case SSH_DIRECTION_OUT:
  ------------------
  |  Branch (1182:5): [True: 1.18k, False: 0]
  ------------------
 1183|  1.18k|        if (crypto->out_cipher != NULL) {
  ------------------
  |  Branch (1183:13): [True: 1.18k, False: 0]
  ------------------
 1184|  1.18k|            return crypto;
 1185|  1.18k|        }
 1186|      0|        break;
 1187|      0|    case SSH_DIRECTION_BOTH:
  ------------------
  |  Branch (1187:5): [True: 0, False: 1.18k]
  ------------------
 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.18k|    }
 1193|       |
 1194|      0|    return NULL;
 1195|  1.18k|}
ssh_packet_socket_callback:
 1287|  63.8k|{
 1288|  63.8k|    ssh_session session = (ssh_session)user;
 1289|  63.8k|    uint32_t blocksize = 8;
 1290|  63.8k|    uint32_t lenfield_blocksize = 8;
 1291|  63.8k|    size_t current_macsize = 0;
 1292|  63.8k|    uint8_t *ptr = NULL;
 1293|  63.8k|    ssize_t to_be_read;
 1294|  63.8k|    int rc;
 1295|  63.8k|    uint8_t *cleartext_packet = NULL;
 1296|  63.8k|    uint8_t *packet_second_block = NULL;
 1297|  63.8k|    uint8_t *mac = NULL;
 1298|  63.8k|    size_t packet_remaining, packet_offset;
 1299|  63.8k|    uint32_t packet_len, compsize, payloadsize;
 1300|  63.8k|    uint8_t padding;
 1301|  63.8k|    size_t processed = 0; /* number of bytes processed from the callback */
 1302|  63.8k|    enum ssh_packet_filter_result_e filter_result;
 1303|  63.8k|    struct ssh_crypto_struct *crypto = NULL;
 1304|  63.8k|    bool etm = false;
 1305|  63.8k|    uint32_t etm_packet_offset = 0;
 1306|  63.8k|    bool ok;
 1307|       |
 1308|  63.8k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
 1309|  63.8k|    if (crypto != NULL) {
  ------------------
  |  Branch (1309:9): [True: 0, False: 63.8k]
  ------------------
 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|  63.8k|    if (etm) {
  ------------------
  |  Branch (1316:9): [True: 0, False: 63.8k]
  ------------------
 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|  63.8k|    } else if (lenfield_blocksize == 0) {
  ------------------
  |  Branch (1323:16): [True: 0, False: 63.8k]
  ------------------
 1324|      0|        lenfield_blocksize = blocksize;
 1325|      0|    }
 1326|  63.8k|    if (data == NULL) {
  ------------------
  |  Branch (1326:9): [True: 0, False: 63.8k]
  ------------------
 1327|      0|        goto error;
 1328|      0|    }
 1329|       |
 1330|  63.8k|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (1330:9): [True: 365, False: 63.4k]
  ------------------
 1331|    365|        goto error;
 1332|    365|    }
 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|  63.4k|    switch (session->packet_state) {
  ------------------
  |  Branch (1344:13): [True: 63.4k, False: 0]
  ------------------
 1345|  62.9k|        case PACKET_STATE_INIT:
  ------------------
  |  Branch (1345:9): [True: 62.9k, False: 494]
  ------------------
 1346|  62.9k|            if (receivedlen < lenfield_blocksize + etm_packet_offset) {
  ------------------
  |  Branch (1346:17): [True: 208, False: 62.7k]
  ------------------
 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|    208|                return 0;
 1358|    208|            }
 1359|       |
 1360|  62.7k|            session->in_packet = (struct packet_struct) {
 1361|  62.7k|                .type = 0,
 1362|  62.7k|            };
 1363|       |
 1364|  62.7k|            if (session->in_buffer) {
  ------------------
  |  Branch (1364:17): [True: 62.7k, False: 0]
  ------------------
 1365|  62.7k|                rc = ssh_buffer_reinit(session->in_buffer);
 1366|  62.7k|                if (rc < 0) {
  ------------------
  |  Branch (1366:21): [True: 0, False: 62.7k]
  ------------------
 1367|      0|                    goto error;
 1368|      0|                }
 1369|  62.7k|            } 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|  62.7k|            if (!etm) {
  ------------------
  |  Branch (1376:17): [True: 62.7k, False: 0]
  ------------------
 1377|  62.7k|                ptr = ssh_buffer_allocate(session->in_buffer,
 1378|  62.7k|                                          lenfield_blocksize);
 1379|  62.7k|                if (ptr == NULL) {
  ------------------
  |  Branch (1379:21): [True: 0, False: 62.7k]
  ------------------
 1380|      0|                    goto error;
 1381|      0|                }
 1382|  62.7k|                packet_len = ssh_packet_decrypt_len(session, ptr,
 1383|  62.7k|                                                    (uint8_t *)data);
 1384|  62.7k|                to_be_read = packet_len - lenfield_blocksize + sizeof(uint32_t);
 1385|  62.7k|            } 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|  62.7k|            processed += lenfield_blocksize + etm_packet_offset;
 1392|  62.7k|            if (packet_len > MAX_PACKET_LEN) {
  ------------------
  |  |  216|  62.7k|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (1392:17): [True: 85, False: 62.6k]
  ------------------
 1393|     85|                ssh_set_error(session,
  ------------------
  |  |  313|     85|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1394|     85|                              SSH_FATAL,
 1395|     85|                              "read_packet(): Packet len too high(%" PRIu32 " %.4" PRIx32 ")",
 1396|     85|                              packet_len, packet_len);
 1397|     85|                goto error;
 1398|     85|            }
 1399|  62.6k|            if (to_be_read < 0) {
  ------------------
  |  Branch (1399:17): [True: 0, False: 62.6k]
  ------------------
 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|  62.6k|            session->in_packet.len = packet_len;
 1409|  62.6k|            session->packet_state = PACKET_STATE_SIZEREAD;
 1410|  62.6k|            FALL_THROUGH;
  ------------------
  |  |  496|  62.6k|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1411|  63.1k|        case PACKET_STATE_SIZEREAD:
  ------------------
  |  Branch (1411:9): [True: 494, False: 62.9k]
  ------------------
 1412|  63.1k|            packet_len = session->in_packet.len;
 1413|  63.1k|            packet_offset = processed = lenfield_blocksize + etm_packet_offset;
 1414|  63.1k|            to_be_read = packet_len + sizeof(uint32_t) + current_macsize;
 1415|       |            /* if to_be_read is zero, the whole packet was blocksize bytes. */
 1416|  63.1k|            if (to_be_read != 0) {
  ------------------
  |  Branch (1416:17): [True: 63.1k, False: 0]
  ------------------
 1417|  63.1k|                if (receivedlen < (unsigned long)to_be_read) {
  ------------------
  |  Branch (1417:21): [True: 566, False: 62.6k]
  ------------------
 1418|       |                    /* give up, not enough data in buffer */
 1419|    566|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|    566|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1420|    566|                            "packet: partial packet (read len) "
 1421|    566|                            "[len=%" PRIu32 ", receivedlen=%zu, to_be_read=%zd]",
 1422|    566|                            packet_len,
 1423|    566|                            receivedlen,
 1424|    566|                            to_be_read);
 1425|    566|                    return 0;
 1426|    566|                }
 1427|       |
 1428|  62.6k|                packet_second_block = (uint8_t*)data + packet_offset;
 1429|  62.6k|                processed = to_be_read - current_macsize;
 1430|  62.6k|            }
 1431|       |
 1432|  62.6k|            if (packet_offset - sizeof(uint32_t) > (size_t)packet_len) {
  ------------------
  |  Branch (1432:17): [True: 3, False: 62.6k]
  ------------------
 1433|      3|                ssh_set_error(session,
  ------------------
  |  |  313|      3|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1434|      3|                              SSH_FATAL,
 1435|      3|                              "Invalid packet length %" PRIu32 ", required %zu",
 1436|      3|                              packet_len,
 1437|      3|                              packet_offset + sizeof(uint32_t));
 1438|      3|                goto error;
 1439|      3|            }
 1440|       |
 1441|       |            /* remaining encrypted bytes from the packet, MAC not included */
 1442|  62.6k|            packet_remaining = packet_len - (packet_offset - sizeof(uint32_t));
 1443|  62.6k|            cleartext_packet = ssh_buffer_allocate(session->in_buffer,
 1444|  62.6k|                                                   (uint32_t)packet_remaining);
 1445|  62.6k|            if (cleartext_packet == NULL) {
  ------------------
  |  Branch (1445:17): [True: 0, False: 62.6k]
  ------------------
 1446|      0|                goto error;
 1447|      0|            }
 1448|       |
 1449|  62.6k|            if (packet_second_block != NULL) {
  ------------------
  |  Branch (1449:17): [True: 62.6k, False: 0]
  ------------------
 1450|  62.6k|                if (crypto != NULL) {
  ------------------
  |  Branch (1450:21): [True: 0, False: 62.6k]
  ------------------
 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|  62.6k|                } else {
 1497|  62.6k|                    memcpy(cleartext_packet,
 1498|  62.6k|                           packet_second_block,
 1499|  62.6k|                           packet_remaining);
 1500|  62.6k|                }
 1501|  62.6k|            }
 1502|       |
 1503|  62.6k|#ifdef WITH_PCAP
 1504|  62.6k|            if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1504:17): [True: 0, False: 62.6k]
  ------------------
 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|  62.6k|#endif
 1512|       |
 1513|  62.6k|            if (!etm) {
  ------------------
  |  Branch (1513:17): [True: 62.6k, False: 0]
  ------------------
 1514|       |                /* skip the size field which has been processed before */
 1515|  62.6k|                ssh_buffer_pass_bytes(session->in_buffer, sizeof(uint32_t));
 1516|  62.6k|            }
 1517|       |
 1518|  62.6k|            rc = ssh_buffer_get_u8(session->in_buffer, &padding);
 1519|  62.6k|            if (rc == 0) {
  ------------------
  |  Branch (1519:17): [True: 0, False: 62.6k]
  ------------------
 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|  62.6k|            if (padding > ssh_buffer_get_len(session->in_buffer)) {
  ------------------
  |  Branch (1526:17): [True: 4, False: 62.5k]
  ------------------
 1527|      4|                ssh_set_error(session,
  ------------------
  |  |  313|      4|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1528|      4|                              SSH_FATAL,
 1529|      4|                              "Invalid padding: %d (%" PRIu32 " left)",
 1530|      4|                              padding,
 1531|      4|                              ssh_buffer_get_len(session->in_buffer));
 1532|      4|                goto error;
 1533|      4|            }
 1534|  62.5k|            ssh_buffer_pass_bytes_end(session->in_buffer, padding);
 1535|  62.5k|            compsize = ssh_buffer_get_len(session->in_buffer);
 1536|       |
 1537|  62.5k|            if (crypto && crypto->do_compress_in &&
  ------------------
  |  Branch (1537:17): [True: 0, False: 62.5k]
  |  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|  62.5k|            payloadsize = ssh_buffer_get_len(session->in_buffer);
 1546|  62.5k|            if (session->recv_seq == UINT32_MAX) {
  ------------------
  |  Branch (1546:17): [True: 0, False: 62.5k]
  ------------------
 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|  62.5k|            session->recv_seq++;
 1560|  62.5k|            if (crypto != NULL) {
  ------------------
  |  Branch (1560:17): [True: 0, False: 62.5k]
  ------------------
 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|  62.5k|            if (session->raw_counter != NULL) {
  ------------------
  |  Branch (1567:17): [True: 0, False: 62.5k]
  ------------------
 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|  62.5k|            session->packet_state = PACKET_STATE_PROCESSING;
 1577|  62.5k|            ssh_packet_parse_type(session);
 1578|  62.5k|            SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|  62.5k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1579|  62.5k|                    "packet: read type %hhd [len=%" PRIu32 ",padding=%hhd,"
 1580|  62.5k|                    "comp=%" PRIu32 ",payload=%" PRIu32 "]",
 1581|  62.5k|                    session->in_packet.type, packet_len, padding, compsize,
 1582|  62.5k|                    payloadsize);
 1583|  62.5k|            if (crypto == NULL) {
  ------------------
  |  Branch (1583:17): [True: 62.5k, 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|  62.5k|                uint8_t type = session->in_packet.type;
 1589|       |
 1590|  62.5k|                if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   12|   125k|#define SSH2_MSG_KEXINIT	 20
  ------------------
                              if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   13|   124k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (1590:21): [True: 62.2k, False: 351]
  |  Branch (1590:49): [True: 62.2k, False: 38]
  ------------------
 1591|  62.2k|                    (type < SSH2_MSG_KEXDH_INIT ||
  ------------------
  |  |   15|   124k|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (1591:22): [True: 41.2k, False: 20.9k]
  ------------------
 1592|  61.4k|                     type > SSH2_MSG_KEX_DH_GEX_REQUEST)) {
  ------------------
  |  |   26|  20.9k|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (1592:22): [True: 20.1k, False: 801]
  ------------------
 1593|  61.4k|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|  61.4k|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1594|  61.4k|                }
 1595|  62.5k|            }
 1596|       |            /* Check if the packet is expected */
 1597|  62.5k|            filter_result = ssh_packet_incoming_filter(session);
 1598|       |
 1599|  62.5k|            switch (filter_result) {
  ------------------
  |  Branch (1599:21): [True: 62.5k, False: 0]
  ------------------
 1600|  29.2k|            case SSH_PACKET_ALLOWED:
  ------------------
  |  Branch (1600:13): [True: 29.2k, False: 33.3k]
  ------------------
 1601|       |                /* Execute callbacks */
 1602|  29.2k|                ssh_packet_process(session, session->in_packet.type);
 1603|  29.2k|                break;
 1604|     38|            case SSH_PACKET_DENIED:
  ------------------
  |  Branch (1604:13): [True: 38, False: 62.5k]
  ------------------
 1605|     38|                ssh_set_error(session,
  ------------------
  |  |  313|     38|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1606|     38|                              SSH_FATAL,
 1607|     38|                              "Packet filter: rejected packet (type %d)",
 1608|     38|                              session->in_packet.type);
 1609|     38|                goto error;
 1610|  33.3k|            case SSH_PACKET_UNKNOWN:
  ------------------
  |  Branch (1610:13): [True: 33.3k, False: 29.2k]
  ------------------
 1611|  33.3k|                if (crypto == NULL) {
  ------------------
  |  Branch (1611:21): [True: 33.3k, False: 0]
  ------------------
 1612|  33.3k|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|  33.3k|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1613|  33.3k|                }
 1614|  33.3k|                ssh_packet_send_unimplemented(session, session->recv_seq - 1);
 1615|  33.3k|                break;
 1616|  62.5k|            }
 1617|       |
 1618|  62.5k|            session->packet_state = PACKET_STATE_INIT;
 1619|  62.5k|            if (processed < receivedlen) {
  ------------------
  |  Branch (1619:17): [True: 62.4k, False: 74]
  ------------------
 1620|  62.4k|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|  62.4k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1621|  62.4k|                        "packet: %zu bytes still remaining in socket buffer "
 1622|  62.4k|                        "after processing",
 1623|  62.4k|                        receivedlen-processed);
 1624|  62.4k|            }
 1625|       |
 1626|  62.5k|            ok = ssh_packet_need_rekey(session, 0);
 1627|  62.5k|            if (ok) {
  ------------------
  |  Branch (1627:17): [True: 0, False: 62.5k]
  ------------------
 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|  62.5k|            return processed;
 1637|      0|        case PACKET_STATE_PROCESSING:
  ------------------
  |  Branch (1637:9): [True: 0, False: 63.4k]
  ------------------
 1638|      0|            SSH_LOG(SSH_LOG_PACKET, "Nested packet processing. Delaying.");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1639|      0|            return 0;
 1640|  63.4k|    }
 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|    495|error:
 1648|    495|    session->session_state = SSH_SESSION_STATE_ERROR;
 1649|    495|    SSH_LOG(SSH_LOG_PACKET, "Packet: processed %zu bytes", processed);
  ------------------
  |  |  283|    495|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1650|    495|    return processed;
 1651|      0|}
ssh_packet_register_socket_callback:
 1678|    501|{
 1679|    501|    struct ssh_socket_callbacks_struct *callbacks = &session->socket_callbacks;
 1680|       |
 1681|    501|    callbacks->data = ssh_packet_socket_callback;
 1682|       |    callbacks->connected = NULL;
 1683|    501|    callbacks->controlflow = ssh_packet_socket_controlflow_callback;
 1684|    501|    callbacks->userdata = session;
 1685|    501|    ssh_socket_set_callbacks(s, callbacks);
 1686|    501|}
ssh_packet_set_callbacks:
 1693|    780|{
 1694|    780|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1694:9): [True: 501, False: 279]
  ------------------
 1695|    501|        session->packet_callbacks = ssh_list_new();
 1696|    501|        if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1696:13): [True: 0, False: 501]
  ------------------
 1697|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  320|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1698|      0|            return;
 1699|      0|        }
 1700|    501|    }
 1701|    780|    ssh_list_append(session->packet_callbacks, callbacks);
 1702|    780|}
ssh_packet_remove_callbacks:
 1709|    174|{
 1710|    174|    struct ssh_iterator *it = NULL;
 1711|       |
 1712|    174|    it = ssh_list_find(session->packet_callbacks, callbacks);
 1713|    174|    if (it != NULL) {
  ------------------
  |  Branch (1713:9): [True: 174, False: 0]
  ------------------
 1714|    174|        ssh_list_remove(session->packet_callbacks, it);
 1715|    174|    }
 1716|    174|}
ssh_packet_set_default_callbacks:
 1722|    501|{
 1723|    501|    struct ssh_packet_callbacks_struct *c = &session->default_packet_callbacks;
 1724|       |
 1725|    501|    c->start = 1;
 1726|    501|    c->n_callbacks = sizeof(default_packet_handlers) / sizeof(ssh_packet_callback);
 1727|    501|    c->user = session;
 1728|    501|    c->callbacks = default_packet_handlers;
 1729|    501|    ssh_packet_set_callbacks(session, c);
 1730|    501|}
ssh_packet_process:
 1737|  29.2k|{
 1738|  29.2k|    struct ssh_iterator *i = NULL;
 1739|  29.2k|    int rc = SSH_PACKET_NOT_USED;
  ------------------
  |  |  641|  29.2k|#define SSH_PACKET_NOT_USED 2
  ------------------
 1740|  29.2k|    ssh_packet_callbacks cb;
 1741|       |
 1742|  29.2k|    SSH_LOG(SSH_LOG_PACKET, "Dispatching handler for packet type %d", type);
  ------------------
  |  |  283|  29.2k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1743|  29.2k|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1743:9): [True: 0, False: 29.2k]
  ------------------
 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|  29.2k|    i = ssh_list_get_iterator(session->packet_callbacks);
 1749|  30.6k|    while (i != NULL) {
  ------------------
  |  Branch (1749:12): [True: 30.0k, False: 616]
  ------------------
 1750|  30.0k|        cb = ssh_iterator_value(ssh_packet_callbacks, i);
  ------------------
  |  |  120|  30.0k|  ((type)((iterator)->data))
  ------------------
 1751|  30.0k|        i = i->next;
 1752|       |
 1753|  30.0k|        if (!cb) {
  ------------------
  |  Branch (1753:13): [True: 0, False: 30.0k]
  ------------------
 1754|      0|            continue;
 1755|      0|        }
 1756|       |
 1757|  30.0k|        if (cb->start > type) {
  ------------------
  |  Branch (1757:13): [True: 0, False: 30.0k]
  ------------------
 1758|      0|            continue;
 1759|      0|        }
 1760|       |
 1761|  30.0k|        if (cb->start + cb->n_callbacks <= type) {
  ------------------
  |  Branch (1761:13): [True: 616, False: 29.4k]
  ------------------
 1762|    616|            continue;
 1763|    616|        }
 1764|       |
 1765|  29.4k|        if (cb->callbacks[type - cb->start] == NULL) {
  ------------------
  |  Branch (1765:13): [True: 797, False: 28.6k]
  ------------------
 1766|    797|            continue;
 1767|    797|        }
 1768|       |
 1769|  28.6k|        rc = cb->callbacks[type - cb->start](session, type, session->in_buffer,
 1770|  28.6k|                                             cb->user);
 1771|  28.6k|        if (rc == SSH_PACKET_USED) {
  ------------------
  |  |  638|  28.6k|#define SSH_PACKET_USED 1
  ------------------
  |  Branch (1771:13): [True: 28.6k, False: 0]
  ------------------
 1772|  28.6k|            break;
 1773|  28.6k|        }
 1774|  28.6k|    }
 1775|       |
 1776|  29.2k|    if (rc == SSH_PACKET_NOT_USED) {
  ------------------
  |  |  641|  29.2k|#define SSH_PACKET_NOT_USED 2
  ------------------
  |  Branch (1776:9): [True: 616, False: 28.6k]
  ------------------
 1777|    616|        SSH_LOG(SSH_LOG_RARE, "Couldn't do anything with packet type %d", type);
  ------------------
  |  |  283|    616|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1778|    616|        rc = ssh_packet_send_unimplemented(session, session->recv_seq - 1);
 1779|    616|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    616|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1779:13): [True: 0, False: 616]
  ------------------
 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|    616|        if (session->current_crypto == NULL) {
  ------------------
  |  Branch (1783:13): [True: 616, False: 0]
  ------------------
 1784|    616|            session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|    616|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1785|    616|        }
 1786|    616|    }
 1787|  29.2k|}
ssh_packet_send_newkeys:
 1795|     54|{
 1796|     54|    int rc;
 1797|       |
 1798|       |    /* Send the MSG_NEWKEYS */
 1799|     54|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS);
  ------------------
  |  |   13|     54|#define SSH2_MSG_NEWKEYS 21
  ------------------
 1800|     54|    if (rc < 0) {
  ------------------
  |  Branch (1800:9): [True: 0, False: 54]
  ------------------
 1801|      0|        return rc;
 1802|      0|    }
 1803|       |
 1804|     54|    rc = ssh_packet_send(session);
 1805|     54|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     54|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1805:9): [True: 0, False: 54]
  ------------------
 1806|      0|        return rc;
 1807|      0|    }
 1808|     54|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_NEWKEYS sent");
  ------------------
  |  |  283|     54|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1809|     54|    return rc;
 1810|     54|}
ssh_packet_send_unimplemented:
 1818|  33.9k|int ssh_packet_send_unimplemented(ssh_session session, uint32_t seqnum){
 1819|  33.9k|    int rc;
 1820|       |
 1821|  33.9k|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|  33.9k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|  33.9k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|  33.9k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|  33.9k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|  33.9k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|  33.9k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  33.9k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1822|  33.9k|                         "bd",
 1823|  33.9k|                         SSH2_MSG_UNIMPLEMENTED,
 1824|  33.9k|                         seqnum);
 1825|  33.9k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  33.9k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1825:9): [True: 0, False: 33.9k]
  ------------------
 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|  33.9k|    rc = ssh_packet_send(session);
 1830|       |
 1831|  33.9k|    return rc;
 1832|  33.9k|}
ssh_packet_unimplemented:
 1837|    699|SSH_PACKET_CALLBACK(ssh_packet_unimplemented){
 1838|    699|    uint32_t seq;
 1839|    699|    int rc;
 1840|       |
 1841|    699|    (void)session; /* unused */
 1842|    699|    (void)type;
 1843|    699|    (void)user;
 1844|       |
 1845|    699|    rc = ssh_buffer_unpack(packet, "d", &seq);
  ------------------
  |  |   60|    699|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|    699|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|    699|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|    699|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|    699|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|    699|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    699|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1846|    699|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    699|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1846:9): [True: 598, False: 101]
  ------------------
 1847|    598|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|    598|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1848|    598|                "Could not unpack SSH_MSG_UNIMPLEMENTED packet");
 1849|    598|        return SSH_PACKET_USED;
  ------------------
  |  |  638|    598|#define SSH_PACKET_USED 1
  ------------------
 1850|    598|    }
 1851|       |
 1852|    101|    SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  283|    101|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1853|    101|            "Received SSH_MSG_UNIMPLEMENTED (sequence number %" PRIu32 ")",seq);
 1854|       |
 1855|    101|    return SSH_PACKET_USED;
  ------------------
  |  |  638|    101|#define SSH_PACKET_USED 1
  ------------------
 1856|    699|}
ssh_packet_parse_type:
 1862|  62.5k|{
 1863|  62.5k|    session->in_packet = (struct packet_struct) {
 1864|  62.5k|        .type = 0,
 1865|  62.5k|    };
 1866|       |
 1867|  62.5k|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (1867:9): [True: 0, False: 62.5k]
  ------------------
 1868|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1869|      0|    }
 1870|       |
 1871|  62.5k|    if (ssh_buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) {
  ------------------
  |  Branch (1871:9): [True: 14.8k, False: 47.7k]
  ------------------
 1872|  14.8k|        ssh_set_error(session, SSH_FATAL, "Packet too short to read type");
  ------------------
  |  |  313|  14.8k|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1873|  14.8k|        return SSH_ERROR;
  ------------------
  |  |  317|  14.8k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1874|  14.8k|    }
 1875|       |
 1876|  47.7k|    session->in_packet.valid = 1;
 1877|       |
 1878|  47.7k|    return SSH_OK;
  ------------------
  |  |  316|  47.7k|#define SSH_OK 0     /* No error */
  ------------------
 1879|  62.5k|}
ssh_packet_send:
 2067|  35.3k|{
 2068|  35.3k|    uint32_t payloadsize;
 2069|  35.3k|    uint8_t type, *payload;
 2070|  35.3k|    bool need_rekey, in_rekey;
 2071|  35.3k|    int rc;
 2072|       |
 2073|  35.3k|    if (session->socket == NULL || !ssh_socket_is_open(session->socket)) {
  ------------------
  |  Branch (2073:9): [True: 0, False: 35.3k]
  |  Branch (2073:36): [True: 0, False: 35.3k]
  ------------------
 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|  35.3k|    payloadsize = ssh_buffer_get_len(session->out_buffer);
 2079|  35.3k|    if (payloadsize < 1) {
  ------------------
  |  Branch (2079:9): [True: 0, False: 35.3k]
  ------------------
 2080|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2081|      0|    }
 2082|       |
 2083|  35.3k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 2084|  35.3k|    type = payload[0]; /* type is the first byte of the packet now */
 2085|  35.3k|    need_rekey = ssh_packet_need_rekey(session, payloadsize);
 2086|  35.3k|    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|  35.3k|    if (need_rekey || (in_rekey && !ssh_packet_is_kex(type))) {
  ------------------
  |  Branch (2091:9): [True: 0, False: 35.3k]
  |  Branch (2091:24): [True: 0, False: 35.3k]
  |  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|  35.3k|    rc = packet_send2(session);
 2121|       |
 2122|       |    /* We finished the key exchange so we can try to send our queue now */
 2123|  35.3k|    if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |  316|  70.6k|#define SSH_OK 0     /* No error */
  ------------------
                  if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  35.3k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2123:9): [True: 35.3k, False: 0]
  |  Branch (2123:25): [True: 54, False: 35.2k]
  ------------------
 2124|     54|        struct ssh_iterator *it = NULL;
 2125|       |
 2126|     54|        if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|     54|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (2126:13): [True: 6, False: 48]
  ------------------
 2127|       |            /* reset packet sequence number when running in strict kex mode */
 2128|      6|            session->send_seq = 0;
 2129|      6|        }
 2130|     54|        for (it = ssh_list_get_iterator(session->out_queue);
 2131|     54|             it != NULL;
  ------------------
  |  Branch (2131:14): [True: 0, False: 54]
  ------------------
 2132|     54|             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|     54|    }
 2155|       |
 2156|  35.3k|    return rc;
 2157|  35.3k|}
ssh_packet_set_newkeys:
 2272|     54|{
 2273|     54|    struct ssh_cipher_struct *in_cipher = NULL, *out_cipher = NULL;
 2274|     54|    int rc;
 2275|       |
 2276|     54|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|    216|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 0, False: 54]
  |  |  |  Branch (283:34): [True: 54, False: 0]
  |  |  ------------------
  ------------------
 2277|     54|            "called, direction =%s%s",
 2278|     54|            direction & SSH_DIRECTION_IN ? " IN " : "",
 2279|     54|            direction & SSH_DIRECTION_OUT ? " OUT " : "");
 2280|       |
 2281|     54|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2281:9): [True: 0, False: 54]
  ------------------
 2282|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2283|      0|    }
 2284|       |
 2285|     54|    session->next_crypto->used |= direction;
 2286|     54|    if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2286:9): [True: 0, False: 54]
  ------------------
 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|     54|    if (session->next_crypto->used == SSH_DIRECTION_BOTH) {
  ------------------
  |  Branch (2295:9): [True: 0, False: 54]
  ------------------
 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|     54|    if (session->client) {
  ------------------
  |  Branch (2330:9): [True: 54, False: 0]
  ------------------
 2331|       |        /* The server has this part already done */
 2332|     54|        rc = ssh_make_sessionid(session);
 2333|     54|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     54|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2333:13): [True: 0, False: 54]
  ------------------
 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|     54|        rc = crypt_set_algorithms_client(session);
 2342|     54|        if (rc < 0) {
  ------------------
  |  Branch (2342:13): [True: 0, False: 54]
  ------------------
 2343|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2344|      0|        }
 2345|     54|    }
 2346|       |
 2347|     54|    if (ssh_generate_session_keys(session) < 0) {
  ------------------
  |  Branch (2347:9): [True: 0, False: 54]
  ------------------
 2348|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2349|      0|    }
 2350|       |
 2351|     54|    in_cipher = session->next_crypto->in_cipher;
 2352|     54|    out_cipher = session->next_crypto->out_cipher;
 2353|     54|    if (in_cipher == NULL || out_cipher == NULL) {
  ------------------
  |  Branch (2353:9): [True: 0, False: 54]
  |  Branch (2353:30): [True: 0, False: 54]
  ------------------
 2354|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2355|      0|    }
 2356|       |
 2357|       |    /* Initialize rekeying states */
 2358|     54|    ssh_init_rekey_state(session, out_cipher);
 2359|     54|    ssh_init_rekey_state(session, in_cipher);
 2360|     54|    if (session->opts.rekey_time != 0) {
  ------------------
  |  Branch (2360:9): [True: 0, False: 54]
  ------------------
 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|     54|    if (in_cipher->set_decrypt_key) {
  ------------------
  |  Branch (2366:9): [True: 0, False: 54]
  ------------------
 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|     54|    if (out_cipher->set_encrypt_key) {
  ------------------
  |  Branch (2378:9): [True: 0, False: 54]
  ------------------
 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|     54|    return SSH_OK;
  ------------------
  |  |  316|     54|#define SSH_OK 0     /* No error */
  ------------------
 2390|     54|}
packet.c:ssh_packet_incoming_filter:
  143|  62.5k|{
  144|  62.5k|    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|  62.5k|    switch(session->in_packet.type) {
  152|      2|    case SSH2_MSG_DISCONNECT:                         // 1
  ------------------
  |  |    4|      2|#define SSH2_MSG_DISCONNECT 1
  ------------------
  |  Branch (152:5): [True: 2, False: 62.5k]
  ------------------
  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|      2|        rc = SSH_PACKET_ALLOWED;
  164|      2|        break;
  165|    134|    case SSH2_MSG_IGNORE:                             // 2
  ------------------
  |  |    5|    134|#define SSH2_MSG_IGNORE	 2
  ------------------
  |  Branch (165:5): [True: 134, False: 62.4k]
  ------------------
  166|       |        /*
  167|       |         * States required:
  168|       |         * - None
  169|       |         *
  170|       |         * Transitions:
  171|       |         * - None
  172|       |         * */
  173|       |
  174|       |        /* Always allowed */
  175|    134|        rc = SSH_PACKET_ALLOWED;
  176|    134|        break;
  177|    699|    case SSH2_MSG_UNIMPLEMENTED:                      // 3
  ------------------
  |  |    6|    699|#define SSH2_MSG_UNIMPLEMENTED 3
  ------------------
  |  Branch (177:5): [True: 699, False: 61.8k]
  ------------------
  178|       |        /*
  179|       |         * States required:
  180|       |         * - None
  181|       |         *
  182|       |         * Transitions:
  183|       |         * - None
  184|       |         * */
  185|       |
  186|       |        /* Always allowed */
  187|    699|        rc = SSH_PACKET_ALLOWED;
  188|    699|        break;
  189|  25.3k|    case SSH2_MSG_DEBUG:                              // 4
  ------------------
  |  |    7|  25.3k|#define SSH2_MSG_DEBUG	4
  ------------------
  |  Branch (189:5): [True: 25.3k, False: 37.2k]
  ------------------
  190|       |        /*
  191|       |         * States required:
  192|       |         * - None
  193|       |         *
  194|       |         * Transitions:
  195|       |         * - None
  196|       |         * */
  197|       |
  198|       |        /* Always allowed */
  199|  25.3k|        rc = SSH_PACKET_ALLOWED;
  200|  25.3k|        break;
  201|      1|    case SSH2_MSG_SERVICE_REQUEST:                    // 5
  ------------------
  |  |    8|      1|#define SSH2_MSG_SERVICE_REQUEST	5
  ------------------
  |  Branch (201:5): [True: 1, False: 62.5k]
  ------------------
  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|      1|    case SSH2_MSG_SERVICE_ACCEPT:                     // 6
  ------------------
  |  |    9|      1|#define SSH2_MSG_SERVICE_ACCEPT 6
  ------------------
  |  Branch (234:5): [True: 1, False: 62.5k]
  ------------------
  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|      1|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (246:13): [True: 1, False: 0]
  ------------------
  247|      1|            (session->session_state != SSH_SESSION_STATE_AUTHENTICATED))
  ------------------
  |  Branch (247:13): [True: 1, False: 0]
  ------------------
  248|      1|        {
  249|      1|            rc = SSH_PACKET_DENIED;
  250|      1|            break;
  251|      1|        }
  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: 62.5k]
  ------------------
  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|    351|    case SSH2_MSG_KEXINIT:                            // 20
  ------------------
  |  |   12|    351|#define SSH2_MSG_KEXINIT	 20
  ------------------
  |  Branch (292:5): [True: 351, False: 62.2k]
  ------------------
  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|    351|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATED) &&
  ------------------
  |  Branch (310:13): [True: 351, False: 0]
  ------------------
  311|    351|            (session->session_state != SSH_SESSION_STATE_INITIAL_KEX))
  ------------------
  |  Branch (311:13): [True: 1, False: 350]
  ------------------
  312|      1|        {
  313|      1|            rc = SSH_PACKET_DENIED;
  314|      1|            break;
  315|      1|        }
  316|       |
  317|    350|        if ((session->dh_handshake_state != DH_STATE_INIT) &&
  ------------------
  |  Branch (317:13): [True: 0, False: 350]
  ------------------
  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|    350|        rc = SSH_PACKET_ALLOWED;
  327|    350|        break;
  328|     38|    case SSH2_MSG_NEWKEYS:                            // 21
  ------------------
  |  |   13|     38|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (328:5): [True: 38, False: 62.5k]
  ------------------
  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|     38|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (342:13): [True: 1, False: 37]
  ------------------
  343|      1|            rc = SSH_PACKET_DENIED;
  344|      1|            break;
  345|      1|        }
  346|       |
  347|       |        /* Only allowed if dh_handshake_state is in NEWKEYS_SENT state */
  348|     37|        if (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (348:13): [True: 1, False: 36]
  ------------------
  349|      1|            rc = SSH_PACKET_DENIED;
  350|      1|            break;
  351|      1|        }
  352|       |
  353|     36|        rc = SSH_PACKET_ALLOWED;
  354|     36|        break;
  355|      1|    case SSH2_MSG_KEXDH_INIT:                         // 30
  ------------------
  |  |   15|      1|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (355:5): [True: 1, False: 62.5k]
  ------------------
  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|      1|        if (session->client) {
  ------------------
  |  Branch (373:13): [True: 1, False: 0]
  ------------------
  374|      1|            rc = SSH_PACKET_DENIED;
  375|      1|            break;
  376|      1|        }
  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|    180|    case SSH2_MSG_KEXDH_REPLY:                        // 31
  ------------------
  |  |   16|    180|#define SSH2_MSG_KEXDH_REPLY 31
  ------------------
  |  Branch (391:5): [True: 180, False: 62.4k]
  ------------------
  392|       |      // SSH2_MSG_KEX_ECDH_REPLY:                     // 31
  393|       |      // SSH2_MSG_KEX_HYBRID_REPLY:                   // 31
  394|       |      // SSH2_MSG_KEX_DH_GEX_GROUP:                   // 31
  395|       |
  396|       |        /* Client only */
  397|       |
  398|       |        /*
  399|       |         * States required:
  400|       |         * - session_state == SSH_SESSION_STATE_DH
  401|       |         * - dh_handshake_state == DH_STATE_INIT_SENT
  402|       |         *   or dh_handshake_state == DH_STATE_REQUEST_SENT (dh-gex)
  403|       |         *
  404|       |         * Transitions:
  405|       |         * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  406|       |         * */
  407|       |
  408|    180|        if (session->server) {
  ------------------
  |  Branch (408:13): [True: 0, False: 180]
  ------------------
  409|      0|            rc = SSH_PACKET_DENIED;
  410|      0|            break;
  411|      0|        }
  412|       |
  413|    180|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (413:13): [True: 0, False: 180]
  ------------------
  414|      0|            rc = SSH_PACKET_DENIED;
  415|      0|            break;
  416|      0|        }
  417|       |
  418|    180|        if (session->dh_handshake_state != DH_STATE_INIT_SENT &&
  ------------------
  |  Branch (418:13): [True: 7, False: 173]
  ------------------
  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|    180|        rc = SSH_PACKET_ALLOWED;
  425|    180|        break;
  426|      2|    case SSH2_MSG_KEX_DH_GEX_INIT:                    // 32
  ------------------
  |  |   24|      2|#define SSH2_MSG_KEX_DH_GEX_INIT 32
  ------------------
  |  Branch (426:5): [True: 2, False: 62.5k]
  ------------------
  427|       |      // SSH2_MSG_KEXGSS_COMPLETE:                    // 32
  428|      2|        if (ssh_kex_is_gss(session->next_crypto)) {
  ------------------
  |  Branch (428:13): [True: 0, False: 2]
  ------------------
  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|      2|        } 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|      2|            if (session->client) {
  ------------------
  |  Branch (472:17): [True: 2, False: 0]
  ------------------
  473|      2|                rc = SSH_PACKET_DENIED;
  474|      2|                break;
  475|      2|            }
  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|    617|    case SSH2_MSG_KEX_DH_GEX_REPLY:                   // 33
  ------------------
  |  |   25|    617|#define SSH2_MSG_KEX_DH_GEX_REPLY 33
  ------------------
  |  Branch (490:5): [True: 617, False: 61.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|    617|        if (session->server) {
  ------------------
  |  Branch (503:13): [True: 0, False: 617]
  ------------------
  504|      0|            rc = SSH_PACKET_DENIED;
  505|      0|            break;
  506|      0|        }
  507|       |
  508|    617|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (508:13): [True: 0, False: 617]
  ------------------
  509|      0|            rc = SSH_PACKET_DENIED;
  510|      0|            break;
  511|      0|        }
  512|       |
  513|    617|        if (session->dh_handshake_state != DH_STATE_INIT_SENT) {
  ------------------
  |  Branch (513:13): [True: 0, False: 617]
  ------------------
  514|      0|            rc = SSH_PACKET_DENIED;
  515|      0|            break;
  516|      0|        }
  517|       |
  518|    617|        rc = SSH_PACKET_ALLOWED;
  519|    617|        break;
  520|      1|    case SSH2_MSG_KEX_DH_GEX_REQUEST:                 // 34
  ------------------
  |  |   26|      1|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (520:5): [True: 1, False: 62.5k]
  ------------------
  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|      1|        if (session->client) {
  ------------------
  |  Branch (535:13): [True: 1, False: 0]
  ------------------
  536|      1|            rc = SSH_PACKET_DENIED;
  537|      1|            break;
  538|      1|        }
  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|      0|    case SSH2_MSG_USERAUTH_REQUEST:                   // 50
  ------------------
  |  |   36|      0|#define SSH2_MSG_USERAUTH_REQUEST 50
  ------------------
  |  Branch (553:5): [True: 0, False: 62.5k]
  ------------------
  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|      0|        if (session->client) {
  ------------------
  |  Branch (567:13): [True: 0, False: 0]
  ------------------
  568|      0|            rc = SSH_PACKET_DENIED;
  569|      0|            break;
  570|      0|        }
  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|      2|    case SSH2_MSG_USERAUTH_FAILURE:                   // 51
  ------------------
  |  |   37|      2|#define SSH2_MSG_USERAUTH_FAILURE 51
  ------------------
  |  Branch (584:5): [True: 2, False: 62.5k]
  ------------------
  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|      2|        if (session->server) {
  ------------------
  |  Branch (605:13): [True: 0, False: 2]
  ------------------
  606|      0|            rc = SSH_PACKET_DENIED;
  607|      0|            break;
  608|      0|        }
  609|       |
  610|      2|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (610:13): [True: 2, False: 0]
  ------------------
  611|      2|            rc = SSH_PACKET_DENIED;
  612|      2|            break;
  613|      2|        }
  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|      2|    case SSH2_MSG_USERAUTH_SUCCESS:                   // 52
  ------------------
  |  |   38|      2|#define SSH2_MSG_USERAUTH_SUCCESS 52
  ------------------
  |  Branch (622:5): [True: 2, False: 62.5k]
  ------------------
  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|      2|        if (session->server) {
  ------------------
  |  Branch (642:13): [True: 0, False: 2]
  ------------------
  643|      0|            rc = SSH_PACKET_DENIED;
  644|      0|            break;
  645|      0|        }
  646|       |
  647|      2|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (647:13): [True: 2, False: 0]
  ------------------
  648|      2|            rc = SSH_PACKET_DENIED;
  649|      2|            break;
  650|      2|        }
  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: 62.5k]
  ------------------
  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|      1|    case SSH2_MSG_USERAUTH_PK_OK:                     // 60
  ------------------
  |  |   40|      1|#define SSH2_MSG_USERAUTH_PK_OK 60
  ------------------
  |  Branch (685:5): [True: 1, False: 62.5k]
  ------------------
  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|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (710:13): [True: 1, False: 0]
  ------------------
  711|      1|            rc = SSH_PACKET_DENIED;
  712|      1|            break;
  713|      1|        }
  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: 62.5k]
  ------------------
  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: 62.5k]
  ------------------
  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: 62.5k]
  ------------------
  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: 62.5k]
  ------------------
  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: 62.5k]
  ------------------
  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|      1|    case SSH2_MSG_GLOBAL_REQUEST:                     // 80
  ------------------
  |  |   51|      1|#define SSH2_MSG_GLOBAL_REQUEST 80
  ------------------
  |  Branch (873:5): [True: 1, False: 62.5k]
  ------------------
  874|       |        /*
  875|       |         * States required:
  876|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  877|       |         *
  878|       |         * Transitions:
  879|       |         * - None
  880|       |         * */
  881|       |
  882|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (882:13): [True: 1, False: 0]
  ------------------
  883|      1|            rc = SSH_PACKET_DENIED;
  884|      1|            break;
  885|      1|        }
  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: 62.5k]
  ------------------
  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: 62.5k]
  ------------------
  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|      1|    case SSH2_MSG_CHANNEL_OPEN:                       // 90
  ------------------
  |  |   54|      1|#define SSH2_MSG_CHANNEL_OPEN 90
  ------------------
  |  Branch (927:5): [True: 1, False: 62.5k]
  ------------------
  928|       |        /*
  929|       |         * States required:
  930|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  931|       |         *
  932|       |         * Transitions:
  933|       |         * - None
  934|       |         * */
  935|       |
  936|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (936:13): [True: 1, False: 0]
  ------------------
  937|      1|            rc = SSH_PACKET_DENIED;
  938|      1|            break;
  939|      1|        }
  940|       |
  941|      0|        rc = SSH_PACKET_ALLOWED;
  942|      0|        break;
  943|      2|    case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION:          // 91
  ------------------
  |  |   55|      2|#define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
  ------------------
  |  Branch (943:5): [True: 2, False: 62.5k]
  ------------------
  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|      2|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (953:13): [True: 2, False: 0]
  ------------------
  954|      2|            rc = SSH_PACKET_DENIED;
  955|      2|            break;
  956|      2|        }
  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: 62.5k]
  ------------------
  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|      2|    case SSH2_MSG_CHANNEL_WINDOW_ADJUST:              // 93
  ------------------
  |  |   57|      2|#define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93
  ------------------
  |  Branch (976:5): [True: 2, False: 62.5k]
  ------------------
  977|       |        /*
  978|       |         * States required:
  979|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  980|       |         *
  981|       |         * Transitions:
  982|       |         * - None
  983|       |         * */
  984|       |
  985|      2|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (985:13): [True: 2, False: 0]
  ------------------
  986|      2|            rc = SSH_PACKET_DENIED;
  987|      2|            break;
  988|      2|        }
  989|       |
  990|      0|        rc = SSH_PACKET_ALLOWED;
  991|      0|        break;
  992|      0|    case SSH2_MSG_CHANNEL_DATA:                       // 94
  ------------------
  |  |   58|      0|#define SSH2_MSG_CHANNEL_DATA 94
  ------------------
  |  Branch (992:5): [True: 0, False: 62.5k]
  ------------------
  993|       |        /*
  994|       |         * States required:
  995|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  996|       |         *
  997|       |         * Transitions:
  998|       |         * - None
  999|       |         * */
 1000|       |
 1001|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1001:13): [True: 0, False: 0]
  ------------------
 1002|      0|            rc = SSH_PACKET_DENIED;
 1003|      0|            break;
 1004|      0|        }
 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: 62.5k]
  ------------------
 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|      2|    case SSH2_MSG_CHANNEL_EOF:                        // 96
  ------------------
  |  |   60|      2|#define SSH2_MSG_CHANNEL_EOF	96
  ------------------
  |  Branch (1024:5): [True: 2, False: 62.5k]
  ------------------
 1025|       |        /*
 1026|       |         * States required:
 1027|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1028|       |         *
 1029|       |         * Transitions:
 1030|       |         * - None
 1031|       |         * */
 1032|       |
 1033|      2|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1033:13): [True: 2, False: 0]
  ------------------
 1034|      2|            rc = SSH_PACKET_DENIED;
 1035|      2|            break;
 1036|      2|        }
 1037|       |
 1038|      0|        rc = SSH_PACKET_ALLOWED;
 1039|      0|        break;
 1040|      1|    case SSH2_MSG_CHANNEL_CLOSE:                      // 97
  ------------------
  |  |   61|      1|#define SSH2_MSG_CHANNEL_CLOSE 97
  ------------------
  |  Branch (1040:5): [True: 1, False: 62.5k]
  ------------------
 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|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1050:13): [True: 1, False: 0]
  ------------------
 1051|      1|            rc = SSH_PACKET_DENIED;
 1052|      1|            break;
 1053|      1|        }
 1054|       |
 1055|      0|        rc = SSH_PACKET_ALLOWED;
 1056|      0|        break;
 1057|      2|    case SSH2_MSG_CHANNEL_REQUEST:                    // 98
  ------------------
  |  |   62|      2|#define SSH2_MSG_CHANNEL_REQUEST 98
  ------------------
  |  Branch (1057:5): [True: 2, False: 62.5k]
  ------------------
 1058|       |        /*
 1059|       |         * States required:
 1060|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1061|       |         *
 1062|       |         * Transitions:
 1063|       |         * - Depends on the request
 1064|       |         * */
 1065|       |
 1066|      2|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1066:13): [True: 2, False: 0]
  ------------------
 1067|      2|            rc = SSH_PACKET_DENIED;
 1068|      2|            break;
 1069|      2|        }
 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: 62.5k]
  ------------------
 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: 62.5k]
  ------------------
 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|  1.88k|    case SSH2_MSG_PING: // 192
  ------------------
  |  |   69|  1.88k|#define SSH2_MSG_PING 192
  ------------------
  |  Branch (1111:5): [True: 1.88k, False: 60.7k]
  ------------------
 1112|  1.88k|    case SSH2_MSG_PONG: // 193
  ------------------
  |  |   70|  1.88k|#define SSH2_MSG_PONG 193
  ------------------
  |  Branch (1112:5): [True: 0, False: 62.5k]
  ------------------
 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|  1.88k|        rc = SSH_PACKET_ALLOWED;
 1128|  1.88k|        break;
 1129|  33.3k|    default:
  ------------------
  |  Branch (1129:5): [True: 33.3k, False: 29.2k]
  ------------------
 1130|       |        /* Unknown message, do not filter */
 1131|  33.3k|        rc = SSH_PACKET_UNKNOWN;
 1132|  33.3k|        goto end;
 1133|  62.5k|    }
 1134|       |
 1135|  62.5k|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|  62.5k|    return rc;
 1149|  62.5k|}
packet.c:ssh_packet_need_rekey:
 1201|  97.8k|{
 1202|  97.8k|    bool data_rekey_needed = false;
 1203|  97.8k|    struct ssh_crypto_struct *crypto = NULL;
 1204|  97.8k|    struct ssh_cipher_struct *out_cipher = NULL, *in_cipher = NULL;
 1205|  97.8k|    uint32_t next_blocks;
 1206|       |
 1207|       |    /* We can safely rekey only in authenticated state */
 1208|  97.8k|    if ((session->flags & SSH_SESSION_FLAG_AUTHENTICATED) == 0) {
  ------------------
  |  |   78|  97.8k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (1208:9): [True: 97.8k, False: 0]
  ------------------
 1209|  97.8k|        return false;
 1210|  97.8k|    }
 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|    475|{
 1655|    475|    ssh_session session = userdata;
 1656|    475|    struct ssh_iterator *it = NULL;
 1657|    475|    ssh_channel channel = NULL;
 1658|       |
 1659|    475|    if (code == SSH_SOCKET_FLOW_WRITEWONTBLOCK) {
  ------------------
  |  |  519|    475|#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
  ------------------
  |  Branch (1659:9): [True: 475, False: 0]
  ------------------
 1660|    475|        SSH_LOG(SSH_LOG_TRACE, "sending channel_write_wontblock callback");
  ------------------
  |  |  283|    475|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1661|       |
 1662|       |        /* the out pipe is empty so we can forward this to channels */
 1663|    475|        it = ssh_list_get_iterator(session->channels);
 1664|    475|        while (it != NULL) {
  ------------------
  |  Branch (1664:16): [True: 0, False: 475]
  ------------------
 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|    475|    }
 1675|    475|}
packet.c:ssh_packet_in_rekey:
 2056|  35.3k|{
 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|  35.3k|    return (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) &&
  ------------------
  |  |   78|  35.3k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (2061:12): [True: 0, False: 35.3k]
  ------------------
 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|  35.3k|}
packet.c:packet_send2:
 1896|  35.3k|{
 1897|  35.3k|    unsigned int blocksize = 8;
 1898|  35.3k|    unsigned int lenfield_blocksize = 0;
 1899|  35.3k|    enum ssh_hmac_e hmac_type;
 1900|  35.3k|    uint32_t currentlen = ssh_buffer_get_len(session->out_buffer);
 1901|  35.3k|    struct ssh_crypto_struct *crypto = NULL;
 1902|  35.3k|    unsigned char *hmac = NULL;
 1903|  35.3k|    uint8_t padding_data[32] = { 0 };
 1904|  35.3k|    uint8_t padding_size;
 1905|  35.3k|    uint32_t finallen, payloadsize, compsize;
 1906|  35.3k|    uint8_t header[5] = {0};
 1907|  35.3k|    uint8_t type, *payload;
 1908|  35.3k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  35.3k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1909|  35.3k|    bool etm = false;
 1910|  35.3k|    int etm_packet_offset = 0;
 1911|       |
 1912|  35.3k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
 1913|  35.3k|    if (crypto) {
  ------------------
  |  Branch (1913:9): [True: 590, False: 34.7k]
  ------------------
 1914|    590|        blocksize = crypto->out_cipher->blocksize;
 1915|    590|        lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
 1916|    590|        hmac_type = crypto->out_hmac;
 1917|    590|        etm = crypto->out_hmac_etm;
 1918|  34.7k|    } else {
 1919|  34.7k|        hmac_type = session->next_crypto->out_hmac;
 1920|  34.7k|    }
 1921|       |
 1922|  35.3k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 1923|  35.3k|    type = payload[0]; /* type is the first byte of the packet now */
 1924|       |
 1925|  35.3k|    payloadsize = currentlen;
 1926|  35.3k|    if (etm) {
  ------------------
  |  Branch (1926:9): [True: 0, False: 35.3k]
  ------------------
 1927|      0|        etm_packet_offset = sizeof(uint32_t);
 1928|      0|        lenfield_blocksize = 0;
 1929|      0|    }
 1930|       |
 1931|  35.3k|    if (crypto != NULL && crypto->do_compress_out &&
  ------------------
  |  Branch (1931:9): [True: 590, False: 34.7k]
  |  Branch (1931:27): [True: 0, False: 590]
  ------------------
 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|  35.3k|    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|  35.3k|    padding_size = (blocksize - ((blocksize - lenfield_blocksize - etm_packet_offset + currentlen + 5) % blocksize));
 1943|  35.3k|    if (padding_size < 4) {
  ------------------
  |  Branch (1943:9): [True: 61, False: 35.2k]
  ------------------
 1944|     61|        padding_size += blocksize;
 1945|     61|    }
 1946|       |
 1947|  35.3k|    if (crypto != NULL) {
  ------------------
  |  Branch (1947:9): [True: 590, False: 34.7k]
  ------------------
 1948|    590|        int ok;
 1949|       |
 1950|    590|        ok = ssh_get_random(padding_data, padding_size, 0);
 1951|    590|        if (!ok) {
  ------------------
  |  Branch (1951:13): [True: 0, False: 590]
  ------------------
 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|    590|    }
 1956|       |
 1957|  35.3k|    finallen = currentlen - etm_packet_offset + padding_size + 1;
 1958|       |
 1959|  35.3k|    PUSH_BE_U32(header, 0, finallen);
  ------------------
  |  |   89|  35.3k|    (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|  35.3k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  35.3k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  35.3k|    (((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|  35.3k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  35.3k|    (((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|  35.3k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  35.3k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  35.3k|    (((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|  35.3k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  35.3k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1960|  35.3k|    PUSH_BE_U8(header, 4, padding_size);
  ------------------
  |  |   83|  35.3k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  ------------------
  |  |  |  |   31|  35.3k|    (((uint8_t *)(data))[(pos)])
  |  |  ------------------
  ------------------
 1961|       |
 1962|  35.3k|    rc = ssh_buffer_prepend_data(session->out_buffer,
 1963|  35.3k|                                 header,
 1964|  35.3k|                                 sizeof(header));
 1965|  35.3k|    if (rc < 0) {
  ------------------
  |  Branch (1965:9): [True: 0, False: 35.3k]
  ------------------
 1966|      0|        goto error;
 1967|      0|    }
 1968|       |
 1969|  35.3k|    rc = ssh_buffer_add_data(session->out_buffer, padding_data, padding_size);
 1970|  35.3k|    if (rc < 0) {
  ------------------
  |  Branch (1970:9): [True: 0, False: 35.3k]
  ------------------
 1971|      0|        goto error;
 1972|      0|    }
 1973|       |
 1974|  35.3k|#ifdef WITH_PCAP
 1975|  35.3k|    if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1975:9): [True: 0, False: 35.3k]
  ------------------
 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|  35.3k|#endif
 1983|       |
 1984|  35.3k|    hmac = ssh_packet_encrypt(session,
 1985|  35.3k|                              ssh_buffer_get(session->out_buffer),
 1986|  35.3k|                              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|  35.3k|    if (hmac != NULL) {
  ------------------
  |  Branch (1990:9): [True: 590, False: 34.7k]
  ------------------
 1991|    590|        rc = ssh_buffer_add_data(session->out_buffer,
 1992|    590|                                 hmac,
 1993|    590|                                 (uint32_t)hmac_digest_len(hmac_type));
 1994|    590|        if (rc < 0) {
  ------------------
  |  Branch (1994:13): [True: 0, False: 590]
  ------------------
 1995|      0|            goto error;
 1996|      0|        }
 1997|    590|    }
 1998|       |
 1999|  35.3k|    rc = ssh_packet_write(session);
 2000|  35.3k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  35.3k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (2000:9): [True: 0, False: 35.3k]
  ------------------
 2001|      0|        goto error;
 2002|      0|    }
 2003|  35.3k|    session->send_seq++;
 2004|  35.3k|    if (crypto != NULL) {
  ------------------
  |  Branch (2004:9): [True: 590, False: 34.7k]
  ------------------
 2005|    590|        struct ssh_cipher_struct *cipher = NULL;
 2006|       |
 2007|    590|        cipher = crypto->out_cipher;
 2008|    590|        cipher->packets++;
 2009|    590|        cipher->blocks += payloadsize / cipher->blocksize;
 2010|    590|    }
 2011|  35.3k|    if (session->raw_counter != NULL) {
  ------------------
  |  Branch (2011:9): [True: 0, False: 35.3k]
  ------------------
 2012|      0|        session->raw_counter->out_bytes += payloadsize;
 2013|      0|        session->raw_counter->out_packets++;
 2014|      0|    }
 2015|       |
 2016|  35.3k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|  35.3k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2017|  35.3k|            "packet: wrote [type=%u, len=%" PRIu32 ", padding_size=%hhd, comp=%" PRIu32 ", "
 2018|  35.3k|            "payload=%" PRIu32 "]",
 2019|  35.3k|            type,
 2020|  35.3k|            finallen,
 2021|  35.3k|            padding_size,
 2022|  35.3k|            compsize,
 2023|  35.3k|            payloadsize);
 2024|       |
 2025|  35.3k|    rc = ssh_buffer_reinit(session->out_buffer);
 2026|  35.3k|    if (rc < 0) {
  ------------------
  |  Branch (2026:9): [True: 0, False: 35.3k]
  ------------------
 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|  35.3k|    if (type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  35.3k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2036:9): [True: 54, False: 35.2k]
  ------------------
 2037|     54|        rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_OUT);
 2038|     54|    }
 2039|  35.3k|error:
 2040|  35.3k|    return rc; /* SSH_OK, AGAIN or ERROR */
 2041|  35.3k|}
packet.c:ssh_packet_write:
 1885|  35.3k|static int ssh_packet_write(ssh_session session) {
 1886|  35.3k|  int rc = SSH_ERROR;
  ------------------
  |  |  317|  35.3k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1887|       |
 1888|  35.3k|  rc=ssh_socket_write(session->socket,
 1889|  35.3k|      ssh_buffer_get(session->out_buffer),
 1890|  35.3k|      ssh_buffer_get_len(session->out_buffer));
 1891|       |
 1892|  35.3k|  return rc;
 1893|  35.3k|}
packet.c:ssh_init_rekey_state:
 2241|    108|{
 2242|       |    /* Reset the counters: should be NOOP */
 2243|    108|    cipher->packets = 0;
 2244|    108|    cipher->blocks = 0;
 2245|       |
 2246|       |    /* Default rekey limits for ciphers as specified in RFC4344, Section 3.2 */
 2247|    108|    if (cipher->blocksize >= 16) {
  ------------------
  |  Branch (2247:9): [True: 0, False: 108]
  ------------------
 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|    108|    } else {
 2251|       |        /* For smaller blocks use limit of 1 GB as recommended in RFC4253 */
 2252|    108|        cipher->max_blocks = ((uint64_t)1 << 30) / cipher->blocksize;
 2253|    108|    }
 2254|       |    /* If we have limit provided by user, use the smaller one */
 2255|    108|    if (session->opts.rekey_data != 0) {
  ------------------
  |  Branch (2255:9): [True: 0, False: 108]
  ------------------
 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|    108|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|    108|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2261|    108|            "Set rekey after %" PRIu64 " blocks",
 2262|    108|            cipher->max_blocks);
 2263|    108|}

ssh_packet_disconnect_callback:
   53|      2|{
   54|      2|    int rc;
   55|      2|    uint32_t code = 0;
   56|      2|    char *error = NULL;
   57|      2|    ssh_string error_s = NULL;
   58|       |
   59|      2|    (void)user;
   60|      2|    (void)type;
   61|       |
   62|      2|    rc = ssh_buffer_get_u32(packet, &code);
   63|      2|    if (rc != 0) {
  ------------------
  |  Branch (63:9): [True: 2, False: 0]
  ------------------
   64|      2|        code = ntohl(code);
   65|      2|    }
   66|       |
   67|      2|    error_s = ssh_buffer_get_ssh_string(packet);
   68|      2|    if (error_s != NULL) {
  ------------------
  |  Branch (68:9): [True: 1, False: 1]
  ------------------
   69|      1|        error = ssh_string_to_char(error_s);
   70|      1|        SSH_STRING_FREE(error_s);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
   71|      1|    }
   72|       |
   73|      2|    if (error != NULL) {
  ------------------
  |  Branch (73:9): [True: 1, False: 1]
  ------------------
   74|      1|        session->peer_discon_msg = strdup(error);
   75|      1|    }
   76|       |
   77|      2|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  283|      4|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 1, False: 1]
  |  |  ------------------
  ------------------
   78|      2|            "Received SSH_MSG_DISCONNECT %" PRIu32 ":%s",
   79|      2|            code,
   80|      2|            error != NULL ? error : "no error");
   81|      2|    ssh_set_error(session,
  ------------------
  |  |  313|      4|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (313:43): [True: 1, False: 1]
  |  |  ------------------
  ------------------
   82|      2|                  SSH_FATAL,
   83|      2|                  "Received SSH_MSG_DISCONNECT: %" PRIu32 ":%s",
   84|      2|                  code,
   85|      2|                  error != NULL ? error : "no error");
   86|      2|    SAFE_FREE(error);
  ------------------
  |  |  375|      2|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1, False: 1]
  |  |  |  Branch (375:71): [Folded, False: 2]
  |  |  ------------------
  ------------------
   87|       |
   88|      2|    ssh_session_socket_close(session);
   89|       |    /* correctly handle disconnect during authorization */
   90|      2|    session->auth.state = SSH_AUTH_STATE_FAILED;
   91|       |
   92|       |    /* TODO: handle a graceful disconnect */
   93|      2|    return SSH_PACKET_USED;
  ------------------
  |  |  638|      2|#define SSH_PACKET_USED 1
  ------------------
   94|      2|}
ssh_packet_ignore_callback:
  102|    134|{
  103|    134|    (void)session; /* unused */
  104|    134|    (void)user;
  105|    134|    (void)type;
  106|    134|    (void)packet;
  107|       |
  108|    134|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_IGNORE packet");
  ------------------
  |  |  283|    134|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  109|       |
  110|    134|    return SSH_PACKET_USED;
  ------------------
  |  |  638|    134|#define SSH_PACKET_USED 1
  ------------------
  111|    134|}
ssh_packet_debug_callback:
  119|  25.3k|{
  120|  25.3k|    uint8_t always_display = -1;
  121|  25.3k|    char *message = NULL;
  122|  25.3k|    int rc;
  123|       |
  124|  25.3k|    (void)session; /* unused */
  125|  25.3k|    (void)type;
  126|  25.3k|    (void)user;
  127|       |
  128|  25.3k|    rc = ssh_buffer_unpack(packet, "bs", &always_display, &message);
  ------------------
  |  |   60|  25.3k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|  25.3k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|  25.3k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|  25.3k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|  25.3k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|  25.3k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  25.3k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  129|  25.3k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  25.3k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (129:9): [True: 21.9k, False: 3.41k]
  ------------------
  130|  21.9k|        SSH_LOG(SSH_LOG_PACKET, "Error reading debug message");
  ------------------
  |  |  283|  21.9k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  131|  21.9k|        return SSH_PACKET_USED;
  ------------------
  |  |  638|  21.9k|#define SSH_PACKET_USED 1
  ------------------
  132|  21.9k|    }
  133|  3.41k|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|  6.83k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 3.41k, False: 0]
  |  |  ------------------
  ------------------
  134|  3.41k|            "Received SSH_MSG_DEBUG packet with message %s%s",
  135|  3.41k|            message,
  136|  3.41k|            always_display != 0 ? " (always display)" : "");
  137|  3.41k|    SAFE_FREE(message);
  ------------------
  |  |  375|  3.41k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 3.41k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 3.41k]
  |  |  ------------------
  ------------------
  138|       |
  139|  3.41k|    return SSH_PACKET_USED;
  ------------------
  |  |  638|  3.41k|#define SSH_PACKET_USED 1
  ------------------
  140|  25.3k|}
ssh_packet_newkeys:
  143|     36|{
  144|     36|    ssh_string sig_blob = NULL;
  145|     36|    ssh_signature sig = NULL;
  146|     36|    int rc;
  147|       |
  148|     36|    (void)packet;
  149|     36|    (void)user;
  150|     36|    (void)type;
  151|       |
  152|     36|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_NEWKEYS");
  ------------------
  |  |  283|     36|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  153|       |
  154|     36|    if (session->session_state != SSH_SESSION_STATE_DH ||
  ------------------
  |  Branch (154:9): [True: 0, False: 36]
  ------------------
  155|     36|        session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (155:9): [True: 0, False: 36]
  ------------------
  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|     36|    if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|     36|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (164:9): [True: 1, False: 35]
  ------------------
  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: 1, False: 0]
  ------------------
  169|      1|            ssh_set_error(session,
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  170|      1|                          SSH_FATAL,
  171|      1|                          "Received unexpected packets in strict KEX mode.");
  172|      1|            goto error;
  173|      1|        }
  174|      1|    }
  175|       |
  176|     35|    if (session->server) {
  ------------------
  |  Branch (176:9): [True: 0, False: 35]
  ------------------
  177|       |        /* server things are done in server.c */
  178|      0|        session->dh_handshake_state=DH_STATE_FINISHED;
  179|     35|    } 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|     35|        {
  218|     35|            ssh_key server_key = NULL;
  219|       |
  220|       |            /* client */
  221|       |
  222|       |            /* Verify the host's signature. FIXME do it sooner */
  223|     35|            sig_blob = session->next_crypto->dh_server_signature;
  224|     35|            session->next_crypto->dh_server_signature = NULL;
  225|       |
  226|       |            /* get the server public key */
  227|     35|            server_key = ssh_dh_get_next_server_publickey(session);
  228|     35|            if (server_key == NULL) {
  ------------------
  |  Branch (228:17): [True: 0, False: 35]
  ------------------
  229|      0|                goto error;
  230|      0|            }
  231|       |
  232|     35|            rc = ssh_pki_import_signature_blob(sig_blob, server_key, &sig);
  233|     35|            ssh_string_burn(sig_blob);
  234|     35|            SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  924|     35|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 35, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 35]
  |  |  ------------------
  ------------------
  235|     35|            if (rc != SSH_OK) {
  ------------------
  |  |  316|     35|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (235:17): [True: 28, False: 7]
  ------------------
  236|     28|                goto error;
  237|     28|            }
  238|       |
  239|       |            /* Check if signature from server matches user preferences */
  240|      7|            if (session->opts.wanted_methods[SSH_HOSTKEYS]) {
  ------------------
  |  Branch (240:17): [True: 0, False: 7]
  ------------------
  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|      7|            rc = ssh_pki_signature_verify(session,
  256|      7|                                          sig,
  257|      7|                                          server_key,
  258|      7|                                          session->next_crypto->secret_hash,
  259|      7|                                          session->next_crypto->digest_len);
  260|      7|            SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|      7|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 7]
  |  |  ------------------
  ------------------
  261|      7|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      7|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (261:17): [True: 7, False: 0]
  ------------------
  262|      7|                ssh_set_error(session,
  ------------------
  |  |  313|      7|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  263|      7|                              SSH_FATAL,
  264|      7|                              "Failed to verify server hostkey signature");
  265|      7|                goto error;
  266|      7|            }
  267|      7|        }
  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|     36|error:
  281|       |#ifdef WITH_GSSAPI
  282|       |    SSH_STRING_FREE(session->gssapi_key_exchange_mic);
  283|       |#endif
  284|     36|    SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|     36|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 36]
  |  |  ------------------
  ------------------
  285|     36|    ssh_string_burn(sig_blob);
  286|     36|    SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  924|     36|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 36]
  |  |  |  Branch (924:69): [Folded, False: 36]
  |  |  ------------------
  ------------------
  287|     36|    session->session_state = SSH_SESSION_STATE_ERROR;
  288|     36|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     36|#define SSH_PACKET_USED 1
  ------------------
  289|     35|}
ssh_packet_ping:
  388|  1.88k|{
  389|  1.88k|    int rc;
  390|  1.88k|    ssh_string payload = NULL;
  391|       |
  392|  1.88k|    (void)type;
  393|  1.88k|    (void)user;
  394|       |
  395|  1.88k|    SSH_LOG(SSH_LOG_PACKET, "Received SSH2_MSG_PING");
  ------------------
  |  |  283|  1.88k|    _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|  1.88k|    if (!(session->flags & SSH_SESSION_FLAG_AUTHENTICATED) &&
  ------------------
  |  |   78|  1.88k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (400:9): [True: 1.88k, False: 0]
  ------------------
  401|  1.88k|        session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (401:9): [True: 1.88k, False: 0]
  ------------------
  402|  1.88k|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|  1.88k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  403|  1.88k|                "Ignoring PING before initial key exchange is complete");
  404|  1.88k|        return SSH_PACKET_USED;
  ------------------
  |  |  638|  1.88k|#define SSH_PACKET_USED 1
  ------------------
  405|  1.88k|    }
  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_decrypt_len:
   55|  62.7k|{
   56|  62.7k|    struct ssh_crypto_struct *crypto = NULL;
   57|  62.7k|    uint32_t decrypted;
   58|  62.7k|    int rc;
   59|       |
   60|  62.7k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
   61|  62.7k|    if (crypto != NULL) {
  ------------------
  |  Branch (61:9): [True: 0, False: 62.7k]
  ------------------
   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|  62.7k|    } else {
   79|  62.7k|        memcpy(destination, source, 8);
   80|  62.7k|    }
   81|  62.7k|    memcpy(&decrypted,destination,sizeof(decrypted));
   82|       |
   83|       |    return ntohl(decrypted);
   84|  62.7k|}
ssh_packet_encrypt:
  134|  35.3k|{
  135|  35.3k|  struct ssh_crypto_struct *crypto = NULL;
  136|  35.3k|  struct ssh_cipher_struct *cipher = NULL;
  137|  35.3k|  HMACCTX ctx = NULL;
  138|  35.3k|  char *out = NULL;
  139|  35.3k|  int etm_packet_offset = 0, rc;
  140|  35.3k|  unsigned int blocksize;
  141|  35.3k|  size_t finallen = DIGEST_MAX_LEN;
  ------------------
  |  |   56|  35.3k|#define DIGEST_MAX_LEN 64
  ------------------
  142|  35.3k|  uint32_t seq, lenfield_blocksize;
  143|  35.3k|  enum ssh_hmac_e type;
  144|  35.3k|  bool etm;
  145|       |
  146|  35.3k|  assert(len);
  ------------------
  |  Branch (146:3): [True: 0, False: 35.3k]
  |  Branch (146:3): [True: 35.3k, False: 0]
  ------------------
  147|       |
  148|  35.3k|  crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
  149|  35.3k|  if (crypto == NULL) {
  ------------------
  |  Branch (149:7): [True: 34.7k, False: 590]
  ------------------
  150|  34.7k|      return NULL; /* nothing to do here */
  151|  34.7k|  }
  152|       |
  153|    590|  blocksize = crypto->out_cipher->blocksize;
  154|    590|  lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
  155|       |
  156|    590|  type = crypto->out_hmac;
  157|    590|  etm = crypto->out_hmac_etm;
  158|       |
  159|    590|  if (etm) {
  ------------------
  |  Branch (159:7): [True: 0, False: 590]
  ------------------
  160|      0|      etm_packet_offset = sizeof(uint32_t);
  161|      0|  }
  162|       |
  163|    590|  if ((len - lenfield_blocksize - etm_packet_offset) % blocksize != 0) {
  ------------------
  |  Branch (163:7): [True: 0, False: 590]
  ------------------
  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|    590|  out = calloc(1, len);
  169|    590|  if (out == NULL) {
  ------------------
  |  Branch (169:7): [True: 0, False: 590]
  ------------------
  170|      0|    return NULL;
  171|      0|  }
  172|       |
  173|    590|  seq = ntohl(session->send_seq);
  174|    590|  cipher = crypto->out_cipher;
  175|       |
  176|    590|  if (cipher->aead_encrypt != NULL) {
  ------------------
  |  Branch (176:7): [True: 0, False: 590]
  ------------------
  177|      0|      cipher->aead_encrypt(cipher, data, out, len,
  178|      0|            crypto->hmacbuf, session->send_seq);
  179|      0|      memcpy(data, out, len);
  180|    590|  } else {
  181|    590|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (181:11): [True: 0, False: 590]
  ------------------
  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|    590|      cipher->encrypt(cipher, (uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  208|    590|      memcpy((uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  209|       |
  210|    590|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (210:11): [True: 0, False: 590]
  ------------------
  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|    590|  }
  238|    590|  ssh_burn(out, len);
  ------------------
  |  |  390|    590|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  239|    590|  SAFE_FREE(out);
  ------------------
  |  |  375|    590|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 590, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 590]
  |  |  ------------------
  ------------------
  240|       |
  241|    590|  return crypto->hmacbuf;
  242|    590|}

ssh_key_new:
  113|     81|{
  114|     81|    ssh_key ptr = malloc (sizeof (struct ssh_key_struct));
  115|     81|    if (ptr == NULL) {
  ------------------
  |  Branch (115:9): [True: 0, False: 81]
  ------------------
  116|      0|        return NULL;
  117|      0|    }
  118|     81|    ZERO_STRUCTP(ptr);
  ------------------
  |  |  381|     81|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (381:34): [True: 81, False: 0]
  |  |  |  Branch (381:85): [Folded, False: 81]
  |  |  ------------------
  ------------------
  119|     81|    return ptr;
  120|     81|}
ssh_key_clean:
  222|     81|{
  223|     81|    if (key == NULL)
  ------------------
  |  Branch (223:9): [True: 0, False: 81]
  ------------------
  224|      0|        return;
  225|       |
  226|     81|    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|     81|    if (key->cert != NULL) {
  ------------------
  |  Branch (235:9): [True: 3, False: 78]
  ------------------
  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|     81|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|     81|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 5, False: 76]
  |  |  |  Branch (153:38): [True: 0, False: 76]
  |  |  ------------------
  |  |  154|     81|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 2, False: 74]
  |  |  ------------------
  |  |  155|     81|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1, False: 73]
  |  |  ------------------
  ------------------
  239|      8|        ssh_string_burn(key->sk_application);
  240|      8|        ssh_string_free(key->sk_application);
  241|      8|        ssh_string_burn(key->sk_key_handle);
  242|      8|        ssh_string_free(key->sk_key_handle);
  243|      8|        ssh_string_burn(key->sk_reserved);
  244|      8|        ssh_string_free(key->sk_reserved);
  245|      8|        ssh_string_burn(key->sk_user_id);
  246|      8|        ssh_string_free(key->sk_user_id);
  247|      8|        key->sk_flags = 0;
  248|      8|    }
  249|     81|    key->cert_type = SSH_KEYTYPE_UNKNOWN;
  250|     81|    key->flags = SSH_KEY_FLAG_EMPTY;
  ------------------
  |  |   53|     81|#define SSH_KEY_FLAG_EMPTY   0x0
  ------------------
  251|     81|    key->type = SSH_KEYTYPE_UNKNOWN;
  252|     81|    key->ecdsa_nid = 0;
  253|       |    key->type_c = NULL;
  254|     81|}
ssh_key_free:
  261|  3.77k|{
  262|  3.77k|    if (key) {
  ------------------
  |  Branch (262:9): [True: 81, False: 3.69k]
  ------------------
  263|     81|        ssh_key_clean(key);
  264|       |        SAFE_FREE(key);
  ------------------
  |  |  375|     81|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 81, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 81]
  |  |  ------------------
  ------------------
  265|     81|    }
  266|  3.77k|}
ssh_key_type:
  280|      7|{
  281|      7|    if (key == NULL) {
  ------------------
  |  Branch (281:9): [True: 0, False: 7]
  ------------------
  282|      0|        return SSH_KEYTYPE_UNKNOWN;
  283|      0|    }
  284|      7|    return key->type;
  285|      7|}
ssh_key_signature_to_char:
  367|      9|{
  368|      9|    switch (type) {
  369|      9|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (369:5): [True: 9, False: 0]
  ------------------
  370|      9|        switch (hash_type) {
  371|      2|        case SSH_DIGEST_SHA256:
  ------------------
  |  Branch (371:9): [True: 2, False: 7]
  ------------------
  372|      2|            return "rsa-sha2-256";
  373|      7|        case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (373:9): [True: 7, False: 2]
  ------------------
  374|      7|            return "rsa-sha2-512";
  375|      0|        case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (375:9): [True: 0, False: 9]
  ------------------
  376|      0|        case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (376:9): [True: 0, False: 9]
  ------------------
  377|      0|            return "ssh-rsa";
  378|      0|        default:
  ------------------
  |  Branch (378:9): [True: 0, False: 9]
  ------------------
  379|      0|            return NULL;
  380|      9|        }
  381|      0|        break;
  382|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (382:5): [True: 0, False: 9]
  ------------------
  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: 9]
  ------------------
  396|      0|        return ssh_key_type_to_char(type);
  397|      9|    }
  398|       |
  399|       |    /* We should never reach this */
  400|      0|    return NULL;
  401|      9|}
ssh_key_type_to_char:
  410|     95|const char *ssh_key_type_to_char(enum ssh_keytypes_e type) {
  411|     95|  switch (type) {
  ------------------
  |  Branch (411:11): [True: 95, False: 0]
  ------------------
  412|     59|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (412:5): [True: 59, False: 36]
  ------------------
  413|     59|      return "ssh-rsa";
  414|      0|    case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (414:5): [True: 0, False: 95]
  ------------------
  415|      0|      return "ssh-ecdsa"; /* deprecated. invalid value */
  416|      5|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (416:5): [True: 5, False: 90]
  ------------------
  417|      5|      return "ecdsa-sha2-nistp256";
  418|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (418:5): [True: 0, False: 95]
  ------------------
  419|      0|      return "ecdsa-sha2-nistp384";
  420|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (420:5): [True: 0, False: 95]
  ------------------
  421|      0|      return "ecdsa-sha2-nistp521";
  422|      9|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (422:5): [True: 9, False: 86]
  ------------------
  423|      9|      return "ssh-ed25519";
  424|      1|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (424:5): [True: 1, False: 94]
  ------------------
  425|      1|      return "ssh-rsa-cert-v01@openssh.com";
  426|      1|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (426:5): [True: 1, False: 94]
  ------------------
  427|      1|      return "ecdsa-sha2-nistp256-cert-v01@openssh.com";
  428|      0|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (428:5): [True: 0, False: 95]
  ------------------
  429|      0|      return "ecdsa-sha2-nistp384-cert-v01@openssh.com";
  430|      0|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (430:5): [True: 0, False: 95]
  ------------------
  431|      0|      return "ecdsa-sha2-nistp521-cert-v01@openssh.com";
  432|      2|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (432:5): [True: 2, False: 93]
  ------------------
  433|      2|      return "ssh-ed25519-cert-v01@openssh.com";
  434|      9|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (434:5): [True: 9, False: 86]
  ------------------
  435|      9|      return "sk-ecdsa-sha2-nistp256@openssh.com";
  436|      1|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (436:5): [True: 1, False: 94]
  ------------------
  437|      1|      return "sk-ssh-ed25519@openssh.com";
  438|      7|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (438:5): [True: 7, False: 88]
  ------------------
  439|      7|      return "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com";
  440|      1|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (440:5): [True: 1, False: 94]
  ------------------
  441|      1|      return "sk-ssh-ed25519-cert-v01@openssh.com";
  442|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (442:5): [True: 0, False: 95]
  ------------------
  443|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (443:5): [True: 0, False: 95]
  ------------------
  444|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (444:5): [True: 0, False: 95]
  ------------------
  445|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (445:5): [True: 0, False: 95]
  ------------------
  446|      0|      return NULL;
  447|     95|  }
  448|       |
  449|       |  /* We should never reach this */
  450|      0|  return NULL;
  451|     95|}
ssh_key_type_and_hash_from_signature_name:
  472|     34|{
  473|     34|    size_t len;
  474|       |
  475|     34|    if (name == NULL || type == NULL || hash_type == NULL) {
  ------------------
  |  Branch (475:9): [True: 0, False: 34]
  |  Branch (475:25): [True: 0, False: 34]
  |  Branch (475:41): [True: 0, False: 34]
  ------------------
  476|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  477|      0|    }
  478|       |
  479|     34|    len = strlen(name);
  480|       |
  481|     34|    if (len == 7 && strcmp(name, "ssh-rsa") == 0) {
  ------------------
  |  Branch (481:9): [True: 1, False: 33]
  |  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|     34|    if (len == 11 && strcmp(name, "ssh-ed25519") == 0) {
  ------------------
  |  Branch (487:9): [True: 1, False: 33]
  |  Branch (487:22): [True: 0, False: 1]
  ------------------
  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|     34|    if (len == 12) {
  ------------------
  |  Branch (493:9): [True: 14, False: 20]
  ------------------
  494|     14|        if (strcmp(name, "rsa-sha2-256") == 0) {
  ------------------
  |  Branch (494:13): [True: 2, False: 12]
  ------------------
  495|      2|            *type = SSH_KEYTYPE_RSA;
  496|      2|            *hash_type = SSH_DIGEST_SHA256;
  497|      2|            return SSH_OK;
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
  498|      2|        }
  499|     12|        if (strcmp(name, "rsa-sha2-512") == 0) {
  ------------------
  |  Branch (499:13): [True: 7, False: 5]
  ------------------
  500|      7|            *type = SSH_KEYTYPE_RSA;
  501|      7|            *hash_type = SSH_DIGEST_SHA512;
  502|      7|            return SSH_OK;
  ------------------
  |  |  316|      7|#define SSH_OK 0     /* No error */
  ------------------
  503|      7|        }
  504|     12|    }
  505|       |
  506|     25|    if (len == 19) {
  ------------------
  |  Branch (506:9): [True: 3, False: 22]
  ------------------
  507|      3|        if (strcmp(name, "ecdsa-sha2-nistp256") == 0) {
  ------------------
  |  Branch (507:13): [True: 1, False: 2]
  ------------------
  508|      1|            *type = SSH_KEYTYPE_ECDSA_P256;
  509|      1|            *hash_type = SSH_DIGEST_SHA256;
  510|      1|            return SSH_OK;
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  511|      1|        }
  512|      2|        if (strcmp(name, "ecdsa-sha2-nistp384") == 0) {
  ------------------
  |  Branch (512:13): [True: 0, False: 2]
  ------------------
  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|      2|        if (strcmp(name, "ecdsa-sha2-nistp521") == 0) {
  ------------------
  |  Branch (518:13): [True: 0, False: 2]
  ------------------
  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|      2|    }
  524|       |
  525|     24|    if (len == 26 && strcmp(name, "sk-ssh-ed25519@openssh.com") == 0) {
  ------------------
  |  Branch (525:9): [True: 3, False: 21]
  |  Branch (525:22): [True: 1, False: 2]
  ------------------
  526|      1|        *type = SSH_KEYTYPE_SK_ED25519;
  527|      1|        *hash_type = SSH_DIGEST_AUTO;
  528|      1|        return SSH_OK;
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  529|      1|    }
  530|       |
  531|     23|    if (len == 28 && strcmp(name, "ssh-rsa-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (531:9): [True: 3, False: 20]
  |  Branch (531:22): [True: 0, False: 3]
  ------------------
  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|     23|    if (len == 32 && strcmp(name, "ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (537:9): [True: 1, False: 22]
  |  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|     23|    if (len == 33) {
  ------------------
  |  Branch (543:9): [True: 2, False: 21]
  ------------------
  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|     21|    if (len == 34 && strcmp(name, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (556:9): [True: 1, False: 20]
  |  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|     21|    if (len == 40) {
  ------------------
  |  Branch (562:9): [True: 2, False: 19]
  ------------------
  563|      2|        if (strcmp(name, "ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (563:13): [True: 0, False: 2]
  ------------------
  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|      2|        if (strcmp(name, "ecdsa-sha2-nistp384-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (568:13): [True: 0, False: 2]
  ------------------
  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|      2|        if (strcmp(name, "ecdsa-sha2-nistp521-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (573:13): [True: 0, False: 2]
  ------------------
  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|      2|    }
  579|       |
  580|     21|    SSH_LOG(SSH_LOG_TRACE, "Unknown signature name %s", name);
  ------------------
  |  |  283|     21|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  581|     21|    return SSH_ERROR;
  ------------------
  |  |  317|     21|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  582|     21|}
ssh_key_size_allowed_rsa:
  624|      7|{
  625|      7|    int key_size = ssh_key_size(key);
  626|       |
  627|      7|    if (min_size < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|      7|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (627:9): [True: 7, False: 0]
  ------------------
  628|      7|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|      7|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 7]
  |  |  ------------------
  ------------------
  629|      0|            min_size = RSA_MIN_FIPS_KEY_SIZE;
  ------------------
  |  |   50|      0|#define RSA_MIN_FIPS_KEY_SIZE 2048
  ------------------
  630|      7|        } else {
  631|      7|            min_size = RSA_MIN_KEY_SIZE;
  ------------------
  |  |   49|      7|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  632|      7|        }
  633|      7|    }
  634|      7|    return (key_size >= min_size);
  635|      7|}
ssh_key_size_allowed:
  646|      7|{
  647|      7|    int min_size = 0;
  648|       |
  649|      7|    switch (ssh_key_type(key)) {
  650|      7|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (650:5): [True: 7, False: 0]
  ------------------
  651|      7|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (651:5): [True: 0, False: 7]
  ------------------
  652|      7|        min_size = session->opts.rsa_min_size;
  653|      7|        return ssh_key_size_allowed_rsa(min_size, key);
  654|      0|    default:
  ------------------
  |  Branch (654:5): [True: 0, False: 7]
  ------------------
  655|       |        return true;
  656|      7|    }
  657|      7|}
ssh_key_type_from_name:
  808|    166|{
  809|    166|    if (name == NULL) {
  ------------------
  |  Branch (809:9): [True: 0, False: 166]
  ------------------
  810|      0|        return SSH_KEYTYPE_UNKNOWN;
  811|      0|    }
  812|       |
  813|    166|    if (strcmp(name, "rsa") == 0) {
  ------------------
  |  Branch (813:9): [True: 0, False: 166]
  ------------------
  814|      0|        return SSH_KEYTYPE_RSA;
  815|    166|    } else if (strcmp(name, "ssh-rsa") == 0) {
  ------------------
  |  Branch (815:16): [True: 58, False: 108]
  ------------------
  816|     58|        return SSH_KEYTYPE_RSA;
  817|    108|    } else if (strcmp(name, "ssh-ecdsa") == 0
  ------------------
  |  Branch (817:16): [True: 1, False: 107]
  ------------------
  818|    107|            || strcmp(name, "ecdsa") == 0
  ------------------
  |  Branch (818:16): [True: 1, False: 106]
  ------------------
  819|    106|            || strcmp(name, "ecdsa-sha2-nistp256") == 0) {
  ------------------
  |  Branch (819:16): [True: 2, False: 104]
  ------------------
  820|      4|        return SSH_KEYTYPE_ECDSA_P256;
  821|    104|    } else if (strcmp(name, "ecdsa-sha2-nistp384") == 0) {
  ------------------
  |  Branch (821:16): [True: 0, False: 104]
  ------------------
  822|      0|        return SSH_KEYTYPE_ECDSA_P384;
  823|    104|    } else if (strcmp(name, "ecdsa-sha2-nistp521") == 0) {
  ------------------
  |  Branch (823:16): [True: 0, False: 104]
  ------------------
  824|      0|        return SSH_KEYTYPE_ECDSA_P521;
  825|    104|    } else if (strcmp(name, "ssh-ed25519") == 0){
  ------------------
  |  Branch (825:16): [True: 8, False: 96]
  ------------------
  826|      8|        return SSH_KEYTYPE_ED25519;
  827|     96|    } else if (strcmp(name, "ssh-rsa-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (827:16): [True: 1, False: 95]
  ------------------
  828|      1|        return SSH_KEYTYPE_RSA_CERT01;
  829|     95|    } else if (strcmp(name, "ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (829:16): [True: 1, False: 94]
  ------------------
  830|      1|        return SSH_KEYTYPE_ECDSA_P256_CERT01;
  831|     94|    } else if (strcmp(name, "ecdsa-sha2-nistp384-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (831:16): [True: 0, False: 94]
  ------------------
  832|      0|        return SSH_KEYTYPE_ECDSA_P384_CERT01;
  833|     94|    } else if (strcmp(name, "ecdsa-sha2-nistp521-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (833:16): [True: 0, False: 94]
  ------------------
  834|      0|        return SSH_KEYTYPE_ECDSA_P521_CERT01;
  835|     94|    } else if (strcmp(name, "ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (835:16): [True: 2, False: 92]
  ------------------
  836|      2|        return SSH_KEYTYPE_ED25519_CERT01;
  837|     92|    } else if(strcmp(name, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (837:15): [True: 0, False: 92]
  ------------------
  838|      0|        return SSH_KEYTYPE_SK_ECDSA;
  839|     92|    } else if(strcmp(name, "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (839:15): [True: 7, False: 85]
  ------------------
  840|      7|        return SSH_KEYTYPE_SK_ECDSA_CERT01;
  841|     85|    } else if(strcmp(name, "sk-ssh-ed25519@openssh.com") == 0) {
  ------------------
  |  Branch (841:15): [True: 0, False: 85]
  ------------------
  842|      0|        return SSH_KEYTYPE_SK_ED25519;
  843|     85|    } else if(strcmp(name, "sk-ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (843:15): [True: 1, False: 84]
  ------------------
  844|      1|        return SSH_KEYTYPE_SK_ED25519_CERT01;
  845|      1|    }
  846|       |
  847|     84|    return SSH_KEYTYPE_UNKNOWN;
  848|    166|}
ssh_key_type_plain:
  858|     19|{
  859|     19|    switch (type) {
  860|      0|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (860:9): [True: 0, False: 19]
  ------------------
  861|      0|            return SSH_KEYTYPE_RSA;
  862|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (862:9): [True: 0, False: 19]
  ------------------
  863|      0|            return SSH_KEYTYPE_ECDSA_P256;
  864|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (864:9): [True: 0, False: 19]
  ------------------
  865|      0|            return SSH_KEYTYPE_ECDSA_P384;
  866|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (866:9): [True: 0, False: 19]
  ------------------
  867|      0|            return SSH_KEYTYPE_ECDSA_P521;
  868|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (868:9): [True: 0, False: 19]
  ------------------
  869|      0|            return SSH_KEYTYPE_ED25519;
  870|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (870:9): [True: 0, False: 19]
  ------------------
  871|      0|            return SSH_KEYTYPE_SK_ECDSA;
  872|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (872:9): [True: 0, False: 19]
  ------------------
  873|      0|            return SSH_KEYTYPE_SK_ED25519;
  874|     19|        default:
  ------------------
  |  Branch (874:9): [True: 19, False: 0]
  ------------------
  875|     19|            return type;
  876|     19|    }
  877|     19|}
ssh_key_is_private:
  902|      6|int ssh_key_is_private(const ssh_key k) {
  903|      6|    if (k == NULL) {
  ------------------
  |  Branch (903:9): [True: 0, False: 6]
  ------------------
  904|      0|        return 0;
  905|      0|    }
  906|       |
  907|      6|    return (k->flags & SSH_KEY_FLAG_PRIVATE) == SSH_KEY_FLAG_PRIVATE;
  ------------------
  |  |   55|      6|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
                  return (k->flags & SSH_KEY_FLAG_PRIVATE) == SSH_KEY_FLAG_PRIVATE;
  ------------------
  |  |   55|      6|#define SSH_KEY_FLAG_PRIVATE 0x0002
  ------------------
  908|      6|}
ssh_signature_new:
  997|      9|{
  998|      9|    struct ssh_signature_struct *sig = NULL;
  999|       |
 1000|      9|    sig = calloc(1, sizeof(struct ssh_signature_struct));
 1001|      9|    if (sig == NULL) {
  ------------------
  |  Branch (1001:9): [True: 0, False: 9]
  ------------------
 1002|      0|        return NULL;
 1003|      0|    }
 1004|       |
 1005|      9|    return sig;
 1006|      9|}
ssh_signature_free:
 1009|     45|{
 1010|     45|    if (sig == NULL) {
  ------------------
  |  Branch (1010:9): [True: 36, False: 9]
  ------------------
 1011|     36|        return;
 1012|     36|    }
 1013|       |
 1014|      9|    switch(sig->type) {
  ------------------
  |  Branch (1014:12): [True: 9, False: 0]
  ------------------
 1015|      9|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1015:9): [True: 9, False: 0]
  ------------------
 1016|       |#ifdef HAVE_LIBMBEDCRYPTO
 1017|       |            SAFE_FREE(sig->rsa_sig);
 1018|       |#endif /* HAVE_LIBMBEDCRYPTO */
 1019|      9|            break;
 1020|      0|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1020:9): [True: 0, False: 9]
  ------------------
 1021|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1021:9): [True: 0, False: 9]
  ------------------
 1022|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1022:9): [True: 0, False: 9]
  ------------------
 1023|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1023:9): [True: 0, False: 9]
  ------------------
 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: 9]
  ------------------
 1032|      0|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1032:9): [True: 0, False: 9]
  ------------------
 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: 9]
  ------------------
 1039|      0|        case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (1039:9): [True: 0, False: 9]
  ------------------
 1040|      0|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1040:9): [True: 0, False: 9]
  ------------------
 1041|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1041:9): [True: 0, False: 9]
  ------------------
 1042|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1042:9): [True: 0, False: 9]
  ------------------
 1043|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1043:9): [True: 0, False: 9]
  ------------------
 1044|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1044:9): [True: 0, False: 9]
  ------------------
 1045|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1045:9): [True: 0, False: 9]
  ------------------
 1046|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1046:9): [True: 0, False: 9]
  ------------------
 1047|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1047:9): [True: 0, False: 9]
  ------------------
 1048|      0|        case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (1048:9): [True: 0, False: 9]
  ------------------
 1049|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1049:9): [True: 0, False: 9]
  ------------------
 1050|      0|            break;
 1051|      9|    }
 1052|       |
 1053|       |    /* Explicitly zero the signature content before free */
 1054|      9|    ssh_string_burn(sig->raw_sig);
 1055|      9|    SSH_STRING_FREE(sig->raw_sig);
  ------------------
  |  |  924|      9|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 7, False: 2]
  |  |  |  Branch (924:69): [Folded, False: 9]
  |  |  ------------------
  ------------------
 1056|       |    SAFE_FREE(sig);
  ------------------
  |  |  375|      9|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 9, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 9]
  |  |  ------------------
  ------------------
 1057|      9|}
ssh_pki_import_pubkey_blob:
 2027|    166|{
 2028|    166|    ssh_buffer buffer = NULL;
 2029|    166|    ssh_string type_s = NULL;
 2030|    166|    enum ssh_keytypes_e type;
 2031|    166|    int rc;
 2032|       |
 2033|    166|    if (key_blob == NULL || pkey == NULL) {
  ------------------
  |  Branch (2033:9): [True: 0, False: 166]
  |  Branch (2033:29): [True: 0, False: 166]
  ------------------
 2034|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2035|      0|    }
 2036|       |
 2037|    166|    buffer = ssh_buffer_new();
 2038|    166|    if (buffer == NULL) {
  ------------------
  |  Branch (2038:9): [True: 0, False: 166]
  ------------------
 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|    166|    rc = ssh_buffer_add_data(buffer,
 2044|    166|                             ssh_string_data(key_blob),
 2045|    166|                             (uint32_t)ssh_string_len(key_blob));
 2046|    166|    if (rc < 0) {
  ------------------
  |  Branch (2046:9): [True: 0, False: 166]
  ------------------
 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|    166|    type_s = ssh_buffer_get_ssh_string(buffer);
 2052|    166|    if (type_s == NULL) {
  ------------------
  |  Branch (2052:9): [True: 0, False: 166]
  ------------------
 2053|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2054|      0|        goto fail;
 2055|      0|    }
 2056|       |
 2057|    166|    type = ssh_key_type_from_name(ssh_string_get_char(type_s));
 2058|    166|    if (type == SSH_KEYTYPE_UNKNOWN) {
  ------------------
  |  Branch (2058:9): [True: 84, False: 82]
  ------------------
 2059|     84|        SSH_LOG(SSH_LOG_TRACE, "Unknown key type found!");
  ------------------
  |  |  283|     84|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2060|     84|        goto fail;
 2061|     84|    }
 2062|     82|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  924|     82|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 82, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 82]
  |  |  ------------------
  ------------------
 2063|       |
 2064|     82|    if (is_cert_type(type)) {
  ------------------
  |  |  146|     82|    ((kt) == SSH_KEYTYPE_RSA_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (146:6): [True: 1, False: 81]
  |  |  ------------------
  |  |  147|     82|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (147:6): [True: 7, False: 74]
  |  |  ------------------
  |  |  148|     82|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (148:6): [True: 1, False: 73]
  |  |  ------------------
  |  |  149|     82|    ((kt) >= SSH_KEYTYPE_ECDSA_P256_CERT01 &&\
  |  |  ------------------
  |  |  |  Branch (149:6): [True: 3, False: 70]
  |  |  ------------------
  |  |  150|     73|     (kt) <= SSH_KEYTYPE_ED25519_CERT01))
  |  |  ------------------
  |  |  |  Branch (150:6): [True: 3, False: 0]
  |  |  ------------------
  ------------------
 2065|     12|        rc = pki_import_cert_buffer(buffer, type, pkey);
 2066|     70|    } else {
 2067|     70|        rc = pki_import_pubkey_buffer(buffer, type, pkey);
 2068|     70|    }
 2069|       |
 2070|     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]
  |  |  ------------------
  ------------------
 2071|       |
 2072|     82|    return rc;
 2073|     84|fail:
 2074|     84|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  966|     84|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 84, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 84]
  |  |  ------------------
  ------------------
 2075|     84|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  924|     84|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 84, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 84]
  |  |  ------------------
  ------------------
 2076|       |
 2077|     84|    return SSH_ERROR;
  ------------------
  |  |  317|     84|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2078|    166|}
ssh_pki_export_pubkey_blob:
 2666|     54|{
 2667|     54|    ssh_string blob = NULL;
 2668|       |
 2669|     54|    if (key == NULL) {
  ------------------
  |  Branch (2669:9): [True: 0, False: 54]
  ------------------
 2670|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2671|      0|    }
 2672|       |
 2673|     54|    blob = pki_key_to_blob(key, SSH_KEY_PUBLIC);
 2674|     54|    if (blob == NULL) {
  ------------------
  |  Branch (2674:9): [True: 0, False: 54]
  ------------------
 2675|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2676|      0|    }
 2677|       |
 2678|     54|    *pblob = blob;
 2679|     54|    return SSH_OK;
  ------------------
  |  |  316|     54|#define SSH_OK 0     /* No error */
  ------------------
 2680|     54|}
ssh_pki_import_signature_blob:
 2947|     35|{
 2948|     35|    ssh_signature sig = NULL;
 2949|     35|    enum ssh_keytypes_e type;
 2950|     35|    enum ssh_digest_e hash_type;
 2951|     35|    ssh_string algorithm = NULL, blob = NULL;
 2952|     35|    ssh_buffer buf = NULL;
 2953|     35|    const char *alg = NULL;
 2954|     35|    uint8_t flags = 0;
 2955|     35|    uint32_t counter = 0;
 2956|     35|    int rc;
 2957|       |
 2958|     35|    if (sig_blob == NULL || psig == NULL) {
  ------------------
  |  Branch (2958:9): [True: 0, False: 35]
  |  Branch (2958:29): [True: 0, False: 35]
  ------------------
 2959|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2960|      0|    }
 2961|       |
 2962|     35|    buf = ssh_buffer_new();
 2963|     35|    if (buf == NULL) {
  ------------------
  |  Branch (2963:9): [True: 0, False: 35]
  ------------------
 2964|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2965|      0|    }
 2966|       |
 2967|     35|    rc = ssh_buffer_add_data(buf,
 2968|     35|                             ssh_string_data(sig_blob),
 2969|     35|                             (uint32_t)ssh_string_len(sig_blob));
 2970|     35|    if (rc < 0) {
  ------------------
  |  Branch (2970:9): [True: 0, False: 35]
  ------------------
 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|     35|    algorithm = ssh_buffer_get_ssh_string(buf);
 2976|     35|    if (algorithm == NULL) {
  ------------------
  |  Branch (2976:9): [True: 1, False: 34]
  ------------------
 2977|      1|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  966|      1|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 1, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
 2978|      1|        return SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2979|      1|    }
 2980|       |
 2981|     34|    alg = ssh_string_get_char(algorithm);
 2982|     34|    rc = ssh_key_type_and_hash_from_signature_name(alg, &type, &hash_type);
 2983|     34|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     34|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2983:9): [True: 21, False: 13]
  ------------------
 2984|     21|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  966|     21|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 21, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 21]
  |  |  ------------------
  ------------------
 2985|     21|        SSH_STRING_FREE(algorithm);
  ------------------
  |  |  924|     21|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 21, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 21]
  |  |  ------------------
  ------------------
 2986|     21|        return SSH_ERROR;
  ------------------
  |  |  317|     21|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2987|     21|    }
 2988|     13|    SSH_STRING_FREE(algorithm);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 2989|       |
 2990|     13|    blob = ssh_buffer_get_ssh_string(buf);
 2991|     13|    if (blob == NULL) {
  ------------------
  |  Branch (2991:9): [True: 1, False: 12]
  ------------------
 2992|      1|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  966|      1|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 1, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
 2993|      1|        return SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2994|      1|    }
 2995|       |
 2996|     12|    if (type == SSH_KEYTYPE_SK_ECDSA ||
  ------------------
  |  Branch (2996:9): [True: 0, False: 12]
  ------------------
 2997|     12|        type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (2997:9): [True: 1, False: 11]
  ------------------
 2998|      1|        rc = ssh_buffer_unpack(buf, "bd", &flags, &counter);
  ------------------
  |  |   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)
  |  |  ------------------
  ------------------
 2999|      1|        if (rc < 0) {
  ------------------
  |  Branch (2999:13): [True: 0, False: 1]
  ------------------
 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|      1|    }
 3005|     12|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  966|     12|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 12, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 12]
  |  |  ------------------
  ------------------
 3006|       |
 3007|     12|    sig = pki_signature_from_blob(pubkey, blob, type, hash_type);
 3008|     12|    SSH_STRING_FREE(blob);
  ------------------
  |  |  924|     12|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 12, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 12]
  |  |  ------------------
  ------------------
 3009|     12|    if (sig == NULL) {
  ------------------
  |  Branch (3009:9): [True: 5, False: 7]
  ------------------
 3010|      5|        return SSH_ERROR;
  ------------------
  |  |  317|      5|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3011|      5|    }
 3012|       |
 3013|       |    /* Set SK specific values */
 3014|      7|    sig->sk_flags = flags;
 3015|      7|    sig->sk_counter = counter;
 3016|       |
 3017|      7|    *psig = sig;
 3018|      7|    return SSH_OK;
  ------------------
  |  |  316|      7|#define SSH_OK 0     /* No error */
  ------------------
 3019|     12|}
pki_key_check_hash_compatible:
 3034|     12|{
 3035|     12|    if (key == NULL) {
  ------------------
  |  Branch (3035:9): [True: 0, False: 12]
  ------------------
 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|     12|    switch(key->type) {
  ------------------
  |  Branch (3041:12): [True: 12, False: 0]
  ------------------
 3042|      0|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (3042:5): [True: 0, False: 12]
  ------------------
 3043|     12|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (3043:5): [True: 12, False: 0]
  ------------------
 3044|     12|        if (hash_type == SSH_DIGEST_SHA1) {
  ------------------
  |  Branch (3044:13): [True: 0, False: 12]
  ------------------
 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|     12|        if (hash_type == SSH_DIGEST_SHA256 ||
  ------------------
  |  Branch (3053:13): [True: 4, False: 8]
  ------------------
 3054|      8|            hash_type == SSH_DIGEST_SHA512)
  ------------------
  |  Branch (3054:13): [True: 8, False: 0]
  ------------------
 3055|     12|        {
 3056|     12|            return SSH_OK;
  ------------------
  |  |  316|     12|#define SSH_OK 0     /* No error */
  ------------------
 3057|     12|        }
 3058|      0|        break;
 3059|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (3059:5): [True: 0, False: 12]
  ------------------
 3060|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (3060:5): [True: 0, False: 12]
  ------------------
 3061|      0|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (3061:5): [True: 0, False: 12]
  ------------------
 3062|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (3062:5): [True: 0, False: 12]
  ------------------
 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: 12]
  ------------------
 3068|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (3068:5): [True: 0, False: 12]
  ------------------
 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: 12]
  ------------------
 3074|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (3074:5): [True: 0, False: 12]
  ------------------
 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: 12]
  ------------------
 3080|      0|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (3080:5): [True: 0, False: 12]
  ------------------
 3081|      0|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (3081:5): [True: 0, False: 12]
  ------------------
 3082|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (3082:5): [True: 0, False: 12]
  ------------------
 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: 12]
  ------------------
 3088|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (3088:5): [True: 0, False: 12]
  ------------------
 3089|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (3089:5): [True: 0, False: 12]
  ------------------
 3090|      0|    case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (3090:5): [True: 0, False: 12]
  ------------------
 3091|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (3091:5): [True: 0, False: 12]
  ------------------
 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|     12|    }
 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|     12|}
ssh_pki_signature_verify:
 3190|      7|{
 3191|      7|    int rc;
 3192|      7|    bool allowed;
 3193|      7|    enum ssh_keytypes_e key_type;
 3194|       |
 3195|      7|    if (session == NULL || sig == NULL || key == NULL || input == NULL) {
  ------------------
  |  Branch (3195:9): [True: 0, False: 7]
  |  Branch (3195:28): [True: 0, False: 7]
  |  Branch (3195:43): [True: 0, False: 7]
  |  Branch (3195:58): [True: 0, False: 7]
  ------------------
 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|      7|    key_type = ssh_key_type_plain(key->type);
 3200|       |
 3201|      7|    SSH_LOG(SSH_LOG_FUNCTIONS,
  ------------------
  |  |  283|      7|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3202|      7|            "Going to verify a %s type signature",
 3203|      7|            sig->type_c);
 3204|       |
 3205|      7|    if (key_type != sig->type) {
  ------------------
  |  Branch (3205:9): [True: 0, False: 7]
  ------------------
 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|      7|    allowed = ssh_key_size_allowed(session, key);
 3213|      7|    if (!allowed) {
  ------------------
  |  Branch (3213:9): [True: 1, False: 6]
  ------------------
 3214|      1|        ssh_set_error(session,
  ------------------
  |  |  313|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3215|      1|                      SSH_FATAL,
 3216|      1|                      "The '%s' key of size %d is not allowed by RSA_MIN_SIZE",
 3217|      1|                      key->type_c,
 3218|      1|                      ssh_key_size(key));
 3219|      1|        return SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3220|      1|    }
 3221|       |
 3222|       |    /* Check if public key and hash type are compatible */
 3223|      6|    rc = pki_key_check_hash_compatible(key, sig->hash_type);
 3224|      6|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      6|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (3224:9): [True: 0, False: 6]
  ------------------
 3225|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3226|      0|    }
 3227|       |
 3228|      6|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|      6|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 0, False: 6]
  |  |  |  Branch (153:38): [True: 0, False: 6]
  |  |  ------------------
  |  |  154|      6|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 0, False: 6]
  |  |  ------------------
  |  |  155|      6|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 6]
  |  |  ------------------
  ------------------
 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|      6|    return pki_verify_data_signature(sig, key, input, input_len);
 3249|      6|}
pki.c:pki_import_cert_buffer:
 1877|     12|{
 1878|     12|    ssh_buffer cert = NULL;
 1879|     12|    ssh_string tmp_s = NULL;
 1880|     12|    const char *type_c = NULL;
 1881|     12|    ssh_key key = NULL;
 1882|     12|    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|     12|    cert = ssh_buffer_new();
 1890|     12|    if (cert == NULL) {
  ------------------
  |  Branch (1890:9): [True: 0, False: 12]
  ------------------
 1891|      0|        goto fail;
 1892|      0|    }
 1893|     12|    type_c = ssh_key_type_to_char(type);
 1894|     12|    tmp_s = ssh_string_from_char(type_c);
 1895|     12|    if (tmp_s == NULL) {
  ------------------
  |  Branch (1895:9): [True: 0, False: 12]
  ------------------
 1896|      0|        goto fail;
 1897|      0|    }
 1898|     12|    rc = ssh_buffer_add_ssh_string(cert, tmp_s);
 1899|     12|    SSH_STRING_FREE(tmp_s);
  ------------------
  |  |  924|     12|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 12, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 12]
  |  |  ------------------
  ------------------
 1900|     12|    if (rc != 0) {
  ------------------
  |  Branch (1900:9): [True: 0, False: 12]
  ------------------
 1901|      0|        goto fail;
 1902|      0|    }
 1903|     12|    rc = ssh_buffer_add_buffer(cert, buffer);
 1904|     12|    if (rc != 0) {
  ------------------
  |  Branch (1904:9): [True: 0, False: 12]
  ------------------
 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|     12|    tmp_s = ssh_buffer_get_ssh_string(buffer);
 1913|     12|    if (tmp_s == NULL) {
  ------------------
  |  Branch (1913:9): [True: 1, False: 11]
  ------------------
 1914|      1|        goto fail;
 1915|      1|    }
 1916|     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]
  |  |  ------------------
  ------------------
 1917|       |
 1918|     11|    switch (type) {
 1919|      1|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1919:9): [True: 1, False: 10]
  ------------------
 1920|      1|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_RSA, &key);
 1921|      1|            break;
 1922|      1|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1922:9): [True: 1, False: 10]
  ------------------
 1923|      1|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ECDSA_P256, &key);
 1924|      1|            break;
 1925|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1925:9): [True: 0, False: 11]
  ------------------
 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: 11]
  ------------------
 1929|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ECDSA_P521, &key);
 1930|      0|            break;
 1931|      1|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1931:9): [True: 1, False: 10]
  ------------------
 1932|      1|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ED25519, &key);
 1933|      1|            break;
 1934|      7|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1934:9): [True: 7, False: 4]
  ------------------
 1935|      7|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_SK_ECDSA, &key);
 1936|      7|            break;
 1937|      1|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1937:9): [True: 1, False: 10]
  ------------------
 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: 11]
  ------------------
 1941|      0|            key = ssh_key_new();
 1942|     11|    }
 1943|     11|    if (rc != 0 || key == NULL) {
  ------------------
  |  Branch (1943:9): [True: 8, False: 3]
  |  Branch (1943:20): [True: 0, False: 3]
  ------------------
 1944|      8|        goto fail;
 1945|      8|    }
 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|      9|fail:
 1955|      9|    ssh_key_free(key);
 1956|      9|    SSH_BUFFER_FREE(cert);
  ------------------
  |  |  966|      9|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 9, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 9]
  |  |  ------------------
  ------------------
 1957|      9|    return SSH_ERROR;
  ------------------
  |  |  317|      9|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1958|     11|}
pki.c:pki_import_pubkey_buffer:
 1736|     81|{
 1737|     81|    ssh_key key = NULL;
 1738|     81|    int rc;
 1739|       |
 1740|     81|    key = ssh_key_new();
 1741|     81|    if (key == NULL) {
  ------------------
  |  Branch (1741:9): [True: 0, False: 81]
  ------------------
 1742|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1743|      0|    }
 1744|       |
 1745|     81|    key->type = type;
 1746|     81|    key->type_c = ssh_key_type_to_char(type);
 1747|     81|    key->flags = SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   54|     81|#define SSH_KEY_FLAG_PUBLIC  0x0001
  ------------------
 1748|       |
 1749|     81|    switch (type) {
 1750|     59|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1750:9): [True: 59, False: 22]
  ------------------
 1751|     59|            {
 1752|     59|                ssh_string e = NULL;
 1753|     59|                ssh_string n = NULL;
 1754|       |
 1755|     59|                rc = ssh_buffer_unpack(buffer, "SS", &e, &n);
  ------------------
  |  |   60|     59|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     59|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     59|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     59|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     59|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     59|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     59|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1756|     59|                if (rc != SSH_OK) {
  ------------------
  |  |  316|     59|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1756:21): [True: 2, False: 57]
  ------------------
 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|     57|                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|     57|                ssh_string_burn(e);
 1767|     57|                SSH_STRING_FREE(e);
  ------------------
  |  |  924|     57|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 57, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 57]
  |  |  ------------------
  ------------------
 1768|     57|                ssh_string_burn(n);
 1769|     57|                SSH_STRING_FREE(n);
  ------------------
  |  |  924|     57|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 57, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 57]
  |  |  ------------------
  ------------------
 1770|     57|                if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     57|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1770:21): [True: 0, False: 57]
  ------------------
 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|     57|            }
 1775|     57|            break;
 1776|     57|#ifdef HAVE_ECC
 1777|     57|        case SSH_KEYTYPE_ECDSA: /* deprecated */
  ------------------
  |  Branch (1777:9): [True: 0, False: 81]
  ------------------
 1778|      5|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1778:9): [True: 5, False: 76]
  ------------------
 1779|      5|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1779:9): [True: 0, False: 81]
  ------------------
 1780|      5|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1780:9): [True: 0, False: 81]
  ------------------
 1781|     12|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1781:9): [True: 7, False: 74]
  ------------------
 1782|     12|            {
 1783|     12|                ssh_string e = NULL;
 1784|     12|                ssh_string i = NULL;
 1785|     12|                int nid;
 1786|       |
 1787|     12|                rc = ssh_buffer_unpack(buffer, "SS", &i, &e);
  ------------------
  |  |   60|     12|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     12|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     12|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     12|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     12|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     12|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     12|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1788|     12|                if (rc != SSH_OK) {
  ------------------
  |  |  316|     12|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1788:21): [True: 4, False: 8]
  ------------------
 1789|      4|                    SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  283|      4|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1790|      4|                    goto fail;
 1791|      4|                }
 1792|       |
 1793|      8|                nid = pki_key_ecdsa_nid_from_name(ssh_string_get_char(i));
 1794|      8|                SSH_STRING_FREE(i);
  ------------------
  |  |  924|      8|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 8, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 8]
  |  |  ------------------
  ------------------
 1795|      8|                if (nid == -1) {
  ------------------
  |  Branch (1795:21): [True: 4, False: 4]
  ------------------
 1796|      4|                    ssh_string_burn(e);
 1797|      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]
  |  |  ------------------
  ------------------
 1798|      4|                    goto fail;
 1799|      4|                }
 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: 1, False: 2]
  ------------------
 1813|      1|                        SSH_LOG(SSH_LOG_TRACE, "SK Unpack error");
  ------------------
  |  |  283|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1814|      1|                        goto fail;
 1815|      1|                    }
 1816|      2|                    key->sk_application = application;
 1817|      2|                    key->type_c = ssh_key_type_to_char(key->type);
 1818|      2|                }
 1819|      3|            }
 1820|      2|            break;
 1821|      2|#endif /* HAVE_ECC */
 1822|      9|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1822:9): [True: 9, False: 72]
  ------------------
 1823|     10|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1823:9): [True: 1, False: 80]
  ------------------
 1824|     10|        {
 1825|     10|            ssh_string pubkey = ssh_buffer_get_ssh_string(buffer);
 1826|       |
 1827|     10|            if (ssh_string_len(pubkey) != ED25519_KEY_LEN) {
  ------------------
  |  |   44|     10|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1827:17): [True: 3, False: 7]
  ------------------
 1828|      3|                SSH_LOG(SSH_LOG_TRACE, "Invalid public key length");
  ------------------
  |  |  283|      3|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1829|      3|                ssh_string_burn(pubkey);
 1830|      3|                SSH_STRING_FREE(pubkey);
  ------------------
  |  |  924|      3|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 2, False: 1]
  |  |  |  Branch (924:69): [Folded, False: 3]
  |  |  ------------------
  ------------------
 1831|      3|                goto fail;
 1832|      3|            }
 1833|       |
 1834|      7|            rc = pki_pubkey_build_ed25519(key, pubkey);
 1835|      7|            ssh_string_burn(pubkey);
 1836|      7|            SSH_STRING_FREE(pubkey);
  ------------------
  |  |  924|      7|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 7, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 7]
  |  |  ------------------
  ------------------
 1837|      7|            if (rc < 0) {
  ------------------
  |  Branch (1837:17): [True: 0, False: 7]
  ------------------
 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|      7|            if (type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1842:17): [True: 1, False: 6]
  ------------------
 1843|      1|                ssh_string application = ssh_buffer_get_ssh_string(buffer);
 1844|      1|                if (application == NULL) {
  ------------------
  |  Branch (1844:21): [True: 0, False: 1]
  ------------------
 1845|      0|                    SSH_LOG(SSH_LOG_TRACE, "SK Unpack error");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1846|      0|                    goto fail;
 1847|      0|                }
 1848|      1|                key->sk_application = application;
 1849|      1|            }
 1850|      7|        }
 1851|      7|        break;
 1852|      7|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1852:9): [True: 0, False: 81]
  ------------------
 1853|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1853:9): [True: 0, False: 81]
  ------------------
 1854|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1854:9): [True: 0, False: 81]
  ------------------
 1855|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1855:9): [True: 0, False: 81]
  ------------------
 1856|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1856:9): [True: 0, False: 81]
  ------------------
 1857|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1857:9): [True: 0, False: 81]
  ------------------
 1858|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1858:9): [True: 0, False: 81]
  ------------------
 1859|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1859:9): [True: 0, False: 81]
  ------------------
 1860|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1860:9): [True: 0, False: 81]
  ------------------
 1861|      0|        default:
  ------------------
  |  Branch (1861:9): [True: 0, False: 81]
  ------------------
 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|     81|    }
 1865|       |
 1866|     66|    *pkey = key;
 1867|     66|    return SSH_OK;
  ------------------
  |  |  316|     66|#define SSH_OK 0     /* No error */
  ------------------
 1868|     15|fail:
 1869|     15|    ssh_key_free(key);
 1870|       |
 1871|     15|    return SSH_ERROR;
  ------------------
  |  |  317|     15|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1872|     81|}

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

pki_key_clean:
   96|     81|{
   97|     81|    if (key == NULL)
  ------------------
  |  Branch (97:9): [True: 0, False: 81]
  ------------------
   98|      0|        return;
   99|     81|    EVP_PKEY_free(key->key);
  100|       |    key->key = NULL;
  101|     81|}
pki_key_ecdsa_nid_from_name:
  194|      8|{
  195|      8|    if (strcmp(name, "nistp256") == 0) {
  ------------------
  |  Branch (195:9): [True: 4, False: 4]
  ------------------
  196|      4|        return NID_X9_62_prime256v1;
  197|      4|    } else if (strcmp(name, "nistp384") == 0) {
  ------------------
  |  Branch (197:16): [True: 0, False: 4]
  ------------------
  198|      0|        return NID_secp384r1;
  199|      4|    } else if (strcmp(name, "nistp521") == 0) {
  ------------------
  |  Branch (199:16): [True: 0, False: 4]
  ------------------
  200|      0|        return NID_secp521r1;
  201|      0|    }
  202|       |
  203|      4|    return -1;
  204|      8|}
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|      7|{
  445|      7|    EVP_PKEY *pkey = NULL;
  446|       |
  447|      7|    if (ssh_string_len(pubkey) != ED25519_KEY_LEN) {
  ------------------
  |  |   44|      7|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (447:9): [True: 0, False: 7]
  ------------------
  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|      7|    if (ssh_fips_mode()) {
  ------------------
  |  |  115|      7|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 7]
  |  |  ------------------
  ------------------
  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|      7|    pkey = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519,
  468|      7|                                       NULL,
  469|      7|                                       (const uint8_t *)ssh_string_data(pubkey),
  470|      7|                                       ED25519_KEY_LEN);
  ------------------
  |  |   44|      7|#define ED25519_KEY_LEN 32
  ------------------
  471|      7|    if (pkey == NULL) {
  ------------------
  |  Branch (471:9): [True: 0, False: 7]
  ------------------
  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|      7|    key->key = pkey;
  479|       |
  480|      7|    return SSH_OK;
  ------------------
  |  |  316|      7|#define SSH_OK 0     /* No error */
  ------------------
  481|      7|}
pki_pubkey_build_rsa:
 1415|     57|                         ssh_string n) {
 1416|     57|    int rc;
 1417|     57|    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|     57|    RSA *key_rsa = RSA_new();
 1425|     57|    if (key_rsa == NULL) {
  ------------------
  |  Branch (1425:9): [True: 0, False: 57]
  ------------------
 1426|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1427|      0|    }
 1428|     57|#endif /* OPENSSL_VERSION_NUMBER */
 1429|       |
 1430|     57|    be = ssh_make_string_bn(e);
 1431|     57|    if (be == NULL) {
  ------------------
  |  Branch (1431:9): [True: 0, False: 57]
  ------------------
 1432|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1433|      0|        goto fail;
 1434|      0|    }
 1435|     57|    bn = ssh_make_string_bn(n);
 1436|     57|    if (bn == NULL) {
  ------------------
  |  Branch (1436:9): [True: 0, False: 57]
  ------------------
 1437|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1438|      0|        goto fail;
 1439|      0|    }
 1440|       |
 1441|     57|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1442|     57|    rc = RSA_set0_key(key_rsa, bn, be, NULL);
 1443|     57|    if (rc == 0) {
  ------------------
  |  Branch (1443:9): [True: 0, False: 57]
  ------------------
 1444|      0|        goto fail;
 1445|      0|    }
 1446|       |    /* Memory management of bn and be is transferred to RSA object */
 1447|     57|    bn = NULL;
 1448|     57|    be = NULL;
 1449|       |
 1450|     57|    key->key = EVP_PKEY_new();
 1451|     57|    if (key->key == NULL) {
  ------------------
  |  Branch (1451:9): [True: 0, False: 57]
  ------------------
 1452|      0|        goto fail;
 1453|      0|    }
 1454|       |
 1455|     57|    rc = EVP_PKEY_assign_RSA(key->key, key_rsa);
 1456|     57|    if (rc != 1) {
  ------------------
  |  Branch (1456:9): [True: 0, False: 57]
  ------------------
 1457|      0|        goto fail;
 1458|      0|    }
 1459|       |
 1460|     57|    return SSH_OK;
  ------------------
  |  |  316|     57|#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|     57|}
pki_key_to_blob:
 1491|     54|{
 1492|     54|    ssh_buffer buffer = NULL;
 1493|     54|    ssh_string type_s = NULL;
 1494|     54|    ssh_string str = NULL;
 1495|     54|    ssh_string e = NULL;
 1496|     54|    ssh_string n = NULL;
 1497|     54|    ssh_string p = NULL;
 1498|     54|    ssh_string g = NULL;
 1499|     54|    ssh_string q = NULL;
 1500|     54|    ssh_string d = NULL;
 1501|     54|    ssh_string iqmp = NULL;
 1502|     54|    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|     54|    uint8_t *ed25519_pubkey = NULL;
 1510|     54|    uint8_t *ed25519_privkey = NULL;
 1511|     54|    size_t key_len = 0;
 1512|       |
 1513|     54|    buffer = ssh_buffer_new();
 1514|     54|    if (buffer == NULL) {
  ------------------
  |  Branch (1514:9): [True: 0, False: 54]
  ------------------
 1515|      0|        return NULL;
 1516|      0|    }
 1517|       |    /* The buffer will contain sensitive information. Make sure it is erased */
 1518|     54|    ssh_buffer_set_secure(buffer);
 1519|       |
 1520|     54|    if (key->cert != NULL) {
  ------------------
  |  Branch (1520:9): [True: 0, False: 54]
  ------------------
 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|     54|    type_s = ssh_string_from_char(key->type_c);
 1530|     54|    if (type_s == NULL) {
  ------------------
  |  Branch (1530:9): [True: 0, False: 54]
  ------------------
 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|     54|    rc = ssh_buffer_add_ssh_string(buffer, type_s);
 1536|     54|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  924|     54|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 54, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 54]
  |  |  ------------------
  ------------------
 1537|     54|    if (rc < 0) {
  ------------------
  |  Branch (1537:9): [True: 0, False: 54]
  ------------------
 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|     54|    switch (key->type) {
 1543|     50|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1543:5): [True: 50, False: 4]
  ------------------
 1544|     50|    case SSH_KEYTYPE_RSA1: {
  ------------------
  |  Branch (1544:5): [True: 0, False: 54]
  ------------------
 1545|     50|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1546|     50|        const BIGNUM *be = NULL, *bn = NULL;
 1547|     50|        const RSA *key_rsa = EVP_PKEY_get0_RSA(key->key);
 1548|     50|        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|     50|        e = ssh_make_bignum_string((BIGNUM *)be);
 1575|     50|        if (e == NULL) {
  ------------------
  |  Branch (1575:13): [True: 0, False: 50]
  ------------------
 1576|      0|            goto fail;
 1577|      0|        }
 1578|       |
 1579|     50|        n = ssh_make_bignum_string((BIGNUM *)bn);
 1580|     50|        if (n == NULL) {
  ------------------
  |  Branch (1580:13): [True: 0, False: 50]
  ------------------
 1581|      0|            goto fail;
 1582|      0|        }
 1583|       |
 1584|     50|        if (type == SSH_KEY_PUBLIC) {
  ------------------
  |  Branch (1584:13): [True: 50, False: 0]
  ------------------
 1585|       |            /* The N and E parts are swapped in the public key export ! */
 1586|     50|            rc = ssh_buffer_add_ssh_string(buffer, e);
 1587|     50|            if (rc < 0) {
  ------------------
  |  Branch (1587:17): [True: 0, False: 50]
  ------------------
 1588|      0|                goto fail;
 1589|      0|            }
 1590|     50|            rc = ssh_buffer_add_ssh_string(buffer, n);
 1591|     50|            if (rc < 0) {
  ------------------
  |  Branch (1591:17): [True: 0, False: 50]
  ------------------
 1592|      0|                goto fail;
 1593|      0|            }
 1594|     50|        } 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|     50|        ssh_string_burn(e);
 1709|     50|        SSH_STRING_FREE(e);
  ------------------
  |  |  924|     50|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 50, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 50]
  |  |  ------------------
  ------------------
 1710|     50|        ssh_string_burn(n);
 1711|     50|        SSH_STRING_FREE(n);
  ------------------
  |  |  924|     50|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 50, False: 0]
  |  |  |  Branch (924:69): [Folded, False: 50]
  |  |  ------------------
  ------------------
 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|     50|        break;
 1719|     50|    }
 1720|      4|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1720:5): [True: 4, False: 50]
  ------------------
 1721|      4|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1721:5): [True: 0, False: 54]
  ------------------
 1722|      4|        rc = EVP_PKEY_get_raw_public_key(key->key, NULL, &key_len);
 1723|      4|        if (rc != 1) {
  ------------------
  |  Branch (1723:13): [True: 0, False: 4]
  ------------------
 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|      4|        if (key_len != ED25519_KEY_LEN) {
  ------------------
  |  |   44|      4|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1730:13): [True: 0, False: 4]
  ------------------
 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|      4|        ed25519_pubkey = malloc(key_len);
 1739|      4|        if (ed25519_pubkey == NULL) {
  ------------------
  |  Branch (1739:13): [True: 0, False: 4]
  ------------------
 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|      4|        rc = EVP_PKEY_get_raw_public_key(key->key,
 1745|      4|                                         (uint8_t *)ed25519_pubkey,
 1746|      4|                                         &key_len);
 1747|      4|        if (rc != 1) {
  ------------------
  |  Branch (1747:13): [True: 0, False: 4]
  ------------------
 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|      4|        rc = ssh_buffer_pack(buffer,
  ------------------
  |  |   50|      4|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|      4|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|      4|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|      4|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|      4|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|      4|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      4|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1755|      4|                             "dP",
 1756|      4|                             (uint32_t)ED25519_KEY_LEN,
 1757|      4|                             (size_t)ED25519_KEY_LEN,
 1758|      4|                             ed25519_pubkey);
 1759|      4|        if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      4|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1759:13): [True: 0, False: 4]
  ------------------
 1760|      0|            goto fail;
 1761|      0|        }
 1762|       |
 1763|      4|        if (type == SSH_KEY_PRIVATE && key->type == SSH_KEYTYPE_ED25519) {
  ------------------
  |  Branch (1763:13): [True: 0, False: 4]
  |  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|      4|        } else if (type == SSH_KEY_PRIVATE &&
  ------------------
  |  Branch (1809:20): [True: 0, False: 4]
  ------------------
 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|      4|        } else if (type == SSH_KEY_PUBLIC &&
  ------------------
  |  Branch (1816:20): [True: 4, False: 0]
  ------------------
 1817|      4|                   key->type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1817:20): [True: 0, False: 4]
  ------------------
 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|      4|        SAFE_FREE(ed25519_pubkey);
  ------------------
  |  |  375|      4|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 4, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 4]
  |  |  ------------------
  ------------------
 1826|      4|        break;
 1827|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1827:5): [True: 0, False: 54]
  ------------------
 1828|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1828:5): [True: 0, False: 54]
  ------------------
 1829|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1829:5): [True: 0, False: 54]
  ------------------
 1830|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1830:5): [True: 0, False: 54]
  ------------------
 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: 54]
  ------------------
 1991|      0|    default:
  ------------------
  |  Branch (1991:5): [True: 0, False: 54]
  ------------------
 1992|      0|        goto fail;
 1993|     54|    }
 1994|       |
 1995|     54|makestring:
 1996|     54|    str = ssh_string_new(ssh_buffer_get_len(buffer));
 1997|     54|    if (str == NULL) {
  ------------------
  |  Branch (1997:9): [True: 0, False: 54]
  ------------------
 1998|      0|        goto fail;
 1999|      0|    }
 2000|       |
 2001|     54|    rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
 2002|     54|    if (rc < 0) {
  ------------------
  |  Branch (2002:9): [True: 0, False: 54]
  ------------------
 2003|      0|        goto fail;
 2004|      0|    }
 2005|     54|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  966|     54|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 54, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 54]
  |  |  ------------------
  ------------------
 2006|       |
 2007|     54|    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|     54|}
pki_signature_from_blob:
 2391|     12|{
 2392|     12|    ssh_signature sig;
 2393|     12|    int rc;
 2394|       |
 2395|     12|    if (ssh_key_type_plain(pubkey->type) != type) {
  ------------------
  |  Branch (2395:9): [True: 3, False: 9]
  ------------------
 2396|      3|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      3|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2397|      3|                "Incompatible public key provided (%d) expecting (%d)",
 2398|      3|                type,
 2399|      3|                pubkey->type);
 2400|      3|        return NULL;
 2401|      3|    }
 2402|       |
 2403|      9|    sig = ssh_signature_new();
 2404|      9|    if (sig == NULL) {
  ------------------
  |  Branch (2404:9): [True: 0, False: 9]
  ------------------
 2405|      0|        return NULL;
 2406|      0|    }
 2407|       |
 2408|      9|    sig->type = type;
 2409|      9|    sig->type_c = ssh_key_signature_to_char(type, hash_type);
 2410|      9|    sig->hash_type = hash_type;
 2411|       |
 2412|      9|    switch(type) {
 2413|      9|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2413:9): [True: 9, False: 0]
  ------------------
 2414|      9|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2414:9): [True: 0, False: 9]
  ------------------
 2415|      9|            rc = pki_signature_from_rsa_blob(pubkey, sig_blob, sig);
 2416|      9|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      9|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2416:17): [True: 2, False: 7]
  ------------------
 2417|      2|                goto error;
 2418|      2|            }
 2419|      7|            break;
 2420|      7|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2420:9): [True: 0, False: 9]
  ------------------
 2421|      0|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2421:9): [True: 0, False: 9]
  ------------------
 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: 9]
  ------------------
 2428|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2428:9): [True: 0, False: 9]
  ------------------
 2429|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2429:9): [True: 0, False: 9]
  ------------------
 2430|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2430:9): [True: 0, False: 9]
  ------------------
 2431|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2431:9): [True: 0, False: 9]
  ------------------
 2432|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2432:9): [True: 0, False: 9]
  ------------------
 2433|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2433:9): [True: 0, False: 9]
  ------------------
 2434|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2434:9): [True: 0, False: 9]
  ------------------
 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: 9]
  ------------------
 2443|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2443:9): [True: 0, False: 9]
  ------------------
 2444|      0|            SSH_LOG(SSH_LOG_TRACE, "Unknown signature type");
  ------------------
  |  |  283|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2445|      0|            goto error;
 2446|      9|    }
 2447|       |
 2448|      7|    return sig;
 2449|       |
 2450|      2|error:
 2451|      2|    ssh_signature_free(sig);
 2452|       |    return NULL;
 2453|      9|}
pki_verify_data_signature:
 2674|      6|{
 2675|      6|    const EVP_MD *md = NULL;
 2676|      6|    EVP_MD_CTX *ctx = NULL;
 2677|      6|    EVP_PKEY *pkey = NULL;
 2678|       |
 2679|      6|    unsigned char *raw_sig_data = NULL;
 2680|      6|    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|      6|    int rc = SSH_ERROR;
  ------------------
  |  |  317|      6|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2687|      6|    int ok;
 2688|       |
 2689|      6|    if (pubkey == NULL || ssh_key_is_private(pubkey) || input == NULL ||
  ------------------
  |  Branch (2689:9): [True: 0, False: 6]
  |  Branch (2689:27): [True: 0, False: 6]
  |  Branch (2689:57): [True: 0, False: 6]
  ------------------
 2690|      6|        signature == NULL || signature->raw_sig == NULL)
  ------------------
  |  Branch (2690:9): [True: 0, False: 6]
  |  Branch (2690:30): [True: 0, False: 6]
  ------------------
 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|      6|    ok = pki_key_check_hash_compatible(pubkey, signature->hash_type);
 2699|      6|    if (ok != SSH_OK) {
  ------------------
  |  |  316|      6|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2699:9): [True: 0, False: 6]
  ------------------
 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|      6|    raw_sig_data = ssh_string_data(signature->raw_sig);
 2705|      6|    raw_sig_len = ssh_string_len(signature->raw_sig);
 2706|      6|    if (raw_sig_data == NULL) {
  ------------------
  |  Branch (2706:9): [True: 0, False: 6]
  ------------------
 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|      6|    md = pki_digest_to_md(signature->hash_type);
 2712|      6|    if (md == NULL) {
  ------------------
  |  Branch (2712:9): [True: 0, False: 6]
  ------------------
 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|      6|    pkey = pki_key_to_pkey(pubkey);
 2720|      6|    if (pkey == NULL) {
  ------------------
  |  Branch (2720:9): [True: 0, False: 6]
  ------------------
 2721|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2722|      0|    }
 2723|       |
 2724|       |    /* Create the context */
 2725|      6|    ctx = EVP_MD_CTX_new();
 2726|      6|    if (ctx == NULL) {
  ------------------
  |  Branch (2726:9): [True: 0, False: 6]
  ------------------
 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|      6|    ok = EVP_DigestVerifyInit(ctx, NULL, md, NULL, pkey);
 2735|      6|    if (ok != 1){
  ------------------
  |  Branch (2735:9): [True: 0, False: 6]
  ------------------
 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|      6|    ok = EVP_DigestVerify(ctx, raw_sig_data, raw_sig_len, input, input_len);
 2743|      6|    if (ok != 1) {
  ------------------
  |  Branch (2743:9): [True: 6, False: 0]
  ------------------
 2744|      6|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      6|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2745|      6|                "Signature invalid: %s",
 2746|      6|                ERR_error_string(ERR_get_error(), NULL));
 2747|      6|        goto out;
 2748|      6|    }
 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|      6|out:
 2754|      6|    EVP_MD_CTX_free(ctx);
 2755|      6|    EVP_PKEY_free(pkey);
 2756|      6|    return rc;
 2757|      0|}
ssh_key_size:
 2760|      8|{
 2761|      8|    int bits = 0;
 2762|      8|    EVP_PKEY *pkey = NULL;
 2763|       |
 2764|      8|    switch (key->type) {
 2765|      8|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2765:5): [True: 8, False: 0]
  ------------------
 2766|      8|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (2766:5): [True: 0, False: 8]
  ------------------
 2767|      8|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2767:5): [True: 0, False: 8]
  ------------------
 2768|      8|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2768:5): [True: 0, False: 8]
  ------------------
 2769|      8|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2769:5): [True: 0, False: 8]
  ------------------
 2770|      8|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2770:5): [True: 0, False: 8]
  ------------------
 2771|      8|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2771:5): [True: 0, False: 8]
  ------------------
 2772|      8|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2772:5): [True: 0, False: 8]
  ------------------
 2773|      8|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2773:5): [True: 0, False: 8]
  ------------------
 2774|      8|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2774:5): [True: 0, False: 8]
  ------------------
 2775|      8|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2775:5): [True: 0, False: 8]
  ------------------
 2776|      8|        pkey = pki_key_to_pkey(key);
 2777|      8|        if (pkey == NULL) {
  ------------------
  |  Branch (2777:13): [True: 0, False: 8]
  ------------------
 2778|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2779|      0|        }
 2780|      8|        bits = EVP_PKEY_bits(pkey);
 2781|      8|        EVP_PKEY_free(pkey);
 2782|      8|        return bits;
 2783|      0|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2783:5): [True: 0, False: 8]
  ------------------
 2784|      0|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (2784:5): [True: 0, False: 8]
  ------------------
 2785|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2785:5): [True: 0, False: 8]
  ------------------
 2786|      0|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (2786:5): [True: 0, False: 8]
  ------------------
 2787|       |        /* ed25519 keys have fixed size */
 2788|      0|        return 255;
 2789|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (2789:5): [True: 0, False: 8]
  ------------------
 2790|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (2790:5): [True: 0, False: 8]
  ------------------
 2791|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2791:5): [True: 0, False: 8]
  ------------------
 2792|      0|    default:
  ------------------
  |  Branch (2792:5): [True: 0, False: 8]
  ------------------
 2793|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2794|      8|    }
 2795|      8|}
pki_crypto.c:pki_signature_from_rsa_blob:
 2169|      9|{
 2170|      9|    size_t pad_len = 0;
 2171|      9|    char *blob_orig = NULL;
 2172|      9|    char *blob_padded_data = NULL;
 2173|      9|    ssh_string sig_blob_padded = NULL;
 2174|       |
 2175|      9|    size_t rsalen = 0;
 2176|      9|    size_t len = ssh_string_len(sig_blob);
 2177|       |
 2178|      9|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 2179|      9|    const RSA *rsa = EVP_PKEY_get0_RSA(pubkey->key);
 2180|       |
 2181|      9|    if (rsa == NULL) {
  ------------------
  |  Branch (2181:9): [True: 0, False: 9]
  ------------------
 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|      9|    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|      9|    if (len > rsalen) {
  ------------------
  |  Branch (2195:9): [True: 2, False: 7]
  ------------------
 2196|      2|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2197|      2|                "Signature is too big: %lu > %lu",
 2198|      2|                (unsigned long)len,
 2199|      2|                (unsigned long)rsalen);
 2200|      2|        goto errout;
 2201|      2|    }
 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|      7|    if (len == rsalen) {
  ------------------
  |  Branch (2208:9): [True: 5, False: 2]
  ------------------
 2209|      5|        sig->raw_sig = ssh_string_copy(sig_blob);
 2210|      5|    } else {
 2211|       |        /* pad the blob to the expected rsalen size */
 2212|      2|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  283|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2213|      2|                "RSA signature len %lu < %lu",
 2214|      2|                (unsigned long)len,
 2215|      2|                (unsigned long)rsalen);
 2216|       |
 2217|      2|        pad_len = rsalen - len;
 2218|       |
 2219|      2|        sig_blob_padded = ssh_string_new(rsalen);
 2220|      2|        if (sig_blob_padded == NULL) {
  ------------------
  |  Branch (2220:13): [True: 0, False: 2]
  ------------------
 2221|      0|            goto errout;
 2222|      0|        }
 2223|       |
 2224|      2|        blob_padded_data = (char *) ssh_string_data(sig_blob_padded);
 2225|      2|        blob_orig = (char *) ssh_string_data(sig_blob);
 2226|       |
 2227|      2|        if (blob_padded_data == NULL || blob_orig == NULL) {
  ------------------
  |  Branch (2227:13): [True: 0, False: 2]
  |  Branch (2227:41): [True: 0, False: 2]
  ------------------
 2228|      0|            goto errout;
 2229|      0|        }
 2230|       |
 2231|       |        /* front-pad the buffer with zeroes */
 2232|      2|        ssh_burn(blob_padded_data, pad_len);
  ------------------
  |  |  390|      2|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
 2233|       |        /* fill the rest with the actual signature blob */
 2234|      2|        memcpy(blob_padded_data + pad_len, blob_orig, len);
 2235|       |
 2236|      2|        sig->raw_sig = sig_blob_padded;
 2237|      2|    }
 2238|       |
 2239|      7|    return SSH_OK;
  ------------------
  |  |  316|      7|#define SSH_OK 0     /* No error */
  ------------------
 2240|       |
 2241|      2|errout:
 2242|      2|    SSH_STRING_FREE(sig_blob_padded);
  ------------------
  |  |  924|      2|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (924:14): [True: 0, False: 2]
  |  |  |  Branch (924:69): [Folded, False: 2]
  |  |  ------------------
  ------------------
 2243|      2|    return SSH_ERROR;
  ------------------
  |  |  317|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2244|      7|}
pki_crypto.c:pki_digest_to_md:
 2456|      6|{
 2457|      6|    const EVP_MD *md = NULL;
 2458|       |
 2459|      6|    switch (hash_type) {
 2460|      2|    case SSH_DIGEST_SHA256:
  ------------------
  |  Branch (2460:5): [True: 2, False: 4]
  ------------------
 2461|      2|        md = EVP_sha256();
 2462|      2|        break;
 2463|      0|    case SSH_DIGEST_SHA384:
  ------------------
  |  Branch (2463:5): [True: 0, False: 6]
  ------------------
 2464|      0|        md = EVP_sha384();
 2465|      0|        break;
 2466|      4|    case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (2466:5): [True: 4, False: 2]
  ------------------
 2467|      4|        md = EVP_sha512();
 2468|      4|        break;
 2469|      0|    case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (2469:5): [True: 0, False: 6]
  ------------------
 2470|      0|        md = EVP_sha1();
 2471|      0|        break;
 2472|      0|    case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (2472:5): [True: 0, False: 6]
  ------------------
 2473|      0|        md = NULL;
 2474|      0|        break;
 2475|      0|    default:
  ------------------
  |  Branch (2475:5): [True: 0, False: 6]
  ------------------
 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|      6|    }
 2480|       |
 2481|      6|    return md;
 2482|      6|}
pki_crypto.c:pki_key_to_pkey:
 2485|     14|{
 2486|     14|    EVP_PKEY *pkey = NULL;
 2487|     14|    int rc = 0;
 2488|       |
 2489|     14|    switch (key->type) {
 2490|     14|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2490:5): [True: 14, False: 0]
  ------------------
 2491|     14|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2491:5): [True: 0, False: 14]
  ------------------
 2492|     14|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (2492:5): [True: 0, False: 14]
  ------------------
 2493|     14|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2493:5): [True: 0, False: 14]
  ------------------
 2494|     14|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2494:5): [True: 0, False: 14]
  ------------------
 2495|     14|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2495:5): [True: 0, False: 14]
  ------------------
 2496|     14|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2496:5): [True: 0, False: 14]
  ------------------
 2497|     14|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2497:5): [True: 0, False: 14]
  ------------------
 2498|     14|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2498:5): [True: 0, False: 14]
  ------------------
 2499|     14|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2499:5): [True: 0, False: 14]
  ------------------
 2500|     14|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2500:5): [True: 0, False: 14]
  ------------------
 2501|     14|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2501:5): [True: 0, False: 14]
  ------------------
 2502|     14|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (2502:5): [True: 0, False: 14]
  ------------------
 2503|     14|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2503:5): [True: 0, False: 14]
  ------------------
 2504|     14|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (2504:5): [True: 0, False: 14]
  ------------------
 2505|     14|        if (key->key == NULL) {
  ------------------
  |  Branch (2505:13): [True: 0, False: 14]
  ------------------
 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|     14|        rc = EVP_PKEY_up_ref(key->key);
 2510|     14|        if (rc != 1) {
  ------------------
  |  Branch (2510:13): [True: 0, False: 14]
  ------------------
 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|     14|        pkey = key->key;
 2515|     14|        break;
 2516|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2516:5): [True: 0, False: 14]
  ------------------
 2517|      0|    default:
  ------------------
  |  Branch (2517:5): [True: 0, False: 14]
  ------------------
 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|     14|    }
 2522|       |
 2523|     14|    return pkey;
 2524|       |
 2525|      0|error:
 2526|      0|    EVP_PKEY_free(pkey);
 2527|       |    return NULL;
 2528|     14|}

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

ssh_new:
   66|  1.10k|{
   67|  1.10k|    ssh_session session = NULL;
   68|  1.10k|    char *id = NULL;
   69|  1.10k|    int rc;
   70|       |
   71|  1.10k|    session = calloc(1, sizeof (struct ssh_session_struct));
   72|  1.10k|    if (session == NULL) {
  ------------------
  |  Branch (72:9): [True: 278, False: 826]
  ------------------
   73|    278|        return NULL;
   74|    278|    }
   75|       |
   76|    826|    session->next_crypto = crypto_new();
   77|    826|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (77:9): [True: 129, False: 697]
  ------------------
   78|    129|        goto err;
   79|    129|    }
   80|       |
   81|    697|    session->socket = ssh_socket_new(session);
   82|    697|    if (session->socket == NULL) {
  ------------------
  |  Branch (82:9): [True: 122, False: 575]
  ------------------
   83|    122|        goto err;
   84|    122|    }
   85|       |
   86|    575|    session->out_buffer = ssh_buffer_new();
   87|    575|    if (session->out_buffer == NULL) {
  ------------------
  |  Branch (87:9): [True: 2, False: 573]
  ------------------
   88|      2|        goto err;
   89|      2|    }
   90|       |
   91|    573|    session->in_buffer = ssh_buffer_new();
   92|    573|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (92:9): [True: 0, False: 573]
  ------------------
   93|      0|        goto err;
   94|      0|    }
   95|       |
   96|    573|    session->out_queue = ssh_list_new();
   97|    573|    if (session->out_queue == NULL) {
  ------------------
  |  Branch (97:9): [True: 0, False: 573]
  ------------------
   98|      0|        goto err;
   99|      0|    }
  100|       |
  101|    573|    session->alive = 0;
  102|    573|    session->auth.supported_methods = 0;
  103|    573|    ssh_set_blocking(session, 1);
  104|    573|    session->maxchannel = FIRST_CHANNEL;
  ------------------
  |  |   49|    573|#define FIRST_CHANNEL 42 // why not ? it helps to find bugs.
  ------------------
  105|    573|    session->proxy_root = true;
  106|       |
  107|    573|    session->agent = ssh_agent_new(session);
  108|    573|    if (session->agent == NULL) {
  ------------------
  |  Branch (108:9): [True: 1, False: 572]
  ------------------
  109|      1|        goto err;
  110|      1|    }
  111|       |
  112|       |    /* Initialise a default PKI context */
  113|    572|    session->pki_context = ssh_pki_ctx_new();
  114|    572|    if (session->pki_context == NULL) {
  ------------------
  |  Branch (114:9): [True: 0, False: 572]
  ------------------
  115|      0|        goto err;
  116|      0|    }
  117|       |
  118|       |    /* OPTIONS */
  119|    572|    session->opts.StrictHostKeyChecking = SSH_STRICT_HOSTKEY_ASK;
  120|    572|    session->opts.port = 22;
  121|    572|    session->opts.fd = -1;
  122|    572|    session->opts.compressionlevel = 7;
  123|    572|    session->opts.nodelay = 0;
  124|    572|    session->opts.identities_only = false;
  125|    572|    session->opts.server_alive_interval = 0;
  126|    572|    session->opts.server_alive_count_max = 3;
  127|    572|    session->opts.batch_mode = false;
  128|    572|    session->opts.gateway_ports = false;
  129|    572|    session->opts.control_master = SSH_CONTROL_MASTER_NO;
  130|       |
  131|    572|    session->opts.flags = SSH_OPT_FLAG_PASSWORD_AUTH |
  ------------------
  |  |  109|    572|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
  132|    572|                          SSH_OPT_FLAG_PUBKEY_AUTH |
  ------------------
  |  |  110|    572|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
  133|    572|                          SSH_OPT_FLAG_KBDINT_AUTH |
  ------------------
  |  |  111|    572|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
  134|    572|                          SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|    572|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
  135|    572|    session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
  136|       |
  137|    572|    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|    572|    if (session->opts.identity_non_exp == NULL) {
  ------------------
  |  Branch (148:9): [True: 572, False: 0]
  ------------------
  149|    572|        session->opts.identity_non_exp = ssh_list_new();
  150|    572|        if (session->opts.identity_non_exp == NULL) {
  ------------------
  |  Branch (150:13): [True: 0, False: 572]
  ------------------
  151|      0|            goto err;
  152|      0|        }
  153|    572|    }
  154|       |
  155|    572|    id = strdup("%d/.ssh/id_ed25519");
  156|    572|    if (id == NULL) {
  ------------------
  |  Branch (156:9): [True: 0, False: 572]
  ------------------
  157|      0|        goto err;
  158|      0|    }
  159|       |
  160|    572|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  161|    572|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    572|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (161:9): [True: 0, False: 572]
  ------------------
  162|      0|        goto err;
  163|      0|    }
  164|       |
  165|    572|#ifdef HAVE_ECC
  166|    572|    id = strdup("%d/.ssh/id_ecdsa");
  167|    572|    if (id == NULL) {
  ------------------
  |  Branch (167:9): [True: 0, False: 572]
  ------------------
  168|      0|        goto err;
  169|      0|    }
  170|    572|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  171|    572|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    572|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (171:9): [True: 0, False: 572]
  ------------------
  172|      0|        goto err;
  173|      0|    }
  174|    572|#endif
  175|       |
  176|    572|    id = strdup("%d/.ssh/id_rsa");
  177|    572|    if (id == NULL) {
  ------------------
  |  Branch (177:9): [True: 0, False: 572]
  ------------------
  178|      0|        goto err;
  179|      0|    }
  180|    572|    rc = ssh_list_append(session->opts.identity_non_exp, id);
  181|    572|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    572|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (181:9): [True: 0, False: 572]
  ------------------
  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|    572|    session->session_state = SSH_SESSION_STATE_NONE;
  210|    572|    session->pending_call_state = SSH_PENDING_CALL_NONE;
  211|    572|    session->packet_state = PACKET_STATE_INIT;
  212|    572|    session->dh_handshake_state = DH_STATE_INIT;
  213|    572|    session->global_req_state = SSH_CHANNEL_REQ_STATE_NONE;
  214|       |
  215|    572|    session->auth.state = SSH_AUTH_STATE_NONE;
  216|    572|    session->auth.service_state = SSH_AUTH_SERVICE_NONE;
  217|       |
  218|    572|    return session;
  219|       |
  220|    254|err:
  221|    254|    free(id);
  222|    254|    ssh_free(session);
  223|       |    return NULL;
  224|    572|}
ssh_free:
  235|  1.35k|{
  236|  1.35k|  int i;
  237|  1.35k|  struct ssh_iterator *it = NULL;
  238|  1.35k|  struct ssh_buffer_struct *b = NULL;
  239|       |
  240|  1.35k|  if (session == NULL) {
  ------------------
  |  Branch (240:7): [True: 532, False: 826]
  ------------------
  241|    532|    return;
  242|    532|  }
  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|    826|  for (it = ssh_list_get_iterator(session->channels);
  252|    826|       it != NULL;
  ------------------
  |  Branch (252:8): [True: 0, False: 826]
  ------------------
  253|    826|       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|    826|  ssh_list_free(session->channels);
  258|    826|  session->channels = NULL;
  259|       |
  260|    826|#ifdef WITH_PCAP
  261|    826|  if (session->pcap_ctx) {
  ------------------
  |  Branch (261:7): [True: 0, False: 826]
  ------------------
  262|      0|      ssh_pcap_context_free(session->pcap_ctx);
  263|      0|      session->pcap_ctx = NULL;
  264|      0|  }
  265|    826|#endif
  266|       |
  267|    826|  ssh_socket_free(session->socket);
  268|    826|  session->socket = NULL;
  269|       |
  270|    826|  if (session->default_poll_ctx) {
  ------------------
  |  Branch (270:7): [True: 572, False: 254]
  ------------------
  271|    572|      ssh_poll_ctx_free(session->default_poll_ctx);
  272|    572|  }
  273|       |
  274|    826|  SSH_BUFFER_FREE(session->in_buffer);
  ------------------
  |  |  966|    826|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 573, False: 253]
  |  |  |  Branch (966:69): [Folded, False: 826]
  |  |  ------------------
  ------------------
  275|    826|  SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  966|    826|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 573, False: 253]
  |  |  |  Branch (966:69): [Folded, False: 826]
  |  |  ------------------
  ------------------
  276|    826|  session->in_buffer = session->out_buffer = NULL;
  277|       |
  278|    826|  if (session->in_hashbuf != NULL) {
  ------------------
  |  Branch (278:7): [True: 295, False: 531]
  ------------------
  279|    295|      SSH_BUFFER_FREE(session->in_hashbuf);
  ------------------
  |  |  966|    295|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 295, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 295]
  |  |  ------------------
  ------------------
  280|    295|  }
  281|    826|  if (session->out_hashbuf != NULL) {
  ------------------
  |  Branch (281:7): [True: 447, False: 379]
  ------------------
  282|    447|      SSH_BUFFER_FREE(session->out_hashbuf);
  ------------------
  |  |  966|    447|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 447, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 447]
  |  |  ------------------
  ------------------
  283|    447|  }
  284|       |
  285|    826|  crypto_free(session->current_crypto);
  286|    826|  crypto_free(session->next_crypto);
  287|       |
  288|    826|  ssh_agent_free(session->agent);
  289|       |
  290|    826|  SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1059|    826|    do {                         \
  |  | 1060|    826|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1060:13): [True: 572, False: 254]
  |  |  ------------------
  |  | 1061|    572|            ssh_pki_ctx_free(x); \
  |  | 1062|    572|            x = NULL;            \
  |  | 1063|    572|        }                        \
  |  | 1064|    826|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1064:14): [Folded, False: 826]
  |  |  ------------------
  ------------------
  291|       |
  292|    826|  ssh_key_free(session->srv.rsa_key);
  293|    826|  session->srv.rsa_key = NULL;
  294|    826|  ssh_key_free(session->srv.ecdsa_key);
  295|    826|  session->srv.ecdsa_key = NULL;
  296|    826|  ssh_key_free(session->srv.ed25519_key);
  297|    826|  session->srv.ed25519_key = NULL;
  298|       |
  299|    826|  if (session->ssh_message_list) {
  ------------------
  |  Branch (299:7): [True: 0, False: 826]
  ------------------
  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|    826|  if (session->kbdint != NULL) {
  ------------------
  |  Branch (310:7): [True: 0, False: 826]
  ------------------
  311|      0|    ssh_kbdint_free(session->kbdint);
  312|      0|  }
  313|       |
  314|    826|  if (session->packet_callbacks) {
  ------------------
  |  Branch (314:7): [True: 0, False: 826]
  ------------------
  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|    826|  if (session->opts.identity) {
  ------------------
  |  Branch (324:7): [True: 572, False: 254]
  ------------------
  325|    572|      char *id = NULL;
  326|       |
  327|    572|      for (id = ssh_list_pop_head(char *, session->opts.identity);
  ------------------
  |  |  128|    572|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  328|  2.28k|           id != NULL;
  ------------------
  |  Branch (328:12): [True: 1.71k, False: 572]
  ------------------
  329|  1.71k|           id = ssh_list_pop_head(char *, session->opts.identity)) {
  ------------------
  |  |  128|  1.71k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  330|  1.71k|          SAFE_FREE(id);
  ------------------
  |  |  375|  1.71k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.71k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.71k]
  |  |  ------------------
  ------------------
  331|  1.71k|      }
  332|    572|      ssh_list_free(session->opts.identity);
  333|    572|  }
  334|       |
  335|    826|  if (session->opts.identity_non_exp) {
  ------------------
  |  Branch (335:7): [True: 572, False: 254]
  ------------------
  336|    572|      char *id = NULL;
  337|       |
  338|    572|      for (id = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  128|    572|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  339|    572|           id != NULL;
  ------------------
  |  Branch (339:12): [True: 0, False: 572]
  ------------------
  340|    572|           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|    572|      ssh_list_free(session->opts.identity_non_exp);
  344|    572|  }
  345|       |
  346|    826|    if (session->opts.certificate) {
  ------------------
  |  Branch (346:9): [True: 572, False: 254]
  ------------------
  347|    572|        char *cert = NULL;
  348|       |
  349|    572|        for (cert = ssh_list_pop_head(char *, session->opts.certificate);
  ------------------
  |  |  128|    572|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  350|    572|             cert != NULL;
  ------------------
  |  Branch (350:14): [True: 0, False: 572]
  ------------------
  351|    572|             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|    572|        ssh_list_free(session->opts.certificate);
  355|    572|    }
  356|       |
  357|    826|    if (session->opts.certificate_non_exp) {
  ------------------
  |  Branch (357:9): [True: 0, False: 826]
  ------------------
  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|    826|    ssh_proxyjumps_free(session->opts.proxy_jumps);
  369|    826|    SSH_LIST_FREE(session->opts.proxy_jumps);
  ------------------
  |  |  131|    826|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (131:14): [True: 0, False: 826]
  |  |  |  Branch (131:69): [Folded, False: 826]
  |  |  ------------------
  ------------------
  370|    826|    SSH_LIST_FREE(session->opts.proxy_jumps_user_cb);
  ------------------
  |  |  131|    826|    do { if ((x) != NULL) { ssh_list_free(x); (x) = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (131:14): [True: 0, False: 826]
  |  |  |  Branch (131:69): [Folded, False: 826]
  |  |  ------------------
  ------------------
  371|    826|    SAFE_FREE(session->opts.proxy_jumps_str);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  372|       |
  373|    826|    if (session->opts.send_env) {
  ------------------
  |  Branch (373:9): [True: 0, False: 826]
  ------------------
  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|    826|    while ((b = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  128|    826|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
  |  Branch (384:12): [True: 0, False: 826]
  ------------------
  385|    826|                                  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|    826|    ssh_list_free(session->out_queue);
  389|       |
  390|    826|  ssh_agent_state_free(session->agent_state);
  391|    826|  session->agent_state = NULL;
  392|       |
  393|    826|  SAFE_FREE(session->auth.auto_state);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  394|    826|  SAFE_FREE(session->serverbanner);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  395|    826|  SAFE_FREE(session->clientbanner);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  396|    826|  SAFE_FREE(session->banner);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  397|    826|  SAFE_FREE(session->disconnect_message);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  398|    826|  SAFE_FREE(session->peer_discon_msg);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1, False: 825]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  399|       |
  400|    826|  SAFE_FREE(session->opts.agent_socket);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  401|    826|  SAFE_FREE(session->opts.bindaddr);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  402|    826|  SAFE_FREE(session->opts.username);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 572, False: 254]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  403|    826|  SAFE_FREE(session->opts.host);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 572, False: 254]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  404|    826|  SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 572, False: 254]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  405|    826|  SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  406|    826|  SAFE_FREE(session->opts.tag);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  407|    826|  SAFE_FREE(session->opts.homedir);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 572, False: 254]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  408|    826|  SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 572, False: 254]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  409|    826|  SAFE_FREE(session->opts.knownhosts);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 572, False: 254]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  410|    826|  SAFE_FREE(session->opts.global_knownhosts);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 572, False: 254]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  411|    826|  SAFE_FREE(session->opts.ProxyCommand);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  412|    826|  SAFE_FREE(session->opts.gss_server_identity);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  413|    826|  SAFE_FREE(session->opts.gss_client_identity);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  414|    826|  SAFE_FREE(session->opts.pubkey_accepted_types);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  415|    826|  SAFE_FREE(session->opts.control_path);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  416|    826|  SAFE_FREE(session->opts.preferred_authentications);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  417|    826|  SAFE_FREE(session->opts.forward_agent_sock_path);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  418|       |
  419|    826|  if (session->opts.local_forward) {
  ------------------
  |  Branch (419:7): [True: 0, False: 826]
  ------------------
  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|    826|  if (session->opts.remote_forward) {
  ------------------
  |  Branch (430:7): [True: 0, False: 826]
  ------------------
  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|  9.08k|  for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  9.08k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (441:15): [True: 8.26k, False: 826]
  ------------------
  442|  8.26k|      if (session->opts.wanted_methods[i]) {
  ------------------
  |  Branch (442:11): [True: 2.28k, False: 5.97k]
  ------------------
  443|  2.28k|          SAFE_FREE(session->opts.wanted_methods[i]);
  ------------------
  |  |  375|  2.28k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 2.28k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 2.28k]
  |  |  ------------------
  ------------------
  444|  2.28k|      }
  445|  8.26k|  }
  446|       |
  447|    826|  SAFE_FREE(session->server_opts.custombanner);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  448|    826|  SAFE_FREE(session->server_opts.moduli_file);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 0, False: 826]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  449|       |
  450|    826|  _ssh_remove_legacy_log_cb();
  451|       |
  452|       |  /* burn connection, it could contain sensitive data */
  453|    826|  ssh_burn(session, sizeof(struct ssh_session_struct));
  ------------------
  |  |  390|    826|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  454|       |  SAFE_FREE(session);
  ------------------
  |  |  375|    826|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 826, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 826]
  |  |  ------------------
  ------------------
  455|    826|}
ssh_session_socket_close:
  635|    823|{
  636|    823|    if (session->opts.fd == SSH_INVALID_SOCKET) {
  ------------------
  |  |  124|    823|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  |  Branch (636:9): [True: 0, False: 823]
  ------------------
  637|      0|        ssh_socket_close(session->socket);
  638|      0|    }
  639|    823|    session->alive = 0;
  640|    823|    session->session_state = SSH_SESSION_STATE_ERROR;
  641|    823|}
ssh_set_blocking:
  669|    573|{
  670|    573|    if (session == NULL) {
  ------------------
  |  Branch (670:9): [True: 0, False: 573]
  ------------------
  671|      0|        return;
  672|      0|    }
  673|    573|    session->flags &= ~SSH_SESSION_FLAG_BLOCKING;
  ------------------
  |  |   75|    573|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  674|    573|    session->flags |= blocking ? SSH_SESSION_FLAG_BLOCKING : 0;
  ------------------
  |  |   75|    573|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (674:23): [True: 573, False: 0]
  ------------------
  675|    573|}
ssh_is_blocking:
  684|  1.14k|{
  685|  1.14k|    return (session->flags & SSH_SESSION_FLAG_BLOCKING) ? 1 : 0;
  ------------------
  |  |   75|  1.14k|#define SSH_SESSION_FLAG_BLOCKING 0x0001
  ------------------
  |  Branch (685:12): [True: 1.14k, False: 0]
  ------------------
  686|  1.14k|}
ssh_set_fd_towrite:
  778|    572|void ssh_set_fd_towrite(ssh_session session) {
  779|    572|  if (session == NULL) {
  ------------------
  |  Branch (779:7): [True: 0, False: 572]
  ------------------
  780|      0|    return;
  781|      0|  }
  782|       |
  783|    572|  ssh_socket_set_write_wontblock(session->socket);
  784|    572|}
ssh_handle_packets:
  821|  2.20k|{
  822|  2.20k|    ssh_poll_handle spoll = NULL;
  823|  2.20k|    ssh_poll_ctx ctx = NULL;
  824|  2.20k|    int tm = timeout;
  825|  2.20k|    int rc;
  826|       |
  827|  2.20k|    if (session == NULL || session->socket == NULL) {
  ------------------
  |  Branch (827:9): [True: 0, False: 2.20k]
  |  Branch (827:28): [True: 0, False: 2.20k]
  ------------------
  828|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  829|      0|    }
  830|       |
  831|  2.20k|    spoll = ssh_socket_get_poll_handle(session->socket);
  832|  2.20k|    if (spoll == NULL) {
  ------------------
  |  Branch (832:9): [True: 0, False: 2.20k]
  ------------------
  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|  2.20k|    ssh_poll_add_events(spoll, POLLIN);
  837|  2.20k|    ctx = ssh_poll_get_ctx(spoll);
  838|       |
  839|  2.20k|    if (ctx == NULL) {
  ------------------
  |  Branch (839:9): [True: 572, False: 1.62k]
  ------------------
  840|    572|        ctx = ssh_poll_get_default_ctx(session);
  841|    572|        if (ctx == NULL) {
  ------------------
  |  Branch (841:13): [True: 0, False: 572]
  ------------------
  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|    572|        rc = ssh_poll_ctx_add(ctx, spoll);
  846|    572|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (846:13): [True: 0, False: 572]
  ------------------
  847|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  848|      0|        }
  849|    572|    }
  850|       |
  851|  2.20k|    if (timeout == SSH_TIMEOUT_USER) {
  ------------------
  |  |  101|  2.20k|#define SSH_TIMEOUT_USER -2
  ------------------
  |  Branch (851:9): [True: 0, False: 2.20k]
  ------------------
  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|  2.20k|    rc = ssh_poll_ctx_dopoll(ctx, tm);
  860|  2.20k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  2.20k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (860:9): [True: 192, False: 2.00k]
  ------------------
  861|    192|        session->session_state = SSH_SESSION_STATE_ERROR;
  862|    192|    }
  863|       |
  864|  2.20k|    return rc;
  865|  2.20k|}
ssh_handle_packets_termination:
  898|    572|{
  899|    572|    struct ssh_timestamp ts;
  900|    572|    int timeout_ms = SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|    572|#define SSH_TIMEOUT_INFINITE -1
  ------------------
  901|    572|    int tm;
  902|    572|    int ret = SSH_OK;
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  903|       |
  904|       |    /* If a timeout has been provided, use it */
  905|    572|    if (timeout >= 0) {
  ------------------
  |  Branch (905:9): [True: 572, False: 0]
  ------------------
  906|    572|        timeout_ms = timeout;
  907|    572|    } 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|    572|    if (timeout_ms != SSH_TIMEOUT_NONBLOCKING) {
  ------------------
  |  |  105|    572|#define SSH_TIMEOUT_NONBLOCKING 0
  ------------------
  |  Branch (923:9): [True: 572, False: 0]
  ------------------
  924|    572|        ssh_timestamp_init(&ts);
  925|    572|    }
  926|       |
  927|    572|    tm = timeout_ms;
  928|  2.58k|    while(!fct(user)) {
  ------------------
  |  Branch (928:11): [True: 2.20k, False: 380]
  ------------------
  929|  2.20k|        ret = ssh_handle_packets(session, tm);
  930|  2.20k|        if (ret == SSH_ERROR) {
  ------------------
  |  |  317|  2.20k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (930:13): [True: 192, False: 2.00k]
  ------------------
  931|    192|            break;
  932|    192|        }
  933|  2.00k|        if (ssh_timeout_elapsed(&ts, timeout_ms)) {
  ------------------
  |  Branch (933:13): [True: 0, False: 2.00k]
  ------------------
  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|  2.00k|        tm = ssh_timeout_update(&ts, timeout_ms);
  939|  2.00k|    }
  940|       |
  941|    572|    return ret;
  942|    572|}
ssh_socket_exception_callback:
 1053|    192|void ssh_socket_exception_callback(int code, int errno_code, void *user){
 1054|    192|    ssh_session session = (ssh_session)user;
 1055|       |
 1056|    192|    SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  283|    192|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1057|    192|            "Socket exception callback: %d (%d)",
 1058|    192|            code,
 1059|    192|            errno_code);
 1060|    192|    session->session_state = SSH_SESSION_STATE_ERROR;
 1061|    192|    if (errno_code == 0 && code == SSH_SOCKET_EXCEPTION_EOF) {
  ------------------
  |  |  521|    192|#define SSH_SOCKET_EXCEPTION_EOF 	     1
  ------------------
  |  Branch (1061:9): [True: 192, False: 0]
  |  Branch (1061:28): [True: 192, False: 0]
  ------------------
 1062|    192|        ssh_set_error(session, SSH_FATAL, "Socket error: disconnected");
  ------------------
  |  |  313|    192|    _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|    192|    } 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|    192|    session->ssh_connection_callback(session);
 1092|    192|}

ssh_client_sntrup761x25519_init:
  105|     38|{
  106|     38|    int rc;
  107|       |
  108|     38|    rc = ssh_sntrup761x25519_init(session);
  109|     38|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     38|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (109:9): [True: 0, False: 38]
  ------------------
  110|      0|        return rc;
  111|      0|    }
  112|       |
  113|     38|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|     38|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  453|     38|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  455|     38|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  450|     38|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  455|     38|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  463|     38|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     38|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  114|     38|                         "bdPP",
  115|     38|                         SSH2_MSG_KEX_ECDH_INIT,
  116|     38|                         CURVE25519_PUBKEY_SIZE + SNTRUP761_PUBLICKEY_SIZE,
  117|     38|                         (size_t)SNTRUP761_PUBLICKEY_SIZE,
  118|     38|                         session->next_crypto->sntrup761_client_pubkey,
  119|     38|                         (size_t)CURVE25519_PUBKEY_SIZE,
  120|     38|                         session->next_crypto->curve25519_client_pubkey);
  121|     38|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     38|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (121:9): [True: 0, False: 38]
  ------------------
  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|     38|    ssh_packet_set_callbacks(session, &ssh_sntrup761x25519_client_callbacks);
  128|     38|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  129|     38|    rc = ssh_packet_send(session);
  130|       |
  131|     38|    return rc;
  132|     38|}
ssh_client_sntrup761x25519_remove_callbacks:
  135|     21|{
  136|     21|    ssh_packet_remove_callbacks(session, &ssh_sntrup761x25519_client_callbacks);
  137|     21|}
sntrup761.c:ssh_sntrup761x25519_init:
   62|     38|{
   63|     38|    int rc;
   64|       |
   65|     38|    rc = ssh_curve25519_init(session);
   66|     38|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     38|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (66:9): [True: 0, False: 38]
  ------------------
   67|      0|        return rc;
   68|      0|    }
   69|       |
   70|     38|    if (!session->server) {
  ------------------
  |  Branch (70:9): [True: 38, 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|     38|        sntrup761_keypair(session->next_crypto->sntrup761_client_pubkey,
   87|     38|                          session->next_crypto->sntrup761_privkey,
   88|     38|                          &rc,
   89|     38|                          crypto_random);
   90|     38|        if (rc != 1) {
  ------------------
  |  Branch (90:13): [True: 0, False: 38]
  ------------------
   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|     38|#endif /* HAVE_LIBGCRYPT */
   96|     38|    }
   97|       |
   98|     38|    return SSH_OK;
  ------------------
  |  |  316|     38|#define SSH_OK 0     /* No error */
  ------------------
   99|     38|}
sntrup761.c:crypto_random:
   41|  57.8k|{
   42|  57.8k|    int *err = ctx;
   43|  57.8k|    *err = ssh_get_random(dst, length, 1);
   44|  57.8k|}
sntrup761.c:ssh_packet_client_sntrup761x25519_reply:
  248|     21|{
  249|     21|    ssh_string q_s_string = NULL;
  250|     21|    ssh_string pubkey_blob = NULL;
  251|     21|    ssh_string signature = NULL;
  252|     21|    int rc;
  253|     21|    (void)type;
  254|     21|    (void)user;
  255|       |
  256|     21|    ssh_client_sntrup761x25519_remove_callbacks(session);
  257|       |
  258|     21|    pubkey_blob = ssh_buffer_get_ssh_string(packet);
  259|     21|    if (pubkey_blob == NULL) {
  ------------------
  |  Branch (259:9): [True: 2, False: 19]
  ------------------
  260|      2|        ssh_set_error(session, SSH_FATAL, "No public key in packet");
  ------------------
  |  |  313|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  261|      2|        goto error;
  262|      2|    }
  263|       |
  264|     19|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  265|     19|    SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  266|     19|    if (rc != 0) {
  ------------------
  |  Branch (266:9): [True: 16, False: 3]
  ------------------
  267|     16|        ssh_set_error(session, SSH_FATAL, "Failed to import next public key");
  ------------------
  |  |  313|     16|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  268|     16|        goto error;
  269|     16|    }
  270|       |
  271|      3|    q_s_string = ssh_buffer_get_ssh_string(packet);
  272|      3|    if (q_s_string == NULL) {
  ------------------
  |  Branch (272:9): [True: 2, False: 1]
  ------------------
  273|      2|        ssh_set_error(session, SSH_FATAL, "No sntrup761x25519 Q_S in packet");
  ------------------
  |  |  313|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  274|      2|        goto error;
  275|      2|    }
  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|     21|error:
  321|     21|    session->session_state = SSH_SESSION_STATE_ERROR;
  322|     21|    return SSH_PACKET_USED;
  ------------------
  |  |  638|     21|#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.27k|{
  183|  1.27k|    ssh_socket s;
  184|       |
  185|  1.27k|    s = calloc(1, sizeof(struct ssh_socket_struct));
  186|  1.27k|    if (s == NULL) {
  ------------------
  |  Branch (186:9): [True: 54, False: 1.21k]
  ------------------
  187|     54|        ssh_set_error_oom(session);
  ------------------
  |  |  320|     54|    _ssh_set_error_oom(error, __func__)
  ------------------
  188|     54|        return NULL;
  189|     54|    }
  190|  1.21k|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|  1.21k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  191|  1.21k|    s->last_errno = -1;
  192|  1.21k|    s->fd_is_socket = 1;
  193|  1.21k|    s->session = session;
  194|  1.21k|    s->in_buffer = ssh_buffer_new();
  195|  1.21k|    if (s->in_buffer == NULL) {
  ------------------
  |  Branch (195:9): [True: 54, False: 1.16k]
  ------------------
  196|     54|        ssh_set_error_oom(session);
  ------------------
  |  |  320|     54|    _ssh_set_error_oom(error, __func__)
  ------------------
  197|     54|        SAFE_FREE(s);
  ------------------
  |  |  375|     54|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 54, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 54]
  |  |  ------------------
  ------------------
  198|     54|        return NULL;
  199|     54|    }
  200|  1.16k|    s->out_buffer=ssh_buffer_new();
  201|  1.16k|    if (s->out_buffer == NULL) {
  ------------------
  |  Branch (201:9): [True: 15, False: 1.14k]
  ------------------
  202|     15|        ssh_set_error_oom(session);
  ------------------
  |  |  320|     15|    _ssh_set_error_oom(error, __func__)
  ------------------
  203|     15|        SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  966|     15|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 15, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 15]
  |  |  ------------------
  ------------------
  204|     15|        SAFE_FREE(s);
  ------------------
  |  |  375|     15|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 15, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 15]
  |  |  ------------------
  ------------------
  205|     15|        return NULL;
  206|     15|    }
  207|  1.14k|    s->read_wontblock = 0;
  208|  1.14k|    s->write_wontblock = 0;
  209|  1.14k|    s->data_except = 0;
  210|       |    s->poll_handle = NULL;
  211|  1.14k|    s->state=SSH_SOCKET_NONE;
  212|  1.14k|    return s;
  213|  1.16k|}
ssh_socket_reset:
  226|    572|{
  227|    572|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|    572|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  228|    572|    s->last_errno = -1;
  229|    572|    s->fd_is_socket = 1;
  230|    572|    ssh_buffer_reinit(s->in_buffer);
  231|    572|    ssh_buffer_reinit(s->out_buffer);
  232|    572|    s->read_wontblock = 0;
  233|    572|    s->write_wontblock = 0;
  234|    572|    s->data_except = 0;
  235|    572|    if (s->poll_handle != NULL) {
  ------------------
  |  Branch (235:9): [True: 572, False: 0]
  ------------------
  236|    572|        ssh_poll_free(s->poll_handle);
  237|       |        s->poll_handle = NULL;
  238|    572|    }
  239|    572|    s->state=SSH_SOCKET_NONE;
  240|    572|#ifndef _WIN32
  241|    572|    s->proxy_pid = 0;
  242|    572|#endif
  243|    572|}
ssh_socket_set_callbacks:
  253|  1.07k|{
  254|  1.07k|    s->callbacks = callbacks;
  255|  1.07k|}
ssh_socket_set_connected:
  269|    572|{
  270|    572|    s->state = SSH_SOCKET_CONNECTED;
  271|       |    /* `POLLOUT` is the event to wait for in a non-blocking connect */
  272|    572|    if (p != NULL) {
  ------------------
  |  Branch (272:9): [True: 572, False: 0]
  ------------------
  273|    572|        ssh_poll_set_events(p, POLLIN | POLLOUT);
  274|    572|    }
  275|    572|}
ssh_socket_pollcallback:
  296|  2.20k|{
  297|  2.20k|    ssh_socket s = (ssh_socket)v_s;
  298|  2.20k|    void *buffer = NULL;
  299|  2.20k|    ssize_t nread = 0;
  300|  2.20k|    int rc;
  301|  2.20k|    int err = 0;
  302|  2.20k|    socklen_t errlen = sizeof(err);
  303|       |
  304|       |    /* Do not do anything if this socket was already closed */
  305|  2.20k|    if (!ssh_socket_is_open(s)) {
  ------------------
  |  Branch (305:9): [True: 0, False: 2.20k]
  ------------------
  306|      0|        return -1;
  307|      0|    }
  308|  2.20k|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  283|  13.2k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (283:34): [True: 2.20k, False: 0]
  |  |  |  Branch (283:34): [True: 2.16k, False: 39]
  |  |  |  Branch (283:34): [True: 0, False: 2.20k]
  |  |  ------------------
  ------------------
  309|  2.20k|            "Poll callback on socket %d (%s%s%s), out buffer %" PRIu32, fd,
  310|  2.20k|            (revents & POLLIN) ? "POLLIN ":"",
  311|  2.20k|            (revents & POLLOUT) ? "POLLOUT ":"",
  312|  2.20k|            (revents & POLLERR) ? "POLLERR":"",
  313|  2.20k|            ssh_buffer_get_len(s->out_buffer));
  314|  2.20k|    if ((revents & POLLERR) || (revents & POLLHUP)) {
  ------------------
  |  Branch (314:9): [True: 0, False: 2.20k]
  |  Branch (314:32): [True: 0, False: 2.20k]
  ------------------
  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|  2.20k|    if ((revents & POLLIN) && s->state == SSH_SOCKET_CONNECTED) {
  ------------------
  |  Branch (339:9): [True: 2.20k, False: 0]
  |  Branch (339:31): [True: 1.62k, False: 572]
  ------------------
  340|  1.62k|        s->read_wontblock = 1;
  341|  1.62k|        buffer = ssh_buffer_allocate(s->in_buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|  1.62k|#define MAX_BUF_SIZE 4096
  ------------------
  342|  1.62k|        if (buffer) {
  ------------------
  |  Branch (342:13): [True: 1.62k, False: 0]
  ------------------
  343|  1.62k|            nread = ssh_socket_unbuffered_read(s, buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|  1.62k|#define MAX_BUF_SIZE 4096
  ------------------
  344|  1.62k|        }
  345|  1.62k|        if (nread < 0) {
  ------------------
  |  Branch (345:13): [True: 0, False: 1.62k]
  ------------------
  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.62k|        ssh_buffer_pass_bytes_end(s->in_buffer,
  361|  1.62k|                                  (uint32_t)(MAX_BUF_SIZE - nread));
  ------------------
  |  |  230|  1.62k|#define MAX_BUF_SIZE 4096
  ------------------
  362|       |
  363|  1.62k|        if (nread == 0) {
  ------------------
  |  Branch (363:13): [True: 192, False: 1.43k]
  ------------------
  364|    192|            if (p != NULL) {
  ------------------
  |  Branch (364:17): [True: 192, False: 0]
  ------------------
  365|    192|                ssh_poll_remove_events(p, POLLIN);
  366|    192|            }
  367|    192|            if (s->callbacks != NULL && s->callbacks->exception != NULL) {
  ------------------
  |  Branch (367:17): [True: 192, False: 0]
  |  Branch (367:41): [True: 192, False: 0]
  ------------------
  368|    192|                s->callbacks->exception(SSH_SOCKET_EXCEPTION_EOF,
  ------------------
  |  |  521|    192|#define SSH_SOCKET_EXCEPTION_EOF 	     1
  ------------------
  369|    192|                                        0,
  370|    192|                                        s->callbacks->userdata);
  371|    192|            }
  372|    192|            return -2;
  373|    192|        }
  374|       |
  375|  1.43k|        if (s->session->socket_counter != NULL) {
  ------------------
  |  Branch (375:13): [True: 0, False: 1.43k]
  ------------------
  376|      0|            s->session->socket_counter->in_bytes += nread;
  377|      0|        }
  378|       |
  379|       |        /* Call the callback */
  380|  1.43k|        if (s->callbacks != NULL && s->callbacks->data != NULL) {
  ------------------
  |  Branch (380:13): [True: 1.43k, False: 0]
  |  Branch (380:37): [True: 1.43k, False: 0]
  ------------------
  381|  1.43k|            size_t processed;
  382|   364k|            do {
  383|   364k|                processed = s->callbacks->data(ssh_buffer_get(s->in_buffer),
  384|   364k|                                               ssh_buffer_get_len(s->in_buffer),
  385|   364k|                                               s->callbacks->userdata);
  386|   364k|                ssh_buffer_pass_bytes(s->in_buffer, (uint32_t)processed);
  387|   364k|            } while ((processed > 0) && (s->state == SSH_SOCKET_CONNECTED));
  ------------------
  |  Branch (387:22): [True: 363k, False: 1.43k]
  |  Branch (387:41): [True: 363k, False: 0]
  ------------------
  388|       |
  389|       |            /* p may have been freed, so don't use it
  390|       |             * anymore in this function */
  391|  1.43k|            p = NULL;
  392|  1.43k|        }
  393|  1.43k|    }
  394|       |#ifdef _WIN32
  395|       |    if (revents & POLLOUT || revents & POLLWRNORM) {
  396|       |#else
  397|  2.00k|    if (revents & POLLOUT) {
  ------------------
  |  Branch (397:9): [True: 1.97k, False: 36]
  ------------------
  398|  1.97k|#endif
  399|  1.97k|        uint32_t len;
  400|       |
  401|       |        /* First, POLLOUT is a sign we may be connected */
  402|  1.97k|        if (s->state == SSH_SOCKET_CONNECTING) {
  ------------------
  |  Branch (402:13): [True: 572, False: 1.40k]
  ------------------
  403|    572|            SSH_LOG(SSH_LOG_PACKET, "Received POLLOUT in connecting state");
  ------------------
  |  |  283|    572|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  404|    572|            ssh_socket_set_connected(s, p);
  405|       |
  406|    572|            rc = ssh_socket_set_blocking(ssh_socket_get_fd(s));
  407|    572|            if (rc < 0) {
  ------------------
  |  Branch (407:17): [True: 0, False: 572]
  ------------------
  408|      0|                return -1;
  409|      0|            }
  410|       |
  411|    572|            if (s->callbacks != NULL && s->callbacks->connected != NULL) {
  ------------------
  |  Branch (411:17): [True: 572, False: 0]
  |  Branch (411:41): [True: 572, False: 0]
  ------------------
  412|    572|                s->callbacks->connected(SSH_SOCKET_CONNECTED_OK,
  ------------------
  |  |  524|    572|#define SSH_SOCKET_CONNECTED_OK 			1
  ------------------
  413|    572|                                        0,
  414|    572|                                        s->callbacks->userdata);
  415|    572|            }
  416|       |
  417|    572|            return 0;
  418|    572|        }
  419|       |
  420|       |        /* So, we can write data */
  421|  1.40k|        s->write_wontblock = 1;
  422|  1.40k|        if (p != NULL) {
  ------------------
  |  Branch (422:13): [True: 0, False: 1.40k]
  ------------------
  423|      0|            ssh_poll_remove_events(p, POLLOUT);
  424|      0|        }
  425|       |
  426|       |        /* If buffered data is pending, write it */
  427|  1.40k|        len = ssh_buffer_get_len(s->out_buffer);
  428|  1.40k|        if (len > 0) {
  ------------------
  |  Branch (428:13): [True: 628, False: 773]
  ------------------
  429|    628|            ssh_socket_nonblocking_flush(s);
  430|    773|        } else if (s->callbacks != NULL && s->callbacks->controlflow != NULL) {
  ------------------
  |  Branch (430:20): [True: 773, False: 0]
  |  Branch (430:44): [True: 475, False: 298]
  ------------------
  431|       |            /* Otherwise advertise the upper level that write can be done */
  432|    475|            SSH_LOG(SSH_LOG_TRACE, "sending control flow event");
  ------------------
  |  |  283|    475|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  433|    475|            s->callbacks->controlflow(SSH_SOCKET_FLOW_WRITEWONTBLOCK,
  ------------------
  |  |  519|    475|#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
  ------------------
  434|    475|                                      s->callbacks->userdata);
  435|    475|        }
  436|       |        /* TODO: Find a way to put back POLLOUT when buffering occurs */
  437|  1.40k|    }
  438|       |
  439|       |    /* Return -1 if the poll handler disappeared */
  440|  1.43k|    if (s->poll_handle == NULL) {
  ------------------
  |  Branch (440:9): [True: 0, False: 1.43k]
  ------------------
  441|      0|        return -1;
  442|      0|    }
  443|       |
  444|  1.43k|    return 0;
  445|  1.43k|}
ssh_socket_get_poll_handle:
  454|  2.77k|{
  455|  2.77k|    if (s->poll_handle) {
  ------------------
  |  Branch (455:9): [True: 2.20k, False: 572]
  ------------------
  456|  2.20k|        return s->poll_handle;
  457|  2.20k|    }
  458|    572|    s->poll_handle = ssh_poll_new(s->fd, 0, ssh_socket_pollcallback, s);
  459|    572|    return s->poll_handle;
  460|  2.77k|}
ssh_socket_free:
  473|  1.39k|{
  474|  1.39k|    if (s == NULL) {
  ------------------
  |  Branch (474:9): [True: 251, False: 1.14k]
  ------------------
  475|    251|        return;
  476|    251|    }
  477|  1.14k|    ssh_socket_close(s);
  478|  1.14k|    SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  966|  1.14k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 1.14k, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 1.14k]
  |  |  ------------------
  ------------------
  479|  1.14k|    SSH_BUFFER_FREE(s->out_buffer);
  ------------------
  |  |  966|  1.14k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (966:14): [True: 1.14k, False: 0]
  |  |  |  Branch (966:69): [Folded, False: 1.14k]
  |  |  ------------------
  ------------------
  480|       |    SAFE_FREE(s);
  ------------------
  |  |  375|  1.14k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (375:31): [True: 1.14k, False: 0]
  |  |  |  Branch (375:71): [Folded, False: 1.14k]
  |  |  ------------------
  ------------------
  481|  1.14k|}
ssh_socket_close:
  546|  1.71k|{
  547|  1.71k|    if (ssh_socket_is_open(s)) {
  ------------------
  |  Branch (547:9): [True: 0, False: 1.71k]
  ------------------
  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.71k|    if (s->poll_handle != NULL && !ssh_poll_is_locked(s->poll_handle)) {
  ------------------
  |  Branch (557:9): [True: 0, False: 1.71k]
  |  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.71k|    s->state = SSH_SOCKET_CLOSED;
  563|       |
  564|  1.71k|#ifndef _WIN32
  565|       |    /* If the proxy command still runs try to kill it */
  566|  1.71k|    if (s->proxy_pid != 0) {
  ------------------
  |  Branch (566:9): [True: 0, False: 1.71k]
  ------------------
  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.71k|#endif
  585|  1.71k|}
ssh_socket_set_fd:
  596|    572|{
  597|    572|    ssh_poll_handle h = NULL;
  598|       |
  599|    572|    s->fd = fd;
  600|       |
  601|    572|    if (s->poll_handle) {
  ------------------
  |  Branch (601:9): [True: 0, False: 572]
  ------------------
  602|      0|        ssh_poll_set_fd(s->poll_handle,fd);
  603|    572|    } else {
  604|    572|        s->state = SSH_SOCKET_CONNECTING;
  605|    572|        h = ssh_socket_get_poll_handle(s);
  606|    572|        if (h == NULL) {
  ------------------
  |  Branch (606:13): [True: 0, False: 572]
  ------------------
  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|    572|        ssh_poll_set_events(h, POLLOUT);
  612|       |#ifdef _WIN32
  613|       |        ssh_poll_add_events(h, POLLWRNORM);
  614|       |#endif
  615|    572|    }
  616|    572|    return SSH_OK;
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  617|    572|}
ssh_socket_get_fd:
  629|    572|{
  630|    572|    return s->fd;
  631|    572|}
ssh_socket_is_open:
  643|  76.3k|{
  644|  76.3k|    return s->fd != SSH_INVALID_SOCKET;
  ------------------
  |  |  124|  76.3k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  645|  76.3k|}
ssh_socket_write:
  811|  35.9k|{
  812|  35.9k|    if (len > 0) {
  ------------------
  |  Branch (812:9): [True: 35.9k, False: 0]
  ------------------
  813|  35.9k|        if (ssh_buffer_add_data(s->out_buffer, buffer, len) < 0) {
  ------------------
  |  Branch (813:13): [True: 0, False: 35.9k]
  ------------------
  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|  35.9k|        ssh_socket_nonblocking_flush(s);
  818|  35.9k|    }
  819|       |
  820|  35.9k|    return SSH_OK;
  ------------------
  |  |  316|  35.9k|#define SSH_OK 0     /* No error */
  ------------------
  821|  35.9k|}
ssh_socket_nonblocking_flush:
  841|  36.5k|{
  842|  36.5k|    ssh_session session = s->session;
  843|  36.5k|    uint32_t len;
  844|       |
  845|  36.5k|    if (!ssh_socket_is_open(s)) {
  ------------------
  |  Branch (845:9): [True: 0, False: 36.5k]
  ------------------
  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|  36.5k|    len = ssh_buffer_get_len(s->out_buffer);
  864|  36.5k|    if (!s->write_wontblock && s->poll_handle && len > 0) {
  ------------------
  |  Branch (864:9): [True: 35.1k, False: 1.33k]
  |  Branch (864:32): [True: 35.1k, False: 0]
  |  Branch (864:50): [True: 35.1k, False: 0]
  ------------------
  865|       |        /* force the poll system to catch pollout events */
  866|  35.1k|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  867|       |
  868|  35.1k|        return SSH_AGAIN;
  ------------------
  |  |  318|  35.1k|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  869|  35.1k|    }
  870|       |
  871|  1.33k|    if (s->write_wontblock && len > 0) {
  ------------------
  |  Branch (871:9): [True: 1.33k, False: 0]
  |  Branch (871:31): [True: 1.33k, False: 0]
  ------------------
  872|  1.33k|        ssize_t bwritten;
  873|       |
  874|  1.33k|        bwritten = ssh_socket_unbuffered_write(s,
  875|  1.33k|                                               ssh_buffer_get(s->out_buffer),
  876|  1.33k|                                               len);
  877|  1.33k|        if (bwritten < 0) {
  ------------------
  |  Branch (877:13): [True: 0, False: 1.33k]
  ------------------
  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.33k|        ssh_buffer_pass_bytes(s->out_buffer, (uint32_t)bwritten);
  898|  1.33k|        if (s->session->socket_counter != NULL) {
  ------------------
  |  Branch (898:13): [True: 0, False: 1.33k]
  ------------------
  899|      0|            s->session->socket_counter->out_bytes += bwritten;
  900|      0|        }
  901|  1.33k|    }
  902|       |
  903|       |    /* Is there some data pending? */
  904|  1.33k|    len = ssh_buffer_get_len(s->out_buffer);
  905|  1.33k|    if (s->poll_handle && len > 0) {
  ------------------
  |  Branch (905:9): [True: 1.33k, False: 0]
  |  Branch (905:27): [True: 0, False: 1.33k]
  ------------------
  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.33k|    return SSH_OK;
  ------------------
  |  |  316|  1.33k|#define SSH_OK 0     /* No error */
  ------------------
  916|  1.33k|}
ssh_socket_set_write_wontblock:
  929|    572|{
  930|    572|    s->write_wontblock = 1;
  931|    572|}
ssh_socket_set_blocking:
 1114|    572|{
 1115|       |    return fcntl(fd, F_SETFL, 0);
 1116|    572|}
socket.c:ssh_socket_unbuffered_read:
  665|  1.62k|{
  666|  1.62k|    ssize_t rc = -1;
  667|       |
  668|  1.62k|    if (s->data_except) {
  ------------------
  |  Branch (668:9): [True: 0, False: 1.62k]
  ------------------
  669|      0|        return -1;
  670|      0|    }
  671|  1.62k|    if (s->fd_is_socket) {
  ------------------
  |  Branch (671:9): [True: 1.62k, False: 0]
  ------------------
  672|  1.62k|        rc = recv(s->fd, buffer, len, 0);
  673|  1.62k|    } else {
  674|      0|        rc = read(s->fd, buffer, len);
  675|      0|    }
  676|       |#ifdef _WIN32
  677|       |    s->last_errno = WSAGetLastError();
  678|       |#else
  679|  1.62k|    s->last_errno = errno;
  680|  1.62k|#endif
  681|  1.62k|    s->read_wontblock = 0;
  682|       |
  683|  1.62k|    if (rc < 0) {
  ------------------
  |  Branch (683:9): [True: 0, False: 1.62k]
  ------------------
  684|      0|        s->data_except = 1;
  685|  1.62k|    } else {
  686|  1.62k|        SSH_LOG(SSH_LOG_TRACE, "read %zd", rc);
  ------------------
  |  |  283|  1.62k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  687|  1.62k|    }
  688|       |
  689|  1.62k|    return rc;
  690|  1.62k|}
socket.c:ssh_socket_unbuffered_write:
  711|  1.33k|{
  712|  1.33k|    ssize_t w = -1;
  713|  1.33k|    int flags = 0;
  714|       |
  715|  1.33k|#ifdef MSG_NOSIGNAL
  716|  1.33k|    flags |= MSG_NOSIGNAL;
  717|  1.33k|#endif
  718|       |
  719|  1.33k|    if (s->data_except) {
  ------------------
  |  Branch (719:9): [True: 0, False: 1.33k]
  ------------------
  720|      0|        return -1;
  721|      0|    }
  722|       |
  723|  1.33k|    if (s->fd_is_socket) {
  ------------------
  |  Branch (723:9): [True: 1.33k, False: 0]
  ------------------
  724|  1.33k|        w = send(s->fd, buffer, len, flags);
  725|  1.33k|    } else {
  726|      0|        w = write(s->fd, buffer, len);
  727|      0|    }
  728|       |#ifdef _WIN32
  729|       |    s->last_errno = WSAGetLastError();
  730|       |#else
  731|  1.33k|    s->last_errno = errno;
  732|  1.33k|#endif
  733|  1.33k|    s->write_wontblock = 0;
  734|       |    /* Reactive the POLLOUT detector in the poll multiplexer system */
  735|  1.33k|    if (s->poll_handle) {
  ------------------
  |  Branch (735:9): [True: 1.33k, False: 0]
  ------------------
  736|  1.33k|        SSH_LOG(SSH_LOG_PACKET, "Enabling POLLOUT for socket");
  ------------------
  |  |  283|  1.33k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  737|  1.33k|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  738|  1.33k|    }
  739|  1.33k|    if (w < 0) {
  ------------------
  |  Branch (739:9): [True: 0, False: 1.33k]
  ------------------
  740|      0|        s->data_except = 1;
  741|      0|    }
  742|       |
  743|  1.33k|    SSH_LOG(SSH_LOG_TRACE, "wrote %zd", w);
  ------------------
  |  |  283|  1.33k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  744|  1.33k|    return w;
  745|  1.33k|}

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

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

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

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

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

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.62k|{
  290|  1.62k|    if (nalloc_fail(count, "recv")) {
  ------------------
  |  Branch (290:9): [True: 0, False: 1.62k]
  ------------------
  291|      0|        errno = EIO;
  292|      0|        return -1;
  293|      0|    }
  294|  1.62k|    return nalloc_recv(fd, buf, count, flags);
  ------------------
  |  |  265|  1.62k|#define nalloc_recv(f, b, s, x) __recv(f, b, s, x)
  ------------------
  295|  1.62k|}
send:
  298|  2.43k|{
  299|  2.43k|    if (nalloc_fail(count, "send")) {
  ------------------
  |  Branch (299:9): [True: 0, False: 2.43k]
  ------------------
  300|      0|        errno = EIO;
  301|      0|        return -1;
  302|      0|    }
  303|  2.43k|    return nalloc_send(fd, buf, count, flags);
  ------------------
  |  |  266|  2.43k|#define nalloc_send(f, b, s, x) __send(f, b, s, x)
  ------------------
  304|  2.43k|}
calloc:
  307|  45.5k|{
  308|  45.5k|    if (nalloc_fail(size, "calloc")) {
  ------------------
  |  Branch (308:9): [True: 501, False: 45.0k]
  ------------------
  309|    501|        errno = ENOMEM;
  310|    501|        return NULL;
  311|    501|    }
  312|  45.0k|    return nalloc_calloc(nmemb, size);
  ------------------
  |  |  259|  45.0k|#define nalloc_calloc(s, n)          __libc_calloc(s, n)
  ------------------
  313|  45.5k|}
malloc:
  316|   272k|{
  317|   272k|    if (nalloc_fail(size, "malloc")) {
  ------------------
  |  Branch (317:9): [True: 0, False: 272k]
  ------------------
  318|      0|        errno = ENOMEM;
  319|      0|        return NULL;
  320|      0|    }
  321|   272k|    return nalloc_malloc(size);
  ------------------
  |  |  258|   272k|#define nalloc_malloc(s)             __libc_malloc(s)
  ------------------
  322|   272k|}
realloc:
  325|  14.5k|{
  326|  14.5k|    if (nalloc_fail(size, "realloc")) {
  ------------------
  |  Branch (326:9): [True: 31, False: 14.5k]
  ------------------
  327|     31|        errno = ENOMEM;
  328|     31|        return NULL;
  329|     31|    }
  330|  14.5k|    return nalloc_realloc(ptr, size);
  ------------------
  |  |  260|  14.5k|#define nalloc_realloc(p, s)         __libc_realloc(p, s)
  ------------------
  331|  14.5k|}
ssh_client_fuzzer.c:nalloc_fail:
  194|   336k|{
  195|       |    // do not fail before thread init
  196|   336k|    if (nalloc_runs == 0) {
  ------------------
  |  Branch (196:9): [True: 10.1k, False: 326k]
  ------------------
  197|  10.1k|        return false;
  198|  10.1k|    }
  199|   326k|    if (__sync_fetch_and_add(&nalloc_running, 1) != 1) {
  ------------------
  |  Branch (199:9): [True: 6.63k, False: 319k]
  ------------------
  200|       |        // do not fail allocations outside of fuzzer input
  201|       |        // and do not fail inside of this function
  202|  6.63k|        __sync_fetch_and_sub(&nalloc_running, 1);
  203|  6.63k|        return false;
  204|  6.63k|    }
  205|   319k|    nalloc_random_update((uint8_t)size);
  206|   319k|    if (size >= 0x100) {
  ------------------
  |  Branch (206:9): [True: 198k, False: 120k]
  ------------------
  207|   198k|        nalloc_random_update((uint8_t)(size >> 8));
  208|   198k|        if (size >= 0x10000) {
  ------------------
  |  Branch (208:13): [True: 91, False: 198k]
  ------------------
  209|     91|            nalloc_random_update((uint8_t)(size >> 16));
  210|       |            // bigger may already fail or oom
  211|     91|        }
  212|   198k|    }
  213|   319k|    if (((nalloc_random_state ^ nalloc_magic) & nalloc_bitmask) == 0) {
  ------------------
  |  Branch (213:9): [True: 532, False: 319k]
  ------------------
  214|    532|        if (nalloc_backtrace_exclude(size, op)) {
  ------------------
  |  Branch (214:13): [True: 0, False: 532]
  ------------------
  215|      0|            __sync_fetch_and_sub(&nalloc_running, 1);
  216|      0|            return false;
  217|      0|        }
  218|    532|        __sync_fetch_and_sub(&nalloc_running, 1);
  219|    532|        return true;
  220|    532|    }
  221|   319k|    __sync_fetch_and_sub(&nalloc_running, 1);
  222|       |    return false;
  223|   319k|}
ssh_client_fuzzer.c:nalloc_random_update:
  143|  12.3M|{
  144|  12.3M|    nalloc_random_state =
  145|  12.3M|        ((uint32_t)((uint32_t)nalloc_random_state << 8)) ^
  146|  12.3M|        nalloc_crc32_table[((nalloc_random_state >> 24) ^ b) & 0xFF];
  147|  12.3M|}
ssh_client_fuzzer.c:nalloc_backtrace_exclude:
  181|    532|{
  182|    532|    if (nalloc_verbose) {
  ------------------
  |  Branch (182:9): [True: 0, False: 532]
  ------------------
  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|    532|}
ssh_client_fuzzer.c:nalloc_start:
  151|  1.10k|{
  152|  1.10k|    if (nalloc_random_bitmask) {
  ------------------
  |  Branch (152:9): [True: 1.10k, False: 0]
  ------------------
  153|  1.10k|        if (nalloc_random_state & 0x10) {
  ------------------
  |  Branch (153:13): [True: 572, False: 532]
  ------------------
  154|    572|            nalloc_bitmask = 0xFFFFFFFF;
  155|    572|        } else {
  156|    532|            nalloc_bitmask = 1 << (5 + (nalloc_random_state & 0xF));
  157|    532|        }
  158|  1.10k|    } else if (nalloc_bitmask == 0) {
  ------------------
  |  Branch (158:16): [True: 0, False: 0]
  ------------------
  159|       |        // nalloc disabled
  160|      0|        return 2;
  161|      0|    }
  162|  1.10k|    nalloc_random_state = 0;
  163|  11.8M|    for (size_t i = 0; i < size; i++) {
  ------------------
  |  Branch (163:24): [True: 11.8M, False: 1.10k]
  ------------------
  164|  11.8M|        nalloc_random_update(data[i]);
  165|  11.8M|    }
  166|  1.10k|    if (__sync_fetch_and_add(&nalloc_running, 1)) {
  ------------------
  |  Branch (166:9): [True: 0, False: 1.10k]
  ------------------
  167|      0|        __sync_fetch_and_sub(&nalloc_running, 1);
  168|      0|        return 0;
  169|      0|    }
  170|  1.10k|    nalloc_runs++;
  171|  1.10k|    return 1;
  172|  1.10k|}
ssh_client_fuzzer.c:nalloc_end:
  176|  1.10k|{
  177|  1.10k|    __sync_fetch_and_sub(&nalloc_running, 1);
  178|  1.10k|}

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|  1.10k|{
  109|  1.10k|    ssh_session session = NULL;
  110|  1.10k|    ssh_channel channel = NULL;
  111|  1.10k|    const char *env = NULL;
  112|  1.10k|    int socket_fds[2] = {-1, -1};
  113|  1.10k|    ssize_t nwritten;
  114|  1.10k|    bool no = false;
  115|  1.10k|    int rc;
  116|  1.10k|    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|  1.10k|    if (size > 219264) {
  ------------------
  |  Branch (122:9): [True: 3, False: 1.10k]
  ------------------
  123|      3|        return -1;
  124|      3|    }
  125|       |
  126|       |    /* Set up the socket to send data */
  127|  1.10k|    rc = socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds);
  128|  1.10k|    assert(rc == 0);
  ------------------
  |  Branch (128:5): [True: 0, False: 1.10k]
  |  Branch (128:5): [True: 1.10k, False: 0]
  ------------------
  129|       |
  130|  1.10k|    nwritten = send(socket_fds[1], data, size, 0);
  131|  1.10k|    assert((size_t)nwritten == size);
  ------------------
  |  Branch (131:5): [True: 0, False: 1.10k]
  |  Branch (131:5): [True: 1.10k, False: 0]
  ------------------
  132|       |
  133|  1.10k|    rc = shutdown(socket_fds[1], SHUT_WR);
  134|  1.10k|    assert(rc == 0);
  ------------------
  |  Branch (134:5): [True: 0, False: 1.10k]
  |  Branch (134:5): [True: 1.10k, False: 0]
  ------------------
  135|       |
  136|  1.10k|    assert(nalloc_start(data, size) > 0);
  ------------------
  |  Branch (136:5): [True: 0, False: 1.10k]
  |  Branch (136:5): [True: 1.10k, False: 0]
  ------------------
  137|       |
  138|  1.10k|    session = ssh_new();
  139|  1.10k|    if (session == NULL) {
  ------------------
  |  Branch (139:9): [True: 532, False: 572]
  ------------------
  140|    532|        goto out;
  141|    532|    }
  142|       |
  143|    572|    env = getenv("LIBSSH_VERBOSITY");
  144|    572|    if (env != NULL && strlen(env) > 0) {
  ------------------
  |  Branch (144:9): [True: 0, False: 572]
  |  Branch (144:24): [True: 0, False: 0]
  ------------------
  145|      0|        ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY_STR, env);
  146|      0|    }
  147|    572|    rc = ssh_options_set(session, SSH_OPTIONS_FD, &socket_fds[0]);
  148|    572|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (148:9): [True: 0, False: 572]
  ------------------
  149|      0|        goto out;
  150|      0|    }
  151|    572|    rc = ssh_options_set(session, SSH_OPTIONS_HOST, "127.0.0.1");
  152|    572|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (152:9): [True: 0, False: 572]
  ------------------
  153|      0|        goto out;
  154|      0|    }
  155|    572|    rc = ssh_options_set(session, SSH_OPTIONS_USER, "alice");
  156|    572|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (156:9): [True: 0, False: 572]
  ------------------
  157|      0|        goto out;
  158|      0|    }
  159|    572|    rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_C_S, "none");
  160|    572|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (160:9): [True: 0, False: 572]
  ------------------
  161|      0|        goto out;
  162|      0|    }
  163|    572|    rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_S_C, "none");
  164|    572|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (164:9): [True: 0, False: 572]
  ------------------
  165|      0|        goto out;
  166|      0|    }
  167|    572|    rc = ssh_options_set(session, SSH_OPTIONS_HMAC_C_S, "none");
  168|    572|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (168:9): [True: 0, False: 572]
  ------------------
  169|      0|        goto out;
  170|      0|    }
  171|    572|    rc = ssh_options_set(session, SSH_OPTIONS_HMAC_S_C, "none");
  172|    572|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (172:9): [True: 0, False: 572]
  ------------------
  173|      0|        goto out;
  174|      0|    }
  175|    572|    rc = ssh_options_set(session, SSH_OPTIONS_PROCESS_CONFIG, &no);
  176|    572|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (176:9): [True: 0, False: 572]
  ------------------
  177|      0|        goto out;
  178|      0|    }
  179|    572|    rc = ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &timeout);
  180|    572|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (180:9): [True: 0, False: 572]
  ------------------
  181|      0|        goto out;
  182|      0|    }
  183|       |
  184|    572|    ssh_callbacks_init(&cb);
  ------------------
  |  |  535|    572|#define ssh_callbacks_init(p) do {\
  |  |  536|    572|	(p)->size=sizeof(*(p)); \
  |  |  537|    572|} while(0);
  |  |  ------------------
  |  |  |  Branch (537:9): [Folded, False: 572]
  |  |  ------------------
  ------------------
  185|    572|    ssh_set_callbacks(session, &cb);
  186|       |
  187|    572|    rc = ssh_connect(session);
  188|    572|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    572|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (188:9): [True: 572, False: 0]
  ------------------
  189|    572|        goto out;
  190|    572|    }
  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|  1.10k|out:
  215|  1.10k|    ssh_channel_free(channel);
  216|  1.10k|    ssh_disconnect(session);
  217|  1.10k|    ssh_free(session);
  218|       |
  219|  1.10k|    close(socket_fds[0]);
  220|  1.10k|    close(socket_fds[1]);
  221|       |
  222|  1.10k|    nalloc_end();
  223|  1.10k|    return 0;
  224|      0|}
ssh_client_fuzzer.c:_fuzz_finalize:
   30|      2|{
   31|      2|    ssh_finalize();
   32|      2|}

