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

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

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

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

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

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

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

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

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

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

ssh_client_dhgex_init:
   65|      6|{
   66|      6|    int rc;
   67|       |
   68|      6|    rc = ssh_dh_init_common(session->next_crypto);
   69|      6|    if (rc != SSH_OK){
  ------------------
  |  |  316|      6|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (69:9): [True: 0, False: 6]
  ------------------
   70|      0|        goto error;
   71|      0|    }
   72|       |
   73|      6|    session->next_crypto->dh_pmin = DH_PMIN;
  ------------------
  |  |   41|      6|#define DH_PMIN 2048
  ------------------
   74|      6|    session->next_crypto->dh_pn = DH_PREQ;
  ------------------
  |  |   42|      6|#define DH_PREQ 2048
  ------------------
   75|      6|    session->next_crypto->dh_pmax = DH_PMAX;
  ------------------
  |  |   43|      6|#define DH_PMAX 8192
  ------------------
   76|       |    /* Minimum group size, preferred group size, maximum group size */
   77|      6|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|      6|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      6|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      6|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      6|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      6|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      6|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      6|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
   78|      6|                         "bddd",
   79|      6|                         SSH2_MSG_KEX_DH_GEX_REQUEST,
   80|      6|                         session->next_crypto->dh_pmin,
   81|      6|                         session->next_crypto->dh_pn,
   82|      6|                         session->next_crypto->dh_pmax);
   83|      6|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      6|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (83:9): [True: 0, False: 6]
  ------------------
   84|      0|        goto error;
   85|      0|    }
   86|       |
   87|       |    /* register the packet callbacks */
   88|      6|    ssh_packet_set_callbacks(session, &ssh_dhgex_client_callbacks);
   89|      6|    session->dh_handshake_state = DH_STATE_REQUEST_SENT;
   90|      6|    rc = ssh_packet_send(session);
   91|      6|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      6|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (91:9): [True: 0, False: 6]
  ------------------
   92|      0|        goto error;
   93|      0|    }
   94|      6|    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|      6|}
dh-gex.c:ssh_packet_client_dhgex_group:
  105|      5|{
  106|      5|    int rc;
  107|      5|    int blen;
  108|      5|    bignum pmin1 = NULL, one = NULL;
  109|      5|    bignum modulus = NULL, generator = NULL;
  110|      5|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
  111|      5|    const_bignum pubkey;
  112|       |#else
  113|       |    bignum pubkey = NULL;
  114|       |#endif /* OPENSSL_VERSION_NUMBER */
  115|      5|    (void) type;
  116|      5|    (void) user;
  117|       |
  118|      5|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_KEX_DH_GEX_GROUP received");
  ------------------
  |  |  281|      5|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  119|       |
  120|      5|    if (session->dh_handshake_state != DH_STATE_REQUEST_SENT) {
  ------------------
  |  Branch (120:9): [True: 1, False: 4]
  ------------------
  121|      1|        ssh_set_error(session,
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  122|      1|                      SSH_FATAL,
  123|      1|                      "Received DH_GEX_GROUP in invalid state");
  124|      1|        goto error;
  125|      1|    }
  126|      4|    one = bignum_new();
  ------------------
  |  |   70|      4|#define bignum_new() BN_new()
  ------------------
  127|      4|    pmin1 = bignum_new();
  ------------------
  |  |   70|      4|#define bignum_new() BN_new()
  ------------------
  128|      4|    if (one == NULL || pmin1 == NULL) {
  ------------------
  |  Branch (128:9): [True: 0, False: 4]
  |  Branch (128:24): [True: 0, False: 4]
  ------------------
  129|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  130|      0|        goto error;
  131|      0|    }
  132|      4|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      4|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      4|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      4|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      4|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      4|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      4|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      4|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  133|      4|                           "BB",
  134|      4|                           &modulus,
  135|      4|                           &generator);
  136|      4|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      4|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (136:9): [True: 1, False: 3]
  ------------------
  137|      1|        ssh_set_error(session, SSH_FATAL, "Invalid DH_GEX_GROUP packet");
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  138|      1|        goto error;
  139|      1|    }
  140|       |    /* basic checks */
  141|      3|    if (ssh_fips_mode() &&
  ------------------
  |  |  115|      6|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 3]
  |  |  ------------------
  ------------------
  142|      0|        !ssh_dh_is_known_group(modulus, generator)) {
  ------------------
  |  Branch (142:9): [True: 0, False: 0]
  ------------------
  143|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      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|      3|    rc = bignum_set_word(one, 1);
  ------------------
  |  |   77|      3|#define bignum_set_word(bn,n) BN_set_word(bn,n)
  ------------------
  149|      3|    if (rc != 1) {
  ------------------
  |  Branch (149:9): [True: 0, False: 3]
  ------------------
  150|      0|        goto error;
  151|      0|    }
  152|      3|    blen = bignum_num_bits(modulus);
  ------------------
  |  |   99|      3|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
  153|      3|    if (blen < DH_PMIN || blen > DH_PMAX) {
  ------------------
  |  |   41|      6|#define DH_PMIN 2048
  ------------------
                  if (blen < DH_PMIN || blen > DH_PMAX) {
  ------------------
  |  |   43|      3|#define DH_PMAX 8192
  ------------------
  |  Branch (153:9): [True: 0, False: 3]
  |  Branch (153:27): [True: 0, False: 3]
  ------------------
  154|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  155|      0|                SSH_FATAL,
  156|      0|                "Invalid dh group parameter p: %d not in [%d:%d]",
  157|      0|                blen,
  158|      0|                DH_PMIN,
  159|      0|                DH_PMAX);
  160|      0|        goto error;
  161|      0|    }
  162|      3|    if (bignum_cmp(modulus, one) <= 0) {
  ------------------
  |  |  102|      3|#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
  ------------------
  |  Branch (162:9): [True: 0, False: 3]
  ------------------
  163|       |        /* p must be positive and preferably bigger than one */
  164|      0|        ssh_set_error(session, SSH_FATAL, "Invalid dh group parameter p");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  165|      0|        goto error;
  166|      0|    }
  167|      3|    if (!bignum_is_bit_set(modulus, 0)) {
  ------------------
  |  |  100|      3|#define bignum_is_bit_set(num,bit) BN_is_bit_set(num, (int)bit)
  ------------------
  |  Branch (167:9): [True: 2, False: 1]
  ------------------
  168|       |        /* p must be a prime and therefore not divisible by 2 */
  169|      2|        ssh_set_error(session, SSH_FATAL, "Invalid dh group parameter p");
  ------------------
  |  |  311|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  170|      2|        goto error;
  171|      2|    }
  172|      1|    bignum_sub(pmin1, modulus, one);
  ------------------
  |  |   96|      1|#define bignum_sub(dest, a, b) BN_sub(dest, a, b)
  ------------------
  173|      1|    if (bignum_cmp(generator, one) <= 0 ||
  ------------------
  |  |  102|      1|#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
  ------------------
  |  Branch (173:9): [True: 0, 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|      0|        ssh_set_error(session, SSH_FATAL, "Invalid dh group parameter g");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  177|      0|        goto error;
  178|      0|    }
  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)
  |  |  ------------------
  |  |  |  |  451|      1|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      1|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      1|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      1|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      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;
  ------------------
  |  |  637|      1|#define SSH_PACKET_USED 1
  ------------------
  227|       |
  228|      4|error:
  229|      4|    bignum_safe_free(modulus);
  ------------------
  |  |   71|      4|#define bignum_safe_free(num) do { \
  |  |   72|      4|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 2, False: 2]
  |  |  ------------------
  |  |   73|      2|        BN_clear_free((num)); \
  |  |   74|      2|        (num)=NULL; \
  |  |   75|      2|    } \
  |  |   76|      4|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 4]
  |  |  ------------------
  ------------------
  230|      4|    bignum_safe_free(generator);
  ------------------
  |  |   71|      4|#define bignum_safe_free(num) do { \
  |  |   72|      4|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 2, False: 2]
  |  |  ------------------
  |  |   73|      2|        BN_clear_free((num)); \
  |  |   74|      2|        (num)=NULL; \
  |  |   75|      2|    } \
  |  |   76|      4|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 4]
  |  |  ------------------
  ------------------
  231|      4|    bignum_safe_free(one);
  ------------------
  |  |   71|      4|#define bignum_safe_free(num) do { \
  |  |   72|      4|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 3, False: 1]
  |  |  ------------------
  |  |   73|      3|        BN_clear_free((num)); \
  |  |   74|      3|        (num)=NULL; \
  |  |   75|      3|    } \
  |  |   76|      4|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 4]
  |  |  ------------------
  ------------------
  232|      4|    bignum_safe_free(pmin1);
  ------------------
  |  |   71|      4|#define bignum_safe_free(num) do { \
  |  |   72|      4|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 3, False: 1]
  |  |  ------------------
  |  |   73|      3|        BN_clear_free((num)); \
  |  |   74|      3|        (num)=NULL; \
  |  |   75|      3|    } \
  |  |   76|      4|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 4]
  |  |  ------------------
  ------------------
  233|       |#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
  234|       |    bignum_safe_free(pubkey);
  235|       |#endif /* OPENSSL_VERSION_NUMBER */
  236|      4|    ssh_dh_cleanup(session->next_crypto);
  237|      4|    session->session_state = SSH_SESSION_STATE_ERROR;
  238|       |
  239|      4|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      4|#define SSH_PACKET_USED 1
  ------------------
  240|      1|}

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

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

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

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

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

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

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

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

ssh_client_hybrid_mlkem_init:
  201|    121|{
  202|    121|    struct ssh_crypto_struct *crypto = session->next_crypto;
  203|    121|    ssh_buffer client_init_buffer = NULL;
  204|    121|    int rc, ret = SSH_ERROR;
  ------------------
  |  |  317|    121|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  205|       |
  206|    121|    SSH_LOG(SSH_LOG_TRACE, "Initializing hybrid ML-KEM key exchange");
  ------------------
  |  |  281|    121|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  207|       |
  208|       |    /* Prepare a buffer to concatenate ML-KEM + ECDH public keys */
  209|    121|    client_init_buffer = ssh_buffer_new();
  210|    121|    if (client_init_buffer == NULL) {
  ------------------
  |  Branch (210:9): [True: 0, False: 121]
  ------------------
  211|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  212|      0|        goto cleanup;
  213|      0|    }
  214|       |
  215|       |    /* Generate an ML-KEM keypair */
  216|    121|    rc = ssh_mlkem_init(session);
  217|    121|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    121|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (217:9): [True: 0, False: 121]
  ------------------
  218|      0|        ssh_set_error(session, SSH_FATAL, "Failed to generate an ML-KEM keypair");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  219|      0|        goto cleanup;
  220|      0|    }
  221|       |
  222|       |#ifdef DEBUG_CRYPTO
  223|       |    ssh_log_hexdump("ML-KEM client pubkey",
  224|       |                    ssh_string_data(crypto->mlkem_client_pubkey),
  225|       |                    ssh_string_len(crypto->mlkem_client_pubkey));
  226|       |#endif
  227|       |
  228|       |    /* Generate an ECDH keypair and concatenate the public keys  */
  229|    121|    switch (crypto->kex_type) {
  230|      4|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (230:5): [True: 4, False: 117]
  ------------------
  231|      4|        rc = ssh_curve25519_init(session);
  232|      4|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      4|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (232:13): [True: 0, False: 4]
  ------------------
  233|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  234|      0|                          SSH_FATAL,
  235|      0|                          "Failed to generate a Curve25519 ECDH keypair");
  236|      0|            goto cleanup;
  237|      0|        }
  238|       |#ifdef DEBUG_CRYPTO
  239|       |        ssh_log_hexdump("Curve25519 client pubkey",
  240|       |                        crypto->curve25519_client_pubkey,
  241|       |                        CURVE25519_PUBKEY_SIZE);
  242|       |#endif
  243|      4|        rc = ssh_buffer_pack(client_init_buffer,
  ------------------
  |  |   50|      4|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      4|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      4|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      4|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      4|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      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)
  |  |  ------------------
  ------------------
  244|      4|                             "PP",
  245|      4|                             ssh_string_len(crypto->mlkem_client_pubkey),
  246|      4|                             ssh_string_data(crypto->mlkem_client_pubkey),
  247|      4|                             (size_t)CURVE25519_PUBKEY_SIZE,
  248|      4|                             crypto->curve25519_client_pubkey);
  249|      4|        break;
  250|    117|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (250:5): [True: 117, False: 4]
  ------------------
  251|       |#ifdef HAVE_MLKEM1024
  252|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
  253|       |#endif
  254|    117|        rc = ssh_ecdh_init(session);
  255|    117|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    117|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (255:13): [True: 0, False: 117]
  ------------------
  256|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  257|      0|                          SSH_FATAL,
  258|      0|                          "Failed to generate a NIST-curve ECDH keypair");
  259|      0|            goto cleanup;
  260|      0|        }
  261|       |#ifdef DEBUG_CRYPTO
  262|       |        ssh_log_hexdump("ECDH client pubkey",
  263|       |                        ssh_string_data(crypto->ecdh_client_pubkey),
  264|       |                        ssh_string_len(crypto->ecdh_client_pubkey));
  265|       |#endif
  266|    117|        rc = ssh_buffer_pack(client_init_buffer,
  ------------------
  |  |   50|    117|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    117|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    117|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    117|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    117|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    117|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    117|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  267|    117|                             "PP",
  268|    117|                             ssh_string_len(crypto->mlkem_client_pubkey),
  269|    117|                             ssh_string_data(crypto->mlkem_client_pubkey),
  270|    117|                             ssh_string_len(crypto->ecdh_client_pubkey),
  271|    117|                             ssh_string_data(crypto->ecdh_client_pubkey));
  272|       |
  273|    117|        break;
  274|      0|    default:
  ------------------
  |  Branch (274:5): [True: 0, False: 121]
  ------------------
  275|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  276|      0|        goto cleanup;
  277|    121|    }
  278|    121|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    121|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (278:9): [True: 0, False: 121]
  ------------------
  279|      0|        ssh_set_error(session, SSH_FATAL, "Failed to construct client init buffer");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  280|      0|        goto cleanup;
  281|      0|    }
  282|       |
  283|       |    /* Convert the client init buffer to an SSH string */
  284|    121|    ssh_string_free(crypto->hybrid_client_init);
  285|    121|    crypto->hybrid_client_init = ssh_string_new(ssh_buffer_get_len(client_init_buffer));
  286|    121|    if (crypto->hybrid_client_init == NULL) {
  ------------------
  |  Branch (286:9): [True: 0, False: 121]
  ------------------
  287|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  288|      0|        goto cleanup;
  289|      0|    }
  290|       |
  291|    121|    rc = ssh_string_fill(crypto->hybrid_client_init,
  292|    121|                         ssh_buffer_get(client_init_buffer),
  293|    121|                         ssh_buffer_get_len(client_init_buffer));
  294|    121|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    121|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (294:9): [True: 0, False: 121]
  ------------------
  295|      0|        ssh_set_error(session, SSH_FATAL, "Failed to convert client init to string");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  296|      0|        goto cleanup;
  297|      0|    }
  298|       |
  299|    121|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    121|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    121|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    121|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    121|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    121|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    121|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    121|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  300|    121|                         "bS",
  301|    121|                         SSH2_MSG_KEX_HYBRID_INIT,
  302|    121|                         crypto->hybrid_client_init);
  303|    121|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    121|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (303:9): [True: 0, False: 121]
  ------------------
  304|      0|        ssh_set_error(session, SSH_FATAL, "Failed to construct SSH_MSG_KEX_HYBRID_INIT");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  305|      0|        goto cleanup;
  306|      0|    }
  307|       |
  308|    121|    ssh_packet_set_callbacks(session, &ssh_hybrid_mlkem_client_callbacks);
  309|    121|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  310|       |
  311|    121|    rc = ssh_packet_send(session);
  312|    121|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    121|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (312:9): [True: 0, False: 121]
  ------------------
  313|      0|        ssh_set_error(session, SSH_FATAL, "Failed to send SSH_MSG_KEX_HYBRID_INIT");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  314|      0|        goto cleanup;
  315|      0|    }
  316|       |
  317|    121|    ret = SSH_OK;
  ------------------
  |  |  316|    121|#define SSH_OK 0     /* No error */
  ------------------
  318|       |
  319|    121|cleanup:
  320|    121|    ssh_buffer_free(client_init_buffer);
  321|    121|    return ret;
  322|    121|}
ssh_client_hybrid_mlkem_remove_callbacks:
  531|     85|{
  532|     85|    ssh_packet_remove_callbacks(session, &ssh_hybrid_mlkem_client_callbacks);
  533|     85|}
hybrid_mlkem.c:ssh_packet_client_hybrid_mlkem_reply:
  325|     85|{
  326|     85|    struct ssh_crypto_struct *crypto = session->next_crypto;
  327|     85|    const struct mlkem_type_info *mlkem_info = NULL;
  328|     85|    ssh_string pubkey_blob = NULL;
  329|     85|    ssh_string signature = NULL;
  330|     85|    ssh_mlkem_shared_secret mlkem_shared_secret;
  331|     85|    ssh_string ecdh_shared_secret = NULL;
  332|     85|    ssh_buffer server_reply_buffer = NULL;
  333|     85|    size_t read_len;
  334|     85|    size_t ecdh_server_pubkey_size;
  335|     85|    int rc;
  336|     85|    (void)type;
  337|     85|    (void)user;
  338|       |
  339|     85|    SSH_LOG(SSH_LOG_TRACE, "Received ML-KEM hybrid server reply");
  ------------------
  |  |  281|     85|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  340|       |
  341|     85|    ssh_client_hybrid_mlkem_remove_callbacks(session);
  342|       |
  343|     85|    mlkem_info = kex_type_to_mlkem_info(crypto->kex_type);
  344|     85|    if (mlkem_info == NULL) {
  ------------------
  |  Branch (344:9): [True: 0, False: 85]
  ------------------
  345|      0|        ssh_set_error(session, SSH_FATAL, "Unknown ML-KEM type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  346|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  347|      0|        goto cleanup;
  348|      0|    }
  349|       |
  350|     85|    pubkey_blob = ssh_buffer_get_ssh_string(packet);
  351|     85|    if (pubkey_blob == NULL) {
  ------------------
  |  Branch (351:9): [True: 2, False: 83]
  ------------------
  352|      2|        ssh_set_error(session, SSH_FATAL, "No public key in packet");
  ------------------
  |  |  311|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  353|      2|        session->session_state = SSH_SESSION_STATE_ERROR;
  354|      2|        goto cleanup;
  355|      2|    }
  356|       |
  357|     83|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  358|     83|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     83|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (358:9): [True: 79, False: 4]
  ------------------
  359|     79|        ssh_set_error(session, SSH_FATAL, "Failed to import public key");
  ------------------
  |  |  311|     79|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  360|     79|        session->session_state = SSH_SESSION_STATE_ERROR;
  361|     79|        goto cleanup;
  362|     79|    }
  363|       |
  364|       |    /* Get server reply containing ML-KEM ciphertext + ECDH public key */
  365|      4|    ssh_string_free(crypto->hybrid_server_reply);
  366|      4|    crypto->hybrid_server_reply = ssh_buffer_get_ssh_string(packet);
  367|      4|    if (crypto->hybrid_server_reply == NULL) {
  ------------------
  |  Branch (367:9): [True: 3, False: 1]
  ------------------
  368|      3|        ssh_set_error(session, SSH_FATAL, "No server reply in packet");
  ------------------
  |  |  311|      3|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  369|      3|        session->session_state = SSH_SESSION_STATE_ERROR;
  370|      3|        goto cleanup;
  371|      3|    }
  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);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  376|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  377|      0|        goto cleanup;
  378|      0|    }
  379|       |
  380|      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");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  385|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  386|      0|        goto cleanup;
  387|      0|    }
  388|       |
  389|       |    /* Store ML-KEM ciphertext for decapsulation and sessionid calculation */
  390|      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);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  394|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  395|      0|        goto cleanup;
  396|      0|    }
  397|       |
  398|      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,
  ------------------
  |  |  311|      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,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  424|      0|                          SSH_FATAL,
  425|      0|                          "Could not read Curve25519 pubkey from "
  426|      0|                          "the server reply buffer, buffer too short");
  427|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
  428|      0|            goto cleanup;
  429|      0|        }
  430|      0|        if (ssh_buffer_get_len(server_reply_buffer) > 0) {
  ------------------
  |  Branch (430:13): [True: 0, False: 0]
  ------------------
  431|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  432|      0|                          SSH_FATAL,
  433|      0|                          "Unrecognized data in the server reply buffer");
  434|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
  435|      0|            goto cleanup;
  436|      0|        }
  437|       |#ifdef DEBUG_CRYPTO
  438|       |        ssh_log_hexdump("Curve25519 server pubkey",
  439|       |                        crypto->curve25519_server_pubkey,
  440|       |                        CURVE25519_PUBKEY_SIZE);
  441|       |#endif
  442|      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);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  452|      0|            session->session_state = SSH_SESSION_STATE_ERROR;
  453|      0|            goto cleanup;
  454|      0|        }
  455|      0|        ssh_buffer_get_data(server_reply_buffer,
  456|      0|                            ssh_string_data(crypto->ecdh_server_pubkey),
  457|      0|                            ecdh_server_pubkey_size);
  458|       |#ifdef DEBUG_CRYPTO
  459|       |        ssh_log_hexdump("ECDH server pubkey",
  460|       |                        ssh_string_data(crypto->ecdh_server_pubkey),
  461|       |                        ssh_string_len(crypto->ecdh_server_pubkey));
  462|       |#endif
  463|      0|        break;
  464|      0|    default:
  ------------------
  |  Branch (464:5): [True: 0, False: 0]
  ------------------
  465|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX type");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  466|      0|        goto cleanup;
  467|      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");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  473|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  474|      0|        goto cleanup;
  475|      0|    }
  476|       |
  477|       |#ifdef DEBUG_CRYPTO
  478|       |    ssh_log_hexdump("ML-KEM shared secret",
  479|       |                    mlkem_shared_secret,
  480|       |                    MLKEM_SHARED_SECRET_SIZE);
  481|       |#endif
  482|       |
  483|       |    /* Derive the classical ECDH shared secret */
  484|      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");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  507|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  508|      0|        goto cleanup;
  509|      0|    }
  510|      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");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  516|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  517|      0|        goto cleanup;
  518|      0|    }
  519|      0|    session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  520|       |
  521|     85|cleanup:
  522|     85|    ssh_burn(mlkem_shared_secret, sizeof(mlkem_shared_secret));
  ------------------
  |  |  388|     85|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  523|     85|    ssh_string_burn(ecdh_shared_secret);
  524|     85|    ssh_string_free(ecdh_shared_secret);
  525|     85|    ssh_string_free(pubkey_blob);
  526|     85|    ssh_buffer_free(server_reply_buffer);
  527|     85|    return SSH_PACKET_USED;
  ------------------
  |  |  637|     85|#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|    579|bool is_ssh_initialized(void) {
  285|       |
  286|    579|    bool is_initialized = false;
  287|       |
  288|    579|    ssh_mutex_lock(&ssh_init_mutex);
  289|    579|    is_initialized = _ssh_initialized > 0;
  290|    579|    ssh_mutex_unlock(&ssh_init_mutex);
  291|       |
  292|    579|    return is_initialized;
  293|    579|}
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|    570|{
  159|       |    /* Can't use VLAs with Visual Studio, so allocate the biggest
  160|       |     * digest buffer we can possibly need */
  161|    570|    unsigned char digest[DIGEST_MAX_LEN];
  162|    570|    size_t output_len = crypto->digest_len;
  163|    570|    ssh_mac_ctx ctx;
  164|    570|    int rc;
  165|       |
  166|    570|    if (DIGEST_MAX_LEN < crypto->digest_len) {
  ------------------
  |  |   56|    570|#define DIGEST_MAX_LEN 64
  ------------------
  |  Branch (166:9): [True: 0, False: 570]
  ------------------
  167|      0|        return -1;
  168|      0|    }
  169|       |
  170|    570|    ctx = ssh_mac_ctx_init(crypto->digest_type);
  171|    570|    if (ctx == NULL) {
  ------------------
  |  Branch (171:9): [True: 0, False: 570]
  ------------------
  172|      0|        return -1;
  173|      0|    }
  174|       |
  175|    570|    rc = ssh_mac_update(ctx, key, key_len);
  176|    570|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    570|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (176:9): [True: 0, False: 570]
  ------------------
  177|      0|        ssh_mac_ctx_free(ctx);
  178|      0|        return -1;
  179|      0|    }
  180|    570|    rc = ssh_mac_update(ctx, crypto->secret_hash, crypto->digest_len);
  181|    570|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    570|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (181:9): [True: 0, False: 570]
  ------------------
  182|      0|        ssh_mac_ctx_free(ctx);
  183|      0|        return -1;
  184|      0|    }
  185|    570|    rc = ssh_mac_update(ctx, &key_type, 1);
  186|    570|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    570|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (186:9): [True: 0, False: 570]
  ------------------
  187|      0|        ssh_mac_ctx_free(ctx);
  188|      0|        return -1;
  189|      0|    }
  190|    570|    rc = ssh_mac_update(ctx, crypto->session_id, crypto->session_id_len);
  191|    570|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    570|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (191:9): [True: 0, False: 570]
  ------------------
  192|      0|        ssh_mac_ctx_free(ctx);
  193|      0|        return -1;
  194|      0|    }
  195|    570|    rc = ssh_mac_final(digest, ctx);
  196|    570|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    570|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (196:9): [True: 0, False: 570]
  ------------------
  197|      0|        return -1;
  198|      0|    }
  199|       |
  200|    570|    if (requested_len < output_len) {
  ------------------
  |  Branch (200:9): [True: 380, False: 190]
  ------------------
  201|    380|        output_len = requested_len;
  202|    380|    }
  203|    570|    memcpy(output, digest, output_len);
  204|       |
  205|    570|    while (requested_len > output_len) {
  ------------------
  |  Branch (205:12): [True: 0, False: 570]
  ------------------
  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|    570|    return 0;
  238|    570|}
kdf.c:ssh_mac_ctx_init:
   54|    570|{
   55|    570|    ssh_mac_ctx ctx = malloc(sizeof(struct ssh_mac_ctx_struct));
   56|    570|    if (ctx == NULL) {
  ------------------
  |  Branch (56:9): [True: 0, False: 570]
  ------------------
   57|      0|        return NULL;
   58|      0|    }
   59|       |
   60|    570|    ctx->digest_type = type;
   61|    570|    switch (type) {
  ------------------
  |  Branch (61:13): [True: 570, False: 0]
  ------------------
   62|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (62:5): [True: 0, False: 570]
  ------------------
   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|    384|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (68:5): [True: 384, False: 186]
  ------------------
   69|    384|        ctx->ctx.sha256_ctx = sha256_init();
   70|    384|        if (ctx->ctx.sha256_ctx == NULL) {
  ------------------
  |  Branch (70:13): [True: 0, False: 384]
  ------------------
   71|      0|            goto err;
   72|      0|        }
   73|    384|        return ctx;
   74|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (74:5): [True: 0, False: 570]
  ------------------
   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|    186|    case SSH_KDF_SHA512:
  ------------------
  |  Branch (80:5): [True: 186, False: 384]
  ------------------
   81|    186|        ctx->ctx.sha512_ctx = sha512_init();
   82|    186|        if (ctx->ctx.sha512_ctx == NULL) {
  ------------------
  |  Branch (82:13): [True: 0, False: 186]
  ------------------
   83|      0|            goto err;
   84|      0|        }
   85|    186|        return ctx;
   86|    570|    }
   87|      0|err:
   88|      0|    SAFE_FREE(ctx);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
   89|       |    return NULL;
   90|    570|}
kdf.c:ssh_mac_update:
  116|  2.28k|{
  117|  2.28k|    switch (ctx->digest_type) {
  ------------------
  |  Branch (117:13): [True: 2.28k, False: 0]
  ------------------
  118|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (118:5): [True: 0, False: 2.28k]
  ------------------
  119|      0|        return sha1_update(ctx->ctx.sha1_ctx, data, len);
  120|  1.53k|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (120:5): [True: 1.53k, False: 744]
  ------------------
  121|  1.53k|        return sha256_update(ctx->ctx.sha256_ctx, data, len);
  122|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (122:5): [True: 0, False: 2.28k]
  ------------------
  123|      0|        return sha384_update(ctx->ctx.sha384_ctx, data, len);
  124|    744|    case SSH_KDF_SHA512:
  ------------------
  |  Branch (124:5): [True: 744, False: 1.53k]
  ------------------
  125|    744|        return sha512_update(ctx->ctx.sha512_ctx, data, len);
  126|  2.28k|    }
  127|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  128|  2.28k|}
kdf.c:ssh_mac_final:
  131|    570|{
  132|    570|    int rc = SSH_ERROR;
  ------------------
  |  |  317|    570|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  133|       |
  134|    570|    switch (ctx->digest_type) {
  ------------------
  |  Branch (134:13): [True: 570, False: 0]
  ------------------
  135|      0|    case SSH_KDF_SHA1:
  ------------------
  |  Branch (135:5): [True: 0, False: 570]
  ------------------
  136|      0|        rc = sha1_final(md, ctx->ctx.sha1_ctx);
  137|      0|        break;
  138|    384|    case SSH_KDF_SHA256:
  ------------------
  |  Branch (138:5): [True: 384, False: 186]
  ------------------
  139|    384|        rc = sha256_final(md, ctx->ctx.sha256_ctx);
  140|    384|        break;
  141|      0|    case SSH_KDF_SHA384:
  ------------------
  |  Branch (141:5): [True: 0, False: 570]
  ------------------
  142|      0|        rc = sha384_final(md, ctx->ctx.sha384_ctx);
  143|      0|        break;
  144|    186|    case SSH_KDF_SHA512:
  ------------------
  |  Branch (144:5): [True: 186, False: 384]
  ------------------
  145|    186|        rc = sha512_final(md, ctx->ctx.sha512_ctx);
  146|    186|        break;
  147|    570|    }
  148|    570|    SAFE_FREE(ctx);
  ------------------
  |  |  373|    570|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 570, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 570]
  |  |  ------------------
  ------------------
  149|    570|    return rc;
  150|    570|}

ssh_kex_get_default_methods:
  300|    508|{
  301|    508|    if (type >= SSH_KEX_METHODS) {
  ------------------
  |  |   27|    508|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (301:9): [True: 0, False: 508]
  ------------------
  302|      0|        return NULL;
  303|      0|    }
  304|       |
  305|    508|    return default_methods[type];
  306|    508|}
ssh_packet_kexinit:
  397|    370|{
  398|    370|    int i, ok;
  399|    370|    struct ssh_crypto_struct *crypto = session->next_crypto;
  400|    370|    int server_kex = session->server;
  401|    370|    ssh_string str = NULL;
  402|    370|    char *strings[SSH_KEX_METHODS] = {0};
  403|    370|    int rc = SSH_ERROR;
  ------------------
  |  |  317|    370|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  404|    370|    size_t len;
  405|       |
  406|    370|    uint8_t first_kex_packet_follows = 0;
  407|    370|    uint32_t kexinit_reserved = 0;
  408|       |
  409|    370|    (void)type;
  410|    370|    (void)user;
  411|       |
  412|    370|    SSH_LOG(SSH_LOG_TRACE, "KEXINIT received");
  ------------------
  |  |  281|    370|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  413|       |
  414|    370|    if (session->session_state == SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (414:9): [True: 0, False: 370]
  ------------------
  415|      0|        if (session->dh_handshake_state == DH_STATE_FINISHED) {
  ------------------
  |  Branch (415:13): [True: 0, False: 0]
  ------------------
  416|      0|            SSH_LOG(SSH_LOG_DEBUG, "Peer initiated key re-exchange");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  417|       |            /* Reset the sent flag if the re-kex was initiated by the peer */
  418|      0|            session->flags &= ~SSH_SESSION_FLAG_KEXINIT_SENT;
  ------------------
  |  |   86|      0|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
  419|      0|        } else if (session->flags & SSH_SESSION_FLAG_KEXINIT_SENT &&
  ------------------
  |  |   86|      0|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
  |  Branch (419:20): [True: 0, False: 0]
  ------------------
  420|      0|                   session->dh_handshake_state == DH_STATE_INIT_SENT) {
  ------------------
  |  Branch (420:20): [True: 0, False: 0]
  ------------------
  421|       |            /* This happens only when we are sending our-guessed first kex
  422|       |             * packet right after our KEXINIT packet. */
  423|      0|            SSH_LOG(SSH_LOG_DEBUG, "Received peer kexinit answer.");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  424|      0|        } else if (session->session_state != SSH_SESSION_STATE_INITIAL_KEX) {
  ------------------
  |  Branch (424:20): [True: 0, False: 0]
  ------------------
  425|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  426|      0|                          "SSH_KEXINIT received in wrong state");
  427|      0|            goto error;
  428|      0|        }
  429|    370|    } else if (session->session_state != SSH_SESSION_STATE_INITIAL_KEX) {
  ------------------
  |  Branch (429:16): [True: 0, False: 370]
  ------------------
  430|      0|        ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  431|      0|                      "SSH_KEXINIT received in wrong state");
  432|      0|        goto error;
  433|      0|    }
  434|       |
  435|    370|    if (server_kex) {
  ------------------
  |  Branch (435:9): [True: 0, False: 370]
  ------------------
  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,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  440|      0|                          "ssh_packet_kexinit: no cookie in packet");
  441|      0|            goto error;
  442|      0|        }
  443|       |
  444|      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,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  447|      0|                          "ssh_packet_kexinit: adding cookie failed");
  448|      0|            goto error;
  449|      0|        }
  450|       |
  451|      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|    370|    } else {
  457|    370|        len = ssh_buffer_get_data(packet, crypto->server_kex.cookie, 16);
  458|    370|        if (len != 16) {
  ------------------
  |  Branch (458:13): [True: 1, False: 369]
  ------------------
  459|      1|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      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|    369|        ok = ssh_hashbufin_add_cookie(session, crypto->server_kex.cookie);
  465|    369|        if (ok < 0) {
  ------------------
  |  Branch (465:13): [True: 0, False: 369]
  ------------------
  466|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  467|      0|                          "ssh_packet_kexinit: adding cookie failed");
  468|      0|            goto error;
  469|      0|        }
  470|       |
  471|    369|        ok = ssh_set_client_kex(session);
  472|    369|        if (ok == SSH_ERROR) {
  ------------------
  |  |  317|    369|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (472:13): [True: 0, False: 369]
  ------------------
  473|      0|            goto error;
  474|      0|        }
  475|    369|    }
  476|       |
  477|  3.89k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.89k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (477:17): [True: 3.54k, False: 349]
  ------------------
  478|  3.54k|        str = ssh_buffer_get_ssh_string(packet);
  479|  3.54k|        if (str == NULL) {
  ------------------
  |  Branch (479:13): [True: 20, False: 3.52k]
  ------------------
  480|     20|          goto error;
  481|     20|        }
  482|       |
  483|  3.52k|        rc = ssh_buffer_add_ssh_string(session->in_hashbuf, str);
  484|  3.52k|        if (rc < 0) {
  ------------------
  |  Branch (484:13): [True: 0, False: 3.52k]
  ------------------
  485|      0|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  486|      0|                          "Error adding string in hash buffer");
  487|      0|            goto error;
  488|      0|        }
  489|       |
  490|  3.52k|        strings[i] = ssh_string_to_char(str);
  491|  3.52k|        if (strings[i] == NULL) {
  ------------------
  |  Branch (491:13): [True: 0, False: 3.52k]
  ------------------
  492|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  493|      0|            goto error;
  494|      0|        }
  495|  3.52k|        SSH_STRING_FREE(str);
  ------------------
  |  |  915|  3.52k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 3.52k, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 3.52k]
  |  |  ------------------
  ------------------
  496|  3.52k|        str = NULL;
  497|  3.52k|    }
  498|       |
  499|       |    /* copy the peer kex info into an array of strings */
  500|    349|    if (server_kex) {
  ------------------
  |  Branch (500:9): [True: 0, False: 349]
  ------------------
  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|    349|    } else { /* client */
  507|  3.83k|        for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.83k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (507:21): [True: 3.49k, False: 349]
  ------------------
  508|  3.49k|            crypto->server_kex.methods[i] = strings[i];
  509|  3.49k|        }
  510|    349|    }
  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|    349|    rc = ssh_buffer_get_u8(packet, &first_kex_packet_follows);
  524|    349|    if (rc != 1) {
  ------------------
  |  Branch (524:9): [True: 2, False: 347]
  ------------------
  525|      2|        goto error;
  526|      2|    }
  527|       |
  528|    347|    rc = ssh_buffer_add_u8(session->in_hashbuf, first_kex_packet_follows);
  529|    347|    if (rc < 0) {
  ------------------
  |  Branch (529:9): [True: 0, False: 347]
  ------------------
  530|      0|        goto error;
  531|      0|    }
  532|       |
  533|    347|    rc = ssh_buffer_add_u32(session->in_hashbuf, kexinit_reserved);
  534|    347|    if (rc < 0) {
  ------------------
  |  Branch (534:9): [True: 0, False: 347]
  ------------------
  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|    347|    if (first_kex_packet_follows || session->send_first_kex_follows) {
  ------------------
  |  Branch (544:9): [True: 194, False: 153]
  |  Branch (544:37): [True: 0, False: 153]
  ------------------
  545|    194|        char **client_methods = crypto->client_kex.methods;
  546|    194|        char **server_methods = crypto->server_kex.methods;
  547|    194|        session->first_kex_follows_guess_wrong =
  548|    194|            cmp_first_kex_algo(client_methods[SSH_KEX],
  ------------------
  |  Branch (548:13): [True: 189, False: 5]
  ------------------
  549|    194|                               server_methods[SSH_KEX]) ||
  550|      5|            cmp_first_kex_algo(client_methods[SSH_HOSTKEYS],
  ------------------
  |  Branch (550:13): [True: 5, False: 0]
  ------------------
  551|      5|                               server_methods[SSH_HOSTKEYS]);
  552|    194|            SSH_LOG(SSH_LOG_DEBUG, "The initial guess was %s.",
  ------------------
  |  |  281|    388|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 194, False: 0]
  |  |  ------------------
  ------------------
  553|    194|                    session->first_kex_follows_guess_wrong ? "wrong" : "right");
  554|    194|    }
  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|    347|    if (server_kex) {
  ------------------
  |  Branch (560:9): [True: 0, False: 347]
  ------------------
  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.");
  ------------------
  |  |  281|      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|    347|    } else {
  568|       |        /* client kex */
  569|    347|        ok = match_group(crypto->server_kex.methods[SSH_KEX],
  570|    347|                         KEX_STRICT_SERVER);
  ------------------
  |  |  197|    347|#define KEX_STRICT_SERVER "kex-strict-s-v00@openssh.com"
  ------------------
  571|    347|        if (ok) {
  ------------------
  |  Branch (571:13): [True: 26, False: 321]
  ------------------
  572|     26|            SSH_LOG(SSH_LOG_DEBUG, "Server supports strict kex, enabling.");
  ------------------
  |  |  281|     26|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  573|     26|            session->flags |= SSH_SESSION_FLAG_KEX_STRICT;
  ------------------
  |  |   90|     26|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  574|     26|        }
  575|    347|    }
  576|    347|#ifdef WITH_SERVER
  577|    347|    if (server_kex) {
  ------------------
  |  Branch (577:9): [True: 0, False: 347]
  ------------------
  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;
  ------------------
  |  |  123|      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;
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  605|      0|                    }
  606|      0|                    SAFE_FREE(is_allowed);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  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;
  ------------------
  |  |  125|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  617|      0|                    }
  618|      0|                    SAFE_FREE(is_allowed);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  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) &&
  ------------------
  |  |  125|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  |  Branch (626:17): [True: 0, False: 0]
  ------------------
  627|      0|                (session->extensions & SSH_EXT_SIG_RSA_SHA512)) {
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  |  Branch (627:17): [True: 0, False: 0]
  ------------------
  628|      0|                char *rsa_sig_ext = NULL;
  629|      0|                session->extensions &= ~(SSH_EXT_SIG_RSA_SHA256 | SSH_EXT_SIG_RSA_SHA512);
  ------------------
  |  |  125|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
                              session->extensions &= ~(SSH_EXT_SIG_RSA_SHA256 | SSH_EXT_SIG_RSA_SHA512);
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  630|      0|                rsa_sig_ext = ssh_find_matching("rsa-sha2-512,rsa-sha2-256",
  631|      0|                                                hostkeys);
  632|      0|                if (rsa_sig_ext == NULL) {
  ------------------
  |  Branch (632:21): [True: 0, False: 0]
  ------------------
  633|      0|                    goto error; /* should never happen */
  634|      0|                } else if (strcmp(rsa_sig_ext, "rsa-sha2-512") == 0) {
  ------------------
  |  Branch (634:28): [True: 0, False: 0]
  ------------------
  635|      0|                    session->extensions |= SSH_EXT_SIG_RSA_SHA512;
  ------------------
  |  |  126|      0|#define SSH_EXT_SIG_RSA_SHA512  0x04
  ------------------
  636|      0|                } else if (strcmp(rsa_sig_ext, "rsa-sha2-256") == 0) {
  ------------------
  |  Branch (636:28): [True: 0, False: 0]
  ------------------
  637|      0|                    session->extensions |= SSH_EXT_SIG_RSA_SHA256;
  ------------------
  |  |  125|      0|#define SSH_EXT_SIG_RSA_SHA256  0x02
  ------------------
  638|      0|                } else {
  639|      0|                    SAFE_FREE(rsa_sig_ext);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  640|      0|                    goto error; /* should never happen */
  641|      0|                }
  642|      0|                SAFE_FREE(rsa_sig_ext);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  643|      0|            }
  644|       |
  645|      0|            SSH_LOG(SSH_LOG_DEBUG, "The client supports extension "
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 0]
  |  |  |  Branch (281: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|    347|#endif /* WITH_SERVER */
  652|       |
  653|       |    /* Note, that his overwrites authenticated state in case of rekeying */
  654|    347|    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|    347|    if (session->send_first_kex_follows == false) {
  ------------------
  |  Branch (658:9): [True: 347, False: 0]
  ------------------
  659|    347|        session->dh_handshake_state = DH_STATE_INIT;
  660|    347|    }
  661|    347|    session->ssh_connection_callback(session);
  662|    347|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    347|#define SSH_PACKET_USED 1
  ------------------
  663|       |
  664|     23|error:
  665|     23|    SSH_STRING_FREE(str);
  ------------------
  |  |  915|     23|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 23]
  |  |  |  Branch (915:69): [Folded, False: 23]
  |  |  ------------------
  ------------------
  666|    253|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|    253|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (666:17): [True: 230, False: 23]
  ------------------
  667|    230|        if (server_kex) {
  ------------------
  |  Branch (667:13): [True: 0, False: 230]
  ------------------
  668|      0|#ifdef WITH_SERVER
  669|      0|            session->next_crypto->client_kex.methods[i] = NULL;
  670|      0|#endif /* WITH_SERVER */
  671|    230|        } else { /* client */
  672|    230|            session->next_crypto->server_kex.methods[i] = NULL;
  673|    230|        }
  674|    230|        SAFE_FREE(strings[i]);
  ------------------
  |  |  373|    230|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 53, False: 177]
  |  |  |  Branch (373:71): [Folded, False: 230]
  |  |  ------------------
  ------------------
  675|    230|    }
  676|       |
  677|     23|    session->session_state = SSH_SESSION_STATE_ERROR;
  678|       |
  679|     23|    return SSH_PACKET_USED;
  ------------------
  |  |  637|     23|#define SSH_PACKET_USED 1
  ------------------
  680|    347|}
ssh_list_kex:
  682|    855|void ssh_list_kex(struct ssh_kex_struct *kex) {
  683|    855|  int i = 0;
  684|       |
  685|       |#ifdef DEBUG_CRYPTO
  686|       |  ssh_log_hexdump("session cookie", kex->cookie, 16);
  687|       |#endif
  688|       |
  689|  9.40k|  for(i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  9.40k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (689:14): [True: 8.55k, False: 855]
  ------------------
  690|  8.55k|    if (kex->methods[i] == NULL) {
  ------------------
  |  Branch (690:9): [True: 0, False: 8.55k]
  ------------------
  691|      0|      continue;
  692|      0|    }
  693|  8.55k|    SSH_LOG(SSH_LOG_FUNCTIONS, "%s: %s",
  ------------------
  |  |  281|  8.55k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  694|  8.55k|        ssh_kex_descriptions[i], kex->methods[i]);
  695|  8.55k|  }
  696|    855|}
ssh_client_select_hostkeys:
  708|    508|{
  709|    508|    const char *wanted = NULL;
  710|    508|    char *wanted_without_certs = NULL;
  711|    508|    char *known_hosts_algorithms = NULL;
  712|    508|    char *known_hosts_ordered = NULL;
  713|    508|    char *new_hostkeys = NULL;
  714|    508|    char *fips_hostkeys = NULL;
  715|       |
  716|    508|    wanted = session->opts.wanted_methods[SSH_HOSTKEYS];
  717|    508|    if (wanted == NULL) {
  ------------------
  |  Branch (717:9): [True: 508, False: 0]
  ------------------
  718|    508|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|    508|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 508]
  |  |  ------------------
  ------------------
  719|      0|            wanted = ssh_kex_get_fips_methods(SSH_HOSTKEYS);
  720|    508|        } else {
  721|    508|            wanted = ssh_kex_get_default_methods(SSH_HOSTKEYS);
  722|    508|        }
  723|    508|    }
  724|       |
  725|       |    /* This removes the certificate types, unsupported for now */
  726|    508|    wanted_without_certs = ssh_find_all_matching(HOSTKEYS, wanted);
  ------------------
  |  |  142|    508|#define HOSTKEYS "ssh-ed25519," \
  |  |  143|    508|                 EC_HOSTKEYS \
  |  |  144|    508|                 "sk-ssh-ed25519@openssh.com," \
  |  |  145|    508|                 EC_SK_HOSTKEYS \
  |  |  146|    508|                 "rsa-sha2-512," \
  |  |  147|    508|                 "rsa-sha2-256," \
  |  |  148|    508|                 "ssh-rsa"
  ------------------
  727|    508|    if (wanted_without_certs == NULL) {
  ------------------
  |  Branch (727:9): [True: 0, False: 508]
  ------------------
  728|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  729|      0|                "List of allowed host key algorithms is empty or contains only "
  730|      0|                "unsupported algorithms");
  731|      0|        return NULL;
  732|      0|    }
  733|       |
  734|    508|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    508|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  735|    508|            "Order of wanted host keys: \"%s\"",
  736|    508|            wanted_without_certs);
  737|       |
  738|    508|    known_hosts_algorithms = ssh_known_hosts_get_algorithms_names(session);
  739|    508|    if (known_hosts_algorithms == NULL) {
  ------------------
  |  Branch (739:9): [True: 508, False: 0]
  ------------------
  740|    508|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    508|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  741|    508|                "No key found in known_hosts; "
  742|    508|                "changing host key method to \"%s\"",
  743|    508|                wanted_without_certs);
  744|       |
  745|    508|        return wanted_without_certs;
  746|    508|    }
  747|       |
  748|      0|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  749|      0|            "Algorithms found in known_hosts files: \"%s\"",
  750|      0|            known_hosts_algorithms);
  751|       |
  752|       |    /* Filter and order the keys from known_hosts according to wanted list */
  753|      0|    known_hosts_ordered = ssh_find_all_matching(known_hosts_algorithms,
  754|      0|                                                wanted_without_certs);
  755|      0|    SAFE_FREE(known_hosts_algorithms);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  756|      0|    if (known_hosts_ordered == NULL) {
  ------------------
  |  Branch (756:9): [True: 0, False: 0]
  ------------------
  757|      0|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  758|      0|                "No key found in known_hosts is allowed; "
  759|      0|                "changing host key method to \"%s\"",
  760|      0|                wanted_without_certs);
  761|       |
  762|      0|        return wanted_without_certs;
  763|      0|    }
  764|       |
  765|       |    /* Append the other supported keys after the preferred ones
  766|       |     * This function tolerates NULL pointers in parameters */
  767|      0|    new_hostkeys = ssh_append_without_duplicates(known_hosts_ordered,
  768|      0|                                                 wanted_without_certs);
  769|      0|    SAFE_FREE(known_hosts_ordered);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  770|      0|    SAFE_FREE(wanted_without_certs);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  771|      0|    if (new_hostkeys == NULL) {
  ------------------
  |  Branch (771:9): [True: 0, False: 0]
  ------------------
  772|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  773|      0|        return NULL;
  774|      0|    }
  775|       |
  776|      0|    if (ssh_fips_mode()) {
  ------------------
  |  |  115|      0|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  777|       |        /* Filter out algorithms not allowed in FIPS mode */
  778|      0|        fips_hostkeys = ssh_keep_fips_algos(SSH_HOSTKEYS, new_hostkeys);
  779|      0|        SAFE_FREE(new_hostkeys);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  780|      0|        if (fips_hostkeys == NULL) {
  ------------------
  |  Branch (780:13): [True: 0, False: 0]
  ------------------
  781|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  782|      0|                    "None of the wanted host keys or keys in known_hosts files "
  783|      0|                    "is allowed in FIPS mode.");
  784|      0|            return NULL;
  785|      0|        }
  786|      0|        new_hostkeys = fips_hostkeys;
  787|      0|    }
  788|       |
  789|      0|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  790|      0|            "Changing host key method to \"%s\"",
  791|      0|            new_hostkeys);
  792|       |
  793|      0|    return new_hostkeys;
  794|      0|}
ssh_set_client_kex:
  801|    877|{
  802|    877|    struct ssh_kex_struct *client = &session->next_crypto->client_kex;
  803|    877|    const char *wanted = NULL;
  804|    877|    int ok;
  805|    877|    int i;
  806|    877|    bool gssapi_null_alg = false;
  807|    877|    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|    877|    if (client->methods[0] != NULL) {
  ------------------
  |  Branch (811:9): [True: 369, False: 508]
  ------------------
  812|    369|        return SSH_OK;
  ------------------
  |  |  316|    369|#define SSH_OK 0     /* No error */
  ------------------
  813|    369|    }
  814|       |
  815|    508|    ok = ssh_get_random(client->cookie, 16, 0);
  816|    508|    if (!ok) {
  ------------------
  |  Branch (816:9): [True: 0, False: 508]
  ------------------
  817|      0|        ssh_set_error(session, SSH_FATAL, "PRNG error");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  818|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  819|      0|    }
  820|       |#ifdef WITH_GSSAPI
  821|       |    if (session->opts.gssapi_key_exchange) {
  822|       |        char *gssapi_algs = NULL;
  823|       |
  824|       |        ok = ssh_gssapi_init(session);
  825|       |        if (ok != SSH_OK) {
  826|       |            ssh_set_error_oom(session);
  827|       |            return SSH_ERROR;
  828|       |        }
  829|       |
  830|       |        ok = ssh_gssapi_import_name(session->gssapi, session->opts.host);
  831|       |        if (ok != SSH_OK) {
  832|       |            return SSH_ERROR;
  833|       |        }
  834|       |
  835|       |        gssapi_algs = ssh_gssapi_kex_mechs(session);
  836|       |        if (gssapi_algs == NULL) {
  837|       |            return SSH_ERROR;
  838|       |        }
  839|       |
  840|       |        /* Prefix the default algorithms with gsskex algs */
  841|       |        if (ssh_fips_mode()) {
  842|       |            session->opts.wanted_methods[SSH_KEX] =
  843|       |                ssh_prefix_without_duplicates(fips_methods[SSH_KEX],
  844|       |                                              gssapi_algs);
  845|       |        } else {
  846|       |            session->opts.wanted_methods[SSH_KEX] =
  847|       |                ssh_prefix_without_duplicates(default_methods[SSH_KEX],
  848|       |                                              gssapi_algs);
  849|       |        }
  850|       |
  851|       |        gssapi_null_alg = true;
  852|       |
  853|       |        SAFE_FREE(gssapi_algs);
  854|       |    }
  855|       |#endif
  856|       |
  857|       |    /* Set the list of allowed algorithms in order of preference, if it hadn't
  858|       |     * been set yet. */
  859|  5.58k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  5.58k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (859:17): [True: 5.08k, False: 508]
  ------------------
  860|  5.08k|        if (i == SSH_HOSTKEYS) {
  ------------------
  |  Branch (860:13): [True: 508, False: 4.57k]
  ------------------
  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|    508|            client->methods[i] = ssh_client_select_hostkeys(session);
  865|    508|            if (client->methods[i] == NULL) {
  ------------------
  |  Branch (865:17): [True: 0, False: 508]
  ------------------
  866|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  867|      0|                return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  868|      0|            }
  869|    508|            if (gssapi_null_alg) {
  ------------------
  |  Branch (869:17): [True: 0, False: 508]
  ------------------
  870|      0|                hostkeys =
  871|      0|                    ssh_append_without_duplicates(client->methods[i], "null");
  872|      0|                if (hostkeys == NULL) {
  ------------------
  |  Branch (872:21): [True: 0, False: 0]
  ------------------
  873|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  874|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  875|      0|                }
  876|      0|                SAFE_FREE(client->methods[i]);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  877|      0|                client->methods[i] = hostkeys;
  878|      0|            }
  879|    508|            continue;
  880|    508|        }
  881|       |
  882|  4.57k|        wanted = session->opts.wanted_methods[i];
  883|  4.57k|        if (wanted == NULL) {
  ------------------
  |  Branch (883:13): [True: 2.54k, False: 2.03k]
  ------------------
  884|  2.54k|            if (ssh_fips_mode()) {
  ------------------
  |  |  115|  2.54k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 2.54k]
  |  |  ------------------
  ------------------
  885|      0|                wanted = fips_methods[i];
  886|  2.54k|            } else {
  887|  2.54k|                wanted = default_methods[i];
  888|  2.54k|            }
  889|  2.54k|        }
  890|  4.57k|        client->methods[i] = strdup(wanted);
  891|  4.57k|        if (client->methods[i] == NULL) {
  ------------------
  |  Branch (891:13): [True: 0, False: 4.57k]
  ------------------
  892|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  893|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  894|      0|        }
  895|  4.57k|    }
  896|       |
  897|       |    /* For rekeying, skip the extension negotiation */
  898|    508|    if (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) {
  ------------------
  |  |   78|    508|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (898:9): [True: 0, False: 508]
  ------------------
  899|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  900|      0|    }
  901|       |
  902|    508|    ok = ssh_kex_append_extensions(session, client);
  903|    508|    if (ok != SSH_OK){
  ------------------
  |  |  316|    508|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (903:9): [True: 0, False: 508]
  ------------------
  904|      0|        return ok;
  905|      0|    }
  906|       |
  907|    508|    return SSH_OK;
  ------------------
  |  |  316|    508|#define SSH_OK 0     /* No error */
  ------------------
  908|    508|}
ssh_kex_append_extensions:
  911|    508|{
  912|    508|    char *kex = NULL;
  913|    508|    char *kex_tmp = NULL;
  914|    508|    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|    508|    kex = pkex->methods[SSH_KEX];
  920|    508|    len = strlen(kex);
  921|    508|    if (session->server) {
  ------------------
  |  Branch (921:9): [True: 0, False: 508]
  ------------------
  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|    508|    } else {
  925|       |        /* Comma, comma, nul byte */
  926|    508|        kex_len = len + 1 + strlen(KEX_EXTENSION_CLIENT) + 1 +
  ------------------
  |  |  194|    508|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  927|    508|                  strlen(KEX_STRICT_CLIENT) + 1;
  ------------------
  |  |  196|    508|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  928|    508|    }
  929|    508|    if (kex_len >= MAX_PACKET_LEN) {
  ------------------
  |  |  216|    508|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (929:9): [True: 0, False: 508]
  ------------------
  930|       |        /* Overflow */
  931|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  932|      0|    }
  933|    508|    kex_tmp = realloc(kex, kex_len);
  934|    508|    if (kex_tmp == NULL) {
  ------------------
  |  Branch (934:9): [True: 0, False: 508]
  ------------------
  935|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  936|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  937|      0|    }
  938|    508|    if (session->server){
  ------------------
  |  Branch (938:9): [True: 0, False: 508]
  ------------------
  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|    508|    } else {
  941|    508|        snprintf(kex_tmp + len,
  942|    508|                 kex_len - len,
  943|    508|                 ",%s,%s",
  944|    508|                 KEX_EXTENSION_CLIENT,
  ------------------
  |  |  194|    508|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
  945|    508|                 KEX_STRICT_CLIENT);
  ------------------
  |  |  196|    508|#define KEX_STRICT_CLIENT "kex-strict-c-v00@openssh.com"
  ------------------
  946|    508|    }
  947|    508|    pkex->methods[SSH_KEX] = kex_tmp;
  948|    508|    return SSH_OK;
  ------------------
  |  |  316|    508|#define SSH_OK 0     /* No error */
  ------------------
  949|    508|}
ssh_kex_select_methods:
 1082|    347|{
 1083|    347|    struct ssh_crypto_struct *crypto = session->next_crypto;
 1084|    347|    struct ssh_kex_struct *server = &crypto->server_kex;
 1085|    347|    struct ssh_kex_struct *client = &crypto->client_kex;
 1086|    347|    char *ext_start = NULL;
 1087|    347|    const char *aead_hmac = NULL;
 1088|    347|    enum ssh_key_exchange_e kex_type;
 1089|    347|    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|    347|    if (session->client) {
  ------------------
  |  Branch (1093:9): [True: 347, False: 0]
  ------------------
 1094|    347|        ext_start = strstr(client->methods[SSH_KEX], "," KEX_EXTENSION_CLIENT);
  ------------------
  |  |  194|    347|#define KEX_EXTENSION_CLIENT "ext-info-c"
  ------------------
 1095|    347|        if (ext_start != NULL) {
  ------------------
  |  Branch (1095:13): [True: 347, False: 0]
  ------------------
 1096|    347|            ext_start[0] = '\0';
 1097|    347|        }
 1098|    347|    }
 1099|    347|    if (session->server) {
  ------------------
  |  Branch (1099:9): [True: 0, False: 347]
  ------------------
 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.30k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  3.30k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (1106:17): [True: 3.00k, False: 295]
  ------------------
 1107|  3.00k|        crypto->kex_methods[i] = ssh_find_matching(server->methods[i],
 1108|  3.00k|                                                   client->methods[i]);
 1109|       |
 1110|  3.00k|        if (i == SSH_MAC_C_S || i == SSH_MAC_S_C) {
  ------------------
  |  Branch (1110:13): [True: 295, False: 2.71k]
  |  Branch (1110:33): [True: 295, False: 2.41k]
  ------------------
 1111|    590|            aead_hmac = ssh_find_aead_hmac(crypto->kex_methods[i - 2]);
 1112|    590|            if (aead_hmac) {
  ------------------
  |  Branch (1112:17): [True: 0, False: 590]
  ------------------
 1113|      0|                free(crypto->kex_methods[i]);
 1114|      0|                crypto->kex_methods[i] = strdup(aead_hmac);
 1115|      0|            }
 1116|    590|        }
 1117|  3.00k|        if (crypto->kex_methods[i] == NULL && i < SSH_LANG_C_S) {
  ------------------
  |  Branch (1117:13): [True: 111, False: 2.89k]
  |  Branch (1117:47): [True: 52, False: 59]
  ------------------
 1118|     52|            ssh_set_error(session, SSH_FATAL,
  ------------------
  |  |  311|     52|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1119|     52|                          "kex error : no match for method %s: server [%s], "
 1120|     52|                          "client [%s]", ssh_kex_descriptions[i],
 1121|     52|                          server->methods[i], client->methods[i]);
 1122|     52|            return SSH_ERROR;
  ------------------
  |  |  317|     52|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1123|  2.95k|        } else if ((i >= SSH_LANG_C_S) && (crypto->kex_methods[i] == NULL)) {
  ------------------
  |  Branch (1123:20): [True: 590, False: 2.36k]
  |  Branch (1123:43): [True: 59, False: 531]
  ------------------
 1124|       |            /* we can safely do that for languages */
 1125|     59|            crypto->kex_methods[i] = strdup("");
 1126|     59|        }
 1127|  3.00k|    }
 1128|       |
 1129|       |    /* We can not set this value directly as the old value is needed to revert
 1130|       |     * callbacks if we are client */
 1131|    295|    kex_type = kex_select_kex_type(crypto->kex_methods[SSH_KEX]);
 1132|    295|    if (session->client && session->first_kex_follows_guess_wrong) {
  ------------------
  |  Branch (1132:9): [True: 295, False: 0]
  |  Branch (1132:28): [True: 173, False: 122]
  ------------------
 1133|    173|        SSH_LOG(SSH_LOG_DEBUG, "Our guess was wrong. Restarting the KEX");
  ------------------
  |  |  281|    173|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1134|       |        /* We need to remove the wrong callbacks and start kex again */
 1135|    173|        revert_kex_callbacks(session);
 1136|    173|        session->dh_handshake_state = DH_STATE_INIT;
 1137|    173|        session->first_kex_follows_guess_wrong = false;
 1138|    173|    }
 1139|    295|    crypto->kex_type = kex_type;
 1140|       |
 1141|    295|    SSH_LOG(SSH_LOG_DEBUG, "Negotiated %s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
  ------------------
  |  |  281|    295|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1142|    295|            session->next_crypto->kex_methods[SSH_KEX],
 1143|    295|            session->next_crypto->kex_methods[SSH_HOSTKEYS],
 1144|    295|            session->next_crypto->kex_methods[SSH_CRYPT_C_S],
 1145|    295|            session->next_crypto->kex_methods[SSH_CRYPT_S_C],
 1146|    295|            session->next_crypto->kex_methods[SSH_MAC_C_S],
 1147|    295|            session->next_crypto->kex_methods[SSH_MAC_S_C],
 1148|    295|            session->next_crypto->kex_methods[SSH_COMP_C_S],
 1149|    295|            session->next_crypto->kex_methods[SSH_COMP_S_C],
 1150|    295|            session->next_crypto->kex_methods[SSH_LANG_C_S],
 1151|    295|            session->next_crypto->kex_methods[SSH_LANG_S_C]
 1152|    295|    );
 1153|    295|    return SSH_OK;
  ------------------
  |  |  316|    295|#define SSH_OK 0     /* No error */
  ------------------
 1154|    347|}
ssh_send_kex:
 1159|    508|{
 1160|    508|    struct ssh_kex_struct *kex = (session->server ?
  ------------------
  |  Branch (1160:35): [True: 0, False: 508]
  ------------------
 1161|      0|        &session->next_crypto->server_kex :
 1162|    508|        &session->next_crypto->client_kex);
 1163|    508|    ssh_string str = NULL;
 1164|    508|    int i;
 1165|    508|    int rc;
 1166|    508|    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|    508|    if (session->client &&
  ------------------
  |  Branch (1170:9): [True: 508, False: 0]
  ------------------
 1171|    508|        session->session_state != SSH_SESSION_STATE_KEXINIT_RECEIVED &&
  ------------------
  |  Branch (1171:9): [True: 508, False: 0]
  ------------------
 1172|    508|        session->send_first_kex_follows) {
  ------------------
  |  Branch (1172:9): [True: 0, False: 508]
  ------------------
 1173|      0|        first_kex_packet_follows = 1;
 1174|      0|    }
 1175|       |
 1176|    508|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|    508|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1177|    508|            "Sending KEXINIT packet, first_kex_packet_follows = %d",
 1178|    508|            first_kex_packet_follows);
 1179|       |
 1180|    508|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    508|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    508|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    508|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    508|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    508|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    508|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    508|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1181|    508|                         "bP",
 1182|    508|                         SSH2_MSG_KEXINIT,
 1183|    508|                         (size_t)16,
 1184|    508|                         kex->cookie); /* cookie */
 1185|    508|    if (rc != SSH_OK)
  ------------------
  |  |  316|    508|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1185:9): [True: 0, False: 508]
  ------------------
 1186|      0|        goto error;
 1187|    508|    if (ssh_hashbufout_add_cookie(session) < 0) {
  ------------------
  |  Branch (1187:9): [True: 0, False: 508]
  ------------------
 1188|      0|        goto error;
 1189|      0|    }
 1190|       |
 1191|    508|    ssh_list_kex(kex);
 1192|       |
 1193|  5.58k|    for (i = 0; i < SSH_KEX_METHODS; i++) {
  ------------------
  |  |   27|  5.58k|#define SSH_KEX_METHODS 10
  ------------------
  |  Branch (1193:17): [True: 5.08k, False: 508]
  ------------------
 1194|  5.08k|        str = ssh_string_from_char(kex->methods[i]);
 1195|  5.08k|        if (str == NULL) {
  ------------------
  |  Branch (1195:13): [True: 0, False: 5.08k]
  ------------------
 1196|      0|            goto error;
 1197|      0|        }
 1198|       |
 1199|  5.08k|        rc = ssh_buffer_add_ssh_string(session->out_hashbuf, str);
 1200|  5.08k|        if (rc < 0) {
  ------------------
  |  Branch (1200:13): [True: 0, False: 5.08k]
  ------------------
 1201|      0|            goto error;
 1202|      0|        }
 1203|  5.08k|        rc = ssh_buffer_add_ssh_string(session->out_buffer, str);
 1204|  5.08k|        if (rc < 0) {
  ------------------
  |  Branch (1204:13): [True: 0, False: 5.08k]
  ------------------
 1205|      0|            goto error;
 1206|      0|        }
 1207|  5.08k|        SSH_STRING_FREE(str);
  ------------------
  |  |  915|  5.08k|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 5.08k, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 5.08k]
  |  |  ------------------
  ------------------
 1208|  5.08k|        str = NULL;
 1209|  5.08k|    }
 1210|       |
 1211|    508|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|    508|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    508|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    508|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    508|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    508|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    508|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    508|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1212|    508|                         "bd",
 1213|    508|                         first_kex_packet_follows,
 1214|    508|                         0);
 1215|    508|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    508|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1215:9): [True: 0, False: 508]
  ------------------
 1216|      0|        goto error;
 1217|      0|    }
 1218|       |
 1219|       |    /* Prepare also the first_kex_packet_follows and reserved to 0 */
 1220|    508|    rc = ssh_buffer_add_u8(session->out_hashbuf, first_kex_packet_follows);
 1221|    508|    if (rc < 0) {
  ------------------
  |  Branch (1221:9): [True: 0, False: 508]
  ------------------
 1222|      0|        goto error;
 1223|      0|    }
 1224|    508|    rc = ssh_buffer_add_u32(session->out_hashbuf, 0);
 1225|    508|    if (rc < 0) {
  ------------------
  |  Branch (1225:9): [True: 0, False: 508]
  ------------------
 1226|      0|        goto error;
 1227|      0|    }
 1228|       |
 1229|    508|    rc = ssh_packet_send(session);
 1230|    508|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|    508|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1230:9): [True: 0, False: 508]
  ------------------
 1231|      0|        return -1;
 1232|      0|    }
 1233|       |
 1234|    508|    session->flags |= SSH_SESSION_FLAG_KEXINIT_SENT;
  ------------------
  |  |   86|    508|#define SSH_SESSION_FLAG_KEXINIT_SENT 0x0008
  ------------------
 1235|    508|    SSH_LOG(SSH_LOG_PACKET, "SSH_MSG_KEXINIT sent");
  ------------------
  |  |  281|    508|    _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|    508|    if (first_kex_packet_follows == 1) {
  ------------------
  |  Branch (1239:9): [True: 0, False: 508]
  ------------------
 1240|      0|        char *list = kex->methods[SSH_KEX];
 1241|      0|        const char *colon = strchr(list, ',');
 1242|      0|        size_t kex_name_len = colon ? (size_t)(colon - list) : strlen(list);
  ------------------
  |  Branch (1242:31): [True: 0, False: 0]
  ------------------
 1243|      0|        char *kex_name = calloc(kex_name_len + 1, 1);
 1244|      0|        if (kex_name == NULL) {
  ------------------
  |  Branch (1244:13): [True: 0, False: 0]
  ------------------
 1245|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1246|      0|            goto error;
 1247|      0|        }
 1248|      0|        snprintf(kex_name, kex_name_len + 1, "%.*s", (int)kex_name_len, list);
 1249|      0|        SSH_LOG(SSH_LOG_TRACE, "Sending the first kex packet for %s", kex_name);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1250|       |
 1251|      0|        session->next_crypto->kex_type = kex_select_kex_type(kex_name);
 1252|      0|        free(kex_name);
 1253|       |
 1254|       |        /* run the first step of the DH handshake */
 1255|      0|        session->dh_handshake_state = DH_STATE_INIT;
 1256|      0|        if (dh_handshake(session) == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1256:13): [True: 0, False: 0]
  ------------------
 1257|      0|            goto error;
 1258|      0|        }
 1259|      0|    }
 1260|    508|    return 0;
 1261|       |
 1262|      0|error:
 1263|      0|    ssh_buffer_reinit(session->out_buffer);
 1264|      0|    ssh_buffer_reinit(session->out_hashbuf);
 1265|      0|    SSH_STRING_FREE(str);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1266|       |
 1267|      0|    return -1;
 1268|    508|}
ssh_keep_known_algos:
 1324|  2.31k|{
 1325|  2.31k|    if (algo > SSH_LANG_S_C) {
  ------------------
  |  Branch (1325:9): [True: 0, False: 2.31k]
  ------------------
 1326|      0|        return NULL;
 1327|      0|    }
 1328|       |
 1329|  2.31k|    return ssh_find_all_matching(supported_methods[algo], list);
 1330|  2.31k|}
ssh_make_sessionid:
 1459|     95|{
 1460|     95|    ssh_string num = NULL;
 1461|     95|    ssh_buffer server_hash = NULL;
 1462|     95|    ssh_buffer client_hash = NULL;
 1463|     95|    ssh_buffer buf = NULL;
 1464|     95|    ssh_string server_pubkey_blob = NULL;
 1465|     95|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
 1466|     95|    const_bignum client_pubkey, server_pubkey;
 1467|       |#else
 1468|       |    bignum client_pubkey = NULL, server_pubkey = NULL;
 1469|       |#endif /* OPENSSL_VERSION_NUMBER */
 1470|     95|#ifdef WITH_GEX
 1471|     95|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
 1472|     95|    const_bignum modulus, generator;
 1473|       |#else
 1474|       |    bignum modulus = NULL, generator = NULL;
 1475|       |#endif /* OPENSSL_VERSION_NUMBER */
 1476|     95|#endif /* WITH_GEX */
 1477|     95|    int rc = SSH_ERROR;
  ------------------
  |  |  317|     95|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1478|       |
 1479|     95|    buf = ssh_buffer_new();
 1480|     95|    if (buf == NULL) {
  ------------------
  |  Branch (1480:9): [True: 0, False: 95]
  ------------------
 1481|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1482|      0|        return rc;
 1483|      0|    }
 1484|       |
 1485|     95|    rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|     95|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|     95|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|     95|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|     95|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|     95|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|     95|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     95|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1486|     95|                         "ss",
 1487|     95|                         session->clientbanner,
 1488|     95|                         session->serverbanner);
 1489|     95|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     95|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1489:9): [True: 0, False: 95]
  ------------------
 1490|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1491|      0|                      SSH_FATAL,
 1492|      0|                      "Failed to pack client and server banner");
 1493|      0|        goto error;
 1494|      0|    }
 1495|       |
 1496|     95|    if (session->client) {
  ------------------
  |  Branch (1496:9): [True: 95, False: 0]
  ------------------
 1497|     95|        server_hash = session->in_hashbuf;
 1498|     95|        client_hash = session->out_hashbuf;
 1499|     95|    } else {
 1500|      0|        server_hash = session->out_hashbuf;
 1501|      0|        client_hash = session->in_hashbuf;
 1502|      0|    }
 1503|       |
 1504|     95|    rc = ssh_dh_get_next_server_publickey_blob(session, &server_pubkey_blob);
 1505|     95|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     95|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1505:9): [True: 0, False: 95]
  ------------------
 1506|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1507|      0|                      SSH_FATAL,
 1508|      0|                      "Failed to get next server pubkey blob");
 1509|      0|        goto error;
 1510|      0|    }
 1511|       |
 1512|     95|    if (server_pubkey_blob == NULL) {
  ------------------
  |  Branch (1512:9): [True: 0, False: 95]
  ------------------
 1513|      0|        if ((session->server && ssh_kex_is_gss(session->next_crypto)) ||
  ------------------
  |  Branch (1513:14): [True: 0, False: 0]
  |  Branch (1513:33): [True: 0, False: 0]
  ------------------
 1514|      0|            session->opts.gssapi_key_exchange) {
  ------------------
  |  Branch (1514:13): [True: 0, False: 0]
  ------------------
 1515|      0|            server_pubkey_blob = ssh_string_new(0);
 1516|      0|            if (server_pubkey_blob == NULL) {
  ------------------
  |  Branch (1516:17): [True: 0, False: 0]
  ------------------
 1517|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1518|      0|                rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1519|      0|                goto error;
 1520|      0|            }
 1521|      0|        }
 1522|      0|    }
 1523|       |
 1524|     95|    rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|     95|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|     95|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|     95|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|     95|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|     95|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|     95|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     95|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1525|     95|                         "dPdPS",
 1526|     95|                         ssh_buffer_get_len(client_hash),
 1527|     95|                         (size_t)ssh_buffer_get_len(client_hash),
 1528|     95|                         ssh_buffer_get(client_hash),
 1529|     95|                         ssh_buffer_get_len(server_hash),
 1530|     95|                         (size_t)ssh_buffer_get_len(server_hash),
 1531|     95|                         ssh_buffer_get(server_hash),
 1532|     95|                         server_pubkey_blob);
 1533|     95|    SSH_STRING_FREE(server_pubkey_blob);
  ------------------
  |  |  915|     95|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 95, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 95]
  |  |  ------------------
  ------------------
 1534|     95|    if (rc != SSH_OK){
  ------------------
  |  |  316|     95|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1534:9): [True: 0, False: 95]
  ------------------
 1535|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1536|      0|                      SSH_FATAL,
 1537|      0|                      "Failed to pack hashes and pubkey blob");
 1538|      0|        goto error;
 1539|      0|    }
 1540|       |
 1541|     95|    switch(session->next_crypto->kex_type) {
 1542|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1542:5): [True: 0, False: 95]
  ------------------
 1543|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1543:5): [True: 0, False: 95]
  ------------------
 1544|     11|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1544:5): [True: 11, False: 84]
  ------------------
 1545|     11|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1545:5): [True: 0, False: 95]
  ------------------
 1546|     32|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1546:5): [True: 21, False: 74]
  ------------------
 1547|     32|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1547:5): [True: 0, False: 95]
  ------------------
 1548|     42|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1548:5): [True: 10, False: 85]
  ------------------
 1549|     42|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1550|     42|                                     DH_CLIENT_KEYPAIR, NULL, &client_pubkey);
  ------------------
  |  |   30|     42|#define DH_CLIENT_KEYPAIR 0
  ------------------
 1551|     42|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     42|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1551:13): [True: 0, False: 42]
  ------------------
 1552|      0|            goto error;
 1553|      0|        }
 1554|     42|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1555|     42|                                     DH_SERVER_KEYPAIR, NULL, &server_pubkey);
  ------------------
  |  |   31|     42|#define DH_SERVER_KEYPAIR 1
  ------------------
 1556|     42|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     42|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1556:13): [True: 0, False: 42]
  ------------------
 1557|      0|            goto error;
 1558|      0|        }
 1559|     42|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|     42|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|     42|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|     42|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|     42|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|     42|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|     42|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     42|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1560|     42|                             "BB",
 1561|     42|                             client_pubkey,
 1562|     42|                             server_pubkey);
 1563|     42|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     42|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1563:13): [True: 0, False: 42]
  ------------------
 1564|      0|            ssh_set_error(session, SSH_FATAL, "Failed to pack DH pubkeys");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1565|      0|            goto error;
 1566|      0|        }
 1567|       |#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
 1568|       |        bignum_safe_free(client_pubkey);
 1569|       |        bignum_safe_free(server_pubkey);
 1570|       |#endif /* OPENSSL_VERSION_NUMBER */
 1571|     42|        break;
 1572|     42|#ifdef WITH_GEX
 1573|     42|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (1573:5): [True: 0, False: 95]
  ------------------
 1574|      0|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1574:5): [True: 0, False: 95]
  ------------------
 1575|      0|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1576|      0|                                     DH_CLIENT_KEYPAIR, NULL, &client_pubkey);
  ------------------
  |  |   30|      0|#define DH_CLIENT_KEYPAIR 0
  ------------------
 1577|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1577:13): [True: 0, False: 0]
  ------------------
 1578|      0|            goto error;
 1579|      0|        }
 1580|      0|        rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
 1581|      0|                                     DH_SERVER_KEYPAIR, NULL, &server_pubkey);
  ------------------
  |  |   31|      0|#define DH_SERVER_KEYPAIR 1
  ------------------
 1582|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1582:13): [True: 0, False: 0]
  ------------------
 1583|      0|            goto error;
 1584|      0|        }
 1585|      0|        rc = ssh_dh_get_parameters(session->next_crypto->dh_ctx,
 1586|      0|                                   &modulus, &generator);
 1587|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1587:13): [True: 0, False: 0]
  ------------------
 1588|      0|            goto error;
 1589|      0|        }
 1590|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1591|      0|                    "dddBBBB",
 1592|      0|                    session->next_crypto->dh_pmin,
 1593|      0|                    session->next_crypto->dh_pn,
 1594|      0|                    session->next_crypto->dh_pmax,
 1595|      0|                    modulus,
 1596|      0|                    generator,
 1597|      0|                    client_pubkey,
 1598|      0|                    server_pubkey);
 1599|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1599:13): [True: 0, False: 0]
  ------------------
 1600|      0|            ssh_set_error(session, SSH_FATAL, "Failed to pack DH GEX params");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1601|      0|            goto error;
 1602|      0|        }
 1603|       |#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
 1604|       |        bignum_safe_free(modulus);
 1605|       |        bignum_safe_free(generator);
 1606|       |#endif /* OPENSSL_VERSION_NUMBER */
 1607|      0|        break;
 1608|      0|#endif /* WITH_GEX */
 1609|      0|#ifdef HAVE_ECDH
 1610|      0|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (1610:5): [True: 0, False: 95]
  ------------------
 1611|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1611:5): [True: 0, False: 95]
  ------------------
 1612|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1612:5): [True: 0, False: 95]
  ------------------
 1613|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1613:5): [True: 0, False: 95]
  ------------------
 1614|      0|        if (session->next_crypto->ecdh_client_pubkey == NULL ||
  ------------------
  |  Branch (1614:13): [True: 0, False: 0]
  ------------------
 1615|      0|            session->next_crypto->ecdh_server_pubkey == NULL) {
  ------------------
  |  Branch (1615:13): [True: 0, False: 0]
  ------------------
 1616|      0|            SSH_LOG(SSH_LOG_TRACE, "ECDH parameter missing");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1617|      0|            goto error;
 1618|      0|        }
 1619|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1620|      0|                             "SS",
 1621|      0|                             session->next_crypto->ecdh_client_pubkey,
 1622|      0|                             session->next_crypto->ecdh_server_pubkey);
 1623|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1623:13): [True: 0, False: 0]
  ------------------
 1624|      0|            ssh_set_error(session, SSH_FATAL, "Failed to pack ECDH pubkeys");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1625|      0|            goto error;
 1626|      0|        }
 1627|      0|        break;
 1628|      0|#endif /* HAVE_ECDH */
 1629|      0|#ifdef HAVE_CURVE25519
 1630|      9|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1630:5): [True: 9, False: 86]
  ------------------
 1631|     53|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1631:5): [True: 44, False: 51]
  ------------------
 1632|     53|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1632:5): [True: 0, False: 95]
  ------------------
 1633|     53|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|     53|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|     53|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|     53|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|     53|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|     53|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|     53|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     53|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1634|     53|                             "dPdP",
 1635|     53|                             CURVE25519_PUBKEY_SIZE,
 1636|     53|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1637|     53|                             session->next_crypto->curve25519_client_pubkey,
 1638|     53|                             CURVE25519_PUBKEY_SIZE,
 1639|     53|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1640|     53|                             session->next_crypto->curve25519_server_pubkey);
 1641|       |
 1642|     53|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     53|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1642:13): [True: 0, False: 53]
  ------------------
 1643|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1644|      0|                          SSH_FATAL,
 1645|      0|                          "Failed to pack Curve25519 pubkeys");
 1646|      0|            goto error;
 1647|      0|        }
 1648|     53|        break;
 1649|     53|#endif /* HAVE_CURVE25519 */
 1650|     53|#ifdef HAVE_SNTRUP761
 1651|     53|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1651:5): [True: 0, False: 95]
  ------------------
 1652|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1652:5): [True: 0, False: 95]
  ------------------
 1653|      0|        rc = ssh_buffer_pack(buf,
  ------------------
  |  |   50|      0|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1654|      0|                             "dPPdPP",
 1655|      0|                             SNTRUP761_PUBLICKEY_SIZE + CURVE25519_PUBKEY_SIZE,
 1656|      0|                             (size_t)SNTRUP761_PUBLICKEY_SIZE,
 1657|      0|                             session->next_crypto->sntrup761_client_pubkey,
 1658|      0|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1659|      0|                             session->next_crypto->curve25519_client_pubkey,
 1660|      0|                             SNTRUP761_CIPHERTEXT_SIZE + CURVE25519_PUBKEY_SIZE,
 1661|      0|                             (size_t)SNTRUP761_CIPHERTEXT_SIZE,
 1662|      0|                             session->next_crypto->sntrup761_ciphertext,
 1663|      0|                             (size_t)CURVE25519_PUBKEY_SIZE,
 1664|      0|                             session->next_crypto->curve25519_server_pubkey);
 1665|       |
 1666|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1666:13): [True: 0, False: 0]
  ------------------
 1667|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1668|      0|                          SSH_FATAL,
 1669|      0|                          "Failed to pack SNTRU Prime params");
 1670|      0|            goto error;
 1671|      0|        }
 1672|      0|        break;
 1673|      0|#endif /* HAVE_SNTRUP761 */
 1674|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1674:5): [True: 0, False: 95]
  ------------------
 1675|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1675:5): [True: 0, False: 95]
  ------------------
 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)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 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,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1685|      0|                          SSH_FATAL,
 1686|      0|                          "Failed to pack ML-KEM individual components");
 1687|      0|            goto error;
 1688|      0|        }
 1689|      0|        break;
 1690|      0|    default:
  ------------------
  |  Branch (1690:5): [True: 0, False: 95]
  ------------------
 1691|       |        /* Handle unsupported kex types - this should not happen in normal operation */
 1692|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1693|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX algorithm");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1694|      0|        goto error;
 1695|     95|    }
 1696|     95|    switch (session->next_crypto->kex_type) {
 1697|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1697:5): [True: 0, False: 95]
  ------------------
 1698|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1698:5): [True: 0, False: 95]
  ------------------
 1699|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1699:5): [True: 0, False: 95]
  ------------------
 1700|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1700:5): [True: 0, False: 95]
  ------------------
 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)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1705|      0|        break;
 1706|     95|    default:
  ------------------
  |  Branch (1706:5): [True: 95, False: 0]
  ------------------
 1707|     95|        rc = ssh_buffer_pack(buf, "B", session->next_crypto->shared_secret);
  ------------------
  |  |   50|     95|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|     95|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|     95|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|     95|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|     95|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|     95|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     95|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1708|     95|        break;
 1709|     95|    }
 1710|     95|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     95|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1710:9): [True: 0, False: 95]
  ------------------
 1711|      0|        ssh_set_error(session, SSH_FATAL, "Failed to pack shared secret");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1712|      0|        goto error;
 1713|      0|    }
 1714|       |
 1715|       |#ifdef DEBUG_CRYPTO
 1716|       |    ssh_log_hexdump("hash buffer", ssh_buffer_get(buf), ssh_buffer_get_len(buf));
 1717|       |#endif
 1718|       |
 1719|       |    /* Set rc for the following switch statement in case we goto error. */
 1720|     95|    rc = SSH_ERROR;
  ------------------
  |  |  317|     95|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1721|     95|    switch (session->next_crypto->kex_type) {
 1722|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1722:5): [True: 0, False: 95]
  ------------------
 1723|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1723:5): [True: 0, False: 95]
  ------------------
 1724|      0|#ifdef WITH_GEX
 1725|      0|    case SSH_KEX_DH_GEX_SHA1:
  ------------------
  |  Branch (1725:5): [True: 0, False: 95]
  ------------------
 1726|      0|#endif /* WITH_GEX */
 1727|      0|        session->next_crypto->digest_len = SHA_DIGEST_LENGTH;
 1728|      0|        session->next_crypto->digest_type = SSH_KDF_SHA1;
 1729|      0|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1730|      0|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1730:13): [True: 0, False: 0]
  ------------------
 1731|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1732|      0|            goto error;
 1733|      0|        }
 1734|      0|        sha1(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
 1735|      0|                                   session->next_crypto->secret_hash);
 1736|      0|        break;
 1737|     11|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1737:5): [True: 11, False: 84]
  ------------------
 1738|     11|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1738:5): [True: 0, False: 95]
  ------------------
 1739|     11|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (1739:5): [True: 0, False: 95]
  ------------------
 1740|     20|    case SSH_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1740:5): [True: 9, False: 86]
  ------------------
 1741|     64|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1741:5): [True: 44, False: 51]
  ------------------
 1742|     64|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1742:5): [True: 0, False: 95]
  ------------------
 1743|     64|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1743:5): [True: 0, False: 95]
  ------------------
 1744|     64|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1744:5): [True: 0, False: 95]
  ------------------
 1745|     64|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1745:5): [True: 0, False: 95]
  ------------------
 1746|     64|#ifdef WITH_GEX
 1747|     64|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1747:5): [True: 0, False: 95]
  ------------------
 1748|     64|#endif /* WITH_GEX */
 1749|     64|        session->next_crypto->digest_len = SHA256_DIGEST_LENGTH;
 1750|     64|        session->next_crypto->digest_type = SSH_KDF_SHA256;
 1751|     64|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1752|     64|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1752:13): [True: 0, False: 64]
  ------------------
 1753|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1754|      0|            goto error;
 1755|      0|        }
 1756|     64|        sha256(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
 1757|     64|                                     session->next_crypto->secret_hash);
 1758|     64|        break;
 1759|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1759:5): [True: 0, False: 95]
  ------------------
 1760|       |#ifdef HAVE_MLKEM1024
 1761|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
 1762|       |#endif
 1763|      0|        session->next_crypto->digest_len = SHA384_DIGEST_LENGTH;
 1764|      0|        session->next_crypto->digest_type = SSH_KDF_SHA384;
 1765|      0|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1766|      0|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1766:13): [True: 0, False: 0]
  ------------------
 1767|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1768|      0|            goto error;
 1769|      0|        }
 1770|      0|        sha384(ssh_buffer_get(buf), ssh_buffer_get_len(buf),
 1771|      0|                                     session->next_crypto->secret_hash);
 1772|      0|        break;
 1773|     21|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1773:5): [True: 21, False: 74]
  ------------------
 1774|     21|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1774:5): [True: 0, False: 95]
  ------------------
 1775|     31|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1775:5): [True: 10, False: 85]
  ------------------
 1776|     31|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1776:5): [True: 0, False: 95]
  ------------------
 1777|     31|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1777:5): [True: 0, False: 95]
  ------------------
 1778|     31|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1778:5): [True: 0, False: 95]
  ------------------
 1779|     31|        session->next_crypto->digest_len = SHA512_DIGEST_LENGTH;
 1780|     31|        session->next_crypto->digest_type = SSH_KDF_SHA512;
 1781|     31|        session->next_crypto->secret_hash = malloc(session->next_crypto->digest_len);
 1782|     31|        if (session->next_crypto->secret_hash == NULL) {
  ------------------
  |  Branch (1782:13): [True: 0, False: 31]
  ------------------
 1783|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1784|      0|            goto error;
 1785|      0|        }
 1786|     31|        sha512(ssh_buffer_get(buf),
 1787|     31|               ssh_buffer_get_len(buf),
 1788|     31|               session->next_crypto->secret_hash);
 1789|     31|        break;
 1790|      0|    default:
  ------------------
  |  Branch (1790:5): [True: 0, False: 95]
  ------------------
 1791|       |        /* Handle unsupported kex types - this should not happen in normal operation */
 1792|      0|        ssh_set_error(session, SSH_FATAL, "Unsupported KEX algorithm for hash computation");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1793|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1794|      0|        goto error;
 1795|     95|    }
 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|     95|    if (!session->next_crypto->session_id) {
  ------------------
  |  Branch (1801:9): [True: 95, False: 0]
  ------------------
 1802|     95|        session->next_crypto->session_id = malloc(session->next_crypto->digest_len);
 1803|     95|        if (session->next_crypto->session_id == NULL) {
  ------------------
  |  Branch (1803:13): [True: 0, False: 95]
  ------------------
 1804|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1805|      0|            rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1806|      0|            goto error;
 1807|      0|        }
 1808|     95|        memcpy(session->next_crypto->session_id, session->next_crypto->secret_hash,
 1809|     95|                session->next_crypto->digest_len);
 1810|       |	/* Initial length is the same as secret hash */
 1811|     95|	session->next_crypto->session_id_len = session->next_crypto->digest_len;
 1812|     95|    }
 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|     95|    rc = SSH_OK;
  ------------------
  |  |  316|     95|#define SSH_OK 0     /* No error */
  ------------------
 1820|     95|error:
 1821|     95|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|     95|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 95, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 95]
  |  |  ------------------
  ------------------
 1822|     95|    SSH_BUFFER_FREE(client_hash);
  ------------------
  |  |  957|     95|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 95, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 95]
  |  |  ------------------
  ------------------
 1823|     95|    SSH_BUFFER_FREE(server_hash);
  ------------------
  |  |  957|     95|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 95, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 95]
  |  |  ------------------
  ------------------
 1824|       |
 1825|     95|    session->in_hashbuf = NULL;
 1826|     95|    session->out_hashbuf = NULL;
 1827|       |
 1828|     95|    SSH_STRING_FREE(num);
  ------------------
  |  |  915|     95|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 95]
  |  |  |  Branch (915:69): [Folded, False: 95]
  |  |  ------------------
  ------------------
 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|     95|    return rc;
 1835|     95|}
ssh_hashbufout_add_cookie:
 1838|    508|{
 1839|    508|    int rc;
 1840|       |
 1841|    508|    session->out_hashbuf = ssh_buffer_new();
 1842|    508|    if (session->out_hashbuf == NULL) {
  ------------------
  |  Branch (1842:9): [True: 0, False: 508]
  ------------------
 1843|      0|        return -1;
 1844|      0|    }
 1845|       |
 1846|    508|    rc = ssh_buffer_allocate_size(session->out_hashbuf,
 1847|    508|            sizeof(uint8_t) + 16);
 1848|    508|    if (rc < 0) {
  ------------------
  |  Branch (1848:9): [True: 0, False: 508]
  ------------------
 1849|      0|        ssh_buffer_reinit(session->out_hashbuf);
 1850|      0|        return -1;
 1851|      0|    }
 1852|       |
 1853|    508|    if (ssh_buffer_add_u8(session->out_hashbuf, 20) < 0) {
  ------------------
  |  Branch (1853:9): [True: 0, False: 508]
  ------------------
 1854|      0|        ssh_buffer_reinit(session->out_hashbuf);
 1855|      0|        return -1;
 1856|      0|    }
 1857|       |
 1858|    508|    if (session->server) {
  ------------------
  |  Branch (1858:9): [True: 0, False: 508]
  ------------------
 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|    508|    } else {
 1865|    508|        if (ssh_buffer_add_data(session->out_hashbuf,
  ------------------
  |  Branch (1865:13): [True: 0, False: 508]
  ------------------
 1866|    508|                    session->next_crypto->client_kex.cookie, 16) < 0) {
 1867|      0|            ssh_buffer_reinit(session->out_hashbuf);
 1868|      0|            return -1;
 1869|      0|        }
 1870|    508|    }
 1871|       |
 1872|    508|    return 0;
 1873|    508|}
ssh_hashbufin_add_cookie:
 1876|    369|{
 1877|    369|    int rc;
 1878|       |
 1879|    369|    session->in_hashbuf = ssh_buffer_new();
 1880|    369|    if (session->in_hashbuf == NULL) {
  ------------------
  |  Branch (1880:9): [True: 0, False: 369]
  ------------------
 1881|      0|        return -1;
 1882|      0|    }
 1883|       |
 1884|    369|    rc = ssh_buffer_allocate_size(session->in_hashbuf,
 1885|    369|            sizeof(uint8_t) + 20 + 16);
 1886|    369|    if (rc < 0) {
  ------------------
  |  Branch (1886:9): [True: 0, False: 369]
  ------------------
 1887|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1888|      0|        return -1;
 1889|      0|    }
 1890|       |
 1891|    369|    if (ssh_buffer_add_u8(session->in_hashbuf, 20) < 0) {
  ------------------
  |  Branch (1891:9): [True: 0, False: 369]
  ------------------
 1892|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1893|      0|        return -1;
 1894|      0|    }
 1895|    369|    if (ssh_buffer_add_data(session->in_hashbuf,cookie, 16) < 0) {
  ------------------
  |  Branch (1895:9): [True: 0, False: 369]
  ------------------
 1896|      0|        ssh_buffer_reinit(session->in_hashbuf);
 1897|      0|        return -1;
 1898|      0|    }
 1899|       |
 1900|    369|    return 0;
 1901|    369|}
ssh_generate_session_keys:
 1904|     95|{
 1905|     95|    ssh_string k_string = NULL;
 1906|     95|    struct ssh_crypto_struct *crypto = session->next_crypto;
 1907|     95|    unsigned char *key = NULL;
 1908|     95|    unsigned char *IV_cli_to_srv = NULL;
 1909|     95|    unsigned char *IV_srv_to_cli = NULL;
 1910|     95|    unsigned char *enckey_cli_to_srv = NULL;
 1911|     95|    unsigned char *enckey_srv_to_cli = NULL;
 1912|     95|    unsigned char *intkey_cli_to_srv = NULL;
 1913|     95|    unsigned char *intkey_srv_to_cli = NULL;
 1914|     95|    size_t key_len = 0;
 1915|     95|    size_t IV_len = 0;
 1916|     95|    size_t enckey_cli_to_srv_len = 0;
 1917|     95|    size_t enckey_srv_to_cli_len = 0;
 1918|     95|    size_t intkey_cli_to_srv_len = 0;
 1919|     95|    size_t intkey_srv_to_cli_len = 0;
 1920|     95|    int rc = -1;
 1921|       |
 1922|     95|    switch (session->next_crypto->kex_type) {
 1923|      0|    case SSH_KEX_SNTRUP761X25519_SHA512:
  ------------------
  |  Branch (1923:5): [True: 0, False: 95]
  ------------------
 1924|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1924:5): [True: 0, False: 95]
  ------------------
 1925|      0|    case SSH_KEX_MLKEM768X25519_SHA256:
  ------------------
  |  Branch (1925:5): [True: 0, False: 95]
  ------------------
 1926|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1926:5): [True: 0, False: 95]
  ------------------
 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|     95|    default:
  ------------------
  |  Branch (1932:5): [True: 95, False: 0]
  ------------------
 1933|     95|        k_string = ssh_make_bignum_string(crypto->shared_secret);
 1934|     95|        break;
 1935|     95|    }
 1936|     95|    if (k_string == NULL) {
  ------------------
  |  Branch (1936:9): [True: 0, False: 95]
  ------------------
 1937|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1938|      0|        goto error;
 1939|      0|    }
 1940|       |    /* See RFC4251 Section 5 for the definition of mpint which is the
 1941|       |     * encoding we need to use for key in the SSH KDF */
 1942|     95|    key = (unsigned char *)k_string;
 1943|     95|    key_len = ssh_string_len(k_string) + 4;
 1944|       |
 1945|     95|    IV_len = crypto->digest_len;
 1946|     95|    if (session->client) {
  ------------------
  |  Branch (1946:9): [True: 95, False: 0]
  ------------------
 1947|     95|        enckey_cli_to_srv_len = crypto->out_cipher->keysize / 8;
 1948|     95|        enckey_srv_to_cli_len = crypto->in_cipher->keysize / 8;
 1949|     95|        intkey_cli_to_srv_len = hmac_digest_len(crypto->out_hmac);
 1950|     95|        intkey_srv_to_cli_len = hmac_digest_len(crypto->in_hmac);
 1951|     95|    } 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|     95|    IV_cli_to_srv = malloc(IV_len);
 1959|     95|    IV_srv_to_cli = malloc(IV_len);
 1960|     95|    enckey_cli_to_srv = malloc(enckey_cli_to_srv_len);
 1961|     95|    enckey_srv_to_cli = malloc(enckey_srv_to_cli_len);
 1962|     95|    intkey_cli_to_srv = malloc(intkey_cli_to_srv_len);
 1963|     95|    intkey_srv_to_cli = malloc(intkey_srv_to_cli_len);
 1964|     95|    if (IV_cli_to_srv == NULL || IV_srv_to_cli == NULL ||
  ------------------
  |  Branch (1964:9): [True: 0, False: 95]
  |  Branch (1964:34): [True: 0, False: 95]
  ------------------
 1965|     95|        enckey_cli_to_srv == NULL || enckey_srv_to_cli == NULL ||
  ------------------
  |  Branch (1965:9): [True: 0, False: 95]
  |  Branch (1965:38): [True: 0, False: 95]
  ------------------
 1966|     95|        intkey_cli_to_srv == NULL || intkey_srv_to_cli == NULL) {
  ------------------
  |  Branch (1966:9): [True: 0, False: 95]
  |  Branch (1966:38): [True: 0, False: 95]
  ------------------
 1967|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1968|      0|        goto error;
 1969|      0|    }
 1970|       |
 1971|       |    /* IV */
 1972|     95|    rc = ssh_kdf(crypto, key, key_len, 'A', IV_cli_to_srv, IV_len);
 1973|     95|    if (rc < 0) {
  ------------------
  |  Branch (1973:9): [True: 0, False: 95]
  ------------------
 1974|      0|        goto error;
 1975|      0|    }
 1976|     95|    rc = ssh_kdf(crypto, key, key_len, 'B', IV_srv_to_cli, IV_len);
 1977|     95|    if (rc < 0) {
  ------------------
  |  Branch (1977:9): [True: 0, False: 95]
  ------------------
 1978|      0|        goto error;
 1979|      0|    }
 1980|       |    /* Encryption Key */
 1981|     95|    rc = ssh_kdf(crypto, key, key_len, 'C', enckey_cli_to_srv,
 1982|     95|                 enckey_cli_to_srv_len);
 1983|     95|    if (rc < 0) {
  ------------------
  |  Branch (1983:9): [True: 0, False: 95]
  ------------------
 1984|      0|        goto error;
 1985|      0|    }
 1986|     95|    rc = ssh_kdf(crypto, key, key_len, 'D', enckey_srv_to_cli,
 1987|     95|                 enckey_srv_to_cli_len);
 1988|     95|    if (rc < 0) {
  ------------------
  |  Branch (1988:9): [True: 0, False: 95]
  ------------------
 1989|      0|        goto error;
 1990|      0|    }
 1991|       |    /* Integrity Key */
 1992|     95|    rc = ssh_kdf(crypto, key, key_len, 'E', intkey_cli_to_srv,
 1993|     95|                 intkey_cli_to_srv_len);
 1994|     95|    if (rc < 0) {
  ------------------
  |  Branch (1994:9): [True: 0, False: 95]
  ------------------
 1995|      0|        goto error;
 1996|      0|    }
 1997|     95|    rc = ssh_kdf(crypto, key, key_len, 'F', intkey_srv_to_cli,
 1998|     95|                 intkey_srv_to_cli_len);
 1999|     95|    if (rc < 0) {
  ------------------
  |  Branch (1999:9): [True: 0, False: 95]
  ------------------
 2000|      0|        goto error;
 2001|      0|    }
 2002|       |
 2003|     95|    if (session->client) {
  ------------------
  |  Branch (2003:9): [True: 95, False: 0]
  ------------------
 2004|     95|        crypto->encryptIV = IV_cli_to_srv;
 2005|     95|        crypto->decryptIV = IV_srv_to_cli;
 2006|     95|        crypto->encryptkey = enckey_cli_to_srv;
 2007|     95|        crypto->decryptkey = enckey_srv_to_cli;
 2008|     95|        crypto->encryptMAC = intkey_cli_to_srv;
 2009|     95|        crypto->decryptMAC = intkey_srv_to_cli;
 2010|     95|    } 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|     95|    rc = 0;
 2033|     95|error:
 2034|     95|    ssh_string_burn(k_string);
 2035|     95|    SSH_STRING_FREE(k_string);
  ------------------
  |  |  915|     95|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 95, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 95]
  |  |  ------------------
  ------------------
 2036|     95|    if (rc != 0) {
  ------------------
  |  Branch (2036:9): [True: 0, False: 95]
  ------------------
 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|     95|    return rc;
 2046|     95|}
ssh_kex_is_gss:
 2055|      1|{
 2056|      1|    switch (crypto->kex_type) {
 2057|      0|    case SSH_GSS_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (2057:5): [True: 0, False: 1]
  ------------------
 2058|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (2058:5): [True: 0, False: 1]
  ------------------
 2059|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (2059:5): [True: 0, False: 1]
  ------------------
 2060|      0|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (2060:5): [True: 0, False: 1]
  ------------------
 2061|      0|        return true;
 2062|      1|    default:
  ------------------
  |  Branch (2062:5): [True: 1, False: 0]
  ------------------
 2063|       |        return false;
 2064|      1|    }
 2065|      1|}
kex.c:cmp_first_kex_algo:
  361|    199|                              const char *server_str) {
  362|    199|    size_t client_kex_len;
  363|    199|    size_t server_kex_len;
  364|       |
  365|    199|    const char *colon = NULL;
  366|       |
  367|    199|    int is_wrong = 1;
  368|       |
  369|    199|    if (client_str == NULL || server_str == NULL) {
  ------------------
  |  Branch (369:9): [True: 0, False: 199]
  |  Branch (369:31): [True: 0, False: 199]
  ------------------
  370|      0|        return is_wrong;
  371|      0|    }
  372|       |
  373|    199|    colon = strchr(client_str, ',');
  374|    199|    if (colon == NULL) {
  ------------------
  |  Branch (374:9): [True: 0, False: 199]
  ------------------
  375|      0|        client_kex_len = strlen(client_str);
  376|    199|    } else {
  377|    199|        client_kex_len = colon - client_str;
  378|    199|    }
  379|       |
  380|    199|    colon = strchr(server_str, ',');
  381|    199|    if (colon == NULL) {
  ------------------
  |  Branch (381:9): [True: 7, False: 192]
  ------------------
  382|      7|        server_kex_len = strlen(server_str);
  383|    192|    } else {
  384|    192|        server_kex_len = colon - server_str;
  385|    192|    }
  386|       |
  387|    199|    if (client_kex_len != server_kex_len) {
  ------------------
  |  Branch (387:9): [True: 187, False: 12]
  ------------------
  388|    187|        return is_wrong;
  389|    187|    }
  390|       |
  391|     12|    is_wrong = (strncmp(client_str, server_str, client_kex_len) != 0);
  392|       |
  393|     12|    return is_wrong;
  394|    199|}
kex.c:ssh_find_aead_hmac:
  952|    590|{
  953|    590|    if (cipher == NULL) {
  ------------------
  |  Branch (953:9): [True: 0, False: 590]
  ------------------
  954|      0|        return NULL;
  955|    590|    } else if (strcmp(cipher, "chacha20-poly1305@openssh.com") == 0) {
  ------------------
  |  Branch (955:16): [True: 0, False: 590]
  ------------------
  956|      0|        return "aead-poly1305";
  957|    590|    } else if (strcmp(cipher, "aes256-gcm@openssh.com") == 0) {
  ------------------
  |  Branch (957:16): [True: 0, False: 590]
  ------------------
  958|      0|        return "aead-gcm";
  959|    590|    } else if (strcmp(cipher, "aes128-gcm@openssh.com") == 0) {
  ------------------
  |  Branch (959:16): [True: 0, False: 590]
  ------------------
  960|      0|        return "aead-gcm";
  961|      0|    }
  962|    590|    return NULL;
  963|    590|}
kex.c:kex_select_kex_type:
  967|    295|{
  968|    295|    if (strcmp(kex, "diffie-hellman-group1-sha1") == 0) {
  ------------------
  |  Branch (968:9): [True: 0, False: 295]
  ------------------
  969|      0|        return SSH_KEX_DH_GROUP1_SHA1;
  970|    295|    } else if (strncmp(kex, "gss-group14-sha256-", 19) == 0) {
  ------------------
  |  Branch (970:16): [True: 0, False: 295]
  ------------------
  971|      0|        return SSH_GSS_KEX_DH_GROUP14_SHA256;
  972|    295|    } else if (strncmp(kex, "gss-group16-sha512-", 19) == 0) {
  ------------------
  |  Branch (972:16): [True: 0, False: 295]
  ------------------
  973|      0|        return SSH_GSS_KEX_DH_GROUP16_SHA512;
  974|    295|    } else if (strncmp(kex, "gss-nistp256-sha256-", 20) == 0) {
  ------------------
  |  Branch (974:16): [True: 0, False: 295]
  ------------------
  975|      0|        return SSH_GSS_KEX_ECDH_NISTP256_SHA256;
  976|    295|    } else if (strncmp(kex, "gss-curve25519-sha256-", 22) == 0) {
  ------------------
  |  Branch (976:16): [True: 0, False: 295]
  ------------------
  977|      0|        return SSH_GSS_KEX_CURVE25519_SHA256;
  978|    295|    } else if (strcmp(kex, "diffie-hellman-group14-sha1") == 0) {
  ------------------
  |  Branch (978:16): [True: 0, False: 295]
  ------------------
  979|      0|        return SSH_KEX_DH_GROUP14_SHA1;
  980|    295|    } else if (strcmp(kex, "diffie-hellman-group14-sha256") == 0) {
  ------------------
  |  Branch (980:16): [True: 17, False: 278]
  ------------------
  981|     17|        return SSH_KEX_DH_GROUP14_SHA256;
  982|    278|    } else if (strcmp(kex, "diffie-hellman-group16-sha512") == 0) {
  ------------------
  |  Branch (982:16): [True: 28, False: 250]
  ------------------
  983|     28|        return SSH_KEX_DH_GROUP16_SHA512;
  984|    250|    } else if (strcmp(kex, "diffie-hellman-group18-sha512") == 0) {
  ------------------
  |  Branch (984:16): [True: 12, False: 238]
  ------------------
  985|     12|        return SSH_KEX_DH_GROUP18_SHA512;
  986|     12|#ifdef WITH_GEX
  987|    238|    } else if (strcmp(kex, "diffie-hellman-group-exchange-sha1") == 0) {
  ------------------
  |  Branch (987:16): [True: 0, False: 238]
  ------------------
  988|      0|        return SSH_KEX_DH_GEX_SHA1;
  989|    238|    } else if (strcmp(kex, "diffie-hellman-group-exchange-sha256") == 0) {
  ------------------
  |  Branch (989:16): [True: 6, False: 232]
  ------------------
  990|      6|        return SSH_KEX_DH_GEX_SHA256;
  991|      6|#endif /* WITH_GEX */
  992|    232|    } else if (strcmp(kex, "ecdh-sha2-nistp256") == 0) {
  ------------------
  |  Branch (992:16): [True: 6, False: 226]
  ------------------
  993|      6|        return SSH_KEX_ECDH_SHA2_NISTP256;
  994|    226|    } else if (strcmp(kex, "ecdh-sha2-nistp384") == 0) {
  ------------------
  |  Branch (994:16): [True: 2, False: 224]
  ------------------
  995|      2|        return SSH_KEX_ECDH_SHA2_NISTP384;
  996|    224|    } else if (strcmp(kex, "ecdh-sha2-nistp521") == 0) {
  ------------------
  |  Branch (996:16): [True: 3, False: 221]
  ------------------
  997|      3|        return SSH_KEX_ECDH_SHA2_NISTP521;
  998|    221|    } else if (strcmp(kex, "curve25519-sha256@libssh.org") == 0) {
  ------------------
  |  Branch (998:16): [True: 63, False: 158]
  ------------------
  999|     63|        return SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG;
 1000|    158|    } else if (strcmp(kex, "curve25519-sha256") == 0) {
  ------------------
  |  Branch (1000:16): [True: 10, False: 148]
  ------------------
 1001|     10|        return SSH_KEX_CURVE25519_SHA256;
 1002|    148|    } else if (strcmp(kex, "sntrup761x25519-sha512@openssh.com") == 0) {
  ------------------
  |  Branch (1002:16): [True: 1, False: 147]
  ------------------
 1003|      1|        return SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM;
 1004|    147|    } else if (strcmp(kex, "sntrup761x25519-sha512") == 0) {
  ------------------
  |  Branch (1004:16): [True: 26, False: 121]
  ------------------
 1005|     26|        return SSH_KEX_SNTRUP761X25519_SHA512;
 1006|    121|    } else if (strcmp(kex, "mlkem768x25519-sha256") == 0) {
  ------------------
  |  Branch (1006:16): [True: 4, False: 117]
  ------------------
 1007|      4|        return SSH_KEX_MLKEM768X25519_SHA256;
 1008|    117|    } else if (strcmp(kex, "mlkem768nistp256-sha256") == 0) {
  ------------------
  |  Branch (1008:16): [True: 117, False: 0]
  ------------------
 1009|    117|        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|    117|    }
 1015|       |    /* should not happen. We should be getting only valid names at this stage */
 1016|      0|    return 0;
 1017|    295|}
kex.c:revert_kex_callbacks:
 1026|    173|{
 1027|    173|    switch (session->next_crypto->kex_type) {
  ------------------
  |  Branch (1027:13): [True: 0, False: 173]
  ------------------
 1028|      0|    case SSH_KEX_DH_GROUP1_SHA1:
  ------------------
  |  Branch (1028:5): [True: 0, False: 173]
  ------------------
 1029|      0|    case SSH_KEX_DH_GROUP14_SHA1:
  ------------------
  |  Branch (1029:5): [True: 0, False: 173]
  ------------------
 1030|      0|    case SSH_KEX_DH_GROUP14_SHA256:
  ------------------
  |  Branch (1030:5): [True: 0, False: 173]
  ------------------
 1031|      0|    case SSH_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1031:5): [True: 0, False: 173]
  ------------------
 1032|      0|    case SSH_KEX_DH_GROUP18_SHA512:
  ------------------
  |  Branch (1032:5): [True: 0, False: 173]
  ------------------
 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: 173]
  ------------------
 1036|      0|    case SSH_GSS_KEX_DH_GROUP16_SHA512:
  ------------------
  |  Branch (1036:5): [True: 0, False: 173]
  ------------------
 1037|      0|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (1037:5): [True: 0, False: 173]
  ------------------
 1038|      0|    case SSH_GSS_KEX_CURVE25519_SHA256:
  ------------------
  |  Branch (1038:5): [True: 0, False: 173]
  ------------------
 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: 173]
  ------------------
 1045|      0|    case SSH_KEX_DH_GEX_SHA256:
  ------------------
  |  Branch (1045:5): [True: 0, False: 173]
  ------------------
 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: 173]
  ------------------
 1051|      0|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (1051:5): [True: 0, False: 173]
  ------------------
 1052|      0|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (1052:5): [True: 0, False: 173]
  ------------------
 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: 173]
  ------------------
 1058|      0|    case SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG:
  ------------------
  |  Branch (1058:5): [True: 0, False: 173]
  ------------------
 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: 173]
  ------------------
 1064|      0|    case SSH_KEX_SNTRUP761X25519_SHA512_OPENSSH_COM:
  ------------------
  |  Branch (1064:5): [True: 0, False: 173]
  ------------------
 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: 173]
  ------------------
 1069|      0|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (1069:5): [True: 0, False: 173]
  ------------------
 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|    173|    }
 1076|    173|}

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

ssh_kdf:
  337|    570|{
  338|    570|    return sshkdf_derive_key(crypto, key, key_len,
  339|    570|                             key_type, output, requested_len);
  340|    570|}
ssh_get_ciphertab:
 1382|    285|{
 1383|    285|    return ssh_ciphertab;
 1384|    285|}
ssh_crypto_init:
 1391|      2|{
 1392|       |#ifndef HAVE_OPENSSL_EVP_CHACHA20
 1393|       |    size_t i;
 1394|       |#endif
 1395|       |
 1396|      2|    if (libcrypto_initialized) {
  ------------------
  |  Branch (1396:9): [True: 0, False: 2]
  ------------------
 1397|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1398|      0|    }
 1399|      2|    if (OpenSSL_version_num() != OPENSSL_VERSION_NUMBER) {
  ------------------
  |  Branch (1399:9): [True: 0, False: 2]
  ------------------
 1400|      0|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1401|      0|                "libssh compiled with %s "
 1402|      0|                "headers, currently running with %s.",
 1403|      0|                OPENSSL_VERSION_TEXT,
 1404|      0|                OpenSSL_version(OpenSSL_version_num()));
 1405|      0|    }
 1406|       |#ifdef CAN_DISABLE_AESNI
 1407|       |    /*
 1408|       |     * disable AES-NI when running within Valgrind, because they generate
 1409|       |     * too many "uninitialized memory access" false positives
 1410|       |     */
 1411|       |    if (RUNNING_ON_VALGRIND) {
 1412|       |        SSH_LOG(SSH_LOG_INFO, "Running within Valgrind, disabling AES-NI");
 1413|       |        /* Bit #57 denotes AES-NI instruction set extension */
 1414|       |        OPENSSL_ia32cap &= ~(1LL << 57);
 1415|       |    }
 1416|       |#endif /* CAN_DISABLE_AESNI */
 1417|       |
 1418|       |#ifndef HAVE_OPENSSL_EVP_CHACHA20
 1419|       |    for (i = 0; ssh_ciphertab[i].name != NULL; i++) {
 1420|       |        int cmp;
 1421|       |
 1422|       |        cmp = strcmp(ssh_ciphertab[i].name, "chacha20-poly1305@openssh.com");
 1423|       |        if (cmp == 0) {
 1424|       |            memcpy(&ssh_ciphertab[i],
 1425|       |                   ssh_get_chacha20poly1305_cipher(),
 1426|       |                   sizeof(struct ssh_cipher_struct));
 1427|       |            break;
 1428|       |        }
 1429|       |    }
 1430|       |#endif /* HAVE_OPENSSL_EVP_CHACHA20 */
 1431|       |
 1432|      2|    libcrypto_initialized = 1;
 1433|       |
 1434|      2|    return SSH_OK;
  ------------------
  |  |  316|      2|#define SSH_OK 0     /* No error */
  ------------------
 1435|      2|}
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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1648|      0|        return NULL;
 1649|      0|    }
 1650|       |
 1651|    128|    return s;
 1652|    128|}
libcrypto.c:none_crypt:
 1217|  5.10k|{
 1218|  5.10k|    memcpy(out, in, len);
 1219|  5.10k|}

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

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

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

ssh_is_ipaddr_v4:
  430|  2.31k|{
  431|  2.31k|    int rc = -1;
  432|  2.31k|    struct in_addr dest;
  433|       |
  434|  2.31k|    rc = inet_pton(AF_INET, str, &dest);
  435|  2.31k|    if (rc > 0) {
  ------------------
  |  Branch (435:9): [True: 2.31k, False: 0]
  ------------------
  436|  2.31k|        return 1;
  437|  2.31k|    }
  438|       |
  439|      0|    return 0;
  440|  2.31k|}
ssh_is_ipaddr:
  450|  2.31k|{
  451|  2.31k|    int rc = -1;
  452|  2.31k|    char *s = strdup(str);
  453|       |
  454|  2.31k|    if (s == NULL) {
  ------------------
  |  Branch (454:9): [True: 0, False: 2.31k]
  ------------------
  455|      0|        return -1;
  456|      0|    }
  457|  2.31k|    if (strchr(s, ':')) {
  ------------------
  |  Branch (457:9): [True: 0, False: 2.31k]
  ------------------
  458|      0|        struct in6_addr dest6;
  459|      0|        char *network_interface = strchr(s, '%');
  460|       |
  461|       |        /* link-local (IP:v6:addr%ifname). */
  462|      0|        if (network_interface != NULL) {
  ------------------
  |  Branch (462:13): [True: 0, False: 0]
  ------------------
  463|      0|            rc = if_nametoindex(network_interface + 1);
  464|      0|            if (rc == 0) {
  ------------------
  |  Branch (464:17): [True: 0, False: 0]
  ------------------
  465|      0|                free(s);
  466|      0|                return 0;
  467|      0|            }
  468|      0|            *network_interface = '\0';
  469|      0|        }
  470|      0|        rc = inet_pton(AF_INET6, s, &dest6);
  471|      0|        if (rc > 0) {
  ------------------
  |  Branch (471:13): [True: 0, False: 0]
  ------------------
  472|      0|            free(s);
  473|      0|            return 1;
  474|      0|        }
  475|      0|    }
  476|       |
  477|  2.31k|    free(s);
  478|  2.31k|    return ssh_is_ipaddr_v4(str);
  479|  2.31k|}
ssh_get_user_home_dir:
  495|  2.89k|{
  496|  2.89k|    char *szPath = NULL;
  497|       |
  498|       |    /* If used previously, reuse cached value */
  499|  2.89k|    if (session != NULL && session->opts.homedir != NULL) {
  ------------------
  |  Branch (499:9): [True: 2.31k, False: 579]
  |  Branch (499:28): [True: 1.73k, False: 579]
  ------------------
  500|  1.73k|        return strdup(session->opts.homedir);
  501|  1.73k|    }
  502|       |
  503|  1.15k|    szPath = ssh_get_user_home_dir_internal();
  504|  1.15k|    if (szPath == NULL) {
  ------------------
  |  Branch (504:9): [True: 0, False: 1.15k]
  ------------------
  505|      0|        return NULL;
  506|      0|    }
  507|       |
  508|  1.15k|    if (session != NULL) {
  ------------------
  |  Branch (508:9): [True: 579, False: 579]
  ------------------
  509|       |        /* cache it:
  510|       |         * failure is not fatal -- at worst we will just not cache it */
  511|    579|        session->opts.homedir = strdup(szPath);
  512|    579|    }
  513|       |
  514|  1.15k|    return szPath;
  515|  1.15k|}
ssh_lowercase:
  526|    508|{
  527|    508|    char *new = NULL, *p = NULL;
  528|       |
  529|    508|    if (str == NULL) {
  ------------------
  |  Branch (529:9): [True: 0, False: 508]
  ------------------
  530|      0|        return NULL;
  531|      0|    }
  532|       |
  533|    508|    new = strdup(str);
  534|    508|    if (new == NULL) {
  ------------------
  |  Branch (534:9): [True: 0, False: 508]
  ------------------
  535|      0|        return NULL;
  536|      0|    }
  537|       |
  538|  5.08k|    for (p = new; *p; p++) {
  ------------------
  |  Branch (538:19): [True: 4.57k, False: 508]
  ------------------
  539|  4.57k|        *p = tolower(*p);
  ------------------
  |  Branch (539:14): [True: 0, False: 0]
  |  Branch (539:14): [True: 0, False: 0]
  |  Branch (539:14): [Folded, False: 4.57k]
  ------------------
  540|  4.57k|    }
  541|       |
  542|    508|    return new;
  543|    508|}
ssh_list_new:
  865|  5.72k|{
  866|  5.72k|    struct ssh_list *ret = malloc(sizeof(struct ssh_list));
  867|  5.72k|    if (ret == NULL) {
  ------------------
  |  Branch (867:9): [True: 1, False: 5.72k]
  ------------------
  868|      1|        return NULL;
  869|      1|    }
  870|  5.72k|    ret->root = ret->end = NULL;
  871|  5.72k|    return ret;
  872|  5.72k|}
ssh_list_free:
  882|  6.90k|{
  883|  6.90k|    struct ssh_iterator *ptr = NULL, *next = NULL;
  884|  6.90k|    if (!list)
  ------------------
  |  Branch (884:9): [True: 1.18k, False: 5.72k]
  ------------------
  885|  1.18k|        return;
  886|  5.72k|    ptr = list->root;
  887|  6.29k|    while (ptr) {
  ------------------
  |  Branch (887:12): [True: 573, False: 5.72k]
  ------------------
  888|    573|        next = ptr->next;
  889|    573|        SAFE_FREE(ptr);
  ------------------
  |  |  373|    573|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 573, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 573]
  |  |  ------------------
  ------------------
  890|    573|        ptr = next;
  891|    573|    }
  892|       |    SAFE_FREE(list);
  ------------------
  |  |  373|  5.72k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 5.72k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 5.72k]
  |  |  ------------------
  ------------------
  893|  5.72k|}
ssh_list_get_iterator:
  903|  38.1k|{
  904|  38.1k|    if (!list)
  ------------------
  |  Branch (904:9): [True: 1.76k, False: 36.3k]
  ------------------
  905|  1.76k|        return NULL;
  906|  36.3k|    return list->root;
  907|  38.1k|}
ssh_list_find:
  918|    230|{
  919|    230|    struct ssh_iterator *it = NULL;
  920|       |
  921|    460|    for (it = ssh_list_get_iterator(list); it != NULL ; it = it->next)
  ------------------
  |  Branch (921:44): [True: 460, False: 0]
  ------------------
  922|    460|        if (it->data == value)
  ------------------
  |  Branch (922:13): [True: 230, False: 230]
  ------------------
  923|    230|            return it;
  924|      0|    return NULL;
  925|    230|}
ssh_list_append:
  969|  4.27k|{
  970|  4.27k|  struct ssh_iterator *iterator = NULL;
  971|       |
  972|  4.27k|  if (list == NULL) {
  ------------------
  |  Branch (972:7): [True: 0, False: 4.27k]
  ------------------
  973|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  974|      0|  }
  975|       |
  976|  4.27k|  iterator = ssh_iterator_new(data);
  977|  4.27k|  if (iterator == NULL) {
  ------------------
  |  Branch (977:7): [True: 0, False: 4.27k]
  ------------------
  978|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  979|      0|  }
  980|       |
  981|  4.27k|  if(!list->end){
  ------------------
  |  Branch (981:6): [True: 1.66k, False: 2.61k]
  ------------------
  982|       |    /* list is empty */
  983|  1.66k|    list->root=list->end=iterator;
  984|  2.61k|  } else {
  985|       |    /* put it on end of list */
  986|  2.61k|    list->end->next=iterator;
  987|  2.61k|    list->end=iterator;
  988|  2.61k|  }
  989|  4.27k|  return SSH_OK;
  ------------------
  |  |  316|  4.27k|#define SSH_OK 0     /* No error */
  ------------------
  990|  4.27k|}
ssh_list_remove:
 1032|    230|{
 1033|    230|    struct ssh_iterator *ptr = NULL, *prev = NULL;
 1034|       |
 1035|    230|    if (list == NULL) {
  ------------------
  |  Branch (1035:9): [True: 0, False: 230]
  ------------------
 1036|      0|        return;
 1037|      0|    }
 1038|       |
 1039|    230|    prev = NULL;
 1040|    230|    ptr = list->root;
 1041|    460|    while (ptr && ptr != iterator) {
  ------------------
  |  Branch (1041:12): [True: 460, False: 0]
  |  Branch (1041:19): [True: 230, False: 230]
  ------------------
 1042|    230|        prev = ptr;
 1043|    230|        ptr = ptr->next;
 1044|    230|    }
 1045|    230|    if (!ptr) {
  ------------------
  |  Branch (1045:9): [True: 0, False: 230]
  ------------------
 1046|       |        /* we did not find the element */
 1047|      0|        return;
 1048|      0|    }
 1049|       |    /* unlink it */
 1050|    230|    if (prev)
  ------------------
  |  Branch (1050:9): [True: 230, False: 0]
  ------------------
 1051|    230|        prev->next = ptr->next;
 1052|       |    /* if iterator was the head */
 1053|    230|    if (list->root == iterator)
  ------------------
  |  Branch (1053:9): [True: 0, False: 230]
  ------------------
 1054|      0|        list->root = iterator->next;
 1055|       |    /* if iterator was the tail */
 1056|    230|    if (list->end == iterator)
  ------------------
  |  Branch (1056:9): [True: 230, False: 0]
  ------------------
 1057|    230|        list->end = prev;
 1058|       |    SAFE_FREE(iterator);
  ------------------
  |  |  373|    230|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 230, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 230]
  |  |  ------------------
  ------------------
 1059|    230|}
_ssh_list_pop_head:
 1073|  9.87k|{
 1074|  9.87k|  struct ssh_iterator *iterator = NULL;
 1075|  9.87k|  const void *data = NULL;
 1076|       |
 1077|  9.87k|  if (list == NULL) {
  ------------------
  |  Branch (1077:7): [True: 609, False: 9.26k]
  ------------------
 1078|    609|      return NULL;
 1079|    609|  }
 1080|       |
 1081|  9.26k|  iterator = list->root;
 1082|  9.26k|  if (iterator == NULL) {
  ------------------
  |  Branch (1082:7): [True: 5.79k, False: 3.47k]
  ------------------
 1083|  5.79k|      return NULL;
 1084|  5.79k|  }
 1085|  3.47k|  data=iterator->data;
 1086|  3.47k|  list->root=iterator->next;
 1087|  3.47k|  if(list->end==iterator)
  ------------------
  |  Branch (1087:6): [True: 1.15k, False: 2.31k]
  ------------------
 1088|  1.15k|    list->end=NULL;
 1089|       |  SAFE_FREE(iterator);
  ------------------
  |  |  373|  3.47k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 3.47k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 3.47k]
  |  |  ------------------
  ------------------
 1090|  3.47k|  return data;
 1091|  9.26k|}
ssh_path_expand_tilde:
 1309|  2.89k|{
 1310|  2.89k|    char *h = NULL, *r = NULL;
 1311|  2.89k|    const char *p = NULL;
 1312|  2.89k|    size_t ld;
 1313|  2.89k|    size_t lh = 0;
 1314|       |
 1315|  2.89k|    if (d[0] != '~') {
  ------------------
  |  Branch (1315:9): [True: 2.31k, False: 579]
  ------------------
 1316|  2.31k|        return strdup(d);
 1317|  2.31k|    }
 1318|    579|    d++;
 1319|       |
 1320|       |    /* handle ~user/path */
 1321|    579|    p = strchr(d, '/');
 1322|    579|    if (p != NULL && p > d) {
  ------------------
  |  Branch (1322:9): [True: 579, False: 0]
  |  Branch (1322:22): [True: 0, False: 579]
  ------------------
 1323|       |#ifdef _WIN32
 1324|       |        return strdup(d);
 1325|       |#else
 1326|      0|        struct passwd *pw = NULL;
 1327|      0|        size_t s = p - d;
 1328|      0|        char u[128];
 1329|       |
 1330|      0|        if (s >= sizeof(u)) {
  ------------------
  |  Branch (1330:13): [True: 0, False: 0]
  ------------------
 1331|      0|            return NULL;
 1332|      0|        }
 1333|      0|        memcpy(u, d, s);
 1334|      0|        u[s] = '\0';
 1335|      0|        pw = getpwnam(u);
 1336|      0|        if (pw == NULL) {
  ------------------
  |  Branch (1336:13): [True: 0, False: 0]
  ------------------
 1337|      0|            return NULL;
 1338|      0|        }
 1339|      0|        ld = strlen(p);
 1340|      0|        h = strdup(pw->pw_dir);
 1341|      0|#endif
 1342|    579|    } else {
 1343|    579|        ld = strlen(d);
 1344|    579|        p = (char *) d;
 1345|    579|        h = ssh_get_user_home_dir(NULL);
 1346|    579|    }
 1347|    579|    if (h == NULL) {
  ------------------
  |  Branch (1347:9): [True: 0, False: 579]
  ------------------
 1348|      0|        return NULL;
 1349|      0|    }
 1350|    579|    lh = strlen(h);
 1351|       |
 1352|    579|    r = malloc(ld + lh + 1);
 1353|    579|    if (r == NULL) {
  ------------------
  |  Branch (1353:9): [True: 0, False: 579]
  ------------------
 1354|      0|        SAFE_FREE(h);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1355|      0|        return NULL;
 1356|      0|    }
 1357|       |
 1358|    579|    if (lh > 0) {
  ------------------
  |  Branch (1358:9): [True: 579, False: 0]
  ------------------
 1359|    579|        memcpy(r, h, lh);
 1360|    579|    }
 1361|    579|    SAFE_FREE(h);
  ------------------
  |  |  373|    579|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 579, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 579]
  |  |  ------------------
  ------------------
 1362|    579|    memcpy(r + lh, p, ld + 1);
 1363|       |
 1364|    579|    return r;
 1365|    579|}
ssh_path_expand_escape:
 1699|  2.31k|{
 1700|       |    return ssh_path_expand_internal(session, s, false);
 1701|  2.31k|}
ssh_analyze_banner:
 1734|    513|{
 1735|    513|    const char *banner = NULL;
 1736|    513|    const char *openssh = NULL;
 1737|    513|    const char *ios = NULL;
 1738|       |
 1739|    513|    if (server) {
  ------------------
  |  Branch (1739:9): [True: 0, False: 513]
  ------------------
 1740|      0|        banner = session->clientbanner;
 1741|    513|    } else {
 1742|    513|        banner = session->serverbanner;
 1743|    513|    }
 1744|       |
 1745|    513|    if (banner == NULL) {
  ------------------
  |  Branch (1745:9): [True: 0, False: 513]
  ------------------
 1746|      0|        ssh_set_error(session, SSH_FATAL, "Invalid banner");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1747|      0|        return -1;
 1748|      0|    }
 1749|       |
 1750|       |    /*
 1751|       |     * Typical banners e.g. are:
 1752|       |     *
 1753|       |     * SSH-1.5-openSSH_5.4
 1754|       |     * SSH-1.99-openSSH_3.0
 1755|       |     *
 1756|       |     * SSH-2.0-something
 1757|       |     * 012345678901234567890
 1758|       |     */
 1759|    513|    if (strlen(banner) < 6 ||
  ------------------
  |  Branch (1759:9): [True: 1, False: 512]
  ------------------
 1760|    512|        strncmp(banner, "SSH-", 4) != 0) {
  ------------------
  |  Branch (1760:9): [True: 0, False: 512]
  ------------------
 1761|      1|          ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1762|      1|          return -1;
 1763|      1|    }
 1764|       |
 1765|    512|    SSH_LOG(SSH_LOG_DEBUG, "Analyzing banner: %s", banner);
  ------------------
  |  |  281|    512|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1766|       |
 1767|    512|    switch (banner[4]) {
 1768|    476|        case '2':
  ------------------
  |  Branch (1768:9): [True: 476, False: 36]
  ------------------
 1769|    476|            break;
 1770|     35|        case '1':
  ------------------
  |  Branch (1770:9): [True: 35, False: 477]
  ------------------
 1771|     35|            if (strlen(banner) > 6) {
  ------------------
  |  Branch (1771:17): [True: 35, False: 0]
  ------------------
 1772|     35|                if (banner[6] == '9') {
  ------------------
  |  Branch (1772:21): [True: 32, False: 3]
  ------------------
 1773|     32|                    break;
 1774|     32|                }
 1775|     35|            }
 1776|      3|            FALL_THROUGH;
  ------------------
  |  |  494|      3|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1777|      4|        default:
  ------------------
  |  Branch (1777:9): [True: 1, False: 511]
  ------------------
 1778|      4|            ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
  ------------------
  |  |  311|      4|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1779|      4|            return -1;
 1780|    512|    }
 1781|       |
 1782|       |    /* Make a best-effort to extract OpenSSH version numbers. */
 1783|    508|    openssh = strstr(banner, "OpenSSH");
 1784|    508|    if (openssh != NULL) {
  ------------------
  |  Branch (1784:9): [True: 77, False: 431]
  ------------------
 1785|     77|        char *tmp = NULL;
 1786|     77|        unsigned long int major = 0UL;
 1787|     77|        unsigned long int minor = 0UL;
 1788|     77|        int off = 0;
 1789|       |
 1790|       |        /*
 1791|       |         * The banner is typical:
 1792|       |         * OpenSSH_5.4
 1793|       |         * 012345678901234567890
 1794|       |         */
 1795|     77|        if (strlen(openssh) > 9) {
  ------------------
  |  Branch (1795:13): [True: 67, False: 10]
  ------------------
 1796|     67|            errno = 0;
 1797|     67|            major = strtoul(openssh + 8, &tmp, 10);
 1798|     67|            if ((tmp == (openssh + 8)) ||
  ------------------
  |  Branch (1798:17): [True: 4, False: 63]
  ------------------
 1799|     63|                ((errno == ERANGE) && (major == ULONG_MAX)) ||
  ------------------
  |  Branch (1799:18): [True: 1, False: 62]
  |  Branch (1799:39): [True: 1, False: 0]
  ------------------
 1800|     62|                ((errno != 0) && (major == 0)) ||
  ------------------
  |  Branch (1800:18): [True: 0, False: 62]
  |  Branch (1800:34): [True: 0, False: 0]
  ------------------
 1801|     62|                ((major < 1) || (major > 100))) {
  ------------------
  |  Branch (1801:18): [True: 3, False: 59]
  |  Branch (1801:33): [True: 36, False: 23]
  ------------------
 1802|       |                /* invalid major */
 1803|     44|                errno = 0;
 1804|     44|                goto done;
 1805|     44|            }
 1806|       |
 1807|     67|            errno = 0;
 1808|     23|            off = major >= 10 ? 11 : 10;
  ------------------
  |  Branch (1808:19): [True: 7, False: 16]
  ------------------
 1809|     23|            minor = strtoul(openssh + off, &tmp, 10);
 1810|     23|            if ((tmp == (openssh + off)) ||
  ------------------
  |  Branch (1810:17): [True: 3, False: 20]
  ------------------
 1811|     20|                ((errno == ERANGE) && (major == ULONG_MAX)) ||
  ------------------
  |  Branch (1811:18): [True: 0, False: 20]
  |  Branch (1811:39): [True: 0, False: 0]
  ------------------
 1812|     20|                ((errno != 0) && (major == 0)) ||
  ------------------
  |  Branch (1812:18): [True: 0, False: 20]
  |  Branch (1812:34): [True: 0, False: 0]
  ------------------
 1813|     20|                (minor > 100)) {
  ------------------
  |  Branch (1813:17): [True: 17, False: 3]
  ------------------
 1814|       |                /* invalid minor */
 1815|     20|                errno = 0;
 1816|     20|                goto done;
 1817|     20|            }
 1818|       |
 1819|      3|            session->openssh = SSH_VERSION_INT(((int) major), ((int) minor), 0);
  ------------------
  |  |   25|      3|#define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
  ------------------
 1820|       |
 1821|      3|            SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      6|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 3]
  |  |  ------------------
  ------------------
 1822|      3|                    "We are talking to an OpenSSH %s version: %lu.%lu (%x)",
 1823|      3|                    server ? "client" : "server",
 1824|      3|                    major, minor, session->openssh);
 1825|      3|        }
 1826|     77|    }
 1827|       |    /* Cisco devices have odd scp implementation which breaks */
 1828|    444|    ios = strstr(banner, "Cisco");
 1829|    444|    if (ios != NULL) {
  ------------------
  |  Branch (1829:9): [True: 2, False: 442]
  ------------------
 1830|      2|        session->flags |= SSH_SESSION_FLAG_SCP_QUOTING_BROKEN;
  ------------------
  |  |   95|      2|#define SSH_SESSION_FLAG_SCP_QUOTING_BROKEN 0x0040
  ------------------
 1831|      2|    }
 1832|       |
 1833|    508|done:
 1834|    508|    return 0;
 1835|    444|}
ssh_timestamp_init:
 1850|  9.32k|{
 1851|  9.32k|#ifdef HAVE_CLOCK_GETTIME
 1852|  9.32k|  struct timespec tp;
 1853|  9.32k|  clock_gettime(CLOCK, &tp);
  ------------------
  |  | 1839|  9.32k|#define CLOCK CLOCK_MONOTONIC
  ------------------
 1854|  9.32k|  ts->useconds = tp.tv_nsec / 1000;
 1855|       |#else
 1856|       |  struct timeval tp;
 1857|       |  gettimeofday(&tp, NULL);
 1858|       |  ts->useconds = tp.tv_usec;
 1859|       |#endif
 1860|  9.32k|  ts->seconds = tp.tv_sec;
 1861|  9.32k|}
ssh_make_milliseconds:
 1898|    579|{
 1899|    579|    unsigned long res;
 1900|       |
 1901|    579|    if (sec == (unsigned long)SSH_TIMEOUT_INFINITE) {
  ------------------
  |  |   99|    579|#define SSH_TIMEOUT_INFINITE -1
  ------------------
  |  Branch (1901:9): [True: 0, False: 579]
  ------------------
 1902|      0|        return SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|      0|#define SSH_TIMEOUT_INFINITE -1
  ------------------
 1903|      0|    }
 1904|    579|    if (sec > (unsigned long)INT_MAX / 1000) {
  ------------------
  |  Branch (1904:9): [True: 0, False: 579]
  ------------------
 1905|      0|        return INT_MAX;
 1906|      0|    }
 1907|       |
 1908|    579|    res = usec / 1000;
 1909|    579|    res += (sec * 1000);
 1910|    579|    if (res == 0) {
  ------------------
  |  Branch (1910:9): [True: 0, False: 579]
  ------------------
 1911|      0|        res = 10 * 1000; /* use a reasonable default value in case
 1912|       |                          * SSH_OPTIONS_TIMEOUT is not set in options. */
 1913|      0|    }
 1914|       |
 1915|    579|    if (res > INT_MAX) {
  ------------------
  |  Branch (1915:9): [True: 0, False: 579]
  ------------------
 1916|      0|        return INT_MAX;
 1917|    579|    } else {
 1918|    579|        return (int)res;
 1919|    579|    }
 1920|    579|}
ssh_timeout_elapsed:
 1933|  2.09k|{
 1934|  2.09k|    struct ssh_timestamp now;
 1935|       |
 1936|  2.09k|    switch(timeout) {
 1937|      0|        case -2: /*
  ------------------
  |  Branch (1937:9): [True: 0, False: 2.09k]
  ------------------
 1938|       |                  * -2 means user-defined timeout as available in
 1939|       |                  * session->timeout, session->timeout_usec.
 1940|       |                  */
 1941|      0|            SSH_LOG(SSH_LOG_DEBUG, "ssh_timeout_elapsed called with -2. this needs to "
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1942|      0|                            "be fixed. please set a breakpoint on misc.c:%d and "
 1943|      0|                            "fix the caller\n", __LINE__);
 1944|      0|            return 0;
 1945|      0|        case -1: /* -1 means infinite timeout */
  ------------------
  |  Branch (1945:9): [True: 0, False: 2.09k]
  ------------------
 1946|      0|            return 0;
 1947|      0|        case 0: /* 0 means no timeout */
  ------------------
  |  Branch (1947:9): [True: 0, False: 2.09k]
  ------------------
 1948|      0|            return 1;
 1949|  2.09k|        default:
  ------------------
  |  Branch (1949:9): [True: 2.09k, False: 0]
  ------------------
 1950|  2.09k|            break;
 1951|  2.09k|    }
 1952|       |
 1953|  2.09k|    ssh_timestamp_init(&now);
 1954|       |
 1955|  2.09k|    return (ssh_timestamp_difference(ts,&now) >= timeout);
 1956|  2.09k|}
ssh_timeout_update:
 1966|  4.37k|{
 1967|  4.37k|  struct ssh_timestamp now;
 1968|  4.37k|  int ms, ret;
 1969|  4.37k|  if (timeout <= 0) {
  ------------------
  |  Branch (1969:7): [True: 0, False: 4.37k]
  ------------------
 1970|      0|      return timeout;
 1971|      0|  }
 1972|  4.37k|  ssh_timestamp_init(&now);
 1973|  4.37k|  ms = ssh_timestamp_difference(ts,&now);
 1974|  4.37k|  if(ms < 0)
  ------------------
  |  Branch (1974:6): [True: 0, False: 4.37k]
  ------------------
 1975|      0|    ms = 0;
 1976|  4.37k|  ret = timeout - ms;
 1977|  4.37k|  return ret >= 0 ? ret: 0;
  ------------------
  |  Branch (1977:10): [True: 4.37k, False: 0]
  ------------------
 1978|  4.37k|}
ssh_strerror:
 2396|  2.03k|{
 2397|       |#if ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE)
 2398|       |    /* GNU extension on Linux */
 2399|       |    return strerror_r(err_num, buf, buflen);
 2400|       |#else
 2401|  2.03k|    int rv;
 2402|       |
 2403|       |#if defined(_WIN32)
 2404|       |    rv = strerror_s(buf, buflen, err_num);
 2405|       |#else
 2406|       |    /* POSIX version available for example on FreeBSD or in musl libc */
 2407|  2.03k|    rv = strerror_r(err_num, buf, buflen);
 2408|  2.03k|#endif /* _WIN32 */
 2409|       |
 2410|       |    /* make sure the buffer is initialized and terminated with NULL */
 2411|  2.03k|    if (-rv == ERANGE) {
  ------------------
  |  Branch (2411:9): [True: 0, False: 2.03k]
  ------------------
 2412|      0|        buf[0] = '\0';
 2413|      0|    }
 2414|  2.03k|    return buf;
 2415|  2.03k|#endif /* ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE) */
 2416|  2.03k|}
ssh_check_username_syntax:
 2606|    579|{
 2607|    579|    size_t username_len;
 2608|       |
 2609|    579|    if (username == NULL || *username == '-') {
  ------------------
  |  Branch (2609:9): [True: 0, False: 579]
  |  Branch (2609:29): [True: 0, False: 579]
  ------------------
 2610|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2611|      0|    }
 2612|       |
 2613|    579|    username_len = strlen(username);
 2614|    579|    if (username_len == 0 || username[username_len - 1] == '\\' ||
  ------------------
  |  Branch (2614:9): [True: 0, False: 579]
  |  Branch (2614:30): [True: 0, False: 579]
  ------------------
 2615|    579|        strpbrk(username, "'`\";&<>|(){}") != NULL) {
  ------------------
  |  Branch (2615:9): [True: 0, False: 579]
  ------------------
 2616|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2617|      0|    }
 2618|  3.47k|    for (size_t i = 0; i < username_len; i++) {
  ------------------
  |  Branch (2618:24): [True: 2.89k, False: 579]
  ------------------
 2619|  2.89k|        if (isspace(username[i]) != 0 && username[i + 1] == '-') {
  ------------------
  |  Branch (2619:13): [True: 0, False: 2.89k]
  |  Branch (2619:42): [True: 0, False: 0]
  ------------------
 2620|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2621|      0|        }
 2622|  2.89k|    }
 2623|       |
 2624|    579|    return SSH_OK;
  ------------------
  |  |  316|    579|#define SSH_OK 0     /* No error */
  ------------------
 2625|    579|}
ssh_proxyjumps_free:
 2637|    884|{
 2638|    884|    struct ssh_jump_info_struct *jump = NULL;
 2639|       |
 2640|    884|    for (jump =
 2641|    884|             ssh_list_pop_head(struct ssh_jump_info_struct *, proxy_jump_list);
  ------------------
  |  |  122|    884|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2642|    884|         jump != NULL;
  ------------------
  |  Branch (2642:10): [True: 0, False: 884]
  ------------------
 2643|    884|         jump = ssh_list_pop_head(struct ssh_jump_info_struct *,
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2644|    884|                                  proxy_jump_list)) {
 2645|      0|        SAFE_FREE(jump->hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2646|      0|        SAFE_FREE(jump->username);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2647|       |        SAFE_FREE(jump);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2648|      0|    }
 2649|    884|}
ssh_strict_fopen:
 2683|  1.01k|{
 2684|  1.01k|    FILE *f = NULL;
 2685|  1.01k|    struct stat sb;
 2686|  1.01k|    int r, fd;
 2687|       |
 2688|       |    /* open first to avoid TOCTOU */
 2689|  1.01k|    fd = open(filename, O_RDONLY);
 2690|  1.01k|    if (fd == -1) {
  ------------------
  |  Branch (2690:9): [True: 1.01k, False: 0]
  ------------------
 2691|  1.01k|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  283|  1.01k|    do {                                                            \
  |  |  284|  1.01k|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|  1.01k|        _ssh_log(priority,                                          \
  |  |  286|  1.01k|                 __func__,                                          \
  |  |  287|  1.01k|                 __VA_ARGS__,                                       \
  |  |  288|  1.01k|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|  1.01k|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|  1.01k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 1.01k]
  |  |  ------------------
  ------------------
 2692|  1.01k|                         errno,
 2693|  1.01k|                         "Failed to open a file %s for reading: %s",
 2694|  1.01k|                         filename);
 2695|  1.01k|        return NULL;
 2696|  1.01k|    }
 2697|       |
 2698|       |    /* Check the file is sensible for a configuration file */
 2699|      0|    r = fstat(fd, &sb);
 2700|      0|    if (r != 0) {
  ------------------
  |  Branch (2700:9): [True: 0, False: 0]
  ------------------
 2701|      0|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    do {                                                            \
  |  |  284|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|      0|        _ssh_log(priority,                                          \
  |  |  286|      0|                 __func__,                                          \
  |  |  287|      0|                 __VA_ARGS__,                                       \
  |  |  288|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2702|      0|                         errno,
 2703|      0|                         "Failed to stat %s: %s",
 2704|      0|                         filename);
 2705|      0|        close(fd);
 2706|      0|        return NULL;
 2707|      0|    }
 2708|      0|    if ((sb.st_mode & S_IFMT) != S_IFREG) {
  ------------------
  |  Branch (2708:9): [True: 0, False: 0]
  ------------------
 2709|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2710|      0|                "The file %s is not a regular file: skipping",
 2711|      0|                filename);
 2712|      0|        close(fd);
 2713|      0|        return NULL;
 2714|      0|    }
 2715|       |
 2716|      0|    if ((size_t)sb.st_size > max_file_size) {
  ------------------
  |  Branch (2716:9): [True: 0, False: 0]
  ------------------
 2717|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2718|      0|                "The file %s is too large (%jd MB > %zu MB): skipping",
 2719|      0|                filename,
 2720|      0|                (intmax_t)sb.st_size / 1024 / 1024,
 2721|      0|                max_file_size / 1024 / 1024);
 2722|      0|        close(fd);
 2723|      0|        return NULL;
 2724|      0|    }
 2725|       |
 2726|      0|    f = fdopen(fd, "r");
 2727|      0|    if (f == NULL) {
  ------------------
  |  Branch (2727:9): [True: 0, False: 0]
  ------------------
 2728|      0|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  283|      0|    do {                                                            \
  |  |  284|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|      0|        _ssh_log(priority,                                          \
  |  |  286|      0|                 __func__,                                          \
  |  |  287|      0|                 __VA_ARGS__,                                       \
  |  |  288|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2729|      0|                         errno,
 2730|      0|                         "Failed to open a file %s for reading: %s",
 2731|      0|                         filename);
 2732|      0|        close(fd);
 2733|      0|        return NULL;
 2734|      0|    }
 2735|       |
 2736|       |    /* the flcose() will close also the underlying fd */
 2737|      0|    return f;
 2738|      0|}
strlcpy:
 2749|  2.31k|{
 2750|  2.31k|    size_t len = strlen(src);
 2751|       |
 2752|  2.31k|    if (size != 0) {
  ------------------
  |  Branch (2752:9): [True: 2.31k, False: 0]
  ------------------
 2753|  2.31k|        size_t copy_len = (len >= size) ? size - 1 : len;
  ------------------
  |  Branch (2753:27): [True: 0, False: 2.31k]
  ------------------
 2754|       |
 2755|  2.31k|        memcpy(dst, src, copy_len);
 2756|  2.31k|        dst[copy_len] = '\0';
 2757|  2.31k|    }
 2758|       |
 2759|  2.31k|    return len;
 2760|  2.31k|}
ssh_normalize_loose_ip:
 2797|  1.15k|{
 2798|  1.15k|    struct in_addr addr;
 2799|  1.15k|    char buf[INET_ADDRSTRLEN];
 2800|  1.15k|    const char *p = NULL;
 2801|  1.15k|    int rc;
 2802|  1.15k|    int is_ip;
 2803|       |#ifdef _WIN32
 2804|       |    unsigned long ip;
 2805|       |    int is_broadcast;
 2806|       |#endif
 2807|       |
 2808|  1.15k|    if (host == NULL || result == NULL) {
  ------------------
  |  Branch (2808:9): [True: 0, False: 1.15k]
  |  Branch (2808:25): [True: 0, False: 1.15k]
  ------------------
 2809|      0|        return -1;
 2810|      0|    }
 2811|       |
 2812|       |    /* We don't want to normalize stricter IP checks already handled by valid
 2813|       |     * IPv4/IPv6 */
 2814|  1.15k|    is_ip = ssh_is_ipaddr(host);
 2815|  1.15k|    if (is_ip) {
  ------------------
  |  Branch (2815:9): [True: 1.15k, False: 0]
  ------------------
 2816|  1.15k|        return 1; /* not a loose IP — already a strict address */
 2817|  1.15k|    }
 2818|       |
 2819|       |#ifdef _WIN32
 2820|       |    ip = inet_addr(host);
 2821|       |    is_broadcast = strcmp(host, "255.255.255.255");
 2822|       |    if (ip == INADDR_NONE && is_broadcast != 0) {
 2823|       |        return 1; /* not a loose IP */
 2824|       |    }
 2825|       |    addr.S_un.S_addr = ip;
 2826|       |#else
 2827|      0|    rc = inet_aton(host, &addr);
 2828|      0|    if (rc == 0) {
  ------------------
  |  Branch (2828:9): [True: 0, False: 0]
  ------------------
 2829|      0|        return 1; /* not a loose IP */
 2830|      0|    }
 2831|      0|#endif
 2832|       |
 2833|      0|    p = inet_ntop(AF_INET, &addr, buf, sizeof(buf));
 2834|      0|    if (p == NULL) {
  ------------------
  |  Branch (2834:9): [True: 0, False: 0]
  ------------------
 2835|      0|        return -1;
 2836|      0|    }
 2837|       |
 2838|      0|    *result = strdup(p);
 2839|      0|    if (*result == NULL) {
  ------------------
  |  Branch (2839:9): [True: 0, False: 0]
  ------------------
 2840|      0|        return -1;
 2841|      0|    }
 2842|       |
 2843|      0|    return 0;
 2844|      0|}
misc.c:ssh_get_user_home_dir_internal:
  329|  1.15k|{
  330|  1.15k|    char *szPath = NULL;
  331|  1.15k|    struct passwd pwd;
  332|  1.15k|    struct passwd *pwdbuf = NULL;
  333|  1.15k|    char buf[NSS_BUFLEN_PASSWD] = {0};
  334|  1.15k|    int rc;
  335|       |
  336|  1.15k|    rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
  337|  1.15k|    if (rc != 0 || pwdbuf == NULL ) {
  ------------------
  |  Branch (337:9): [True: 0, False: 1.15k]
  |  Branch (337:20): [True: 0, False: 1.15k]
  ------------------
  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.15k|    szPath = strdup(pwd.pw_dir);
  347|       |
  348|  1.15k|    return szPath;
  349|  1.15k|}
misc.c:ssh_iterator_new:
  947|  4.27k|{
  948|  4.27k|    struct ssh_iterator *iterator = malloc(sizeof(struct ssh_iterator));
  949|       |
  950|  4.27k|    if (iterator == NULL) {
  ------------------
  |  Branch (950:9): [True: 0, False: 4.27k]
  ------------------
  951|      0|        return NULL;
  952|      0|    }
  953|  4.27k|    iterator->next = NULL;
  954|  4.27k|    iterator->data = data;
  955|  4.27k|    return iterator;
  956|  4.27k|}
misc.c:ssh_path_expand_internal:
 1478|  2.31k|{
 1479|  2.31k|    char *buf = NULL;
 1480|  2.31k|    char *r = NULL;
 1481|  2.31k|    char *x = NULL;
 1482|  2.31k|    const char *p = NULL;
 1483|  2.31k|    size_t i, l;
 1484|       |
 1485|  2.31k|    r = ssh_path_expand_tilde(s);
 1486|  2.31k|    if (r == NULL) {
  ------------------
  |  Branch (1486:9): [True: 0, False: 2.31k]
  ------------------
 1487|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1488|      0|        return NULL;
 1489|      0|    }
 1490|       |
 1491|  2.31k|    if (strlen(r) > MAX_BUF_SIZE) {
  ------------------
  |  |  230|  2.31k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1491:9): [True: 0, False: 2.31k]
  ------------------
 1492|      0|        ssh_set_error(session, SSH_FATAL, "string to expand too long");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1493|      0|        free(r);
 1494|      0|        return NULL;
 1495|      0|    }
 1496|       |
 1497|  2.31k|    buf = malloc(MAX_BUF_SIZE);
  ------------------
  |  |  230|  2.31k|#define MAX_BUF_SIZE 4096
  ------------------
 1498|  2.31k|    if (buf == NULL) {
  ------------------
  |  Branch (1498:9): [True: 0, False: 2.31k]
  ------------------
 1499|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1500|      0|        free(r);
 1501|      0|        return NULL;
 1502|      0|    }
 1503|       |
 1504|  2.31k|    p = r;
 1505|  2.31k|    buf[0] = '\0';
 1506|       |
 1507|  38.7k|    for (i = 0; *p != '\0'; p++) {
  ------------------
  |  Branch (1507:17): [True: 36.4k, False: 2.31k]
  ------------------
 1508|  36.4k|        if (*p != '%') {
  ------------------
  |  Branch (1508:13): [True: 34.1k, False: 2.31k]
  ------------------
 1509|  34.1k|            buf[i] = hostname_lenient ? tolower((unsigned char)*p) : *p;
  ------------------
  |  Branch (1509:22): [True: 0, False: 34.1k]
  |  Branch (1509:41): [True: 0, False: 0]
  |  Branch (1509:41): [True: 0, False: 0]
  |  Branch (1509:41): [Folded, False: 0]
  ------------------
 1510|  34.1k|            i++;
 1511|  34.1k|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|  34.1k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1511:17): [True: 0, False: 34.1k]
  ------------------
 1512|      0|                free(buf);
 1513|      0|                free(r);
 1514|      0|                return NULL;
 1515|      0|            }
 1516|  34.1k|            buf[i] = '\0';
 1517|  34.1k|            continue;
 1518|  34.1k|        }
 1519|       |
 1520|  2.31k|        p++;
 1521|  2.31k|        if (*p == '\0') {
  ------------------
  |  Branch (1521:13): [True: 0, False: 2.31k]
  ------------------
 1522|       |            /* HostName expansion rejects trailing '%' to match the parse-time
 1523|       |             * scan. Keep the general expansion path unchanged, where a
 1524|       |             * trailing '%' is truncated.
 1525|       |             */
 1526|      0|            if (hostname_lenient) {
  ------------------
  |  Branch (1526:17): [True: 0, False: 0]
  ------------------
 1527|      0|                ssh_set_error(session, SSH_FATAL, "Incomplete Hostname token");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1528|      0|                free(buf);
 1529|      0|                free(r);
 1530|      0|                return NULL;
 1531|      0|            }
 1532|      0|            break;
 1533|      0|        }
 1534|       |
 1535|  2.31k|        if (hostname_lenient && *p != '%' && *p != 'h') {
  ------------------
  |  Branch (1535:13): [True: 0, False: 2.31k]
  |  Branch (1535:33): [True: 0, False: 0]
  |  Branch (1535:46): [True: 0, False: 0]
  ------------------
 1536|      0|            buf[i] = '%';
 1537|      0|            i++;
 1538|      0|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|      0|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1538:17): [True: 0, False: 0]
  ------------------
 1539|      0|                ssh_set_error(session, SSH_FATAL, "String too long");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1540|      0|                free(buf);
 1541|      0|                free(r);
 1542|      0|                return NULL;
 1543|      0|            }
 1544|      0|            buf[i] = *p;
 1545|      0|            i++;
 1546|      0|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|      0|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1546:17): [True: 0, False: 0]
  ------------------
 1547|      0|                ssh_set_error(session, SSH_FATAL, "String too long");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1548|      0|                free(buf);
 1549|      0|                free(r);
 1550|      0|                return NULL;
 1551|      0|            }
 1552|      0|            buf[i] = '\0';
 1553|      0|            continue;
 1554|      0|        }
 1555|       |
 1556|  2.31k|        switch (*p) {
 1557|      0|        case '%':
  ------------------
  |  Branch (1557:9): [True: 0, False: 2.31k]
  ------------------
 1558|      0|            buf[i] = '%';
 1559|      0|            i++;
 1560|      0|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|      0|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1560:17): [True: 0, False: 0]
  ------------------
 1561|      0|                free(buf);
 1562|      0|                free(r);
 1563|      0|                return NULL;
 1564|      0|            }
 1565|      0|            buf[i] = '\0';
 1566|      0|            continue;
 1567|  2.31k|        case 'd':
  ------------------
  |  Branch (1567:9): [True: 2.31k, False: 0]
  ------------------
 1568|  2.31k|            x = ssh_get_user_home_dir(session);
 1569|  2.31k|            if (x == NULL) {
  ------------------
  |  Branch (1569:17): [True: 0, False: 2.31k]
  ------------------
 1570|      0|                ssh_set_error(session, SSH_FATAL, "Cannot expand homedir");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1571|      0|                free(buf);
 1572|      0|                free(r);
 1573|      0|                return NULL;
 1574|      0|            }
 1575|  2.31k|            break;
 1576|  2.31k|        case 'u':
  ------------------
  |  Branch (1576:9): [True: 0, False: 2.31k]
  ------------------
 1577|      0|            x = ssh_get_local_username();
 1578|      0|            break;
 1579|      0|        case 'l':
  ------------------
  |  Branch (1579:9): [True: 0, False: 2.31k]
  ------------------
 1580|      0|            x = ssh_get_local_hostname();
 1581|      0|            break;
 1582|      0|        case 'h':
  ------------------
  |  Branch (1582:9): [True: 0, False: 2.31k]
  ------------------
 1583|      0|            if (session->opts.host) {
  ------------------
  |  Branch (1583:17): [True: 0, False: 0]
  ------------------
 1584|      0|                x = hostname_lenient ? ssh_lowercase(session->opts.host)
  ------------------
  |  Branch (1584:21): [True: 0, False: 0]
  ------------------
 1585|      0|                                     : strdup(session->opts.host);
 1586|      0|            } else if (session->opts.originalhost) {
  ------------------
  |  Branch (1586:24): [True: 0, False: 0]
  ------------------
 1587|      0|                x = hostname_lenient ? ssh_lowercase(session->opts.originalhost)
  ------------------
  |  Branch (1587:21): [True: 0, False: 0]
  ------------------
 1588|      0|                                     : strdup(session->opts.originalhost);
 1589|      0|            } else {
 1590|      0|                ssh_set_error(session, SSH_FATAL, "Cannot expand host");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1591|      0|                free(buf);
 1592|      0|                free(r);
 1593|      0|                return NULL;
 1594|      0|            }
 1595|      0|            break;
 1596|      0|        case 'n':
  ------------------
  |  Branch (1596:9): [True: 0, False: 2.31k]
  ------------------
 1597|      0|            if (session->opts.originalhost) {
  ------------------
  |  Branch (1597:17): [True: 0, False: 0]
  ------------------
 1598|      0|                x = strdup(session->opts.originalhost);
 1599|      0|            } else {
 1600|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1601|      0|                              SSH_FATAL,
 1602|      0|                              "Cannot expand original host");
 1603|      0|                free(buf);
 1604|      0|                free(r);
 1605|      0|                return NULL;
 1606|      0|            }
 1607|      0|            break;
 1608|      0|        case 'r':
  ------------------
  |  Branch (1608:9): [True: 0, False: 2.31k]
  ------------------
 1609|      0|            if (session->opts.username) {
  ------------------
  |  Branch (1609:17): [True: 0, False: 0]
  ------------------
 1610|      0|                x = strdup(session->opts.username);
 1611|      0|            } else {
 1612|      0|                ssh_set_error(session, SSH_FATAL, "Cannot expand username");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1613|      0|                free(buf);
 1614|      0|                free(r);
 1615|      0|                return NULL;
 1616|      0|            }
 1617|      0|            break;
 1618|      0|        case 'p': {
  ------------------
  |  Branch (1618:9): [True: 0, False: 2.31k]
  ------------------
 1619|      0|            char tmp[6];
 1620|      0|            unsigned int port;
 1621|       |
 1622|      0|            ssh_options_get_port(session, &port);
 1623|      0|            snprintf(tmp, sizeof(tmp), "%u", port);
 1624|      0|            x = strdup(tmp);
 1625|      0|            break;
 1626|      0|        }
 1627|      0|        case 'j':
  ------------------
  |  Branch (1627:9): [True: 0, False: 2.31k]
  ------------------
 1628|      0|            if (session->opts.proxy_jumps_str != NULL) {
  ------------------
  |  Branch (1628:17): [True: 0, False: 0]
  ------------------
 1629|      0|                x = strdup(session->opts.proxy_jumps_str);
 1630|      0|            } else {
 1631|      0|                x = strdup("");
 1632|      0|            }
 1633|      0|            break;
 1634|      0|        case 'C':
  ------------------
  |  Branch (1634:9): [True: 0, False: 2.31k]
  ------------------
 1635|      0|            x = get_connection_hash(session);
 1636|      0|            break;
 1637|      0|        default:
  ------------------
  |  Branch (1637:9): [True: 0, False: 2.31k]
  ------------------
 1638|      0|            ssh_set_error(session, SSH_FATAL, "Wrong escape sequence detected");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1639|      0|            free(buf);
 1640|      0|            free(r);
 1641|      0|            return NULL;
 1642|  2.31k|        }
 1643|       |
 1644|  2.31k|        if (x == NULL) {
  ------------------
  |  Branch (1644:13): [True: 0, False: 2.31k]
  ------------------
 1645|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1646|      0|            free(buf);
 1647|      0|            free(r);
 1648|      0|            return NULL;
 1649|      0|        }
 1650|       |
 1651|  2.31k|        i += strlen(x);
 1652|  2.31k|        if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|  2.31k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1652:13): [True: 0, False: 2.31k]
  ------------------
 1653|      0|            ssh_set_error(session, SSH_FATAL, "String too long");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1654|      0|            free(buf);
 1655|      0|            free(x);
 1656|      0|            free(r);
 1657|      0|            return NULL;
 1658|      0|        }
 1659|  2.31k|        l = strlen(buf);
 1660|  2.31k|        strlcpy(buf + l, x, MAX_BUF_SIZE - l);
  ------------------
  |  |  230|  2.31k|#define MAX_BUF_SIZE 4096
  ------------------
 1661|  2.31k|        buf[i] = '\0';
 1662|  2.31k|        SAFE_FREE(x);
  ------------------
  |  |  373|  2.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2.31k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 2.31k]
  |  |  ------------------
  ------------------
 1663|  2.31k|    }
 1664|       |
 1665|  2.31k|    free(r);
 1666|       |
 1667|       |    /* strip the unused space by realloc */
 1668|  2.31k|    x = realloc(buf, strlen(buf) + 1);
 1669|  2.31k|    if (x == NULL) {
  ------------------
  |  Branch (1669:9): [True: 0, False: 2.31k]
  ------------------
 1670|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1671|      0|        free(buf);
 1672|      0|    }
 1673|  2.31k|    return x;
 1674|  2.31k|}
misc.c:ssh_timestamp_difference:
 1875|  6.46k|{
 1876|  6.46k|    long seconds, usecs, msecs;
 1877|  6.46k|    seconds = new->seconds - old->seconds;
 1878|  6.46k|    usecs = new->useconds - old->useconds;
 1879|  6.46k|    if (usecs < 0){
  ------------------
  |  Branch (1879:9): [True: 130, False: 6.33k]
  ------------------
 1880|    130|        seconds--;
 1881|    130|        usecs += 1000000;
 1882|    130|    }
 1883|  6.46k|    msecs = seconds * 1000 + usecs/1000;
 1884|  6.46k|    return msecs;
 1885|  6.46k|}

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

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

ssh_options_set_algo:
  374|  2.31k|{
  375|       |    /* When the list start with +,-,^ the filtration of unknown algorithms
  376|       |     * gets handled inside the helper functions, otherwise the list is taken
  377|       |     * as it is. */
  378|  2.31k|    char *p = (char *)list;
  379|       |
  380|  2.31k|    if (algo < SSH_COMP_C_S) {
  ------------------
  |  Branch (380:9): [True: 2.31k, False: 0]
  ------------------
  381|  2.31k|        if (list[0] == '+') {
  ------------------
  |  Branch (381:13): [True: 0, False: 2.31k]
  ------------------
  382|      0|            p = ssh_add_to_default_algos(algo, list+1);
  383|  2.31k|        } else if (list[0] == '-') {
  ------------------
  |  Branch (383:20): [True: 0, False: 2.31k]
  ------------------
  384|      0|            p = ssh_remove_from_default_algos(algo, list+1);
  385|  2.31k|        } else if (list[0] == '^') {
  ------------------
  |  Branch (385:20): [True: 0, False: 2.31k]
  ------------------
  386|      0|            p = ssh_prefix_default_algos(algo, list+1);
  387|      0|        }
  388|  2.31k|    }
  389|       |
  390|  2.31k|    if (p == list) {
  ------------------
  |  Branch (390:9): [True: 2.31k, False: 0]
  ------------------
  391|  2.31k|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|  2.31k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 2.31k]
  |  |  ------------------
  ------------------
  392|      0|            p = ssh_keep_fips_algos(algo, list);
  393|  2.31k|        } else {
  394|  2.31k|            p = ssh_keep_known_algos(algo, list);
  395|  2.31k|        }
  396|  2.31k|    }
  397|       |
  398|  2.31k|    if (p == NULL) {
  ------------------
  |  Branch (398:9): [True: 0, False: 2.31k]
  ------------------
  399|      0|        ssh_set_error(session, SSH_REQUEST_DENIED,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  400|      0|                "Setting method: no allowed algorithm for method \"%s\" (%s)",
  401|      0|                ssh_kex_get_description(algo), list);
  402|      0|        return -1;
  403|      0|    }
  404|       |
  405|  2.31k|    SAFE_FREE(*place);
  ------------------
  |  |  373|  2.31k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 2.31k]
  |  |  |  Branch (373:71): [Folded, False: 2.31k]
  |  |  ------------------
  ------------------
  406|  2.31k|    *place = p;
  407|       |
  408|  2.31k|    return 0;
  409|  2.31k|}
ssh_options_set:
  882|  5.79k|{
  883|  5.79k|    const char *v = NULL;
  884|  5.79k|    char *p = NULL, *q = NULL;
  885|  5.79k|    long int i;
  886|  5.79k|    unsigned int u;
  887|  5.79k|    int rc;
  888|  5.79k|    char **wanted_methods = session->opts.wanted_methods;
  889|  5.79k|    struct ssh_jump_callbacks_struct *j = NULL;
  890|       |
  891|  5.79k|    if (session == NULL) {
  ------------------
  |  Branch (891:9): [True: 0, False: 5.79k]
  ------------------
  892|      0|        return -1;
  893|      0|    }
  894|       |
  895|  5.79k|    switch (type) {
  896|    579|        case SSH_OPTIONS_HOST:
  ------------------
  |  Branch (896:9): [True: 579, False: 5.21k]
  ------------------
  897|    579|            v = value;
  898|    579|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (898:17): [True: 0, False: 579]
  |  Branch (898:30): [True: 0, False: 579]
  ------------------
  899|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  900|      0|                return -1;
  901|    579|            } else {
  902|    579|                char *username = NULL, *hostname = NULL;
  903|    579|                char *strict_hostname = NULL;
  904|    579|                char *normalized = NULL;
  905|       |
  906|       |                /* Non-strict parse: reject shell metacharacters */
  907|    579|                rc = ssh_config_parse_uri(value,
  908|    579|                                          &username,
  909|    579|                                          &hostname,
  910|    579|                                          NULL,
  911|    579|                                          true,
  912|    579|                                          false);
  913|    579|                if (rc != SSH_OK || hostname == NULL) {
  ------------------
  |  |  316|  1.15k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (913:21): [True: 0, False: 579]
  |  Branch (913:37): [True: 0, False: 579]
  ------------------
  914|      0|                    SAFE_FREE(username);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  915|      0|                    SAFE_FREE(hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  916|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  917|      0|                    return -1;
  918|      0|                }
  919|       |
  920|       |                /* Non-strict passed: set username and originalhost */
  921|    579|                if (username != NULL) {
  ------------------
  |  Branch (921:21): [True: 0, False: 579]
  ------------------
  922|      0|                    SAFE_FREE(session->opts.username);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  923|      0|                    session->opts.username = username;
  924|      0|                }
  925|    579|                if (!session->opts.config_hostname_only) {
  ------------------
  |  Branch (925:21): [True: 579, False: 0]
  ------------------
  926|    579|                    SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  373|    579|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 579]
  |  |  |  Branch (373:71): [Folded, False: 579]
  |  |  ------------------
  ------------------
  927|    579|                    SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  373|    579|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 579]
  |  |  |  Branch (373:71): [Folded, False: 579]
  |  |  ------------------
  ------------------
  928|    579|                    session->opts.originalhost = hostname;
  929|    579|                } else {
  930|      0|                    SAFE_FREE(hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  931|      0|                }
  932|       |
  933|       |                /* Strict parse: set host only if valid hostname or IP */
  934|    579|                rc = ssh_normalize_loose_ip(value, &normalized);
  935|    579|                if (rc == -1) {
  ------------------
  |  Branch (935:21): [True: 0, False: 579]
  ------------------
  936|       |                    /* Error */
  937|      0|                    SAFE_FREE(username);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  938|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  939|      0|                    return -1;
  940|      0|                }
  941|    579|                rc = ssh_config_parse_uri(
  942|    579|                    (normalized != NULL) ? normalized : value,
  ------------------
  |  Branch (942:21): [True: 0, False: 579]
  ------------------
  943|    579|                    NULL,
  944|    579|                    &strict_hostname,
  945|    579|                    NULL,
  946|    579|                    true,
  947|    579|                    true);
  948|    579|                SAFE_FREE(normalized);
  ------------------
  |  |  373|    579|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 579]
  |  |  |  Branch (373:71): [Folded, False: 579]
  |  |  ------------------
  ------------------
  949|       |
  950|    579|                if (rc != SSH_OK || strict_hostname == NULL) {
  ------------------
  |  |  316|  1.15k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (950:21): [True: 0, False: 579]
  |  Branch (950:37): [True: 0, False: 579]
  ------------------
  951|      0|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  952|      0|                    SAFE_FREE(strict_hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  953|      0|                    if (session->opts.config_hostname_only) {
  ------------------
  |  Branch (953:25): [True: 0, False: 0]
  ------------------
  954|       |                        /* Config path: Hostname must be valid */
  955|      0|                        ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  956|      0|                        return -1;
  957|      0|                    }
  958|    579|                } else {
  959|    579|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|    579|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 579]
  |  |  |  Branch (373:71): [Folded, False: 579]
  |  |  ------------------
  ------------------
  960|    579|                    session->opts.host = strict_hostname;
  961|    579|                }
  962|    579|            }
  963|    579|            break;
  964|    579|        case SSH_OPTIONS_PORT:
  ------------------
  |  Branch (964:9): [True: 0, False: 5.79k]
  ------------------
  965|      0|            if (value == NULL) {
  ------------------
  |  Branch (965:17): [True: 0, False: 0]
  ------------------
  966|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  967|      0|                return -1;
  968|      0|            } else {
  969|      0|                int *x = (int *) value;
  970|      0|                if (*x <= 0 || *x > 65535) {
  ------------------
  |  Branch (970:21): [True: 0, False: 0]
  |  Branch (970:32): [True: 0, False: 0]
  ------------------
  971|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  972|      0|                    return -1;
  973|      0|                }
  974|       |
  975|      0|                session->opts.port = *x;
  976|      0|            }
  977|      0|            break;
  978|      0|        case SSH_OPTIONS_PORT_STR:
  ------------------
  |  Branch (978:9): [True: 0, False: 5.79k]
  ------------------
  979|      0|            v = value;
  980|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (980:17): [True: 0, False: 0]
  |  Branch (980:30): [True: 0, False: 0]
  ------------------
  981|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  982|      0|                return -1;
  983|      0|            } else {
  984|      0|                q = strdup(v);
  985|      0|                if (q == NULL) {
  ------------------
  |  Branch (985:21): [True: 0, False: 0]
  ------------------
  986|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  987|      0|                    return -1;
  988|      0|                }
  989|      0|                i = strtol(q, &p, 10);
  990|      0|                if (q == p || *p != '\0') {
  ------------------
  |  Branch (990:21): [True: 0, False: 0]
  |  Branch (990:31): [True: 0, False: 0]
  ------------------
  991|      0|                    SSH_LOG(SSH_LOG_DEBUG, "No port number was parsed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  992|      0|                    SAFE_FREE(q);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  993|      0|                    return -1;
  994|      0|                }
  995|      0|                SAFE_FREE(q);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  996|      0|                if (i <= 0 || i > 65535) {
  ------------------
  |  Branch (996:21): [True: 0, False: 0]
  |  Branch (996:31): [True: 0, False: 0]
  ------------------
  997|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  998|      0|                    return -1;
  999|      0|                }
 1000|       |
 1001|      0|                session->opts.port = i;
 1002|      0|            }
 1003|      0|            break;
 1004|    579|        case SSH_OPTIONS_FD:
  ------------------
  |  Branch (1004:9): [True: 579, False: 5.21k]
  ------------------
 1005|    579|            if (value == NULL) {
  ------------------
  |  Branch (1005:17): [True: 0, False: 579]
  ------------------
 1006|      0|                session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
 1007|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1008|      0|                return -1;
 1009|    579|            } else {
 1010|    579|                socket_t *x = (socket_t *) value;
 1011|    579|                if (*x < 0) {
  ------------------
  |  Branch (1011:21): [True: 0, False: 579]
  ------------------
 1012|      0|                    session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
 1013|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1014|      0|                    return -1;
 1015|      0|                }
 1016|       |
 1017|    579|                session->opts.fd = *x & 0xffff;
 1018|    579|            }
 1019|    579|            break;
 1020|    579|        case SSH_OPTIONS_BINDADDR:
  ------------------
  |  Branch (1020:9): [True: 0, False: 5.79k]
  ------------------
 1021|      0|            v = value;
 1022|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1022:17): [True: 0, False: 0]
  |  Branch (1022:30): [True: 0, False: 0]
  ------------------
 1023|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1024|      0|                return -1;
 1025|      0|            }
 1026|       |
 1027|      0|            q = strdup(v);
 1028|      0|            if (q == NULL) {
  ------------------
  |  Branch (1028:17): [True: 0, False: 0]
  ------------------
 1029|      0|                return -1;
 1030|      0|            }
 1031|      0|            SAFE_FREE(session->opts.bindaddr);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1032|      0|            session->opts.bindaddr = q;
 1033|      0|            break;
 1034|    579|        case SSH_OPTIONS_USER:
  ------------------
  |  Branch (1034:9): [True: 579, False: 5.21k]
  ------------------
 1035|    579|            v = value;
 1036|    579|            SAFE_FREE(session->opts.username);
  ------------------
  |  |  373|    579|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 579]
  |  |  |  Branch (373:71): [Folded, False: 579]
  |  |  ------------------
  ------------------
 1037|    579|            if (v == NULL) {
  ------------------
  |  Branch (1037:17): [True: 0, False: 579]
  ------------------
 1038|      0|                q = ssh_get_local_username();
 1039|      0|                if (q == NULL) {
  ------------------
  |  Branch (1039:21): [True: 0, False: 0]
  ------------------
 1040|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1041|      0|                    return -1;
 1042|      0|                }
 1043|      0|                session->opts.username = q;
 1044|    579|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1044:24): [True: 0, False: 579]
  ------------------
 1045|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1046|      0|                return -1;
 1047|    579|            } else { /* username provided */
 1048|    579|                session->opts.username = strdup(value);
 1049|    579|                if (session->opts.username == NULL) {
  ------------------
  |  Branch (1049:21): [True: 0, False: 579]
  ------------------
 1050|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1051|      0|                    return -1;
 1052|      0|                }
 1053|    579|                rc = ssh_check_username_syntax(session->opts.username);
 1054|    579|                if (rc != SSH_OK) {
  ------------------
  |  |  316|    579|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1054:21): [True: 0, False: 579]
  ------------------
 1055|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1056|      0|                    return -1;
 1057|      0|                }
 1058|    579|            }
 1059|    579|            break;
 1060|    579|        case SSH_OPTIONS_SSH_DIR:
  ------------------
  |  Branch (1060:9): [True: 579, False: 5.21k]
  ------------------
 1061|    579|            v = value;
 1062|    579|            SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  373|    579|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 579]
  |  |  |  Branch (373:71): [Folded, False: 579]
  |  |  ------------------
  ------------------
 1063|    579|            if (v == NULL) {
  ------------------
  |  Branch (1063:17): [True: 579, False: 0]
  ------------------
 1064|    579|                session->opts.sshdir = ssh_path_expand_tilde("~/.ssh");
 1065|    579|                if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (1065:21): [True: 0, False: 579]
  ------------------
 1066|      0|                    return -1;
 1067|      0|                }
 1068|    579|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1068:24): [True: 0, False: 0]
  ------------------
 1069|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1070|      0|                return -1;
 1071|      0|            } else {
 1072|      0|                session->opts.sshdir = ssh_path_expand_tilde(v);
 1073|      0|                if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (1073:21): [True: 0, False: 0]
  ------------------
 1074|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1075|      0|                    return -1;
 1076|      0|                }
 1077|      0|            }
 1078|    579|            break;
 1079|    579|        case SSH_OPTIONS_IDENTITY:
  ------------------
  |  Branch (1079:9): [True: 0, False: 5.79k]
  ------------------
 1080|      0|        case SSH_OPTIONS_ADD_IDENTITY:
  ------------------
  |  Branch (1080:9): [True: 0, False: 5.79k]
  ------------------
 1081|      0|            v = value;
 1082|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1082:17): [True: 0, False: 0]
  |  Branch (1082:30): [True: 0, False: 0]
  ------------------
 1083|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1084|      0|                return -1;
 1085|      0|            }
 1086|      0|            q = strdup(v);
 1087|      0|            if (q == NULL) {
  ------------------
  |  Branch (1087:17): [True: 0, False: 0]
  ------------------
 1088|      0|                return -1;
 1089|      0|            }
 1090|      0|            if (session->opts.exp_flags & SSH_OPT_EXP_FLAG_IDENTITY) {
  ------------------
  |  |  118|      0|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
  |  Branch (1090:17): [True: 0, False: 0]
  ------------------
 1091|      0|                rc = ssh_list_append(session->opts.identity_non_exp, q);
 1092|      0|            } else {
 1093|      0|                rc = ssh_list_prepend(session->opts.identity_non_exp, q);
 1094|      0|            }
 1095|      0|            if (rc < 0) {
  ------------------
  |  Branch (1095:17): [True: 0, False: 0]
  ------------------
 1096|      0|                free(q);
 1097|      0|                return -1;
 1098|      0|            }
 1099|      0|            break;
 1100|      0|        case SSH_OPTIONS_CERTIFICATE:
  ------------------
  |  Branch (1100:9): [True: 0, False: 5.79k]
  ------------------
 1101|      0|            v = value;
 1102|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1102:17): [True: 0, False: 0]
  |  Branch (1102:30): [True: 0, False: 0]
  ------------------
 1103|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1104|      0|                return -1;
 1105|      0|            }
 1106|      0|            q = strdup(v);
 1107|      0|            if (q == NULL) {
  ------------------
  |  Branch (1107:17): [True: 0, False: 0]
  ------------------
 1108|      0|                return -1;
 1109|      0|            }
 1110|      0|            rc = ssh_list_append(session->opts.certificate_non_exp, q);
 1111|      0|            if (rc < 0) {
  ------------------
  |  Branch (1111:17): [True: 0, False: 0]
  ------------------
 1112|      0|                free(q);
 1113|      0|                return -1;
 1114|      0|            }
 1115|      0|            break;
 1116|      0|        case SSH_OPTIONS_KNOWNHOSTS:
  ------------------
  |  Branch (1116:9): [True: 0, False: 5.79k]
  ------------------
 1117|      0|            v = value;
 1118|      0|            SAFE_FREE(session->opts.knownhosts);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1119|      0|            if (v == NULL) {
  ------------------
  |  Branch (1119:17): [True: 0, False: 0]
  ------------------
 1120|       |                /* The default value will be set by the ssh_options_apply() */
 1121|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1121:24): [True: 0, False: 0]
  ------------------
 1122|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1123|      0|                return -1;
 1124|      0|            } else {
 1125|      0|                session->opts.knownhosts = strdup(v);
 1126|      0|                if (session->opts.knownhosts == NULL) {
  ------------------
  |  Branch (1126:21): [True: 0, False: 0]
  ------------------
 1127|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1128|      0|                    return -1;
 1129|      0|                }
 1130|      0|                session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_KNOWNHOSTS;
  ------------------
  |  |  115|      0|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
 1131|      0|            }
 1132|      0|            break;
 1133|      0|        case SSH_OPTIONS_GLOBAL_KNOWNHOSTS:
  ------------------
  |  Branch (1133:9): [True: 0, False: 5.79k]
  ------------------
 1134|      0|            v = value;
 1135|      0|            SAFE_FREE(session->opts.global_knownhosts);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1136|      0|            if (v == NULL) {
  ------------------
  |  Branch (1136:17): [True: 0, False: 0]
  ------------------
 1137|      0|                session->opts.global_knownhosts =
 1138|      0|                    strdup(GLOBAL_CONF_DIR "/ssh_known_hosts");
  ------------------
  |  |   13|      0|#define GLOBAL_CONF_DIR "/etc/ssh"
  ------------------
 1139|      0|                if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (1139:21): [True: 0, False: 0]
  ------------------
 1140|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1141|      0|                    return -1;
 1142|      0|                }
 1143|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1143:24): [True: 0, False: 0]
  ------------------
 1144|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1145|      0|                return -1;
 1146|      0|            } else {
 1147|      0|                session->opts.global_knownhosts = strdup(v);
 1148|      0|                if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (1148:21): [True: 0, False: 0]
  ------------------
 1149|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1150|      0|                    return -1;
 1151|      0|                }
 1152|      0|                session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS;
  ------------------
  |  |  116|      0|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
 1153|      0|            }
 1154|      0|            break;
 1155|    579|        case SSH_OPTIONS_TIMEOUT:
  ------------------
  |  Branch (1155:9): [True: 579, False: 5.21k]
  ------------------
 1156|    579|            if (value == NULL) {
  ------------------
  |  Branch (1156:17): [True: 0, False: 579]
  ------------------
 1157|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1158|      0|                return -1;
 1159|    579|            } else {
 1160|    579|                long *x = (long *) value;
 1161|    579|                if (*x < 0) {
  ------------------
  |  Branch (1161:21): [True: 0, False: 579]
  ------------------
 1162|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1163|      0|                    return -1;
 1164|      0|                }
 1165|       |
 1166|    579|                session->opts.timeout = *x & 0xffffffffU;
 1167|    579|            }
 1168|    579|            break;
 1169|    579|        case SSH_OPTIONS_TIMEOUT_USEC:
  ------------------
  |  Branch (1169:9): [True: 0, False: 5.79k]
  ------------------
 1170|      0|            if (value == NULL) {
  ------------------
  |  Branch (1170:17): [True: 0, False: 0]
  ------------------
 1171|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1172|      0|                return -1;
 1173|      0|            } else {
 1174|      0|                long *x = (long *) value;
 1175|      0|                if (*x < 0) {
  ------------------
  |  Branch (1175:21): [True: 0, False: 0]
  ------------------
 1176|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1177|      0|                    return -1;
 1178|      0|                }
 1179|       |
 1180|      0|                session->opts.timeout_usec = *x & 0xffffffffU;
 1181|      0|            }
 1182|      0|            break;
 1183|      0|        case SSH_OPTIONS_SSH1:
  ------------------
  |  Branch (1183:9): [True: 0, False: 5.79k]
  ------------------
 1184|      0|            break;
 1185|      0|        case SSH_OPTIONS_SSH2:
  ------------------
  |  Branch (1185:9): [True: 0, False: 5.79k]
  ------------------
 1186|      0|            break;
 1187|      0|        case SSH_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (1187:9): [True: 0, False: 5.79k]
  ------------------
 1188|      0|            if (value == NULL) {
  ------------------
  |  Branch (1188:17): [True: 0, False: 0]
  ------------------
 1189|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1190|      0|                return -1;
 1191|      0|            } else {
 1192|      0|                int *x = (int *) value;
 1193|      0|                if (*x < 0) {
  ------------------
  |  Branch (1193:21): [True: 0, False: 0]
  ------------------
 1194|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1195|      0|                    return -1;
 1196|      0|                }
 1197|       |
 1198|      0|                session->common.log_verbosity = *x & 0xffffU;
 1199|      0|                ssh_set_log_level(*x & 0xffffU);
 1200|      0|            }
 1201|      0|            break;
 1202|      0|        case SSH_OPTIONS_LOG_VERBOSITY_STR:
  ------------------
  |  Branch (1202:9): [True: 0, False: 5.79k]
  ------------------
 1203|      0|            v = value;
 1204|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1204:17): [True: 0, False: 0]
  |  Branch (1204:30): [True: 0, False: 0]
  ------------------
 1205|      0|                session->common.log_verbosity = 0;
 1206|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1207|      0|                return -1;
 1208|      0|            } else {
 1209|      0|                q = strdup(v);
 1210|      0|                if (q == NULL) {
  ------------------
  |  Branch (1210:21): [True: 0, False: 0]
  ------------------
 1211|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1212|      0|                    return -1;
 1213|      0|                }
 1214|      0|                i = strtol(q, &p, 10);
 1215|      0|                if (q == p) {
  ------------------
  |  Branch (1215:21): [True: 0, False: 0]
  ------------------
 1216|      0|                    SSH_LOG(SSH_LOG_DEBUG, "No log verbositiy was parsed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1217|      0|                    SAFE_FREE(q);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1218|      0|                    return -1;
 1219|      0|                }
 1220|      0|                SAFE_FREE(q);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1221|      0|                if (i < 0) {
  ------------------
  |  Branch (1221:21): [True: 0, False: 0]
  ------------------
 1222|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1223|      0|                    return -1;
 1224|      0|                }
 1225|       |
 1226|      0|                session->common.log_verbosity = i & 0xffffU;
 1227|      0|                ssh_set_log_level(i & 0xffffU);
 1228|      0|            }
 1229|      0|            break;
 1230|    579|        case SSH_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (1230:9): [True: 579, False: 5.21k]
  ------------------
 1231|    579|            v = value;
 1232|    579|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1232:17): [True: 0, False: 579]
  |  Branch (1232:30): [True: 0, False: 579]
  ------------------
 1233|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1234|      0|                return -1;
 1235|    579|            } else {
 1236|    579|                rc = ssh_options_set_algo(session,
 1237|    579|                                          SSH_CRYPT_C_S,
 1238|    579|                                          v,
 1239|    579|                                          &wanted_methods[SSH_CRYPT_C_S]);
 1240|    579|                if (rc < 0)
  ------------------
  |  Branch (1240:21): [True: 0, False: 579]
  ------------------
 1241|      0|                    return -1;
 1242|    579|            }
 1243|    579|            break;
 1244|    579|        case SSH_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (1244:9): [True: 579, False: 5.21k]
  ------------------
 1245|    579|            v = value;
 1246|    579|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1246:17): [True: 0, False: 579]
  |  Branch (1246:30): [True: 0, False: 579]
  ------------------
 1247|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1248|      0|                return -1;
 1249|    579|            } else {
 1250|    579|                rc = ssh_options_set_algo(session,
 1251|    579|                                          SSH_CRYPT_S_C,
 1252|    579|                                          v,
 1253|    579|                                          &wanted_methods[SSH_CRYPT_S_C]);
 1254|    579|                if (rc < 0)
  ------------------
  |  Branch (1254:21): [True: 0, False: 579]
  ------------------
 1255|      0|                    return -1;
 1256|    579|            }
 1257|    579|            break;
 1258|    579|        case SSH_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (1258:9): [True: 0, False: 5.79k]
  ------------------
 1259|      0|            v = value;
 1260|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1260:17): [True: 0, False: 0]
  |  Branch (1260:30): [True: 0, False: 0]
  ------------------
 1261|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1262|      0|                return -1;
 1263|      0|            } else {
 1264|      0|                rc = ssh_options_set_algo(session,
 1265|      0|                                          SSH_KEX,
 1266|      0|                                          v,
 1267|      0|                                          &wanted_methods[SSH_KEX]);
 1268|      0|                if (rc < 0)
  ------------------
  |  Branch (1268:21): [True: 0, False: 0]
  ------------------
 1269|      0|                    return -1;
 1270|      0|            }
 1271|      0|            break;
 1272|      0|        case SSH_OPTIONS_HOSTKEYS:
  ------------------
  |  Branch (1272:9): [True: 0, False: 5.79k]
  ------------------
 1273|      0|            v = value;
 1274|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1274:17): [True: 0, False: 0]
  |  Branch (1274:30): [True: 0, False: 0]
  ------------------
 1275|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1276|      0|                return -1;
 1277|      0|            } else {
 1278|      0|                rc = ssh_options_set_algo(session,
 1279|      0|                                          SSH_HOSTKEYS,
 1280|      0|                                          v,
 1281|      0|                                          &wanted_methods[SSH_HOSTKEYS]);
 1282|      0|                if (rc < 0)
  ------------------
  |  Branch (1282:21): [True: 0, False: 0]
  ------------------
 1283|      0|                    return -1;
 1284|      0|            }
 1285|      0|            break;
 1286|      0|        case SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES:
  ------------------
  |  Branch (1286:9): [True: 0, False: 5.79k]
  ------------------
 1287|      0|            v = value;
 1288|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1288:17): [True: 0, False: 0]
  |  Branch (1288:30): [True: 0, False: 0]
  ------------------
 1289|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1290|      0|                return -1;
 1291|      0|            } else {
 1292|      0|                rc = ssh_options_set_algo(session,
 1293|      0|                                          SSH_HOSTKEYS,
 1294|      0|                                          v,
 1295|      0|                                          &session->opts.pubkey_accepted_types);
 1296|      0|                if (rc < 0)
  ------------------
  |  Branch (1296:21): [True: 0, False: 0]
  ------------------
 1297|      0|                    return -1;
 1298|      0|            }
 1299|      0|            break;
 1300|    579|        case SSH_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (1300:9): [True: 579, False: 5.21k]
  ------------------
 1301|    579|            v = value;
 1302|    579|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1302:17): [True: 0, False: 579]
  |  Branch (1302:30): [True: 0, False: 579]
  ------------------
 1303|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1304|      0|                return -1;
 1305|    579|            } else {
 1306|    579|                rc = ssh_options_set_algo(session,
 1307|    579|                                          SSH_MAC_C_S,
 1308|    579|                                          v,
 1309|    579|                                          &wanted_methods[SSH_MAC_C_S]);
 1310|    579|                if (rc < 0)
  ------------------
  |  Branch (1310:21): [True: 0, False: 579]
  ------------------
 1311|      0|                    return -1;
 1312|    579|            }
 1313|    579|            break;
 1314|    579|         case SSH_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (1314:10): [True: 579, False: 5.21k]
  ------------------
 1315|    579|            v = value;
 1316|    579|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1316:17): [True: 0, False: 579]
  |  Branch (1316:30): [True: 0, False: 579]
  ------------------
 1317|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1318|      0|                return -1;
 1319|    579|            } else {
 1320|    579|                rc = ssh_options_set_algo(session,
 1321|    579|                                          SSH_MAC_S_C,
 1322|    579|                                          v,
 1323|    579|                                          &wanted_methods[SSH_MAC_S_C]);
 1324|    579|                if (rc < 0)
  ------------------
  |  Branch (1324:21): [True: 0, False: 579]
  ------------------
 1325|      0|                    return -1;
 1326|    579|            }
 1327|    579|            break;
 1328|    579|        case SSH_OPTIONS_COMPRESSION_C_S:
  ------------------
  |  Branch (1328:9): [True: 0, False: 5.79k]
  ------------------
 1329|      0|            v = value;
 1330|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1330:17): [True: 0, False: 0]
  |  Branch (1330:30): [True: 0, False: 0]
  ------------------
 1331|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1332|      0|                return -1;
 1333|      0|            } else {
 1334|      0|                const char *tmp = v;
 1335|      0|                if (strcasecmp(value, "yes") == 0){
  ------------------
  |  Branch (1335:21): [True: 0, False: 0]
  ------------------
 1336|      0|                    tmp = "zlib@openssh.com,none";
 1337|      0|                } else if (strcasecmp(value, "no") == 0){
  ------------------
  |  Branch (1337:28): [True: 0, False: 0]
  ------------------
 1338|      0|                    tmp = "none,zlib@openssh.com";
 1339|      0|                }
 1340|      0|                rc = ssh_options_set_algo(session,
 1341|      0|                                          SSH_COMP_C_S,
 1342|      0|                                          tmp,
 1343|      0|                                          &wanted_methods[SSH_COMP_C_S]);
 1344|      0|                if (rc < 0)
  ------------------
  |  Branch (1344:21): [True: 0, False: 0]
  ------------------
 1345|      0|                    return -1;
 1346|      0|            }
 1347|      0|            break;
 1348|      0|        case SSH_OPTIONS_COMPRESSION_S_C:
  ------------------
  |  Branch (1348:9): [True: 0, False: 5.79k]
  ------------------
 1349|      0|            v = value;
 1350|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1350:17): [True: 0, False: 0]
  |  Branch (1350:30): [True: 0, False: 0]
  ------------------
 1351|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1352|      0|                return -1;
 1353|      0|            } else {
 1354|      0|                const char *tmp = v;
 1355|      0|                if (strcasecmp(value, "yes") == 0){
  ------------------
  |  Branch (1355:21): [True: 0, False: 0]
  ------------------
 1356|      0|                    tmp = "zlib@openssh.com,none";
 1357|      0|                } else if (strcasecmp(value, "no") == 0){
  ------------------
  |  Branch (1357:28): [True: 0, False: 0]
  ------------------
 1358|      0|                    tmp = "none,zlib@openssh.com";
 1359|      0|                }
 1360|       |
 1361|      0|                rc = ssh_options_set_algo(session,
 1362|      0|                                          SSH_COMP_S_C,
 1363|      0|                                          tmp,
 1364|      0|                                          &wanted_methods[SSH_COMP_S_C]);
 1365|      0|                if (rc < 0)
  ------------------
  |  Branch (1365:21): [True: 0, False: 0]
  ------------------
 1366|      0|                    return -1;
 1367|      0|            }
 1368|      0|            break;
 1369|      0|        case SSH_OPTIONS_COMPRESSION:
  ------------------
  |  Branch (1369:9): [True: 0, False: 5.79k]
  ------------------
 1370|      0|            v = value;
 1371|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1371:17): [True: 0, False: 0]
  |  Branch (1371:30): [True: 0, False: 0]
  ------------------
 1372|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1373|      0|                return -1;
 1374|      0|            }
 1375|      0|            if(ssh_options_set(session,SSH_OPTIONS_COMPRESSION_C_S, v) < 0)
  ------------------
  |  Branch (1375:16): [True: 0, False: 0]
  ------------------
 1376|      0|                return -1;
 1377|      0|            if(ssh_options_set(session,SSH_OPTIONS_COMPRESSION_S_C, v) < 0)
  ------------------
  |  Branch (1377:16): [True: 0, False: 0]
  ------------------
 1378|      0|                return -1;
 1379|      0|            break;
 1380|      0|        case SSH_OPTIONS_COMPRESSION_LEVEL:
  ------------------
  |  Branch (1380:9): [True: 0, False: 5.79k]
  ------------------
 1381|      0|            if (value == NULL) {
  ------------------
  |  Branch (1381:17): [True: 0, False: 0]
  ------------------
 1382|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1383|      0|                return -1;
 1384|      0|            } else {
 1385|      0|                int *x = (int *)value;
 1386|      0|                if (*x < 1 || *x > 9) {
  ------------------
  |  Branch (1386:21): [True: 0, False: 0]
  |  Branch (1386:31): [True: 0, False: 0]
  ------------------
 1387|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1388|      0|                    return -1;
 1389|      0|                }
 1390|      0|                session->opts.compressionlevel = *x & 0xff;
 1391|      0|            }
 1392|      0|            break;
 1393|      0|        case SSH_OPTIONS_STRICTHOSTKEYCHECK:
  ------------------
  |  Branch (1393:9): [True: 0, False: 5.79k]
  ------------------
 1394|      0|            if (value == NULL) {
  ------------------
  |  Branch (1394:17): [True: 0, False: 0]
  ------------------
 1395|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1396|      0|                return -1;
 1397|      0|            } else {
 1398|      0|                int *x = (int *) value;
 1399|      0|                int mode = *x;
 1400|       |
 1401|      0|                switch (mode) {
 1402|      0|                case SSH_STRICT_HOSTKEY_OFF:
  ------------------
  |  Branch (1402:17): [True: 0, False: 0]
  ------------------
 1403|      0|                case SSH_STRICT_HOSTKEY_YES:
  ------------------
  |  Branch (1403:17): [True: 0, False: 0]
  ------------------
 1404|      0|                case SSH_STRICT_HOSTKEY_ASK:
  ------------------
  |  Branch (1404:17): [True: 0, False: 0]
  ------------------
 1405|      0|                case SSH_STRICT_HOSTKEY_ACCEPT_NEW:
  ------------------
  |  Branch (1405:17): [True: 0, False: 0]
  ------------------
 1406|      0|                    session->opts.StrictHostKeyChecking = mode;
 1407|      0|                    break;
 1408|      0|                default:
  ------------------
  |  Branch (1408:17): [True: 0, False: 0]
  ------------------
 1409|       |                    /* Preserve the legacy low-byte "non-zero means yes"
 1410|       |                     * normalization.
 1411|       |                     */
 1412|      0|                    session->opts.StrictHostKeyChecking =
 1413|      0|                        (mode & 0xff) > 0 ? SSH_STRICT_HOSTKEY_YES
  ------------------
  |  Branch (1413:25): [True: 0, False: 0]
  ------------------
 1414|      0|                                          : SSH_STRICT_HOSTKEY_OFF;
 1415|      0|                    break;
 1416|      0|                }
 1417|      0|            }
 1418|      0|            break;
 1419|      0|        case SSH_OPTIONS_PROXYCOMMAND:
  ------------------
  |  Branch (1419:9): [True: 0, False: 5.79k]
  ------------------
 1420|      0|            v = value;
 1421|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1421:17): [True: 0, False: 0]
  |  Branch (1421:30): [True: 0, False: 0]
  ------------------
 1422|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1423|      0|                return -1;
 1424|      0|            } else {
 1425|      0|                SAFE_FREE(session->opts.ProxyCommand);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1426|       |                /* Setting the command to 'none' disables this option. */
 1427|      0|                rc = strcasecmp(v, "none");
 1428|      0|                if (rc != 0) {
  ------------------
  |  Branch (1428:21): [True: 0, False: 0]
  ------------------
 1429|      0|                    q = strdup(v);
 1430|      0|                    if (q == NULL) {
  ------------------
  |  Branch (1430:25): [True: 0, False: 0]
  ------------------
 1431|      0|                        return -1;
 1432|      0|                    }
 1433|      0|                    session->opts.ProxyCommand = q;
 1434|      0|                    session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_PROXYCOMMAND;
  ------------------
  |  |  117|      0|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
 1435|      0|                }
 1436|      0|            }
 1437|      0|            break;
 1438|      0|        case SSH_OPTIONS_PROXYJUMP:
  ------------------
  |  Branch (1438:9): [True: 0, False: 5.79k]
  ------------------
 1439|      0|            v = value;
 1440|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1440:17): [True: 0, False: 0]
  |  Branch (1440:30): [True: 0, False: 0]
  ------------------
 1441|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1442|      0|                return -1;
 1443|      0|            } else {
 1444|      0|                rc = ssh_config_parse_proxy_jump(session, v, true);
 1445|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1445:21): [True: 0, False: 0]
  ------------------
 1446|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1447|      0|                }
 1448|      0|            }
 1449|      0|            break;
 1450|      0|        case SSH_OPTIONS_PROXYJUMP_CB_LIST_APPEND:
  ------------------
  |  Branch (1450:9): [True: 0, False: 5.79k]
  ------------------
 1451|      0|            j = (struct ssh_jump_callbacks_struct *)value;
 1452|      0|            if (j == NULL) {
  ------------------
  |  Branch (1452:17): [True: 0, False: 0]
  ------------------
 1453|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1454|      0|                return -1;
 1455|      0|            } else {
 1456|      0|                rc = ssh_list_prepend(session->opts.proxy_jumps_user_cb, j);
 1457|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1457:21): [True: 0, False: 0]
  ------------------
 1458|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1459|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1460|      0|                }
 1461|      0|            }
 1462|      0|            break;
 1463|      0|        case SSH_OPTIONS_GSSAPI_SERVER_IDENTITY:
  ------------------
  |  Branch (1463:9): [True: 0, False: 5.79k]
  ------------------
 1464|      0|            v = value;
 1465|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1465:17): [True: 0, False: 0]
  |  Branch (1465:30): [True: 0, False: 0]
  ------------------
 1466|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1467|      0|                return -1;
 1468|      0|            } else {
 1469|      0|                SAFE_FREE(session->opts.gss_server_identity);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1470|      0|                session->opts.gss_server_identity = strdup(v);
 1471|      0|                if (session->opts.gss_server_identity == NULL) {
  ------------------
  |  Branch (1471:21): [True: 0, False: 0]
  ------------------
 1472|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1473|      0|                    return -1;
 1474|      0|                }
 1475|      0|            }
 1476|      0|            break;
 1477|      0|        case SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY:
  ------------------
  |  Branch (1477:9): [True: 0, False: 5.79k]
  ------------------
 1478|      0|            v = value;
 1479|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1479:17): [True: 0, False: 0]
  |  Branch (1479:30): [True: 0, False: 0]
  ------------------
 1480|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1481|      0|                return -1;
 1482|      0|            } else {
 1483|      0|                SAFE_FREE(session->opts.gss_client_identity);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1484|      0|                session->opts.gss_client_identity = strdup(v);
 1485|      0|                if (session->opts.gss_client_identity == NULL) {
  ------------------
  |  Branch (1485:21): [True: 0, False: 0]
  ------------------
 1486|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1487|      0|                    return -1;
 1488|      0|                }
 1489|      0|            }
 1490|      0|            break;
 1491|      0|        case SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS:
  ------------------
  |  Branch (1491:9): [True: 0, False: 5.79k]
  ------------------
 1492|      0|            if (value == NULL) {
  ------------------
  |  Branch (1492:17): [True: 0, False: 0]
  ------------------
 1493|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1494|      0|                return -1;
 1495|      0|            } else {
 1496|      0|                int x = *(int *)value;
 1497|       |
 1498|      0|                session->opts.gss_delegate_creds = (x & 0xff);
 1499|      0|            }
 1500|      0|            break;
 1501|       |#ifdef WITH_GSSAPI
 1502|       |        case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE:
 1503|       |            if (value == NULL) {
 1504|       |                ssh_set_error_invalid(session);
 1505|       |                return -1;
 1506|       |            } else {
 1507|       |                bool *x = (bool *)value;
 1508|       |                session->opts.gssapi_key_exchange = *x;
 1509|       |            }
 1510|       |            break;
 1511|       |        case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE_ALGS:
 1512|       |            v = value;
 1513|       |            if (v == NULL || v[0] == '\0') {
 1514|       |                ssh_set_error_invalid(session);
 1515|       |                return -1;
 1516|       |            } else {
 1517|       |                /* Check if algorithms are supported */
 1518|       |                char *ret =
 1519|       |                    ssh_find_all_matching(GSSAPI_KEY_EXCHANGE_SUPPORTED, v);
 1520|       |                if (ret == NULL) {
 1521|       |                    ssh_set_error(session,
 1522|       |                                  SSH_FATAL,
 1523|       |                                  "GSSAPI key exchange algorithms not "
 1524|       |                                  "supported or invalid");
 1525|       |                    return -1;
 1526|       |                }
 1527|       |                SAFE_FREE(session->opts.gssapi_key_exchange_algs);
 1528|       |                session->opts.gssapi_key_exchange_algs = ret;
 1529|       |            }
 1530|       |            break;
 1531|       |#endif
 1532|      0|        case SSH_OPTIONS_PASSWORD_AUTH:
  ------------------
  |  Branch (1532:9): [True: 0, False: 5.79k]
  ------------------
 1533|      0|        case SSH_OPTIONS_PUBKEY_AUTH:
  ------------------
  |  Branch (1533:9): [True: 0, False: 5.79k]
  ------------------
 1534|      0|        case SSH_OPTIONS_KBDINT_AUTH:
  ------------------
  |  Branch (1534:9): [True: 0, False: 5.79k]
  ------------------
 1535|      0|        case SSH_OPTIONS_GSSAPI_AUTH:
  ------------------
  |  Branch (1535:9): [True: 0, False: 5.79k]
  ------------------
 1536|      0|            if (value == NULL) {
  ------------------
  |  Branch (1536:17): [True: 0, False: 0]
  ------------------
 1537|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1538|      0|                return -1;
 1539|      0|            } else {
 1540|      0|                int x = *(int *)value;
 1541|      0|                u = type == SSH_OPTIONS_PASSWORD_AUTH ?
  ------------------
  |  Branch (1541:21): [True: 0, False: 0]
  ------------------
 1542|      0|                    SSH_OPT_FLAG_PASSWORD_AUTH:
  ------------------
  |  |  109|      0|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
 1543|      0|                    type == SSH_OPTIONS_PUBKEY_AUTH ?
  ------------------
  |  Branch (1543:21): [True: 0, False: 0]
  ------------------
 1544|      0|                        SSH_OPT_FLAG_PUBKEY_AUTH:
  ------------------
  |  |  110|      0|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
 1545|      0|                        type == SSH_OPTIONS_KBDINT_AUTH ?
  ------------------
  |  Branch (1545:25): [True: 0, False: 0]
  ------------------
 1546|      0|                            SSH_OPT_FLAG_KBDINT_AUTH:
  ------------------
  |  |  111|      0|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
 1547|      0|                            SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|      0|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
 1548|      0|                if (x != 0) {
  ------------------
  |  Branch (1548:21): [True: 0, False: 0]
  ------------------
 1549|      0|                    session->opts.flags |= u;
 1550|      0|                } else {
 1551|      0|                    session->opts.flags &= ~u;
 1552|      0|                }
 1553|      0|                if (type == SSH_OPTIONS_PUBKEY_AUTH) {
  ------------------
  |  Branch (1553:21): [True: 0, False: 0]
  ------------------
 1554|       |                    /*
 1555|       |                     * Keep the legacy enabled/disabled auth flag semantics in
 1556|       |                     * sync above while also storing the selected
 1557|       |                     * PubkeyAuthentication mode here.
 1558|       |                     */
 1559|      0|                    switch (x) {
 1560|      0|                    case SSH_PUBKEY_AUTH_NO:
  ------------------
  |  Branch (1560:21): [True: 0, False: 0]
  ------------------
 1561|      0|                    case SSH_PUBKEY_AUTH_ALL:
  ------------------
  |  Branch (1561:21): [True: 0, False: 0]
  ------------------
 1562|      0|                    case SSH_PUBKEY_AUTH_UNBOUND:
  ------------------
  |  Branch (1562:21): [True: 0, False: 0]
  ------------------
 1563|      0|                    case SSH_PUBKEY_AUTH_HOST_BOUND:
  ------------------
  |  Branch (1563:21): [True: 0, False: 0]
  ------------------
 1564|      0|                        session->opts.pubkey_auth = x;
 1565|      0|                        break;
 1566|      0|                    default:
  ------------------
  |  Branch (1566:21): [True: 0, False: 0]
  ------------------
 1567|       |                        /* Preserve the legacy non-zero "yes" normalization
 1568|       |                         * here so callers passing -1 still land on
 1569|       |                         * SSH_PUBKEY_AUTH_ALL.
 1570|       |                         */
 1571|      0|                        session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
 1572|      0|                        break;
 1573|      0|                    }
 1574|      0|                }
 1575|      0|            }
 1576|      0|            break;
 1577|      0|        case SSH_OPTIONS_NODELAY:
  ------------------
  |  Branch (1577:9): [True: 0, False: 5.79k]
  ------------------
 1578|      0|            if (value == NULL) {
  ------------------
  |  Branch (1578:17): [True: 0, False: 0]
  ------------------
 1579|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1580|      0|                return -1;
 1581|      0|            } else {
 1582|      0|                int *x = (int *) value;
 1583|      0|                session->opts.nodelay = (*x & 0xff) > 0 ? 1 : 0;
  ------------------
  |  Branch (1583:41): [True: 0, False: 0]
  ------------------
 1584|      0|            }
 1585|      0|            break;
 1586|    579|        case SSH_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (1586:9): [True: 579, False: 5.21k]
  ------------------
 1587|    579|            if (value == NULL) {
  ------------------
  |  Branch (1587:17): [True: 0, False: 579]
  ------------------
 1588|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1589|      0|                return -1;
 1590|    579|            } else {
 1591|    579|                bool *x = (bool *)value;
 1592|    579|                session->opts.config_processed = !(*x);
 1593|    579|            }
 1594|    579|            break;
 1595|    579|        case SSH_OPTIONS_REKEY_DATA:
  ------------------
  |  Branch (1595:9): [True: 0, False: 5.79k]
  ------------------
 1596|      0|            if (value == NULL) {
  ------------------
  |  Branch (1596:17): [True: 0, False: 0]
  ------------------
 1597|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1598|      0|                return -1;
 1599|      0|            } else {
 1600|      0|                uint64_t *x = (uint64_t *)value;
 1601|      0|                session->opts.rekey_data = *x;
 1602|      0|            }
 1603|      0|            break;
 1604|      0|        case SSH_OPTIONS_REKEY_TIME:
  ------------------
  |  Branch (1604:9): [True: 0, False: 5.79k]
  ------------------
 1605|      0|            if (value == NULL) {
  ------------------
  |  Branch (1605:17): [True: 0, False: 0]
  ------------------
 1606|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1607|      0|                return -1;
 1608|      0|            } else {
 1609|      0|                uint32_t *x = (uint32_t *)value;
 1610|      0|                if ((*x * 1000) < *x) {
  ------------------
  |  Branch (1610:21): [True: 0, False: 0]
  ------------------
 1611|      0|                    ssh_set_error(session, SSH_REQUEST_DENIED,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1612|      0|                                  "The provided value (%" PRIu32 ") for rekey"
 1613|      0|                                  " time is too large", *x);
 1614|      0|                    return -1;
 1615|      0|                }
 1616|      0|                session->opts.rekey_time = (*x) * 1000;
 1617|      0|            }
 1618|      0|            break;
 1619|      0|        case SSH_OPTIONS_RSA_MIN_SIZE:
  ------------------
  |  Branch (1619:9): [True: 0, False: 5.79k]
  ------------------
 1620|      0|            if (value == NULL) {
  ------------------
  |  Branch (1620:17): [True: 0, False: 0]
  ------------------
 1621|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1622|      0|                return -1;
 1623|      0|            } else {
 1624|      0|                int *x = (int *)value;
 1625|       |
 1626|      0|                if (*x < 0) {
  ------------------
  |  Branch (1626:21): [True: 0, False: 0]
  ------------------
 1627|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1628|      0|                    return -1;
 1629|      0|                }
 1630|       |
 1631|       |                /* (*x == 0) is allowed as it is used to revert to default */
 1632|       |
 1633|      0|                if (*x > 0 && *x < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|      0|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (1633:21): [True: 0, False: 0]
  |  Branch (1633:31): [True: 0, False: 0]
  ------------------
 1634|      0|                    ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1635|      0|                                  SSH_REQUEST_DENIED,
 1636|      0|                                  "The provided value (%d) for minimal RSA key "
 1637|      0|                                  "size is too small. Use at least %d bits.",
 1638|      0|                                  *x,
 1639|      0|                                  RSA_MIN_KEY_SIZE);
 1640|      0|                    return -1;
 1641|      0|                }
 1642|      0|                session->opts.rsa_min_size = *x;
 1643|      0|            }
 1644|      0|            break;
 1645|      0|        case SSH_OPTIONS_IDENTITY_AGENT:
  ------------------
  |  Branch (1645:9): [True: 0, False: 5.79k]
  ------------------
 1646|      0|            v = value;
 1647|      0|            SAFE_FREE(session->opts.agent_socket);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1648|      0|            if (v == NULL) {
  ------------------
  |  Branch (1648:17): [True: 0, False: 0]
  ------------------
 1649|       |                /* The default value will be set by the ssh_options_apply() */
 1650|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1650:24): [True: 0, False: 0]
  ------------------
 1651|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1652|      0|                return -1;
 1653|      0|            } else {
 1654|      0|                session->opts.agent_socket = ssh_path_expand_tilde(v);
 1655|      0|                if (session->opts.agent_socket == NULL) {
  ------------------
  |  Branch (1655:21): [True: 0, False: 0]
  ------------------
 1656|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1657|      0|                    return -1;
 1658|      0|                }
 1659|      0|            }
 1660|      0|            break;
 1661|      0|        case SSH_OPTIONS_IDENTITIES_ONLY:
  ------------------
  |  Branch (1661:9): [True: 0, False: 5.79k]
  ------------------
 1662|      0|            if (value == NULL) {
  ------------------
  |  Branch (1662:17): [True: 0, False: 0]
  ------------------
 1663|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1664|      0|                return -1;
 1665|      0|            } else {
 1666|      0|                bool *x = (bool *)value;
 1667|      0|                session->opts.identities_only = *x;
 1668|      0|            }
 1669|      0|            break;
 1670|      0|        case SSH_OPTIONS_CONTROL_MASTER:
  ------------------
  |  Branch (1670:9): [True: 0, False: 5.79k]
  ------------------
 1671|      0|            if (value == NULL) {
  ------------------
  |  Branch (1671:17): [True: 0, False: 0]
  ------------------
 1672|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1673|      0|                return -1;
 1674|      0|            } else {
 1675|      0|                int *x = (int *) value;
 1676|      0|                if (*x < SSH_CONTROL_MASTER_NO || *x > SSH_CONTROL_MASTER_AUTOASK) {
  ------------------
  |  Branch (1676:21): [True: 0, False: 0]
  |  Branch (1676:51): [True: 0, False: 0]
  ------------------
 1677|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1678|      0|                    return -1;
 1679|      0|                }
 1680|      0|                session->opts.control_master = *x;
 1681|      0|            }
 1682|      0|            break;
 1683|      0|        case SSH_OPTIONS_CONTROL_PATH:
  ------------------
  |  Branch (1683:9): [True: 0, False: 5.79k]
  ------------------
 1684|      0|            v = value;
 1685|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1685:17): [True: 0, False: 0]
  |  Branch (1685:30): [True: 0, False: 0]
  ------------------
 1686|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1687|      0|                return -1;
 1688|      0|            } else {
 1689|      0|                SAFE_FREE(session->opts.control_path);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1690|      0|                rc = strcasecmp(v, "none");
 1691|      0|                if (rc != 0) {
  ------------------
  |  Branch (1691:21): [True: 0, False: 0]
  ------------------
 1692|      0|                    session->opts.control_path = ssh_path_expand_tilde(v);
 1693|      0|                    if (session->opts.control_path == NULL) {
  ------------------
  |  Branch (1693:25): [True: 0, False: 0]
  ------------------
 1694|      0|                        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1695|      0|                        return -1;
 1696|      0|                    }
 1697|      0|                    session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_CONTROL_PATH;
  ------------------
  |  |  119|      0|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
 1698|      0|                }
 1699|      0|            }
 1700|      0|            break;
 1701|      0|        case SSH_OPTIONS_PKI_CONTEXT:
  ------------------
  |  Branch (1701:9): [True: 0, False: 5.79k]
  ------------------
 1702|      0|            if (value == NULL) {
  ------------------
  |  Branch (1702:17): [True: 0, False: 0]
  ------------------
 1703|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1704|      0|                return -1;
 1705|      0|            }
 1706|       |
 1707|      0|            SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1050|      0|    do {                         \
  |  | 1051|      0|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1051:13): [True: 0, False: 0]
  |  |  ------------------
  |  | 1052|      0|            ssh_pki_ctx_free(x); \
  |  | 1053|      0|            x = NULL;            \
  |  | 1054|      0|        }                        \
  |  | 1055|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1055:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1708|       |
 1709|      0|            session->pki_context = ssh_pki_ctx_dup((const ssh_pki_ctx)value);
 1710|      0|            if (session->pki_context == NULL) {
  ------------------
  |  Branch (1710:17): [True: 0, False: 0]
  ------------------
 1711|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1712|      0|                return -1;
 1713|      0|            }
 1714|      0|            break;
 1715|      0|        case SSH_OPTIONS_ADDRESS_FAMILY:
  ------------------
  |  Branch (1715:9): [True: 0, False: 5.79k]
  ------------------
 1716|      0|            if (value == NULL) {
  ------------------
  |  Branch (1716:17): [True: 0, False: 0]
  ------------------
 1717|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1718|      0|                return -1;
 1719|      0|            } else {
 1720|      0|                int *x = (int *)value;
 1721|      0|                if (*x < SSH_ADDRESS_FAMILY_ANY ||
  ------------------
  |  Branch (1721:21): [True: 0, False: 0]
  ------------------
 1722|      0|                    *x > SSH_ADDRESS_FAMILY_INET6) {
  ------------------
  |  Branch (1722:21): [True: 0, False: 0]
  ------------------
 1723|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1724|      0|                    return -1;
 1725|      0|                }
 1726|      0|                session->opts.address_family = *x;
 1727|      0|            }
 1728|      0|            break;
 1729|      0|        case SSH_OPTIONS_BATCH_MODE:
  ------------------
  |  Branch (1729:9): [True: 0, False: 5.79k]
  ------------------
 1730|      0|            if (value == NULL) {
  ------------------
  |  Branch (1730:17): [True: 0, False: 0]
  ------------------
 1731|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1732|      0|                return -1;
 1733|      0|            } else {
 1734|      0|                bool *x = (bool *)value;
 1735|      0|                session->opts.batch_mode = *x;
 1736|      0|            }
 1737|      0|            break;
 1738|      0|        case SSH_OPTIONS_ESCAPE_CHAR:
  ------------------
  |  Branch (1738:9): [True: 0, False: 5.79k]
  ------------------
 1739|      0|            if (value == NULL) {
  ------------------
  |  Branch (1739:17): [True: 0, False: 0]
  ------------------
 1740|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1741|      0|                return -1;
 1742|      0|            } else {
 1743|      0|                int *x = (int *)value;
 1744|      0|                if (*x == 0 || *x < -1 || *x > 255) {
  ------------------
  |  Branch (1744:21): [True: 0, False: 0]
  |  Branch (1744:32): [True: 0, False: 0]
  |  Branch (1744:43): [True: 0, False: 0]
  ------------------
 1745|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1746|      0|                    return -1;
 1747|      0|                }
 1748|      0|                session->opts.escape_char = *x;
 1749|      0|            }
 1750|      0|            break;
 1751|      0|        case SSH_OPTIONS_LOCAL_FORWARD:
  ------------------
  |  Branch (1751:9): [True: 0, False: 5.79k]
  ------------------
 1752|      0|            v = value;
 1753|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1753:17): [True: 0, False: 0]
  |  Branch (1753:30): [True: 0, False: 0]
  ------------------
 1754|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1755|      0|                return -1;
 1756|      0|            }
 1757|      0|            q = strdup(v);
 1758|      0|            if (q == NULL) {
  ------------------
  |  Branch (1758:17): [True: 0, False: 0]
  ------------------
 1759|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1760|      0|                return -1;
 1761|      0|            }
 1762|      0|            rc = ssh_list_append(session->opts.local_forward, q);
 1763|      0|            if (rc < 0) {
  ------------------
  |  Branch (1763:17): [True: 0, False: 0]
  ------------------
 1764|      0|                free(q);
 1765|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1766|      0|                return -1;
 1767|      0|            }
 1768|      0|            break;
 1769|      0|        case SSH_OPTIONS_PREFERRED_AUTHENTICATIONS:
  ------------------
  |  Branch (1769:9): [True: 0, False: 5.79k]
  ------------------
 1770|      0|            v = value;
 1771|      0|            SAFE_FREE(session->opts.preferred_authentications);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1772|      0|            if (v != NULL) {
  ------------------
  |  Branch (1772:17): [True: 0, False: 0]
  ------------------
 1773|      0|                if (v[0] == '\0') {
  ------------------
  |  Branch (1773:21): [True: 0, False: 0]
  ------------------
 1774|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1775|      0|                    return -1;
 1776|      0|                }
 1777|      0|                session->opts.preferred_authentications = strdup(v);
 1778|      0|                if (session->opts.preferred_authentications == NULL) {
  ------------------
  |  Branch (1778:21): [True: 0, False: 0]
  ------------------
 1779|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1780|      0|                    return -1;
 1781|      0|                }
 1782|      0|            }
 1783|      0|            break;
 1784|      0|        case SSH_OPTIONS_NUMBER_OF_PASSWORD_PROMPTS:
  ------------------
  |  Branch (1784:9): [True: 0, False: 5.79k]
  ------------------
 1785|      0|            if (value == NULL) {
  ------------------
  |  Branch (1785:17): [True: 0, False: 0]
  ------------------
 1786|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1787|      0|                return -1;
 1788|      0|            } else {
 1789|      0|                int *x = (int *)value;
 1790|      0|                if (*x <= 0) {
  ------------------
  |  Branch (1790:21): [True: 0, False: 0]
  ------------------
 1791|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1792|      0|                    return -1;
 1793|      0|                }
 1794|      0|                session->opts.number_of_password_prompts = *x;
 1795|      0|            }
 1796|      0|            break;
 1797|      0|        case SSH_OPTIONS_REQUEST_TTY:
  ------------------
  |  Branch (1797:9): [True: 0, False: 5.79k]
  ------------------
 1798|      0|            if (value == NULL) {
  ------------------
  |  Branch (1798:17): [True: 0, False: 0]
  ------------------
 1799|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1800|      0|                return -1;
 1801|      0|            } else {
 1802|      0|                int *x = (int *)value;
 1803|      0|                if (*x < SSH_REQUEST_TTY_NO || *x > SSH_REQUEST_TTY_FORCE) {
  ------------------
  |  Branch (1803:21): [True: 0, False: 0]
  |  Branch (1803:48): [True: 0, False: 0]
  ------------------
 1804|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1805|      0|                    return -1;
 1806|      0|                }
 1807|      0|                session->opts.request_tty = *x;
 1808|      0|            }
 1809|      0|            break;
 1810|      0|        case SSH_OPTIONS_SEND_ENV:
  ------------------
  |  Branch (1810:9): [True: 0, False: 5.79k]
  ------------------
 1811|      0|            v = value;
 1812|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1812:17): [True: 0, False: 0]
  |  Branch (1812:30): [True: 0, False: 0]
  ------------------
 1813|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1814|      0|                return -1;
 1815|      0|            }
 1816|       |            /* A leading '-' removes the pattern from the list */
 1817|      0|            if (v[0] == '-') {
  ------------------
  |  Branch (1817:17): [True: 0, False: 0]
  ------------------
 1818|      0|                const char *pattern = NULL;
 1819|      0|                const char *env_value = NULL;
 1820|      0|                struct ssh_iterator *it = NULL;
 1821|      0|                struct ssh_iterator *next = NULL;
 1822|      0|                int cmp = 0;
 1823|       |
 1824|      0|                pattern = v + 1;
 1825|      0|                if (pattern[0] == '\0') {
  ------------------
  |  Branch (1825:21): [True: 0, False: 0]
  ------------------
 1826|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1827|      0|                    return -1;
 1828|      0|                }
 1829|      0|                it = ssh_list_get_iterator(session->opts.send_env);
 1830|      0|                while (it != NULL) {
  ------------------
  |  Branch (1830:24): [True: 0, False: 0]
  ------------------
 1831|      0|                    env_value = ssh_iterator_value(const char *, it);
  ------------------
  |  |  114|      0|  ((type)((iterator)->data))
  ------------------
 1832|      0|                    cmp = strcmp(env_value, pattern);
 1833|      0|                    next = it->next;
 1834|      0|                    if (cmp == 0) {
  ------------------
  |  Branch (1834:25): [True: 0, False: 0]
  ------------------
 1835|      0|                        free((void *)env_value);
 1836|      0|                        ssh_list_remove(session->opts.send_env, it);
 1837|      0|                    }
 1838|      0|                    it = next;
 1839|      0|                }
 1840|      0|                rc = SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 1841|      0|            } else {
 1842|      0|                q = strdup(v);
 1843|      0|                if (q == NULL) {
  ------------------
  |  Branch (1843:21): [True: 0, False: 0]
  ------------------
 1844|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1845|      0|                    return -1;
 1846|      0|                }
 1847|      0|                rc = ssh_list_append(session->opts.send_env, q);
 1848|      0|                if (rc < 0) {
  ------------------
  |  Branch (1848:21): [True: 0, False: 0]
  ------------------
 1849|      0|                    free(q);
 1850|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1851|      0|                    return -1;
 1852|      0|                }
 1853|      0|            }
 1854|      0|            break;
 1855|      0|        default:
  ------------------
  |  Branch (1855:9): [True: 0, False: 5.79k]
  ------------------
 1856|      0|            ssh_set_error(session, SSH_REQUEST_DENIED, "Unknown ssh option %d", type);
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1857|      0|            return -1;
 1858|      0|            break;
 1859|  5.79k|    }
 1860|       |
 1861|  5.79k|    return 0;
 1862|  5.79k|}
ssh_options_apply:
 2620|    579|{
 2621|    579|    char *tmp = NULL;
 2622|    579|    int rc;
 2623|       |
 2624|    579|    if (session->opts.host != NULL) {
  ------------------
  |  Branch (2624:9): [True: 579, False: 0]
  ------------------
 2625|    579|        char *normalized_host = NULL;
 2626|    579|        rc = ssh_normalize_loose_ip(session->opts.host, &normalized_host);
 2627|    579|        if (rc == -1) {
  ------------------
  |  Branch (2627:13): [True: 0, False: 579]
  ------------------
 2628|       |            /* Error (e.g. NULL input or OOM) — leave host as it is */
 2629|    579|        } else if (rc == 0) {
  ------------------
  |  Branch (2629:20): [True: 0, False: 579]
  ------------------
 2630|       |            /* Was a loose IP — use the normalized dotted-quad form */
 2631|      0|            SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2632|      0|            session->opts.host = normalized_host;
 2633|    579|        } else {
 2634|       |            /* rc == 1: not a loose IP — lowercase if it's not a strict IP */
 2635|    579|            bool is_ip = ssh_is_ipaddr(session->opts.host);
 2636|    579|            if (!is_ip) {
  ------------------
  |  Branch (2636:17): [True: 0, False: 579]
  ------------------
 2637|      0|                char *lower = ssh_lowercase(session->opts.host);
 2638|      0|                if (lower != NULL) {
  ------------------
  |  Branch (2638:21): [True: 0, False: 0]
  ------------------
 2639|      0|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2640|      0|                    session->opts.host = lower;
 2641|      0|                }
 2642|      0|            }
 2643|    579|        }
 2644|    579|    }
 2645|       |
 2646|    579|    if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (2646:9): [True: 579, False: 0]
  ------------------
 2647|    579|        rc = ssh_options_set(session, SSH_OPTIONS_SSH_DIR, NULL);
 2648|    579|        if (rc < 0) {
  ------------------
  |  Branch (2648:13): [True: 0, False: 579]
  ------------------
 2649|      0|            return -1;
 2650|      0|        }
 2651|    579|    }
 2652|       |
 2653|    579|    if (session->opts.username == NULL) {
  ------------------
  |  Branch (2653:9): [True: 0, False: 579]
  ------------------
 2654|      0|        rc = ssh_options_set(session, SSH_OPTIONS_USER, NULL);
 2655|      0|        if (rc < 0) {
  ------------------
  |  Branch (2655:13): [True: 0, False: 0]
  ------------------
 2656|      0|            return -1;
 2657|      0|        }
 2658|      0|    }
 2659|       |
 2660|    579|    if (session->opts.config_hostname != NULL) {
  ------------------
  |  Branch (2660:9): [True: 0, False: 579]
  ------------------
 2661|      0|        char *saved_host = NULL;
 2662|       |
 2663|      0|        tmp = ssh_path_expand_hostname(session, session->opts.config_hostname);
 2664|      0|        if (tmp == NULL) {
  ------------------
  |  Branch (2664:13): [True: 0, False: 0]
  ------------------
 2665|      0|            return -1;
 2666|      0|        }
 2667|      0|        if (session->opts.host != NULL) {
  ------------------
  |  Branch (2667:13): [True: 0, False: 0]
  ------------------
 2668|      0|            saved_host = strdup(session->opts.host);
 2669|      0|            if (saved_host == NULL) {
  ------------------
  |  Branch (2669:17): [True: 0, False: 0]
  ------------------
 2670|      0|                free(tmp);
 2671|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2672|      0|                return -1;
 2673|      0|            }
 2674|      0|        }
 2675|      0|        session->opts.config_hostname_only = true;
 2676|      0|        rc = ssh_options_set(session, SSH_OPTIONS_HOST, tmp);
 2677|      0|        session->opts.config_hostname_only = false;
 2678|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2678:13): [True: 0, False: 0]
  ------------------
 2679|       |            /* If HostName expansion leaves a literal '%', keep the current
 2680|       |             * host instead of treating the deferred HostName as fatal.
 2681|       |             */
 2682|      0|            if (strchr(tmp, '%') == NULL) {
  ------------------
  |  Branch (2682:17): [True: 0, False: 0]
  ------------------
 2683|      0|                SAFE_FREE(saved_host);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2684|      0|                free(tmp);
 2685|      0|                return -1;
 2686|      0|            }
 2687|      0|            SSH_LOG(SSH_LOG_WARN,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2688|      0|                    "HostName %s contains unknown expansion tokens and could "
 2689|      0|                    "not be applied; falling back to current host",
 2690|      0|                    tmp);
 2691|      0|            SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2692|      0|            session->opts.host = saved_host;
 2693|      0|            saved_host = NULL;
 2694|      0|        }
 2695|      0|        SAFE_FREE(saved_host);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2696|      0|        free(tmp);
 2697|      0|        SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2698|      0|    }
 2699|       |
 2700|    579|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_KNOWNHOSTS) == 0) {
  ------------------
  |  |  115|    579|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
  |  Branch (2700:9): [True: 579, False: 0]
  ------------------
 2701|    579|        if (session->opts.knownhosts == NULL) {
  ------------------
  |  Branch (2701:13): [True: 579, False: 0]
  ------------------
 2702|    579|            tmp = ssh_path_expand_escape(session, "%d/.ssh/known_hosts");
 2703|    579|        } else {
 2704|      0|            tmp = ssh_path_expand_escape(session, session->opts.knownhosts);
 2705|      0|        }
 2706|    579|        if (tmp == NULL) {
  ------------------
  |  Branch (2706:13): [True: 0, False: 579]
  ------------------
 2707|      0|            return -1;
 2708|      0|        }
 2709|    579|        free(session->opts.knownhosts);
 2710|    579|        session->opts.knownhosts = tmp;
 2711|    579|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_KNOWNHOSTS;
  ------------------
  |  |  115|    579|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
 2712|    579|    }
 2713|       |
 2714|    579|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS) == 0) {
  ------------------
  |  |  116|    579|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
  |  Branch (2714:9): [True: 579, False: 0]
  ------------------
 2715|    579|        if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (2715:13): [True: 579, False: 0]
  ------------------
 2716|    579|            tmp = strdup(GLOBAL_CONF_DIR "/ssh_known_hosts");
  ------------------
  |  |   13|    579|#define GLOBAL_CONF_DIR "/etc/ssh"
  ------------------
 2717|    579|        } else {
 2718|      0|            tmp = ssh_path_expand_escape(session,
 2719|      0|                                         session->opts.global_knownhosts);
 2720|      0|        }
 2721|    579|        if (tmp == NULL) {
  ------------------
  |  Branch (2721:13): [True: 0, False: 579]
  ------------------
 2722|      0|            return -1;
 2723|      0|        }
 2724|    579|        free(session->opts.global_knownhosts);
 2725|    579|        session->opts.global_knownhosts = tmp;
 2726|    579|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS;
  ------------------
  |  |  116|    579|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
 2727|    579|    }
 2728|       |
 2729|       |
 2730|    579|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_PROXYCOMMAND) == 0) {
  ------------------
  |  |  117|    579|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
  |  Branch (2730:9): [True: 579, False: 0]
  ------------------
 2731|    579|        if (session->opts.ProxyCommand != NULL) {
  ------------------
  |  Branch (2731:13): [True: 0, False: 579]
  ------------------
 2732|      0|            char *p = NULL;
 2733|      0|            size_t plen = strlen(session->opts.ProxyCommand) +
 2734|      0|                          5 /* strlen("exec ") */;
 2735|       |
 2736|      0|            if (strncmp(session->opts.ProxyCommand, "exec ", 5) != 0) {
  ------------------
  |  Branch (2736:17): [True: 0, False: 0]
  ------------------
 2737|      0|                p = malloc(plen + 1 /* \0 */);
 2738|      0|                if (p == NULL) {
  ------------------
  |  Branch (2738:21): [True: 0, False: 0]
  ------------------
 2739|      0|                    return -1;
 2740|      0|                }
 2741|       |
 2742|      0|                rc = snprintf(p, plen + 1, "exec %s", session->opts.ProxyCommand);
 2743|      0|                if ((size_t)rc != plen) {
  ------------------
  |  Branch (2743:21): [True: 0, False: 0]
  ------------------
 2744|      0|                    free(p);
 2745|      0|                    return -1;
 2746|      0|                }
 2747|      0|                tmp = ssh_path_expand_escape(session, p);
 2748|      0|                free(p);
 2749|      0|            } else {
 2750|      0|                tmp = ssh_path_expand_escape(session,
 2751|      0|                                             session->opts.ProxyCommand);
 2752|      0|            }
 2753|       |
 2754|      0|            if (tmp == NULL) {
  ------------------
  |  Branch (2754:17): [True: 0, False: 0]
  ------------------
 2755|      0|                return -1;
 2756|      0|            }
 2757|      0|            free(session->opts.ProxyCommand);
 2758|      0|            session->opts.ProxyCommand = tmp;
 2759|      0|            session->opts.exp_flags |= SSH_OPT_EXP_FLAG_PROXYCOMMAND;
  ------------------
  |  |  117|      0|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
 2760|      0|        }
 2761|    579|    }
 2762|       |
 2763|    579|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_CONTROL_PATH) == 0) {
  ------------------
  |  |  119|    579|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
  |  Branch (2763:9): [True: 579, False: 0]
  ------------------
 2764|    579|        if (session->opts.control_path != NULL) {
  ------------------
  |  Branch (2764:13): [True: 0, False: 579]
  ------------------
 2765|      0|            tmp = ssh_path_expand_escape(session, session->opts.control_path);
 2766|      0|            if (tmp == NULL) {
  ------------------
  |  Branch (2766:17): [True: 0, False: 0]
  ------------------
 2767|      0|                return -1;
 2768|      0|            }
 2769|      0|            free(session->opts.control_path);
 2770|      0|            session->opts.control_path = tmp;
 2771|      0|            session->opts.exp_flags |= SSH_OPT_EXP_FLAG_CONTROL_PATH;
  ------------------
  |  |  119|      0|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
 2772|      0|        }
 2773|    579|    }
 2774|       |
 2775|    579|    for (tmp = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  122|    579|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2776|  2.31k|         tmp != NULL;
  ------------------
  |  Branch (2776:10): [True: 1.73k, False: 579]
  ------------------
 2777|  1.73k|         tmp = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  122|  1.73k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2778|  1.73k|        char *id = tmp;
 2779|  1.73k|        if (strncmp(id, "pkcs11:", 6) != 0) {
  ------------------
  |  Branch (2779:13): [True: 1.73k, False: 0]
  ------------------
 2780|       |            /* PKCS#11 URIs are using percent-encoding so we can not mix
 2781|       |             * it with ssh expansion of ssh escape characters.
 2782|       |             */
 2783|  1.73k|            tmp = ssh_path_expand_escape(session, id);
 2784|  1.73k|            free(id);
 2785|  1.73k|            if (tmp == NULL) {
  ------------------
  |  Branch (2785:17): [True: 0, False: 1.73k]
  ------------------
 2786|      0|                return -1;
 2787|      0|            }
 2788|  1.73k|        }
 2789|       |
 2790|       |        /* use append to keep the order at first call and use prepend
 2791|       |         * to put anything that comes on the nth calls to the beginning */
 2792|  1.73k|        if (session->opts.exp_flags & SSH_OPT_EXP_FLAG_IDENTITY) {
  ------------------
  |  |  118|  1.73k|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
  |  Branch (2792:13): [True: 0, False: 1.73k]
  ------------------
 2793|      0|            rc = ssh_list_prepend(session->opts.identity, tmp);
 2794|  1.73k|        } else {
 2795|  1.73k|            rc = ssh_list_append(session->opts.identity, tmp);
 2796|  1.73k|        }
 2797|  1.73k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.73k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2797:13): [True: 0, False: 1.73k]
  ------------------
 2798|      0|            free(tmp);
 2799|      0|            return -1;
 2800|      0|        }
 2801|  1.73k|    }
 2802|    579|    session->opts.exp_flags |= SSH_OPT_EXP_FLAG_IDENTITY;
  ------------------
  |  |  118|    579|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
 2803|       |
 2804|    579|    for (tmp = ssh_list_pop_head(char *, session->opts.certificate_non_exp);
  ------------------
  |  |  122|    579|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2805|    579|         tmp != NULL;
  ------------------
  |  Branch (2805:10): [True: 0, False: 579]
  ------------------
 2806|    579|         tmp = ssh_list_pop_head(char *, session->opts.certificate_non_exp)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2807|      0|        char *id = tmp;
 2808|       |
 2809|      0|        tmp = ssh_path_expand_escape(session, id);
 2810|      0|        free(id);
 2811|      0|        if (tmp == NULL) {
  ------------------
  |  Branch (2811:13): [True: 0, False: 0]
  ------------------
 2812|      0|            return -1;
 2813|      0|        }
 2814|       |
 2815|      0|        rc = ssh_list_append(session->opts.certificate, tmp);
 2816|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2816:13): [True: 0, False: 0]
  ------------------
 2817|      0|            free(tmp);
 2818|      0|            return -1;
 2819|      0|        }
 2820|      0|    }
 2821|       |
 2822|       |#ifdef WITH_GSSAPI
 2823|       |    if (session->opts.gssapi_key_exchange) {
 2824|       |        rc = ssh_gssapi_check_client_config(session);
 2825|       |        if (rc != SSH_OK) {
 2826|       |            SSH_LOG(SSH_LOG_WARN, "Disabled GSSAPI key exchange");
 2827|       |            session->opts.gssapi_key_exchange = false;
 2828|       |        }
 2829|       |    }
 2830|       |#endif
 2831|       |
 2832|    579|    return 0;
 2833|    579|}

ssh_packet_get_current_crypto:
 1159|   264k|{
 1160|   264k|    struct ssh_crypto_struct *crypto = NULL;
 1161|       |
 1162|   264k|    if (session == NULL) {
  ------------------
  |  Branch (1162:9): [True: 0, False: 264k]
  ------------------
 1163|      0|        return NULL;
 1164|      0|    }
 1165|       |
 1166|   264k|    if (session->current_crypto != NULL &&
  ------------------
  |  Branch (1166:9): [True: 0, False: 264k]
  ------------------
 1167|      0|        session->current_crypto->used & direction) {
  ------------------
  |  Branch (1167:9): [True: 0, False: 0]
  ------------------
 1168|      0|        crypto = session->current_crypto;
 1169|   264k|    } else if (session->next_crypto != NULL &&
  ------------------
  |  Branch (1169:16): [True: 264k, False: 0]
  ------------------
 1170|   264k|               session->next_crypto->used & direction) {
  ------------------
  |  Branch (1170:16): [True: 10.2k, False: 254k]
  ------------------
 1171|  10.2k|        crypto = session->next_crypto;
 1172|   254k|    } else {
 1173|   254k|        return NULL;
 1174|   254k|    }
 1175|       |
 1176|  10.2k|    switch (direction) {
  ------------------
  |  Branch (1176:13): [True: 10.2k, False: 0]
  ------------------
 1177|      0|    case SSH_DIRECTION_IN:
  ------------------
  |  Branch (1177:5): [True: 0, False: 10.2k]
  ------------------
 1178|      0|        if (crypto->in_cipher != NULL) {
  ------------------
  |  Branch (1178:13): [True: 0, False: 0]
  ------------------
 1179|      0|            return crypto;
 1180|      0|        }
 1181|      0|        break;
 1182|  10.2k|    case SSH_DIRECTION_OUT:
  ------------------
  |  Branch (1182:5): [True: 10.2k, False: 0]
  ------------------
 1183|  10.2k|        if (crypto->out_cipher != NULL) {
  ------------------
  |  Branch (1183:13): [True: 10.2k, False: 0]
  ------------------
 1184|  10.2k|            return crypto;
 1185|  10.2k|        }
 1186|      0|        break;
 1187|      0|    case SSH_DIRECTION_BOTH:
  ------------------
  |  Branch (1187:5): [True: 0, False: 10.2k]
  ------------------
 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|  10.2k|    }
 1193|       |
 1194|      0|    return NULL;
 1195|  10.2k|}
ssh_packet_socket_callback:
 1286|  83.8k|{
 1287|  83.8k|    ssh_session session = (ssh_session)user;
 1288|  83.8k|    uint32_t blocksize = 8;
 1289|  83.8k|    uint32_t lenfield_blocksize = 8;
 1290|  83.8k|    size_t current_macsize = 0;
 1291|  83.8k|    uint8_t *ptr = NULL;
 1292|  83.8k|    ssize_t to_be_read;
 1293|  83.8k|    int rc;
 1294|  83.8k|    uint8_t *cleartext_packet = NULL;
 1295|  83.8k|    uint8_t *packet_second_block = NULL;
 1296|  83.8k|    uint8_t *mac = NULL;
 1297|  83.8k|    size_t packet_remaining, packet_offset;
 1298|  83.8k|    uint32_t packet_len, compsize, payloadsize;
 1299|  83.8k|    uint8_t padding;
 1300|  83.8k|    size_t processed = 0; /* number of bytes processed from the callback */
 1301|  83.8k|    enum ssh_packet_filter_result_e filter_result;
 1302|  83.8k|    struct ssh_crypto_struct *crypto = NULL;
 1303|  83.8k|    bool etm = false;
 1304|  83.8k|    uint32_t etm_packet_offset = 0;
 1305|  83.8k|    bool ok;
 1306|       |
 1307|  83.8k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
 1308|  83.8k|    if (crypto != NULL) {
  ------------------
  |  Branch (1308:9): [True: 0, False: 83.8k]
  ------------------
 1309|      0|        current_macsize = hmac_digest_len(crypto->in_hmac);
 1310|      0|        blocksize = crypto->in_cipher->blocksize;
 1311|      0|        lenfield_blocksize = crypto->in_cipher->lenfield_blocksize;
 1312|      0|        etm = crypto->in_hmac_etm;
 1313|      0|    }
 1314|       |
 1315|  83.8k|    if (etm) {
  ------------------
  |  Branch (1315:9): [True: 0, False: 83.8k]
  ------------------
 1316|       |        /* In EtM mode packet size is unencrypted. This means
 1317|       |         * we need to use this offset and set the block size
 1318|       |         * that is part of the encrypted part to 0.
 1319|       |         */
 1320|      0|        etm_packet_offset = sizeof(uint32_t);
 1321|      0|        lenfield_blocksize = 0;
 1322|  83.8k|    } else if (lenfield_blocksize == 0) {
  ------------------
  |  Branch (1322:16): [True: 0, False: 83.8k]
  ------------------
 1323|      0|        lenfield_blocksize = blocksize;
 1324|      0|    }
 1325|  83.8k|    if (data == NULL) {
  ------------------
  |  Branch (1325:9): [True: 0, False: 83.8k]
  ------------------
 1326|      0|        goto error;
 1327|      0|    }
 1328|       |
 1329|  83.8k|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (1329:9): [True: 384, False: 83.4k]
  ------------------
 1330|    384|        goto error;
 1331|    384|    }
 1332|       |#ifdef DEBUG_PACKET
 1333|       |    SSH_LOG(SSH_LOG_PACKET,
 1334|       |            "rcv packet cb (len=%zu, state=%s)",
 1335|       |            receivedlen,
 1336|       |            session->packet_state == PACKET_STATE_INIT ?
 1337|       |                "INIT" :
 1338|       |                session->packet_state == PACKET_STATE_SIZEREAD ?
 1339|       |                    "SIZE_READ" :
 1340|       |                    session->packet_state == PACKET_STATE_PROCESSING ?
 1341|       |                    "PROCESSING" : "unknown");
 1342|       |#endif
 1343|  83.4k|    switch (session->packet_state) {
  ------------------
  |  Branch (1343:13): [True: 83.4k, False: 0]
  ------------------
 1344|  83.0k|        case PACKET_STATE_INIT:
  ------------------
  |  Branch (1344:9): [True: 83.0k, False: 401]
  ------------------
 1345|  83.0k|            if (receivedlen < lenfield_blocksize + etm_packet_offset) {
  ------------------
  |  Branch (1345:17): [True: 219, False: 82.8k]
  ------------------
 1346|       |                /*
 1347|       |                 * We didn't receive enough data to read either at least one
 1348|       |                 * block size or the unencrypted length in EtM mode.
 1349|       |                 */
 1350|       |#ifdef DEBUG_PACKET
 1351|       |                SSH_LOG(SSH_LOG_PACKET,
 1352|       |                        "Waiting for more data (%zu < %u)",
 1353|       |                        receivedlen,
 1354|       |                        lenfield_blocksize);
 1355|       |#endif
 1356|    219|                return 0;
 1357|    219|            }
 1358|       |
 1359|  82.8k|            session->in_packet = (struct packet_struct) {
 1360|  82.8k|                .type = 0,
 1361|  82.8k|            };
 1362|       |
 1363|  82.8k|            if (session->in_buffer) {
  ------------------
  |  Branch (1363:17): [True: 82.8k, False: 0]
  ------------------
 1364|  82.8k|                rc = ssh_buffer_reinit(session->in_buffer);
 1365|  82.8k|                if (rc < 0) {
  ------------------
  |  Branch (1365:21): [True: 0, False: 82.8k]
  ------------------
 1366|      0|                    goto error;
 1367|      0|                }
 1368|  82.8k|            } else {
 1369|      0|                session->in_buffer = ssh_buffer_new();
 1370|      0|                if (session->in_buffer == NULL) {
  ------------------
  |  Branch (1370:21): [True: 0, False: 0]
  ------------------
 1371|      0|                    goto error;
 1372|      0|                }
 1373|      0|            }
 1374|       |
 1375|  82.8k|            if (!etm) {
  ------------------
  |  Branch (1375:17): [True: 82.8k, False: 0]
  ------------------
 1376|  82.8k|                ptr = ssh_buffer_allocate(session->in_buffer,
 1377|  82.8k|                                          lenfield_blocksize);
 1378|  82.8k|                if (ptr == NULL) {
  ------------------
  |  Branch (1378:21): [True: 0, False: 82.8k]
  ------------------
 1379|      0|                    goto error;
 1380|      0|                }
 1381|  82.8k|                packet_len = ssh_packet_decrypt_len(session, ptr,
 1382|  82.8k|                                                    (uint8_t *)data);
 1383|  82.8k|                to_be_read = packet_len - lenfield_blocksize + sizeof(uint32_t);
 1384|  82.8k|            } else {
 1385|       |                /* Length is unencrypted in case of Encrypt-then-MAC */
 1386|      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)]))
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1387|      0|                to_be_read = packet_len - etm_packet_offset;
 1388|      0|            }
 1389|       |
 1390|  82.8k|            processed += lenfield_blocksize + etm_packet_offset;
 1391|  82.8k|            if (packet_len > MAX_PACKET_LEN) {
  ------------------
  |  |  216|  82.8k|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (1391:17): [True: 60, False: 82.8k]
  ------------------
 1392|     60|                ssh_set_error(session,
  ------------------
  |  |  311|     60|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1393|     60|                              SSH_FATAL,
 1394|     60|                              "read_packet(): Packet len too high(%" PRIu32 " %.4" PRIx32 ")",
 1395|     60|                              packet_len, packet_len);
 1396|     60|                goto error;
 1397|     60|            }
 1398|  82.8k|            if (to_be_read < 0) {
  ------------------
  |  Branch (1398:17): [True: 0, False: 82.8k]
  ------------------
 1399|       |                /* remote sshd sends invalid sizes? */
 1400|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1401|      0|                              SSH_FATAL,
 1402|      0|                              "Given numbers of bytes left to be read < 0 (%zd)!",
 1403|      0|                              to_be_read);
 1404|      0|                goto error;
 1405|      0|            }
 1406|       |
 1407|  82.8k|            session->in_packet.len = packet_len;
 1408|  82.8k|            session->packet_state = PACKET_STATE_SIZEREAD;
 1409|  82.8k|            FALL_THROUGH;
  ------------------
  |  |  494|  82.8k|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1410|  83.2k|        case PACKET_STATE_SIZEREAD:
  ------------------
  |  Branch (1410:9): [True: 401, False: 83.0k]
  ------------------
 1411|  83.2k|            packet_len = session->in_packet.len;
 1412|  83.2k|            packet_offset = processed = lenfield_blocksize + etm_packet_offset;
 1413|  83.2k|            to_be_read = packet_len + sizeof(uint32_t) + current_macsize;
 1414|       |            /* if to_be_read is zero, the whole packet was blocksize bytes. */
 1415|  83.2k|            if (to_be_read != 0) {
  ------------------
  |  Branch (1415:17): [True: 83.2k, False: 0]
  ------------------
 1416|  83.2k|                if (receivedlen < (unsigned long)to_be_read) {
  ------------------
  |  Branch (1416:21): [True: 456, False: 82.7k]
  ------------------
 1417|       |                    /* give up, not enough data in buffer */
 1418|    456|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    456|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1419|    456|                            "packet: partial packet (read len) "
 1420|    456|                            "[len=%" PRIu32 ", receivedlen=%zu, to_be_read=%zd]",
 1421|    456|                            packet_len,
 1422|    456|                            receivedlen,
 1423|    456|                            to_be_read);
 1424|    456|                    return 0;
 1425|    456|                }
 1426|       |
 1427|  82.7k|                packet_second_block = (uint8_t*)data + packet_offset;
 1428|  82.7k|                processed = to_be_read - current_macsize;
 1429|  82.7k|            }
 1430|       |
 1431|  82.7k|            if (packet_offset - sizeof(uint32_t) > (size_t)packet_len) {
  ------------------
  |  Branch (1431:17): [True: 6, False: 82.7k]
  ------------------
 1432|      6|                ssh_set_error(session,
  ------------------
  |  |  311|      6|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1433|      6|                              SSH_FATAL,
 1434|      6|                              "Invalid packet length %" PRIu32 ", required %zu",
 1435|      6|                              packet_len,
 1436|      6|                              packet_offset + sizeof(uint32_t));
 1437|      6|                goto error;
 1438|      6|            }
 1439|       |
 1440|       |            /* remaining encrypted bytes from the packet, MAC not included */
 1441|  82.7k|            packet_remaining = packet_len - (packet_offset - sizeof(uint32_t));
 1442|  82.7k|            cleartext_packet = ssh_buffer_allocate(session->in_buffer,
 1443|  82.7k|                                                   (uint32_t)packet_remaining);
 1444|  82.7k|            if (cleartext_packet == NULL) {
  ------------------
  |  Branch (1444:17): [True: 0, False: 82.7k]
  ------------------
 1445|      0|                goto error;
 1446|      0|            }
 1447|       |
 1448|  82.7k|            if (packet_second_block != NULL) {
  ------------------
  |  Branch (1448:17): [True: 82.7k, False: 0]
  ------------------
 1449|  82.7k|                if (crypto != NULL) {
  ------------------
  |  Branch (1449:21): [True: 0, False: 82.7k]
  ------------------
 1450|      0|                    mac = packet_second_block + packet_remaining;
 1451|       |
 1452|      0|                    if (crypto->in_hmac != SSH_HMAC_NONE && etm) {
  ------------------
  |  Branch (1452:25): [True: 0, False: 0]
  |  Branch (1452:61): [True: 0, False: 0]
  ------------------
 1453|      0|                        rc = ssh_packet_hmac_verify(session,
 1454|      0|                                                    data,
 1455|      0|                                                    processed,
 1456|      0|                                                    mac,
 1457|      0|                                                    crypto->in_hmac);
 1458|      0|                        if (rc < 0) {
  ------------------
  |  Branch (1458:29): [True: 0, False: 0]
  ------------------
 1459|      0|                            ssh_set_error(session, SSH_FATAL, "HMAC error");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1460|      0|                            goto error;
 1461|      0|                        }
 1462|      0|                    }
 1463|       |                    /*
 1464|       |                     * Decrypt the packet. In case of EtM mode, the length is
 1465|       |                     * already known as it's unencrypted. In the other case,
 1466|       |                     * lenfield_blocksize bytes already have been decrypted.
 1467|       |                     */
 1468|      0|                    if (packet_remaining > 0) {
  ------------------
  |  Branch (1468:25): [True: 0, False: 0]
  ------------------
 1469|      0|                        rc = ssh_packet_decrypt(session,
 1470|      0|                                                cleartext_packet,
 1471|      0|                                                (uint8_t *)data,
 1472|      0|                                                packet_offset,
 1473|      0|                                                processed - packet_offset);
 1474|      0|                        if (rc < 0) {
  ------------------
  |  Branch (1474:29): [True: 0, False: 0]
  ------------------
 1475|      0|                            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1476|      0|                                          SSH_FATAL,
 1477|      0|                                          "Decryption error");
 1478|      0|                            goto error;
 1479|      0|                        }
 1480|      0|                    }
 1481|       |
 1482|      0|                    if (crypto->in_hmac != SSH_HMAC_NONE && !etm) {
  ------------------
  |  Branch (1482:25): [True: 0, False: 0]
  |  Branch (1482:61): [True: 0, False: 0]
  ------------------
 1483|      0|                        ssh_buffer in = session->in_buffer;
 1484|      0|                        rc = ssh_packet_hmac_verify(session,
 1485|      0|                                                    ssh_buffer_get(in),
 1486|      0|                                                    ssh_buffer_get_len(in),
 1487|      0|                                                    mac,
 1488|      0|                                                    crypto->in_hmac);
 1489|      0|                        if (rc < 0) {
  ------------------
  |  Branch (1489:29): [True: 0, False: 0]
  ------------------
 1490|      0|                            ssh_set_error(session, SSH_FATAL, "HMAC error");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1491|      0|                            goto error;
 1492|      0|                        }
 1493|      0|                    }
 1494|      0|                    processed += current_macsize;
 1495|  82.7k|                } else {
 1496|  82.7k|                    memcpy(cleartext_packet,
 1497|  82.7k|                           packet_second_block,
 1498|  82.7k|                           packet_remaining);
 1499|  82.7k|                }
 1500|  82.7k|            }
 1501|       |
 1502|  82.7k|#ifdef WITH_PCAP
 1503|  82.7k|            if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1503:17): [True: 0, False: 82.7k]
  ------------------
 1504|      0|                ssh_pcap_context_write(session->pcap_ctx,
 1505|      0|                                       SSH_PCAP_DIR_IN,
 1506|      0|                                       ssh_buffer_get(session->in_buffer),
 1507|      0|                                       ssh_buffer_get_len(session->in_buffer),
 1508|      0|                                       ssh_buffer_get_len(session->in_buffer));
 1509|      0|            }
 1510|  82.7k|#endif
 1511|       |
 1512|  82.7k|            if (!etm) {
  ------------------
  |  Branch (1512:17): [True: 82.7k, False: 0]
  ------------------
 1513|       |                /* skip the size field which has been processed before */
 1514|  82.7k|                ssh_buffer_pass_bytes(session->in_buffer, sizeof(uint32_t));
 1515|  82.7k|            }
 1516|       |
 1517|  82.7k|            rc = ssh_buffer_get_u8(session->in_buffer, &padding);
 1518|  82.7k|            if (rc == 0) {
  ------------------
  |  Branch (1518:17): [True: 0, False: 82.7k]
  ------------------
 1519|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1520|      0|                              SSH_FATAL,
 1521|      0|                              "Packet too short to read padding");
 1522|      0|                goto error;
 1523|      0|            }
 1524|       |
 1525|  82.7k|            if (padding > ssh_buffer_get_len(session->in_buffer)) {
  ------------------
  |  Branch (1525:17): [True: 3, False: 82.7k]
  ------------------
 1526|      3|                ssh_set_error(session,
  ------------------
  |  |  311|      3|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1527|      3|                              SSH_FATAL,
 1528|      3|                              "Invalid padding: %d (%" PRIu32 " left)",
 1529|      3|                              padding,
 1530|      3|                              ssh_buffer_get_len(session->in_buffer));
 1531|      3|                goto error;
 1532|      3|            }
 1533|  82.7k|            ssh_buffer_pass_bytes_end(session->in_buffer, padding);
 1534|  82.7k|            compsize = ssh_buffer_get_len(session->in_buffer);
 1535|       |
 1536|  82.7k|            if (crypto && crypto->do_compress_in &&
  ------------------
  |  Branch (1536:17): [True: 0, False: 82.7k]
  |  Branch (1536:27): [True: 0, False: 0]
  ------------------
 1537|      0|                ssh_buffer_get_len(session->in_buffer) > 0) {
  ------------------
  |  Branch (1537:17): [True: 0, False: 0]
  ------------------
 1538|      0|                rc = decompress_buffer(session, session->in_buffer,
 1539|      0|                                       MAX_PACKET_LEN);
  ------------------
  |  |  216|      0|#define MAX_PACKET_LEN 262144
  ------------------
 1540|      0|                if (rc < 0) {
  ------------------
  |  Branch (1540:21): [True: 0, False: 0]
  ------------------
 1541|      0|                    goto error;
 1542|      0|                }
 1543|      0|            }
 1544|  82.7k|            payloadsize = ssh_buffer_get_len(session->in_buffer);
 1545|  82.7k|            if (session->recv_seq == UINT32_MAX) {
  ------------------
  |  Branch (1545:17): [True: 0, False: 82.7k]
  ------------------
 1546|       |                /* Overflowing sequence numbers is always fishy */
 1547|      0|                if (crypto == NULL) {
  ------------------
  |  Branch (1547:21): [True: 0, False: 0]
  ------------------
 1548|       |                    /* don't allow sequence number overflow when unencrypted */
 1549|      0|                    ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1550|      0|                                  SSH_FATAL,
 1551|      0|                                  "Incoming sequence number overflow");
 1552|      0|                    goto error;
 1553|      0|                } else {
 1554|      0|                    SSH_LOG(SSH_LOG_WARNING,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1555|      0|                            "Incoming sequence number overflow");
 1556|      0|                }
 1557|      0|            }
 1558|  82.7k|            session->recv_seq++;
 1559|  82.7k|            if (crypto != NULL) {
  ------------------
  |  Branch (1559:17): [True: 0, False: 82.7k]
  ------------------
 1560|      0|                struct ssh_cipher_struct *cipher = NULL;
 1561|       |
 1562|      0|                cipher = crypto->in_cipher;
 1563|      0|                cipher->packets++;
 1564|      0|                cipher->blocks += payloadsize / cipher->blocksize;
 1565|      0|            }
 1566|  82.7k|            if (session->raw_counter != NULL) {
  ------------------
  |  Branch (1566:17): [True: 0, False: 82.7k]
  ------------------
 1567|      0|                session->raw_counter->in_bytes += payloadsize;
 1568|      0|                session->raw_counter->in_packets++;
 1569|      0|            }
 1570|       |
 1571|       |            /*
 1572|       |             * We don't want to rewrite a new packet while still executing the
 1573|       |             * packet callbacks
 1574|       |             */
 1575|  82.7k|            session->packet_state = PACKET_STATE_PROCESSING;
 1576|  82.7k|            ssh_packet_parse_type(session);
 1577|  82.7k|            SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  82.7k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1578|  82.7k|                    "packet: read type %hhd [len=%" PRIu32 ",padding=%hhd,"
 1579|  82.7k|                    "comp=%" PRIu32 ",payload=%" PRIu32 "]",
 1580|  82.7k|                    session->in_packet.type, packet_len, padding, compsize,
 1581|  82.7k|                    payloadsize);
 1582|  82.7k|            if (crypto == NULL) {
  ------------------
  |  Branch (1582:17): [True: 82.7k, False: 0]
  ------------------
 1583|       |                /* In strict kex, only a few packets are allowed. Taint the session
 1584|       |                 * if we received packets that are normally allowed but to be
 1585|       |                 * refused if we are in strict kex when KEX is over.
 1586|       |                 */
 1587|  82.7k|                uint8_t type = session->in_packet.type;
 1588|       |
 1589|  82.7k|                if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   12|   165k|#define SSH2_MSG_KEXINIT	 20
  ------------------
                              if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   13|   165k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (1589:21): [True: 82.3k, False: 370]
  |  Branch (1589:49): [True: 82.3k, False: 63]
  ------------------
 1590|  82.3k|                    (type < SSH2_MSG_KEXDH_INIT ||
  ------------------
  |  |   15|   164k|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (1590:22): [True: 55.3k, False: 26.9k]
  ------------------
 1591|  81.3k|                     type > SSH2_MSG_KEX_DH_GEX_REQUEST)) {
  ------------------
  |  |   26|  26.9k|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (1591:22): [True: 26.0k, False: 956]
  ------------------
 1592|  81.3k|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|  81.3k|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1593|  81.3k|                }
 1594|  82.7k|            }
 1595|       |            /* Check if the packet is expected */
 1596|  82.7k|            filter_result = ssh_packet_incoming_filter(session);
 1597|       |
 1598|  82.7k|            switch (filter_result) {
  ------------------
  |  Branch (1598:21): [True: 82.7k, False: 0]
  ------------------
 1599|  36.0k|            case SSH_PACKET_ALLOWED:
  ------------------
  |  Branch (1599:13): [True: 36.0k, False: 46.6k]
  ------------------
 1600|       |                /* Execute callbacks */
 1601|  36.0k|                ssh_packet_process(session, session->in_packet.type);
 1602|  36.0k|                break;
 1603|     34|            case SSH_PACKET_DENIED:
  ------------------
  |  Branch (1603:13): [True: 34, False: 82.7k]
  ------------------
 1604|     34|                ssh_set_error(session,
  ------------------
  |  |  311|     34|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1605|     34|                              SSH_FATAL,
 1606|     34|                              "Packet filter: rejected packet (type %d)",
 1607|     34|                              session->in_packet.type);
 1608|     34|                goto error;
 1609|  46.6k|            case SSH_PACKET_UNKNOWN:
  ------------------
  |  Branch (1609:13): [True: 46.6k, False: 36.1k]
  ------------------
 1610|  46.6k|                if (crypto == NULL) {
  ------------------
  |  Branch (1610:21): [True: 46.6k, False: 0]
  ------------------
 1611|  46.6k|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|  46.6k|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1612|  46.6k|                }
 1613|  46.6k|                ssh_packet_send_unimplemented(session, session->recv_seq - 1);
 1614|  46.6k|                break;
 1615|  82.7k|            }
 1616|       |
 1617|  82.7k|            session->packet_state = PACKET_STATE_INIT;
 1618|  82.7k|            if (processed < receivedlen) {
  ------------------
  |  Branch (1618:17): [True: 82.6k, False: 114]
  ------------------
 1619|  82.6k|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  82.6k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1620|  82.6k|                        "packet: %zu bytes still remaining in socket buffer "
 1621|  82.6k|                        "after processing",
 1622|  82.6k|                        receivedlen-processed);
 1623|  82.6k|            }
 1624|       |
 1625|  82.7k|            ok = ssh_packet_need_rekey(session, 0);
 1626|  82.7k|            if (ok) {
  ------------------
  |  Branch (1626:17): [True: 0, False: 82.7k]
  ------------------
 1627|      0|                SSH_LOG(SSH_LOG_PACKET, "Incoming packet triggered rekey");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1628|      0|                rc = ssh_send_rekex(session);
 1629|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1629:21): [True: 0, False: 0]
  ------------------
 1630|      0|                    SSH_LOG(SSH_LOG_PACKET, "Rekey failed: rc = %d", rc);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1631|      0|                    goto error;
 1632|      0|                }
 1633|      0|            }
 1634|       |
 1635|  82.7k|            return processed;
 1636|      0|        case PACKET_STATE_PROCESSING:
  ------------------
  |  Branch (1636:9): [True: 0, False: 83.4k]
  ------------------
 1637|      0|            SSH_LOG(SSH_LOG_PACKET, "Nested packet processing. Delaying.");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1638|      0|            return 0;
 1639|  83.4k|    }
 1640|       |
 1641|      0|    ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1642|      0|                  SSH_FATAL,
 1643|      0|                  "Invalid state into packet_read2(): %d",
 1644|      0|                  session->packet_state);
 1645|       |
 1646|    487|error:
 1647|    487|    session->session_state = SSH_SESSION_STATE_ERROR;
 1648|    487|    SSH_LOG(SSH_LOG_PACKET, "Packet: processed %zu bytes", processed);
  ------------------
  |  |  281|    487|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1649|    487|    return processed;
 1650|      0|}
ssh_packet_register_socket_callback:
 1677|    508|{
 1678|    508|    struct ssh_socket_callbacks_struct *callbacks = &session->socket_callbacks;
 1679|       |
 1680|    508|    callbacks->data = ssh_packet_socket_callback;
 1681|       |    callbacks->connected = NULL;
 1682|    508|    callbacks->controlflow = ssh_packet_socket_controlflow_callback;
 1683|    508|    callbacks->userdata = session;
 1684|    508|    ssh_socket_set_callbacks(s, callbacks);
 1685|    508|}
ssh_packet_set_callbacks:
 1692|    803|{
 1693|    803|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1693:9): [True: 508, False: 295]
  ------------------
 1694|    508|        session->packet_callbacks = ssh_list_new();
 1695|    508|        if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1695:13): [True: 0, False: 508]
  ------------------
 1696|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1697|      0|            return;
 1698|      0|        }
 1699|    508|    }
 1700|    803|    ssh_list_append(session->packet_callbacks, callbacks);
 1701|    803|}
ssh_packet_remove_callbacks:
 1708|    230|{
 1709|    230|    struct ssh_iterator *it = NULL;
 1710|       |
 1711|    230|    it = ssh_list_find(session->packet_callbacks, callbacks);
 1712|    230|    if (it != NULL) {
  ------------------
  |  Branch (1712:9): [True: 230, False: 0]
  ------------------
 1713|    230|        ssh_list_remove(session->packet_callbacks, it);
 1714|    230|    }
 1715|    230|}
ssh_packet_set_default_callbacks:
 1721|    508|{
 1722|    508|    struct ssh_packet_callbacks_struct *c = &session->default_packet_callbacks;
 1723|       |
 1724|    508|    c->start = 1;
 1725|    508|    c->n_callbacks = sizeof(default_packet_handlers) / sizeof(ssh_packet_callback);
 1726|    508|    c->user = session;
 1727|    508|    c->callbacks = default_packet_handlers;
 1728|    508|    ssh_packet_set_callbacks(session, c);
 1729|    508|}
ssh_packet_process:
 1736|  36.0k|{
 1737|  36.0k|    struct ssh_iterator *i = NULL;
 1738|  36.0k|    int rc = SSH_PACKET_NOT_USED;
  ------------------
  |  |  640|  36.0k|#define SSH_PACKET_NOT_USED 2
  ------------------
 1739|  36.0k|    ssh_packet_callbacks cb;
 1740|       |
 1741|  36.0k|    SSH_LOG(SSH_LOG_PACKET, "Dispatching handler for packet type %d", type);
  ------------------
  |  |  281|  36.0k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1742|  36.0k|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1742:9): [True: 0, False: 36.0k]
  ------------------
 1743|      0|        SSH_LOG(SSH_LOG_RARE, "Packet callback is not initialized !");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1744|      0|        return;
 1745|      0|    }
 1746|       |
 1747|  36.0k|    i = ssh_list_get_iterator(session->packet_callbacks);
 1748|  37.7k|    while (i != NULL) {
  ------------------
  |  Branch (1748:12): [True: 37.0k, False: 714]
  ------------------
 1749|  37.0k|        cb = ssh_iterator_value(ssh_packet_callbacks, i);
  ------------------
  |  |  114|  37.0k|  ((type)((iterator)->data))
  ------------------
 1750|  37.0k|        i = i->next;
 1751|       |
 1752|  37.0k|        if (!cb) {
  ------------------
  |  Branch (1752:13): [True: 0, False: 37.0k]
  ------------------
 1753|      0|            continue;
 1754|      0|        }
 1755|       |
 1756|  37.0k|        if (cb->start > type) {
  ------------------
  |  Branch (1756:13): [True: 0, False: 37.0k]
  ------------------
 1757|      0|            continue;
 1758|      0|        }
 1759|       |
 1760|  37.0k|        if (cb->start + cb->n_callbacks <= type) {
  ------------------
  |  Branch (1760:13): [True: 714, False: 36.3k]
  ------------------
 1761|    714|            continue;
 1762|    714|        }
 1763|       |
 1764|  36.3k|        if (cb->callbacks[type - cb->start] == NULL) {
  ------------------
  |  Branch (1764:13): [True: 949, False: 35.3k]
  ------------------
 1765|    949|            continue;
 1766|    949|        }
 1767|       |
 1768|  35.3k|        rc = cb->callbacks[type - cb->start](session, type, session->in_buffer,
 1769|  35.3k|                                             cb->user);
 1770|  35.3k|        if (rc == SSH_PACKET_USED) {
  ------------------
  |  |  637|  35.3k|#define SSH_PACKET_USED 1
  ------------------
  |  Branch (1770:13): [True: 35.3k, False: 0]
  ------------------
 1771|  35.3k|            break;
 1772|  35.3k|        }
 1773|  35.3k|    }
 1774|       |
 1775|  36.0k|    if (rc == SSH_PACKET_NOT_USED) {
  ------------------
  |  |  640|  36.0k|#define SSH_PACKET_NOT_USED 2
  ------------------
  |  Branch (1775:9): [True: 714, False: 35.3k]
  ------------------
 1776|    714|        SSH_LOG(SSH_LOG_RARE, "Couldn't do anything with packet type %d", type);
  ------------------
  |  |  281|    714|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1777|    714|        rc = ssh_packet_send_unimplemented(session, session->recv_seq - 1);
 1778|    714|        if (rc != SSH_OK) {
  ------------------
  |  |  316|    714|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1778:13): [True: 0, False: 714]
  ------------------
 1779|      0|            SSH_LOG(SSH_LOG_RARE, "Failed to send unimplemented: %s",
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1780|      0|                    ssh_get_error(session));
 1781|      0|        }
 1782|    714|        if (session->current_crypto == NULL) {
  ------------------
  |  Branch (1782:13): [True: 714, False: 0]
  ------------------
 1783|    714|            session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|    714|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1784|    714|        }
 1785|    714|    }
 1786|  36.0k|}
ssh_packet_send_newkeys:
 1794|     95|{
 1795|     95|    int rc;
 1796|       |
 1797|       |    /* Send the MSG_NEWKEYS */
 1798|     95|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS);
  ------------------
  |  |   13|     95|#define SSH2_MSG_NEWKEYS 21
  ------------------
 1799|     95|    if (rc < 0) {
  ------------------
  |  Branch (1799:9): [True: 0, False: 95]
  ------------------
 1800|      0|        return rc;
 1801|      0|    }
 1802|       |
 1803|     95|    rc = ssh_packet_send(session);
 1804|     95|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     95|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1804:9): [True: 0, False: 95]
  ------------------
 1805|      0|        return rc;
 1806|      0|    }
 1807|     95|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_NEWKEYS sent");
  ------------------
  |  |  281|     95|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1808|     95|    return rc;
 1809|     95|}
ssh_packet_send_unimplemented:
 1817|  47.3k|int ssh_packet_send_unimplemented(ssh_session session, uint32_t seqnum){
 1818|  47.3k|    int rc;
 1819|       |
 1820|  47.3k|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|  47.3k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  47.3k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  47.3k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  47.3k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  47.3k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  47.3k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  47.3k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1821|  47.3k|                         "bd",
 1822|  47.3k|                         SSH2_MSG_UNIMPLEMENTED,
 1823|  47.3k|                         seqnum);
 1824|  47.3k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  47.3k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1824:9): [True: 0, False: 47.3k]
  ------------------
 1825|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1826|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1827|      0|    }
 1828|  47.3k|    rc = ssh_packet_send(session);
 1829|       |
 1830|  47.3k|    return rc;
 1831|  47.3k|}
ssh_packet_unimplemented:
 1836|    686|SSH_PACKET_CALLBACK(ssh_packet_unimplemented){
 1837|    686|    uint32_t seq;
 1838|    686|    int rc;
 1839|       |
 1840|    686|    (void)session; /* unused */
 1841|    686|    (void)type;
 1842|    686|    (void)user;
 1843|       |
 1844|    686|    rc = ssh_buffer_unpack(packet, "d", &seq);
  ------------------
  |  |   60|    686|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    686|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    686|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    686|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    686|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    686|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    686|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1845|    686|    if (rc != SSH_OK) {
  ------------------
  |  |  316|    686|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1845:9): [True: 636, False: 50]
  ------------------
 1846|    636|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|    636|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1847|    636|                "Could not unpack SSH_MSG_UNIMPLEMENTED packet");
 1848|    636|        return SSH_PACKET_USED;
  ------------------
  |  |  637|    636|#define SSH_PACKET_USED 1
  ------------------
 1849|    636|    }
 1850|       |
 1851|     50|    SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  281|     50|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1852|     50|            "Received SSH_MSG_UNIMPLEMENTED (sequence number %" PRIu32 ")",seq);
 1853|       |
 1854|     50|    return SSH_PACKET_USED;
  ------------------
  |  |  637|     50|#define SSH_PACKET_USED 1
  ------------------
 1855|    686|}
ssh_packet_parse_type:
 1861|  82.7k|{
 1862|  82.7k|    session->in_packet = (struct packet_struct) {
 1863|  82.7k|        .type = 0,
 1864|  82.7k|    };
 1865|       |
 1866|  82.7k|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (1866:9): [True: 0, False: 82.7k]
  ------------------
 1867|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1868|      0|    }
 1869|       |
 1870|  82.7k|    if (ssh_buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) {
  ------------------
  |  Branch (1870:9): [True: 20.4k, False: 62.2k]
  ------------------
 1871|  20.4k|        ssh_set_error(session, SSH_FATAL, "Packet too short to read type");
  ------------------
  |  |  311|  20.4k|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1872|  20.4k|        return SSH_ERROR;
  ------------------
  |  |  317|  20.4k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1873|  20.4k|    }
 1874|       |
 1875|  62.2k|    session->in_packet.valid = 1;
 1876|       |
 1877|  62.2k|    return SSH_OK;
  ------------------
  |  |  316|  62.2k|#define SSH_OK 0     /* No error */
  ------------------
 1878|  82.7k|}
ssh_packet_send:
 2066|  48.8k|{
 2067|  48.8k|    uint32_t payloadsize;
 2068|  48.8k|    uint8_t type, *payload;
 2069|  48.8k|    bool need_rekey, in_rekey;
 2070|  48.8k|    int rc;
 2071|       |
 2072|  48.8k|    if (session->socket == NULL || !ssh_socket_is_open(session->socket)) {
  ------------------
  |  Branch (2072:9): [True: 0, False: 48.8k]
  |  Branch (2072:36): [True: 0, False: 48.8k]
  ------------------
 2073|      0|        ssh_buffer_reinit(session->out_buffer);
 2074|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2075|      0|    }
 2076|       |
 2077|  48.8k|    payloadsize = ssh_buffer_get_len(session->out_buffer);
 2078|  48.8k|    if (payloadsize < 1) {
  ------------------
  |  Branch (2078:9): [True: 0, False: 48.8k]
  ------------------
 2079|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2080|      0|    }
 2081|       |
 2082|  48.8k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 2083|  48.8k|    type = payload[0]; /* type is the first byte of the packet now */
 2084|  48.8k|    need_rekey = ssh_packet_need_rekey(session, payloadsize);
 2085|  48.8k|    in_rekey = ssh_packet_in_rekey(session);
 2086|       |
 2087|       |    /* The rekey is triggered here. After that, only the key exchange
 2088|       |     * packets can be sent, until we send our NEWKEYS.
 2089|       |     */
 2090|  48.8k|    if (need_rekey || (in_rekey && !ssh_packet_is_kex(type))) {
  ------------------
  |  Branch (2090:9): [True: 0, False: 48.8k]
  |  Branch (2090:24): [True: 0, False: 48.8k]
  |  Branch (2090:36): [True: 0, False: 0]
  ------------------
 2091|      0|        if (need_rekey) {
  ------------------
  |  Branch (2091:13): [True: 0, False: 0]
  ------------------
 2092|      0|            SSH_LOG(SSH_LOG_PACKET, "Outgoing packet triggered rekey");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2093|      0|        }
 2094|       |        /* Queue the current packet -- we will send it after the rekey */
 2095|      0|        SSH_LOG(SSH_LOG_PACKET, "Queuing packet type %d", type);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2096|      0|        rc = ssh_list_append(session->out_queue, session->out_buffer);
 2097|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2097:13): [True: 0, False: 0]
  ------------------
 2098|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2099|      0|        }
 2100|      0|        session->out_buffer = ssh_buffer_new();
 2101|      0|        if (session->out_buffer == NULL) {
  ------------------
  |  Branch (2101:13): [True: 0, False: 0]
  ------------------
 2102|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2103|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2104|      0|        }
 2105|       |
 2106|      0|        if (need_rekey) {
  ------------------
  |  Branch (2106:13): [True: 0, False: 0]
  ------------------
 2107|       |            /* Send the KEXINIT packet instead.
 2108|       |             * This recursively calls the packet_send(), but it should
 2109|       |             * not get into rekeying again.
 2110|       |             * After that we need to handle the key exchange responses
 2111|       |             * up to the point where we can send the rest of the queue.
 2112|       |             */
 2113|      0|            return ssh_send_rekex(session);
 2114|      0|        }
 2115|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2116|      0|    }
 2117|       |
 2118|       |    /* Send the packet normally */
 2119|  48.8k|    rc = packet_send2(session);
 2120|       |
 2121|       |    /* We finished the key exchange so we can try to send our queue now */
 2122|  48.8k|    if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |  316|  97.6k|#define SSH_OK 0     /* No error */
  ------------------
                  if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  48.8k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2122:9): [True: 48.8k, False: 0]
  |  Branch (2122:25): [True: 95, False: 48.7k]
  ------------------
 2123|     95|        struct ssh_iterator *it = NULL;
 2124|       |
 2125|     95|        if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|     95|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (2125:13): [True: 16, False: 79]
  ------------------
 2126|       |            /* reset packet sequence number when running in strict kex mode */
 2127|     16|            session->send_seq = 0;
 2128|     16|        }
 2129|     95|        for (it = ssh_list_get_iterator(session->out_queue);
 2130|     95|             it != NULL;
  ------------------
  |  Branch (2130:14): [True: 0, False: 95]
  ------------------
 2131|     95|             it = ssh_list_get_iterator(session->out_queue)) {
 2132|      0|            struct ssh_buffer_struct *next_buffer = NULL;
 2133|       |
 2134|       |            /* Peek only -- do not remove from queue yet */
 2135|      0|            next_buffer = (struct ssh_buffer_struct *)it->data;
 2136|      0|            payloadsize = ssh_buffer_get_len(next_buffer);
 2137|      0|            if (ssh_packet_need_rekey(session, payloadsize)) {
  ------------------
  |  Branch (2137:17): [True: 0, False: 0]
  ------------------
 2138|       |                /* Sigh ... we still can not send this packet. Repeat. */
 2139|      0|                SSH_LOG(SSH_LOG_PACKET, "Queued packet triggered rekey");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2140|      0|                return ssh_send_rekex(session);
 2141|      0|            }
 2142|      0|            SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2143|      0|            session->out_buffer = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2144|      0|                                                    session->out_queue);
 2145|      0|            payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 2146|      0|            type = payload[0];
 2147|      0|            SSH_LOG(SSH_LOG_PACKET, "Dequeue packet type %d", type);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2148|      0|            rc = packet_send2(session);
 2149|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2149:17): [True: 0, False: 0]
  ------------------
 2150|      0|                return rc;
 2151|      0|            }
 2152|      0|        }
 2153|     95|    }
 2154|       |
 2155|  48.8k|    return rc;
 2156|  48.8k|}
ssh_packet_set_newkeys:
 2271|     95|{
 2272|     95|    struct ssh_cipher_struct *in_cipher = NULL, *out_cipher = NULL;
 2273|     95|    int rc;
 2274|       |
 2275|     95|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|    380|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 95]
  |  |  |  Branch (281:34): [True: 95, False: 0]
  |  |  ------------------
  ------------------
 2276|     95|            "called, direction =%s%s",
 2277|     95|            direction & SSH_DIRECTION_IN ? " IN " : "",
 2278|     95|            direction & SSH_DIRECTION_OUT ? " OUT " : "");
 2279|       |
 2280|     95|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2280:9): [True: 0, False: 95]
  ------------------
 2281|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2282|      0|    }
 2283|       |
 2284|     95|    session->next_crypto->used |= direction;
 2285|     95|    if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2285:9): [True: 0, False: 95]
  ------------------
 2286|      0|        if (session->current_crypto->used & direction) {
  ------------------
  |  Branch (2286:13): [True: 0, False: 0]
  ------------------
 2287|      0|            SSH_LOG(SSH_LOG_TRACE, "This direction isn't used anymore.");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2288|      0|        }
 2289|       |        /* Mark the current requested direction unused */
 2290|      0|        session->current_crypto->used &= ~direction;
 2291|      0|    }
 2292|       |
 2293|       |    /* Both sides switched: do the actual switch now */
 2294|     95|    if (session->next_crypto->used == SSH_DIRECTION_BOTH) {
  ------------------
  |  Branch (2294:9): [True: 0, False: 95]
  ------------------
 2295|      0|        size_t session_id_len;
 2296|       |
 2297|      0|        if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2297:13): [True: 0, False: 0]
  ------------------
 2298|      0|            crypto_free(session->current_crypto);
 2299|      0|            session->current_crypto = NULL;
 2300|      0|        }
 2301|       |
 2302|      0|        session->current_crypto = session->next_crypto;
 2303|      0|        session->current_crypto->used = SSH_DIRECTION_BOTH;
 2304|       |
 2305|       |        /* Initialize the next_crypto structure */
 2306|      0|        session->next_crypto = crypto_new();
 2307|      0|        if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2307:13): [True: 0, False: 0]
  ------------------
 2308|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2309|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2310|      0|        }
 2311|       |
 2312|      0|        session_id_len = session->current_crypto->session_id_len;
 2313|      0|        session->next_crypto->session_id = malloc(session_id_len);
 2314|      0|        if (session->next_crypto->session_id == NULL) {
  ------------------
  |  Branch (2314:13): [True: 0, False: 0]
  ------------------
 2315|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2316|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2317|      0|        }
 2318|       |
 2319|      0|        memcpy(session->next_crypto->session_id,
 2320|      0|               session->current_crypto->session_id,
 2321|      0|               session_id_len);
 2322|      0|        session->next_crypto->session_id_len = session_id_len;
 2323|       |
 2324|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2325|      0|    }
 2326|       |
 2327|       |    /* Initialize common structures so the next context can be used in
 2328|       |     * either direction */
 2329|     95|    if (session->client) {
  ------------------
  |  Branch (2329:9): [True: 95, False: 0]
  ------------------
 2330|       |        /* The server has this part already done */
 2331|     95|        rc = ssh_make_sessionid(session);
 2332|     95|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     95|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2332:13): [True: 0, False: 95]
  ------------------
 2333|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2334|      0|        }
 2335|       |
 2336|       |        /*
 2337|       |         * Set the cryptographic functions for the next crypto
 2338|       |         * (it is needed for ssh_generate_session_keys for key lengths)
 2339|       |         */
 2340|     95|        rc = crypt_set_algorithms_client(session);
 2341|     95|        if (rc < 0) {
  ------------------
  |  Branch (2341:13): [True: 0, False: 95]
  ------------------
 2342|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2343|      0|        }
 2344|     95|    }
 2345|       |
 2346|     95|    if (ssh_generate_session_keys(session) < 0) {
  ------------------
  |  Branch (2346:9): [True: 0, False: 95]
  ------------------
 2347|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2348|      0|    }
 2349|       |
 2350|     95|    in_cipher = session->next_crypto->in_cipher;
 2351|     95|    out_cipher = session->next_crypto->out_cipher;
 2352|     95|    if (in_cipher == NULL || out_cipher == NULL) {
  ------------------
  |  Branch (2352:9): [True: 0, False: 95]
  |  Branch (2352:30): [True: 0, False: 95]
  ------------------
 2353|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2354|      0|    }
 2355|       |
 2356|       |    /* Initialize rekeying states */
 2357|     95|    ssh_init_rekey_state(session, out_cipher);
 2358|     95|    ssh_init_rekey_state(session, in_cipher);
 2359|     95|    if (session->opts.rekey_time != 0) {
  ------------------
  |  Branch (2359:9): [True: 0, False: 95]
  ------------------
 2360|      0|        ssh_timestamp_init(&session->last_rekey_time);
 2361|      0|        SSH_LOG(SSH_LOG_DEBUG, "Set rekey after %" PRIu32 " seconds",
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2362|      0|                session->opts.rekey_time/1000);
 2363|      0|    }
 2364|       |
 2365|     95|    if (in_cipher->set_decrypt_key) {
  ------------------
  |  Branch (2365:9): [True: 0, False: 95]
  ------------------
 2366|       |        /* Initialize the encryption and decryption keys in next_crypto */
 2367|      0|        rc = in_cipher->set_decrypt_key(in_cipher,
 2368|      0|                                        session->next_crypto->decryptkey,
 2369|      0|                                        session->next_crypto->decryptIV);
 2370|      0|        if (rc < 0) {
  ------------------
  |  Branch (2370:13): [True: 0, False: 0]
  ------------------
 2371|       |            /* On error, make sure it is not used */
 2372|      0|            session->next_crypto->used = 0;
 2373|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2374|      0|        }
 2375|      0|    }
 2376|       |
 2377|     95|    if (out_cipher->set_encrypt_key) {
  ------------------
  |  Branch (2377:9): [True: 0, False: 95]
  ------------------
 2378|      0|        rc = out_cipher->set_encrypt_key(out_cipher,
 2379|      0|                                         session->next_crypto->encryptkey,
 2380|      0|                                         session->next_crypto->encryptIV);
 2381|      0|        if (rc < 0) {
  ------------------
  |  Branch (2381:13): [True: 0, False: 0]
  ------------------
 2382|       |            /* On error, make sure it is not used */
 2383|      0|            session->next_crypto->used = 0;
 2384|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2385|      0|        }
 2386|      0|    }
 2387|       |
 2388|     95|    return SSH_OK;
  ------------------
  |  |  316|     95|#define SSH_OK 0     /* No error */
  ------------------
 2389|     95|}
packet.c:ssh_packet_incoming_filter:
  143|  82.7k|{
  144|  82.7k|    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|  82.7k|    switch(session->in_packet.type) {
  152|      5|    case SSH2_MSG_DISCONNECT:                         // 1
  ------------------
  |  |    4|      5|#define SSH2_MSG_DISCONNECT 1
  ------------------
  |  Branch (152:5): [True: 5, False: 82.7k]
  ------------------
  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|      5|        rc = SSH_PACKET_ALLOWED;
  164|      5|        break;
  165|    279|    case SSH2_MSG_IGNORE:                             // 2
  ------------------
  |  |    5|    279|#define SSH2_MSG_IGNORE	 2
  ------------------
  |  Branch (165:5): [True: 279, False: 82.4k]
  ------------------
  166|       |        /*
  167|       |         * States required:
  168|       |         * - None
  169|       |         *
  170|       |         * Transitions:
  171|       |         * - None
  172|       |         * */
  173|       |
  174|       |        /* Always allowed */
  175|    279|        rc = SSH_PACKET_ALLOWED;
  176|    279|        break;
  177|    686|    case SSH2_MSG_UNIMPLEMENTED:                      // 3
  ------------------
  |  |    6|    686|#define SSH2_MSG_UNIMPLEMENTED 3
  ------------------
  |  Branch (177:5): [True: 686, False: 82.0k]
  ------------------
  178|       |        /*
  179|       |         * States required:
  180|       |         * - None
  181|       |         *
  182|       |         * Transitions:
  183|       |         * - None
  184|       |         * */
  185|       |
  186|       |        /* Always allowed */
  187|    686|        rc = SSH_PACKET_ALLOWED;
  188|    686|        break;
  189|  33.7k|    case SSH2_MSG_DEBUG:                              // 4
  ------------------
  |  |    7|  33.7k|#define SSH2_MSG_DEBUG	4
  ------------------
  |  Branch (189:5): [True: 33.7k, False: 49.0k]
  ------------------
  190|       |        /*
  191|       |         * States required:
  192|       |         * - None
  193|       |         *
  194|       |         * Transitions:
  195|       |         * - None
  196|       |         * */
  197|       |
  198|       |        /* Always allowed */
  199|  33.7k|        rc = SSH_PACKET_ALLOWED;
  200|  33.7k|        break;
  201|      1|    case SSH2_MSG_SERVICE_REQUEST:                    // 5
  ------------------
  |  |    8|      1|#define SSH2_MSG_SERVICE_REQUEST	5
  ------------------
  |  Branch (201:5): [True: 1, False: 82.7k]
  ------------------
  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: 82.7k]
  ------------------
  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: 82.7k]
  ------------------
  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|    370|    case SSH2_MSG_KEXINIT:                            // 20
  ------------------
  |  |   12|    370|#define SSH2_MSG_KEXINIT	 20
  ------------------
  |  Branch (292:5): [True: 370, False: 82.3k]
  ------------------
  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|    370|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATED) &&
  ------------------
  |  Branch (310:13): [True: 370, False: 0]
  ------------------
  311|    370|            (session->session_state != SSH_SESSION_STATE_INITIAL_KEX))
  ------------------
  |  Branch (311:13): [True: 0, False: 370]
  ------------------
  312|      0|        {
  313|      0|            rc = SSH_PACKET_DENIED;
  314|      0|            break;
  315|      0|        }
  316|       |
  317|    370|        if ((session->dh_handshake_state != DH_STATE_INIT) &&
  ------------------
  |  Branch (317:13): [True: 0, False: 370]
  ------------------
  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|    370|        rc = SSH_PACKET_ALLOWED;
  327|    370|        break;
  328|     63|    case SSH2_MSG_NEWKEYS:                            // 21
  ------------------
  |  |   13|     63|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (328:5): [True: 63, False: 82.6k]
  ------------------
  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|     63|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (342:13): [True: 0, False: 63]
  ------------------
  343|      0|            rc = SSH_PACKET_DENIED;
  344|      0|            break;
  345|      0|        }
  346|       |
  347|       |        /* Only allowed if dh_handshake_state is in NEWKEYS_SENT state */
  348|     63|        if (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (348:13): [True: 1, False: 62]
  ------------------
  349|      1|            rc = SSH_PACKET_DENIED;
  350|      1|            break;
  351|      1|        }
  352|       |
  353|     62|        rc = SSH_PACKET_ALLOWED;
  354|     62|        break;
  355|      1|    case SSH2_MSG_KEXDH_INIT:                         // 30
  ------------------
  |  |   15|      1|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (355:5): [True: 1, False: 82.7k]
  ------------------
  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|    237|    case SSH2_MSG_KEXDH_REPLY:                        // 31
  ------------------
  |  |   16|    237|#define SSH2_MSG_KEXDH_REPLY 31
  ------------------
  |  Branch (391:5): [True: 237, False: 82.5k]
  ------------------
  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|    237|        if (session->server) {
  ------------------
  |  Branch (408:13): [True: 0, False: 237]
  ------------------
  409|      0|            rc = SSH_PACKET_DENIED;
  410|      0|            break;
  411|      0|        }
  412|       |
  413|    237|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (413:13): [True: 1, False: 236]
  ------------------
  414|      1|            rc = SSH_PACKET_DENIED;
  415|      1|            break;
  416|      1|        }
  417|       |
  418|    236|        if (session->dh_handshake_state != DH_STATE_INIT_SENT &&
  ------------------
  |  Branch (418:13): [True: 5, False: 231]
  ------------------
  419|      5|            session->dh_handshake_state != DH_STATE_REQUEST_SENT) {
  ------------------
  |  Branch (419:13): [True: 1, False: 4]
  ------------------
  420|      1|            rc = SSH_PACKET_DENIED;
  421|      1|            break;
  422|      1|        }
  423|       |
  424|    235|        rc = SSH_PACKET_ALLOWED;
  425|    235|        break;
  426|      1|    case SSH2_MSG_KEX_DH_GEX_INIT:                    // 32
  ------------------
  |  |   24|      1|#define SSH2_MSG_KEX_DH_GEX_INIT 32
  ------------------
  |  Branch (426:5): [True: 1, False: 82.7k]
  ------------------
  427|       |      // SSH2_MSG_KEXGSS_COMPLETE:                    // 32
  428|      1|        if (ssh_kex_is_gss(session->next_crypto)) {
  ------------------
  |  Branch (428:13): [True: 0, False: 1]
  ------------------
  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|      1|        } 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|      1|            if (session->client) {
  ------------------
  |  Branch (472:17): [True: 1, False: 0]
  ------------------
  473|      1|                rc = SSH_PACKET_DENIED;
  474|      1|                break;
  475|      1|            }
  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|    717|    case SSH2_MSG_KEX_DH_GEX_REPLY:                   // 33
  ------------------
  |  |   25|    717|#define SSH2_MSG_KEX_DH_GEX_REPLY 33
  ------------------
  |  Branch (490:5): [True: 717, False: 82.0k]
  ------------------
  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|    717|        if (session->server) {
  ------------------
  |  Branch (503:13): [True: 0, False: 717]
  ------------------
  504|      0|            rc = SSH_PACKET_DENIED;
  505|      0|            break;
  506|      0|        }
  507|       |
  508|    717|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (508:13): [True: 1, False: 716]
  ------------------
  509|      1|            rc = SSH_PACKET_DENIED;
  510|      1|            break;
  511|      1|        }
  512|       |
  513|    716|        if (session->dh_handshake_state != DH_STATE_INIT_SENT) {
  ------------------
  |  Branch (513:13): [True: 2, False: 714]
  ------------------
  514|      2|            rc = SSH_PACKET_DENIED;
  515|      2|            break;
  516|      2|        }
  517|       |
  518|    714|        rc = SSH_PACKET_ALLOWED;
  519|    714|        break;
  520|      0|    case SSH2_MSG_KEX_DH_GEX_REQUEST:                 // 34
  ------------------
  |  |   26|      0|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (520:5): [True: 0, False: 82.7k]
  ------------------
  521|       |
  522|       |        /* Server only */
  523|       |
  524|       |        /*
  525|       |         * States required:
  526|       |         * - session_state == SSH_SESSION_STATE_DH
  527|       |         * - dh_handshake_state == DH_STATE_INIT
  528|       |         *
  529|       |         * Transitions:
  530|       |         * - session->dh_handshake_state = DH_STATE_INIT_SENT
  531|       |         * then calls ssh_packet_server_dhgex_request which triggers:
  532|       |         * - session->dh_handshake_state = DH_STATE_GROUP_SENT
  533|       |         * */
  534|       |
  535|      0|        if (session->client) {
  ------------------
  |  Branch (535:13): [True: 0, False: 0]
  ------------------
  536|      0|            rc = SSH_PACKET_DENIED;
  537|      0|            break;
  538|      0|        }
  539|       |
  540|      0|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (540:13): [True: 0, False: 0]
  ------------------
  541|      0|            rc = SSH_PACKET_DENIED;
  542|      0|            break;
  543|      0|        }
  544|       |
  545|       |        /* Only allowed if dh_handshake_state is in initial state */
  546|      0|        if (session->dh_handshake_state != DH_STATE_INIT) {
  ------------------
  |  Branch (546:13): [True: 0, False: 0]
  ------------------
  547|      0|            rc = SSH_PACKET_DENIED;
  548|      0|            break;
  549|      0|        }
  550|       |
  551|      0|        rc = SSH_PACKET_ALLOWED;
  552|      0|        break;
  553|      0|    case SSH2_MSG_USERAUTH_REQUEST:                   // 50
  ------------------
  |  |   36|      0|#define SSH2_MSG_USERAUTH_REQUEST 50
  ------------------
  |  Branch (553:5): [True: 0, False: 82.7k]
  ------------------
  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: 82.7k]
  ------------------
  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|      1|    case SSH2_MSG_USERAUTH_SUCCESS:                   // 52
  ------------------
  |  |   38|      1|#define SSH2_MSG_USERAUTH_SUCCESS 52
  ------------------
  |  Branch (622:5): [True: 1, False: 82.7k]
  ------------------
  623|       |        /*
  624|       |         * States required:
  625|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  626|       |         * - dh_handshake_state == DH_STATE_FINISHED
  627|       |         * - session->auth.state == SSH_AUTH_STATE_KBDINT_SENT
  628|       |         *   or session->auth.state == SSH_AUTH_STATE_PUBKEY_AUTH_SENT
  629|       |         *   or session->auth.state == SSH_AUTH_STATE_PASSWORD_AUTH_SENT
  630|       |         *   or session->auth.state == SSH_AUTH_STATE_GSSAPI_MIC_SENT
  631|       |         *   or session->auth.state == SSH_AUTH_STATE_GSSAPI_KEYEX_MIC_SENT
  632|       |         *   or session->auth.state == SSH_AUTH_STATE_AUTH_NONE_SENT
  633|       |         *
  634|       |         * Transitions:
  635|       |         * - session->auth.state = SSH_AUTH_STATE_SUCCESS
  636|       |         * - session->session_state = SSH_SESSION_STATE_AUTHENTICATED
  637|       |         * - session->flags |= SSH_SESSION_FLAG_AUTHENTICATED
  638|       |         * - sessions->auth.current_method = SSH_AUTH_METHOD_UNKNOWN
  639|       |         * */
  640|       |
  641|       |        /* If this is a server, reject the message */
  642|      1|        if (session->server) {
  ------------------
  |  Branch (642:13): [True: 0, False: 1]
  ------------------
  643|      0|            rc = SSH_PACKET_DENIED;
  644|      0|            break;
  645|      0|        }
  646|       |
  647|      1|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (647:13): [True: 1, False: 0]
  ------------------
  648|      1|            rc = SSH_PACKET_DENIED;
  649|      1|            break;
  650|      1|        }
  651|       |
  652|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (652:13): [True: 0, False: 0]
  ------------------
  653|      0|            rc = SSH_PACKET_DENIED;
  654|      0|            break;
  655|      0|        }
  656|       |
  657|      0|        if ((session->auth.state != SSH_AUTH_STATE_KBDINT_SENT) &&
  ------------------
  |  Branch (657:13): [True: 0, False: 0]
  ------------------
  658|      0|            (session->auth.state != SSH_AUTH_STATE_PUBKEY_AUTH_SENT) &&
  ------------------
  |  Branch (658:13): [True: 0, False: 0]
  ------------------
  659|      0|            (session->auth.state != SSH_AUTH_STATE_PASSWORD_AUTH_SENT) &&
  ------------------
  |  Branch (659:13): [True: 0, False: 0]
  ------------------
  660|      0|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_MIC_SENT) &&
  ------------------
  |  Branch (660:13): [True: 0, False: 0]
  ------------------
  661|      0|            (session->auth.state != SSH_AUTH_STATE_GSSAPI_KEYEX_MIC_SENT) &&
  ------------------
  |  Branch (661:13): [True: 0, False: 0]
  ------------------
  662|      0|            (session->auth.state != SSH_AUTH_STATE_AUTH_NONE_SENT)) {
  ------------------
  |  Branch (662:13): [True: 0, False: 0]
  ------------------
  663|      0|            rc = SSH_PACKET_DENIED;
  664|      0|            break;
  665|      0|        }
  666|       |
  667|      0|        rc = SSH_PACKET_ALLOWED;
  668|      0|        break;
  669|      1|    case SSH2_MSG_USERAUTH_BANNER:                    // 53
  ------------------
  |  |   39|      1|#define SSH2_MSG_USERAUTH_BANNER 53
  ------------------
  |  Branch (669:5): [True: 1, False: 82.7k]
  ------------------
  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: 82.7k]
  ------------------
  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: 82.7k]
  ------------------
  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|      0|    case SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE:  // 63
  ------------------
  |  |   46|      0|#define SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE 63
  ------------------
  |  Branch (753:5): [True: 0, False: 82.7k]
  ------------------
  754|       |        /* Server only */
  755|       |        /*
  756|       |         * States required:
  757|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  758|       |         * - session->gssapi->state == SSH_GSSAPI_STATE_RCV_MIC
  759|       |         *
  760|       |         * Transitions:
  761|       |         * - None
  762|       |         */
  763|       |#ifdef WITH_GSSAPI
  764|       |        if (session->client) {
  765|       |            rc = SSH_PACKET_DENIED;
  766|       |            break;
  767|       |        }
  768|       |        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  769|       |            rc = SSH_PACKET_DENIED;
  770|       |            break;
  771|       |        }
  772|       |        if (session->gssapi == NULL) {
  773|       |            rc = SSH_PACKET_DENIED;
  774|       |            break;
  775|       |        }
  776|       |        if (session->gssapi->state != SSH_GSSAPI_STATE_RCV_MIC) {
  777|       |            rc = SSH_PACKET_DENIED;
  778|       |            break;
  779|       |        }
  780|       |        rc = SSH_PACKET_ALLOWED;
  781|       |        break;
  782|       |#else
  783|      0|        rc = SSH_PACKET_DENIED;
  784|      0|        break;
  785|      0|#endif  /* WITH_GSSAPI */
  786|      4|    case SSH2_MSG_USERAUTH_GSSAPI_ERROR:              // 64
  ------------------
  |  |   47|      4|#define SSH2_MSG_USERAUTH_GSSAPI_ERROR 64
  ------------------
  |  Branch (786:5): [True: 4, False: 82.7k]
  ------------------
  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|      4|        rc = SSH_PACKET_DENIED;
  809|      4|        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: 82.7k]
  ------------------
  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: 82.7k]
  ------------------
  832|       |        /* Server only */
  833|       |
  834|       |        /*
  835|       |         * States required:
  836|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  837|       |         * - session->gssapi->state == SSH_GSSAPI_STATE_RCV_MIC
  838|       |         *
  839|       |         * Transitions:
  840|       |         * Depending on the result of the verification, the states are
  841|       |         * changed:
  842|       |         * - SSH_AUTH_SUCCESS:
  843|       |         *   - session->session_state = SSH_SESSION_STATE_AUTHENTICATED
  844|       |         *   - session->flags != SSH_SESSION_FLAG_AUTHENTICATED
  845|       |         * - SSH_AUTH_PARTIAL:
  846|       |         *   - None
  847|       |         * - any other case:
  848|       |         *   - None
  849|       |         * */
  850|       |#ifdef WITH_GSSAPI
  851|       |        /* If this is a client, reject the message */
  852|       |        if (session->client) {
  853|       |            rc = SSH_PACKET_DENIED;
  854|       |            break;
  855|       |        }
  856|       |
  857|       |        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  858|       |            rc = SSH_PACKET_DENIED;
  859|       |            break;
  860|       |        }
  861|       |
  862|       |        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  863|       |            rc = SSH_PACKET_DENIED;
  864|       |            break;
  865|       |        }
  866|       |
  867|       |        rc = SSH_PACKET_ALLOWED;
  868|       |        break;
  869|       |#else
  870|      0|        rc = SSH_PACKET_DENIED;
  871|      0|        break;
  872|      0|#endif  /* WITH_GSSAPI */
  873|      0|    case SSH2_MSG_GLOBAL_REQUEST:                     // 80
  ------------------
  |  |   51|      0|#define SSH2_MSG_GLOBAL_REQUEST 80
  ------------------
  |  Branch (873:5): [True: 0, False: 82.7k]
  ------------------
  874|       |        /*
  875|       |         * States required:
  876|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  877|       |         *
  878|       |         * Transitions:
  879|       |         * - None
  880|       |         * */
  881|       |
  882|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (882:13): [True: 0, False: 0]
  ------------------
  883|      0|            rc = SSH_PACKET_DENIED;
  884|      0|            break;
  885|      0|        }
  886|       |
  887|      0|        rc = SSH_PACKET_ALLOWED;
  888|      0|        break;
  889|      2|    case SSH2_MSG_REQUEST_SUCCESS:                    // 81
  ------------------
  |  |   52|      2|#define SSH2_MSG_REQUEST_SUCCESS 81
  ------------------
  |  Branch (889:5): [True: 2, False: 82.7k]
  ------------------
  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: 82.7k]
  ------------------
  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|      2|    case SSH2_MSG_CHANNEL_OPEN:                       // 90
  ------------------
  |  |   54|      2|#define SSH2_MSG_CHANNEL_OPEN 90
  ------------------
  |  Branch (927:5): [True: 2, False: 82.7k]
  ------------------
  928|       |        /*
  929|       |         * States required:
  930|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  931|       |         *
  932|       |         * Transitions:
  933|       |         * - None
  934|       |         * */
  935|       |
  936|      2|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (936:13): [True: 2, False: 0]
  ------------------
  937|      2|            rc = SSH_PACKET_DENIED;
  938|      2|            break;
  939|      2|        }
  940|       |
  941|      0|        rc = SSH_PACKET_ALLOWED;
  942|      0|        break;
  943|      1|    case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION:          // 91
  ------------------
  |  |   55|      1|#define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
  ------------------
  |  Branch (943:5): [True: 1, False: 82.7k]
  ------------------
  944|       |        /*
  945|       |         * States required:
  946|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  947|       |         *
  948|       |         * Transitions:
  949|       |         * - channel->state = SSH_CHANNEL_STATE_OPEN
  950|       |         * - channel->flags &= ~SSH_CHANNEL_FLAG_NOT_BOUND
  951|       |         * */
  952|       |
  953|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (953:13): [True: 1, False: 0]
  ------------------
  954|      1|            rc = SSH_PACKET_DENIED;
  955|      1|            break;
  956|      1|        }
  957|       |
  958|      0|        rc = SSH_PACKET_ALLOWED;
  959|      0|        break;
  960|      0|    case SSH2_MSG_CHANNEL_OPEN_FAILURE:               // 92
  ------------------
  |  |   56|      0|#define SSH2_MSG_CHANNEL_OPEN_FAILURE 92
  ------------------
  |  Branch (960:5): [True: 0, False: 82.7k]
  ------------------
  961|       |        /*
  962|       |         * States required:
  963|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  964|       |         *
  965|       |         * Transitions:
  966|       |         * - channel->state = SSH_CHANNEL_STATE_OPEN_DENIED
  967|       |         * */
  968|       |
  969|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (969:13): [True: 0, False: 0]
  ------------------
  970|      0|            rc = SSH_PACKET_DENIED;
  971|      0|            break;
  972|      0|        }
  973|       |
  974|      0|        rc = SSH_PACKET_ALLOWED;
  975|      0|        break;
  976|      2|    case SSH2_MSG_CHANNEL_WINDOW_ADJUST:              // 93
  ------------------
  |  |   57|      2|#define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93
  ------------------
  |  Branch (976:5): [True: 2, False: 82.7k]
  ------------------
  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|      1|    case SSH2_MSG_CHANNEL_DATA:                       // 94
  ------------------
  |  |   58|      1|#define SSH2_MSG_CHANNEL_DATA 94
  ------------------
  |  Branch (992:5): [True: 1, False: 82.7k]
  ------------------
  993|       |        /*
  994|       |         * States required:
  995|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  996|       |         *
  997|       |         * Transitions:
  998|       |         * - None
  999|       |         * */
 1000|       |
 1001|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1001:13): [True: 1, False: 0]
  ------------------
 1002|      1|            rc = SSH_PACKET_DENIED;
 1003|      1|            break;
 1004|      1|        }
 1005|       |
 1006|      0|        rc = SSH_PACKET_ALLOWED;
 1007|      0|        break;
 1008|      0|    case SSH2_MSG_CHANNEL_EXTENDED_DATA:              // 95
  ------------------
  |  |   59|      0|#define SSH2_MSG_CHANNEL_EXTENDED_DATA 95
  ------------------
  |  Branch (1008:5): [True: 0, False: 82.7k]
  ------------------
 1009|       |        /*
 1010|       |         * States required:
 1011|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1012|       |         *
 1013|       |         * Transitions:
 1014|       |         * - None
 1015|       |         * */
 1016|       |
 1017|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1017:13): [True: 0, False: 0]
  ------------------
 1018|      0|            rc = SSH_PACKET_DENIED;
 1019|      0|            break;
 1020|      0|        }
 1021|       |
 1022|      0|        rc = SSH_PACKET_ALLOWED;
 1023|      0|        break;
 1024|      1|    case SSH2_MSG_CHANNEL_EOF:                        // 96
  ------------------
  |  |   60|      1|#define SSH2_MSG_CHANNEL_EOF	96
  ------------------
  |  Branch (1024:5): [True: 1, False: 82.7k]
  ------------------
 1025|       |        /*
 1026|       |         * States required:
 1027|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1028|       |         *
 1029|       |         * Transitions:
 1030|       |         * - None
 1031|       |         * */
 1032|       |
 1033|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1033:13): [True: 1, False: 0]
  ------------------
 1034|      1|            rc = SSH_PACKET_DENIED;
 1035|      1|            break;
 1036|      1|        }
 1037|       |
 1038|      0|        rc = SSH_PACKET_ALLOWED;
 1039|      0|        break;
 1040|      0|    case SSH2_MSG_CHANNEL_CLOSE:                      // 97
  ------------------
  |  |   61|      0|#define SSH2_MSG_CHANNEL_CLOSE 97
  ------------------
  |  Branch (1040:5): [True: 0, False: 82.7k]
  ------------------
 1041|       |        /*
 1042|       |         * States required:
 1043|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1044|       |         *
 1045|       |         * Transitions:
 1046|       |         * - channel->state = SSH_CHANNEL_STATE_CLOSED
 1047|       |         * - channel->flags |= SSH_CHANNEL_FLAG_CLOSED_REMOTE
 1048|       |         * */
 1049|       |
 1050|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1050:13): [True: 0, False: 0]
  ------------------
 1051|      0|            rc = SSH_PACKET_DENIED;
 1052|      0|            break;
 1053|      0|        }
 1054|       |
 1055|      0|        rc = SSH_PACKET_ALLOWED;
 1056|      0|        break;
 1057|      0|    case SSH2_MSG_CHANNEL_REQUEST:                    // 98
  ------------------
  |  |   62|      0|#define SSH2_MSG_CHANNEL_REQUEST 98
  ------------------
  |  Branch (1057:5): [True: 0, False: 82.7k]
  ------------------
 1058|       |        /*
 1059|       |         * States required:
 1060|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1061|       |         *
 1062|       |         * Transitions:
 1063|       |         * - Depends on the request
 1064|       |         * */
 1065|       |
 1066|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1066:13): [True: 0, False: 0]
  ------------------
 1067|      0|            rc = SSH_PACKET_DENIED;
 1068|      0|            break;
 1069|      0|        }
 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: 82.7k]
  ------------------
 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|      3|    case SSH2_MSG_CHANNEL_FAILURE:                    // 100
  ------------------
  |  |   64|      3|#define SSH2_MSG_CHANNEL_FAILURE 100
  ------------------
  |  Branch (1092:5): [True: 3, False: 82.7k]
  ------------------
 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|      3|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1104:13): [True: 3, False: 0]
  ------------------
 1105|      3|            rc = SSH_PACKET_DENIED;
 1106|      3|            break;
 1107|      3|        }
 1108|       |
 1109|      0|        rc = SSH_PACKET_ALLOWED;
 1110|      0|        break;
 1111|      7|    case SSH2_MSG_PING: // 192
  ------------------
  |  |   69|      7|#define SSH2_MSG_PING 192
  ------------------
  |  Branch (1111:5): [True: 7, False: 82.7k]
  ------------------
 1112|      7|    case SSH2_MSG_PONG: // 193
  ------------------
  |  |   70|      7|#define SSH2_MSG_PONG 193
  ------------------
  |  Branch (1112:5): [True: 0, False: 82.7k]
  ------------------
 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|      7|        rc = SSH_PACKET_ALLOWED;
 1128|      7|        break;
 1129|  46.6k|    default:
  ------------------
  |  Branch (1129:5): [True: 46.6k, False: 36.1k]
  ------------------
 1130|       |        /* Unknown message, do not filter */
 1131|  46.6k|        rc = SSH_PACKET_UNKNOWN;
 1132|  46.6k|        goto end;
 1133|  82.7k|    }
 1134|       |
 1135|  82.7k|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|  82.7k|    return rc;
 1149|  82.7k|}
packet.c:ssh_packet_need_rekey:
 1201|   131k|{
 1202|   131k|    bool data_rekey_needed = false;
 1203|   131k|    struct ssh_crypto_struct *crypto = NULL;
 1204|   131k|    struct ssh_cipher_struct *out_cipher = NULL, *in_cipher = NULL;
 1205|   131k|    uint32_t next_blocks;
 1206|       |
 1207|       |    /* We can safely rekey only in authenticated state */
 1208|   131k|    if ((session->flags & SSH_SESSION_FLAG_AUTHENTICATED) == 0) {
  ------------------
  |  |   78|   131k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (1208:9): [True: 131k, False: 0]
  ------------------
 1209|   131k|        return false;
 1210|   131k|    }
 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,
  ------------------
  |  |  281|      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:
 1653|    306|{
 1654|    306|    ssh_session session = userdata;
 1655|    306|    struct ssh_iterator *it = NULL;
 1656|    306|    ssh_channel channel = NULL;
 1657|       |
 1658|    306|    if (code == SSH_SOCKET_FLOW_WRITEWONTBLOCK) {
  ------------------
  |  |  518|    306|#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
  ------------------
  |  Branch (1658:9): [True: 306, False: 0]
  ------------------
 1659|    306|        SSH_LOG(SSH_LOG_TRACE, "sending channel_write_wontblock callback");
  ------------------
  |  |  281|    306|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1660|       |
 1661|       |        /* the out pipe is empty so we can forward this to channels */
 1662|    306|        it = ssh_list_get_iterator(session->channels);
 1663|    306|        while (it != NULL) {
  ------------------
  |  Branch (1663:16): [True: 0, False: 306]
  ------------------
 1664|      0|            channel = ssh_iterator_value(ssh_channel, it);
  ------------------
  |  |  114|      0|  ((type)((iterator)->data))
  ------------------
 1665|       |            ssh_callbacks_execute_list(channel->callbacks,
  ------------------
  |  |  566|      0|    do {                                                      \
  |  |  567|      0|        struct ssh_iterator *i = ssh_list_get_iterator(list); \
  |  |  568|      0|        cbtype cb;                                            \
  |  |  569|      0|        while (i != NULL){                                    \
  |  |  ------------------
  |  |  |  Branch (569:16): [True: 0, False: 0]
  |  |  ------------------
  |  |  570|      0|            cb = ssh_iterator_value(cbtype, i);               \
  |  |  ------------------
  |  |  |  |  114|      0|  ((type)((iterator)->data))
  |  |  ------------------
  |  |  571|      0|            if (ssh_callbacks_exists(cb, c))                  \
  |  |  ------------------
  |  |  |  |  547|      0|#define ssh_callbacks_exists(p,c) (\
  |  |  |  |  548|      0|  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (548:3): [True: 0, False: 0]
  |  |  |  |  |  Branch (548:18): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  549|      0|  ((p)-> c != NULL) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (549:3): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  550|      0|  )
  |  |  ------------------
  |  |  572|      0|                cb-> c (__VA_ARGS__, cb->userdata);           \
  |  |  573|      0|            i = i->next;                                      \
  |  |  574|      0|        }                                                     \
  |  |  575|      0|    } while(0)
  |  |  ------------------
  |  |  |  Branch (575:13): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1666|      0|                                       ssh_channel_callbacks,
 1667|      0|                                       channel_write_wontblock_function,
 1668|      0|                                       session,
 1669|      0|                                       channel,
 1670|      0|                                       channel->remote_window);
 1671|      0|            it = it->next;
 1672|      0|        }
 1673|    306|    }
 1674|    306|}
packet.c:ssh_packet_in_rekey:
 2055|  48.8k|{
 2056|       |    /* We know we are rekeying if we are authenticated and the DH
 2057|       |     * status is not finished, but we only queue packets until we've
 2058|       |     * sent our NEWKEYS.
 2059|       |     */
 2060|  48.8k|    return (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) &&
  ------------------
  |  |   78|  48.8k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (2060:12): [True: 0, False: 48.8k]
  ------------------
 2061|      0|           (session->dh_handshake_state != DH_STATE_FINISHED) &&
  ------------------
  |  Branch (2061:12): [True: 0, False: 0]
  ------------------
 2062|      0|           (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT);
  ------------------
  |  Branch (2062:12): [True: 0, False: 0]
  ------------------
 2063|  48.8k|}
packet.c:packet_send2:
 1895|  48.8k|{
 1896|  48.8k|    unsigned int blocksize = 8;
 1897|  48.8k|    unsigned int lenfield_blocksize = 0;
 1898|  48.8k|    enum ssh_hmac_e hmac_type;
 1899|  48.8k|    uint32_t currentlen = ssh_buffer_get_len(session->out_buffer);
 1900|  48.8k|    struct ssh_crypto_struct *crypto = NULL;
 1901|  48.8k|    unsigned char *hmac = NULL;
 1902|  48.8k|    uint8_t padding_data[32] = { 0 };
 1903|  48.8k|    uint8_t padding_size;
 1904|  48.8k|    uint32_t finallen, payloadsize, compsize;
 1905|  48.8k|    uint8_t header[5] = {0};
 1906|  48.8k|    uint8_t type, *payload;
 1907|  48.8k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  48.8k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1908|  48.8k|    bool etm = false;
 1909|  48.8k|    int etm_packet_offset = 0;
 1910|       |
 1911|  48.8k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
 1912|  48.8k|    if (crypto) {
  ------------------
  |  Branch (1912:9): [True: 5.10k, False: 43.7k]
  ------------------
 1913|  5.10k|        blocksize = crypto->out_cipher->blocksize;
 1914|  5.10k|        lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
 1915|  5.10k|        hmac_type = crypto->out_hmac;
 1916|  5.10k|        etm = crypto->out_hmac_etm;
 1917|  43.7k|    } else {
 1918|  43.7k|        hmac_type = session->next_crypto->out_hmac;
 1919|  43.7k|    }
 1920|       |
 1921|  48.8k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 1922|  48.8k|    type = payload[0]; /* type is the first byte of the packet now */
 1923|       |
 1924|  48.8k|    payloadsize = currentlen;
 1925|  48.8k|    if (etm) {
  ------------------
  |  Branch (1925:9): [True: 0, False: 48.8k]
  ------------------
 1926|      0|        etm_packet_offset = sizeof(uint32_t);
 1927|      0|        lenfield_blocksize = 0;
 1928|      0|    }
 1929|       |
 1930|  48.8k|    if (crypto != NULL && crypto->do_compress_out &&
  ------------------
  |  Branch (1930:9): [True: 5.10k, False: 43.7k]
  |  Branch (1930:27): [True: 0, False: 5.10k]
  ------------------
 1931|      0|        ssh_buffer_get_len(session->out_buffer) > 0) {
  ------------------
  |  Branch (1931:9): [True: 0, False: 0]
  ------------------
 1932|      0|        rc = compress_buffer(session,session->out_buffer);
 1933|      0|        if (rc < 0) {
  ------------------
  |  Branch (1933:13): [True: 0, False: 0]
  ------------------
 1934|      0|            goto error;
 1935|      0|        }
 1936|      0|        currentlen = ssh_buffer_get_len(session->out_buffer);
 1937|      0|    }
 1938|  48.8k|    compsize = currentlen;
 1939|       |    /* compressed payload + packet len (4) + padding_size len (1) */
 1940|       |    /* totallen - lenfield_blocksize - etm_packet_offset must be equal to 0 (mod blocksize) */
 1941|  48.8k|    padding_size = (blocksize - ((blocksize - lenfield_blocksize - etm_packet_offset + currentlen + 5) % blocksize));
 1942|  48.8k|    if (padding_size < 4) {
  ------------------
  |  Branch (1942:9): [True: 99, False: 48.7k]
  ------------------
 1943|     99|        padding_size += blocksize;
 1944|     99|    }
 1945|       |
 1946|  48.8k|    if (crypto != NULL) {
  ------------------
  |  Branch (1946:9): [True: 5.10k, False: 43.7k]
  ------------------
 1947|  5.10k|        int ok;
 1948|       |
 1949|  5.10k|        ok = ssh_get_random(padding_data, padding_size, 0);
 1950|  5.10k|        if (!ok) {
  ------------------
  |  Branch (1950:13): [True: 0, False: 5.10k]
  ------------------
 1951|      0|            ssh_set_error(session, SSH_FATAL, "PRNG error");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1952|      0|            goto error;
 1953|      0|        }
 1954|  5.10k|    }
 1955|       |
 1956|  48.8k|    finallen = currentlen - etm_packet_offset + padding_size + 1;
 1957|       |
 1958|  48.8k|    PUSH_BE_U32(header, 0, finallen);
  ------------------
  |  |   89|  48.8k|    (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|  48.8k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  48.8k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  48.8k|    (((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|  48.8k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  48.8k|    (((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|  48.8k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  48.8k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  48.8k|    (((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|  48.8k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  48.8k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1959|  48.8k|    PUSH_BE_U8(header, 4, padding_size);
  ------------------
  |  |   83|  48.8k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  ------------------
  |  |  |  |   31|  48.8k|    (((uint8_t *)(data))[(pos)])
  |  |  ------------------
  ------------------
 1960|       |
 1961|  48.8k|    rc = ssh_buffer_prepend_data(session->out_buffer,
 1962|  48.8k|                                 header,
 1963|  48.8k|                                 sizeof(header));
 1964|  48.8k|    if (rc < 0) {
  ------------------
  |  Branch (1964:9): [True: 0, False: 48.8k]
  ------------------
 1965|      0|        goto error;
 1966|      0|    }
 1967|       |
 1968|  48.8k|    rc = ssh_buffer_add_data(session->out_buffer, padding_data, padding_size);
 1969|  48.8k|    if (rc < 0) {
  ------------------
  |  Branch (1969:9): [True: 0, False: 48.8k]
  ------------------
 1970|      0|        goto error;
 1971|      0|    }
 1972|       |
 1973|  48.8k|#ifdef WITH_PCAP
 1974|  48.8k|    if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1974:9): [True: 0, False: 48.8k]
  ------------------
 1975|      0|        ssh_pcap_context_write(session->pcap_ctx,
 1976|      0|                               SSH_PCAP_DIR_OUT,
 1977|      0|                               ssh_buffer_get(session->out_buffer),
 1978|      0|                               ssh_buffer_get_len(session->out_buffer),
 1979|      0|                               ssh_buffer_get_len(session->out_buffer));
 1980|      0|    }
 1981|  48.8k|#endif
 1982|       |
 1983|  48.8k|    hmac = ssh_packet_encrypt(session,
 1984|  48.8k|                              ssh_buffer_get(session->out_buffer),
 1985|  48.8k|                              ssh_buffer_get_len(session->out_buffer));
 1986|       |    /* XXX This returns null before switching on crypto, with none MAC
 1987|       |     * and on various errors.
 1988|       |     * We should distinguish between these cases to avoid hiding errors. */
 1989|  48.8k|    if (hmac != NULL) {
  ------------------
  |  Branch (1989:9): [True: 5.10k, False: 43.7k]
  ------------------
 1990|  5.10k|        rc = ssh_buffer_add_data(session->out_buffer,
 1991|  5.10k|                                 hmac,
 1992|  5.10k|                                 (uint32_t)hmac_digest_len(hmac_type));
 1993|  5.10k|        if (rc < 0) {
  ------------------
  |  Branch (1993:13): [True: 0, False: 5.10k]
  ------------------
 1994|      0|            goto error;
 1995|      0|        }
 1996|  5.10k|    }
 1997|       |
 1998|  48.8k|    rc = ssh_packet_write(session);
 1999|  48.8k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  48.8k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1999:9): [True: 0, False: 48.8k]
  ------------------
 2000|      0|        goto error;
 2001|      0|    }
 2002|  48.8k|    session->send_seq++;
 2003|  48.8k|    if (crypto != NULL) {
  ------------------
  |  Branch (2003:9): [True: 5.10k, False: 43.7k]
  ------------------
 2004|  5.10k|        struct ssh_cipher_struct *cipher = NULL;
 2005|       |
 2006|  5.10k|        cipher = crypto->out_cipher;
 2007|  5.10k|        cipher->packets++;
 2008|  5.10k|        cipher->blocks += payloadsize / cipher->blocksize;
 2009|  5.10k|    }
 2010|  48.8k|    if (session->raw_counter != NULL) {
  ------------------
  |  Branch (2010:9): [True: 0, False: 48.8k]
  ------------------
 2011|      0|        session->raw_counter->out_bytes += payloadsize;
 2012|      0|        session->raw_counter->out_packets++;
 2013|      0|    }
 2014|       |
 2015|  48.8k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  48.8k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2016|  48.8k|            "packet: wrote [type=%u, len=%" PRIu32 ", padding_size=%hhd, comp=%" PRIu32 ", "
 2017|  48.8k|            "payload=%" PRIu32 "]",
 2018|  48.8k|            type,
 2019|  48.8k|            finallen,
 2020|  48.8k|            padding_size,
 2021|  48.8k|            compsize,
 2022|  48.8k|            payloadsize);
 2023|       |
 2024|  48.8k|    rc = ssh_buffer_reinit(session->out_buffer);
 2025|  48.8k|    if (rc < 0) {
  ------------------
  |  Branch (2025:9): [True: 0, False: 48.8k]
  ------------------
 2026|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2027|      0|        goto error;
 2028|      0|    }
 2029|       |
 2030|       |    /* We sent the NEWKEYS so any further packet needs to be encrypted
 2031|       |     * with the new keys. We can not switch both directions (need to decrypt
 2032|       |     * peer NEWKEYS) and we do not want to wait for the peer NEWKEYS
 2033|       |     * too, so we will switch only the OUT direction now.
 2034|       |     */
 2035|  48.8k|    if (type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  48.8k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2035:9): [True: 95, False: 48.7k]
  ------------------
 2036|     95|        rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_OUT);
 2037|     95|    }
 2038|  48.8k|error:
 2039|  48.8k|    return rc; /* SSH_OK, AGAIN or ERROR */
 2040|  48.8k|}
packet.c:ssh_packet_write:
 1884|  48.8k|static int ssh_packet_write(ssh_session session) {
 1885|  48.8k|  int rc = SSH_ERROR;
  ------------------
  |  |  317|  48.8k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1886|       |
 1887|  48.8k|  rc=ssh_socket_write(session->socket,
 1888|  48.8k|      ssh_buffer_get(session->out_buffer),
 1889|  48.8k|      ssh_buffer_get_len(session->out_buffer));
 1890|       |
 1891|  48.8k|  return rc;
 1892|  48.8k|}
packet.c:ssh_init_rekey_state:
 2240|    190|{
 2241|       |    /* Reset the counters: should be NOOP */
 2242|    190|    cipher->packets = 0;
 2243|    190|    cipher->blocks = 0;
 2244|       |
 2245|       |    /* Default rekey limits for ciphers as specified in RFC4344, Section 3.2 */
 2246|    190|    if (cipher->blocksize >= 16) {
  ------------------
  |  Branch (2246:9): [True: 0, False: 190]
  ------------------
 2247|       |        /* For larger block size (L bits) use maximum of 2**(L/4) blocks */
 2248|      0|        cipher->max_blocks = (uint64_t)1 << (cipher->blocksize*2);
 2249|    190|    } else {
 2250|       |        /* For smaller blocks use limit of 1 GB as recommended in RFC4253 */
 2251|    190|        cipher->max_blocks = ((uint64_t)1 << 30) / cipher->blocksize;
 2252|    190|    }
 2253|       |    /* If we have limit provided by user, use the smaller one */
 2254|    190|    if (session->opts.rekey_data != 0) {
  ------------------
  |  Branch (2254:9): [True: 0, False: 190]
  ------------------
 2255|      0|        cipher->max_blocks = MIN(cipher->max_blocks,
  ------------------
  |  |  365|      0|#define MIN(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (365:19): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 2256|      0|                                 session->opts.rekey_data / cipher->blocksize);
 2257|      0|    }
 2258|       |
 2259|    190|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    190|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2260|    190|            "Set rekey after %" PRIu64 " blocks",
 2261|    190|            cipher->max_blocks);
 2262|    190|}

ssh_packet_disconnect_callback:
   53|      5|{
   54|      5|    int rc;
   55|      5|    uint32_t code = 0;
   56|      5|    char *error = NULL;
   57|      5|    ssh_string error_s = NULL;
   58|       |
   59|      5|    (void)user;
   60|      5|    (void)type;
   61|       |
   62|      5|    rc = ssh_buffer_get_u32(packet, &code);
   63|      5|    if (rc != 0) {
  ------------------
  |  Branch (63:9): [True: 4, False: 1]
  ------------------
   64|      4|        code = ntohl(code);
   65|      4|    }
   66|       |
   67|      5|    error_s = ssh_buffer_get_ssh_string(packet);
   68|      5|    if (error_s != NULL) {
  ------------------
  |  Branch (68:9): [True: 2, False: 3]
  ------------------
   69|      2|        error = ssh_string_to_char(error_s);
   70|      2|        SSH_STRING_FREE(error_s);
  ------------------
  |  |  915|      2|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 2, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 2]
  |  |  ------------------
  ------------------
   71|      2|    }
   72|       |
   73|      5|    if (error != NULL) {
  ------------------
  |  Branch (73:9): [True: 2, False: 3]
  ------------------
   74|      2|        session->peer_discon_msg = strdup(error);
   75|      2|    }
   76|       |
   77|      5|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|     10|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 2, False: 3]
  |  |  ------------------
  ------------------
   78|      5|            "Received SSH_MSG_DISCONNECT %" PRIu32 ":%s",
   79|      5|            code,
   80|      5|            error != NULL ? error : "no error");
   81|      5|    ssh_set_error(session,
  ------------------
  |  |  311|     10|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (311:43): [True: 2, False: 3]
  |  |  ------------------
  ------------------
   82|      5|                  SSH_FATAL,
   83|      5|                  "Received SSH_MSG_DISCONNECT: %" PRIu32 ":%s",
   84|      5|                  code,
   85|      5|                  error != NULL ? error : "no error");
   86|      5|    SAFE_FREE(error);
  ------------------
  |  |  373|      5|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 2, False: 3]
  |  |  |  Branch (373:71): [Folded, False: 5]
  |  |  ------------------
  ------------------
   87|       |
   88|      5|    ssh_session_socket_close(session);
   89|       |    /* correctly handle disconnect during authorization */
   90|      5|    session->auth.state = SSH_AUTH_STATE_FAILED;
   91|       |
   92|       |    /* TODO: handle a graceful disconnect */
   93|      5|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      5|#define SSH_PACKET_USED 1
  ------------------
   94|      5|}
ssh_packet_ignore_callback:
  102|    279|{
  103|    279|    (void)session; /* unused */
  104|    279|    (void)user;
  105|    279|    (void)type;
  106|    279|    (void)packet;
  107|       |
  108|    279|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_IGNORE packet");
  ------------------
  |  |  281|    279|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  109|       |
  110|    279|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    279|#define SSH_PACKET_USED 1
  ------------------
  111|    279|}
ssh_packet_debug_callback:
  119|  33.7k|{
  120|  33.7k|    uint8_t always_display = -1;
  121|  33.7k|    char *message = NULL;
  122|  33.7k|    int rc;
  123|       |
  124|  33.7k|    (void)session; /* unused */
  125|  33.7k|    (void)type;
  126|  33.7k|    (void)user;
  127|       |
  128|  33.7k|    rc = ssh_buffer_unpack(packet, "bs", &always_display, &message);
  ------------------
  |  |   60|  33.7k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  33.7k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  33.7k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  33.7k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  33.7k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  33.7k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  33.7k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  129|  33.7k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  33.7k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (129:9): [True: 28.6k, False: 5.07k]
  ------------------
  130|  28.6k|        SSH_LOG(SSH_LOG_PACKET, "Error reading debug message");
  ------------------
  |  |  281|  28.6k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  131|  28.6k|        return SSH_PACKET_USED;
  ------------------
  |  |  637|  28.6k|#define SSH_PACKET_USED 1
  ------------------
  132|  28.6k|    }
  133|  5.07k|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|  10.1k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 5.06k, False: 14]
  |  |  ------------------
  ------------------
  134|  5.07k|            "Received SSH_MSG_DEBUG packet with message %s%s",
  135|  5.07k|            message,
  136|  5.07k|            always_display != 0 ? " (always display)" : "");
  137|  5.07k|    SAFE_FREE(message);
  ------------------
  |  |  373|  5.07k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 5.07k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 5.07k]
  |  |  ------------------
  ------------------
  138|       |
  139|  5.07k|    return SSH_PACKET_USED;
  ------------------
  |  |  637|  5.07k|#define SSH_PACKET_USED 1
  ------------------
  140|  33.7k|}
ssh_packet_newkeys:
  143|     62|{
  144|     62|    ssh_string sig_blob = NULL;
  145|     62|    ssh_signature sig = NULL;
  146|     62|    int rc;
  147|       |
  148|     62|    (void)packet;
  149|     62|    (void)user;
  150|     62|    (void)type;
  151|       |
  152|     62|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_NEWKEYS");
  ------------------
  |  |  281|     62|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  153|       |
  154|     62|    if (session->session_state != SSH_SESSION_STATE_DH ||
  ------------------
  |  Branch (154:9): [True: 0, False: 62]
  ------------------
  155|     62|        session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (155:9): [True: 0, False: 62]
  ------------------
  156|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  157|      0|                      SSH_FATAL,
  158|      0|                      "ssh_packet_newkeys called in wrong state : %d:%d",
  159|      0|                      session->session_state,
  160|      0|                      session->dh_handshake_state);
  161|      0|        goto error;
  162|      0|    }
  163|       |
  164|     62|    if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|     62|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (164:9): [True: 14, False: 48]
  ------------------
  165|       |        /* reset packet sequence number when running in strict kex mode */
  166|     14|        session->recv_seq = 0;
  167|       |        /* Check that we aren't tainted */
  168|     14|        if (session->flags & SSH_SESSION_FLAG_KEX_TAINTED) {
  ------------------
  |  |   92|     14|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
  |  Branch (168:13): [True: 0, False: 14]
  ------------------
  169|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  170|      0|                          SSH_FATAL,
  171|      0|                          "Received unexpected packets in strict KEX mode.");
  172|      0|            goto error;
  173|      0|        }
  174|     14|    }
  175|       |
  176|     62|    if (session->server) {
  ------------------
  |  Branch (176:9): [True: 0, False: 62]
  ------------------
  177|       |        /* server things are done in server.c */
  178|      0|        session->dh_handshake_state=DH_STATE_FINISHED;
  179|     62|    } 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|     62|        {
  218|     62|            ssh_key server_key = NULL;
  219|       |
  220|       |            /* client */
  221|       |
  222|       |            /* Verify the host's signature. FIXME do it sooner */
  223|     62|            sig_blob = session->next_crypto->dh_server_signature;
  224|     62|            session->next_crypto->dh_server_signature = NULL;
  225|       |
  226|       |            /* get the server public key */
  227|     62|            server_key = ssh_dh_get_next_server_publickey(session);
  228|     62|            if (server_key == NULL) {
  ------------------
  |  Branch (228:17): [True: 0, False: 62]
  ------------------
  229|      0|                goto error;
  230|      0|            }
  231|       |
  232|     62|            rc = ssh_pki_import_signature_blob(sig_blob, server_key, &sig);
  233|     62|            ssh_string_burn(sig_blob);
  234|     62|            SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  915|     62|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 62, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 62]
  |  |  ------------------
  ------------------
  235|     62|            if (rc != SSH_OK) {
  ------------------
  |  |  316|     62|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (235:17): [True: 53, False: 9]
  ------------------
  236|     53|                goto error;
  237|     53|            }
  238|       |
  239|       |            /* Check if signature from server matches user preferences */
  240|      9|            if (session->opts.wanted_methods[SSH_HOSTKEYS]) {
  ------------------
  |  Branch (240:17): [True: 0, False: 9]
  ------------------
  241|      0|                rc = match_group(session->opts.wanted_methods[SSH_HOSTKEYS],
  242|      0|                                 sig->type_c);
  243|      0|                if (rc == 0) {
  ------------------
  |  Branch (243:21): [True: 0, False: 0]
  ------------------
  244|      0|                    ssh_set_error(
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  245|      0|                        session,
  246|      0|                        SSH_FATAL,
  247|      0|                        "Public key from server (%s) doesn't match user "
  248|      0|                        "preference (%s)",
  249|      0|                        sig->type_c,
  250|      0|                        session->opts.wanted_methods[SSH_HOSTKEYS]);
  251|      0|                    goto error;
  252|      0|                }
  253|      0|            }
  254|       |
  255|      9|            rc = ssh_pki_signature_verify(session,
  256|      9|                                          sig,
  257|      9|                                          server_key,
  258|      9|                                          session->next_crypto->secret_hash,
  259|      9|                                          session->next_crypto->digest_len);
  260|      9|            SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|      9|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 9]
  |  |  ------------------
  ------------------
  261|      9|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      9|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (261:17): [True: 9, False: 0]
  ------------------
  262|      9|                ssh_set_error(session,
  ------------------
  |  |  311|      9|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  263|      9|                              SSH_FATAL,
  264|      9|                              "Failed to verify server hostkey signature");
  265|      9|                goto error;
  266|      9|            }
  267|      9|        }
  268|      0|        SSH_LOG(SSH_LOG_DEBUG, "Signature verified and valid");
  ------------------
  |  |  281|      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;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  279|       |
  280|     62|error:
  281|       |#ifdef WITH_GSSAPI
  282|       |    SSH_STRING_FREE(session->gssapi_key_exchange_mic);
  283|       |#endif
  284|     62|    SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|     62|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 62]
  |  |  ------------------
  ------------------
  285|     62|    ssh_string_burn(sig_blob);
  286|     62|    SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  915|     62|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 62]
  |  |  |  Branch (915:69): [Folded, False: 62]
  |  |  ------------------
  ------------------
  287|     62|    session->session_state = SSH_SESSION_STATE_ERROR;
  288|     62|    return SSH_PACKET_USED;
  ------------------
  |  |  637|     62|#define SSH_PACKET_USED 1
  ------------------
  289|     62|}
ssh_packet_ping:
  388|      7|{
  389|      7|    int rc;
  390|      7|    ssh_string payload = NULL;
  391|       |
  392|      7|    (void)type;
  393|      7|    (void)user;
  394|       |
  395|      7|    SSH_LOG(SSH_LOG_PACKET, "Received SSH2_MSG_PING");
  ------------------
  |  |  281|      7|    _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|      7|    if (!(session->flags & SSH_SESSION_FLAG_AUTHENTICATED) &&
  ------------------
  |  |   78|      7|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (400:9): [True: 7, False: 0]
  ------------------
  401|      7|        session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (401:9): [True: 7, False: 0]
  ------------------
  402|      7|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      7|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  403|      7|                "Ignoring PING before initial key exchange is complete");
  404|      7|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      7|#define SSH_PACKET_USED 1
  ------------------
  405|      7|    }
  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");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  410|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      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;
  ------------------
  |  |  637|      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,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  419|      0|                "SSH2_MSG_PING: unexpected trailing data after payload");
  420|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  425|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      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)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  429|      0|    SSH_STRING_FREE(payload);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  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);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  432|      0|        ssh_buffer_reinit(session->out_buffer);
  433|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      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");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  439|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  440|      0|    }
  441|       |
  442|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  443|      0|}

ssh_packet_decrypt_len:
   55|  82.8k|{
   56|  82.8k|    struct ssh_crypto_struct *crypto = NULL;
   57|  82.8k|    uint32_t decrypted;
   58|  82.8k|    int rc;
   59|       |
   60|  82.8k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
   61|  82.8k|    if (crypto != NULL) {
  ------------------
  |  Branch (61:9): [True: 0, False: 82.8k]
  ------------------
   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|  82.8k|    } else {
   79|  82.8k|        memcpy(destination, source, 8);
   80|  82.8k|    }
   81|  82.8k|    memcpy(&decrypted,destination,sizeof(decrypted));
   82|       |
   83|       |    return ntohl(decrypted);
   84|  82.8k|}
ssh_packet_encrypt:
  134|  48.8k|{
  135|  48.8k|  struct ssh_crypto_struct *crypto = NULL;
  136|  48.8k|  struct ssh_cipher_struct *cipher = NULL;
  137|  48.8k|  HMACCTX ctx = NULL;
  138|  48.8k|  char *out = NULL;
  139|  48.8k|  int etm_packet_offset = 0, rc;
  140|  48.8k|  unsigned int blocksize;
  141|  48.8k|  size_t finallen = DIGEST_MAX_LEN;
  ------------------
  |  |   56|  48.8k|#define DIGEST_MAX_LEN 64
  ------------------
  142|  48.8k|  uint32_t seq, lenfield_blocksize;
  143|  48.8k|  enum ssh_hmac_e type;
  144|  48.8k|  bool etm;
  145|       |
  146|  48.8k|  assert(len);
  ------------------
  |  Branch (146:3): [True: 0, False: 48.8k]
  |  Branch (146:3): [True: 48.8k, False: 0]
  ------------------
  147|       |
  148|  48.8k|  crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
  149|  48.8k|  if (crypto == NULL) {
  ------------------
  |  Branch (149:7): [True: 43.7k, False: 5.10k]
  ------------------
  150|  43.7k|      return NULL; /* nothing to do here */
  151|  43.7k|  }
  152|       |
  153|  5.10k|  blocksize = crypto->out_cipher->blocksize;
  154|  5.10k|  lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
  155|       |
  156|  5.10k|  type = crypto->out_hmac;
  157|  5.10k|  etm = crypto->out_hmac_etm;
  158|       |
  159|  5.10k|  if (etm) {
  ------------------
  |  Branch (159:7): [True: 0, False: 5.10k]
  ------------------
  160|      0|      etm_packet_offset = sizeof(uint32_t);
  161|      0|  }
  162|       |
  163|  5.10k|  if ((len - lenfield_blocksize - etm_packet_offset) % blocksize != 0) {
  ------------------
  |  Branch (163:7): [True: 0, False: 5.10k]
  ------------------
  164|      0|      ssh_set_error(session, SSH_FATAL, "Cryptographic functions must be set"
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  165|      0|                    " on at least one blocksize (received %zu)", len);
  166|      0|      return NULL;
  167|      0|  }
  168|  5.10k|  out = calloc(1, len);
  169|  5.10k|  if (out == NULL) {
  ------------------
  |  Branch (169:7): [True: 0, False: 5.10k]
  ------------------
  170|      0|    return NULL;
  171|      0|  }
  172|       |
  173|  5.10k|  seq = ntohl(session->send_seq);
  174|  5.10k|  cipher = crypto->out_cipher;
  175|       |
  176|  5.10k|  if (cipher->aead_encrypt != NULL) {
  ------------------
  |  Branch (176:7): [True: 0, False: 5.10k]
  ------------------
  177|      0|      cipher->aead_encrypt(cipher, data, out, len,
  178|      0|            crypto->hmacbuf, session->send_seq);
  179|      0|      memcpy(data, out, len);
  180|  5.10k|  } else {
  181|  5.10k|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (181:11): [True: 0, False: 5.10k]
  ------------------
  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);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  185|      0|              return NULL;
  186|      0|          }
  187|       |
  188|      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);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  192|      0|                  return NULL;
  193|      0|              }
  194|      0|              rc = hmac_update(ctx, data, len);
  195|      0|              if (rc != 1) {
  ------------------
  |  Branch (195:19): [True: 0, False: 0]
  ------------------
  196|      0|                  SAFE_FREE(out);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  197|      0|                  return NULL;
  198|      0|              }
  199|      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);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  202|      0|                  return NULL;
  203|      0|              }
  204|      0|          }
  205|      0|      }
  206|       |
  207|  5.10k|      cipher->encrypt(cipher, (uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  208|  5.10k|      memcpy((uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  209|       |
  210|  5.10k|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (210:11): [True: 0, False: 5.10k]
  ------------------
  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);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  216|      0|                  return NULL;
  217|      0|              }
  218|      0|              rc = hmac_update(ctx, data, len);
  219|      0|              if (rc != 1) {
  ------------------
  |  Branch (219:19): [True: 0, False: 0]
  ------------------
  220|      0|                  SAFE_FREE(out);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  221|      0|                  return NULL;
  222|      0|              }
  223|      0|              rc = hmac_final(ctx, crypto->hmacbuf, &finallen);
  224|      0|              if (rc != 1) {
  ------------------
  |  Branch (224:19): [True: 0, False: 0]
  ------------------
  225|      0|                  SAFE_FREE(out);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
  226|      0|                  return NULL;
  227|      0|              }
  228|      0|          }
  229|       |#ifdef DEBUG_CRYPTO
  230|       |          ssh_log_hexdump("mac: ", data, len);
  231|       |          if (finallen != hmac_digest_len(type)) {
  232|       |              printf("Final len is %zu\n", finallen);
  233|       |          }
  234|       |          ssh_log_hexdump("Packet hmac", crypto->hmacbuf, hmac_digest_len(type));
  235|       |#endif
  236|      0|      }
  237|  5.10k|  }
  238|  5.10k|  ssh_burn(out, len);
  ------------------
  |  |  388|  5.10k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  239|  5.10k|  SAFE_FREE(out);
  ------------------
  |  |  373|  5.10k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 5.10k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 5.10k]
  |  |  ------------------
  ------------------
  240|       |
  241|  5.10k|  return crypto->hmacbuf;
  242|  5.10k|}

ssh_key_new:
  113|    135|{
  114|    135|    ssh_key ptr = malloc (sizeof (struct ssh_key_struct));
  115|    135|    if (ptr == NULL) {
  ------------------
  |  Branch (115:9): [True: 0, False: 135]
  ------------------
  116|      0|        return NULL;
  117|      0|    }
  118|    135|    ZERO_STRUCTP(ptr);
  ------------------
  |  |  379|    135|#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((x), 0, sizeof(*(x))); } while(0)
  |  |  ------------------
  |  |  |  Branch (379:34): [True: 135, False: 0]
  |  |  |  Branch (379:85): [Folded, False: 135]
  |  |  ------------------
  ------------------
  119|    135|    return ptr;
  120|    135|}
ssh_key_clean:
  222|    135|{
  223|    135|    if (key == NULL)
  ------------------
  |  Branch (223:9): [True: 0, False: 135]
  ------------------
  224|      0|        return;
  225|       |
  226|    135|    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|    135|    if (key->cert != NULL) {
  ------------------
  |  Branch (235:9): [True: 11, False: 124]
  ------------------
  236|     11|        SSH_BUFFER_FREE(key->cert);
  ------------------
  |  |  957|     11|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 11, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 11]
  |  |  ------------------
  ------------------
  237|     11|    }
  238|    135|    if (is_sk_key_type(key->type)) {
  ------------------
  |  |  153|    135|    ((kt) == SSH_KEYTYPE_SK_ECDSA || (kt) == SSH_KEYTYPE_SK_ED25519 || \
  |  |  ------------------
  |  |  |  Branch (153:6): [True: 9, False: 126]
  |  |  |  Branch (153:38): [True: 4, False: 122]
  |  |  ------------------
  |  |  154|    135|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||                            \
  |  |  ------------------
  |  |  |  Branch (154:6): [True: 1, False: 121]
  |  |  ------------------
  |  |  155|    135|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01)
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 6, False: 115]
  |  |  ------------------
  ------------------
  239|     20|        ssh_string_burn(key->sk_application);
  240|     20|        ssh_string_free(key->sk_application);
  241|     20|        ssh_string_burn(key->sk_key_handle);
  242|     20|        ssh_string_free(key->sk_key_handle);
  243|     20|        ssh_string_burn(key->sk_reserved);
  244|     20|        ssh_string_free(key->sk_reserved);
  245|     20|        ssh_string_burn(key->sk_user_id);
  246|     20|        ssh_string_free(key->sk_user_id);
  247|     20|        key->sk_flags = 0;
  248|     20|    }
  249|    135|    key->cert_type = SSH_KEYTYPE_UNKNOWN;
  250|    135|    key->flags = SSH_KEY_FLAG_EMPTY;
  ------------------
  |  |   53|    135|#define SSH_KEY_FLAG_EMPTY   0x0
  ------------------
  251|    135|    key->type = SSH_KEYTYPE_UNKNOWN;
  252|    135|    key->ecdsa_nid = 0;
  253|       |    key->type_c = NULL;
  254|    135|}
ssh_key_free:
  261|  3.99k|{
  262|  3.99k|    if (key) {
  ------------------
  |  Branch (262:9): [True: 135, False: 3.85k]
  ------------------
  263|    135|        ssh_key_clean(key);
  264|       |        SAFE_FREE(key);
  ------------------
  |  |  373|    135|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 135, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 135]
  |  |  ------------------
  ------------------
  265|    135|    }
  266|  3.99k|}
ssh_key_type:
  280|      9|{
  281|      9|    if (key == NULL) {
  ------------------
  |  Branch (281:9): [True: 0, False: 9]
  ------------------
  282|      0|        return SSH_KEYTYPE_UNKNOWN;
  283|      0|    }
  284|      9|    return key->type;
  285|      9|}
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|      3|        case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (373:9): [True: 3, False: 6]
  ------------------
  374|      3|            return "rsa-sha2-512";
  375|      4|        case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (375:9): [True: 4, False: 5]
  ------------------
  376|      4|        case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (376:9): [True: 0, False: 9]
  ------------------
  377|      4|            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|    162|const char *ssh_key_type_to_char(enum ssh_keytypes_e type) {
  411|    162|  switch (type) {
  ------------------
  |  Branch (411:11): [True: 162, False: 0]
  ------------------
  412|    101|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (412:5): [True: 101, False: 61]
  ------------------
  413|    101|      return "ssh-rsa";
  414|      0|    case SSH_KEYTYPE_ECDSA:
  ------------------
  |  Branch (414:5): [True: 0, False: 162]
  ------------------
  415|      0|      return "ssh-ecdsa"; /* deprecated. invalid value */
  416|      3|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (416:5): [True: 3, False: 159]
  ------------------
  417|      3|      return "ecdsa-sha2-nistp256";
  418|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (418:5): [True: 0, False: 162]
  ------------------
  419|      0|      return "ecdsa-sha2-nistp384";
  420|      2|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (420:5): [True: 2, False: 160]
  ------------------
  421|      2|      return "ecdsa-sha2-nistp521";
  422|      9|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (422:5): [True: 9, False: 153]
  ------------------
  423|      9|      return "ssh-ed25519";
  424|      4|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (424:5): [True: 4, False: 158]
  ------------------
  425|      4|      return "ssh-rsa-cert-v01@openssh.com";
  426|      0|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (426:5): [True: 0, False: 162]
  ------------------
  427|      0|      return "ecdsa-sha2-nistp256-cert-v01@openssh.com";
  428|      0|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (428:5): [True: 0, False: 162]
  ------------------
  429|      0|      return "ecdsa-sha2-nistp384-cert-v01@openssh.com";
  430|      0|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (430:5): [True: 0, False: 162]
  ------------------
  431|      0|      return "ecdsa-sha2-nistp521-cert-v01@openssh.com";
  432|      3|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (432:5): [True: 3, False: 159]
  ------------------
  433|      3|      return "ssh-ed25519-cert-v01@openssh.com";
  434|     11|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (434:5): [True: 11, False: 151]
  ------------------
  435|     11|      return "sk-ecdsa-sha2-nistp256@openssh.com";
  436|     10|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (436:5): [True: 10, False: 152]
  ------------------
  437|     10|      return "sk-ssh-ed25519@openssh.com";
  438|      9|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (438:5): [True: 9, False: 153]
  ------------------
  439|      9|      return "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com";
  440|     10|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (440:5): [True: 10, False: 152]
  ------------------
  441|     10|      return "sk-ssh-ed25519-cert-v01@openssh.com";
  442|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (442:5): [True: 0, False: 162]
  ------------------
  443|      0|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (443:5): [True: 0, False: 162]
  ------------------
  444|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (444:5): [True: 0, False: 162]
  ------------------
  445|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (445:5): [True: 0, False: 162]
  ------------------
  446|      0|      return NULL;
  447|    162|  }
  448|       |
  449|       |  /* We should never reach this */
  450|      0|  return NULL;
  451|    162|}
ssh_key_type_and_hash_from_signature_name:
  472|     61|{
  473|     61|    size_t len;
  474|       |
  475|     61|    if (name == NULL || type == NULL || hash_type == NULL) {
  ------------------
  |  Branch (475:9): [True: 0, False: 61]
  |  Branch (475:25): [True: 0, False: 61]
  |  Branch (475:41): [True: 0, False: 61]
  ------------------
  476|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  477|      0|    }
  478|       |
  479|     61|    len = strlen(name);
  480|       |
  481|     61|    if (len == 7 && strcmp(name, "ssh-rsa") == 0) {
  ------------------
  |  Branch (481:9): [True: 7, False: 54]
  |  Branch (481:21): [True: 4, False: 3]
  ------------------
  482|      4|        *type = SSH_KEYTYPE_RSA;
  483|      4|        *hash_type = SSH_DIGEST_SHA1;
  484|      4|        return SSH_OK;
  ------------------
  |  |  316|      4|#define SSH_OK 0     /* No error */
  ------------------
  485|      4|    }
  486|       |
  487|     57|    if (len == 11 && strcmp(name, "ssh-ed25519") == 0) {
  ------------------
  |  Branch (487:9): [True: 2, False: 55]
  |  Branch (487:22): [True: 0, False: 2]
  ------------------
  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|     57|    if (len == 12) {
  ------------------
  |  Branch (493:9): [True: 11, False: 46]
  ------------------
  494|     11|        if (strcmp(name, "rsa-sha2-256") == 0) {
  ------------------
  |  Branch (494:13): [True: 2, False: 9]
  ------------------
  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|      9|        if (strcmp(name, "rsa-sha2-512") == 0) {
  ------------------
  |  Branch (499:13): [True: 3, False: 6]
  ------------------
  500|      3|            *type = SSH_KEYTYPE_RSA;
  501|      3|            *hash_type = SSH_DIGEST_SHA512;
  502|      3|            return SSH_OK;
  ------------------
  |  |  316|      3|#define SSH_OK 0     /* No error */
  ------------------
  503|      3|        }
  504|      9|    }
  505|       |
  506|     52|    if (len == 19) {
  ------------------
  |  Branch (506:9): [True: 5, False: 47]
  ------------------
  507|      5|        if (strcmp(name, "ecdsa-sha2-nistp256") == 0) {
  ------------------
  |  Branch (507:13): [True: 0, False: 5]
  ------------------
  508|      0|            *type = SSH_KEYTYPE_ECDSA_P256;
  509|      0|            *hash_type = SSH_DIGEST_SHA256;
  510|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  511|      0|        }
  512|      5|        if (strcmp(name, "ecdsa-sha2-nistp384") == 0) {
  ------------------
  |  Branch (512:13): [True: 0, False: 5]
  ------------------
  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|      5|        if (strcmp(name, "ecdsa-sha2-nistp521") == 0) {
  ------------------
  |  Branch (518:13): [True: 1, False: 4]
  ------------------
  519|      1|            *type = SSH_KEYTYPE_ECDSA_P521;
  520|      1|            *hash_type = SSH_DIGEST_SHA512;
  521|      1|            return SSH_OK;
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  522|      1|        }
  523|      5|    }
  524|       |
  525|     51|    if (len == 26 && strcmp(name, "sk-ssh-ed25519@openssh.com") == 0) {
  ------------------
  |  Branch (525:9): [True: 5, False: 46]
  |  Branch (525:22): [True: 0, False: 5]
  ------------------
  526|      0|        *type = SSH_KEYTYPE_SK_ED25519;
  527|      0|        *hash_type = SSH_DIGEST_AUTO;
  528|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  529|      0|    }
  530|       |
  531|     51|    if (len == 28 && strcmp(name, "ssh-rsa-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (531:9): [True: 3, False: 48]
  |  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|     51|    if (len == 32 && strcmp(name, "ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (537:9): [True: 3, False: 48]
  |  Branch (537:22): [True: 0, False: 3]
  ------------------
  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|     51|    if (len == 33) {
  ------------------
  |  Branch (543:9): [True: 6, False: 45]
  ------------------
  544|      6|        if (strcmp(name, "rsa-sha2-256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (544:13): [True: 1, False: 5]
  ------------------
  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|      5|        if (strcmp(name, "rsa-sha2-512-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (549:13): [True: 0, False: 5]
  ------------------
  550|      0|            *type = SSH_KEYTYPE_RSA_CERT01;
  551|      0|            *hash_type = SSH_DIGEST_SHA512;
  552|      0|            return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  553|      0|        }
  554|      5|    }
  555|       |
  556|     50|    if (len == 34 && strcmp(name, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (556:9): [True: 3, False: 47]
  |  Branch (556:22): [True: 0, False: 3]
  ------------------
  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|     50|    if (len == 40) {
  ------------------
  |  Branch (562:9): [True: 12, False: 38]
  ------------------
  563|     12|        if (strcmp(name, "ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (563:13): [True: 1, False: 11]
  ------------------
  564|      1|            *type = SSH_KEYTYPE_ECDSA_P256_CERT01;
  565|      1|            *hash_type = SSH_DIGEST_SHA256;
  566|      1|            return SSH_OK;
  ------------------
  |  |  316|      1|#define SSH_OK 0     /* No error */
  ------------------
  567|      1|        }
  568|     11|        if (strcmp(name, "ecdsa-sha2-nistp384-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (568:13): [True: 0, False: 11]
  ------------------
  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|     11|        if (strcmp(name, "ecdsa-sha2-nistp521-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (573:13): [True: 0, False: 11]
  ------------------
  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|     11|    }
  579|       |
  580|     49|    SSH_LOG(SSH_LOG_TRACE, "Unknown signature name %s", name);
  ------------------
  |  |  281|     49|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  581|     49|    return SSH_ERROR;
  ------------------
  |  |  317|     49|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  582|     50|}
ssh_key_size_allowed_rsa:
  624|      9|{
  625|      9|    int key_size = ssh_key_size(key);
  626|       |
  627|      9|    if (min_size < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|      9|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (627:9): [True: 9, False: 0]
  ------------------
  628|      9|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|      9|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 9]
  |  |  ------------------
  ------------------
  629|      0|            min_size = RSA_MIN_FIPS_KEY_SIZE;
  ------------------
  |  |   50|      0|#define RSA_MIN_FIPS_KEY_SIZE 2048
  ------------------
  630|      9|        } else {
  631|      9|            min_size = RSA_MIN_KEY_SIZE;
  ------------------
  |  |   49|      9|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  632|      9|        }
  633|      9|    }
  634|      9|    return (key_size >= min_size);
  635|      9|}
ssh_key_size_allowed:
  646|      9|{
  647|      9|    int min_size = 0;
  648|       |
  649|      9|    switch (ssh_key_type(key)) {
  650|      9|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (650:5): [True: 9, False: 0]
  ------------------
  651|      9|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (651:5): [True: 0, False: 9]
  ------------------
  652|      9|        min_size = session->opts.rsa_min_size;
  653|      9|        return ssh_key_size_allowed_rsa(min_size, key);
  654|      0|    default:
  ------------------
  |  Branch (654:5): [True: 0, False: 9]
  ------------------
  655|       |        return true;
  656|      9|    }
  657|      9|}
ssh_key_type_from_name:
  808|    220|{
  809|    220|    if (name == NULL) {
  ------------------
  |  Branch (809:9): [True: 0, False: 220]
  ------------------
  810|      0|        return SSH_KEYTYPE_UNKNOWN;
  811|      0|    }
  812|       |
  813|    220|    if (strcmp(name, "rsa") == 0) {
  ------------------
  |  Branch (813:9): [True: 1, False: 219]
  ------------------
  814|      1|        return SSH_KEYTYPE_RSA;
  815|    219|    } else if (strcmp(name, "ssh-rsa") == 0) {
  ------------------
  |  Branch (815:16): [True: 97, False: 122]
  ------------------
  816|     97|        return SSH_KEYTYPE_RSA;
  817|    122|    } else if (strcmp(name, "ssh-ecdsa") == 0
  ------------------
  |  Branch (817:16): [True: 1, False: 121]
  ------------------
  818|    121|            || strcmp(name, "ecdsa") == 0
  ------------------
  |  Branch (818:16): [True: 2, False: 119]
  ------------------
  819|    119|            || strcmp(name, "ecdsa-sha2-nistp256") == 0) {
  ------------------
  |  Branch (819:16): [True: 0, False: 119]
  ------------------
  820|      3|        return SSH_KEYTYPE_ECDSA_P256;
  821|    119|    } else if (strcmp(name, "ecdsa-sha2-nistp384") == 0) {
  ------------------
  |  Branch (821:16): [True: 0, False: 119]
  ------------------
  822|      0|        return SSH_KEYTYPE_ECDSA_P384;
  823|    119|    } else if (strcmp(name, "ecdsa-sha2-nistp521") == 0) {
  ------------------
  |  Branch (823:16): [True: 2, False: 117]
  ------------------
  824|      2|        return SSH_KEYTYPE_ECDSA_P521;
  825|    117|    } else if (strcmp(name, "ssh-ed25519") == 0){
  ------------------
  |  Branch (825:16): [True: 6, False: 111]
  ------------------
  826|      6|        return SSH_KEYTYPE_ED25519;
  827|    111|    } else if (strcmp(name, "ssh-rsa-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (827:16): [True: 4, False: 107]
  ------------------
  828|      4|        return SSH_KEYTYPE_RSA_CERT01;
  829|    107|    } else if (strcmp(name, "ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (829:16): [True: 0, False: 107]
  ------------------
  830|      0|        return SSH_KEYTYPE_ECDSA_P256_CERT01;
  831|    107|    } else if (strcmp(name, "ecdsa-sha2-nistp384-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (831:16): [True: 0, False: 107]
  ------------------
  832|      0|        return SSH_KEYTYPE_ECDSA_P384_CERT01;
  833|    107|    } else if (strcmp(name, "ecdsa-sha2-nistp521-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (833:16): [True: 0, False: 107]
  ------------------
  834|      0|        return SSH_KEYTYPE_ECDSA_P521_CERT01;
  835|    107|    } else if (strcmp(name, "ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (835:16): [True: 3, False: 104]
  ------------------
  836|      3|        return SSH_KEYTYPE_ED25519_CERT01;
  837|    104|    } else if(strcmp(name, "sk-ecdsa-sha2-nistp256@openssh.com") == 0) {
  ------------------
  |  Branch (837:15): [True: 1, False: 103]
  ------------------
  838|      1|        return SSH_KEYTYPE_SK_ECDSA;
  839|    103|    } else if(strcmp(name, "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (839:15): [True: 9, False: 94]
  ------------------
  840|      9|        return SSH_KEYTYPE_SK_ECDSA_CERT01;
  841|     94|    } else if(strcmp(name, "sk-ssh-ed25519@openssh.com") == 0) {
  ------------------
  |  Branch (841:15): [True: 0, False: 94]
  ------------------
  842|      0|        return SSH_KEYTYPE_SK_ED25519;
  843|     94|    } else if(strcmp(name, "sk-ssh-ed25519-cert-v01@openssh.com") == 0) {
  ------------------
  |  Branch (843:15): [True: 10, False: 84]
  ------------------
  844|     10|        return SSH_KEYTYPE_SK_ED25519_CERT01;
  845|     10|    }
  846|       |
  847|     84|    return SSH_KEYTYPE_UNKNOWN;
  848|    220|}
ssh_key_type_plain:
  858|     20|{
  859|     20|    switch (type) {
  860|      0|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (860:9): [True: 0, False: 20]
  ------------------
  861|      0|            return SSH_KEYTYPE_RSA;
  862|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (862:9): [True: 0, False: 20]
  ------------------
  863|      0|            return SSH_KEYTYPE_ECDSA_P256;
  864|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (864:9): [True: 0, False: 20]
  ------------------
  865|      0|            return SSH_KEYTYPE_ECDSA_P384;
  866|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (866:9): [True: 0, False: 20]
  ------------------
  867|      0|            return SSH_KEYTYPE_ECDSA_P521;
  868|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (868:9): [True: 0, False: 20]
  ------------------
  869|      0|            return SSH_KEYTYPE_ED25519;
  870|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (870:9): [True: 0, False: 20]
  ------------------
  871|      0|            return SSH_KEYTYPE_SK_ECDSA;
  872|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (872:9): [True: 0, False: 20]
  ------------------
  873|      0|            return SSH_KEYTYPE_SK_ED25519;
  874|     20|        default:
  ------------------
  |  Branch (874:9): [True: 20, False: 0]
  ------------------
  875|     20|            return type;
  876|     20|    }
  877|     20|}
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|     71|{
 1010|     71|    if (sig == NULL) {
  ------------------
  |  Branch (1010:9): [True: 62, False: 9]
  ------------------
 1011|     62|        return;
 1012|     62|    }
 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);
  ------------------
  |  |  915|      9|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 9, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 9]
  |  |  ------------------
  ------------------
 1056|       |    SAFE_FREE(sig);
  ------------------
  |  |  373|      9|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 9, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 9]
  |  |  ------------------
  ------------------
 1057|      9|}
ssh_pki_import_pubkey_blob:
 2027|    221|{
 2028|    221|    ssh_buffer buffer = NULL;
 2029|    221|    ssh_string type_s = NULL;
 2030|    221|    enum ssh_keytypes_e type;
 2031|    221|    int rc;
 2032|       |
 2033|    221|    if (key_blob == NULL || pkey == NULL) {
  ------------------
  |  Branch (2033:9): [True: 0, False: 221]
  |  Branch (2033:29): [True: 0, False: 221]
  ------------------
 2034|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2035|      0|    }
 2036|       |
 2037|    221|    buffer = ssh_buffer_new();
 2038|    221|    if (buffer == NULL) {
  ------------------
  |  Branch (2038:9): [True: 0, False: 221]
  ------------------
 2039|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2040|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2041|      0|    }
 2042|       |
 2043|    221|    rc = ssh_buffer_add_data(buffer,
 2044|    221|                             ssh_string_data(key_blob),
 2045|    221|                             (uint32_t)ssh_string_len(key_blob));
 2046|    221|    if (rc < 0) {
  ------------------
  |  Branch (2046:9): [True: 0, False: 221]
  ------------------
 2047|      0|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2048|      0|        goto fail;
 2049|      0|    }
 2050|       |
 2051|    221|    type_s = ssh_buffer_get_ssh_string(buffer);
 2052|    221|    if (type_s == NULL) {
  ------------------
  |  Branch (2052:9): [True: 1, False: 220]
  ------------------
 2053|      1|        SSH_LOG(SSH_LOG_TRACE, "Out of memory!");
  ------------------
  |  |  281|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2054|      1|        goto fail;
 2055|      1|    }
 2056|       |
 2057|    220|    type = ssh_key_type_from_name(ssh_string_get_char(type_s));
 2058|    220|    if (type == SSH_KEYTYPE_UNKNOWN) {
  ------------------
  |  Branch (2058:9): [True: 84, False: 136]
  ------------------
 2059|     84|        SSH_LOG(SSH_LOG_TRACE, "Unknown key type found!");
  ------------------
  |  |  281|     84|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2060|     84|        goto fail;
 2061|     84|    }
 2062|    136|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  915|    136|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 136, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 136]
  |  |  ------------------
  ------------------
 2063|       |
 2064|    136|    if (is_cert_type(type)) {
  ------------------
  |  |  146|    136|    ((kt) == SSH_KEYTYPE_RSA_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (146:6): [True: 4, False: 132]
  |  |  ------------------
  |  |  147|    136|     (kt) == SSH_KEYTYPE_SK_ECDSA_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (147:6): [True: 9, False: 123]
  |  |  ------------------
  |  |  148|    136|     (kt) == SSH_KEYTYPE_SK_ED25519_CERT01 ||\
  |  |  ------------------
  |  |  |  Branch (148:6): [True: 10, False: 113]
  |  |  ------------------
  |  |  149|    136|    ((kt) >= SSH_KEYTYPE_ECDSA_P256_CERT01 &&\
  |  |  ------------------
  |  |  |  Branch (149:6): [True: 4, False: 109]
  |  |  ------------------
  |  |  150|    113|     (kt) <= SSH_KEYTYPE_ED25519_CERT01))
  |  |  ------------------
  |  |  |  Branch (150:6): [True: 3, False: 1]
  |  |  ------------------
  ------------------
 2065|     26|        rc = pki_import_cert_buffer(buffer, type, pkey);
 2066|    110|    } else {
 2067|    110|        rc = pki_import_pubkey_buffer(buffer, type, pkey);
 2068|    110|    }
 2069|       |
 2070|    136|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  957|    136|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 136, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 136]
  |  |  ------------------
  ------------------
 2071|       |
 2072|    136|    return rc;
 2073|     85|fail:
 2074|     85|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  957|     85|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 85, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 85]
  |  |  ------------------
  ------------------
 2075|     85|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  915|     85|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 84, False: 1]
  |  |  |  Branch (915:69): [Folded, False: 85]
  |  |  ------------------
  ------------------
 2076|       |
 2077|     85|    return SSH_ERROR;
  ------------------
  |  |  317|     85|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2078|    220|}
ssh_pki_export_pubkey_blob:
 2666|     95|{
 2667|     95|    ssh_string blob = NULL;
 2668|       |
 2669|     95|    if (key == NULL) {
  ------------------
  |  Branch (2669:9): [True: 0, False: 95]
  ------------------
 2670|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2671|      0|    }
 2672|       |
 2673|     95|    blob = pki_key_to_blob(key, SSH_KEY_PUBLIC);
 2674|     95|    if (blob == NULL) {
  ------------------
  |  Branch (2674:9): [True: 0, False: 95]
  ------------------
 2675|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2676|      0|    }
 2677|       |
 2678|     95|    *pblob = blob;
 2679|     95|    return SSH_OK;
  ------------------
  |  |  316|     95|#define SSH_OK 0     /* No error */
  ------------------
 2680|     95|}
ssh_pki_import_signature_blob:
 2947|     62|{
 2948|     62|    ssh_signature sig = NULL;
 2949|     62|    enum ssh_keytypes_e type;
 2950|     62|    enum ssh_digest_e hash_type;
 2951|     62|    ssh_string algorithm = NULL, blob = NULL;
 2952|     62|    ssh_buffer buf = NULL;
 2953|     62|    const char *alg = NULL;
 2954|     62|    uint8_t flags = 0;
 2955|     62|    uint32_t counter = 0;
 2956|     62|    int rc;
 2957|       |
 2958|     62|    if (sig_blob == NULL || psig == NULL) {
  ------------------
  |  Branch (2958:9): [True: 0, False: 62]
  |  Branch (2958:29): [True: 0, False: 62]
  ------------------
 2959|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2960|      0|    }
 2961|       |
 2962|     62|    buf = ssh_buffer_new();
 2963|     62|    if (buf == NULL) {
  ------------------
  |  Branch (2963:9): [True: 0, False: 62]
  ------------------
 2964|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2965|      0|    }
 2966|       |
 2967|     62|    rc = ssh_buffer_add_data(buf,
 2968|     62|                             ssh_string_data(sig_blob),
 2969|     62|                             (uint32_t)ssh_string_len(sig_blob));
 2970|     62|    if (rc < 0) {
  ------------------
  |  Branch (2970:9): [True: 0, False: 62]
  ------------------
 2971|      0|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2972|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2973|      0|    }
 2974|       |
 2975|     62|    algorithm = ssh_buffer_get_ssh_string(buf);
 2976|     62|    if (algorithm == NULL) {
  ------------------
  |  Branch (2976:9): [True: 1, False: 61]
  ------------------
 2977|      1|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      1|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 1, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
 2978|      1|        return SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2979|      1|    }
 2980|       |
 2981|     61|    alg = ssh_string_get_char(algorithm);
 2982|     61|    rc = ssh_key_type_and_hash_from_signature_name(alg, &type, &hash_type);
 2983|     61|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     61|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2983:9): [True: 49, False: 12]
  ------------------
 2984|     49|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|     49|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 49, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 49]
  |  |  ------------------
  ------------------
 2985|     49|        SSH_STRING_FREE(algorithm);
  ------------------
  |  |  915|     49|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 49, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 49]
  |  |  ------------------
  ------------------
 2986|     49|        return SSH_ERROR;
  ------------------
  |  |  317|     49|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2987|     49|    }
 2988|     12|    SSH_STRING_FREE(algorithm);
  ------------------
  |  |  915|     12|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 12, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 12]
  |  |  ------------------
  ------------------
 2989|       |
 2990|     12|    blob = ssh_buffer_get_ssh_string(buf);
 2991|     12|    if (blob == NULL) {
  ------------------
  |  Branch (2991:9): [True: 1, False: 11]
  ------------------
 2992|      1|        SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      1|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 1, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
 2993|      1|        return SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2994|      1|    }
 2995|       |
 2996|     11|    if (type == SSH_KEYTYPE_SK_ECDSA ||
  ------------------
  |  Branch (2996:9): [True: 0, False: 11]
  ------------------
 2997|     11|        type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (2997:9): [True: 0, False: 11]
  ------------------
 2998|      0|        rc = ssh_buffer_unpack(buf, "bd", &flags, &counter);
  ------------------
  |  |   60|      0|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      0|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      0|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      0|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      0|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      0|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 2999|      0|        if (rc < 0) {
  ------------------
  |  Branch (2999:13): [True: 0, False: 0]
  ------------------
 3000|      0|            SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3001|      0|            SSH_STRING_FREE(blob);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3002|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3003|      0|        }
 3004|      0|    }
 3005|     11|    SSH_BUFFER_FREE(buf);
  ------------------
  |  |  957|     11|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 11, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 11]
  |  |  ------------------
  ------------------
 3006|       |
 3007|     11|    sig = pki_signature_from_blob(pubkey, blob, type, hash_type);
 3008|     11|    SSH_STRING_FREE(blob);
  ------------------
  |  |  915|     11|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 11, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 11]
  |  |  ------------------
  ------------------
 3009|     11|    if (sig == NULL) {
  ------------------
  |  Branch (3009:9): [True: 2, False: 9]
  ------------------
 3010|      2|        return SSH_ERROR;
  ------------------
  |  |  317|      2|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3011|      2|    }
 3012|       |
 3013|       |    /* Set SK specific values */
 3014|      9|    sig->sk_flags = flags;
 3015|      9|    sig->sk_counter = counter;
 3016|       |
 3017|      9|    *psig = sig;
 3018|      9|    return SSH_OK;
  ------------------
  |  |  316|      9|#define SSH_OK 0     /* No error */
  ------------------
 3019|     11|}
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 "
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3037|      0|                               "pki_key_check_hash_compatible()");
 3038|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3039|      0|    }
 3040|       |
 3041|     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: 4, False: 8]
  ------------------
 3045|      4|            if (ssh_fips_mode()) {
  ------------------
  |  |  115|      4|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 4]
  |  |  ------------------
  ------------------
 3046|      0|                SSH_LOG(SSH_LOG_TRACE, "SHA1 is not allowed in FIPS mode");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3047|      0|                return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3048|      4|            } else {
 3049|      4|                return SSH_OK;
  ------------------
  |  |  316|      4|#define SSH_OK 0     /* No error */
  ------------------
 3050|      4|            }
 3051|      4|        }
 3052|       |
 3053|      8|        if (hash_type == SSH_DIGEST_SHA256 ||
  ------------------
  |  Branch (3053:13): [True: 2, False: 6]
  ------------------
 3054|      6|            hash_type == SSH_DIGEST_SHA512)
  ------------------
  |  Branch (3054:13): [True: 6, False: 0]
  ------------------
 3055|      8|        {
 3056|      8|            return SSH_OK;
  ------------------
  |  |  316|      8|#define SSH_OK 0     /* No error */
  ------------------
 3057|      8|        }
 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);
  ------------------
  |  |  281|      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",
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3097|      0|            key->type, hash_type);
 3098|       |
 3099|      0|    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3100|     12|}
ssh_pki_signature_verify:
 3190|      9|{
 3191|      9|    int rc;
 3192|      9|    bool allowed;
 3193|      9|    enum ssh_keytypes_e key_type;
 3194|       |
 3195|      9|    if (session == NULL || sig == NULL || key == NULL || input == NULL) {
  ------------------
  |  Branch (3195:9): [True: 0, False: 9]
  |  Branch (3195:28): [True: 0, False: 9]
  |  Branch (3195:43): [True: 0, False: 9]
  |  Branch (3195:58): [True: 0, False: 9]
  ------------------
 3196|      0|        SSH_LOG(SSH_LOG_TRACE, "Bad parameter(s) provided to %s()", __func__);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3197|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3198|      0|    }
 3199|      9|    key_type = ssh_key_type_plain(key->type);
 3200|       |
 3201|      9|    SSH_LOG(SSH_LOG_FUNCTIONS,
  ------------------
  |  |  281|      9|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3202|      9|            "Going to verify a %s type signature",
 3203|      9|            sig->type_c);
 3204|       |
 3205|      9|    if (key_type != sig->type) {
  ------------------
  |  Branch (3205:9): [True: 0, False: 9]
  ------------------
 3206|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 3207|      0|                "Can not verify %s signature with %s key",
 3208|      0|                sig->type_c, key->type_c);
 3209|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3210|      0|    }
 3211|       |
 3212|      9|    allowed = ssh_key_size_allowed(session, key);
 3213|      9|    if (!allowed) {
  ------------------
  |  Branch (3213:9): [True: 3, False: 6]
  ------------------
 3214|      3|        ssh_set_error(session,
  ------------------
  |  |  311|      3|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 3215|      3|                      SSH_FATAL,
 3216|      3|                      "The '%s' key of size %d is not allowed by RSA_MIN_SIZE",
 3217|      3|                      key->type_c,
 3218|      3|                      ssh_key_size(key));
 3219|      3|        return SSH_ERROR;
  ------------------
  |  |  317|      3|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 3220|      3|    }
 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);
  ------------------
  |  |  957|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 0, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 3245|      0|        return rc;
 3246|      0|    }
 3247|       |
 3248|      6|    return pki_verify_data_signature(sig, key, input, input_len);
 3249|      6|}
pki.c:pki_import_cert_buffer:
 1877|     26|{
 1878|     26|    ssh_buffer cert = NULL;
 1879|     26|    ssh_string tmp_s = NULL;
 1880|     26|    const char *type_c = NULL;
 1881|     26|    ssh_key key = NULL;
 1882|     26|    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|     26|    cert = ssh_buffer_new();
 1890|     26|    if (cert == NULL) {
  ------------------
  |  Branch (1890:9): [True: 0, False: 26]
  ------------------
 1891|      0|        goto fail;
 1892|      0|    }
 1893|     26|    type_c = ssh_key_type_to_char(type);
 1894|     26|    tmp_s = ssh_string_from_char(type_c);
 1895|     26|    if (tmp_s == NULL) {
  ------------------
  |  Branch (1895:9): [True: 0, False: 26]
  ------------------
 1896|      0|        goto fail;
 1897|      0|    }
 1898|     26|    rc = ssh_buffer_add_ssh_string(cert, tmp_s);
 1899|     26|    SSH_STRING_FREE(tmp_s);
  ------------------
  |  |  915|     26|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 26, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 26]
  |  |  ------------------
  ------------------
 1900|     26|    if (rc != 0) {
  ------------------
  |  Branch (1900:9): [True: 0, False: 26]
  ------------------
 1901|      0|        goto fail;
 1902|      0|    }
 1903|     26|    rc = ssh_buffer_add_buffer(cert, buffer);
 1904|     26|    if (rc != 0) {
  ------------------
  |  Branch (1904:9): [True: 0, False: 26]
  ------------------
 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|     26|    tmp_s = ssh_buffer_get_ssh_string(buffer);
 1913|     26|    if (tmp_s == NULL) {
  ------------------
  |  Branch (1913:9): [True: 1, False: 25]
  ------------------
 1914|      1|        goto fail;
 1915|      1|    }
 1916|     25|    SSH_STRING_FREE(tmp_s);
  ------------------
  |  |  915|     25|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 25, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 25]
  |  |  ------------------
  ------------------
 1917|       |
 1918|     25|    switch (type) {
 1919|      3|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1919:9): [True: 3, False: 22]
  ------------------
 1920|      3|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_RSA, &key);
 1921|      3|            break;
 1922|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1922:9): [True: 0, False: 25]
  ------------------
 1923|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ECDSA_P256, &key);
 1924|      0|            break;
 1925|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1925:9): [True: 0, False: 25]
  ------------------
 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: 25]
  ------------------
 1929|      0|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ECDSA_P521, &key);
 1930|      0|            break;
 1931|      3|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1931:9): [True: 3, False: 22]
  ------------------
 1932|      3|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_ED25519, &key);
 1933|      3|            break;
 1934|      9|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1934:9): [True: 9, False: 16]
  ------------------
 1935|      9|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_SK_ECDSA, &key);
 1936|      9|            break;
 1937|     10|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1937:9): [True: 10, False: 15]
  ------------------
 1938|     10|            rc = pki_import_pubkey_buffer(buffer, SSH_KEYTYPE_SK_ED25519, &key);
 1939|     10|            break;
 1940|      0|        default:
  ------------------
  |  Branch (1940:9): [True: 0, False: 25]
  ------------------
 1941|      0|            key = ssh_key_new();
 1942|     25|    }
 1943|     25|    if (rc != 0 || key == NULL) {
  ------------------
  |  Branch (1943:9): [True: 14, False: 11]
  |  Branch (1943:20): [True: 0, False: 11]
  ------------------
 1944|     14|        goto fail;
 1945|     14|    }
 1946|       |
 1947|     11|    key->type = type;
 1948|     11|    key->type_c = type_c;
 1949|     11|    key->cert = cert;
 1950|       |
 1951|     11|    *pkey = key;
 1952|     11|    return SSH_OK;
  ------------------
  |  |  316|     11|#define SSH_OK 0     /* No error */
  ------------------
 1953|       |
 1954|     15|fail:
 1955|     15|    ssh_key_free(key);
 1956|     15|    SSH_BUFFER_FREE(cert);
  ------------------
  |  |  957|     15|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 15, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 15]
  |  |  ------------------
  ------------------
 1957|     15|    return SSH_ERROR;
  ------------------
  |  |  317|     15|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1958|     25|}
pki.c:pki_import_pubkey_buffer:
 1736|    135|{
 1737|    135|    ssh_key key = NULL;
 1738|    135|    int rc;
 1739|       |
 1740|    135|    key = ssh_key_new();
 1741|    135|    if (key == NULL) {
  ------------------
  |  Branch (1741:9): [True: 0, False: 135]
  ------------------
 1742|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1743|      0|    }
 1744|       |
 1745|    135|    key->type = type;
 1746|    135|    key->type_c = ssh_key_type_to_char(type);
 1747|    135|    key->flags = SSH_KEY_FLAG_PUBLIC;
  ------------------
  |  |   54|    135|#define SSH_KEY_FLAG_PUBLIC  0x0001
  ------------------
 1748|       |
 1749|    135|    switch (type) {
 1750|    101|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1750:9): [True: 101, False: 34]
  ------------------
 1751|    101|            {
 1752|    101|                ssh_string e = NULL;
 1753|    101|                ssh_string n = NULL;
 1754|       |
 1755|    101|                rc = ssh_buffer_unpack(buffer, "SS", &e, &n);
  ------------------
  |  |   60|    101|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|    101|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|    101|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|    101|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|    101|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|    101|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|    101|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1756|    101|                if (rc != SSH_OK) {
  ------------------
  |  |  316|    101|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1756:21): [True: 2, False: 99]
  ------------------
 1757|      2|                    SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  281|      2|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1758|      2|                    goto fail;
 1759|      2|                }
 1760|       |
 1761|     99|                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|     99|                ssh_string_burn(e);
 1767|     99|                SSH_STRING_FREE(e);
  ------------------
  |  |  915|     99|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 99, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 99]
  |  |  ------------------
  ------------------
 1768|     99|                ssh_string_burn(n);
 1769|     99|                SSH_STRING_FREE(n);
  ------------------
  |  |  915|     99|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 99, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 99]
  |  |  ------------------
  ------------------
 1770|     99|                if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     99|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1770:21): [True: 0, False: 99]
  ------------------
 1771|      0|                    SSH_LOG(SSH_LOG_TRACE, "Failed to build RSA public key");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1772|      0|                    goto fail;
 1773|      0|                }
 1774|     99|            }
 1775|     99|            break;
 1776|     99|#ifdef HAVE_ECC
 1777|     99|        case SSH_KEYTYPE_ECDSA: /* deprecated */
  ------------------
  |  Branch (1777:9): [True: 0, False: 135]
  ------------------
 1778|      3|        case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1778:9): [True: 3, False: 132]
  ------------------
 1779|      3|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1779:9): [True: 0, False: 135]
  ------------------
 1780|      5|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1780:9): [True: 2, False: 133]
  ------------------
 1781|     15|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1781:9): [True: 10, False: 125]
  ------------------
 1782|     15|            {
 1783|     15|                ssh_string e = NULL;
 1784|     15|                ssh_string i = NULL;
 1785|     15|                int nid;
 1786|       |
 1787|     15|                rc = ssh_buffer_unpack(buffer, "SS", &i, &e);
  ------------------
  |  |   60|     15|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|     15|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|     15|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|     15|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|     15|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|     15|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     15|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1788|     15|                if (rc != SSH_OK) {
  ------------------
  |  |  316|     15|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1788:21): [True: 4, False: 11]
  ------------------
 1789|      4|                    SSH_LOG(SSH_LOG_TRACE, "Unpack error");
  ------------------
  |  |  281|      4|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1790|      4|                    goto fail;
 1791|      4|                }
 1792|       |
 1793|     11|                nid = pki_key_ecdsa_nid_from_name(ssh_string_get_char(i));
 1794|     11|                SSH_STRING_FREE(i);
  ------------------
  |  |  915|     11|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 11, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 11]
  |  |  ------------------
  ------------------
 1795|     11|                if (nid == -1) {
  ------------------
  |  Branch (1795:21): [True: 8, False: 3]
  ------------------
 1796|      8|                    ssh_string_burn(e);
 1797|      8|                    SSH_STRING_FREE(e);
  ------------------
  |  |  915|      8|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 8, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 8]
  |  |  ------------------
  ------------------
 1798|      8|                    goto fail;
 1799|      8|                }
 1800|       |
 1801|      3|                rc = pki_pubkey_build_ecdsa(key, nid, e);
 1802|      3|                ssh_string_burn(e);
 1803|      3|                SSH_STRING_FREE(e);
  ------------------
  |  |  915|      3|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 3, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 3]
  |  |  ------------------
  ------------------
 1804|      3|                if (rc < 0) {
  ------------------
  |  Branch (1804:21): [True: 1, False: 2]
  ------------------
 1805|      1|                    SSH_LOG(SSH_LOG_TRACE, "Failed to build ECDSA public key");
  ------------------
  |  |  281|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1806|      1|                    goto fail;
 1807|      1|                }
 1808|       |
 1809|       |                /* Unpack SK specific parameters */
 1810|      2|                if (type == SSH_KEYTYPE_SK_ECDSA) {
  ------------------
  |  Branch (1810:21): [True: 2, False: 0]
  ------------------
 1811|      2|                    ssh_string application = ssh_buffer_get_ssh_string(buffer);
 1812|      2|                    if (application == NULL) {
  ------------------
  |  Branch (1812:25): [True: 1, False: 1]
  ------------------
 1813|      1|                        SSH_LOG(SSH_LOG_TRACE, "SK Unpack error");
  ------------------
  |  |  281|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1814|      1|                        goto fail;
 1815|      1|                    }
 1816|      1|                    key->sk_application = application;
 1817|      1|                    key->type_c = ssh_key_type_to_char(key->type);
 1818|      1|                }
 1819|      2|            }
 1820|      1|            break;
 1821|      1|#endif /* HAVE_ECC */
 1822|      9|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1822:9): [True: 9, False: 126]
  ------------------
 1823|     19|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1823:9): [True: 10, False: 125]
  ------------------
 1824|     19|        {
 1825|     19|            ssh_string pubkey = ssh_buffer_get_ssh_string(buffer);
 1826|       |
 1827|     19|            if (ssh_string_len(pubkey) != ED25519_KEY_LEN) {
  ------------------
  |  |   44|     19|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1827:17): [True: 5, False: 14]
  ------------------
 1828|      5|                SSH_LOG(SSH_LOG_TRACE, "Invalid public key length");
  ------------------
  |  |  281|      5|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1829|      5|                ssh_string_burn(pubkey);
 1830|      5|                SSH_STRING_FREE(pubkey);
  ------------------
  |  |  915|      5|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 3, False: 2]
  |  |  |  Branch (915:69): [Folded, False: 5]
  |  |  ------------------
  ------------------
 1831|      5|                goto fail;
 1832|      5|            }
 1833|       |
 1834|     14|            rc = pki_pubkey_build_ed25519(key, pubkey);
 1835|     14|            ssh_string_burn(pubkey);
 1836|     14|            SSH_STRING_FREE(pubkey);
  ------------------
  |  |  915|     14|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 14, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 14]
  |  |  ------------------
  ------------------
 1837|     14|            if (rc < 0) {
  ------------------
  |  Branch (1837:17): [True: 0, False: 14]
  ------------------
 1838|      0|                SSH_LOG(SSH_LOG_TRACE, "Failed to build ED25519 public key");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1839|      0|                goto fail;
 1840|      0|            }
 1841|       |
 1842|     14|            if (type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1842:17): [True: 7, False: 7]
  ------------------
 1843|      7|                ssh_string application = ssh_buffer_get_ssh_string(buffer);
 1844|      7|                if (application == NULL) {
  ------------------
  |  Branch (1844:21): [True: 1, False: 6]
  ------------------
 1845|      1|                    SSH_LOG(SSH_LOG_TRACE, "SK Unpack error");
  ------------------
  |  |  281|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1846|      1|                    goto fail;
 1847|      1|                }
 1848|      6|                key->sk_application = application;
 1849|      6|            }
 1850|     14|        }
 1851|     13|        break;
 1852|     13|        case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (1852:9): [True: 0, False: 135]
  ------------------
 1853|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (1853:9): [True: 0, False: 135]
  ------------------
 1854|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (1854:9): [True: 0, False: 135]
  ------------------
 1855|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (1855:9): [True: 0, False: 135]
  ------------------
 1856|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (1856:9): [True: 0, False: 135]
  ------------------
 1857|      0|        case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (1857:9): [True: 0, False: 135]
  ------------------
 1858|      0|        case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (1858:9): [True: 0, False: 135]
  ------------------
 1859|      0|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (1859:9): [True: 0, False: 135]
  ------------------
 1860|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (1860:9): [True: 0, False: 135]
  ------------------
 1861|      0|        default:
  ------------------
  |  Branch (1861:9): [True: 0, False: 135]
  ------------------
 1862|      0|            SSH_LOG(SSH_LOG_TRACE, "Unknown public key type %d", type);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1863|      0|            goto fail;
 1864|    135|    }
 1865|       |
 1866|    113|    *pkey = key;
 1867|    113|    return SSH_OK;
  ------------------
  |  |  316|    113|#define SSH_OK 0     /* No error */
  ------------------
 1868|     22|fail:
 1869|     22|    ssh_key_free(key);
 1870|       |
 1871|     22|    return SSH_ERROR;
  ------------------
  |  |  317|     22|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1872|    135|}

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

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

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

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

ssh_client_sntrup761x25519_init:
  105|     27|{
  106|     27|    int rc;
  107|       |
  108|     27|    rc = ssh_sntrup761x25519_init(session);
  109|     27|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     27|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (109:9): [True: 0, False: 27]
  ------------------
  110|      0|        return rc;
  111|      0|    }
  112|       |
  113|     27|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|     27|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|     27|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|     27|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|     27|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|     27|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|     27|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     27|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  114|     27|                         "bdPP",
  115|     27|                         SSH2_MSG_KEX_ECDH_INIT,
  116|     27|                         CURVE25519_PUBKEY_SIZE + SNTRUP761_PUBLICKEY_SIZE,
  117|     27|                         (size_t)SNTRUP761_PUBLICKEY_SIZE,
  118|     27|                         session->next_crypto->sntrup761_client_pubkey,
  119|     27|                         (size_t)CURVE25519_PUBKEY_SIZE,
  120|     27|                         session->next_crypto->curve25519_client_pubkey);
  121|     27|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     27|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (121:9): [True: 0, False: 27]
  ------------------
  122|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      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|     27|    ssh_packet_set_callbacks(session, &ssh_sntrup761x25519_client_callbacks);
  128|     27|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  129|     27|    rc = ssh_packet_send(session);
  130|       |
  131|     27|    return rc;
  132|     27|}
ssh_client_sntrup761x25519_remove_callbacks:
  135|     19|{
  136|     19|    ssh_packet_remove_callbacks(session, &ssh_sntrup761x25519_client_callbacks);
  137|     19|}
sntrup761.c:ssh_sntrup761x25519_init:
   62|     27|{
   63|     27|    int rc;
   64|       |
   65|     27|    rc = ssh_curve25519_init(session);
   66|     27|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     27|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (66:9): [True: 0, False: 27]
  ------------------
   67|      0|        return rc;
   68|      0|    }
   69|       |
   70|     27|    if (!session->server) {
  ------------------
  |  Branch (70:9): [True: 27, 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|     27|        sntrup761_keypair(session->next_crypto->sntrup761_client_pubkey,
   87|     27|                          session->next_crypto->sntrup761_privkey,
   88|     27|                          &rc,
   89|     27|                          crypto_random);
   90|     27|        if (rc != 1) {
  ------------------
  |  Branch (90:13): [True: 0, False: 27]
  ------------------
   91|      0|            SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      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|     27|#endif /* HAVE_LIBGCRYPT */
   96|     27|    }
   97|       |
   98|     27|    return SSH_OK;
  ------------------
  |  |  316|     27|#define SSH_OK 0     /* No error */
  ------------------
   99|     27|}
sntrup761.c:crypto_random:
   41|  41.1k|{
   42|  41.1k|    int *err = ctx;
   43|  41.1k|    *err = ssh_get_random(dst, length, 1);
   44|  41.1k|}
sntrup761.c:ssh_packet_client_sntrup761x25519_reply:
  248|     19|{
  249|     19|    ssh_string q_s_string = NULL;
  250|     19|    ssh_string pubkey_blob = NULL;
  251|     19|    ssh_string signature = NULL;
  252|     19|    int rc;
  253|     19|    (void)type;
  254|     19|    (void)user;
  255|       |
  256|     19|    ssh_client_sntrup761x25519_remove_callbacks(session);
  257|       |
  258|     19|    pubkey_blob = ssh_buffer_get_ssh_string(packet);
  259|     19|    if (pubkey_blob == NULL) {
  ------------------
  |  Branch (259:9): [True: 2, False: 17]
  ------------------
  260|      2|        ssh_set_error(session, SSH_FATAL, "No public key in packet");
  ------------------
  |  |  311|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  261|      2|        goto error;
  262|      2|    }
  263|       |
  264|     17|    rc = ssh_dh_import_next_pubkey_blob(session, pubkey_blob);
  265|     17|    SSH_STRING_FREE(pubkey_blob);
  ------------------
  |  |  915|     17|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 17, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 17]
  |  |  ------------------
  ------------------
  266|     17|    if (rc != 0) {
  ------------------
  |  Branch (266:9): [True: 15, False: 2]
  ------------------
  267|     15|        ssh_set_error(session, SSH_FATAL, "Failed to import next public key");
  ------------------
  |  |  311|     15|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  268|     15|        goto error;
  269|     15|    }
  270|       |
  271|      2|    q_s_string = ssh_buffer_get_ssh_string(packet);
  272|      2|    if (q_s_string == NULL) {
  ------------------
  |  Branch (272:9): [True: 1, False: 1]
  ------------------
  273|      1|        ssh_set_error(session, SSH_FATAL, "No sntrup761x25519 Q_S in packet");
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  274|      1|        goto error;
  275|      1|    }
  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,
  ------------------
  |  |  311|      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);
  ------------------
  |  |  915|      1|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 1, False: 0]
  |  |  |  Branch (915: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);
  ------------------
  |  |  915|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (915:14): [True: 0, False: 0]
  |  |  |  Branch (915:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  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");
  ------------------
  |  |  311|      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");
  ------------------
  |  |  311|      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");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  316|      0|    session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
  317|       |
  318|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  319|       |
  320|     19|error:
  321|     19|    session->session_state = SSH_SESSION_STATE_ERROR;
  322|     19|    return SSH_PACKET_USED;
  ------------------
  |  |  637|     19|#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.30k|{
  183|  1.30k|    ssh_socket s;
  184|       |
  185|  1.30k|    s = calloc(1, sizeof(struct ssh_socket_struct));
  186|  1.30k|    if (s == NULL) {
  ------------------
  |  Branch (186:9): [True: 64, False: 1.24k]
  ------------------
  187|     64|        ssh_set_error_oom(session);
  ------------------
  |  |  318|     64|    _ssh_set_error_oom(error, __func__)
  ------------------
  188|     64|        return NULL;
  189|     64|    }
  190|  1.24k|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|  1.24k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  191|  1.24k|    s->last_errno = -1;
  192|  1.24k|    s->fd_is_socket = 1;
  193|  1.24k|    s->session = session;
  194|  1.24k|    s->in_buffer = ssh_buffer_new();
  195|  1.24k|    if (s->in_buffer == NULL) {
  ------------------
  |  Branch (195:9): [True: 61, False: 1.17k]
  ------------------
  196|     61|        ssh_set_error_oom(session);
  ------------------
  |  |  318|     61|    _ssh_set_error_oom(error, __func__)
  ------------------
  197|     61|        SAFE_FREE(s);
  ------------------
  |  |  373|     61|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 61, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 61]
  |  |  ------------------
  ------------------
  198|     61|        return NULL;
  199|     61|    }
  200|  1.17k|    s->out_buffer=ssh_buffer_new();
  201|  1.17k|    if (s->out_buffer == NULL) {
  ------------------
  |  Branch (201:9): [True: 17, False: 1.16k]
  ------------------
  202|     17|        ssh_set_error_oom(session);
  ------------------
  |  |  318|     17|    _ssh_set_error_oom(error, __func__)
  ------------------
  203|     17|        SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  957|     17|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 17, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 17]
  |  |  ------------------
  ------------------
  204|     17|        SAFE_FREE(s);
  ------------------
  |  |  373|     17|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 17, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 17]
  |  |  ------------------
  ------------------
  205|     17|        return NULL;
  206|     17|    }
  207|  1.16k|    s->read_wontblock = 0;
  208|  1.16k|    s->write_wontblock = 0;
  209|  1.16k|    s->data_except = 0;
  210|       |    s->poll_handle = NULL;
  211|  1.16k|    s->state=SSH_SOCKET_NONE;
  212|  1.16k|    return s;
  213|  1.17k|}
ssh_socket_reset:
  226|    579|{
  227|    579|    s->fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|    579|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  228|    579|    s->last_errno = -1;
  229|    579|    s->fd_is_socket = 1;
  230|    579|    ssh_buffer_reinit(s->in_buffer);
  231|    579|    ssh_buffer_reinit(s->out_buffer);
  232|    579|    s->read_wontblock = 0;
  233|    579|    s->write_wontblock = 0;
  234|    579|    s->data_except = 0;
  235|    579|    if (s->poll_handle != NULL) {
  ------------------
  |  Branch (235:9): [True: 579, False: 0]
  ------------------
  236|    579|        ssh_poll_free(s->poll_handle);
  237|       |        s->poll_handle = NULL;
  238|    579|    }
  239|    579|    s->state=SSH_SOCKET_NONE;
  240|    579|#ifndef _WIN32
  241|    579|    s->proxy_pid = 0;
  242|    579|#endif
  243|    579|}
ssh_socket_set_callbacks:
  253|  1.08k|{
  254|  1.08k|    s->callbacks = callbacks;
  255|  1.08k|}
ssh_socket_set_connected:
  269|    579|{
  270|    579|    s->state = SSH_SOCKET_CONNECTED;
  271|       |    /* `POLLOUT` is the event to wait for in a non-blocking connect */
  272|    579|    if (p != NULL) {
  ------------------
  |  Branch (272:9): [True: 579, False: 0]
  ------------------
  273|    579|        ssh_poll_set_events(p, POLLIN | POLLOUT);
  274|    579|    }
  275|    579|}
ssh_socket_pollcallback:
  296|  2.27k|{
  297|  2.27k|    ssh_socket s = (ssh_socket)v_s;
  298|  2.27k|    void *buffer = NULL;
  299|  2.27k|    ssize_t nread = 0;
  300|  2.27k|    int rc;
  301|  2.27k|    int err = 0;
  302|  2.27k|    socklen_t errlen = sizeof(err);
  303|       |
  304|       |    /* Do not do anything if this socket was already closed */
  305|  2.27k|    if (!ssh_socket_is_open(s)) {
  ------------------
  |  Branch (305:9): [True: 0, False: 2.27k]
  ------------------
  306|      0|        return -1;
  307|      0|    }
  308|  2.27k|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|  13.6k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 2.27k, False: 0]
  |  |  |  Branch (281:34): [True: 2.21k, False: 62]
  |  |  |  Branch (281:34): [True: 0, False: 2.27k]
  |  |  ------------------
  ------------------
  309|  2.27k|            "Poll callback on socket %d (%s%s%s), out buffer %" PRIu32, fd,
  310|  2.27k|            (revents & POLLIN) ? "POLLIN ":"",
  311|  2.27k|            (revents & POLLOUT) ? "POLLOUT ":"",
  312|  2.27k|            (revents & POLLERR) ? "POLLERR":"",
  313|  2.27k|            ssh_buffer_get_len(s->out_buffer));
  314|  2.27k|    if ((revents & POLLERR) || (revents & POLLHUP)) {
  ------------------
  |  Branch (314:9): [True: 0, False: 2.27k]
  |  Branch (314:32): [True: 0, False: 2.27k]
  ------------------
  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,
  ------------------
  |  |  524|      0|#define SSH_SOCKET_CONNECTED_ERROR 		2
  ------------------
  329|      0|                                        err,
  330|      0|                                        s->callbacks->userdata);
  331|      0|            }
  332|       |
  333|      0|            return -1;
  334|      0|        }
  335|       |        /* Then we are in a more standard kind of error */
  336|       |        /* force a read to get an explanation */
  337|      0|        revents |= POLLIN;
  338|      0|    }
  339|  2.27k|    if ((revents & POLLIN) && s->state == SSH_SOCKET_CONNECTED) {
  ------------------
  |  Branch (339:9): [True: 2.27k, False: 0]
  |  Branch (339:31): [True: 1.69k, False: 579]
  ------------------
  340|  1.69k|        s->read_wontblock = 1;
  341|  1.69k|        buffer = ssh_buffer_allocate(s->in_buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|  1.69k|#define MAX_BUF_SIZE 4096
  ------------------
  342|  1.69k|        if (buffer) {
  ------------------
  |  Branch (342:13): [True: 1.69k, False: 0]
  ------------------
  343|  1.69k|            nread = ssh_socket_unbuffered_read(s, buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|  1.69k|#define MAX_BUF_SIZE 4096
  ------------------
  344|  1.69k|        }
  345|  1.69k|        if (nread < 0) {
  ------------------
  |  Branch (345:13): [True: 0, False: 1.69k]
  ------------------
  346|      0|            ssh_buffer_pass_bytes_end(s->in_buffer, MAX_BUF_SIZE);
  ------------------
  |  |  230|      0|#define MAX_BUF_SIZE 4096
  ------------------
  347|      0|            if (p != NULL) {
  ------------------
  |  Branch (347:17): [True: 0, False: 0]
  ------------------
  348|      0|                ssh_poll_remove_events(p, POLLIN);
  349|      0|            }
  350|       |
  351|      0|            if (s->callbacks != NULL && s->callbacks->exception != NULL) {
  ------------------
  |  Branch (351:17): [True: 0, False: 0]
  |  Branch (351:41): [True: 0, False: 0]
  ------------------
  352|      0|                s->callbacks->exception(SSH_SOCKET_EXCEPTION_ERROR,
  ------------------
  |  |  521|      0|#define SSH_SOCKET_EXCEPTION_ERROR     2
  ------------------
  353|      0|                                        s->last_errno,
  354|      0|                                        s->callbacks->userdata);
  355|      0|            }
  356|      0|            return -2;
  357|      0|        }
  358|       |
  359|       |        /* Rollback the unused space */
  360|  1.69k|        ssh_buffer_pass_bytes_end(s->in_buffer,
  361|  1.69k|                                  (uint32_t)(MAX_BUF_SIZE - nread));
  ------------------
  |  |  230|  1.69k|#define MAX_BUF_SIZE 4096
  ------------------
  362|       |
  363|  1.69k|        if (nread == 0) {
  ------------------
  |  Branch (363:13): [True: 183, False: 1.51k]
  ------------------
  364|    183|            if (p != NULL) {
  ------------------
  |  Branch (364:17): [True: 183, False: 0]
  ------------------
  365|    183|                ssh_poll_remove_events(p, POLLIN);
  366|    183|            }
  367|    183|            if (s->callbacks != NULL && s->callbacks->exception != NULL) {
  ------------------
  |  Branch (367:17): [True: 183, False: 0]
  |  Branch (367:41): [True: 183, False: 0]
  ------------------
  368|    183|                s->callbacks->exception(SSH_SOCKET_EXCEPTION_EOF,
  ------------------
  |  |  520|    183|#define SSH_SOCKET_EXCEPTION_EOF 	     1
  ------------------
  369|    183|                                        0,
  370|    183|                                        s->callbacks->userdata);
  371|    183|            }
  372|    183|            return -2;
  373|    183|        }
  374|       |
  375|  1.51k|        if (s->session->socket_counter != NULL) {
  ------------------
  |  Branch (375:13): [True: 0, False: 1.51k]
  ------------------
  376|      0|            s->session->socket_counter->in_bytes += nread;
  377|      0|        }
  378|       |
  379|       |        /* Call the callback */
  380|  1.51k|        if (s->callbacks != NULL && s->callbacks->data != NULL) {
  ------------------
  |  Branch (380:13): [True: 1.51k, False: 0]
  |  Branch (380:37): [True: 1.51k, False: 0]
  ------------------
  381|  1.51k|            size_t processed;
  382|   398k|            do {
  383|   398k|                processed = s->callbacks->data(ssh_buffer_get(s->in_buffer),
  384|   398k|                                               ssh_buffer_get_len(s->in_buffer),
  385|   398k|                                               s->callbacks->userdata);
  386|   398k|                ssh_buffer_pass_bytes(s->in_buffer, (uint32_t)processed);
  387|   398k|            } while ((processed > 0) && (s->state == SSH_SOCKET_CONNECTED));
  ------------------
  |  Branch (387:22): [True: 396k, False: 1.51k]
  |  Branch (387:41): [True: 396k, False: 0]
  ------------------
  388|       |
  389|       |            /* p may have been freed, so don't use it
  390|       |             * anymore in this function */
  391|  1.51k|            p = NULL;
  392|  1.51k|        }
  393|  1.51k|    }
  394|       |#ifdef _WIN32
  395|       |    if (revents & POLLOUT || revents & POLLWRNORM) {
  396|       |#else
  397|  2.09k|    if (revents & POLLOUT) {
  ------------------
  |  Branch (397:9): [True: 2.03k, False: 58]
  ------------------
  398|  2.03k|#endif
  399|  2.03k|        uint32_t len;
  400|       |
  401|       |        /* First, POLLOUT is a sign we may be connected */
  402|  2.03k|        if (s->state == SSH_SOCKET_CONNECTING) {
  ------------------
  |  Branch (402:13): [True: 579, False: 1.45k]
  ------------------
  403|    579|            SSH_LOG(SSH_LOG_PACKET, "Received POLLOUT in connecting state");
  ------------------
  |  |  281|    579|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  404|    579|            ssh_socket_set_connected(s, p);
  405|       |
  406|    579|            rc = ssh_socket_set_blocking(ssh_socket_get_fd(s));
  407|    579|            if (rc < 0) {
  ------------------
  |  Branch (407:17): [True: 0, False: 579]
  ------------------
  408|      0|                return -1;
  409|      0|            }
  410|       |
  411|    579|            if (s->callbacks != NULL && s->callbacks->connected != NULL) {
  ------------------
  |  Branch (411:17): [True: 579, False: 0]
  |  Branch (411:41): [True: 579, False: 0]
  ------------------
  412|    579|                s->callbacks->connected(SSH_SOCKET_CONNECTED_OK,
  ------------------
  |  |  523|    579|#define SSH_SOCKET_CONNECTED_OK 			1
  ------------------
  413|    579|                                        0,
  414|    579|                                        s->callbacks->userdata);
  415|    579|            }
  416|       |
  417|    579|            return 0;
  418|    579|        }
  419|       |
  420|       |        /* So, we can write data */
  421|  1.45k|        s->write_wontblock = 1;
  422|  1.45k|        if (p != NULL) {
  ------------------
  |  Branch (422:13): [True: 0, False: 1.45k]
  ------------------
  423|      0|            ssh_poll_remove_events(p, POLLOUT);
  424|      0|        }
  425|       |
  426|       |        /* If buffered data is pending, write it */
  427|  1.45k|        len = ssh_buffer_get_len(s->out_buffer);
  428|  1.45k|        if (len > 0) {
  ------------------
  |  Branch (428:13): [True: 695, False: 763]
  ------------------
  429|    695|            ssh_socket_nonblocking_flush(s);
  430|    763|        } else if (s->callbacks != NULL && s->callbacks->controlflow != NULL) {
  ------------------
  |  Branch (430:20): [True: 763, False: 0]
  |  Branch (430:44): [True: 306, False: 457]
  ------------------
  431|       |            /* Otherwise advertise the upper level that write can be done */
  432|    306|            SSH_LOG(SSH_LOG_TRACE, "sending control flow event");
  ------------------
  |  |  281|    306|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  433|    306|            s->callbacks->controlflow(SSH_SOCKET_FLOW_WRITEWONTBLOCK,
  ------------------
  |  |  518|    306|#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
  ------------------
  434|    306|                                      s->callbacks->userdata);
  435|    306|        }
  436|       |        /* TODO: Find a way to put back POLLOUT when buffering occurs */
  437|  1.45k|    }
  438|       |
  439|       |    /* Return -1 if the poll handler disappeared */
  440|  1.51k|    if (s->poll_handle == NULL) {
  ------------------
  |  Branch (440:9): [True: 0, False: 1.51k]
  ------------------
  441|      0|        return -1;
  442|      0|    }
  443|       |
  444|  1.51k|    return 0;
  445|  1.51k|}
ssh_socket_get_poll_handle:
  454|  2.85k|{
  455|  2.85k|    if (s->poll_handle) {
  ------------------
  |  Branch (455:9): [True: 2.27k, False: 579]
  ------------------
  456|  2.27k|        return s->poll_handle;
  457|  2.27k|    }
  458|    579|    s->poll_handle = ssh_poll_new(s->fd, 0, ssh_socket_pollcallback, s);
  459|    579|    return s->poll_handle;
  460|  2.85k|}
ssh_socket_free:
  473|  1.46k|{
  474|  1.46k|    if (s == NULL) {
  ------------------
  |  Branch (474:9): [True: 301, False: 1.16k]
  ------------------
  475|    301|        return;
  476|    301|    }
  477|  1.16k|    ssh_socket_close(s);
  478|  1.16k|    SSH_BUFFER_FREE(s->in_buffer);
  ------------------
  |  |  957|  1.16k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 1.16k, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 1.16k]
  |  |  ------------------
  ------------------
  479|  1.16k|    SSH_BUFFER_FREE(s->out_buffer);
  ------------------
  |  |  957|  1.16k|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (957:14): [True: 1.16k, False: 0]
  |  |  |  Branch (957:69): [Folded, False: 1.16k]
  |  |  ------------------
  ------------------
  480|       |    SAFE_FREE(s);
  ------------------
  |  |  373|  1.16k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 1.16k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 1.16k]
  |  |  ------------------
  ------------------
  481|  1.16k|}
ssh_socket_close:
  546|  1.74k|{
  547|  1.74k|    if (ssh_socket_is_open(s)) {
  ------------------
  |  Branch (547:9): [True: 0, False: 1.74k]
  ------------------
  548|       |#ifdef _WIN32
  549|       |        CLOSE_SOCKET(s->fd);
  550|       |        s->last_errno = WSAGetLastError();
  551|       |#else
  552|      0|        CLOSE_SOCKET(s->fd);
  ------------------
  |  |  472|      0|#define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |               #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  199|      0|#define _XCLOSESOCKET close
  |  |  ------------------
  |  |               #define CLOSE_SOCKET(s) do { if ((s) != SSH_INVALID_SOCKET) { _XCLOSESOCKET(s); (s) = SSH_INVALID_SOCKET;} } while(0)
  |  |  ------------------
  |  |  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  |  |  ------------------
  |  |  |  Branch (472:34): [True: 0, False: 0]
  |  |  |  Branch (472:116): [Folded, False: 0]
  |  |  ------------------
  ------------------
  553|      0|        s->last_errno = errno;
  554|      0|#endif
  555|      0|    }
  556|       |
  557|  1.74k|    if (s->poll_handle != NULL && !ssh_poll_is_locked(s->poll_handle)) {
  ------------------
  |  Branch (557:9): [True: 0, False: 1.74k]
  |  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.74k|    s->state = SSH_SOCKET_CLOSED;
  563|       |
  564|  1.74k|#ifndef _WIN32
  565|       |    /* If the proxy command still runs try to kill it */
  566|  1.74k|    if (s->proxy_pid != 0) {
  ------------------
  |  Branch (566:9): [True: 0, False: 1.74k]
  ------------------
  567|      0|        int status;
  568|      0|        pid_t pid = s->proxy_pid;
  569|       |
  570|      0|        s->proxy_pid = 0;
  571|      0|        kill(pid, SIGTERM);
  572|      0|        while (waitpid(pid, &status, 0) == -1) {
  ------------------
  |  Branch (572:16): [True: 0, False: 0]
  ------------------
  573|      0|            if (errno != EINTR) {
  ------------------
  |  Branch (573:17): [True: 0, False: 0]
  ------------------
  574|      0|                SSH_LOG_STRERROR(SSH_LOG_TRACE, errno, "waitpid failed: %s");
  ------------------
  |  |  283|      0|    do {                                                            \
  |  |  284|      0|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|      0|        _ssh_log(priority,                                          \
  |  |  286|      0|                 __func__,                                          \
  |  |  287|      0|                 __VA_ARGS__,                                       \
  |  |  288|      0|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|      0|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
  575|      0|                return;
  576|      0|            }
  577|      0|        }
  578|      0|        if (!WIFEXITED(status)) {
  ------------------
  |  Branch (578:13): [True: 0, False: 0]
  ------------------
  579|      0|            SSH_LOG(SSH_LOG_TRACE, "Proxy command exited abnormally");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  580|      0|            return;
  581|      0|        }
  582|      0|        SSH_LOG(SSH_LOG_TRACE, "Proxy command returned %d", WEXITSTATUS(status));
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  583|      0|    }
  584|  1.74k|#endif
  585|  1.74k|}
ssh_socket_set_fd:
  596|    579|{
  597|    579|    ssh_poll_handle h = NULL;
  598|       |
  599|    579|    s->fd = fd;
  600|       |
  601|    579|    if (s->poll_handle) {
  ------------------
  |  Branch (601:9): [True: 0, False: 579]
  ------------------
  602|      0|        ssh_poll_set_fd(s->poll_handle,fd);
  603|    579|    } else {
  604|    579|        s->state = SSH_SOCKET_CONNECTING;
  605|    579|        h = ssh_socket_get_poll_handle(s);
  606|    579|        if (h == NULL) {
  ------------------
  |  Branch (606:13): [True: 0, False: 579]
  ------------------
  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|    579|        ssh_poll_set_events(h, POLLOUT);
  612|       |#ifdef _WIN32
  613|       |        ssh_poll_add_events(h, POLLWRNORM);
  614|       |#endif
  615|    579|    }
  616|    579|    return SSH_OK;
  ------------------
  |  |  316|    579|#define SSH_OK 0     /* No error */
  ------------------
  617|    579|}
ssh_socket_get_fd:
  629|    579|{
  630|    579|    return s->fd;
  631|    579|}
ssh_socket_is_open:
  643|   103k|{
  644|   103k|    return s->fd != SSH_INVALID_SOCKET;
  ------------------
  |  |  124|   103k|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  645|   103k|}
ssh_socket_write:
  811|  49.4k|{
  812|  49.4k|    if (len > 0) {
  ------------------
  |  Branch (812:9): [True: 49.4k, False: 0]
  ------------------
  813|  49.4k|        if (ssh_buffer_add_data(s->out_buffer, buffer, len) < 0) {
  ------------------
  |  Branch (813:13): [True: 0, False: 49.4k]
  ------------------
  814|      0|            ssh_set_error_oom(s->session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  815|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  816|      0|        }
  817|  49.4k|        ssh_socket_nonblocking_flush(s);
  818|  49.4k|    }
  819|       |
  820|  49.4k|    return SSH_OK;
  ------------------
  |  |  316|  49.4k|#define SSH_OK 0     /* No error */
  ------------------
  821|  49.4k|}
ssh_socket_nonblocking_flush:
  841|  50.1k|{
  842|  50.1k|    ssh_session session = s->session;
  843|  50.1k|    uint32_t len;
  844|       |
  845|  50.1k|    if (!ssh_socket_is_open(s)) {
  ------------------
  |  Branch (845:9): [True: 0, False: 50.1k]
  ------------------
  846|      0|        session->alive = 0;
  847|      0|        if (s->callbacks && s->callbacks->exception) {
  ------------------
  |  Branch (847:13): [True: 0, False: 0]
  |  Branch (847:29): [True: 0, False: 0]
  ------------------
  848|      0|            s->callbacks->exception(SSH_SOCKET_EXCEPTION_ERROR,
  ------------------
  |  |  521|      0|#define SSH_SOCKET_EXCEPTION_ERROR     2
  ------------------
  849|      0|                                    s->last_errno,
  850|      0|                                    s->callbacks->userdata);
  851|      0|        } else {
  852|      0|            char err_msg[SSH_ERRNO_MSG_MAX] = {0};
  853|      0|            ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  854|      0|                          SSH_FATAL,
  855|      0|                          "Writing packet: error on socket (or connection "
  856|      0|                          "closed): %s",
  857|      0|                          ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
  858|      0|        }
  859|       |
  860|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  861|      0|    }
  862|       |
  863|  50.1k|    len = ssh_buffer_get_len(s->out_buffer);
  864|  50.1k|    if (!s->write_wontblock && s->poll_handle && len > 0) {
  ------------------
  |  Branch (864:9): [True: 48.7k, False: 1.40k]
  |  Branch (864:32): [True: 48.7k, False: 0]
  |  Branch (864:50): [True: 48.7k, False: 0]
  ------------------
  865|       |        /* force the poll system to catch pollout events */
  866|  48.7k|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  867|       |
  868|  48.7k|        return SSH_AGAIN;
  ------------------
  |  |  318|  48.7k|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  869|  48.7k|    }
  870|       |
  871|  1.40k|    if (s->write_wontblock && len > 0) {
  ------------------
  |  Branch (871:9): [True: 1.40k, False: 0]
  |  Branch (871:31): [True: 1.40k, False: 0]
  ------------------
  872|  1.40k|        ssize_t bwritten;
  873|       |
  874|  1.40k|        bwritten = ssh_socket_unbuffered_write(s,
  875|  1.40k|                                               ssh_buffer_get(s->out_buffer),
  876|  1.40k|                                               len);
  877|  1.40k|        if (bwritten < 0) {
  ------------------
  |  Branch (877:13): [True: 0, False: 1.40k]
  ------------------
  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,
  ------------------
  |  |  521|      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,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  888|      0|                              SSH_FATAL,
  889|      0|                              "Writing packet: error on socket (or connection "
  890|      0|                              "closed): %s",
  891|      0|                              ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
  892|      0|            }
  893|       |
  894|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  895|      0|        }
  896|       |
  897|  1.40k|        ssh_buffer_pass_bytes(s->out_buffer, (uint32_t)bwritten);
  898|  1.40k|        if (s->session->socket_counter != NULL) {
  ------------------
  |  Branch (898:13): [True: 0, False: 1.40k]
  ------------------
  899|      0|            s->session->socket_counter->out_bytes += bwritten;
  900|      0|        }
  901|  1.40k|    }
  902|       |
  903|       |    /* Is there some data pending? */
  904|  1.40k|    len = ssh_buffer_get_len(s->out_buffer);
  905|  1.40k|    if (s->poll_handle && len > 0) {
  ------------------
  |  Branch (905:9): [True: 1.40k, False: 0]
  |  Branch (905:27): [True: 0, False: 1.40k]
  ------------------
  906|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  907|      0|                "did not send all the data, queuing pollout event");
  908|       |        /* force the poll system to catch pollout events */
  909|      0|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  910|       |
  911|      0|        return SSH_AGAIN;
  ------------------
  |  |  318|      0|#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
  ------------------
  912|      0|    }
  913|       |
  914|       |    /* all data written */
  915|  1.40k|    return SSH_OK;
  ------------------
  |  |  316|  1.40k|#define SSH_OK 0     /* No error */
  ------------------
  916|  1.40k|}
ssh_socket_set_write_wontblock:
  929|    579|{
  930|    579|    s->write_wontblock = 1;
  931|    579|}
ssh_socket_set_blocking:
 1114|    579|{
 1115|       |    return fcntl(fd, F_SETFL, 0);
 1116|    579|}
socket.c:ssh_socket_unbuffered_read:
  665|  1.69k|{
  666|  1.69k|    ssize_t rc = -1;
  667|       |
  668|  1.69k|    if (s->data_except) {
  ------------------
  |  Branch (668:9): [True: 0, False: 1.69k]
  ------------------
  669|      0|        return -1;
  670|      0|    }
  671|  1.69k|    if (s->fd_is_socket) {
  ------------------
  |  Branch (671:9): [True: 1.69k, False: 0]
  ------------------
  672|  1.69k|        rc = recv(s->fd, buffer, len, 0);
  673|  1.69k|    } else {
  674|      0|        rc = read(s->fd, buffer, len);
  675|      0|    }
  676|       |#ifdef _WIN32
  677|       |    s->last_errno = WSAGetLastError();
  678|       |#else
  679|  1.69k|    s->last_errno = errno;
  680|  1.69k|#endif
  681|  1.69k|    s->read_wontblock = 0;
  682|       |
  683|  1.69k|    if (rc < 0) {
  ------------------
  |  Branch (683:9): [True: 0, False: 1.69k]
  ------------------
  684|      0|        s->data_except = 1;
  685|  1.69k|    } else {
  686|  1.69k|        SSH_LOG(SSH_LOG_TRACE, "read %zd", rc);
  ------------------
  |  |  281|  1.69k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  687|  1.69k|    }
  688|       |
  689|  1.69k|    return rc;
  690|  1.69k|}
socket.c:ssh_socket_unbuffered_write:
  711|  1.40k|{
  712|  1.40k|    ssize_t w = -1;
  713|  1.40k|    int flags = 0;
  714|       |
  715|  1.40k|#ifdef MSG_NOSIGNAL
  716|  1.40k|    flags |= MSG_NOSIGNAL;
  717|  1.40k|#endif
  718|       |
  719|  1.40k|    if (s->data_except) {
  ------------------
  |  Branch (719:9): [True: 0, False: 1.40k]
  ------------------
  720|      0|        return -1;
  721|      0|    }
  722|       |
  723|  1.40k|    if (s->fd_is_socket) {
  ------------------
  |  Branch (723:9): [True: 1.40k, False: 0]
  ------------------
  724|  1.40k|        w = send(s->fd, buffer, len, flags);
  725|  1.40k|    } else {
  726|      0|        w = write(s->fd, buffer, len);
  727|      0|    }
  728|       |#ifdef _WIN32
  729|       |    s->last_errno = WSAGetLastError();
  730|       |#else
  731|  1.40k|    s->last_errno = errno;
  732|  1.40k|#endif
  733|  1.40k|    s->write_wontblock = 0;
  734|       |    /* Reactive the POLLOUT detector in the poll multiplexer system */
  735|  1.40k|    if (s->poll_handle) {
  ------------------
  |  Branch (735:9): [True: 1.40k, False: 0]
  ------------------
  736|  1.40k|        SSH_LOG(SSH_LOG_PACKET, "Enabling POLLOUT for socket");
  ------------------
  |  |  281|  1.40k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  737|  1.40k|        ssh_poll_add_events(s->poll_handle, POLLOUT);
  738|  1.40k|    }
  739|  1.40k|    if (w < 0) {
  ------------------
  |  Branch (739:9): [True: 0, False: 1.40k]
  ------------------
  740|      0|        s->data_except = 1;
  741|      0|    }
  742|       |
  743|  1.40k|    SSH_LOG(SSH_LOG_TRACE, "wrote %zd", w);
  ------------------
  |  |  281|  1.40k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  744|  1.40k|    return w;
  745|  1.40k|}

ssh_string_new:
   57|  10.7k|{
   58|  10.7k|    struct ssh_string_struct *str = NULL;
   59|       |
   60|  10.7k|    if (size > STRING_SIZE_MAX) {
  ------------------
  |  |   38|  10.7k|#define STRING_SIZE_MAX 0x10000000
  ------------------
  |  Branch (60:9): [True: 0, False: 10.7k]
  ------------------
   61|      0|        errno = EINVAL;
   62|      0|        return NULL;
   63|      0|    }
   64|       |
   65|  10.7k|    str = calloc(1, sizeof(struct ssh_string_struct) + size);
   66|  10.7k|    if (str == NULL) {
  ------------------
  |  Branch (66:9): [True: 0, False: 10.7k]
  ------------------
   67|      0|        return NULL;
   68|      0|    }
   69|       |
   70|  10.7k|    str->size = htonl((uint32_t)size);
   71|       |
   72|  10.7k|    return str;
   73|  10.7k|}
ssh_string_fill:
   87|    337|{
   88|    337|    if ((s == NULL) || (data == NULL) || (len == 0) ||
  ------------------
  |  Branch (88:9): [True: 0, False: 337]
  |  Branch (88:24): [True: 0, False: 337]
  |  Branch (88:42): [True: 0, False: 337]
  ------------------
   89|    337|        (len > ssh_string_len(s))) {
  ------------------
  |  Branch (89:9): [True: 0, False: 337]
  ------------------
   90|      0|        return -1;
   91|      0|    }
   92|       |
   93|    337|    memcpy(s->data, data, len);
   94|       |
   95|    337|    return 0;
   96|    337|}
ssh_string_from_char:
  109|  5.19k|{
  110|  5.19k|    struct ssh_string_struct *ptr = NULL;
  111|  5.19k|    size_t len;
  112|       |
  113|  5.19k|    if (what == NULL) {
  ------------------
  |  Branch (113:9): [True: 0, False: 5.19k]
  ------------------
  114|      0|        errno = EINVAL;
  115|      0|        return NULL;
  116|      0|    }
  117|       |
  118|  5.19k|    len = strlen(what);
  119|       |
  120|  5.19k|    ptr = ssh_string_new(len);
  121|  5.19k|    if (ptr == NULL) {
  ------------------
  |  Branch (121:9): [True: 0, False: 5.19k]
  ------------------
  122|      0|        return NULL;
  123|      0|    }
  124|       |
  125|  5.19k|    memcpy(ptr->data, what, len);
  126|       |
  127|  5.19k|    return ptr;
  128|  5.19k|}
ssh_string_len:
  177|  20.7k|{
  178|  20.7k|    size_t size;
  179|       |
  180|  20.7k|    if (s == NULL) {
  ------------------
  |  Branch (180:9): [True: 123, False: 20.6k]
  ------------------
  181|    123|        return 0;
  182|    123|    }
  183|       |
  184|  20.6k|    size = ntohl(s->size);
  185|  20.6k|    if (size > 0 && size <= STRING_SIZE_MAX) {
  ------------------
  |  |   38|  16.8k|#define STRING_SIZE_MAX 0x10000000
  ------------------
  |  Branch (185:9): [True: 16.8k, False: 3.78k]
  |  Branch (185:21): [True: 16.8k, False: 0]
  ------------------
  186|  16.8k|        return size;
  187|  16.8k|    }
  188|       |
  189|  3.78k|    return 0;
  190|  20.6k|}
ssh_string_get_char:
  202|    292|{
  203|    292|    if (s == NULL) {
  ------------------
  |  Branch (203:9): [True: 0, False: 292]
  ------------------
  204|      0|        return NULL;
  205|      0|    }
  206|    292|    s->data[ssh_string_len(s)] = '\0';
  207|       |
  208|    292|    return (const char *)s->data;
  209|    292|}
ssh_string_to_char:
  223|  3.52k|{
  224|  3.52k|    size_t len;
  225|  3.52k|    char *new = NULL;
  226|       |
  227|  3.52k|    if (s == NULL) {
  ------------------
  |  Branch (227:9): [True: 0, False: 3.52k]
  ------------------
  228|      0|        return NULL;
  229|      0|    }
  230|       |
  231|  3.52k|    len = ssh_string_len(s);
  232|  3.52k|    if (len + 1 < len) {
  ------------------
  |  Branch (232:9): [True: 0, False: 3.52k]
  ------------------
  233|      0|        return NULL;
  234|      0|    }
  235|       |
  236|  3.52k|    new = malloc(len + 1);
  237|  3.52k|    if (new == NULL) {
  ------------------
  |  Branch (237:9): [True: 0, False: 3.52k]
  ------------------
  238|      0|        return NULL;
  239|      0|    }
  240|  3.52k|    memcpy(new, s->data, len);
  241|  3.52k|    new[len] = '\0';
  242|       |
  243|  3.52k|    return new;
  244|  3.52k|}
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|  2.16k|{
  342|  2.16k|    if (s == NULL || s->size == 0) {
  ------------------
  |  Branch (342:9): [True: 1.52k, False: 635]
  |  Branch (342:22): [True: 56, False: 579]
  ------------------
  343|  1.58k|        return;
  344|  1.58k|    }
  345|       |
  346|    579|    ssh_burn(s->data, ssh_string_len(s));
  ------------------
  |  |  388|    579|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  347|    579|}
ssh_string_data:
  357|  5.27k|{
  358|  5.27k|    if (s == NULL) {
  ------------------
  |  Branch (358:9): [True: 0, False: 5.27k]
  ------------------
  359|      0|        return NULL;
  360|      0|    }
  361|       |
  362|  5.27k|    return s->data;
  363|  5.27k|}
ssh_string_free:
  371|  16.9k|{
  372|       |    SAFE_FREE(s);
  ------------------
  |  |  373|  16.9k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 10.3k, False: 6.69k]
  |  |  |  Branch (373:71): [Folded, False: 16.9k]
  |  |  ------------------
  ------------------
  373|  16.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|    579|{
   97|    579|    if (user_callbacks != NULL) {
  ------------------
  |  Branch (97:9): [True: 579, False: 0]
  ------------------
   98|    579|        return user_callbacks->type;
   99|    579|    }
  100|      0|    return NULL;
  101|    579|}

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

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

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

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

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

