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

ssh_agent_state_free:
 1056|  1.18k|{
 1057|  1.18k|    struct ssh_agent_state_struct *state = data;
 1058|       |
 1059|  1.18k|    if (state) {
  ------------------
  |  Branch (1059:9): [True: 0, False: 1.18k]
  ------------------
 1060|       |        SSH_STRING_FREE_CHAR(state->comment);
  ------------------
  |  |  902|      0|    do { if ((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (902:14): [True: 0, False: 0]
  |  |  |  Branch (902:74): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1061|      0|        ssh_key_free(state->pubkey);
 1062|      0|        free(state);
 1063|      0|    }
 1064|  1.18k|}

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

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

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

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

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

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

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

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

ssh_client_dhgex_init:
   65|     10|{
   66|     10|    int rc;
   67|       |
   68|     10|    rc = ssh_dh_init_common(session->next_crypto);
   69|     10|    if (rc != SSH_OK){
  ------------------
  |  |  316|     10|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (69:9): [True: 0, False: 10]
  ------------------
   70|      0|        goto error;
   71|      0|    }
   72|       |
   73|     10|    session->next_crypto->dh_pmin = DH_PMIN;
  ------------------
  |  |   41|     10|#define DH_PMIN 2048
  ------------------
   74|     10|    session->next_crypto->dh_pn = DH_PREQ;
  ------------------
  |  |   42|     10|#define DH_PREQ 2048
  ------------------
   75|     10|    session->next_crypto->dh_pmax = DH_PMAX;
  ------------------
  |  |   43|     10|#define DH_PMAX 8192
  ------------------
   76|       |    /* Minimum group size, preferred group size, maximum group size */
   77|     10|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|     10|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|     10|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|     10|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|     10|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|     10|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|     10|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|     10|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
   78|     10|                         "bddd",
   79|     10|                         SSH2_MSG_KEX_DH_GEX_REQUEST,
   80|     10|                         session->next_crypto->dh_pmin,
   81|     10|                         session->next_crypto->dh_pn,
   82|     10|                         session->next_crypto->dh_pmax);
   83|     10|    if (rc != SSH_OK) {
  ------------------
  |  |  316|     10|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (83:9): [True: 0, False: 10]
  ------------------
   84|      0|        goto error;
   85|      0|    }
   86|       |
   87|       |    /* register the packet callbacks */
   88|     10|    ssh_packet_set_callbacks(session, &ssh_dhgex_client_callbacks);
   89|     10|    session->dh_handshake_state = DH_STATE_REQUEST_SENT;
   90|     10|    rc = ssh_packet_send(session);
   91|     10|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     10|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (91:9): [True: 0, False: 10]
  ------------------
   92|      0|        goto error;
   93|      0|    }
   94|     10|    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|     10|}
dh-gex.c:ssh_packet_client_dhgex_group:
  105|     10|{
  106|     10|    int rc;
  107|     10|    int blen;
  108|     10|    bignum pmin1 = NULL, one = NULL;
  109|     10|    bignum modulus = NULL, generator = NULL;
  110|     10|#if !defined(HAVE_LIBCRYPTO) || OPENSSL_VERSION_NUMBER < 0x30000000L
  111|     10|    const_bignum pubkey;
  112|       |#else
  113|       |    bignum pubkey = NULL;
  114|       |#endif /* OPENSSL_VERSION_NUMBER */
  115|     10|    (void) type;
  116|     10|    (void) user;
  117|       |
  118|     10|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_KEX_DH_GEX_GROUP received");
  ------------------
  |  |  281|     10|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  119|       |
  120|     10|    if (session->dh_handshake_state != DH_STATE_REQUEST_SENT) {
  ------------------
  |  Branch (120:9): [True: 1, False: 9]
  ------------------
  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|      9|    one = bignum_new();
  ------------------
  |  |   70|      9|#define bignum_new() BN_new()
  ------------------
  127|      9|    pmin1 = bignum_new();
  ------------------
  |  |   70|      9|#define bignum_new() BN_new()
  ------------------
  128|      9|    if (one == NULL || pmin1 == NULL) {
  ------------------
  |  Branch (128:9): [True: 0, False: 9]
  |  Branch (128:24): [True: 0, False: 9]
  ------------------
  129|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  130|      0|        goto error;
  131|      0|    }
  132|      9|    rc = ssh_buffer_unpack(packet,
  ------------------
  |  |   60|      9|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|      9|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|      9|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|      9|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|      9|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|      9|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|      9|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  133|      9|                           "BB",
  134|      9|                           &modulus,
  135|      9|                           &generator);
  136|      9|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      9|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (136:9): [True: 2, False: 7]
  ------------------
  137|      2|        ssh_set_error(session, SSH_FATAL, "Invalid DH_GEX_GROUP packet");
  ------------------
  |  |  311|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  138|      2|        goto error;
  139|      2|    }
  140|       |    /* basic checks */
  141|      7|    if (ssh_fips_mode() &&
  ------------------
  |  |  115|     14|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 7]
  |  |  ------------------
  ------------------
  142|      0|        !ssh_dh_is_known_group(modulus, generator)) {
  ------------------
  |  Branch (142:9): [True: 0, False: 0]
  ------------------
  143|      0|        ssh_set_error(session,
  ------------------
  |  |  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|      7|    rc = bignum_set_word(one, 1);
  ------------------
  |  |   77|      7|#define bignum_set_word(bn,n) BN_set_word(bn,n)
  ------------------
  149|      7|    if (rc != 1) {
  ------------------
  |  Branch (149:9): [True: 0, False: 7]
  ------------------
  150|      0|        goto error;
  151|      0|    }
  152|      7|    blen = bignum_num_bits(modulus);
  ------------------
  |  |   99|      7|#define bignum_num_bits(num) (size_t)BN_num_bits(num)
  ------------------
  153|      7|    if (blen < DH_PMIN || blen > DH_PMAX) {
  ------------------
  |  |   41|     14|#define DH_PMIN 2048
  ------------------
                  if (blen < DH_PMIN || blen > DH_PMAX) {
  ------------------
  |  |   43|      6|#define DH_PMAX 8192
  ------------------
  |  Branch (153:9): [True: 1, False: 6]
  |  Branch (153:27): [True: 0, False: 6]
  ------------------
  154|      1|        ssh_set_error(session,
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  155|      1|                SSH_FATAL,
  156|      1|                "Invalid dh group parameter p: %d not in [%d:%d]",
  157|      1|                blen,
  158|      1|                DH_PMIN,
  159|      1|                DH_PMAX);
  160|      1|        goto error;
  161|      1|    }
  162|      6|    if (bignum_cmp(modulus, one) <= 0) {
  ------------------
  |  |  102|      6|#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
  ------------------
  |  Branch (162:9): [True: 0, False: 6]
  ------------------
  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|      6|    if (!bignum_is_bit_set(modulus, 0)) {
  ------------------
  |  |  100|      6|#define bignum_is_bit_set(num,bit) BN_is_bit_set(num, (int)bit)
  ------------------
  |  Branch (167:9): [True: 0, False: 6]
  ------------------
  168|       |        /* p must be a prime and therefore not divisible by 2 */
  169|      0|        ssh_set_error(session, SSH_FATAL, "Invalid dh group parameter p");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  170|      0|        goto error;
  171|      0|    }
  172|      6|    bignum_sub(pmin1, modulus, one);
  ------------------
  |  |   96|      6|#define bignum_sub(dest, a, b) BN_sub(dest, a, b)
  ------------------
  173|      6|    if (bignum_cmp(generator, one) <= 0 ||
  ------------------
  |  |  102|      6|#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
  ------------------
  |  Branch (173:9): [True: 1, False: 5]
  ------------------
  174|      5|        bignum_cmp(generator, pmin1) > 0) {
  ------------------
  |  |  102|      5|#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
  ------------------
  |  Branch (174:9): [True: 1, False: 4]
  ------------------
  175|       |        /* generator must be at least 2 and smaller than p-1*/
  176|      2|        ssh_set_error(session, SSH_FATAL, "Invalid dh group parameter g");
  ------------------
  |  |  311|      2|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  177|      2|        goto error;
  178|      2|    }
  179|       |
  180|       |    /* all checks passed, set parameters (the BNs are copied in openssl backend) */
  181|      4|    rc = ssh_dh_set_parameters(session->next_crypto->dh_ctx,
  182|      4|                               modulus, generator);
  183|      4|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      4|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (183:9): [True: 0, False: 4]
  ------------------
  184|      0|        goto error;
  185|      0|    }
  186|      4|#ifdef HAVE_LIBCRYPTO
  187|      4|    bignum_safe_free(modulus);
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
  188|      4|    bignum_safe_free(generator);
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
  189|      4|#endif
  190|      4|    modulus = NULL;
  191|      4|    generator = NULL;
  192|       |
  193|       |    /* compute and send DH public parameter */
  194|      4|    rc = ssh_dh_keypair_gen_keys(session->next_crypto->dh_ctx,
  195|      4|                                 DH_CLIENT_KEYPAIR);
  ------------------
  |  |   30|      4|#define DH_CLIENT_KEYPAIR 0
  ------------------
  196|      4|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      4|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (196:9): [True: 0, False: 4]
  ------------------
  197|      0|        goto error;
  198|      0|    }
  199|       |
  200|      4|    rc = ssh_dh_keypair_get_keys(session->next_crypto->dh_ctx,
  201|      4|                                 DH_CLIENT_KEYPAIR, NULL, &pubkey);
  ------------------
  |  |   30|      4|#define DH_CLIENT_KEYPAIR 0
  ------------------
  202|      4|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      4|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (202:9): [True: 0, False: 4]
  ------------------
  203|      0|        goto error;
  204|      0|    }
  205|       |
  206|      4|    rc = ssh_buffer_pack(session->out_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)
  |  |  ------------------
  ------------------
  207|      4|                         "bB",
  208|      4|                         SSH2_MSG_KEX_DH_GEX_INIT,
  209|      4|                         pubkey);
  210|      4|    if (rc != SSH_OK) {
  ------------------
  |  |  316|      4|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (210:9): [True: 0, False: 4]
  ------------------
  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|      4|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  218|       |
  219|      4|    rc = ssh_packet_send(session);
  220|      4|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      4|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (220:9): [True: 0, False: 4]
  ------------------
  221|      0|        goto error;
  222|      0|    }
  223|       |
  224|      4|    bignum_safe_free(one);
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
  225|      4|    bignum_safe_free(pmin1);
  ------------------
  |  |   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]
  |  |  ------------------
  ------------------
  226|      4|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      4|#define SSH_PACKET_USED 1
  ------------------
  227|       |
  228|      6|error:
  229|      6|    bignum_safe_free(modulus);
  ------------------
  |  |   71|      6|#define bignum_safe_free(num) do { \
  |  |   72|      6|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 3, False: 3]
  |  |  ------------------
  |  |   73|      3|        BN_clear_free((num)); \
  |  |   74|      3|        (num)=NULL; \
  |  |   75|      3|    } \
  |  |   76|      6|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 6]
  |  |  ------------------
  ------------------
  230|      6|    bignum_safe_free(generator);
  ------------------
  |  |   71|      6|#define bignum_safe_free(num) do { \
  |  |   72|      6|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 3, False: 3]
  |  |  ------------------
  |  |   73|      3|        BN_clear_free((num)); \
  |  |   74|      3|        (num)=NULL; \
  |  |   75|      3|    } \
  |  |   76|      6|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 6]
  |  |  ------------------
  ------------------
  231|      6|    bignum_safe_free(one);
  ------------------
  |  |   71|      6|#define bignum_safe_free(num) do { \
  |  |   72|      6|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 5, False: 1]
  |  |  ------------------
  |  |   73|      5|        BN_clear_free((num)); \
  |  |   74|      5|        (num)=NULL; \
  |  |   75|      5|    } \
  |  |   76|      6|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 6]
  |  |  ------------------
  ------------------
  232|      6|    bignum_safe_free(pmin1);
  ------------------
  |  |   71|      6|#define bignum_safe_free(num) do { \
  |  |   72|      6|    if ((num) != NULL) { \
  |  |  ------------------
  |  |  |  Branch (72:9): [True: 5, False: 1]
  |  |  ------------------
  |  |   73|      5|        BN_clear_free((num)); \
  |  |   74|      5|        (num)=NULL; \
  |  |   75|      5|    } \
  |  |   76|      6|    } while(0)
  |  |  ------------------
  |  |  |  Branch (76:13): [Folded, False: 6]
  |  |  ------------------
  ------------------
  233|       |#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
  234|       |    bignum_safe_free(pubkey);
  235|       |#endif /* OPENSSL_VERSION_NUMBER */
  236|      6|    ssh_dh_cleanup(session->next_crypto);
  237|      6|    session->session_state = SSH_SESSION_STATE_ERROR;
  238|       |
  239|      6|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      6|#define SSH_PACKET_USED 1
  ------------------
  240|      4|}

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

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

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

ssh_ecdh_init:
  220|    178|{
  221|    178|    ssh_string pubkey = NULL;
  222|    178|    ssh_string *pubkey_loc = NULL;
  223|       |
  224|    178|    pubkey = ssh_ecdh_generate(session);
  225|    178|    if (pubkey == NULL) {
  ------------------
  |  Branch (225:9): [True: 0, False: 178]
  ------------------
  226|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  227|      0|    }
  228|       |
  229|    178|    if (session->server) {
  ------------------
  |  Branch (229:9): [True: 0, False: 178]
  ------------------
  230|      0|        pubkey_loc = &session->next_crypto->ecdh_server_pubkey;
  231|    178|    } else {
  232|    178|        pubkey_loc = &session->next_crypto->ecdh_client_pubkey;
  233|    178|    }
  234|       |
  235|    178|    ssh_string_free(*pubkey_loc);
  236|    178|    *pubkey_loc = pubkey;
  237|       |
  238|    178|    return SSH_OK;
  ------------------
  |  |  316|    178|#define SSH_OK 0     /* No error */
  ------------------
  239|    178|}
ssh_client_ecdh_init:
  245|     16|{
  246|     16|    int rc;
  247|       |
  248|     16|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_KEX_ECDH_INIT);
  ------------------
  |  |   17|     16|#define SSH2_MSG_KEX_ECDH_INIT 30
  ------------------
  249|     16|    if (rc < 0) {
  ------------------
  |  Branch (249:9): [True: 0, False: 16]
  ------------------
  250|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  251|      0|    }
  252|       |
  253|     16|    rc = ssh_ecdh_init(session);
  254|     16|    if (rc < 0) {
  ------------------
  |  Branch (254:9): [True: 0, False: 16]
  ------------------
  255|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  256|      0|    }
  257|       |
  258|     16|    rc = ssh_buffer_add_ssh_string(session->out_buffer,
  259|     16|                                   session->next_crypto->ecdh_client_pubkey);
  260|     16|    if (rc < 0) {
  ------------------
  |  Branch (260:9): [True: 0, False: 16]
  ------------------
  261|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  262|      0|    }
  263|       |
  264|       |    /* register the packet callbacks */
  265|     16|    ssh_packet_set_callbacks(session, &ssh_ecdh_client_callbacks);
  266|     16|    session->dh_handshake_state = DH_STATE_INIT_SENT;
  267|       |
  268|     16|    rc = ssh_packet_send(session);
  269|       |
  270|     16|    return rc;
  271|     16|}
ecdh_crypto.c:ssh_ecdh_generate:
   80|    178|{
   81|    178|    ssh_string pubkey_string = NULL;
   82|    178|#if OPENSSL_VERSION_NUMBER < 0x30000000L
   83|    178|    const EC_POINT *point = NULL;
   84|    178|    const EC_GROUP *group = NULL;
   85|    178|    EC_KEY *key = NULL;
   86|    178|    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|    178|    curve = ecdh_kex_type_to_curve(session->next_crypto->kex_type);
  101|    178|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  102|    178|    if (curve == SSH_ERROR) {
  ------------------
  |  |  317|    178|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (102:9): [True: 0, False: 178]
  ------------------
  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|    178|    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|    178|    if (key == NULL) {
  ------------------
  |  Branch (116:9): [True: 0, False: 178]
  ------------------
  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|    178|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  122|    178|    group = EC_KEY_get0_group(key);
  123|       |
  124|    178|    EC_KEY_generate_key(key);
  125|       |
  126|    178|    point = EC_KEY_get0_public_key(key);
  127|       |
  128|    178|    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|    178|    if (pubkey_string == NULL) {
  ------------------
  |  Branch (192:9): [True: 0, False: 178]
  ------------------
  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|    178|    if (session->next_crypto->ecdh_privkey != NULL) {
  ------------------
  |  Branch (203:9): [True: 0, False: 178]
  ------------------
  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|    178|    session->next_crypto->ecdh_privkey = key;
  213|    178|    return pubkey_string;
  214|    178|}
ecdh_crypto.c:ecdh_kex_type_to_curve:
   50|    178|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|    178|    switch (kex_type) {
   55|      6|    case SSH_KEX_ECDH_SHA2_NISTP256:
  ------------------
  |  Branch (55:5): [True: 6, False: 172]
  ------------------
   56|    168|    case SSH_KEX_MLKEM768NISTP256_SHA256:
  ------------------
  |  Branch (56:5): [True: 162, False: 16]
  ------------------
   57|    168|    case SSH_GSS_KEX_ECDH_NISTP256_SHA256:
  ------------------
  |  Branch (57:5): [True: 0, False: 178]
  ------------------
   58|    168|        return NISTP256;
  ------------------
  |  |   34|    168|#define NISTP256 NID_X9_62_prime256v1
  ------------------
   59|      2|    case SSH_KEX_ECDH_SHA2_NISTP384:
  ------------------
  |  Branch (59:5): [True: 2, False: 176]
  ------------------
   60|       |#if HAVE_MLKEM1024
   61|       |    case SSH_KEX_MLKEM1024NISTP384_SHA384:
   62|       |#endif
   63|      2|        return NISTP384;
  ------------------
  |  |   35|      2|#define NISTP384 NID_secp384r1
  ------------------
   64|      8|    case SSH_KEX_ECDH_SHA2_NISTP521:
  ------------------
  |  Branch (64:5): [True: 8, False: 170]
  ------------------
   65|      8|        return NISTP521;
  ------------------
  |  |   36|      8|#define NISTP521 NID_secp521r1
  ------------------
   66|      0|    default:
  ------------------
  |  Branch (66:5): [True: 0, False: 178]
  ------------------
   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|    178|    }
   73|    178|}

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

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

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

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

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

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

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

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

ssh_kdf:
  337|    426|{
  338|    426|    return sshkdf_derive_key(crypto, key, key_len,
  339|    426|                             key_type, output, requested_len);
  340|    426|}
ssh_get_ciphertab:
 1382|    213|{
 1383|    213|    return ssh_ciphertab;
 1384|    213|}
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|    178|{
 1622|    178|    ssh_string s = NULL;
 1623|    178|    size_t len;
 1624|       |
 1625|    178|    len = EC_POINT_point2oct(g,
 1626|    178|                             p,
 1627|    178|                             POINT_CONVERSION_UNCOMPRESSED,
 1628|    178|                             NULL,
 1629|    178|                             0,
 1630|    178|                             NULL);
 1631|    178|    if (len == 0) {
  ------------------
  |  Branch (1631:9): [True: 0, False: 178]
  ------------------
 1632|      0|        return NULL;
 1633|      0|    }
 1634|       |
 1635|    178|    s = ssh_string_new(len);
 1636|    178|    if (s == NULL) {
  ------------------
  |  Branch (1636:9): [True: 0, False: 178]
  ------------------
 1637|      0|        return NULL;
 1638|      0|    }
 1639|       |
 1640|    178|    len = EC_POINT_point2oct(g,
 1641|    178|                             p,
 1642|    178|                             POINT_CONVERSION_UNCOMPRESSED,
 1643|    178|                             ssh_string_data(s),
 1644|    178|                             ssh_string_len(s),
 1645|    178|                             NULL);
 1646|    178|    if (len != ssh_string_len(s)) {
  ------------------
  |  Branch (1646:9): [True: 0, False: 178]
  ------------------
 1647|      0|        SSH_STRING_FREE(s);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1648|      0|        return NULL;
 1649|      0|    }
 1650|       |
 1651|    178|    return s;
 1652|    178|}
libcrypto.c:none_crypt:
 1217|  8.55k|{
 1218|  8.55k|    memcpy(out, in, len);
 1219|  8.55k|}

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

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

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

ssh_is_ipaddr_v4:
  430|  3.20k|{
  431|  3.20k|    int rc = -1;
  432|  3.20k|    struct in_addr dest;
  433|       |
  434|  3.20k|    rc = inet_pton(AF_INET, str, &dest);
  435|  3.20k|    if (rc > 0) {
  ------------------
  |  Branch (435:9): [True: 3.20k, False: 0]
  ------------------
  436|  3.20k|        return 1;
  437|  3.20k|    }
  438|       |
  439|      0|    return 0;
  440|  3.20k|}
ssh_is_ipaddr:
  450|  3.20k|{
  451|  3.20k|    int rc = -1;
  452|  3.20k|    char *s = strdup(str);
  453|       |
  454|  3.20k|    if (s == NULL) {
  ------------------
  |  Branch (454:9): [True: 0, False: 3.20k]
  ------------------
  455|      0|        return -1;
  456|      0|    }
  457|  3.20k|    if (strchr(s, ':')) {
  ------------------
  |  Branch (457:9): [True: 0, False: 3.20k]
  ------------------
  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|  3.20k|    free(s);
  478|  3.20k|    return ssh_is_ipaddr_v4(str);
  479|  3.20k|}
ssh_get_user_home_dir:
  495|  4.00k|{
  496|  4.00k|    char *szPath = NULL;
  497|       |
  498|       |    /* If used previously, reuse cached value */
  499|  4.00k|    if (session != NULL && session->opts.homedir != NULL) {
  ------------------
  |  Branch (499:9): [True: 3.20k, False: 800]
  |  Branch (499:28): [True: 2.40k, False: 800]
  ------------------
  500|  2.40k|        return strdup(session->opts.homedir);
  501|  2.40k|    }
  502|       |
  503|  1.60k|    szPath = ssh_get_user_home_dir_internal();
  504|  1.60k|    if (szPath == NULL) {
  ------------------
  |  Branch (504:9): [True: 0, False: 1.60k]
  ------------------
  505|      0|        return NULL;
  506|      0|    }
  507|       |
  508|  1.60k|    if (session != NULL) {
  ------------------
  |  Branch (508:9): [True: 800, False: 800]
  ------------------
  509|       |        /* cache it:
  510|       |         * failure is not fatal -- at worst we will just not cache it */
  511|    800|        session->opts.homedir = strdup(szPath);
  512|    800|    }
  513|       |
  514|  1.60k|    return szPath;
  515|  1.60k|}
ssh_lowercase:
  526|    728|{
  527|    728|    char *new = NULL, *p = NULL;
  528|       |
  529|    728|    if (str == NULL) {
  ------------------
  |  Branch (529:9): [True: 0, False: 728]
  ------------------
  530|      0|        return NULL;
  531|      0|    }
  532|       |
  533|    728|    new = strdup(str);
  534|    728|    if (new == NULL) {
  ------------------
  |  Branch (534:9): [True: 0, False: 728]
  ------------------
  535|      0|        return NULL;
  536|      0|    }
  537|       |
  538|  7.28k|    for (p = new; *p; p++) {
  ------------------
  |  Branch (538:19): [True: 6.55k, False: 728]
  ------------------
  539|  6.55k|        *p = tolower(*p);
  ------------------
  |  Branch (539:14): [True: 0, False: 0]
  |  Branch (539:14): [True: 0, False: 0]
  |  Branch (539:14): [Folded, False: 6.55k]
  ------------------
  540|  6.55k|    }
  541|       |
  542|    728|    return new;
  543|    728|}
ssh_list_new:
  865|  6.33k|{
  866|  6.33k|    struct ssh_list *ret = malloc(sizeof(struct ssh_list));
  867|  6.33k|    if (ret == NULL) {
  ------------------
  |  Branch (867:9): [True: 3, False: 6.32k]
  ------------------
  868|      3|        return NULL;
  869|      3|    }
  870|  6.32k|    ret->root = ret->end = NULL;
  871|  6.32k|    return ret;
  872|  6.33k|}
ssh_list_free:
  882|  7.90k|{
  883|  7.90k|    struct ssh_iterator *ptr = NULL, *next = NULL;
  884|  7.90k|    if (!list)
  ------------------
  |  Branch (884:9): [True: 1.57k, False: 6.32k]
  ------------------
  885|  1.57k|        return;
  886|  6.32k|    ptr = list->root;
  887|  7.12k|    while (ptr) {
  ------------------
  |  Branch (887:12): [True: 794, False: 6.32k]
  ------------------
  888|    794|        next = ptr->next;
  889|    794|        SAFE_FREE(ptr);
  ------------------
  |  |  373|    794|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 794, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 794]
  |  |  ------------------
  ------------------
  890|    794|        ptr = next;
  891|    794|    }
  892|       |    SAFE_FREE(list);
  ------------------
  |  |  373|  6.32k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 6.32k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 6.32k]
  |  |  ------------------
  ------------------
  893|  6.32k|}
ssh_list_get_iterator:
  903|  27.6k|{
  904|  27.6k|    if (!list)
  ------------------
  |  Branch (904:9): [True: 2.45k, False: 25.2k]
  ------------------
  905|  2.45k|        return NULL;
  906|  25.2k|    return list->root;
  907|  27.6k|}
ssh_list_find:
  918|    292|{
  919|    292|    struct ssh_iterator *it = NULL;
  920|       |
  921|    584|    for (it = ssh_list_get_iterator(list); it != NULL ; it = it->next)
  ------------------
  |  Branch (921:44): [True: 584, False: 0]
  ------------------
  922|    584|        if (it->data == value)
  ------------------
  |  Branch (922:13): [True: 292, False: 292]
  ------------------
  923|    292|            return it;
  924|      0|    return NULL;
  925|    292|}
ssh_list_append:
  969|  5.88k|{
  970|  5.88k|  struct ssh_iterator *iterator = NULL;
  971|       |
  972|  5.88k|  if (list == NULL) {
  ------------------
  |  Branch (972:7): [True: 0, False: 5.88k]
  ------------------
  973|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  974|      0|  }
  975|       |
  976|  5.88k|  iterator = ssh_iterator_new(data);
  977|  5.88k|  if (iterator == NULL) {
  ------------------
  |  Branch (977:7): [True: 0, False: 5.88k]
  ------------------
  978|      0|      return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  979|      0|  }
  980|       |
  981|  5.88k|  if(!list->end){
  ------------------
  |  Branch (981:6): [True: 2.32k, False: 3.55k]
  ------------------
  982|       |    /* list is empty */
  983|  2.32k|    list->root=list->end=iterator;
  984|  3.55k|  } else {
  985|       |    /* put it on end of list */
  986|  3.55k|    list->end->next=iterator;
  987|  3.55k|    list->end=iterator;
  988|  3.55k|  }
  989|  5.88k|  return SSH_OK;
  ------------------
  |  |  316|  5.88k|#define SSH_OK 0     /* No error */
  ------------------
  990|  5.88k|}
ssh_list_remove:
 1032|    292|{
 1033|    292|    struct ssh_iterator *ptr = NULL, *prev = NULL;
 1034|       |
 1035|    292|    if (list == NULL) {
  ------------------
  |  Branch (1035:9): [True: 0, False: 292]
  ------------------
 1036|      0|        return;
 1037|      0|    }
 1038|       |
 1039|    292|    prev = NULL;
 1040|    292|    ptr = list->root;
 1041|    584|    while (ptr && ptr != iterator) {
  ------------------
  |  Branch (1041:12): [True: 584, False: 0]
  |  Branch (1041:19): [True: 292, False: 292]
  ------------------
 1042|    292|        prev = ptr;
 1043|    292|        ptr = ptr->next;
 1044|    292|    }
 1045|    292|    if (!ptr) {
  ------------------
  |  Branch (1045:9): [True: 0, False: 292]
  ------------------
 1046|       |        /* we did not find the element */
 1047|      0|        return;
 1048|      0|    }
 1049|       |    /* unlink it */
 1050|    292|    if (prev)
  ------------------
  |  Branch (1050:9): [True: 292, False: 0]
  ------------------
 1051|    292|        prev->next = ptr->next;
 1052|       |    /* if iterator was the head */
 1053|    292|    if (list->root == iterator)
  ------------------
  |  Branch (1053:9): [True: 0, False: 292]
  ------------------
 1054|      0|        list->root = iterator->next;
 1055|       |    /* if iterator was the tail */
 1056|    292|    if (list->end == iterator)
  ------------------
  |  Branch (1056:9): [True: 292, False: 0]
  ------------------
 1057|    292|        list->end = prev;
 1058|       |    SAFE_FREE(iterator);
  ------------------
  |  |  373|    292|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 292, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 292]
  |  |  ------------------
  ------------------
 1059|    292|}
_ssh_list_pop_head:
 1073|  11.9k|{
 1074|  11.9k|  struct ssh_iterator *iterator = NULL;
 1075|  11.9k|  const void *data = NULL;
 1076|       |
 1077|  11.9k|  if (list == NULL) {
  ------------------
  |  Branch (1077:7): [True: 778, False: 11.2k]
  ------------------
 1078|    778|      return NULL;
 1079|    778|  }
 1080|       |
 1081|  11.2k|  iterator = list->root;
 1082|  11.2k|  if (iterator == NULL) {
  ------------------
  |  Branch (1082:7): [True: 6.40k, False: 4.80k]
  ------------------
 1083|  6.40k|      return NULL;
 1084|  6.40k|  }
 1085|  4.80k|  data=iterator->data;
 1086|  4.80k|  list->root=iterator->next;
 1087|  4.80k|  if(list->end==iterator)
  ------------------
  |  Branch (1087:6): [True: 1.60k, False: 3.20k]
  ------------------
 1088|  1.60k|    list->end=NULL;
 1089|       |  SAFE_FREE(iterator);
  ------------------
  |  |  373|  4.80k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 4.80k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 4.80k]
  |  |  ------------------
  ------------------
 1090|  4.80k|  return data;
 1091|  11.2k|}
ssh_path_expand_tilde:
 1309|  4.00k|{
 1310|  4.00k|    char *h = NULL, *r = NULL;
 1311|  4.00k|    const char *p = NULL;
 1312|  4.00k|    size_t ld;
 1313|  4.00k|    size_t lh = 0;
 1314|       |
 1315|  4.00k|    if (d[0] != '~') {
  ------------------
  |  Branch (1315:9): [True: 3.20k, False: 800]
  ------------------
 1316|  3.20k|        return strdup(d);
 1317|  3.20k|    }
 1318|    800|    d++;
 1319|       |
 1320|       |    /* handle ~user/path */
 1321|    800|    p = strchr(d, '/');
 1322|    800|    if (p != NULL && p > d) {
  ------------------
  |  Branch (1322:9): [True: 800, False: 0]
  |  Branch (1322:22): [True: 0, False: 800]
  ------------------
 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|    800|    } else {
 1343|    800|        ld = strlen(d);
 1344|    800|        p = (char *) d;
 1345|    800|        h = ssh_get_user_home_dir(NULL);
 1346|    800|    }
 1347|    800|    if (h == NULL) {
  ------------------
  |  Branch (1347:9): [True: 0, False: 800]
  ------------------
 1348|      0|        return NULL;
 1349|      0|    }
 1350|    800|    lh = strlen(h);
 1351|       |
 1352|    800|    r = malloc(ld + lh + 1);
 1353|    800|    if (r == NULL) {
  ------------------
  |  Branch (1353:9): [True: 0, False: 800]
  ------------------
 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|    800|    if (lh > 0) {
  ------------------
  |  Branch (1358:9): [True: 800, False: 0]
  ------------------
 1359|    800|        memcpy(r, h, lh);
 1360|    800|    }
 1361|    800|    SAFE_FREE(h);
  ------------------
  |  |  373|    800|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 800, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 800]
  |  |  ------------------
  ------------------
 1362|    800|    memcpy(r + lh, p, ld + 1);
 1363|       |
 1364|    800|    return r;
 1365|    800|}
ssh_path_expand_escape:
 1699|  3.20k|{
 1700|       |    return ssh_path_expand_internal(session, s, false);
 1701|  3.20k|}
ssh_analyze_banner:
 1734|    739|{
 1735|    739|    const char *banner = NULL;
 1736|    739|    const char *openssh = NULL;
 1737|    739|    const char *ios = NULL;
 1738|       |
 1739|    739|    if (server) {
  ------------------
  |  Branch (1739:9): [True: 0, False: 739]
  ------------------
 1740|      0|        banner = session->clientbanner;
 1741|    739|    } else {
 1742|    739|        banner = session->serverbanner;
 1743|    739|    }
 1744|       |
 1745|    739|    if (banner == NULL) {
  ------------------
  |  Branch (1745:9): [True: 0, False: 739]
  ------------------
 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|    739|    if (strlen(banner) < 6 ||
  ------------------
  |  Branch (1759:9): [True: 1, False: 738]
  ------------------
 1760|    738|        strncmp(banner, "SSH-", 4) != 0) {
  ------------------
  |  Branch (1760:9): [True: 0, False: 738]
  ------------------
 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|    738|    SSH_LOG(SSH_LOG_DEBUG, "Analyzing banner: %s", banner);
  ------------------
  |  |  281|    738|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1766|       |
 1767|    738|    switch (banner[4]) {
 1768|    671|        case '2':
  ------------------
  |  Branch (1768:9): [True: 671, False: 67]
  ------------------
 1769|    671|            break;
 1770|     64|        case '1':
  ------------------
  |  Branch (1770:9): [True: 64, False: 674]
  ------------------
 1771|     64|            if (strlen(banner) > 6) {
  ------------------
  |  Branch (1771:17): [True: 64, False: 0]
  ------------------
 1772|     64|                if (banner[6] == '9') {
  ------------------
  |  Branch (1772:21): [True: 57, False: 7]
  ------------------
 1773|     57|                    break;
 1774|     57|                }
 1775|     64|            }
 1776|      7|            FALL_THROUGH;
  ------------------
  |  |  494|      7|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1777|     10|        default:
  ------------------
  |  Branch (1777:9): [True: 3, False: 735]
  ------------------
 1778|     10|            ssh_set_error(session, SSH_FATAL, "Protocol mismatch: %s", banner);
  ------------------
  |  |  311|     10|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1779|     10|            return -1;
 1780|    738|    }
 1781|       |
 1782|       |    /* Make a best-effort to extract OpenSSH version numbers. */
 1783|    728|    openssh = strstr(banner, "OpenSSH");
 1784|    728|    if (openssh != NULL) {
  ------------------
  |  Branch (1784:9): [True: 110, False: 618]
  ------------------
 1785|    110|        char *tmp = NULL;
 1786|    110|        unsigned long int major = 0UL;
 1787|    110|        unsigned long int minor = 0UL;
 1788|    110|        int off = 0;
 1789|       |
 1790|       |        /*
 1791|       |         * The banner is typical:
 1792|       |         * OpenSSH_5.4
 1793|       |         * 012345678901234567890
 1794|       |         */
 1795|    110|        if (strlen(openssh) > 9) {
  ------------------
  |  Branch (1795:13): [True: 102, False: 8]
  ------------------
 1796|    102|            errno = 0;
 1797|    102|            major = strtoul(openssh + 8, &tmp, 10);
 1798|    102|            if ((tmp == (openssh + 8)) ||
  ------------------
  |  Branch (1798:17): [True: 6, False: 96]
  ------------------
 1799|     96|                ((errno == ERANGE) && (major == ULONG_MAX)) ||
  ------------------
  |  Branch (1799:18): [True: 1, False: 95]
  |  Branch (1799:39): [True: 1, False: 0]
  ------------------
 1800|     95|                ((errno != 0) && (major == 0)) ||
  ------------------
  |  Branch (1800:18): [True: 0, False: 95]
  |  Branch (1800:34): [True: 0, False: 0]
  ------------------
 1801|     95|                ((major < 1) || (major > 100))) {
  ------------------
  |  Branch (1801:18): [True: 0, False: 95]
  |  Branch (1801:33): [True: 52, False: 43]
  ------------------
 1802|       |                /* invalid major */
 1803|     59|                errno = 0;
 1804|     59|                goto done;
 1805|     59|            }
 1806|       |
 1807|    102|            errno = 0;
 1808|     43|            off = major >= 10 ? 11 : 10;
  ------------------
  |  Branch (1808:19): [True: 14, False: 29]
  ------------------
 1809|     43|            minor = strtoul(openssh + off, &tmp, 10);
 1810|     43|            if ((tmp == (openssh + off)) ||
  ------------------
  |  Branch (1810:17): [True: 3, False: 40]
  ------------------
 1811|     40|                ((errno == ERANGE) && (major == ULONG_MAX)) ||
  ------------------
  |  Branch (1811:18): [True: 1, False: 39]
  |  Branch (1811:39): [True: 0, False: 1]
  ------------------
 1812|     40|                ((errno != 0) && (major == 0)) ||
  ------------------
  |  Branch (1812:18): [True: 1, False: 39]
  |  Branch (1812:34): [True: 0, False: 1]
  ------------------
 1813|     40|                (minor > 100)) {
  ------------------
  |  Branch (1813:17): [True: 36, False: 4]
  ------------------
 1814|       |                /* invalid minor */
 1815|     39|                errno = 0;
 1816|     39|                goto done;
 1817|     39|            }
 1818|       |
 1819|      4|            session->openssh = SSH_VERSION_INT(((int) major), ((int) minor), 0);
  ------------------
  |  |   25|      4|#define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
  ------------------
 1820|       |
 1821|      4|            SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|      8|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 4]
  |  |  ------------------
  ------------------
 1822|      4|                    "We are talking to an OpenSSH %s version: %lu.%lu (%x)",
 1823|      4|                    server ? "client" : "server",
 1824|      4|                    major, minor, session->openssh);
 1825|      4|        }
 1826|    110|    }
 1827|       |    /* Cisco devices have odd scp implementation which breaks */
 1828|    630|    ios = strstr(banner, "Cisco");
 1829|    630|    if (ios != NULL) {
  ------------------
  |  Branch (1829:9): [True: 12, False: 618]
  ------------------
 1830|     12|        session->flags |= SSH_SESSION_FLAG_SCP_QUOTING_BROKEN;
  ------------------
  |  |   95|     12|#define SSH_SESSION_FLAG_SCP_QUOTING_BROKEN 0x0040
  ------------------
 1831|     12|    }
 1832|       |
 1833|    728|done:
 1834|    728|    return 0;
 1835|    630|}
ssh_timestamp_init:
 1850|  12.3k|{
 1851|  12.3k|#ifdef HAVE_CLOCK_GETTIME
 1852|  12.3k|  struct timespec tp;
 1853|  12.3k|  clock_gettime(CLOCK, &tp);
  ------------------
  |  | 1839|  12.3k|#define CLOCK CLOCK_MONOTONIC
  ------------------
 1854|  12.3k|  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|  12.3k|  ts->seconds = tp.tv_sec;
 1861|  12.3k|}
ssh_make_milliseconds:
 1898|    800|{
 1899|    800|    unsigned long res;
 1900|       |
 1901|    800|    if (sec == (unsigned long)SSH_TIMEOUT_INFINITE) {
  ------------------
  |  |   99|    800|#define SSH_TIMEOUT_INFINITE -1
  ------------------
  |  Branch (1901:9): [True: 0, False: 800]
  ------------------
 1902|      0|        return SSH_TIMEOUT_INFINITE;
  ------------------
  |  |   99|      0|#define SSH_TIMEOUT_INFINITE -1
  ------------------
 1903|      0|    }
 1904|    800|    if (sec > (unsigned long)INT_MAX / 1000) {
  ------------------
  |  Branch (1904:9): [True: 0, False: 800]
  ------------------
 1905|      0|        return INT_MAX;
 1906|      0|    }
 1907|       |
 1908|    800|    res = usec / 1000;
 1909|    800|    res += (sec * 1000);
 1910|    800|    if (res == 0) {
  ------------------
  |  Branch (1910:9): [True: 0, False: 800]
  ------------------
 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|    800|    if (res > INT_MAX) {
  ------------------
  |  Branch (1915:9): [True: 0, False: 800]
  ------------------
 1916|      0|        return INT_MAX;
 1917|    800|    } else {
 1918|    800|        return (int)res;
 1919|    800|    }
 1920|    800|}
ssh_timeout_elapsed:
 1933|  2.75k|{
 1934|  2.75k|    struct ssh_timestamp now;
 1935|       |
 1936|  2.75k|    switch(timeout) {
 1937|      0|        case -2: /*
  ------------------
  |  Branch (1937:9): [True: 0, False: 2.75k]
  ------------------
 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.75k]
  ------------------
 1946|      0|            return 0;
 1947|      0|        case 0: /* 0 means no timeout */
  ------------------
  |  Branch (1947:9): [True: 0, False: 2.75k]
  ------------------
 1948|      0|            return 1;
 1949|  2.75k|        default:
  ------------------
  |  Branch (1949:9): [True: 2.75k, False: 0]
  ------------------
 1950|  2.75k|            break;
 1951|  2.75k|    }
 1952|       |
 1953|  2.75k|    ssh_timestamp_init(&now);
 1954|       |
 1955|  2.75k|    return (ssh_timestamp_difference(ts,&now) >= timeout);
 1956|  2.75k|}
ssh_timeout_update:
 1966|  5.76k|{
 1967|  5.76k|  struct ssh_timestamp now;
 1968|  5.76k|  int ms, ret;
 1969|  5.76k|  if (timeout <= 0) {
  ------------------
  |  Branch (1969:7): [True: 0, False: 5.76k]
  ------------------
 1970|      0|      return timeout;
 1971|      0|  }
 1972|  5.76k|  ssh_timestamp_init(&now);
 1973|  5.76k|  ms = ssh_timestamp_difference(ts,&now);
 1974|  5.76k|  if(ms < 0)
  ------------------
  |  Branch (1974:6): [True: 0, False: 5.76k]
  ------------------
 1975|      0|    ms = 0;
 1976|  5.76k|  ret = timeout - ms;
 1977|  5.76k|  return ret >= 0 ? ret: 0;
  ------------------
  |  Branch (1977:10): [True: 5.76k, False: 0]
  ------------------
 1978|  5.76k|}
ssh_strerror:
 2396|  2.91k|{
 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.91k|    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.91k|    rv = strerror_r(err_num, buf, buflen);
 2408|  2.91k|#endif /* _WIN32 */
 2409|       |
 2410|       |    /* make sure the buffer is initialized and terminated with NULL */
 2411|  2.91k|    if (-rv == ERANGE) {
  ------------------
  |  Branch (2411:9): [True: 0, False: 2.91k]
  ------------------
 2412|      0|        buf[0] = '\0';
 2413|      0|    }
 2414|  2.91k|    return buf;
 2415|  2.91k|#endif /* ((defined(__linux__) && defined(__GLIBC__)) || defined(__CYGWIN__)) && defined(_GNU_SOURCE) */
 2416|  2.91k|}
ssh_check_username_syntax:
 2606|    800|{
 2607|    800|    size_t username_len;
 2608|       |
 2609|    800|    if (username == NULL || *username == '-') {
  ------------------
  |  Branch (2609:9): [True: 0, False: 800]
  |  Branch (2609:29): [True: 0, False: 800]
  ------------------
 2610|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2611|      0|    }
 2612|       |
 2613|    800|    username_len = strlen(username);
 2614|    800|    if (username_len == 0 || username[username_len - 1] == '\\' ||
  ------------------
  |  Branch (2614:9): [True: 0, False: 800]
  |  Branch (2614:30): [True: 0, False: 800]
  ------------------
 2615|    800|        strpbrk(username, "'`\";&<>|(){}") != NULL) {
  ------------------
  |  Branch (2615:9): [True: 0, False: 800]
  ------------------
 2616|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2617|      0|    }
 2618|  4.80k|    for (size_t i = 0; i < username_len; i++) {
  ------------------
  |  Branch (2618:24): [True: 4.00k, False: 800]
  ------------------
 2619|  4.00k|        if (isspace(username[i]) != 0 && username[i + 1] == '-') {
  ------------------
  |  Branch (2619:13): [True: 0, False: 4.00k]
  |  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|  4.00k|    }
 2623|       |
 2624|    800|    return SSH_OK;
  ------------------
  |  |  316|    800|#define SSH_OK 0     /* No error */
  ------------------
 2625|    800|}
ssh_proxyjumps_free:
 2637|  1.18k|{
 2638|  1.18k|    struct ssh_jump_info_struct *jump = NULL;
 2639|       |
 2640|  1.18k|    for (jump =
 2641|  1.18k|             ssh_list_pop_head(struct ssh_jump_info_struct *, proxy_jump_list);
  ------------------
  |  |  122|  1.18k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2642|  1.18k|         jump != NULL;
  ------------------
  |  Branch (2642:10): [True: 0, False: 1.18k]
  ------------------
 2643|  1.18k|         jump = ssh_list_pop_head(struct ssh_jump_info_struct *,
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2644|  1.18k|                                  proxy_jump_list)) {
 2645|      0|        SAFE_FREE(jump->hostname);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2646|      0|        SAFE_FREE(jump->username);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2647|       |        SAFE_FREE(jump);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2648|      0|    }
 2649|  1.18k|}
ssh_strict_fopen:
 2683|  1.45k|{
 2684|  1.45k|    FILE *f = NULL;
 2685|  1.45k|    struct stat sb;
 2686|  1.45k|    int r, fd;
 2687|       |
 2688|       |    /* open first to avoid TOCTOU */
 2689|  1.45k|    fd = open(filename, O_RDONLY);
 2690|  1.45k|    if (fd == -1) {
  ------------------
  |  Branch (2690:9): [True: 1.45k, False: 0]
  ------------------
 2691|  1.45k|        SSH_LOG_STRERROR(SSH_LOG_TRACE,
  ------------------
  |  |  283|  1.45k|    do {                                                            \
  |  |  284|  1.45k|        char err_msg[SSH_ERRNO_MSG_MAX] = {0};                      \
  |  |  285|  1.45k|        _ssh_log(priority,                                          \
  |  |  286|  1.45k|                 __func__,                                          \
  |  |  287|  1.45k|                 __VA_ARGS__,                                       \
  |  |  288|  1.45k|                 ssh_strerror(errnum, err_msg, SSH_ERRNO_MSG_MAX)); \
  |  |  ------------------
  |  |  |  |  520|  1.45k|#define SSH_ERRNO_MSG_MAX   1024
  |  |  ------------------
  |  |  289|  1.45k|    } while (0)
  |  |  ------------------
  |  |  |  Branch (289:14): [Folded, False: 1.45k]
  |  |  ------------------
  ------------------
 2692|  1.45k|                         errno,
 2693|  1.45k|                         "Failed to open a file %s for reading: %s",
 2694|  1.45k|                         filename);
 2695|  1.45k|        return NULL;
 2696|  1.45k|    }
 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|  3.20k|{
 2750|  3.20k|    size_t len = strlen(src);
 2751|       |
 2752|  3.20k|    if (size != 0) {
  ------------------
  |  Branch (2752:9): [True: 3.20k, False: 0]
  ------------------
 2753|  3.20k|        size_t copy_len = (len >= size) ? size - 1 : len;
  ------------------
  |  Branch (2753:27): [True: 0, False: 3.20k]
  ------------------
 2754|       |
 2755|  3.20k|        memcpy(dst, src, copy_len);
 2756|  3.20k|        dst[copy_len] = '\0';
 2757|  3.20k|    }
 2758|       |
 2759|  3.20k|    return len;
 2760|  3.20k|}
ssh_normalize_loose_ip:
 2797|  1.60k|{
 2798|  1.60k|    struct in_addr addr;
 2799|  1.60k|    char buf[INET_ADDRSTRLEN];
 2800|  1.60k|    const char *p = NULL;
 2801|  1.60k|    int rc;
 2802|  1.60k|    int is_ip;
 2803|       |#ifdef _WIN32
 2804|       |    unsigned long ip;
 2805|       |    int is_broadcast;
 2806|       |#endif
 2807|       |
 2808|  1.60k|    if (host == NULL || result == NULL) {
  ------------------
  |  Branch (2808:9): [True: 0, False: 1.60k]
  |  Branch (2808:25): [True: 0, False: 1.60k]
  ------------------
 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.60k|    is_ip = ssh_is_ipaddr(host);
 2815|  1.60k|    if (is_ip) {
  ------------------
  |  Branch (2815:9): [True: 1.60k, False: 0]
  ------------------
 2816|  1.60k|        return 1; /* not a loose IP — already a strict address */
 2817|  1.60k|    }
 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.60k|{
  330|  1.60k|    char *szPath = NULL;
  331|  1.60k|    struct passwd pwd;
  332|  1.60k|    struct passwd *pwdbuf = NULL;
  333|  1.60k|    char buf[NSS_BUFLEN_PASSWD] = {0};
  334|  1.60k|    int rc;
  335|       |
  336|  1.60k|    rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
  337|  1.60k|    if (rc != 0 || pwdbuf == NULL ) {
  ------------------
  |  Branch (337:9): [True: 0, False: 1.60k]
  |  Branch (337:20): [True: 0, False: 1.60k]
  ------------------
  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.60k|    szPath = strdup(pwd.pw_dir);
  347|       |
  348|  1.60k|    return szPath;
  349|  1.60k|}
misc.c:ssh_iterator_new:
  947|  5.88k|{
  948|  5.88k|    struct ssh_iterator *iterator = malloc(sizeof(struct ssh_iterator));
  949|       |
  950|  5.88k|    if (iterator == NULL) {
  ------------------
  |  Branch (950:9): [True: 0, False: 5.88k]
  ------------------
  951|      0|        return NULL;
  952|      0|    }
  953|  5.88k|    iterator->next = NULL;
  954|  5.88k|    iterator->data = data;
  955|  5.88k|    return iterator;
  956|  5.88k|}
misc.c:ssh_path_expand_internal:
 1478|  3.20k|{
 1479|  3.20k|    char *buf = NULL;
 1480|  3.20k|    char *r = NULL;
 1481|  3.20k|    char *x = NULL;
 1482|  3.20k|    const char *p = NULL;
 1483|  3.20k|    size_t i, l;
 1484|       |
 1485|  3.20k|    r = ssh_path_expand_tilde(s);
 1486|  3.20k|    if (r == NULL) {
  ------------------
  |  Branch (1486:9): [True: 0, False: 3.20k]
  ------------------
 1487|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1488|      0|        return NULL;
 1489|      0|    }
 1490|       |
 1491|  3.20k|    if (strlen(r) > MAX_BUF_SIZE) {
  ------------------
  |  |  230|  3.20k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1491:9): [True: 0, False: 3.20k]
  ------------------
 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|  3.20k|    buf = malloc(MAX_BUF_SIZE);
  ------------------
  |  |  230|  3.20k|#define MAX_BUF_SIZE 4096
  ------------------
 1498|  3.20k|    if (buf == NULL) {
  ------------------
  |  Branch (1498:9): [True: 0, False: 3.20k]
  ------------------
 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|  3.20k|    p = r;
 1505|  3.20k|    buf[0] = '\0';
 1506|       |
 1507|  53.6k|    for (i = 0; *p != '\0'; p++) {
  ------------------
  |  Branch (1507:17): [True: 50.4k, False: 3.20k]
  ------------------
 1508|  50.4k|        if (*p != '%') {
  ------------------
  |  Branch (1508:13): [True: 47.2k, False: 3.20k]
  ------------------
 1509|  47.2k|            buf[i] = hostname_lenient ? tolower((unsigned char)*p) : *p;
  ------------------
  |  Branch (1509:22): [True: 0, False: 47.2k]
  |  Branch (1509:41): [True: 0, False: 0]
  |  Branch (1509:41): [True: 0, False: 0]
  |  Branch (1509:41): [Folded, False: 0]
  ------------------
 1510|  47.2k|            i++;
 1511|  47.2k|            if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|  47.2k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1511:17): [True: 0, False: 47.2k]
  ------------------
 1512|      0|                free(buf);
 1513|      0|                free(r);
 1514|      0|                return NULL;
 1515|      0|            }
 1516|  47.2k|            buf[i] = '\0';
 1517|  47.2k|            continue;
 1518|  47.2k|        }
 1519|       |
 1520|  3.20k|        p++;
 1521|  3.20k|        if (*p == '\0') {
  ------------------
  |  Branch (1521:13): [True: 0, False: 3.20k]
  ------------------
 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|  3.20k|        if (hostname_lenient && *p != '%' && *p != 'h') {
  ------------------
  |  Branch (1535:13): [True: 0, False: 3.20k]
  |  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|  3.20k|        switch (*p) {
 1557|      0|        case '%':
  ------------------
  |  Branch (1557:9): [True: 0, False: 3.20k]
  ------------------
 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|  3.20k|        case 'd':
  ------------------
  |  Branch (1567:9): [True: 3.20k, False: 0]
  ------------------
 1568|  3.20k|            x = ssh_get_user_home_dir(session);
 1569|  3.20k|            if (x == NULL) {
  ------------------
  |  Branch (1569:17): [True: 0, False: 3.20k]
  ------------------
 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|  3.20k|            break;
 1576|  3.20k|        case 'u':
  ------------------
  |  Branch (1576:9): [True: 0, False: 3.20k]
  ------------------
 1577|      0|            x = ssh_get_local_username();
 1578|      0|            break;
 1579|      0|        case 'l':
  ------------------
  |  Branch (1579:9): [True: 0, False: 3.20k]
  ------------------
 1580|      0|            x = ssh_get_local_hostname();
 1581|      0|            break;
 1582|      0|        case 'h':
  ------------------
  |  Branch (1582:9): [True: 0, False: 3.20k]
  ------------------
 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: 3.20k]
  ------------------
 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: 3.20k]
  ------------------
 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: 3.20k]
  ------------------
 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: 3.20k]
  ------------------
 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: 3.20k]
  ------------------
 1635|      0|            x = get_connection_hash(session);
 1636|      0|            break;
 1637|      0|        default:
  ------------------
  |  Branch (1637:9): [True: 0, False: 3.20k]
  ------------------
 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|  3.20k|        }
 1643|       |
 1644|  3.20k|        if (x == NULL) {
  ------------------
  |  Branch (1644:13): [True: 0, False: 3.20k]
  ------------------
 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|  3.20k|        i += strlen(x);
 1652|  3.20k|        if (i >= MAX_BUF_SIZE) {
  ------------------
  |  |  230|  3.20k|#define MAX_BUF_SIZE 4096
  ------------------
  |  Branch (1652:13): [True: 0, False: 3.20k]
  ------------------
 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|  3.20k|        l = strlen(buf);
 1660|  3.20k|        strlcpy(buf + l, x, MAX_BUF_SIZE - l);
  ------------------
  |  |  230|  3.20k|#define MAX_BUF_SIZE 4096
  ------------------
 1661|  3.20k|        buf[i] = '\0';
 1662|  3.20k|        SAFE_FREE(x);
  ------------------
  |  |  373|  3.20k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 3.20k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 3.20k]
  |  |  ------------------
  ------------------
 1663|  3.20k|    }
 1664|       |
 1665|  3.20k|    free(r);
 1666|       |
 1667|       |    /* strip the unused space by realloc */
 1668|  3.20k|    x = realloc(buf, strlen(buf) + 1);
 1669|  3.20k|    if (x == NULL) {
  ------------------
  |  Branch (1669:9): [True: 0, False: 3.20k]
  ------------------
 1670|      0|        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1671|      0|        free(buf);
 1672|      0|    }
 1673|  3.20k|    return x;
 1674|  3.20k|}
misc.c:ssh_timestamp_difference:
 1875|  8.51k|{
 1876|  8.51k|    long seconds, usecs, msecs;
 1877|  8.51k|    seconds = new->seconds - old->seconds;
 1878|  8.51k|    usecs = new->useconds - old->useconds;
 1879|  8.51k|    if (usecs < 0){
  ------------------
  |  Branch (1879:9): [True: 52, False: 8.46k]
  ------------------
 1880|     52|        seconds--;
 1881|     52|        usecs += 1000000;
 1882|     52|    }
 1883|  8.51k|    msecs = seconds * 1000 + usecs/1000;
 1884|  8.51k|    return msecs;
 1885|  8.51k|}

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

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

ssh_options_set_algo:
  327|  3.20k|{
  328|       |    /* When the list start with +,-,^ the filtration of unknown algorithms
  329|       |     * gets handled inside the helper functions, otherwise the list is taken
  330|       |     * as it is. */
  331|  3.20k|    char *p = (char *)list;
  332|       |
  333|  3.20k|    if (algo < SSH_COMP_C_S) {
  ------------------
  |  Branch (333:9): [True: 3.20k, False: 0]
  ------------------
  334|  3.20k|        if (list[0] == '+') {
  ------------------
  |  Branch (334:13): [True: 0, False: 3.20k]
  ------------------
  335|      0|            p = ssh_add_to_default_algos(algo, list+1);
  336|  3.20k|        } else if (list[0] == '-') {
  ------------------
  |  Branch (336:20): [True: 0, False: 3.20k]
  ------------------
  337|      0|            p = ssh_remove_from_default_algos(algo, list+1);
  338|  3.20k|        } else if (list[0] == '^') {
  ------------------
  |  Branch (338:20): [True: 0, False: 3.20k]
  ------------------
  339|      0|            p = ssh_prefix_default_algos(algo, list+1);
  340|      0|        }
  341|  3.20k|    }
  342|       |
  343|  3.20k|    if (p == list) {
  ------------------
  |  Branch (343:9): [True: 3.20k, False: 0]
  ------------------
  344|  3.20k|        if (ssh_fips_mode()) {
  ------------------
  |  |  115|  3.20k|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 3.20k]
  |  |  ------------------
  ------------------
  345|      0|            p = ssh_keep_fips_algos(algo, list);
  346|  3.20k|        } else {
  347|  3.20k|            p = ssh_keep_known_algos(algo, list);
  348|  3.20k|        }
  349|  3.20k|    }
  350|       |
  351|  3.20k|    if (p == NULL) {
  ------------------
  |  Branch (351:9): [True: 0, False: 3.20k]
  ------------------
  352|      0|        ssh_set_error(session, SSH_REQUEST_DENIED,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  353|      0|                "Setting method: no allowed algorithm for method \"%s\" (%s)",
  354|      0|                ssh_kex_get_description(algo), list);
  355|      0|        return -1;
  356|      0|    }
  357|       |
  358|  3.20k|    SAFE_FREE(*place);
  ------------------
  |  |  373|  3.20k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 3.20k]
  |  |  |  Branch (373:71): [Folded, False: 3.20k]
  |  |  ------------------
  ------------------
  359|  3.20k|    *place = p;
  360|       |
  361|  3.20k|    return 0;
  362|  3.20k|}
ssh_options_set:
  755|  8.00k|{
  756|  8.00k|    const char *v = NULL;
  757|  8.00k|    char *p = NULL, *q = NULL;
  758|  8.00k|    long int i;
  759|  8.00k|    unsigned int u;
  760|  8.00k|    int rc;
  761|  8.00k|    char **wanted_methods = session->opts.wanted_methods;
  762|  8.00k|    struct ssh_jump_callbacks_struct *j = NULL;
  763|       |
  764|  8.00k|    if (session == NULL) {
  ------------------
  |  Branch (764:9): [True: 0, False: 8.00k]
  ------------------
  765|      0|        return -1;
  766|      0|    }
  767|       |
  768|  8.00k|    switch (type) {
  769|    800|        case SSH_OPTIONS_HOST:
  ------------------
  |  Branch (769:9): [True: 800, False: 7.20k]
  ------------------
  770|    800|            v = value;
  771|    800|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (771:17): [True: 0, False: 800]
  |  Branch (771:30): [True: 0, False: 800]
  ------------------
  772|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  773|      0|                return -1;
  774|    800|            } else {
  775|    800|                char *username = NULL, *hostname = NULL;
  776|    800|                char *strict_hostname = NULL;
  777|    800|                char *normalized = NULL;
  778|       |
  779|       |                /* Non-strict parse: reject shell metacharacters */
  780|    800|                rc = ssh_config_parse_uri(value,
  781|    800|                                          &username,
  782|    800|                                          &hostname,
  783|    800|                                          NULL,
  784|    800|                                          true,
  785|    800|                                          false);
  786|    800|                if (rc != SSH_OK || hostname == NULL) {
  ------------------
  |  |  316|  1.60k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (786:21): [True: 0, False: 800]
  |  Branch (786:37): [True: 0, False: 800]
  ------------------
  787|      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]
  |  |  ------------------
  ------------------
  788|      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]
  |  |  ------------------
  ------------------
  789|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  790|      0|                    return -1;
  791|      0|                }
  792|       |
  793|       |                /* Non-strict passed: set username and originalhost */
  794|    800|                if (username != NULL) {
  ------------------
  |  Branch (794:21): [True: 0, False: 800]
  ------------------
  795|      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]
  |  |  ------------------
  ------------------
  796|      0|                    session->opts.username = username;
  797|      0|                }
  798|    800|                if (!session->opts.config_hostname_only) {
  ------------------
  |  Branch (798:21): [True: 800, False: 0]
  ------------------
  799|    800|                    SAFE_FREE(session->opts.config_hostname);
  ------------------
  |  |  373|    800|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 800]
  |  |  |  Branch (373:71): [Folded, False: 800]
  |  |  ------------------
  ------------------
  800|    800|                    SAFE_FREE(session->opts.originalhost);
  ------------------
  |  |  373|    800|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 800]
  |  |  |  Branch (373:71): [Folded, False: 800]
  |  |  ------------------
  ------------------
  801|    800|                    session->opts.originalhost = hostname;
  802|    800|                } else {
  803|      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]
  |  |  ------------------
  ------------------
  804|      0|                }
  805|       |
  806|       |                /* Strict parse: set host only if valid hostname or IP */
  807|    800|                rc = ssh_normalize_loose_ip(value, &normalized);
  808|    800|                if (rc == -1) {
  ------------------
  |  Branch (808:21): [True: 0, False: 800]
  ------------------
  809|       |                    /* Error */
  810|      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]
  |  |  ------------------
  ------------------
  811|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  812|      0|                    return -1;
  813|      0|                }
  814|    800|                rc = ssh_config_parse_uri(
  815|    800|                    (normalized != NULL) ? normalized : value,
  ------------------
  |  Branch (815:21): [True: 0, False: 800]
  ------------------
  816|    800|                    NULL,
  817|    800|                    &strict_hostname,
  818|    800|                    NULL,
  819|    800|                    true,
  820|    800|                    true);
  821|    800|                SAFE_FREE(normalized);
  ------------------
  |  |  373|    800|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 800]
  |  |  |  Branch (373:71): [Folded, False: 800]
  |  |  ------------------
  ------------------
  822|       |
  823|    800|                if (rc != SSH_OK || strict_hostname == NULL) {
  ------------------
  |  |  316|  1.60k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (823:21): [True: 0, False: 800]
  |  Branch (823:37): [True: 0, False: 800]
  ------------------
  824|      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]
  |  |  ------------------
  ------------------
  825|      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]
  |  |  ------------------
  ------------------
  826|      0|                    if (session->opts.config_hostname_only) {
  ------------------
  |  Branch (826:25): [True: 0, False: 0]
  ------------------
  827|       |                        /* Config path: Hostname must be valid */
  828|      0|                        ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  829|      0|                        return -1;
  830|      0|                    }
  831|    800|                } else {
  832|    800|                    SAFE_FREE(session->opts.host);
  ------------------
  |  |  373|    800|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 800]
  |  |  |  Branch (373:71): [Folded, False: 800]
  |  |  ------------------
  ------------------
  833|    800|                    session->opts.host = strict_hostname;
  834|    800|                }
  835|    800|            }
  836|    800|            break;
  837|    800|        case SSH_OPTIONS_PORT:
  ------------------
  |  Branch (837:9): [True: 0, False: 8.00k]
  ------------------
  838|      0|            if (value == NULL) {
  ------------------
  |  Branch (838:17): [True: 0, False: 0]
  ------------------
  839|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  840|      0|                return -1;
  841|      0|            } else {
  842|      0|                int *x = (int *) value;
  843|      0|                if (*x <= 0 || *x > 65535) {
  ------------------
  |  Branch (843:21): [True: 0, False: 0]
  |  Branch (843:32): [True: 0, False: 0]
  ------------------
  844|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  845|      0|                    return -1;
  846|      0|                }
  847|       |
  848|      0|                session->opts.port = *x;
  849|      0|            }
  850|      0|            break;
  851|      0|        case SSH_OPTIONS_PORT_STR:
  ------------------
  |  Branch (851:9): [True: 0, False: 8.00k]
  ------------------
  852|      0|            v = value;
  853|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (853:17): [True: 0, False: 0]
  |  Branch (853:30): [True: 0, False: 0]
  ------------------
  854|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  855|      0|                return -1;
  856|      0|            } else {
  857|      0|                q = strdup(v);
  858|      0|                if (q == NULL) {
  ------------------
  |  Branch (858:21): [True: 0, False: 0]
  ------------------
  859|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  860|      0|                    return -1;
  861|      0|                }
  862|      0|                i = strtol(q, &p, 10);
  863|      0|                if (q == p || *p != '\0') {
  ------------------
  |  Branch (863:21): [True: 0, False: 0]
  |  Branch (863:31): [True: 0, False: 0]
  ------------------
  864|      0|                    SSH_LOG(SSH_LOG_DEBUG, "No port number was parsed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  865|      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]
  |  |  ------------------
  ------------------
  866|      0|                    return -1;
  867|      0|                }
  868|      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]
  |  |  ------------------
  ------------------
  869|      0|                if (i <= 0 || i > 65535) {
  ------------------
  |  Branch (869:21): [True: 0, False: 0]
  |  Branch (869:31): [True: 0, False: 0]
  ------------------
  870|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  871|      0|                    return -1;
  872|      0|                }
  873|       |
  874|      0|                session->opts.port = i;
  875|      0|            }
  876|      0|            break;
  877|    800|        case SSH_OPTIONS_FD:
  ------------------
  |  Branch (877:9): [True: 800, False: 7.20k]
  ------------------
  878|    800|            if (value == NULL) {
  ------------------
  |  Branch (878:17): [True: 0, False: 800]
  ------------------
  879|      0|                session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  880|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  881|      0|                return -1;
  882|    800|            } else {
  883|    800|                socket_t *x = (socket_t *) value;
  884|    800|                if (*x < 0) {
  ------------------
  |  Branch (884:21): [True: 0, False: 800]
  ------------------
  885|      0|                    session->opts.fd = SSH_INVALID_SOCKET;
  ------------------
  |  |  124|      0|#define SSH_INVALID_SOCKET ((socket_t) -1)
  ------------------
  886|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  887|      0|                    return -1;
  888|      0|                }
  889|       |
  890|    800|                session->opts.fd = *x & 0xffff;
  891|    800|            }
  892|    800|            break;
  893|    800|        case SSH_OPTIONS_BINDADDR:
  ------------------
  |  Branch (893:9): [True: 0, False: 8.00k]
  ------------------
  894|      0|            v = value;
  895|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (895:17): [True: 0, False: 0]
  |  Branch (895:30): [True: 0, False: 0]
  ------------------
  896|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  897|      0|                return -1;
  898|      0|            }
  899|       |
  900|      0|            q = strdup(v);
  901|      0|            if (q == NULL) {
  ------------------
  |  Branch (901:17): [True: 0, False: 0]
  ------------------
  902|      0|                return -1;
  903|      0|            }
  904|      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]
  |  |  ------------------
  ------------------
  905|      0|            session->opts.bindaddr = q;
  906|      0|            break;
  907|    800|        case SSH_OPTIONS_USER:
  ------------------
  |  Branch (907:9): [True: 800, False: 7.20k]
  ------------------
  908|    800|            v = value;
  909|    800|            SAFE_FREE(session->opts.username);
  ------------------
  |  |  373|    800|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 800]
  |  |  |  Branch (373:71): [Folded, False: 800]
  |  |  ------------------
  ------------------
  910|    800|            if (v == NULL) {
  ------------------
  |  Branch (910:17): [True: 0, False: 800]
  ------------------
  911|      0|                q = ssh_get_local_username();
  912|      0|                if (q == NULL) {
  ------------------
  |  Branch (912:21): [True: 0, False: 0]
  ------------------
  913|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  914|      0|                    return -1;
  915|      0|                }
  916|      0|                session->opts.username = q;
  917|    800|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (917:24): [True: 0, False: 800]
  ------------------
  918|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  919|      0|                return -1;
  920|    800|            } else { /* username provided */
  921|    800|                session->opts.username = strdup(value);
  922|    800|                if (session->opts.username == NULL) {
  ------------------
  |  Branch (922:21): [True: 0, False: 800]
  ------------------
  923|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  924|      0|                    return -1;
  925|      0|                }
  926|    800|                rc = ssh_check_username_syntax(session->opts.username);
  927|    800|                if (rc != SSH_OK) {
  ------------------
  |  |  316|    800|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (927:21): [True: 0, False: 800]
  ------------------
  928|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  929|      0|                    return -1;
  930|      0|                }
  931|    800|            }
  932|    800|            break;
  933|    800|        case SSH_OPTIONS_SSH_DIR:
  ------------------
  |  Branch (933:9): [True: 800, False: 7.20k]
  ------------------
  934|    800|            v = value;
  935|    800|            SAFE_FREE(session->opts.sshdir);
  ------------------
  |  |  373|    800|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 800]
  |  |  |  Branch (373:71): [Folded, False: 800]
  |  |  ------------------
  ------------------
  936|    800|            if (v == NULL) {
  ------------------
  |  Branch (936:17): [True: 800, False: 0]
  ------------------
  937|    800|                session->opts.sshdir = ssh_path_expand_tilde("~/.ssh");
  938|    800|                if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (938:21): [True: 0, False: 800]
  ------------------
  939|      0|                    return -1;
  940|      0|                }
  941|    800|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (941:24): [True: 0, False: 0]
  ------------------
  942|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  943|      0|                return -1;
  944|      0|            } else {
  945|      0|                session->opts.sshdir = ssh_path_expand_tilde(v);
  946|      0|                if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (946:21): [True: 0, False: 0]
  ------------------
  947|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
  948|      0|                    return -1;
  949|      0|                }
  950|      0|            }
  951|    800|            break;
  952|    800|        case SSH_OPTIONS_IDENTITY:
  ------------------
  |  Branch (952:9): [True: 0, False: 8.00k]
  ------------------
  953|      0|        case SSH_OPTIONS_ADD_IDENTITY:
  ------------------
  |  Branch (953:9): [True: 0, False: 8.00k]
  ------------------
  954|      0|            v = value;
  955|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (955:17): [True: 0, False: 0]
  |  Branch (955:30): [True: 0, False: 0]
  ------------------
  956|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  957|      0|                return -1;
  958|      0|            }
  959|      0|            q = strdup(v);
  960|      0|            if (q == NULL) {
  ------------------
  |  Branch (960:17): [True: 0, False: 0]
  ------------------
  961|      0|                return -1;
  962|      0|            }
  963|      0|            if (session->opts.exp_flags & SSH_OPT_EXP_FLAG_IDENTITY) {
  ------------------
  |  |  118|      0|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
  |  Branch (963:17): [True: 0, False: 0]
  ------------------
  964|      0|                rc = ssh_list_append(session->opts.identity_non_exp, q);
  965|      0|            } else {
  966|      0|                rc = ssh_list_prepend(session->opts.identity_non_exp, q);
  967|      0|            }
  968|      0|            if (rc < 0) {
  ------------------
  |  Branch (968:17): [True: 0, False: 0]
  ------------------
  969|      0|                free(q);
  970|      0|                return -1;
  971|      0|            }
  972|      0|            break;
  973|      0|        case SSH_OPTIONS_CERTIFICATE:
  ------------------
  |  Branch (973:9): [True: 0, False: 8.00k]
  ------------------
  974|      0|            v = value;
  975|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (975:17): [True: 0, False: 0]
  |  Branch (975:30): [True: 0, False: 0]
  ------------------
  976|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  977|      0|                return -1;
  978|      0|            }
  979|      0|            q = strdup(v);
  980|      0|            if (q == NULL) {
  ------------------
  |  Branch (980:17): [True: 0, False: 0]
  ------------------
  981|      0|                return -1;
  982|      0|            }
  983|      0|            rc = ssh_list_append(session->opts.certificate_non_exp, q);
  984|      0|            if (rc < 0) {
  ------------------
  |  Branch (984:17): [True: 0, False: 0]
  ------------------
  985|      0|                free(q);
  986|      0|                return -1;
  987|      0|            }
  988|      0|            break;
  989|      0|        case SSH_OPTIONS_KNOWNHOSTS:
  ------------------
  |  Branch (989:9): [True: 0, False: 8.00k]
  ------------------
  990|      0|            v = value;
  991|      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]
  |  |  ------------------
  ------------------
  992|      0|            if (v == NULL) {
  ------------------
  |  Branch (992:17): [True: 0, False: 0]
  ------------------
  993|       |                /* The default value will be set by the ssh_options_apply() */
  994|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (994:24): [True: 0, False: 0]
  ------------------
  995|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
  996|      0|                return -1;
  997|      0|            } else {
  998|      0|                session->opts.knownhosts = strdup(v);
  999|      0|                if (session->opts.knownhosts == NULL) {
  ------------------
  |  Branch (999:21): [True: 0, False: 0]
  ------------------
 1000|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1001|      0|                    return -1;
 1002|      0|                }
 1003|      0|                session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_KNOWNHOSTS;
  ------------------
  |  |  115|      0|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
 1004|      0|            }
 1005|      0|            break;
 1006|      0|        case SSH_OPTIONS_GLOBAL_KNOWNHOSTS:
  ------------------
  |  Branch (1006:9): [True: 0, False: 8.00k]
  ------------------
 1007|      0|            v = value;
 1008|      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]
  |  |  ------------------
  ------------------
 1009|      0|            if (v == NULL) {
  ------------------
  |  Branch (1009:17): [True: 0, False: 0]
  ------------------
 1010|      0|                session->opts.global_knownhosts =
 1011|      0|                    strdup(GLOBAL_CONF_DIR "/ssh_known_hosts");
  ------------------
  |  |   13|      0|#define GLOBAL_CONF_DIR "/etc/ssh"
  ------------------
 1012|      0|                if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (1012:21): [True: 0, False: 0]
  ------------------
 1013|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1014|      0|                    return -1;
 1015|      0|                }
 1016|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1016:24): [True: 0, False: 0]
  ------------------
 1017|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1018|      0|                return -1;
 1019|      0|            } else {
 1020|      0|                session->opts.global_knownhosts = strdup(v);
 1021|      0|                if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (1021:21): [True: 0, False: 0]
  ------------------
 1022|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1023|      0|                    return -1;
 1024|      0|                }
 1025|      0|                session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS;
  ------------------
  |  |  116|      0|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
 1026|      0|            }
 1027|      0|            break;
 1028|    800|        case SSH_OPTIONS_TIMEOUT:
  ------------------
  |  Branch (1028:9): [True: 800, False: 7.20k]
  ------------------
 1029|    800|            if (value == NULL) {
  ------------------
  |  Branch (1029:17): [True: 0, False: 800]
  ------------------
 1030|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1031|      0|                return -1;
 1032|    800|            } else {
 1033|    800|                long *x = (long *) value;
 1034|    800|                if (*x < 0) {
  ------------------
  |  Branch (1034:21): [True: 0, False: 800]
  ------------------
 1035|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1036|      0|                    return -1;
 1037|      0|                }
 1038|       |
 1039|    800|                session->opts.timeout = *x & 0xffffffffU;
 1040|    800|            }
 1041|    800|            break;
 1042|    800|        case SSH_OPTIONS_TIMEOUT_USEC:
  ------------------
  |  Branch (1042:9): [True: 0, False: 8.00k]
  ------------------
 1043|      0|            if (value == NULL) {
  ------------------
  |  Branch (1043:17): [True: 0, False: 0]
  ------------------
 1044|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1045|      0|                return -1;
 1046|      0|            } else {
 1047|      0|                long *x = (long *) value;
 1048|      0|                if (*x < 0) {
  ------------------
  |  Branch (1048:21): [True: 0, False: 0]
  ------------------
 1049|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1050|      0|                    return -1;
 1051|      0|                }
 1052|       |
 1053|      0|                session->opts.timeout_usec = *x & 0xffffffffU;
 1054|      0|            }
 1055|      0|            break;
 1056|      0|        case SSH_OPTIONS_SSH1:
  ------------------
  |  Branch (1056:9): [True: 0, False: 8.00k]
  ------------------
 1057|      0|            break;
 1058|      0|        case SSH_OPTIONS_SSH2:
  ------------------
  |  Branch (1058:9): [True: 0, False: 8.00k]
  ------------------
 1059|      0|            break;
 1060|      0|        case SSH_OPTIONS_LOG_VERBOSITY:
  ------------------
  |  Branch (1060:9): [True: 0, False: 8.00k]
  ------------------
 1061|      0|            if (value == NULL) {
  ------------------
  |  Branch (1061:17): [True: 0, False: 0]
  ------------------
 1062|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1063|      0|                return -1;
 1064|      0|            } else {
 1065|      0|                int *x = (int *) value;
 1066|      0|                if (*x < 0) {
  ------------------
  |  Branch (1066:21): [True: 0, False: 0]
  ------------------
 1067|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1068|      0|                    return -1;
 1069|      0|                }
 1070|       |
 1071|      0|                session->common.log_verbosity = *x & 0xffffU;
 1072|      0|                ssh_set_log_level(*x & 0xffffU);
 1073|      0|            }
 1074|      0|            break;
 1075|      0|        case SSH_OPTIONS_LOG_VERBOSITY_STR:
  ------------------
  |  Branch (1075:9): [True: 0, False: 8.00k]
  ------------------
 1076|      0|            v = value;
 1077|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1077:17): [True: 0, False: 0]
  |  Branch (1077:30): [True: 0, False: 0]
  ------------------
 1078|      0|                session->common.log_verbosity = 0;
 1079|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1080|      0|                return -1;
 1081|      0|            } else {
 1082|      0|                q = strdup(v);
 1083|      0|                if (q == NULL) {
  ------------------
  |  Branch (1083:21): [True: 0, False: 0]
  ------------------
 1084|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1085|      0|                    return -1;
 1086|      0|                }
 1087|      0|                i = strtol(q, &p, 10);
 1088|      0|                if (q == p) {
  ------------------
  |  Branch (1088:21): [True: 0, False: 0]
  ------------------
 1089|      0|                    SSH_LOG(SSH_LOG_DEBUG, "No log verbositiy was parsed");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1090|      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]
  |  |  ------------------
  ------------------
 1091|      0|                    return -1;
 1092|      0|                }
 1093|      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]
  |  |  ------------------
  ------------------
 1094|      0|                if (i < 0) {
  ------------------
  |  Branch (1094:21): [True: 0, False: 0]
  ------------------
 1095|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1096|      0|                    return -1;
 1097|      0|                }
 1098|       |
 1099|      0|                session->common.log_verbosity = i & 0xffffU;
 1100|      0|                ssh_set_log_level(i & 0xffffU);
 1101|      0|            }
 1102|      0|            break;
 1103|    800|        case SSH_OPTIONS_CIPHERS_C_S:
  ------------------
  |  Branch (1103:9): [True: 800, False: 7.20k]
  ------------------
 1104|    800|            v = value;
 1105|    800|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1105:17): [True: 0, False: 800]
  |  Branch (1105:30): [True: 0, False: 800]
  ------------------
 1106|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1107|      0|                return -1;
 1108|    800|            } else {
 1109|    800|                rc = ssh_options_set_algo(session,
 1110|    800|                                          SSH_CRYPT_C_S,
 1111|    800|                                          v,
 1112|    800|                                          &wanted_methods[SSH_CRYPT_C_S]);
 1113|    800|                if (rc < 0)
  ------------------
  |  Branch (1113:21): [True: 0, False: 800]
  ------------------
 1114|      0|                    return -1;
 1115|    800|            }
 1116|    800|            break;
 1117|    800|        case SSH_OPTIONS_CIPHERS_S_C:
  ------------------
  |  Branch (1117:9): [True: 800, False: 7.20k]
  ------------------
 1118|    800|            v = value;
 1119|    800|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1119:17): [True: 0, False: 800]
  |  Branch (1119:30): [True: 0, False: 800]
  ------------------
 1120|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1121|      0|                return -1;
 1122|    800|            } else {
 1123|    800|                rc = ssh_options_set_algo(session,
 1124|    800|                                          SSH_CRYPT_S_C,
 1125|    800|                                          v,
 1126|    800|                                          &wanted_methods[SSH_CRYPT_S_C]);
 1127|    800|                if (rc < 0)
  ------------------
  |  Branch (1127:21): [True: 0, False: 800]
  ------------------
 1128|      0|                    return -1;
 1129|    800|            }
 1130|    800|            break;
 1131|    800|        case SSH_OPTIONS_KEY_EXCHANGE:
  ------------------
  |  Branch (1131:9): [True: 0, False: 8.00k]
  ------------------
 1132|      0|            v = value;
 1133|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1133:17): [True: 0, False: 0]
  |  Branch (1133:30): [True: 0, False: 0]
  ------------------
 1134|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1135|      0|                return -1;
 1136|      0|            } else {
 1137|      0|                rc = ssh_options_set_algo(session,
 1138|      0|                                          SSH_KEX,
 1139|      0|                                          v,
 1140|      0|                                          &wanted_methods[SSH_KEX]);
 1141|      0|                if (rc < 0)
  ------------------
  |  Branch (1141:21): [True: 0, False: 0]
  ------------------
 1142|      0|                    return -1;
 1143|      0|            }
 1144|      0|            break;
 1145|      0|        case SSH_OPTIONS_HOSTKEYS:
  ------------------
  |  Branch (1145:9): [True: 0, False: 8.00k]
  ------------------
 1146|      0|            v = value;
 1147|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1147:17): [True: 0, False: 0]
  |  Branch (1147:30): [True: 0, False: 0]
  ------------------
 1148|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1149|      0|                return -1;
 1150|      0|            } else {
 1151|      0|                rc = ssh_options_set_algo(session,
 1152|      0|                                          SSH_HOSTKEYS,
 1153|      0|                                          v,
 1154|      0|                                          &wanted_methods[SSH_HOSTKEYS]);
 1155|      0|                if (rc < 0)
  ------------------
  |  Branch (1155:21): [True: 0, False: 0]
  ------------------
 1156|      0|                    return -1;
 1157|      0|            }
 1158|      0|            break;
 1159|      0|        case SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES:
  ------------------
  |  Branch (1159:9): [True: 0, False: 8.00k]
  ------------------
 1160|      0|            v = value;
 1161|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1161:17): [True: 0, False: 0]
  |  Branch (1161:30): [True: 0, False: 0]
  ------------------
 1162|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1163|      0|                return -1;
 1164|      0|            } else {
 1165|      0|                rc = ssh_options_set_algo(session,
 1166|      0|                                          SSH_HOSTKEYS,
 1167|      0|                                          v,
 1168|      0|                                          &session->opts.pubkey_accepted_types);
 1169|      0|                if (rc < 0)
  ------------------
  |  Branch (1169:21): [True: 0, False: 0]
  ------------------
 1170|      0|                    return -1;
 1171|      0|            }
 1172|      0|            break;
 1173|    800|        case SSH_OPTIONS_HMAC_C_S:
  ------------------
  |  Branch (1173:9): [True: 800, False: 7.20k]
  ------------------
 1174|    800|            v = value;
 1175|    800|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1175:17): [True: 0, False: 800]
  |  Branch (1175:30): [True: 0, False: 800]
  ------------------
 1176|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1177|      0|                return -1;
 1178|    800|            } else {
 1179|    800|                rc = ssh_options_set_algo(session,
 1180|    800|                                          SSH_MAC_C_S,
 1181|    800|                                          v,
 1182|    800|                                          &wanted_methods[SSH_MAC_C_S]);
 1183|    800|                if (rc < 0)
  ------------------
  |  Branch (1183:21): [True: 0, False: 800]
  ------------------
 1184|      0|                    return -1;
 1185|    800|            }
 1186|    800|            break;
 1187|    800|         case SSH_OPTIONS_HMAC_S_C:
  ------------------
  |  Branch (1187:10): [True: 800, False: 7.20k]
  ------------------
 1188|    800|            v = value;
 1189|    800|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1189:17): [True: 0, False: 800]
  |  Branch (1189:30): [True: 0, False: 800]
  ------------------
 1190|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1191|      0|                return -1;
 1192|    800|            } else {
 1193|    800|                rc = ssh_options_set_algo(session,
 1194|    800|                                          SSH_MAC_S_C,
 1195|    800|                                          v,
 1196|    800|                                          &wanted_methods[SSH_MAC_S_C]);
 1197|    800|                if (rc < 0)
  ------------------
  |  Branch (1197:21): [True: 0, False: 800]
  ------------------
 1198|      0|                    return -1;
 1199|    800|            }
 1200|    800|            break;
 1201|    800|        case SSH_OPTIONS_COMPRESSION_C_S:
  ------------------
  |  Branch (1201:9): [True: 0, False: 8.00k]
  ------------------
 1202|      0|            v = value;
 1203|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1203:17): [True: 0, False: 0]
  |  Branch (1203:30): [True: 0, False: 0]
  ------------------
 1204|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1205|      0|                return -1;
 1206|      0|            } else {
 1207|      0|                const char *tmp = v;
 1208|      0|                if (strcasecmp(value, "yes") == 0){
  ------------------
  |  Branch (1208:21): [True: 0, False: 0]
  ------------------
 1209|      0|                    tmp = "zlib@openssh.com,none";
 1210|      0|                } else if (strcasecmp(value, "no") == 0){
  ------------------
  |  Branch (1210:28): [True: 0, False: 0]
  ------------------
 1211|      0|                    tmp = "none,zlib@openssh.com";
 1212|      0|                }
 1213|      0|                rc = ssh_options_set_algo(session,
 1214|      0|                                          SSH_COMP_C_S,
 1215|      0|                                          tmp,
 1216|      0|                                          &wanted_methods[SSH_COMP_C_S]);
 1217|      0|                if (rc < 0)
  ------------------
  |  Branch (1217:21): [True: 0, False: 0]
  ------------------
 1218|      0|                    return -1;
 1219|      0|            }
 1220|      0|            break;
 1221|      0|        case SSH_OPTIONS_COMPRESSION_S_C:
  ------------------
  |  Branch (1221:9): [True: 0, False: 8.00k]
  ------------------
 1222|      0|            v = value;
 1223|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1223:17): [True: 0, False: 0]
  |  Branch (1223:30): [True: 0, False: 0]
  ------------------
 1224|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1225|      0|                return -1;
 1226|      0|            } else {
 1227|      0|                const char *tmp = v;
 1228|      0|                if (strcasecmp(value, "yes") == 0){
  ------------------
  |  Branch (1228:21): [True: 0, False: 0]
  ------------------
 1229|      0|                    tmp = "zlib@openssh.com,none";
 1230|      0|                } else if (strcasecmp(value, "no") == 0){
  ------------------
  |  Branch (1230:28): [True: 0, False: 0]
  ------------------
 1231|      0|                    tmp = "none,zlib@openssh.com";
 1232|      0|                }
 1233|       |
 1234|      0|                rc = ssh_options_set_algo(session,
 1235|      0|                                          SSH_COMP_S_C,
 1236|      0|                                          tmp,
 1237|      0|                                          &wanted_methods[SSH_COMP_S_C]);
 1238|      0|                if (rc < 0)
  ------------------
  |  Branch (1238:21): [True: 0, False: 0]
  ------------------
 1239|      0|                    return -1;
 1240|      0|            }
 1241|      0|            break;
 1242|      0|        case SSH_OPTIONS_COMPRESSION:
  ------------------
  |  Branch (1242:9): [True: 0, False: 8.00k]
  ------------------
 1243|      0|            v = value;
 1244|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1244:17): [True: 0, False: 0]
  |  Branch (1244:30): [True: 0, False: 0]
  ------------------
 1245|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1246|      0|                return -1;
 1247|      0|            }
 1248|      0|            if(ssh_options_set(session,SSH_OPTIONS_COMPRESSION_C_S, v) < 0)
  ------------------
  |  Branch (1248:16): [True: 0, False: 0]
  ------------------
 1249|      0|                return -1;
 1250|      0|            if(ssh_options_set(session,SSH_OPTIONS_COMPRESSION_S_C, v) < 0)
  ------------------
  |  Branch (1250:16): [True: 0, False: 0]
  ------------------
 1251|      0|                return -1;
 1252|      0|            break;
 1253|      0|        case SSH_OPTIONS_COMPRESSION_LEVEL:
  ------------------
  |  Branch (1253:9): [True: 0, False: 8.00k]
  ------------------
 1254|      0|            if (value == NULL) {
  ------------------
  |  Branch (1254:17): [True: 0, False: 0]
  ------------------
 1255|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1256|      0|                return -1;
 1257|      0|            } else {
 1258|      0|                int *x = (int *)value;
 1259|      0|                if (*x < 1 || *x > 9) {
  ------------------
  |  Branch (1259:21): [True: 0, False: 0]
  |  Branch (1259:31): [True: 0, False: 0]
  ------------------
 1260|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1261|      0|                    return -1;
 1262|      0|                }
 1263|      0|                session->opts.compressionlevel = *x & 0xff;
 1264|      0|            }
 1265|      0|            break;
 1266|      0|        case SSH_OPTIONS_STRICTHOSTKEYCHECK:
  ------------------
  |  Branch (1266:9): [True: 0, False: 8.00k]
  ------------------
 1267|      0|            if (value == NULL) {
  ------------------
  |  Branch (1267:17): [True: 0, False: 0]
  ------------------
 1268|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1269|      0|                return -1;
 1270|      0|            } else {
 1271|      0|                int *x = (int *) value;
 1272|      0|                int mode = *x;
 1273|       |
 1274|      0|                switch (mode) {
 1275|      0|                case SSH_STRICT_HOSTKEY_OFF:
  ------------------
  |  Branch (1275:17): [True: 0, False: 0]
  ------------------
 1276|      0|                case SSH_STRICT_HOSTKEY_YES:
  ------------------
  |  Branch (1276:17): [True: 0, False: 0]
  ------------------
 1277|      0|                case SSH_STRICT_HOSTKEY_ASK:
  ------------------
  |  Branch (1277:17): [True: 0, False: 0]
  ------------------
 1278|      0|                case SSH_STRICT_HOSTKEY_ACCEPT_NEW:
  ------------------
  |  Branch (1278:17): [True: 0, False: 0]
  ------------------
 1279|      0|                    session->opts.StrictHostKeyChecking = mode;
 1280|      0|                    break;
 1281|      0|                default:
  ------------------
  |  Branch (1281:17): [True: 0, False: 0]
  ------------------
 1282|       |                    /* Preserve the legacy low-byte "non-zero means yes"
 1283|       |                     * normalization.
 1284|       |                     */
 1285|      0|                    session->opts.StrictHostKeyChecking =
 1286|      0|                        (mode & 0xff) > 0 ? SSH_STRICT_HOSTKEY_YES
  ------------------
  |  Branch (1286:25): [True: 0, False: 0]
  ------------------
 1287|      0|                                          : SSH_STRICT_HOSTKEY_OFF;
 1288|      0|                    break;
 1289|      0|                }
 1290|      0|            }
 1291|      0|            break;
 1292|      0|        case SSH_OPTIONS_PROXYCOMMAND:
  ------------------
  |  Branch (1292:9): [True: 0, False: 8.00k]
  ------------------
 1293|      0|            v = value;
 1294|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1294:17): [True: 0, False: 0]
  |  Branch (1294:30): [True: 0, False: 0]
  ------------------
 1295|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1296|      0|                return -1;
 1297|      0|            } else {
 1298|      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]
  |  |  ------------------
  ------------------
 1299|       |                /* Setting the command to 'none' disables this option. */
 1300|      0|                rc = strcasecmp(v, "none");
 1301|      0|                if (rc != 0) {
  ------------------
  |  Branch (1301:21): [True: 0, False: 0]
  ------------------
 1302|      0|                    q = strdup(v);
 1303|      0|                    if (q == NULL) {
  ------------------
  |  Branch (1303:25): [True: 0, False: 0]
  ------------------
 1304|      0|                        return -1;
 1305|      0|                    }
 1306|      0|                    session->opts.ProxyCommand = q;
 1307|      0|                    session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_PROXYCOMMAND;
  ------------------
  |  |  117|      0|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
 1308|      0|                }
 1309|      0|            }
 1310|      0|            break;
 1311|      0|        case SSH_OPTIONS_PROXYJUMP:
  ------------------
  |  Branch (1311:9): [True: 0, False: 8.00k]
  ------------------
 1312|      0|            v = value;
 1313|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1313:17): [True: 0, False: 0]
  |  Branch (1313:30): [True: 0, False: 0]
  ------------------
 1314|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1315|      0|                return -1;
 1316|      0|            } else {
 1317|      0|                rc = ssh_config_parse_proxy_jump(session, v, true);
 1318|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1318:21): [True: 0, False: 0]
  ------------------
 1319|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1320|      0|                }
 1321|      0|            }
 1322|      0|            break;
 1323|      0|        case SSH_OPTIONS_PROXYJUMP_CB_LIST_APPEND:
  ------------------
  |  Branch (1323:9): [True: 0, False: 8.00k]
  ------------------
 1324|      0|            j = (struct ssh_jump_callbacks_struct *)value;
 1325|      0|            if (j == NULL) {
  ------------------
  |  Branch (1325:17): [True: 0, False: 0]
  ------------------
 1326|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1327|      0|                return -1;
 1328|      0|            } else {
 1329|      0|                rc = ssh_list_prepend(session->opts.proxy_jumps_user_cb, j);
 1330|      0|                if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1330:21): [True: 0, False: 0]
  ------------------
 1331|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1332|      0|                    return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1333|      0|                }
 1334|      0|            }
 1335|      0|            break;
 1336|      0|        case SSH_OPTIONS_GSSAPI_SERVER_IDENTITY:
  ------------------
  |  Branch (1336:9): [True: 0, False: 8.00k]
  ------------------
 1337|      0|            v = value;
 1338|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1338:17): [True: 0, False: 0]
  |  Branch (1338:30): [True: 0, False: 0]
  ------------------
 1339|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1340|      0|                return -1;
 1341|      0|            } else {
 1342|      0|                SAFE_FREE(session->opts.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]
  |  |  ------------------
  ------------------
 1343|      0|                session->opts.gss_server_identity = strdup(v);
 1344|      0|                if (session->opts.gss_server_identity == NULL) {
  ------------------
  |  Branch (1344:21): [True: 0, False: 0]
  ------------------
 1345|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1346|      0|                    return -1;
 1347|      0|                }
 1348|      0|            }
 1349|      0|            break;
 1350|      0|        case SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY:
  ------------------
  |  Branch (1350:9): [True: 0, False: 8.00k]
  ------------------
 1351|      0|            v = value;
 1352|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1352:17): [True: 0, False: 0]
  |  Branch (1352:30): [True: 0, False: 0]
  ------------------
 1353|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1354|      0|                return -1;
 1355|      0|            } else {
 1356|      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]
  |  |  ------------------
  ------------------
 1357|      0|                session->opts.gss_client_identity = strdup(v);
 1358|      0|                if (session->opts.gss_client_identity == NULL) {
  ------------------
  |  Branch (1358:21): [True: 0, False: 0]
  ------------------
 1359|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1360|      0|                    return -1;
 1361|      0|                }
 1362|      0|            }
 1363|      0|            break;
 1364|      0|        case SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS:
  ------------------
  |  Branch (1364:9): [True: 0, False: 8.00k]
  ------------------
 1365|      0|            if (value == NULL) {
  ------------------
  |  Branch (1365:17): [True: 0, False: 0]
  ------------------
 1366|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1367|      0|                return -1;
 1368|      0|            } else {
 1369|      0|                int x = *(int *)value;
 1370|       |
 1371|      0|                session->opts.gss_delegate_creds = (x & 0xff);
 1372|      0|            }
 1373|      0|            break;
 1374|       |#ifdef WITH_GSSAPI
 1375|       |        case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE:
 1376|       |            if (value == NULL) {
 1377|       |                ssh_set_error_invalid(session);
 1378|       |                return -1;
 1379|       |            } else {
 1380|       |                bool *x = (bool *)value;
 1381|       |                session->opts.gssapi_key_exchange = *x;
 1382|       |            }
 1383|       |            break;
 1384|       |        case SSH_OPTIONS_GSSAPI_KEY_EXCHANGE_ALGS:
 1385|       |            v = value;
 1386|       |            if (v == NULL || v[0] == '\0') {
 1387|       |                ssh_set_error_invalid(session);
 1388|       |                return -1;
 1389|       |            } else {
 1390|       |                /* Check if algorithms are supported */
 1391|       |                char *ret =
 1392|       |                    ssh_find_all_matching(GSSAPI_KEY_EXCHANGE_SUPPORTED, v);
 1393|       |                if (ret == NULL) {
 1394|       |                    ssh_set_error(session,
 1395|       |                                  SSH_FATAL,
 1396|       |                                  "GSSAPI key exchange algorithms not "
 1397|       |                                  "supported or invalid");
 1398|       |                    return -1;
 1399|       |                }
 1400|       |                SAFE_FREE(session->opts.gssapi_key_exchange_algs);
 1401|       |                session->opts.gssapi_key_exchange_algs = ret;
 1402|       |            }
 1403|       |            break;
 1404|       |#endif
 1405|      0|        case SSH_OPTIONS_PASSWORD_AUTH:
  ------------------
  |  Branch (1405:9): [True: 0, False: 8.00k]
  ------------------
 1406|      0|        case SSH_OPTIONS_PUBKEY_AUTH:
  ------------------
  |  Branch (1406:9): [True: 0, False: 8.00k]
  ------------------
 1407|      0|        case SSH_OPTIONS_KBDINT_AUTH:
  ------------------
  |  Branch (1407:9): [True: 0, False: 8.00k]
  ------------------
 1408|      0|        case SSH_OPTIONS_GSSAPI_AUTH:
  ------------------
  |  Branch (1408:9): [True: 0, False: 8.00k]
  ------------------
 1409|      0|            if (value == NULL) {
  ------------------
  |  Branch (1409:17): [True: 0, False: 0]
  ------------------
 1410|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1411|      0|                return -1;
 1412|      0|            } else {
 1413|      0|                int x = *(int *)value;
 1414|      0|                u = type == SSH_OPTIONS_PASSWORD_AUTH ?
  ------------------
  |  Branch (1414:21): [True: 0, False: 0]
  ------------------
 1415|      0|                    SSH_OPT_FLAG_PASSWORD_AUTH:
  ------------------
  |  |  109|      0|#define SSH_OPT_FLAG_PASSWORD_AUTH 0x1
  ------------------
 1416|      0|                    type == SSH_OPTIONS_PUBKEY_AUTH ?
  ------------------
  |  Branch (1416:21): [True: 0, False: 0]
  ------------------
 1417|      0|                        SSH_OPT_FLAG_PUBKEY_AUTH:
  ------------------
  |  |  110|      0|#define SSH_OPT_FLAG_PUBKEY_AUTH 0x2
  ------------------
 1418|      0|                        type == SSH_OPTIONS_KBDINT_AUTH ?
  ------------------
  |  Branch (1418:25): [True: 0, False: 0]
  ------------------
 1419|      0|                            SSH_OPT_FLAG_KBDINT_AUTH:
  ------------------
  |  |  111|      0|#define SSH_OPT_FLAG_KBDINT_AUTH 0x4
  ------------------
 1420|      0|                            SSH_OPT_FLAG_GSSAPI_AUTH;
  ------------------
  |  |  112|      0|#define SSH_OPT_FLAG_GSSAPI_AUTH 0x8
  ------------------
 1421|      0|                if (x != 0) {
  ------------------
  |  Branch (1421:21): [True: 0, False: 0]
  ------------------
 1422|      0|                    session->opts.flags |= u;
 1423|      0|                } else {
 1424|      0|                    session->opts.flags &= ~u;
 1425|      0|                }
 1426|      0|                if (type == SSH_OPTIONS_PUBKEY_AUTH) {
  ------------------
  |  Branch (1426:21): [True: 0, False: 0]
  ------------------
 1427|       |                    /*
 1428|       |                     * Keep the legacy enabled/disabled auth flag semantics in
 1429|       |                     * sync above while also storing the selected
 1430|       |                     * PubkeyAuthentication mode here.
 1431|       |                     */
 1432|      0|                    switch (x) {
 1433|      0|                    case SSH_PUBKEY_AUTH_NO:
  ------------------
  |  Branch (1433:21): [True: 0, False: 0]
  ------------------
 1434|      0|                    case SSH_PUBKEY_AUTH_ALL:
  ------------------
  |  Branch (1434:21): [True: 0, False: 0]
  ------------------
 1435|      0|                    case SSH_PUBKEY_AUTH_UNBOUND:
  ------------------
  |  Branch (1435:21): [True: 0, False: 0]
  ------------------
 1436|      0|                    case SSH_PUBKEY_AUTH_HOST_BOUND:
  ------------------
  |  Branch (1436:21): [True: 0, False: 0]
  ------------------
 1437|      0|                        session->opts.pubkey_auth = x;
 1438|      0|                        break;
 1439|      0|                    default:
  ------------------
  |  Branch (1439:21): [True: 0, False: 0]
  ------------------
 1440|       |                        /* Preserve the legacy non-zero "yes" normalization
 1441|       |                         * here so callers passing -1 still land on
 1442|       |                         * SSH_PUBKEY_AUTH_ALL.
 1443|       |                         */
 1444|      0|                        session->opts.pubkey_auth = SSH_PUBKEY_AUTH_ALL;
 1445|      0|                        break;
 1446|      0|                    }
 1447|      0|                }
 1448|      0|            }
 1449|      0|            break;
 1450|      0|        case SSH_OPTIONS_NODELAY:
  ------------------
  |  Branch (1450:9): [True: 0, False: 8.00k]
  ------------------
 1451|      0|            if (value == NULL) {
  ------------------
  |  Branch (1451:17): [True: 0, False: 0]
  ------------------
 1452|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1453|      0|                return -1;
 1454|      0|            } else {
 1455|      0|                int *x = (int *) value;
 1456|      0|                session->opts.nodelay = (*x & 0xff) > 0 ? 1 : 0;
  ------------------
  |  Branch (1456:41): [True: 0, False: 0]
  ------------------
 1457|      0|            }
 1458|      0|            break;
 1459|    800|        case SSH_OPTIONS_PROCESS_CONFIG:
  ------------------
  |  Branch (1459:9): [True: 800, False: 7.20k]
  ------------------
 1460|    800|            if (value == NULL) {
  ------------------
  |  Branch (1460:17): [True: 0, False: 800]
  ------------------
 1461|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1462|      0|                return -1;
 1463|    800|            } else {
 1464|    800|                bool *x = (bool *)value;
 1465|    800|                session->opts.config_processed = !(*x);
 1466|    800|            }
 1467|    800|            break;
 1468|    800|        case SSH_OPTIONS_REKEY_DATA:
  ------------------
  |  Branch (1468:9): [True: 0, False: 8.00k]
  ------------------
 1469|      0|            if (value == NULL) {
  ------------------
  |  Branch (1469:17): [True: 0, False: 0]
  ------------------
 1470|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1471|      0|                return -1;
 1472|      0|            } else {
 1473|      0|                uint64_t *x = (uint64_t *)value;
 1474|      0|                session->opts.rekey_data = *x;
 1475|      0|            }
 1476|      0|            break;
 1477|      0|        case SSH_OPTIONS_REKEY_TIME:
  ------------------
  |  Branch (1477:9): [True: 0, False: 8.00k]
  ------------------
 1478|      0|            if (value == NULL) {
  ------------------
  |  Branch (1478:17): [True: 0, False: 0]
  ------------------
 1479|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1480|      0|                return -1;
 1481|      0|            } else {
 1482|      0|                uint32_t *x = (uint32_t *)value;
 1483|      0|                if ((*x * 1000) < *x) {
  ------------------
  |  Branch (1483:21): [True: 0, False: 0]
  ------------------
 1484|      0|                    ssh_set_error(session, SSH_REQUEST_DENIED,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1485|      0|                                  "The provided value (%" PRIu32 ") for rekey"
 1486|      0|                                  " time is too large", *x);
 1487|      0|                    return -1;
 1488|      0|                }
 1489|      0|                session->opts.rekey_time = (*x) * 1000;
 1490|      0|            }
 1491|      0|            break;
 1492|      0|        case SSH_OPTIONS_RSA_MIN_SIZE:
  ------------------
  |  Branch (1492:9): [True: 0, False: 8.00k]
  ------------------
 1493|      0|            if (value == NULL) {
  ------------------
  |  Branch (1493:17): [True: 0, False: 0]
  ------------------
 1494|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1495|      0|                return -1;
 1496|      0|            } else {
 1497|      0|                int *x = (int *)value;
 1498|       |
 1499|      0|                if (*x < 0) {
  ------------------
  |  Branch (1499:21): [True: 0, False: 0]
  ------------------
 1500|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1501|      0|                    return -1;
 1502|      0|                }
 1503|       |
 1504|       |                /* (*x == 0) is allowed as it is used to revert to default */
 1505|       |
 1506|      0|                if (*x > 0 && *x < RSA_MIN_KEY_SIZE) {
  ------------------
  |  |   49|      0|#define RSA_MIN_KEY_SIZE      1024
  ------------------
  |  Branch (1506:21): [True: 0, False: 0]
  |  Branch (1506:31): [True: 0, False: 0]
  ------------------
 1507|      0|                    ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1508|      0|                                  SSH_REQUEST_DENIED,
 1509|      0|                                  "The provided value (%d) for minimal RSA key "
 1510|      0|                                  "size is too small. Use at least %d bits.",
 1511|      0|                                  *x,
 1512|      0|                                  RSA_MIN_KEY_SIZE);
 1513|      0|                    return -1;
 1514|      0|                }
 1515|      0|                session->opts.rsa_min_size = *x;
 1516|      0|            }
 1517|      0|            break;
 1518|      0|        case SSH_OPTIONS_IDENTITY_AGENT:
  ------------------
  |  Branch (1518:9): [True: 0, False: 8.00k]
  ------------------
 1519|      0|            v = value;
 1520|      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]
  |  |  ------------------
  ------------------
 1521|      0|            if (v == NULL) {
  ------------------
  |  Branch (1521:17): [True: 0, False: 0]
  ------------------
 1522|       |                /* The default value will be set by the ssh_options_apply() */
 1523|      0|            } else if (v[0] == '\0') {
  ------------------
  |  Branch (1523:24): [True: 0, False: 0]
  ------------------
 1524|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1525|      0|                return -1;
 1526|      0|            } else {
 1527|      0|                session->opts.agent_socket = ssh_path_expand_tilde(v);
 1528|      0|                if (session->opts.agent_socket == NULL) {
  ------------------
  |  Branch (1528:21): [True: 0, False: 0]
  ------------------
 1529|      0|                    ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1530|      0|                    return -1;
 1531|      0|                }
 1532|      0|            }
 1533|      0|            break;
 1534|      0|        case SSH_OPTIONS_IDENTITIES_ONLY:
  ------------------
  |  Branch (1534:9): [True: 0, False: 8.00k]
  ------------------
 1535|      0|            if (value == NULL) {
  ------------------
  |  Branch (1535:17): [True: 0, False: 0]
  ------------------
 1536|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1537|      0|                return -1;
 1538|      0|            } else {
 1539|      0|                bool *x = (bool *)value;
 1540|      0|                session->opts.identities_only = *x;
 1541|      0|            }
 1542|      0|            break;
 1543|      0|        case SSH_OPTIONS_CONTROL_MASTER:
  ------------------
  |  Branch (1543:9): [True: 0, False: 8.00k]
  ------------------
 1544|      0|            if (value == NULL) {
  ------------------
  |  Branch (1544:17): [True: 0, False: 0]
  ------------------
 1545|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1546|      0|                return -1;
 1547|      0|            } else {
 1548|      0|                int *x = (int *) value;
 1549|      0|                if (*x < SSH_CONTROL_MASTER_NO || *x > SSH_CONTROL_MASTER_AUTOASK) {
  ------------------
  |  Branch (1549:21): [True: 0, False: 0]
  |  Branch (1549:51): [True: 0, False: 0]
  ------------------
 1550|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1551|      0|                    return -1;
 1552|      0|                }
 1553|      0|                session->opts.control_master = *x;
 1554|      0|            }
 1555|      0|            break;
 1556|      0|        case SSH_OPTIONS_CONTROL_PATH:
  ------------------
  |  Branch (1556:9): [True: 0, False: 8.00k]
  ------------------
 1557|      0|            v = value;
 1558|      0|            if (v == NULL || v[0] == '\0') {
  ------------------
  |  Branch (1558:17): [True: 0, False: 0]
  |  Branch (1558:30): [True: 0, False: 0]
  ------------------
 1559|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1560|      0|                return -1;
 1561|      0|            } else {
 1562|      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]
  |  |  ------------------
  ------------------
 1563|      0|                rc = strcasecmp(v, "none");
 1564|      0|                if (rc != 0) {
  ------------------
  |  Branch (1564:21): [True: 0, False: 0]
  ------------------
 1565|      0|                    session->opts.control_path = ssh_path_expand_tilde(v);
 1566|      0|                    if (session->opts.control_path == NULL) {
  ------------------
  |  Branch (1566:25): [True: 0, False: 0]
  ------------------
 1567|      0|                        ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1568|      0|                        return -1;
 1569|      0|                    }
 1570|      0|                    session->opts.exp_flags &= ~SSH_OPT_EXP_FLAG_CONTROL_PATH;
  ------------------
  |  |  119|      0|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
 1571|      0|                }
 1572|      0|            }
 1573|      0|            break;
 1574|      0|        case SSH_OPTIONS_PKI_CONTEXT:
  ------------------
  |  Branch (1574:9): [True: 0, False: 8.00k]
  ------------------
 1575|      0|            if (value == NULL) {
  ------------------
  |  Branch (1575:17): [True: 0, False: 0]
  ------------------
 1576|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1577|      0|                return -1;
 1578|      0|            }
 1579|       |
 1580|      0|            SSH_PKI_CTX_FREE(session->pki_context);
  ------------------
  |  | 1027|      0|    do {                         \
  |  | 1028|      0|        if ((x) != NULL) {       \
  |  |  ------------------
  |  |  |  Branch (1028:13): [True: 0, False: 0]
  |  |  ------------------
  |  | 1029|      0|            ssh_pki_ctx_free(x); \
  |  | 1030|      0|            x = NULL;            \
  |  | 1031|      0|        }                        \
  |  | 1032|      0|    } while (0)
  |  |  ------------------
  |  |  |  Branch (1032:14): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1581|       |
 1582|      0|            session->pki_context = ssh_pki_ctx_dup((const ssh_pki_ctx)value);
 1583|      0|            if (session->pki_context == NULL) {
  ------------------
  |  Branch (1583:17): [True: 0, False: 0]
  ------------------
 1584|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1585|      0|                return -1;
 1586|      0|            }
 1587|      0|            break;
 1588|      0|        case SSH_OPTIONS_ADDRESS_FAMILY:
  ------------------
  |  Branch (1588:9): [True: 0, False: 8.00k]
  ------------------
 1589|      0|            if (value == NULL) {
  ------------------
  |  Branch (1589:17): [True: 0, False: 0]
  ------------------
 1590|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1591|      0|                return -1;
 1592|      0|            } else {
 1593|      0|                int *x = (int *)value;
 1594|      0|                if (*x < SSH_ADDRESS_FAMILY_ANY ||
  ------------------
  |  Branch (1594:21): [True: 0, False: 0]
  ------------------
 1595|      0|                    *x > SSH_ADDRESS_FAMILY_INET6) {
  ------------------
  |  Branch (1595:21): [True: 0, False: 0]
  ------------------
 1596|      0|                    ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1597|      0|                    return -1;
 1598|      0|                }
 1599|      0|                session->opts.address_family = *x;
 1600|      0|            }
 1601|      0|            break;
 1602|      0|        case SSH_OPTIONS_BATCH_MODE:
  ------------------
  |  Branch (1602:9): [True: 0, False: 8.00k]
  ------------------
 1603|      0|            if (value == NULL) {
  ------------------
  |  Branch (1603:17): [True: 0, False: 0]
  ------------------
 1604|      0|                ssh_set_error_invalid(session);
  ------------------
  |  |  322|      0|    _ssh_set_error_invalid(error, __func__)
  ------------------
 1605|      0|                return -1;
 1606|      0|            } else {
 1607|      0|                bool *x = (bool *)value;
 1608|      0|                session->opts.batch_mode = *x;
 1609|      0|            }
 1610|      0|            break;
 1611|      0|        default:
  ------------------
  |  Branch (1611:9): [True: 0, False: 8.00k]
  ------------------
 1612|      0|            ssh_set_error(session, SSH_REQUEST_DENIED, "Unknown ssh option %d", type);
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1613|      0|            return -1;
 1614|      0|            break;
 1615|  8.00k|    }
 1616|       |
 1617|  8.00k|    return 0;
 1618|  8.00k|}
ssh_options_apply:
 2286|    800|{
 2287|    800|    char *tmp = NULL;
 2288|    800|    int rc;
 2289|       |
 2290|    800|    if (session->opts.host != NULL) {
  ------------------
  |  Branch (2290:9): [True: 800, False: 0]
  ------------------
 2291|    800|        char *normalized_host = NULL;
 2292|    800|        rc = ssh_normalize_loose_ip(session->opts.host, &normalized_host);
 2293|    800|        if (rc == -1) {
  ------------------
  |  Branch (2293:13): [True: 0, False: 800]
  ------------------
 2294|       |            /* Error (e.g. NULL input or OOM) — leave host as it is */
 2295|    800|        } else if (rc == 0) {
  ------------------
  |  Branch (2295:20): [True: 0, False: 800]
  ------------------
 2296|       |            /* Was a loose IP — use the normalized dotted-quad form */
 2297|      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]
  |  |  ------------------
  ------------------
 2298|      0|            session->opts.host = normalized_host;
 2299|    800|        } else {
 2300|       |            /* rc == 1: not a loose IP — lowercase if it's not a strict IP */
 2301|    800|            bool is_ip = ssh_is_ipaddr(session->opts.host);
 2302|    800|            if (!is_ip) {
  ------------------
  |  Branch (2302:17): [True: 0, False: 800]
  ------------------
 2303|      0|                char *lower = ssh_lowercase(session->opts.host);
 2304|      0|                if (lower != NULL) {
  ------------------
  |  Branch (2304:21): [True: 0, False: 0]
  ------------------
 2305|      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]
  |  |  ------------------
  ------------------
 2306|      0|                    session->opts.host = lower;
 2307|      0|                }
 2308|      0|            }
 2309|    800|        }
 2310|    800|    }
 2311|       |
 2312|    800|    if (session->opts.sshdir == NULL) {
  ------------------
  |  Branch (2312:9): [True: 800, False: 0]
  ------------------
 2313|    800|        rc = ssh_options_set(session, SSH_OPTIONS_SSH_DIR, NULL);
 2314|    800|        if (rc < 0) {
  ------------------
  |  Branch (2314:13): [True: 0, False: 800]
  ------------------
 2315|      0|            return -1;
 2316|      0|        }
 2317|    800|    }
 2318|       |
 2319|    800|    if (session->opts.username == NULL) {
  ------------------
  |  Branch (2319:9): [True: 0, False: 800]
  ------------------
 2320|      0|        rc = ssh_options_set(session, SSH_OPTIONS_USER, NULL);
 2321|      0|        if (rc < 0) {
  ------------------
  |  Branch (2321:13): [True: 0, False: 0]
  ------------------
 2322|      0|            return -1;
 2323|      0|        }
 2324|      0|    }
 2325|       |
 2326|    800|    if (session->opts.config_hostname != NULL) {
  ------------------
  |  Branch (2326:9): [True: 0, False: 800]
  ------------------
 2327|      0|        char *saved_host = NULL;
 2328|       |
 2329|      0|        tmp = ssh_path_expand_hostname(session, session->opts.config_hostname);
 2330|      0|        if (tmp == NULL) {
  ------------------
  |  Branch (2330:13): [True: 0, False: 0]
  ------------------
 2331|      0|            return -1;
 2332|      0|        }
 2333|      0|        if (session->opts.host != NULL) {
  ------------------
  |  Branch (2333:13): [True: 0, False: 0]
  ------------------
 2334|      0|            saved_host = strdup(session->opts.host);
 2335|      0|            if (saved_host == NULL) {
  ------------------
  |  Branch (2335:17): [True: 0, False: 0]
  ------------------
 2336|      0|                free(tmp);
 2337|      0|                ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2338|      0|                return -1;
 2339|      0|            }
 2340|      0|        }
 2341|      0|        session->opts.config_hostname_only = true;
 2342|      0|        rc = ssh_options_set(session, SSH_OPTIONS_HOST, tmp);
 2343|      0|        session->opts.config_hostname_only = false;
 2344|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2344:13): [True: 0, False: 0]
  ------------------
 2345|       |            /* If HostName expansion leaves a literal '%', keep the current
 2346|       |             * host instead of treating the deferred HostName as fatal.
 2347|       |             */
 2348|      0|            if (strchr(tmp, '%') == NULL) {
  ------------------
  |  Branch (2348:17): [True: 0, False: 0]
  ------------------
 2349|      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]
  |  |  ------------------
  ------------------
 2350|      0|                free(tmp);
 2351|      0|                return -1;
 2352|      0|            }
 2353|      0|            SSH_LOG(SSH_LOG_WARN,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2354|      0|                    "HostName %s contains unknown expansion tokens and could "
 2355|      0|                    "not be applied; falling back to current host",
 2356|      0|                    tmp);
 2357|      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]
  |  |  ------------------
  ------------------
 2358|      0|            session->opts.host = saved_host;
 2359|      0|            saved_host = NULL;
 2360|      0|        }
 2361|      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]
  |  |  ------------------
  ------------------
 2362|      0|        free(tmp);
 2363|      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]
  |  |  ------------------
  ------------------
 2364|      0|    }
 2365|       |
 2366|    800|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_KNOWNHOSTS) == 0) {
  ------------------
  |  |  115|    800|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
  |  Branch (2366:9): [True: 800, False: 0]
  ------------------
 2367|    800|        if (session->opts.knownhosts == NULL) {
  ------------------
  |  Branch (2367:13): [True: 800, False: 0]
  ------------------
 2368|    800|            tmp = ssh_path_expand_escape(session, "%d/.ssh/known_hosts");
 2369|    800|        } else {
 2370|      0|            tmp = ssh_path_expand_escape(session, session->opts.knownhosts);
 2371|      0|        }
 2372|    800|        if (tmp == NULL) {
  ------------------
  |  Branch (2372:13): [True: 0, False: 800]
  ------------------
 2373|      0|            return -1;
 2374|      0|        }
 2375|    800|        free(session->opts.knownhosts);
 2376|    800|        session->opts.knownhosts = tmp;
 2377|    800|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_KNOWNHOSTS;
  ------------------
  |  |  115|    800|#define SSH_OPT_EXP_FLAG_KNOWNHOSTS 0x1
  ------------------
 2378|    800|    }
 2379|       |
 2380|    800|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS) == 0) {
  ------------------
  |  |  116|    800|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
  |  Branch (2380:9): [True: 800, False: 0]
  ------------------
 2381|    800|        if (session->opts.global_knownhosts == NULL) {
  ------------------
  |  Branch (2381:13): [True: 800, False: 0]
  ------------------
 2382|    800|            tmp = strdup(GLOBAL_CONF_DIR "/ssh_known_hosts");
  ------------------
  |  |   13|    800|#define GLOBAL_CONF_DIR "/etc/ssh"
  ------------------
 2383|    800|        } else {
 2384|      0|            tmp = ssh_path_expand_escape(session,
 2385|      0|                                         session->opts.global_knownhosts);
 2386|      0|        }
 2387|    800|        if (tmp == NULL) {
  ------------------
  |  Branch (2387:13): [True: 0, False: 800]
  ------------------
 2388|      0|            return -1;
 2389|      0|        }
 2390|    800|        free(session->opts.global_knownhosts);
 2391|    800|        session->opts.global_knownhosts = tmp;
 2392|    800|        session->opts.exp_flags |= SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS;
  ------------------
  |  |  116|    800|#define SSH_OPT_EXP_FLAG_GLOBAL_KNOWNHOSTS 0x2
  ------------------
 2393|    800|    }
 2394|       |
 2395|       |
 2396|    800|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_PROXYCOMMAND) == 0) {
  ------------------
  |  |  117|    800|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
  |  Branch (2396:9): [True: 800, False: 0]
  ------------------
 2397|    800|        if (session->opts.ProxyCommand != NULL) {
  ------------------
  |  Branch (2397:13): [True: 0, False: 800]
  ------------------
 2398|      0|            char *p = NULL;
 2399|      0|            size_t plen = strlen(session->opts.ProxyCommand) +
 2400|      0|                          5 /* strlen("exec ") */;
 2401|       |
 2402|      0|            if (strncmp(session->opts.ProxyCommand, "exec ", 5) != 0) {
  ------------------
  |  Branch (2402:17): [True: 0, False: 0]
  ------------------
 2403|      0|                p = malloc(plen + 1 /* \0 */);
 2404|      0|                if (p == NULL) {
  ------------------
  |  Branch (2404:21): [True: 0, False: 0]
  ------------------
 2405|      0|                    return -1;
 2406|      0|                }
 2407|       |
 2408|      0|                rc = snprintf(p, plen + 1, "exec %s", session->opts.ProxyCommand);
 2409|      0|                if ((size_t)rc != plen) {
  ------------------
  |  Branch (2409:21): [True: 0, False: 0]
  ------------------
 2410|      0|                    free(p);
 2411|      0|                    return -1;
 2412|      0|                }
 2413|      0|                tmp = ssh_path_expand_escape(session, p);
 2414|      0|                free(p);
 2415|      0|            } else {
 2416|      0|                tmp = ssh_path_expand_escape(session,
 2417|      0|                                             session->opts.ProxyCommand);
 2418|      0|            }
 2419|       |
 2420|      0|            if (tmp == NULL) {
  ------------------
  |  Branch (2420:17): [True: 0, False: 0]
  ------------------
 2421|      0|                return -1;
 2422|      0|            }
 2423|      0|            free(session->opts.ProxyCommand);
 2424|      0|            session->opts.ProxyCommand = tmp;
 2425|      0|            session->opts.exp_flags |= SSH_OPT_EXP_FLAG_PROXYCOMMAND;
  ------------------
  |  |  117|      0|#define SSH_OPT_EXP_FLAG_PROXYCOMMAND 0x4
  ------------------
 2426|      0|        }
 2427|    800|    }
 2428|       |
 2429|    800|    if ((session->opts.exp_flags & SSH_OPT_EXP_FLAG_CONTROL_PATH) == 0) {
  ------------------
  |  |  119|    800|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
  |  Branch (2429:9): [True: 800, False: 0]
  ------------------
 2430|    800|        if (session->opts.control_path != NULL) {
  ------------------
  |  Branch (2430:13): [True: 0, False: 800]
  ------------------
 2431|      0|            tmp = ssh_path_expand_escape(session, session->opts.control_path);
 2432|      0|            if (tmp == NULL) {
  ------------------
  |  Branch (2432:17): [True: 0, False: 0]
  ------------------
 2433|      0|                return -1;
 2434|      0|            }
 2435|      0|            free(session->opts.control_path);
 2436|      0|            session->opts.control_path = tmp;
 2437|      0|            session->opts.exp_flags |= SSH_OPT_EXP_FLAG_CONTROL_PATH;
  ------------------
  |  |  119|      0|#define SSH_OPT_EXP_FLAG_CONTROL_PATH 0x10
  ------------------
 2438|      0|        }
 2439|    800|    }
 2440|       |
 2441|    800|    for (tmp = ssh_list_pop_head(char *, session->opts.identity_non_exp);
  ------------------
  |  |  122|    800|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2442|  3.20k|         tmp != NULL;
  ------------------
  |  Branch (2442:10): [True: 2.40k, False: 800]
  ------------------
 2443|  2.40k|         tmp = ssh_list_pop_head(char *, session->opts.identity_non_exp)) {
  ------------------
  |  |  122|  2.40k|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2444|  2.40k|        char *id = tmp;
 2445|  2.40k|        if (strncmp(id, "pkcs11:", 6) != 0) {
  ------------------
  |  Branch (2445:13): [True: 2.40k, False: 0]
  ------------------
 2446|       |            /* PKCS#11 URIs are using percent-encoding so we can not mix
 2447|       |             * it with ssh expansion of ssh escape characters.
 2448|       |             */
 2449|  2.40k|            tmp = ssh_path_expand_escape(session, id);
 2450|  2.40k|            free(id);
 2451|  2.40k|            if (tmp == NULL) {
  ------------------
  |  Branch (2451:17): [True: 0, False: 2.40k]
  ------------------
 2452|      0|                return -1;
 2453|      0|            }
 2454|  2.40k|        }
 2455|       |
 2456|       |        /* use append to keep the order at first call and use prepend
 2457|       |         * to put anything that comes on the nth calls to the beginning */
 2458|  2.40k|        if (session->opts.exp_flags & SSH_OPT_EXP_FLAG_IDENTITY) {
  ------------------
  |  |  118|  2.40k|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
  |  Branch (2458:13): [True: 0, False: 2.40k]
  ------------------
 2459|      0|            rc = ssh_list_prepend(session->opts.identity, tmp);
 2460|  2.40k|        } else {
 2461|  2.40k|            rc = ssh_list_append(session->opts.identity, tmp);
 2462|  2.40k|        }
 2463|  2.40k|        if (rc != SSH_OK) {
  ------------------
  |  |  316|  2.40k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2463:13): [True: 0, False: 2.40k]
  ------------------
 2464|      0|            free(tmp);
 2465|      0|            return -1;
 2466|      0|        }
 2467|  2.40k|    }
 2468|    800|    session->opts.exp_flags |= SSH_OPT_EXP_FLAG_IDENTITY;
  ------------------
  |  |  118|    800|#define SSH_OPT_EXP_FLAG_IDENTITY 0x8
  ------------------
 2469|       |
 2470|    800|    for (tmp = ssh_list_pop_head(char *, session->opts.certificate_non_exp);
  ------------------
  |  |  122|    800|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2471|    800|         tmp != NULL;
  ------------------
  |  Branch (2471:10): [True: 0, False: 800]
  ------------------
 2472|    800|         tmp = ssh_list_pop_head(char *, session->opts.certificate_non_exp)) {
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2473|      0|        char *id = tmp;
 2474|       |
 2475|      0|        tmp = ssh_path_expand_escape(session, id);
 2476|      0|        free(id);
 2477|      0|        if (tmp == NULL) {
  ------------------
  |  Branch (2477:13): [True: 0, False: 0]
  ------------------
 2478|      0|            return -1;
 2479|      0|        }
 2480|       |
 2481|      0|        rc = ssh_list_append(session->opts.certificate, tmp);
 2482|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2482:13): [True: 0, False: 0]
  ------------------
 2483|      0|            free(tmp);
 2484|      0|            return -1;
 2485|      0|        }
 2486|      0|    }
 2487|       |
 2488|       |#ifdef WITH_GSSAPI
 2489|       |    if (session->opts.gssapi_key_exchange) {
 2490|       |        rc = ssh_gssapi_check_client_config(session);
 2491|       |        if (rc != SSH_OK) {
 2492|       |            SSH_LOG(SSH_LOG_WARN, "Disabled GSSAPI key exchange");
 2493|       |            session->opts.gssapi_key_exchange = false;
 2494|       |        }
 2495|       |    }
 2496|       |#endif
 2497|       |
 2498|    800|    return 0;
 2499|    800|}

ssh_packet_get_current_crypto:
 1159|   180k|{
 1160|   180k|    struct ssh_crypto_struct *crypto = NULL;
 1161|       |
 1162|   180k|    if (session == NULL) {
  ------------------
  |  Branch (1162:9): [True: 0, False: 180k]
  ------------------
 1163|      0|        return NULL;
 1164|      0|    }
 1165|       |
 1166|   180k|    if (session->current_crypto != NULL &&
  ------------------
  |  Branch (1166:9): [True: 0, False: 180k]
  ------------------
 1167|      0|        session->current_crypto->used & direction) {
  ------------------
  |  Branch (1167:9): [True: 0, False: 0]
  ------------------
 1168|      0|        crypto = session->current_crypto;
 1169|   180k|    } else if (session->next_crypto != NULL &&
  ------------------
  |  Branch (1169:16): [True: 180k, False: 0]
  ------------------
 1170|   180k|               session->next_crypto->used & direction) {
  ------------------
  |  Branch (1170:16): [True: 17.1k, False: 163k]
  ------------------
 1171|  17.1k|        crypto = session->next_crypto;
 1172|   163k|    } else {
 1173|   163k|        return NULL;
 1174|   163k|    }
 1175|       |
 1176|  17.1k|    switch (direction) {
  ------------------
  |  Branch (1176:13): [True: 17.1k, False: 0]
  ------------------
 1177|      0|    case SSH_DIRECTION_IN:
  ------------------
  |  Branch (1177:5): [True: 0, False: 17.1k]
  ------------------
 1178|      0|        if (crypto->in_cipher != NULL) {
  ------------------
  |  Branch (1178:13): [True: 0, False: 0]
  ------------------
 1179|      0|            return crypto;
 1180|      0|        }
 1181|      0|        break;
 1182|  17.1k|    case SSH_DIRECTION_OUT:
  ------------------
  |  Branch (1182:5): [True: 17.1k, False: 0]
  ------------------
 1183|  17.1k|        if (crypto->out_cipher != NULL) {
  ------------------
  |  Branch (1183:13): [True: 17.1k, False: 0]
  ------------------
 1184|  17.1k|            return crypto;
 1185|  17.1k|        }
 1186|      0|        break;
 1187|      0|    case SSH_DIRECTION_BOTH:
  ------------------
  |  Branch (1187:5): [True: 0, False: 17.1k]
  ------------------
 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|  17.1k|    }
 1193|       |
 1194|      0|    return NULL;
 1195|  17.1k|}
ssh_packet_socket_callback:
 1286|  57.5k|{
 1287|  57.5k|    ssh_session session = (ssh_session)user;
 1288|  57.5k|    uint32_t blocksize = 8;
 1289|  57.5k|    uint32_t lenfield_blocksize = 8;
 1290|  57.5k|    size_t current_macsize = 0;
 1291|  57.5k|    uint8_t *ptr = NULL;
 1292|  57.5k|    ssize_t to_be_read;
 1293|  57.5k|    int rc;
 1294|  57.5k|    uint8_t *cleartext_packet = NULL;
 1295|  57.5k|    uint8_t *packet_second_block = NULL;
 1296|  57.5k|    uint8_t *mac = NULL;
 1297|  57.5k|    size_t packet_remaining, packet_offset;
 1298|  57.5k|    uint32_t packet_len, compsize, payloadsize;
 1299|  57.5k|    uint8_t padding;
 1300|  57.5k|    size_t processed = 0; /* number of bytes processed from the callback */
 1301|  57.5k|    enum ssh_packet_filter_result_e filter_result;
 1302|  57.5k|    struct ssh_crypto_struct *crypto = NULL;
 1303|  57.5k|    bool etm = false;
 1304|  57.5k|    uint32_t etm_packet_offset = 0;
 1305|  57.5k|    bool ok;
 1306|       |
 1307|  57.5k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
 1308|  57.5k|    if (crypto != NULL) {
  ------------------
  |  Branch (1308:9): [True: 0, False: 57.5k]
  ------------------
 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|  57.5k|    if (etm) {
  ------------------
  |  Branch (1315:9): [True: 0, False: 57.5k]
  ------------------
 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|  57.5k|    } else if (lenfield_blocksize == 0) {
  ------------------
  |  Branch (1322:16): [True: 0, False: 57.5k]
  ------------------
 1323|      0|        lenfield_blocksize = blocksize;
 1324|      0|    }
 1325|  57.5k|    if (data == NULL) {
  ------------------
  |  Branch (1325:9): [True: 0, False: 57.5k]
  ------------------
 1326|      0|        goto error;
 1327|      0|    }
 1328|       |
 1329|  57.5k|    if (session->session_state == SSH_SESSION_STATE_ERROR) {
  ------------------
  |  Branch (1329:9): [True: 542, False: 56.9k]
  ------------------
 1330|    542|        goto error;
 1331|    542|    }
 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|  56.9k|    switch (session->packet_state) {
  ------------------
  |  Branch (1343:13): [True: 56.9k, False: 0]
  ------------------
 1344|  56.4k|        case PACKET_STATE_INIT:
  ------------------
  |  Branch (1344:9): [True: 56.4k, False: 512]
  ------------------
 1345|  56.4k|            if (receivedlen < lenfield_blocksize + etm_packet_offset) {
  ------------------
  |  Branch (1345:17): [True: 195, False: 56.2k]
  ------------------
 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|    195|                return 0;
 1357|    195|            }
 1358|       |
 1359|  56.2k|            session->in_packet = (struct packet_struct) {
 1360|  56.2k|                .type = 0,
 1361|  56.2k|            };
 1362|       |
 1363|  56.2k|            if (session->in_buffer) {
  ------------------
  |  Branch (1363:17): [True: 56.2k, False: 0]
  ------------------
 1364|  56.2k|                rc = ssh_buffer_reinit(session->in_buffer);
 1365|  56.2k|                if (rc < 0) {
  ------------------
  |  Branch (1365:21): [True: 0, False: 56.2k]
  ------------------
 1366|      0|                    goto error;
 1367|      0|                }
 1368|  56.2k|            } 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|  56.2k|            if (!etm) {
  ------------------
  |  Branch (1375:17): [True: 56.2k, False: 0]
  ------------------
 1376|  56.2k|                ptr = ssh_buffer_allocate(session->in_buffer,
 1377|  56.2k|                                          lenfield_blocksize);
 1378|  56.2k|                if (ptr == NULL) {
  ------------------
  |  Branch (1378:21): [True: 0, False: 56.2k]
  ------------------
 1379|      0|                    goto error;
 1380|      0|                }
 1381|  56.2k|                packet_len = ssh_packet_decrypt_len(session, ptr,
 1382|  56.2k|                                                    (uint8_t *)data);
 1383|  56.2k|                to_be_read = packet_len - lenfield_blocksize + sizeof(uint32_t);
 1384|  56.2k|            } 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|  56.2k|            processed += lenfield_blocksize + etm_packet_offset;
 1391|  56.2k|            if (packet_len > MAX_PACKET_LEN) {
  ------------------
  |  |  216|  56.2k|#define MAX_PACKET_LEN 262144
  ------------------
  |  Branch (1391:17): [True: 99, False: 56.1k]
  ------------------
 1392|     99|                ssh_set_error(session,
  ------------------
  |  |  311|     99|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1393|     99|                              SSH_FATAL,
 1394|     99|                              "read_packet(): Packet len too high(%" PRIu32 " %.4" PRIx32 ")",
 1395|     99|                              packet_len, packet_len);
 1396|     99|                goto error;
 1397|     99|            }
 1398|  56.1k|            if (to_be_read < 0) {
  ------------------
  |  Branch (1398:17): [True: 0, False: 56.1k]
  ------------------
 1399|       |                /* remote sshd sends invalid sizes? */
 1400|      0|                ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1401|      0|                              SSH_FATAL,
 1402|      0|                              "Given numbers of bytes left to be read < 0 (%zd)!",
 1403|      0|                              to_be_read);
 1404|      0|                goto error;
 1405|      0|            }
 1406|       |
 1407|  56.1k|            session->in_packet.len = packet_len;
 1408|  56.1k|            session->packet_state = PACKET_STATE_SIZEREAD;
 1409|  56.1k|            FALL_THROUGH;
  ------------------
  |  |  494|  56.1k|#  define FALL_THROUGH __attribute__ ((fallthrough))
  ------------------
 1410|  56.6k|        case PACKET_STATE_SIZEREAD:
  ------------------
  |  Branch (1410:9): [True: 512, False: 56.4k]
  ------------------
 1411|  56.6k|            packet_len = session->in_packet.len;
 1412|  56.6k|            packet_offset = processed = lenfield_blocksize + etm_packet_offset;
 1413|  56.6k|            to_be_read = packet_len + sizeof(uint32_t) + current_macsize;
 1414|       |            /* if to_be_read is zero, the whole packet was blocksize bytes. */
 1415|  56.6k|            if (to_be_read != 0) {
  ------------------
  |  Branch (1415:17): [True: 56.6k, False: 0]
  ------------------
 1416|  56.6k|                if (receivedlen < (unsigned long)to_be_read) {
  ------------------
  |  Branch (1416:21): [True: 605, False: 56.0k]
  ------------------
 1417|       |                    /* give up, not enough data in buffer */
 1418|    605|                    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|    605|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1419|    605|                            "packet: partial packet (read len) "
 1420|    605|                            "[len=%" PRIu32 ", receivedlen=%zu, to_be_read=%zd]",
 1421|    605|                            packet_len,
 1422|    605|                            receivedlen,
 1423|    605|                            to_be_read);
 1424|    605|                    return 0;
 1425|    605|                }
 1426|       |
 1427|  56.0k|                packet_second_block = (uint8_t*)data + packet_offset;
 1428|  56.0k|                processed = to_be_read - current_macsize;
 1429|  56.0k|            }
 1430|       |
 1431|  56.0k|            if (packet_offset - sizeof(uint32_t) > (size_t)packet_len) {
  ------------------
  |  Branch (1431:17): [True: 12, False: 56.0k]
  ------------------
 1432|     12|                ssh_set_error(session,
  ------------------
  |  |  311|     12|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1433|     12|                              SSH_FATAL,
 1434|     12|                              "Invalid packet length %" PRIu32 ", required %zu",
 1435|     12|                              packet_len,
 1436|     12|                              packet_offset + sizeof(uint32_t));
 1437|     12|                goto error;
 1438|     12|            }
 1439|       |
 1440|       |            /* remaining encrypted bytes from the packet, MAC not included */
 1441|  56.0k|            packet_remaining = packet_len - (packet_offset - sizeof(uint32_t));
 1442|  56.0k|            cleartext_packet = ssh_buffer_allocate(session->in_buffer,
 1443|  56.0k|                                                   (uint32_t)packet_remaining);
 1444|  56.0k|            if (cleartext_packet == NULL) {
  ------------------
  |  Branch (1444:17): [True: 0, False: 56.0k]
  ------------------
 1445|      0|                goto error;
 1446|      0|            }
 1447|       |
 1448|  56.0k|            if (packet_second_block != NULL) {
  ------------------
  |  Branch (1448:17): [True: 56.0k, False: 0]
  ------------------
 1449|  56.0k|                if (crypto != NULL) {
  ------------------
  |  Branch (1449:21): [True: 0, False: 56.0k]
  ------------------
 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|  56.0k|                } else {
 1496|  56.0k|                    memcpy(cleartext_packet,
 1497|  56.0k|                           packet_second_block,
 1498|  56.0k|                           packet_remaining);
 1499|  56.0k|                }
 1500|  56.0k|            }
 1501|       |
 1502|  56.0k|#ifdef WITH_PCAP
 1503|  56.0k|            if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1503:17): [True: 0, False: 56.0k]
  ------------------
 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|  56.0k|#endif
 1511|       |
 1512|  56.0k|            if (!etm) {
  ------------------
  |  Branch (1512:17): [True: 56.0k, False: 0]
  ------------------
 1513|       |                /* skip the size field which has been processed before */
 1514|  56.0k|                ssh_buffer_pass_bytes(session->in_buffer, sizeof(uint32_t));
 1515|  56.0k|            }
 1516|       |
 1517|  56.0k|            rc = ssh_buffer_get_u8(session->in_buffer, &padding);
 1518|  56.0k|            if (rc == 0) {
  ------------------
  |  Branch (1518:17): [True: 0, False: 56.0k]
  ------------------
 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|  56.0k|            if (padding > ssh_buffer_get_len(session->in_buffer)) {
  ------------------
  |  Branch (1525:17): [True: 7, False: 56.0k]
  ------------------
 1526|      7|                ssh_set_error(session,
  ------------------
  |  |  311|      7|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1527|      7|                              SSH_FATAL,
 1528|      7|                              "Invalid padding: %d (%" PRIu32 " left)",
 1529|      7|                              padding,
 1530|      7|                              ssh_buffer_get_len(session->in_buffer));
 1531|      7|                goto error;
 1532|      7|            }
 1533|  56.0k|            ssh_buffer_pass_bytes_end(session->in_buffer, padding);
 1534|  56.0k|            compsize = ssh_buffer_get_len(session->in_buffer);
 1535|       |
 1536|  56.0k|            if (crypto && crypto->do_compress_in &&
  ------------------
  |  Branch (1536:17): [True: 0, False: 56.0k]
  |  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|  56.0k|            payloadsize = ssh_buffer_get_len(session->in_buffer);
 1545|  56.0k|            if (session->recv_seq == UINT32_MAX) {
  ------------------
  |  Branch (1545:17): [True: 0, False: 56.0k]
  ------------------
 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|  56.0k|            session->recv_seq++;
 1559|  56.0k|            if (crypto != NULL) {
  ------------------
  |  Branch (1559:17): [True: 0, False: 56.0k]
  ------------------
 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|  56.0k|            if (session->raw_counter != NULL) {
  ------------------
  |  Branch (1566:17): [True: 0, False: 56.0k]
  ------------------
 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|  56.0k|            session->packet_state = PACKET_STATE_PROCESSING;
 1576|  56.0k|            ssh_packet_parse_type(session);
 1577|  56.0k|            SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  56.0k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1578|  56.0k|                    "packet: read type %hhd [len=%" PRIu32 ",padding=%hhd,"
 1579|  56.0k|                    "comp=%" PRIu32 ",payload=%" PRIu32 "]",
 1580|  56.0k|                    session->in_packet.type, packet_len, padding, compsize,
 1581|  56.0k|                    payloadsize);
 1582|  56.0k|            if (crypto == NULL) {
  ------------------
  |  Branch (1582:17): [True: 56.0k, 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|  56.0k|                uint8_t type = session->in_packet.type;
 1588|       |
 1589|  56.0k|                if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   12|   112k|#define SSH2_MSG_KEXINIT	 20
  ------------------
                              if (type != SSH2_MSG_KEXINIT && type != SSH2_MSG_NEWKEYS &&
  ------------------
  |  |   13|   111k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (1589:21): [True: 55.5k, False: 479]
  |  Branch (1589:49): [True: 55.5k, False: 37]
  ------------------
 1590|  55.5k|                    (type < SSH2_MSG_KEXDH_INIT ||
  ------------------
  |  |   15|   111k|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (1590:22): [True: 37.4k, False: 18.1k]
  ------------------
 1591|  55.1k|                     type > SSH2_MSG_KEX_DH_GEX_REQUEST)) {
  ------------------
  |  |   26|  18.1k|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (1591:22): [True: 17.7k, False: 368]
  ------------------
 1592|  55.1k|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|  55.1k|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1593|  55.1k|                }
 1594|  56.0k|            }
 1595|       |            /* Check if the packet is expected */
 1596|  56.0k|            filter_result = ssh_packet_incoming_filter(session);
 1597|       |
 1598|  56.0k|            switch (filter_result) {
  ------------------
  |  Branch (1598:21): [True: 56.0k, False: 0]
  ------------------
 1599|  24.8k|            case SSH_PACKET_ALLOWED:
  ------------------
  |  Branch (1599:13): [True: 24.8k, False: 31.1k]
  ------------------
 1600|       |                /* Execute callbacks */
 1601|  24.8k|                ssh_packet_process(session, session->in_packet.type);
 1602|  24.8k|                break;
 1603|     37|            case SSH_PACKET_DENIED:
  ------------------
  |  Branch (1603:13): [True: 37, False: 56.0k]
  ------------------
 1604|     37|                ssh_set_error(session,
  ------------------
  |  |  311|     37|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1605|     37|                              SSH_FATAL,
 1606|     37|                              "Packet filter: rejected packet (type %d)",
 1607|     37|                              session->in_packet.type);
 1608|     37|                goto error;
 1609|  31.1k|            case SSH_PACKET_UNKNOWN:
  ------------------
  |  Branch (1609:13): [True: 31.1k, False: 24.9k]
  ------------------
 1610|  31.1k|                if (crypto == NULL) {
  ------------------
  |  Branch (1610:21): [True: 31.1k, False: 0]
  ------------------
 1611|  31.1k|                    session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|  31.1k|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1612|  31.1k|                }
 1613|  31.1k|                ssh_packet_send_unimplemented(session, session->recv_seq - 1);
 1614|  31.1k|                break;
 1615|  56.0k|            }
 1616|       |
 1617|  56.0k|            session->packet_state = PACKET_STATE_INIT;
 1618|  56.0k|            if (processed < receivedlen) {
  ------------------
  |  Branch (1618:17): [True: 55.9k, False: 40]
  ------------------
 1619|  55.9k|                SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  55.9k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1620|  55.9k|                        "packet: %zu bytes still remaining in socket buffer "
 1621|  55.9k|                        "after processing",
 1622|  55.9k|                        receivedlen-processed);
 1623|  55.9k|            }
 1624|       |
 1625|  56.0k|            ok = ssh_packet_need_rekey(session, 0);
 1626|  56.0k|            if (ok) {
  ------------------
  |  Branch (1626:17): [True: 0, False: 56.0k]
  ------------------
 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|  56.0k|            return processed;
 1636|      0|        case PACKET_STATE_PROCESSING:
  ------------------
  |  Branch (1636:9): [True: 0, False: 56.9k]
  ------------------
 1637|      0|            SSH_LOG(SSH_LOG_PACKET, "Nested packet processing. Delaying.");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1638|      0|            return 0;
 1639|  56.9k|    }
 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|    697|error:
 1647|    697|    session->session_state = SSH_SESSION_STATE_ERROR;
 1648|    697|    SSH_LOG(SSH_LOG_PACKET, "Packet: processed %zu bytes", processed);
  ------------------
  |  |  281|    697|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1649|    697|    return processed;
 1650|      0|}
ssh_packet_register_socket_callback:
 1677|    728|{
 1678|    728|    struct ssh_socket_callbacks_struct *callbacks = &session->socket_callbacks;
 1679|       |
 1680|    728|    callbacks->data = ssh_packet_socket_callback;
 1681|       |    callbacks->connected = NULL;
 1682|    728|    callbacks->controlflow = ssh_packet_socket_controlflow_callback;
 1683|    728|    callbacks->userdata = session;
 1684|    728|    ssh_socket_set_callbacks(s, callbacks);
 1685|    728|}
ssh_packet_set_callbacks:
 1692|  1.08k|{
 1693|  1.08k|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1693:9): [True: 728, False: 358]
  ------------------
 1694|    728|        session->packet_callbacks = ssh_list_new();
 1695|    728|        if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1695:13): [True: 0, False: 728]
  ------------------
 1696|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 1697|      0|            return;
 1698|      0|        }
 1699|    728|    }
 1700|  1.08k|    ssh_list_append(session->packet_callbacks, callbacks);
 1701|  1.08k|}
ssh_packet_remove_callbacks:
 1708|    292|{
 1709|    292|    struct ssh_iterator *it = NULL;
 1710|       |
 1711|    292|    it = ssh_list_find(session->packet_callbacks, callbacks);
 1712|    292|    if (it != NULL) {
  ------------------
  |  Branch (1712:9): [True: 292, False: 0]
  ------------------
 1713|    292|        ssh_list_remove(session->packet_callbacks, it);
 1714|    292|    }
 1715|    292|}
ssh_packet_set_default_callbacks:
 1721|    728|{
 1722|    728|    struct ssh_packet_callbacks_struct *c = &session->default_packet_callbacks;
 1723|       |
 1724|    728|    c->start = 1;
 1725|    728|    c->n_callbacks = sizeof(default_packet_handlers) / sizeof(ssh_packet_callback);
 1726|    728|    c->user = session;
 1727|    728|    c->callbacks = default_packet_handlers;
 1728|    728|    ssh_packet_set_callbacks(session, c);
 1729|    728|}
ssh_packet_process:
 1736|  24.8k|{
 1737|  24.8k|    struct ssh_iterator *i = NULL;
 1738|  24.8k|    int rc = SSH_PACKET_NOT_USED;
  ------------------
  |  |  640|  24.8k|#define SSH_PACKET_NOT_USED 2
  ------------------
 1739|  24.8k|    ssh_packet_callbacks cb;
 1740|       |
 1741|  24.8k|    SSH_LOG(SSH_LOG_PACKET, "Dispatching handler for packet type %d", type);
  ------------------
  |  |  281|  24.8k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1742|  24.8k|    if (session->packet_callbacks == NULL) {
  ------------------
  |  Branch (1742:9): [True: 0, False: 24.8k]
  ------------------
 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|  24.8k|    i = ssh_list_get_iterator(session->packet_callbacks);
 1748|  25.3k|    while (i != NULL) {
  ------------------
  |  Branch (1748:12): [True: 25.2k, False: 60]
  ------------------
 1749|  25.2k|        cb = ssh_iterator_value(ssh_packet_callbacks, i);
  ------------------
  |  |  114|  25.2k|  ((type)((iterator)->data))
  ------------------
 1750|  25.2k|        i = i->next;
 1751|       |
 1752|  25.2k|        if (!cb) {
  ------------------
  |  Branch (1752:13): [True: 0, False: 25.2k]
  ------------------
 1753|      0|            continue;
 1754|      0|        }
 1755|       |
 1756|  25.2k|        if (cb->start > type) {
  ------------------
  |  Branch (1756:13): [True: 0, False: 25.2k]
  ------------------
 1757|      0|            continue;
 1758|      0|        }
 1759|       |
 1760|  25.2k|        if (cb->start + cb->n_callbacks <= type) {
  ------------------
  |  Branch (1760:13): [True: 60, False: 25.1k]
  ------------------
 1761|     60|            continue;
 1762|     60|        }
 1763|       |
 1764|  25.1k|        if (cb->callbacks[type - cb->start] == NULL) {
  ------------------
  |  Branch (1764:13): [True: 362, False: 24.8k]
  ------------------
 1765|    362|            continue;
 1766|    362|        }
 1767|       |
 1768|  24.8k|        rc = cb->callbacks[type - cb->start](session, type, session->in_buffer,
 1769|  24.8k|                                             cb->user);
 1770|  24.8k|        if (rc == SSH_PACKET_USED) {
  ------------------
  |  |  637|  24.8k|#define SSH_PACKET_USED 1
  ------------------
  |  Branch (1770:13): [True: 24.8k, False: 0]
  ------------------
 1771|  24.8k|            break;
 1772|  24.8k|        }
 1773|  24.8k|    }
 1774|       |
 1775|  24.8k|    if (rc == SSH_PACKET_NOT_USED) {
  ------------------
  |  |  640|  24.8k|#define SSH_PACKET_NOT_USED 2
  ------------------
  |  Branch (1775:9): [True: 60, False: 24.8k]
  ------------------
 1776|     60|        SSH_LOG(SSH_LOG_RARE, "Couldn't do anything with packet type %d", type);
  ------------------
  |  |  281|     60|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1777|     60|        rc = ssh_packet_send_unimplemented(session, session->recv_seq - 1);
 1778|     60|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     60|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1778:13): [True: 0, False: 60]
  ------------------
 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|     60|        if (session->current_crypto == NULL) {
  ------------------
  |  Branch (1782:13): [True: 60, False: 0]
  ------------------
 1783|     60|            session->flags |= SSH_SESSION_FLAG_KEX_TAINTED;
  ------------------
  |  |   92|     60|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
 1784|     60|        }
 1785|     60|    }
 1786|  24.8k|}
ssh_packet_send_newkeys:
 1794|     71|{
 1795|     71|    int rc;
 1796|       |
 1797|       |    /* Send the MSG_NEWKEYS */
 1798|     71|    rc = ssh_buffer_add_u8(session->out_buffer, SSH2_MSG_NEWKEYS);
  ------------------
  |  |   13|     71|#define SSH2_MSG_NEWKEYS 21
  ------------------
 1799|     71|    if (rc < 0) {
  ------------------
  |  Branch (1799:9): [True: 0, False: 71]
  ------------------
 1800|      0|        return rc;
 1801|      0|    }
 1802|       |
 1803|     71|    rc = ssh_packet_send(session);
 1804|     71|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|     71|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1804:9): [True: 0, False: 71]
  ------------------
 1805|      0|        return rc;
 1806|      0|    }
 1807|     71|    SSH_LOG(SSH_LOG_DEBUG, "SSH_MSG_NEWKEYS sent");
  ------------------
  |  |  281|     71|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1808|     71|    return rc;
 1809|     71|}
ssh_packet_send_unimplemented:
 1817|  31.2k|int ssh_packet_send_unimplemented(ssh_session session, uint32_t seqnum){
 1818|  31.2k|    int rc;
 1819|       |
 1820|  31.2k|    rc = ssh_buffer_pack(session->out_buffer,
  ------------------
  |  |   50|  31.2k|    _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  31.2k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  31.2k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  31.2k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  31.2k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  31.2k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  31.2k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1821|  31.2k|                         "bd",
 1822|  31.2k|                         SSH2_MSG_UNIMPLEMENTED,
 1823|  31.2k|                         seqnum);
 1824|  31.2k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  31.2k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1824:9): [True: 0, False: 31.2k]
  ------------------
 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|  31.2k|    rc = ssh_packet_send(session);
 1829|       |
 1830|  31.2k|    return rc;
 1831|  31.2k|}
ssh_packet_unimplemented:
 1836|  1.13k|SSH_PACKET_CALLBACK(ssh_packet_unimplemented){
 1837|  1.13k|    uint32_t seq;
 1838|  1.13k|    int rc;
 1839|       |
 1840|  1.13k|    (void)session; /* unused */
 1841|  1.13k|    (void)type;
 1842|  1.13k|    (void)user;
 1843|       |
 1844|  1.13k|    rc = ssh_buffer_unpack(packet, "d", &seq);
  ------------------
  |  |   60|  1.13k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  1.13k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  1.13k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  1.13k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  1.13k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  1.13k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  1.13k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
 1845|  1.13k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  1.13k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (1845:9): [True: 720, False: 416]
  ------------------
 1846|    720|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|    720|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1847|    720|                "Could not unpack SSH_MSG_UNIMPLEMENTED packet");
 1848|    720|    }
 1849|       |
 1850|  1.13k|    SSH_LOG(SSH_LOG_RARE,
  ------------------
  |  |  281|  1.13k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1851|  1.13k|            "Received SSH_MSG_UNIMPLEMENTED (sequence number %" PRIu32 ")",seq);
 1852|       |
 1853|  1.13k|    return SSH_PACKET_USED;
  ------------------
  |  |  637|  1.13k|#define SSH_PACKET_USED 1
  ------------------
 1854|  1.13k|}
ssh_packet_parse_type:
 1860|  56.0k|{
 1861|  56.0k|    session->in_packet = (struct packet_struct) {
 1862|  56.0k|        .type = 0,
 1863|  56.0k|    };
 1864|       |
 1865|  56.0k|    if (session->in_buffer == NULL) {
  ------------------
  |  Branch (1865:9): [True: 0, False: 56.0k]
  ------------------
 1866|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1867|      0|    }
 1868|       |
 1869|  56.0k|    if (ssh_buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) {
  ------------------
  |  Branch (1869:9): [True: 12.8k, False: 43.2k]
  ------------------
 1870|  12.8k|        ssh_set_error(session, SSH_FATAL, "Packet too short to read type");
  ------------------
  |  |  311|  12.8k|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1871|  12.8k|        return SSH_ERROR;
  ------------------
  |  |  317|  12.8k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1872|  12.8k|    }
 1873|       |
 1874|  43.2k|    session->in_packet.valid = 1;
 1875|       |
 1876|  43.2k|    return SSH_OK;
  ------------------
  |  |  316|  43.2k|#define SSH_OK 0     /* No error */
  ------------------
 1877|  56.0k|}
ssh_packet_send:
 2065|  33.1k|{
 2066|  33.1k|    uint32_t payloadsize;
 2067|  33.1k|    uint8_t type, *payload;
 2068|  33.1k|    bool need_rekey, in_rekey;
 2069|  33.1k|    int rc;
 2070|       |
 2071|  33.1k|    if (session->socket == NULL || !ssh_socket_is_open(session->socket)) {
  ------------------
  |  Branch (2071:9): [True: 0, False: 33.1k]
  |  Branch (2071:36): [True: 0, False: 33.1k]
  ------------------
 2072|      0|        ssh_buffer_reinit(session->out_buffer);
 2073|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2074|      0|    }
 2075|       |
 2076|  33.1k|    payloadsize = ssh_buffer_get_len(session->out_buffer);
 2077|  33.1k|    if (payloadsize < 1) {
  ------------------
  |  Branch (2077:9): [True: 0, False: 33.1k]
  ------------------
 2078|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2079|      0|    }
 2080|       |
 2081|  33.1k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 2082|  33.1k|    type = payload[0]; /* type is the first byte of the packet now */
 2083|  33.1k|    need_rekey = ssh_packet_need_rekey(session, payloadsize);
 2084|  33.1k|    in_rekey = ssh_packet_in_rekey(session);
 2085|       |
 2086|       |    /* The rekey is triggered here. After that, only the key exchange
 2087|       |     * packets can be sent, until we send our NEWKEYS.
 2088|       |     */
 2089|  33.1k|    if (need_rekey || (in_rekey && !ssh_packet_is_kex(type))) {
  ------------------
  |  Branch (2089:9): [True: 0, False: 33.1k]
  |  Branch (2089:24): [True: 0, False: 33.1k]
  |  Branch (2089:36): [True: 0, False: 0]
  ------------------
 2090|      0|        if (need_rekey) {
  ------------------
  |  Branch (2090:13): [True: 0, False: 0]
  ------------------
 2091|      0|            SSH_LOG(SSH_LOG_PACKET, "Outgoing packet triggered rekey");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2092|      0|        }
 2093|       |        /* Queue the current packet -- we will send it after the rekey */
 2094|      0|        SSH_LOG(SSH_LOG_PACKET, "Queuing packet type %d", type);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2095|      0|        rc = ssh_list_append(session->out_queue, session->out_buffer);
 2096|      0|        if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2096:13): [True: 0, False: 0]
  ------------------
 2097|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2098|      0|        }
 2099|      0|        session->out_buffer = ssh_buffer_new();
 2100|      0|        if (session->out_buffer == NULL) {
  ------------------
  |  Branch (2100:13): [True: 0, False: 0]
  ------------------
 2101|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2102|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2103|      0|        }
 2104|       |
 2105|      0|        if (need_rekey) {
  ------------------
  |  Branch (2105:13): [True: 0, False: 0]
  ------------------
 2106|       |            /* Send the KEXINIT packet instead.
 2107|       |             * This recursively calls the packet_send(), but it should
 2108|       |             * not get into rekeying again.
 2109|       |             * After that we need to handle the key exchange responses
 2110|       |             * up to the point where we can send the rest of the queue.
 2111|       |             */
 2112|      0|            return ssh_send_rekex(session);
 2113|      0|        }
 2114|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2115|      0|    }
 2116|       |
 2117|       |    /* Send the packet normally */
 2118|  33.1k|    rc = packet_send2(session);
 2119|       |
 2120|       |    /* We finished the key exchange so we can try to send our queue now */
 2121|  33.1k|    if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |  316|  66.3k|#define SSH_OK 0     /* No error */
  ------------------
                  if (rc == SSH_OK && type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  33.1k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2121:9): [True: 33.1k, False: 0]
  |  Branch (2121:25): [True: 71, False: 33.1k]
  ------------------
 2122|     71|        struct ssh_iterator *it = NULL;
 2123|       |
 2124|     71|        if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|     71|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (2124:13): [True: 3, False: 68]
  ------------------
 2125|       |            /* reset packet sequence number when running in strict kex mode */
 2126|      3|            session->send_seq = 0;
 2127|      3|        }
 2128|     71|        for (it = ssh_list_get_iterator(session->out_queue);
 2129|     71|             it != NULL;
  ------------------
  |  Branch (2129:14): [True: 0, False: 71]
  ------------------
 2130|     71|             it = ssh_list_get_iterator(session->out_queue)) {
 2131|      0|            struct ssh_buffer_struct *next_buffer = NULL;
 2132|       |
 2133|       |            /* Peek only -- do not remove from queue yet */
 2134|      0|            next_buffer = (struct ssh_buffer_struct *)it->data;
 2135|      0|            payloadsize = ssh_buffer_get_len(next_buffer);
 2136|      0|            if (ssh_packet_need_rekey(session, payloadsize)) {
  ------------------
  |  Branch (2136:17): [True: 0, False: 0]
  ------------------
 2137|       |                /* Sigh ... we still can not send this packet. Repeat. */
 2138|      0|                SSH_LOG(SSH_LOG_PACKET, "Queued packet triggered rekey");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2139|      0|                return ssh_send_rekex(session);
 2140|      0|            }
 2141|      0|            SSH_BUFFER_FREE(session->out_buffer);
  ------------------
  |  |  934|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (934:14): [True: 0, False: 0]
  |  |  |  Branch (934:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2142|      0|            session->out_buffer = ssh_list_pop_head(struct ssh_buffer_struct *,
  ------------------
  |  |  122|      0|  ((type)_ssh_list_pop_head(ssh_list))
  ------------------
 2143|      0|                                                    session->out_queue);
 2144|      0|            payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 2145|      0|            type = payload[0];
 2146|      0|            SSH_LOG(SSH_LOG_PACKET, "Dequeue packet type %d", type);
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2147|      0|            rc = packet_send2(session);
 2148|      0|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2148:17): [True: 0, False: 0]
  ------------------
 2149|      0|                return rc;
 2150|      0|            }
 2151|      0|        }
 2152|     71|    }
 2153|       |
 2154|  33.1k|    return rc;
 2155|  33.1k|}
ssh_packet_set_newkeys:
 2270|     71|{
 2271|     71|    struct ssh_cipher_struct *in_cipher = NULL, *out_cipher = NULL;
 2272|     71|    int rc;
 2273|       |
 2274|     71|    SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|    284|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 0, False: 71]
  |  |  |  Branch (281:34): [True: 71, False: 0]
  |  |  ------------------
  ------------------
 2275|     71|            "called, direction =%s%s",
 2276|     71|            direction & SSH_DIRECTION_IN ? " IN " : "",
 2277|     71|            direction & SSH_DIRECTION_OUT ? " OUT " : "");
 2278|       |
 2279|     71|    if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2279:9): [True: 0, False: 71]
  ------------------
 2280|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2281|      0|    }
 2282|       |
 2283|     71|    session->next_crypto->used |= direction;
 2284|     71|    if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2284:9): [True: 0, False: 71]
  ------------------
 2285|      0|        if (session->current_crypto->used & direction) {
  ------------------
  |  Branch (2285:13): [True: 0, False: 0]
  ------------------
 2286|      0|            SSH_LOG(SSH_LOG_TRACE, "This direction isn't used anymore.");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2287|      0|        }
 2288|       |        /* Mark the current requested direction unused */
 2289|      0|        session->current_crypto->used &= ~direction;
 2290|      0|    }
 2291|       |
 2292|       |    /* Both sides switched: do the actual switch now */
 2293|     71|    if (session->next_crypto->used == SSH_DIRECTION_BOTH) {
  ------------------
  |  Branch (2293:9): [True: 0, False: 71]
  ------------------
 2294|      0|        size_t session_id_len;
 2295|       |
 2296|      0|        if (session->current_crypto != NULL) {
  ------------------
  |  Branch (2296:13): [True: 0, False: 0]
  ------------------
 2297|      0|            crypto_free(session->current_crypto);
 2298|      0|            session->current_crypto = NULL;
 2299|      0|        }
 2300|       |
 2301|      0|        session->current_crypto = session->next_crypto;
 2302|      0|        session->current_crypto->used = SSH_DIRECTION_BOTH;
 2303|       |
 2304|       |        /* Initialize the next_crypto structure */
 2305|      0|        session->next_crypto = crypto_new();
 2306|      0|        if (session->next_crypto == NULL) {
  ------------------
  |  Branch (2306:13): [True: 0, False: 0]
  ------------------
 2307|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2308|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2309|      0|        }
 2310|       |
 2311|      0|        session_id_len = session->current_crypto->session_id_len;
 2312|      0|        session->next_crypto->session_id = malloc(session_id_len);
 2313|      0|        if (session->next_crypto->session_id == NULL) {
  ------------------
  |  Branch (2313:13): [True: 0, False: 0]
  ------------------
 2314|      0|            ssh_set_error_oom(session);
  ------------------
  |  |  318|      0|    _ssh_set_error_oom(error, __func__)
  ------------------
 2315|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2316|      0|        }
 2317|       |
 2318|      0|        memcpy(session->next_crypto->session_id,
 2319|      0|               session->current_crypto->session_id,
 2320|      0|               session_id_len);
 2321|      0|        session->next_crypto->session_id_len = session_id_len;
 2322|       |
 2323|      0|        return SSH_OK;
  ------------------
  |  |  316|      0|#define SSH_OK 0     /* No error */
  ------------------
 2324|      0|    }
 2325|       |
 2326|       |    /* Initialize common structures so the next context can be used in
 2327|       |     * either direction */
 2328|     71|    if (session->client) {
  ------------------
  |  Branch (2328:9): [True: 71, False: 0]
  ------------------
 2329|       |        /* The server has this part already done */
 2330|     71|        rc = ssh_make_sessionid(session);
 2331|     71|        if (rc != SSH_OK) {
  ------------------
  |  |  316|     71|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2331:13): [True: 0, False: 71]
  ------------------
 2332|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2333|      0|        }
 2334|       |
 2335|       |        /*
 2336|       |         * Set the cryptographic functions for the next crypto
 2337|       |         * (it is needed for ssh_generate_session_keys for key lengths)
 2338|       |         */
 2339|     71|        rc = crypt_set_algorithms_client(session);
 2340|     71|        if (rc < 0) {
  ------------------
  |  Branch (2340:13): [True: 0, False: 71]
  ------------------
 2341|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2342|      0|        }
 2343|     71|    }
 2344|       |
 2345|     71|    if (ssh_generate_session_keys(session) < 0) {
  ------------------
  |  Branch (2345:9): [True: 0, False: 71]
  ------------------
 2346|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2347|      0|    }
 2348|       |
 2349|     71|    in_cipher = session->next_crypto->in_cipher;
 2350|     71|    out_cipher = session->next_crypto->out_cipher;
 2351|     71|    if (in_cipher == NULL || out_cipher == NULL) {
  ------------------
  |  Branch (2351:9): [True: 0, False: 71]
  |  Branch (2351:30): [True: 0, False: 71]
  ------------------
 2352|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2353|      0|    }
 2354|       |
 2355|       |    /* Initialize rekeying states */
 2356|     71|    ssh_init_rekey_state(session, out_cipher);
 2357|     71|    ssh_init_rekey_state(session, in_cipher);
 2358|     71|    if (session->opts.rekey_time != 0) {
  ------------------
  |  Branch (2358:9): [True: 0, False: 71]
  ------------------
 2359|      0|        ssh_timestamp_init(&session->last_rekey_time);
 2360|      0|        SSH_LOG(SSH_LOG_DEBUG, "Set rekey after %" PRIu32 " seconds",
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2361|      0|                session->opts.rekey_time/1000);
 2362|      0|    }
 2363|       |
 2364|     71|    if (in_cipher->set_decrypt_key) {
  ------------------
  |  Branch (2364:9): [True: 0, False: 71]
  ------------------
 2365|       |        /* Initialize the encryption and decryption keys in next_crypto */
 2366|      0|        rc = in_cipher->set_decrypt_key(in_cipher,
 2367|      0|                                        session->next_crypto->decryptkey,
 2368|      0|                                        session->next_crypto->decryptIV);
 2369|      0|        if (rc < 0) {
  ------------------
  |  Branch (2369:13): [True: 0, False: 0]
  ------------------
 2370|       |            /* On error, make sure it is not used */
 2371|      0|            session->next_crypto->used = 0;
 2372|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2373|      0|        }
 2374|      0|    }
 2375|       |
 2376|     71|    if (out_cipher->set_encrypt_key) {
  ------------------
  |  Branch (2376:9): [True: 0, False: 71]
  ------------------
 2377|      0|        rc = out_cipher->set_encrypt_key(out_cipher,
 2378|      0|                                         session->next_crypto->encryptkey,
 2379|      0|                                         session->next_crypto->encryptIV);
 2380|      0|        if (rc < 0) {
  ------------------
  |  Branch (2380:13): [True: 0, False: 0]
  ------------------
 2381|       |            /* On error, make sure it is not used */
 2382|      0|            session->next_crypto->used = 0;
 2383|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2384|      0|        }
 2385|      0|    }
 2386|       |
 2387|     71|    return SSH_OK;
  ------------------
  |  |  316|     71|#define SSH_OK 0     /* No error */
  ------------------
 2388|     71|}
packet.c:ssh_packet_incoming_filter:
  143|  56.0k|{
  144|  56.0k|    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|  56.0k|    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: 56.0k]
  ------------------
  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|    373|    case SSH2_MSG_IGNORE:                             // 2
  ------------------
  |  |    5|    373|#define SSH2_MSG_IGNORE	 2
  ------------------
  |  Branch (165:5): [True: 373, False: 55.7k]
  ------------------
  166|       |        /*
  167|       |         * States required:
  168|       |         * - None
  169|       |         *
  170|       |         * Transitions:
  171|       |         * - None
  172|       |         * */
  173|       |
  174|       |        /* Always allowed */
  175|    373|        rc = SSH_PACKET_ALLOWED;
  176|    373|        break;
  177|  1.13k|    case SSH2_MSG_UNIMPLEMENTED:                      // 3
  ------------------
  |  |    6|  1.13k|#define SSH2_MSG_UNIMPLEMENTED 3
  ------------------
  |  Branch (177:5): [True: 1.13k, False: 54.9k]
  ------------------
  178|       |        /*
  179|       |         * States required:
  180|       |         * - None
  181|       |         *
  182|       |         * Transitions:
  183|       |         * - None
  184|       |         * */
  185|       |
  186|       |        /* Always allowed */
  187|  1.13k|        rc = SSH_PACKET_ALLOWED;
  188|  1.13k|        break;
  189|  22.4k|    case SSH2_MSG_DEBUG:                              // 4
  ------------------
  |  |    7|  22.4k|#define SSH2_MSG_DEBUG	4
  ------------------
  |  Branch (189:5): [True: 22.4k, False: 33.6k]
  ------------------
  190|       |        /*
  191|       |         * States required:
  192|       |         * - None
  193|       |         *
  194|       |         * Transitions:
  195|       |         * - None
  196|       |         * */
  197|       |
  198|       |        /* Always allowed */
  199|  22.4k|        rc = SSH_PACKET_ALLOWED;
  200|  22.4k|        break;
  201|      1|    case SSH2_MSG_SERVICE_REQUEST:                    // 5
  ------------------
  |  |    8|      1|#define SSH2_MSG_SERVICE_REQUEST	5
  ------------------
  |  Branch (201:5): [True: 1, False: 56.0k]
  ------------------
  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: 56.0k]
  ------------------
  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|      1|    case SSH2_MSG_EXT_INFO:                           // 7
  ------------------
  |  |   10|      1|#define SSH2_MSG_EXT_INFO 7
  ------------------
  |  Branch (266:5): [True: 1, False: 56.0k]
  ------------------
  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|      1|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATING) &&
  ------------------
  |  Branch (278:13): [True: 1, False: 0]
  ------------------
  279|      1|            (session->session_state != SSH_SESSION_STATE_AUTHENTICATED))
  ------------------
  |  Branch (279:13): [True: 1, False: 0]
  ------------------
  280|      1|        {
  281|      1|            rc = SSH_PACKET_DENIED;
  282|      1|            break;
  283|      1|        }
  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|    479|    case SSH2_MSG_KEXINIT:                            // 20
  ------------------
  |  |   12|    479|#define SSH2_MSG_KEXINIT	 20
  ------------------
  |  Branch (292:5): [True: 479, False: 55.5k]
  ------------------
  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|    479|        if ((session->session_state != SSH_SESSION_STATE_AUTHENTICATED) &&
  ------------------
  |  Branch (310:13): [True: 479, False: 0]
  ------------------
  311|    479|            (session->session_state != SSH_SESSION_STATE_INITIAL_KEX))
  ------------------
  |  Branch (311:13): [True: 1, False: 478]
  ------------------
  312|      1|        {
  313|      1|            rc = SSH_PACKET_DENIED;
  314|      1|            break;
  315|      1|        }
  316|       |
  317|    478|        if ((session->dh_handshake_state != DH_STATE_INIT) &&
  ------------------
  |  Branch (317:13): [True: 0, False: 478]
  ------------------
  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|    478|        rc = SSH_PACKET_ALLOWED;
  327|    478|        break;
  328|     37|    case SSH2_MSG_NEWKEYS:                            // 21
  ------------------
  |  |   13|     37|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (328:5): [True: 37, False: 56.0k]
  ------------------
  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|     37|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (342:13): [True: 1, False: 36]
  ------------------
  343|      1|            rc = SSH_PACKET_DENIED;
  344|      1|            break;
  345|      1|        }
  346|       |
  347|       |        /* Only allowed if dh_handshake_state is in NEWKEYS_SENT state */
  348|     36|        if (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (348:13): [True: 2, False: 34]
  ------------------
  349|      2|            rc = SSH_PACKET_DENIED;
  350|      2|            break;
  351|      2|        }
  352|       |
  353|     34|        rc = SSH_PACKET_ALLOWED;
  354|     34|        break;
  355|      0|    case SSH2_MSG_KEXDH_INIT:                         // 30
  ------------------
  |  |   15|      0|#define SSH2_MSG_KEXDH_INIT 30
  ------------------
  |  Branch (355:5): [True: 0, False: 56.0k]
  ------------------
  356|       |      // SSH2_MSG_KEX_ECDH_INIT:                      // 30
  357|       |      // SSH2_MSG_KEX_HYBRID_INIT:                    // 30
  358|       |      // SSH2_MSG_KEX_DH_GEX_REQUEST_OLD:             // 30
  359|       |
  360|       |        /* Server only */
  361|       |
  362|       |        /*
  363|       |         * States required:
  364|       |         * - session_state == SSH_SESSION_STATE_DH
  365|       |         * - dh_handshake_state == DH_STATE_INIT
  366|       |         *
  367|       |         * Transitions:
  368|       |         * - session->dh_handshake_state = DH_STATE_INIT_SENT
  369|       |         * then calls dh_handshake_server which triggers:
  370|       |         * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  371|       |         * */
  372|       |
  373|      0|        if (session->client) {
  ------------------
  |  Branch (373:13): [True: 0, False: 0]
  ------------------
  374|      0|            rc = SSH_PACKET_DENIED;
  375|      0|            break;
  376|      0|        }
  377|       |
  378|      0|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (378:13): [True: 0, False: 0]
  ------------------
  379|      0|            rc = SSH_PACKET_DENIED;
  380|      0|            break;
  381|      0|        }
  382|       |
  383|       |        /* Only allowed if dh_handshake_state is in initial state */
  384|      0|        if (session->dh_handshake_state != DH_STATE_INIT) {
  ------------------
  |  Branch (384:13): [True: 0, False: 0]
  ------------------
  385|      0|            rc = SSH_PACKET_DENIED;
  386|      0|            break;
  387|      0|        }
  388|       |
  389|      0|        rc = SSH_PACKET_ALLOWED;
  390|      0|        break;
  391|    304|    case SSH2_MSG_KEXDH_REPLY:                        // 31
  ------------------
  |  |   16|    304|#define SSH2_MSG_KEXDH_REPLY 31
  ------------------
  |  Branch (391:5): [True: 304, False: 55.7k]
  ------------------
  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|    304|        if (session->server) {
  ------------------
  |  Branch (408:13): [True: 0, False: 304]
  ------------------
  409|      0|            rc = SSH_PACKET_DENIED;
  410|      0|            break;
  411|      0|        }
  412|       |
  413|    304|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (413:13): [True: 1, False: 303]
  ------------------
  414|      1|            rc = SSH_PACKET_DENIED;
  415|      1|            break;
  416|      1|        }
  417|       |
  418|    303|        if (session->dh_handshake_state != DH_STATE_INIT_SENT &&
  ------------------
  |  Branch (418:13): [True: 10, False: 293]
  ------------------
  419|     10|            session->dh_handshake_state != DH_STATE_REQUEST_SENT) {
  ------------------
  |  Branch (419:13): [True: 1, False: 9]
  ------------------
  420|      1|            rc = SSH_PACKET_DENIED;
  421|      1|            break;
  422|      1|        }
  423|       |
  424|    302|        rc = SSH_PACKET_ALLOWED;
  425|    302|        break;
  426|      0|    case SSH2_MSG_KEX_DH_GEX_INIT:                    // 32
  ------------------
  |  |   24|      0|#define SSH2_MSG_KEX_DH_GEX_INIT 32
  ------------------
  |  Branch (426:5): [True: 0, False: 56.0k]
  ------------------
  427|       |      // SSH2_MSG_KEXGSS_COMPLETE:                    // 32
  428|      0|        if (ssh_kex_is_gss(session->next_crypto)) {
  ------------------
  |  Branch (428:13): [True: 0, False: 0]
  ------------------
  429|       |            /* SSH2_MSG_KEXGSS_COMPLETE */
  430|       |            /* Client only */
  431|       |
  432|       |            /*
  433|       |             * States required:
  434|       |             * - session_state == SSH_SESSION_STATE_DH
  435|       |             * - dh_handshake_state == DH_STATE_INIT_SENT
  436|       |             *
  437|       |             * Transitions:
  438|       |             * - session->dh_handshake_state = DH_STATE_INIT_SENT
  439|       |             * then calls ssh_packet_client_gss_kex_reply which triggers:
  440|       |             * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  441|       |             * */
  442|       |
  443|      0|            if (!session->client) {
  ------------------
  |  Branch (443:17): [True: 0, False: 0]
  ------------------
  444|      0|                rc = SSH_PACKET_DENIED;
  445|      0|                break;
  446|      0|            }
  447|       |
  448|      0|            if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (448:17): [True: 0, False: 0]
  ------------------
  449|      0|                rc = SSH_PACKET_DENIED;
  450|      0|                break;
  451|      0|            }
  452|       |
  453|      0|            if (session->dh_handshake_state != DH_STATE_INIT_SENT) {
  ------------------
  |  Branch (453:17): [True: 0, False: 0]
  ------------------
  454|      0|                rc = SSH_PACKET_DENIED;
  455|      0|                break;
  456|      0|            }
  457|      0|        } else {
  458|       |            /* SSH2_MSG_KEX_DH_GEX_INIT */
  459|       |            /* Server only */
  460|       |
  461|       |            /*
  462|       |             * States required:
  463|       |             * - session_state == SSH_SESSION_STATE_DH
  464|       |             * - dh_handshake_state == DH_STATE_GROUP_SENT
  465|       |             *
  466|       |             * Transitions:
  467|       |             * - session->dh_handshake_state = DH_STATE_GROUP_SENT
  468|       |             * then calls ssh_packet_server_dhgex_init which triggers:
  469|       |             * - session->dh_handshake_state = DH_STATE_NEWKEYS_SENT
  470|       |             * */
  471|       |
  472|      0|            if (session->client) {
  ------------------
  |  Branch (472:17): [True: 0, False: 0]
  ------------------
  473|      0|                rc = SSH_PACKET_DENIED;
  474|      0|                break;
  475|      0|            }
  476|       |
  477|      0|            if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (477:17): [True: 0, False: 0]
  ------------------
  478|      0|                rc = SSH_PACKET_DENIED;
  479|      0|                break;
  480|      0|            }
  481|       |
  482|       |            /* Only allowed if dh_handshake_state is in initial state */
  483|      0|            if (session->dh_handshake_state != DH_STATE_GROUP_SENT) {
  ------------------
  |  Branch (483:17): [True: 0, False: 0]
  ------------------
  484|      0|                rc = SSH_PACKET_DENIED;
  485|      0|                break;
  486|      0|            }
  487|      0|        }
  488|      0|        rc = SSH_PACKET_ALLOWED;
  489|      0|        break;
  490|     63|    case SSH2_MSG_KEX_DH_GEX_REPLY:                   // 33
  ------------------
  |  |   25|     63|#define SSH2_MSG_KEX_DH_GEX_REPLY 33
  ------------------
  |  Branch (490:5): [True: 63, False: 56.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|     63|        if (session->server) {
  ------------------
  |  Branch (503:13): [True: 0, False: 63]
  ------------------
  504|      0|            rc = SSH_PACKET_DENIED;
  505|      0|            break;
  506|      0|        }
  507|       |
  508|     63|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (508:13): [True: 1, False: 62]
  ------------------
  509|      1|            rc = SSH_PACKET_DENIED;
  510|      1|            break;
  511|      1|        }
  512|       |
  513|     62|        if (session->dh_handshake_state != DH_STATE_INIT_SENT) {
  ------------------
  |  Branch (513:13): [True: 2, False: 60]
  ------------------
  514|      2|            rc = SSH_PACKET_DENIED;
  515|      2|            break;
  516|      2|        }
  517|       |
  518|     60|        rc = SSH_PACKET_ALLOWED;
  519|     60|        break;
  520|      1|    case SSH2_MSG_KEX_DH_GEX_REQUEST:                 // 34
  ------------------
  |  |   26|      1|#define SSH2_MSG_KEX_DH_GEX_REQUEST 34
  ------------------
  |  Branch (520:5): [True: 1, False: 56.0k]
  ------------------
  521|       |
  522|       |        /* Server only */
  523|       |
  524|       |        /*
  525|       |         * States required:
  526|       |         * - session_state == SSH_SESSION_STATE_DH
  527|       |         * - dh_handshake_state == DH_STATE_INIT
  528|       |         *
  529|       |         * Transitions:
  530|       |         * - session->dh_handshake_state = DH_STATE_INIT_SENT
  531|       |         * then calls ssh_packet_server_dhgex_request which triggers:
  532|       |         * - session->dh_handshake_state = DH_STATE_GROUP_SENT
  533|       |         * */
  534|       |
  535|      1|        if (session->client) {
  ------------------
  |  Branch (535:13): [True: 1, False: 0]
  ------------------
  536|      1|            rc = SSH_PACKET_DENIED;
  537|      1|            break;
  538|      1|        }
  539|       |
  540|      0|        if (session->session_state != SSH_SESSION_STATE_DH) {
  ------------------
  |  Branch (540:13): [True: 0, False: 0]
  ------------------
  541|      0|            rc = SSH_PACKET_DENIED;
  542|      0|            break;
  543|      0|        }
  544|       |
  545|       |        /* Only allowed if dh_handshake_state is in initial state */
  546|      0|        if (session->dh_handshake_state != DH_STATE_INIT) {
  ------------------
  |  Branch (546:13): [True: 0, False: 0]
  ------------------
  547|      0|            rc = SSH_PACKET_DENIED;
  548|      0|            break;
  549|      0|        }
  550|       |
  551|      0|        rc = SSH_PACKET_ALLOWED;
  552|      0|        break;
  553|      1|    case SSH2_MSG_USERAUTH_REQUEST:                   // 50
  ------------------
  |  |   36|      1|#define SSH2_MSG_USERAUTH_REQUEST 50
  ------------------
  |  Branch (553:5): [True: 1, False: 56.0k]
  ------------------
  554|       |        /* Server only */
  555|       |
  556|       |        /*
  557|       |         * States required:
  558|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATING
  559|       |         * - dh_handshake_state == DH_STATE_FINISHED
  560|       |         *
  561|       |         * Transitions:
  562|       |         * - if authentication was successful:
  563|       |         *   - session_state = SSH_SESSION_STATE_AUTHENTICATED
  564|       |         * */
  565|       |
  566|       |        /* If this is a client, reject the message */
  567|      1|        if (session->client) {
  ------------------
  |  Branch (567:13): [True: 1, False: 0]
  ------------------
  568|      1|            rc = SSH_PACKET_DENIED;
  569|      1|            break;
  570|      1|        }
  571|       |
  572|      0|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (572:13): [True: 0, False: 0]
  ------------------
  573|      0|            rc = SSH_PACKET_DENIED;
  574|      0|            break;
  575|      0|        }
  576|       |
  577|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATING) {
  ------------------
  |  Branch (577:13): [True: 0, False: 0]
  ------------------
  578|      0|            rc = SSH_PACKET_DENIED;
  579|      0|            break;
  580|      0|        }
  581|       |
  582|      0|        rc = SSH_PACKET_ALLOWED;
  583|      0|        break;
  584|      1|    case SSH2_MSG_USERAUTH_FAILURE:                   // 51
  ------------------
  |  |   37|      1|#define SSH2_MSG_USERAUTH_FAILURE 51
  ------------------
  |  Branch (584:5): [True: 1, False: 56.0k]
  ------------------
  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|      1|        if (session->server) {
  ------------------
  |  Branch (605:13): [True: 0, False: 1]
  ------------------
  606|      0|            rc = SSH_PACKET_DENIED;
  607|      0|            break;
  608|      0|        }
  609|       |
  610|      1|        if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (610:13): [True: 1, False: 0]
  ------------------
  611|      1|            rc = SSH_PACKET_DENIED;
  612|      1|            break;
  613|      1|        }
  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: 56.0k]
  ------------------
  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: 56.0k]
  ------------------
  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: 56.0k]
  ------------------
  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: 56.0k]
  ------------------
  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|      2|    case SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE:  // 63
  ------------------
  |  |   46|      2|#define SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE 63
  ------------------
  |  Branch (753:5): [True: 2, False: 56.0k]
  ------------------
  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|      2|        rc = SSH_PACKET_DENIED;
  784|      2|        break;
  785|      0|#endif  /* WITH_GSSAPI */
  786|      1|    case SSH2_MSG_USERAUTH_GSSAPI_ERROR:              // 64
  ------------------
  |  |   47|      1|#define SSH2_MSG_USERAUTH_GSSAPI_ERROR 64
  ------------------
  |  Branch (786:5): [True: 1, False: 56.0k]
  ------------------
  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|      1|        rc = SSH_PACKET_DENIED;
  809|      1|        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: 56.0k]
  ------------------
  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|      1|    case SSH2_MSG_USERAUTH_GSSAPI_MIC:                // 66
  ------------------
  |  |   49|      1|#define SSH2_MSG_USERAUTH_GSSAPI_MIC 66
  ------------------
  |  Branch (831:5): [True: 1, False: 56.0k]
  ------------------
  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|      1|        rc = SSH_PACKET_DENIED;
  871|      1|        break;
  872|      0|#endif  /* WITH_GSSAPI */
  873|      2|    case SSH2_MSG_GLOBAL_REQUEST:                     // 80
  ------------------
  |  |   51|      2|#define SSH2_MSG_GLOBAL_REQUEST 80
  ------------------
  |  Branch (873:5): [True: 2, False: 56.0k]
  ------------------
  874|       |        /*
  875|       |         * States required:
  876|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  877|       |         *
  878|       |         * Transitions:
  879|       |         * - None
  880|       |         * */
  881|       |
  882|      2|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (882:13): [True: 2, False: 0]
  ------------------
  883|      2|            rc = SSH_PACKET_DENIED;
  884|      2|            break;
  885|      2|        }
  886|       |
  887|      0|        rc = SSH_PACKET_ALLOWED;
  888|      0|        break;
  889|      0|    case SSH2_MSG_REQUEST_SUCCESS:                    // 81
  ------------------
  |  |   52|      0|#define SSH2_MSG_REQUEST_SUCCESS 81
  ------------------
  |  Branch (889:5): [True: 0, False: 56.0k]
  ------------------
  890|       |        /*
  891|       |         * States required:
  892|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  893|       |         *
  894|       |         * Transitions:
  895|       |         * - From channel->request_state == SSH_CHANNEL_REQ_STATE_PENDING
  896|       |         * - To   channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED
  897|       |         *
  898|       |         * If not in a pending state, message is ignored in the callback handler.
  899|       |         * */
  900|       |
  901|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (901:13): [True: 0, False: 0]
  ------------------
  902|      0|            rc = SSH_PACKET_DENIED;
  903|      0|            break;
  904|      0|        }
  905|       |
  906|      0|        rc = SSH_PACKET_ALLOWED;
  907|      0|        break;
  908|      1|    case SSH2_MSG_REQUEST_FAILURE:                    // 82
  ------------------
  |  |   53|      1|#define SSH2_MSG_REQUEST_FAILURE 82
  ------------------
  |  Branch (908:5): [True: 1, False: 56.0k]
  ------------------
  909|       |        /*
  910|       |         * States required:
  911|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  912|       |         *
  913|       |         * Transitions:
  914|       |         * - From channel->request_state == SSH_CHANNEL_REQ_STATE_PENDING
  915|       |         * - To   channel->request_state = SSH_CHANNEL_REQ_STATE_ACCEPTED
  916|       |         *
  917|       |         * If not in a pending state, message is ignored in the callback handler.
  918|       |         * */
  919|       |
  920|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (920:13): [True: 1, False: 0]
  ------------------
  921|      1|            rc = SSH_PACKET_DENIED;
  922|      1|            break;
  923|      1|        }
  924|       |
  925|      0|        rc = SSH_PACKET_ALLOWED;
  926|      0|        break;
  927|      0|    case SSH2_MSG_CHANNEL_OPEN:                       // 90
  ------------------
  |  |   54|      0|#define SSH2_MSG_CHANNEL_OPEN 90
  ------------------
  |  Branch (927:5): [True: 0, False: 56.0k]
  ------------------
  928|       |        /*
  929|       |         * States required:
  930|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  931|       |         *
  932|       |         * Transitions:
  933|       |         * - None
  934|       |         * */
  935|       |
  936|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (936:13): [True: 0, False: 0]
  ------------------
  937|      0|            rc = SSH_PACKET_DENIED;
  938|      0|            break;
  939|      0|        }
  940|       |
  941|      0|        rc = SSH_PACKET_ALLOWED;
  942|      0|        break;
  943|      1|    case SSH2_MSG_CHANNEL_OPEN_CONFIRMATION:          // 91
  ------------------
  |  |   55|      1|#define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
  ------------------
  |  Branch (943:5): [True: 1, False: 56.0k]
  ------------------
  944|       |        /*
  945|       |         * States required:
  946|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  947|       |         *
  948|       |         * Transitions:
  949|       |         * - channel->state = SSH_CHANNEL_STATE_OPEN
  950|       |         * - channel->flags &= ~SSH_CHANNEL_FLAG_NOT_BOUND
  951|       |         * */
  952|       |
  953|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (953:13): [True: 1, False: 0]
  ------------------
  954|      1|            rc = SSH_PACKET_DENIED;
  955|      1|            break;
  956|      1|        }
  957|       |
  958|      0|        rc = SSH_PACKET_ALLOWED;
  959|      0|        break;
  960|      1|    case SSH2_MSG_CHANNEL_OPEN_FAILURE:               // 92
  ------------------
  |  |   56|      1|#define SSH2_MSG_CHANNEL_OPEN_FAILURE 92
  ------------------
  |  Branch (960:5): [True: 1, False: 56.0k]
  ------------------
  961|       |        /*
  962|       |         * States required:
  963|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  964|       |         *
  965|       |         * Transitions:
  966|       |         * - channel->state = SSH_CHANNEL_STATE_OPEN_DENIED
  967|       |         * */
  968|       |
  969|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (969:13): [True: 1, False: 0]
  ------------------
  970|      1|            rc = SSH_PACKET_DENIED;
  971|      1|            break;
  972|      1|        }
  973|       |
  974|      0|        rc = SSH_PACKET_ALLOWED;
  975|      0|        break;
  976|      0|    case SSH2_MSG_CHANNEL_WINDOW_ADJUST:              // 93
  ------------------
  |  |   57|      0|#define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93
  ------------------
  |  Branch (976:5): [True: 0, False: 56.0k]
  ------------------
  977|       |        /*
  978|       |         * States required:
  979|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  980|       |         *
  981|       |         * Transitions:
  982|       |         * - None
  983|       |         * */
  984|       |
  985|      0|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (985:13): [True: 0, False: 0]
  ------------------
  986|      0|            rc = SSH_PACKET_DENIED;
  987|      0|            break;
  988|      0|        }
  989|       |
  990|      0|        rc = SSH_PACKET_ALLOWED;
  991|      0|        break;
  992|      1|    case SSH2_MSG_CHANNEL_DATA:                       // 94
  ------------------
  |  |   58|      1|#define SSH2_MSG_CHANNEL_DATA 94
  ------------------
  |  Branch (992:5): [True: 1, False: 56.0k]
  ------------------
  993|       |        /*
  994|       |         * States required:
  995|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
  996|       |         *
  997|       |         * Transitions:
  998|       |         * - None
  999|       |         * */
 1000|       |
 1001|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1001:13): [True: 1, False: 0]
  ------------------
 1002|      1|            rc = SSH_PACKET_DENIED;
 1003|      1|            break;
 1004|      1|        }
 1005|       |
 1006|      0|        rc = SSH_PACKET_ALLOWED;
 1007|      0|        break;
 1008|      1|    case SSH2_MSG_CHANNEL_EXTENDED_DATA:              // 95
  ------------------
  |  |   59|      1|#define SSH2_MSG_CHANNEL_EXTENDED_DATA 95
  ------------------
  |  Branch (1008:5): [True: 1, False: 56.0k]
  ------------------
 1009|       |        /*
 1010|       |         * States required:
 1011|       |         * - session_state == SSH_SESSION_STATE_AUTHENTICATED
 1012|       |         *
 1013|       |         * Transitions:
 1014|       |         * - None
 1015|       |         * */
 1016|       |
 1017|      1|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1017:13): [True: 1, False: 0]
  ------------------
 1018|      1|            rc = SSH_PACKET_DENIED;
 1019|      1|            break;
 1020|      1|        }
 1021|       |
 1022|      0|        rc = SSH_PACKET_ALLOWED;
 1023|      0|        break;
 1024|      1|    case SSH2_MSG_CHANNEL_EOF:                        // 96
  ------------------
  |  |   60|      1|#define SSH2_MSG_CHANNEL_EOF	96
  ------------------
  |  Branch (1024:5): [True: 1, False: 56.0k]
  ------------------
 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|      2|    case SSH2_MSG_CHANNEL_CLOSE:                      // 97
  ------------------
  |  |   61|      2|#define SSH2_MSG_CHANNEL_CLOSE 97
  ------------------
  |  Branch (1040:5): [True: 2, False: 56.0k]
  ------------------
 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|      2|        if (session->session_state != SSH_SESSION_STATE_AUTHENTICATED) {
  ------------------
  |  Branch (1050:13): [True: 2, False: 0]
  ------------------
 1051|      2|            rc = SSH_PACKET_DENIED;
 1052|      2|            break;
 1053|      2|        }
 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: 56.0k]
  ------------------
 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: 56.0k]
  ------------------
 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: 56.0k]
  ------------------
 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|     32|    case SSH2_MSG_PING: // 192
  ------------------
  |  |   69|     32|#define SSH2_MSG_PING 192
  ------------------
  |  Branch (1111:5): [True: 32, False: 56.0k]
  ------------------
 1112|     33|    case SSH2_MSG_PONG: // 193
  ------------------
  |  |   70|     33|#define SSH2_MSG_PONG 193
  ------------------
  |  Branch (1112:5): [True: 1, False: 56.0k]
  ------------------
 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|     33|        rc = SSH_PACKET_ALLOWED;
 1128|     33|        break;
 1129|  31.1k|    default:
  ------------------
  |  Branch (1129:5): [True: 31.1k, False: 24.9k]
  ------------------
 1130|       |        /* Unknown message, do not filter */
 1131|  31.1k|        rc = SSH_PACKET_UNKNOWN;
 1132|  31.1k|        goto end;
 1133|  56.0k|    }
 1134|       |
 1135|  56.0k|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|  56.0k|    return rc;
 1149|  56.0k|}
packet.c:ssh_packet_need_rekey:
 1201|  89.2k|{
 1202|  89.2k|    bool data_rekey_needed = false;
 1203|  89.2k|    struct ssh_crypto_struct *crypto = NULL;
 1204|  89.2k|    struct ssh_cipher_struct *out_cipher = NULL, *in_cipher = NULL;
 1205|  89.2k|    uint32_t next_blocks;
 1206|       |
 1207|       |    /* We can safely rekey only in authenticated state */
 1208|  89.2k|    if ((session->flags & SSH_SESSION_FLAG_AUTHENTICATED) == 0) {
  ------------------
  |  |   78|  89.2k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (1208:9): [True: 89.2k, False: 0]
  ------------------
 1209|  89.2k|        return false;
 1210|  89.2k|    }
 1211|       |
 1212|       |    /* Do not rekey if the rekey/key-exchange is in progress */
 1213|      0|    if (session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (1213:9): [True: 0, False: 0]
  ------------------
 1214|      0|        return false;
 1215|      0|    }
 1216|       |
 1217|      0|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_BOTH);
 1218|      0|    if (crypto == NULL) {
  ------------------
  |  Branch (1218:9): [True: 0, False: 0]
  ------------------
 1219|      0|        return false;
 1220|      0|    }
 1221|       |
 1222|      0|    out_cipher = crypto->out_cipher;
 1223|      0|    in_cipher = crypto->in_cipher;
 1224|       |
 1225|       |    /* Make sure we can send at least something for very small limits */
 1226|      0|    if ((out_cipher->packets == 0) && (in_cipher->packets == 0)) {
  ------------------
  |  Branch (1226:9): [True: 0, False: 0]
  |  Branch (1226:39): [True: 0, False: 0]
  ------------------
 1227|      0|        return false;
 1228|      0|    }
 1229|       |
 1230|       |    /* Time based rekeying */
 1231|      0|    if (session->opts.rekey_time != 0 &&
  ------------------
  |  Branch (1231:9): [True: 0, False: 0]
  ------------------
 1232|      0|        ssh_timeout_elapsed(&session->last_rekey_time,
  ------------------
  |  Branch (1232:9): [True: 0, False: 0]
  ------------------
 1233|      0|                            session->opts.rekey_time)) {
 1234|      0|        return true;
 1235|      0|    }
 1236|       |
 1237|       |    /* RFC4344, Section 3.1 Recommends rekeying after 2^31 packets in either
 1238|       |     * direction to avoid possible information leakage through the MAC tag
 1239|       |     */
 1240|      0|    if (out_cipher->packets > MAX_PACKETS ||
  ------------------
  |  | 1197|      0|#define MAX_PACKETS    (1UL<<31)
  ------------------
  |  Branch (1240:9): [True: 0, False: 0]
  ------------------
 1241|      0|        in_cipher->packets > MAX_PACKETS) {
  ------------------
  |  | 1197|      0|#define MAX_PACKETS    (1UL<<31)
  ------------------
  |  Branch (1241:9): [True: 0, False: 0]
  ------------------
 1242|      0|        return true;
 1243|      0|    }
 1244|       |
 1245|       |    /* Data-based rekeying:
 1246|       |     *  * For outgoing packets we can still delay them
 1247|       |     *  * Incoming packets need to be processed anyway, but we can
 1248|       |     *    signalize our intention to rekey
 1249|       |     */
 1250|      0|    next_blocks = payloadsize / out_cipher->blocksize;
 1251|      0|    data_rekey_needed = (out_cipher->max_blocks != 0 &&
  ------------------
  |  Branch (1251:26): [True: 0, False: 0]
  ------------------
 1252|      0|                         out_cipher->blocks + next_blocks > out_cipher->max_blocks) ||
  ------------------
  |  Branch (1252:26): [True: 0, False: 0]
  ------------------
 1253|      0|                         (in_cipher->max_blocks != 0 &&
  ------------------
  |  Branch (1253:27): [True: 0, False: 0]
  ------------------
 1254|      0|                         in_cipher->blocks + next_blocks > in_cipher->max_blocks);
  ------------------
  |  Branch (1254:26): [True: 0, False: 0]
  ------------------
 1255|       |
 1256|      0|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  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|    466|{
 1654|    466|    ssh_session session = userdata;
 1655|    466|    struct ssh_iterator *it = NULL;
 1656|    466|    ssh_channel channel = NULL;
 1657|       |
 1658|    466|    if (code == SSH_SOCKET_FLOW_WRITEWONTBLOCK) {
  ------------------
  |  |  518|    466|#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
  ------------------
  |  Branch (1658:9): [True: 466, False: 0]
  ------------------
 1659|    466|        SSH_LOG(SSH_LOG_TRACE, "sending channel_write_wontblock callback");
  ------------------
  |  |  281|    466|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 1660|       |
 1661|       |        /* the out pipe is empty so we can forward this to channels */
 1662|    466|        it = ssh_list_get_iterator(session->channels);
 1663|    466|        while (it != NULL) {
  ------------------
  |  Branch (1663:16): [True: 0, False: 466]
  ------------------
 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|    466|    }
 1674|    466|}
packet.c:ssh_packet_in_rekey:
 2054|  33.1k|{
 2055|       |    /* We know we are rekeying if we are authenticated and the DH
 2056|       |     * status is not finished, but we only queue packets until we've
 2057|       |     * sent our NEWKEYS.
 2058|       |     */
 2059|  33.1k|    return (session->flags & SSH_SESSION_FLAG_AUTHENTICATED) &&
  ------------------
  |  |   78|  33.1k|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (2059:12): [True: 0, False: 33.1k]
  ------------------
 2060|      0|           (session->dh_handshake_state != DH_STATE_FINISHED) &&
  ------------------
  |  Branch (2060:12): [True: 0, False: 0]
  ------------------
 2061|      0|           (session->dh_handshake_state != DH_STATE_NEWKEYS_SENT);
  ------------------
  |  Branch (2061:12): [True: 0, False: 0]
  ------------------
 2062|  33.1k|}
packet.c:packet_send2:
 1894|  33.1k|{
 1895|  33.1k|    unsigned int blocksize = 8;
 1896|  33.1k|    unsigned int lenfield_blocksize = 0;
 1897|  33.1k|    enum ssh_hmac_e hmac_type;
 1898|  33.1k|    uint32_t currentlen = ssh_buffer_get_len(session->out_buffer);
 1899|  33.1k|    struct ssh_crypto_struct *crypto = NULL;
 1900|  33.1k|    unsigned char *hmac = NULL;
 1901|  33.1k|    uint8_t padding_data[32] = { 0 };
 1902|  33.1k|    uint8_t padding_size;
 1903|  33.1k|    uint32_t finallen, payloadsize, compsize;
 1904|  33.1k|    uint8_t header[5] = {0};
 1905|  33.1k|    uint8_t type, *payload;
 1906|  33.1k|    int rc = SSH_ERROR;
  ------------------
  |  |  317|  33.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1907|  33.1k|    bool etm = false;
 1908|  33.1k|    int etm_packet_offset = 0;
 1909|       |
 1910|  33.1k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
 1911|  33.1k|    if (crypto) {
  ------------------
  |  Branch (1911:9): [True: 8.55k, False: 24.6k]
  ------------------
 1912|  8.55k|        blocksize = crypto->out_cipher->blocksize;
 1913|  8.55k|        lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
 1914|  8.55k|        hmac_type = crypto->out_hmac;
 1915|  8.55k|        etm = crypto->out_hmac_etm;
 1916|  24.6k|    } else {
 1917|  24.6k|        hmac_type = session->next_crypto->out_hmac;
 1918|  24.6k|    }
 1919|       |
 1920|  33.1k|    payload = (uint8_t *)ssh_buffer_get(session->out_buffer);
 1921|  33.1k|    type = payload[0]; /* type is the first byte of the packet now */
 1922|       |
 1923|  33.1k|    payloadsize = currentlen;
 1924|  33.1k|    if (etm) {
  ------------------
  |  Branch (1924:9): [True: 0, False: 33.1k]
  ------------------
 1925|      0|        etm_packet_offset = sizeof(uint32_t);
 1926|      0|        lenfield_blocksize = 0;
 1927|      0|    }
 1928|       |
 1929|  33.1k|    if (crypto != NULL && crypto->do_compress_out &&
  ------------------
  |  Branch (1929:9): [True: 8.55k, False: 24.6k]
  |  Branch (1929:27): [True: 0, False: 8.55k]
  ------------------
 1930|      0|        ssh_buffer_get_len(session->out_buffer) > 0) {
  ------------------
  |  Branch (1930:9): [True: 0, False: 0]
  ------------------
 1931|      0|        rc = compress_buffer(session,session->out_buffer);
 1932|      0|        if (rc < 0) {
  ------------------
  |  Branch (1932:13): [True: 0, False: 0]
  ------------------
 1933|      0|            goto error;
 1934|      0|        }
 1935|      0|        currentlen = ssh_buffer_get_len(session->out_buffer);
 1936|      0|    }
 1937|  33.1k|    compsize = currentlen;
 1938|       |    /* compressed payload + packet len (4) + padding_size len (1) */
 1939|       |    /* totallen - lenfield_blocksize - etm_packet_offset must be equal to 0 (mod blocksize) */
 1940|  33.1k|    padding_size = (blocksize - ((blocksize - lenfield_blocksize - etm_packet_offset + currentlen + 5) % blocksize));
 1941|  33.1k|    if (padding_size < 4) {
  ------------------
  |  Branch (1941:9): [True: 82, False: 33.0k]
  ------------------
 1942|     82|        padding_size += blocksize;
 1943|     82|    }
 1944|       |
 1945|  33.1k|    if (crypto != NULL) {
  ------------------
  |  Branch (1945:9): [True: 8.55k, False: 24.6k]
  ------------------
 1946|  8.55k|        int ok;
 1947|       |
 1948|  8.55k|        ok = ssh_get_random(padding_data, padding_size, 0);
 1949|  8.55k|        if (!ok) {
  ------------------
  |  Branch (1949:13): [True: 0, False: 8.55k]
  ------------------
 1950|      0|            ssh_set_error(session, SSH_FATAL, "PRNG error");
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
 1951|      0|            goto error;
 1952|      0|        }
 1953|  8.55k|    }
 1954|       |
 1955|  33.1k|    finallen = currentlen - etm_packet_offset + padding_size + 1;
 1956|       |
 1957|  33.1k|    PUSH_BE_U32(header, 0, finallen);
  ------------------
  |  |   89|  33.1k|    (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|  33.1k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  33.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  33.1k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  33.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  33.1k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   (PUSH_BE_U16((data), (pos), (uint16_t)(((uint32_t)(val)) >> 16)), PUSH_BE_U16((data), (pos) + 2, (uint16_t)((val) & 0xffff)))
  |  |  ------------------
  |  |  |  |   86|  33.1k|    (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  33.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  33.1k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |                   (PUSH_BE_U8((data), (pos), (uint8_t)(((uint16_t)(val)) >> 8)), PUSH_BE_U8((data), (pos) + 1, (uint8_t)((val) & 0xff)))
  |  |  |  |  ------------------
  |  |  |  |  |  |   83|  33.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   31|  33.1k|    (((uint8_t *)(data))[(pos)])
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1958|  33.1k|    PUSH_BE_U8(header, 4, padding_size);
  ------------------
  |  |   83|  33.1k|    (_DATA_BYTE(data, pos) = ((uint8_t)(val)))
  |  |  ------------------
  |  |  |  |   31|  33.1k|    (((uint8_t *)(data))[(pos)])
  |  |  ------------------
  ------------------
 1959|       |
 1960|  33.1k|    rc = ssh_buffer_prepend_data(session->out_buffer,
 1961|  33.1k|                                 header,
 1962|  33.1k|                                 sizeof(header));
 1963|  33.1k|    if (rc < 0) {
  ------------------
  |  Branch (1963:9): [True: 0, False: 33.1k]
  ------------------
 1964|      0|        goto error;
 1965|      0|    }
 1966|       |
 1967|  33.1k|    rc = ssh_buffer_add_data(session->out_buffer, padding_data, padding_size);
 1968|  33.1k|    if (rc < 0) {
  ------------------
  |  Branch (1968:9): [True: 0, False: 33.1k]
  ------------------
 1969|      0|        goto error;
 1970|      0|    }
 1971|       |
 1972|  33.1k|#ifdef WITH_PCAP
 1973|  33.1k|    if (session->pcap_ctx != NULL) {
  ------------------
  |  Branch (1973:9): [True: 0, False: 33.1k]
  ------------------
 1974|      0|        ssh_pcap_context_write(session->pcap_ctx,
 1975|      0|                               SSH_PCAP_DIR_OUT,
 1976|      0|                               ssh_buffer_get(session->out_buffer),
 1977|      0|                               ssh_buffer_get_len(session->out_buffer),
 1978|      0|                               ssh_buffer_get_len(session->out_buffer));
 1979|      0|    }
 1980|  33.1k|#endif
 1981|       |
 1982|  33.1k|    hmac = ssh_packet_encrypt(session,
 1983|  33.1k|                              ssh_buffer_get(session->out_buffer),
 1984|  33.1k|                              ssh_buffer_get_len(session->out_buffer));
 1985|       |    /* XXX This returns null before switching on crypto, with none MAC
 1986|       |     * and on various errors.
 1987|       |     * We should distinguish between these cases to avoid hiding errors. */
 1988|  33.1k|    if (hmac != NULL) {
  ------------------
  |  Branch (1988:9): [True: 8.55k, False: 24.6k]
  ------------------
 1989|  8.55k|        rc = ssh_buffer_add_data(session->out_buffer,
 1990|  8.55k|                                 hmac,
 1991|  8.55k|                                 (uint32_t)hmac_digest_len(hmac_type));
 1992|  8.55k|        if (rc < 0) {
  ------------------
  |  Branch (1992:13): [True: 0, False: 8.55k]
  ------------------
 1993|      0|            goto error;
 1994|      0|        }
 1995|  8.55k|    }
 1996|       |
 1997|  33.1k|    rc = ssh_packet_write(session);
 1998|  33.1k|    if (rc == SSH_ERROR) {
  ------------------
  |  |  317|  33.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1998:9): [True: 0, False: 33.1k]
  ------------------
 1999|      0|        goto error;
 2000|      0|    }
 2001|  33.1k|    session->send_seq++;
 2002|  33.1k|    if (crypto != NULL) {
  ------------------
  |  Branch (2002:9): [True: 8.55k, False: 24.6k]
  ------------------
 2003|  8.55k|        struct ssh_cipher_struct *cipher = NULL;
 2004|       |
 2005|  8.55k|        cipher = crypto->out_cipher;
 2006|  8.55k|        cipher->packets++;
 2007|  8.55k|        cipher->blocks += payloadsize / cipher->blocksize;
 2008|  8.55k|    }
 2009|  33.1k|    if (session->raw_counter != NULL) {
  ------------------
  |  Branch (2009:9): [True: 0, False: 33.1k]
  ------------------
 2010|      0|        session->raw_counter->out_bytes += payloadsize;
 2011|      0|        session->raw_counter->out_packets++;
 2012|      0|    }
 2013|       |
 2014|  33.1k|    SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|  33.1k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2015|  33.1k|            "packet: wrote [type=%u, len=%" PRIu32 ", padding_size=%hhd, comp=%" PRIu32 ", "
 2016|  33.1k|            "payload=%" PRIu32 "]",
 2017|  33.1k|            type,
 2018|  33.1k|            finallen,
 2019|  33.1k|            padding_size,
 2020|  33.1k|            compsize,
 2021|  33.1k|            payloadsize);
 2022|       |
 2023|  33.1k|    rc = ssh_buffer_reinit(session->out_buffer);
 2024|  33.1k|    if (rc < 0) {
  ------------------
  |  Branch (2024:9): [True: 0, False: 33.1k]
  ------------------
 2025|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2026|      0|        goto error;
 2027|      0|    }
 2028|       |
 2029|       |    /* We sent the NEWKEYS so any further packet needs to be encrypted
 2030|       |     * with the new keys. We can not switch both directions (need to decrypt
 2031|       |     * peer NEWKEYS) and we do not want to wait for the peer NEWKEYS
 2032|       |     * too, so we will switch only the OUT direction now.
 2033|       |     */
 2034|  33.1k|    if (type == SSH2_MSG_NEWKEYS) {
  ------------------
  |  |   13|  33.1k|#define SSH2_MSG_NEWKEYS 21
  ------------------
  |  Branch (2034:9): [True: 71, False: 33.1k]
  ------------------
 2035|     71|        rc = ssh_packet_set_newkeys(session, SSH_DIRECTION_OUT);
 2036|     71|    }
 2037|  33.1k|error:
 2038|  33.1k|    return rc; /* SSH_OK, AGAIN or ERROR */
 2039|  33.1k|}
packet.c:ssh_packet_write:
 1883|  33.1k|static int ssh_packet_write(ssh_session session) {
 1884|  33.1k|  int rc = SSH_ERROR;
  ------------------
  |  |  317|  33.1k|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1885|       |
 1886|  33.1k|  rc=ssh_socket_write(session->socket,
 1887|  33.1k|      ssh_buffer_get(session->out_buffer),
 1888|  33.1k|      ssh_buffer_get_len(session->out_buffer));
 1889|       |
 1890|  33.1k|  return rc;
 1891|  33.1k|}
packet.c:ssh_init_rekey_state:
 2239|    142|{
 2240|       |    /* Reset the counters: should be NOOP */
 2241|    142|    cipher->packets = 0;
 2242|    142|    cipher->blocks = 0;
 2243|       |
 2244|       |    /* Default rekey limits for ciphers as specified in RFC4344, Section 3.2 */
 2245|    142|    if (cipher->blocksize >= 16) {
  ------------------
  |  Branch (2245:9): [True: 0, False: 142]
  ------------------
 2246|       |        /* For larger block size (L bits) use maximum of 2**(L/4) blocks */
 2247|      0|        cipher->max_blocks = (uint64_t)1 << (cipher->blocksize*2);
 2248|    142|    } else {
 2249|       |        /* For smaller blocks use limit of 1 GB as recommended in RFC4253 */
 2250|    142|        cipher->max_blocks = ((uint64_t)1 << 30) / cipher->blocksize;
 2251|    142|    }
 2252|       |    /* If we have limit provided by user, use the smaller one */
 2253|    142|    if (session->opts.rekey_data != 0) {
  ------------------
  |  Branch (2253:9): [True: 0, False: 142]
  ------------------
 2254|      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]
  |  |  ------------------
  ------------------
 2255|      0|                                 session->opts.rekey_data / cipher->blocksize);
 2256|      0|    }
 2257|       |
 2258|    142|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|    142|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2259|    142|            "Set rekey after %" PRIu64 " blocks",
 2260|    142|            cipher->max_blocks);
 2261|    142|}

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);
  ------------------
  |  |  893|      2|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 2, False: 0]
  |  |  |  Branch (893: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|    373|{
  103|    373|    (void)session; /* unused */
  104|    373|    (void)user;
  105|    373|    (void)type;
  106|    373|    (void)packet;
  107|       |
  108|    373|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_IGNORE packet");
  ------------------
  |  |  281|    373|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  109|       |
  110|    373|    return SSH_PACKET_USED;
  ------------------
  |  |  637|    373|#define SSH_PACKET_USED 1
  ------------------
  111|    373|}
ssh_packet_debug_callback:
  119|  22.4k|{
  120|  22.4k|    uint8_t always_display = -1;
  121|  22.4k|    char *message = NULL;
  122|  22.4k|    int rc;
  123|       |
  124|  22.4k|    (void)session; /* unused */
  125|  22.4k|    (void)type;
  126|  22.4k|    (void)user;
  127|       |
  128|  22.4k|    rc = ssh_buffer_unpack(packet, "bs", &always_display, &message);
  ------------------
  |  |   60|  22.4k|    _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |  451|  22.4k|        (__VA_NARG_(__VA_ARGS__, __RSEQ_N()))
  |  |  |  |  ------------------
  |  |  |  |  |  |  453|  22.4k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  448|  22.4k|#define VA_APPLY_VARIADIC_MACRO(macro, tuple) macro tuple
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  453|  22.4k|        VA_APPLY_VARIADIC_MACRO(__VA_ARG_N, (__VA_ARGS__))
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |  |  |  461|  22.4k|        _61,_62,_63,N,...) N
  |  |  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                   _ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
  |  |  ------------------
  |  |  |  |   28|  22.4k|#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
  |  |  ------------------
  ------------------
  129|  22.4k|    if (rc != SSH_OK) {
  ------------------
  |  |  316|  22.4k|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (129:9): [True: 18.2k, False: 4.18k]
  ------------------
  130|  18.2k|        SSH_LOG(SSH_LOG_PACKET, "Error reading debug message");
  ------------------
  |  |  281|  18.2k|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  131|  18.2k|        return SSH_PACKET_USED;
  ------------------
  |  |  637|  18.2k|#define SSH_PACKET_USED 1
  ------------------
  132|  18.2k|    }
  133|  4.18k|    SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|  8.36k|    _ssh_log(priority, __func__, __VA_ARGS__)
  |  |  ------------------
  |  |  |  Branch (281:34): [True: 4.17k, False: 7]
  |  |  ------------------
  ------------------
  134|  4.18k|            "Received SSH_MSG_DEBUG packet with message %s%s",
  135|  4.18k|            message,
  136|  4.18k|            always_display != 0 ? " (always display)" : "");
  137|  4.18k|    SAFE_FREE(message);
  ------------------
  |  |  373|  4.18k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 4.18k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 4.18k]
  |  |  ------------------
  ------------------
  138|       |
  139|  4.18k|    return SSH_PACKET_USED;
  ------------------
  |  |  637|  4.18k|#define SSH_PACKET_USED 1
  ------------------
  140|  22.4k|}
ssh_packet_newkeys:
  143|     34|{
  144|     34|    ssh_string sig_blob = NULL;
  145|     34|    ssh_signature sig = NULL;
  146|     34|    int rc;
  147|       |
  148|     34|    (void)packet;
  149|     34|    (void)user;
  150|     34|    (void)type;
  151|       |
  152|     34|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH_MSG_NEWKEYS");
  ------------------
  |  |  281|     34|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  153|       |
  154|     34|    if (session->session_state != SSH_SESSION_STATE_DH ||
  ------------------
  |  Branch (154:9): [True: 0, False: 34]
  ------------------
  155|     34|        session->dh_handshake_state != DH_STATE_NEWKEYS_SENT) {
  ------------------
  |  Branch (155:9): [True: 0, False: 34]
  ------------------
  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|     34|    if (session->flags & SSH_SESSION_FLAG_KEX_STRICT) {
  ------------------
  |  |   90|     34|#define SSH_SESSION_FLAG_KEX_STRICT 0x0010
  ------------------
  |  Branch (164:9): [True: 3, False: 31]
  ------------------
  165|       |        /* reset packet sequence number when running in strict kex mode */
  166|      3|        session->recv_seq = 0;
  167|       |        /* Check that we aren't tainted */
  168|      3|        if (session->flags & SSH_SESSION_FLAG_KEX_TAINTED) {
  ------------------
  |  |   92|      3|#define SSH_SESSION_FLAG_KEX_TAINTED 0x0020
  ------------------
  |  Branch (168:13): [True: 1, False: 2]
  ------------------
  169|      1|            ssh_set_error(session,
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  170|      1|                          SSH_FATAL,
  171|      1|                          "Received unexpected packets in strict KEX mode.");
  172|      1|            goto error;
  173|      1|        }
  174|      3|    }
  175|       |
  176|     33|    if (session->server) {
  ------------------
  |  Branch (176:9): [True: 0, False: 33]
  ------------------
  177|       |        /* server things are done in server.c */
  178|      0|        session->dh_handshake_state=DH_STATE_FINISHED;
  179|     33|    } 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|     33|        {
  218|     33|            ssh_key server_key = NULL;
  219|       |
  220|       |            /* client */
  221|       |
  222|       |            /* Verify the host's signature. FIXME do it sooner */
  223|     33|            sig_blob = session->next_crypto->dh_server_signature;
  224|     33|            session->next_crypto->dh_server_signature = NULL;
  225|       |
  226|       |            /* get the server public key */
  227|     33|            server_key = ssh_dh_get_next_server_publickey(session);
  228|     33|            if (server_key == NULL) {
  ------------------
  |  Branch (228:17): [True: 0, False: 33]
  ------------------
  229|      0|                goto error;
  230|      0|            }
  231|       |
  232|     33|            rc = ssh_pki_import_signature_blob(sig_blob, server_key, &sig);
  233|     33|            ssh_string_burn(sig_blob);
  234|     33|            SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  893|     33|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 33, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 33]
  |  |  ------------------
  ------------------
  235|     33|            if (rc != SSH_OK) {
  ------------------
  |  |  316|     33|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (235:17): [True: 26, False: 7]
  ------------------
  236|     26|                goto error;
  237|     26|            }
  238|       |
  239|       |            /* Check if signature from server matches user preferences */
  240|      7|            if (session->opts.wanted_methods[SSH_HOSTKEYS]) {
  ------------------
  |  Branch (240:17): [True: 0, False: 7]
  ------------------
  241|      0|                rc = match_group(session->opts.wanted_methods[SSH_HOSTKEYS],
  242|      0|                                 sig->type_c);
  243|      0|                if (rc == 0) {
  ------------------
  |  Branch (243:21): [True: 0, False: 0]
  ------------------
  244|      0|                    ssh_set_error(
  ------------------
  |  |  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|      7|            rc = ssh_pki_signature_verify(session,
  256|      7|                                          sig,
  257|      7|                                          server_key,
  258|      7|                                          session->next_crypto->secret_hash,
  259|      7|                                          session->next_crypto->digest_len);
  260|      7|            SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|      7|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 7]
  |  |  ------------------
  ------------------
  261|      7|            if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      7|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (261:17): [True: 7, False: 0]
  ------------------
  262|      7|                ssh_set_error(session,
  ------------------
  |  |  311|      7|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  263|      7|                              SSH_FATAL,
  264|      7|                              "Failed to verify server hostkey signature");
  265|      7|                goto error;
  266|      7|            }
  267|      7|        }
  268|      0|        SSH_LOG(SSH_LOG_DEBUG, "Signature verified and valid");
  ------------------
  |  |  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|     34|error:
  281|       |#ifdef WITH_GSSAPI
  282|       |    SSH_STRING_FREE(session->gssapi_key_exchange_mic);
  283|       |#endif
  284|     34|    SSH_SIGNATURE_FREE(sig);
  ------------------
  |  |  161|     34|    do { ssh_signature_free(x); x = NULL; } while(0)
  |  |  ------------------
  |  |  |  Branch (161:51): [Folded, False: 34]
  |  |  ------------------
  ------------------
  285|     34|    ssh_string_burn(sig_blob);
  286|     34|    SSH_STRING_FREE(sig_blob);
  ------------------
  |  |  893|     34|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 34]
  |  |  |  Branch (893:69): [Folded, False: 34]
  |  |  ------------------
  ------------------
  287|     34|    session->session_state = SSH_SESSION_STATE_ERROR;
  288|     34|    return SSH_PACKET_USED;
  ------------------
  |  |  637|     34|#define SSH_PACKET_USED 1
  ------------------
  289|     33|}
ssh_packet_ping:
  388|     32|{
  389|     32|    int rc;
  390|     32|    ssh_string payload = NULL;
  391|       |
  392|     32|    (void)type;
  393|     32|    (void)user;
  394|       |
  395|     32|    SSH_LOG(SSH_LOG_PACKET, "Received SSH2_MSG_PING");
  ------------------
  |  |  281|     32|    _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|     32|    if (!(session->flags & SSH_SESSION_FLAG_AUTHENTICATED) &&
  ------------------
  |  |   78|     32|#define SSH_SESSION_FLAG_AUTHENTICATED 0x0002
  ------------------
  |  Branch (400:9): [True: 32, False: 0]
  ------------------
  401|     32|        session->dh_handshake_state != DH_STATE_FINISHED) {
  ------------------
  |  Branch (401:9): [True: 32, False: 0]
  ------------------
  402|     32|        SSH_LOG(SSH_LOG_DEBUG,
  ------------------
  |  |  281|     32|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  403|     32|                "Ignoring PING before initial key exchange is complete");
  404|     32|        return SSH_PACKET_USED;
  ------------------
  |  |  637|     32|#define SSH_PACKET_USED 1
  ------------------
  405|     32|    }
  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);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893: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);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893: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_pong:
  454|      1|{
  455|      1|    const void *payload_data = NULL;
  456|      1|    ssh_string payload = NULL;
  457|      1|    size_t payload_len = 0;
  458|       |
  459|      1|    (void)type;
  460|      1|    (void)user;
  461|       |
  462|      1|    SSH_LOG(SSH_LOG_DEBUG, "Received SSH2_MSG_PONG");
  ------------------
  |  |  281|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  463|       |
  464|      1|    if (session->pending_pings == 0) {
  ------------------
  |  Branch (464:9): [True: 1, False: 0]
  ------------------
  465|      1|        SSH_LOG(SSH_LOG_PACKET, "Received unsolicited SSH2_MSG_PONG");
  ------------------
  |  |  281|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  466|      1|        ssh_set_error(session, SSH_FATAL, "Received unsolicited SSH2_MSG_PONG");
  ------------------
  |  |  311|      1|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  467|      1|        session->session_state = SSH_SESSION_STATE_ERROR;
  468|      1|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      1|#define SSH_PACKET_USED 1
  ------------------
  469|      1|    }
  470|       |
  471|      0|    payload = ssh_buffer_get_ssh_string(packet);
  472|      0|    if (payload == NULL) {
  ------------------
  |  Branch (472:9): [True: 0, False: 0]
  ------------------
  473|      0|        SSH_LOG(SSH_LOG_PACKET, "SSH2_MSG_PONG: missing string payload");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  474|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  475|      0|                      SSH_FATAL,
  476|      0|                      "SSH2_MSG_PONG: missing string payload");
  477|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  478|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  479|      0|    }
  480|       |
  481|      0|    if (ssh_buffer_get_len(packet) != 0) {
  ------------------
  |  Branch (481:9): [True: 0, False: 0]
  ------------------
  482|      0|        SSH_LOG(SSH_LOG_PACKET,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
  483|      0|                "SSH2_MSG_PONG: unexpected trailing data after payload");
  484|      0|        ssh_set_error(session,
  ------------------
  |  |  311|      0|    _ssh_set_error(error, code, __func__, __VA_ARGS__)
  ------------------
  485|      0|                      SSH_FATAL,
  486|      0|                      "SSH2_MSG_PONG: unexpected trailing data after payload");
  487|      0|        session->session_state = SSH_SESSION_STATE_ERROR;
  488|      0|        SSH_STRING_FREE(payload);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  489|      0|        return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  490|      0|    }
  491|       |
  492|      0|    payload_data = ssh_string_data(payload);
  493|      0|    payload_len = ssh_string_len(payload);
  494|       |
  495|       |    /* If user provided a high-level PONG callback, decode and invoke it. */
  496|      0|    if (ssh_callbacks_exists(session->common.callbacks, pong_function)) {
  ------------------
  |  |  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|  )
  ------------------
  497|      0|        session->common.callbacks->pong_function(
  498|      0|            session,
  499|      0|            payload_data,
  500|      0|            payload_len,
  501|      0|            session->common.callbacks->userdata);
  502|      0|    }
  503|       |
  504|      0|    SSH_STRING_FREE(payload);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
  505|      0|    session->pending_pings--;
  506|       |
  507|      0|    return SSH_PACKET_USED;
  ------------------
  |  |  637|      0|#define SSH_PACKET_USED 1
  ------------------
  508|      0|}

ssh_packet_decrypt_len:
   55|  56.2k|{
   56|  56.2k|    struct ssh_crypto_struct *crypto = NULL;
   57|  56.2k|    uint32_t decrypted;
   58|  56.2k|    int rc;
   59|       |
   60|  56.2k|    crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_IN);
   61|  56.2k|    if (crypto != NULL) {
  ------------------
  |  Branch (61:9): [True: 0, False: 56.2k]
  ------------------
   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|  56.2k|    } else {
   79|  56.2k|        memcpy(destination, source, 8);
   80|  56.2k|    }
   81|  56.2k|    memcpy(&decrypted,destination,sizeof(decrypted));
   82|       |
   83|       |    return ntohl(decrypted);
   84|  56.2k|}
ssh_packet_encrypt:
  134|  33.1k|{
  135|  33.1k|  struct ssh_crypto_struct *crypto = NULL;
  136|  33.1k|  struct ssh_cipher_struct *cipher = NULL;
  137|  33.1k|  HMACCTX ctx = NULL;
  138|  33.1k|  char *out = NULL;
  139|  33.1k|  int etm_packet_offset = 0, rc;
  140|  33.1k|  unsigned int blocksize;
  141|  33.1k|  size_t finallen = DIGEST_MAX_LEN;
  ------------------
  |  |   56|  33.1k|#define DIGEST_MAX_LEN 64
  ------------------
  142|  33.1k|  uint32_t seq, lenfield_blocksize;
  143|  33.1k|  enum ssh_hmac_e type;
  144|  33.1k|  bool etm;
  145|       |
  146|  33.1k|  assert(len);
  ------------------
  |  Branch (146:3): [True: 0, False: 33.1k]
  |  Branch (146:3): [True: 33.1k, False: 0]
  ------------------
  147|       |
  148|  33.1k|  crypto = ssh_packet_get_current_crypto(session, SSH_DIRECTION_OUT);
  149|  33.1k|  if (crypto == NULL) {
  ------------------
  |  Branch (149:7): [True: 24.6k, False: 8.55k]
  ------------------
  150|  24.6k|      return NULL; /* nothing to do here */
  151|  24.6k|  }
  152|       |
  153|  8.55k|  blocksize = crypto->out_cipher->blocksize;
  154|  8.55k|  lenfield_blocksize = crypto->out_cipher->lenfield_blocksize;
  155|       |
  156|  8.55k|  type = crypto->out_hmac;
  157|  8.55k|  etm = crypto->out_hmac_etm;
  158|       |
  159|  8.55k|  if (etm) {
  ------------------
  |  Branch (159:7): [True: 0, False: 8.55k]
  ------------------
  160|      0|      etm_packet_offset = sizeof(uint32_t);
  161|      0|  }
  162|       |
  163|  8.55k|  if ((len - lenfield_blocksize - etm_packet_offset) % blocksize != 0) {
  ------------------
  |  Branch (163:7): [True: 0, False: 8.55k]
  ------------------
  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|  8.55k|  out = calloc(1, len);
  169|  8.55k|  if (out == NULL) {
  ------------------
  |  Branch (169:7): [True: 0, False: 8.55k]
  ------------------
  170|      0|    return NULL;
  171|      0|  }
  172|       |
  173|  8.55k|  seq = ntohl(session->send_seq);
  174|  8.55k|  cipher = crypto->out_cipher;
  175|       |
  176|  8.55k|  if (cipher->aead_encrypt != NULL) {
  ------------------
  |  Branch (176:7): [True: 0, False: 8.55k]
  ------------------
  177|      0|      cipher->aead_encrypt(cipher, data, out, len,
  178|      0|            crypto->hmacbuf, session->send_seq);
  179|      0|      memcpy(data, out, len);
  180|  8.55k|  } else {
  181|  8.55k|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (181:11): [True: 0, False: 8.55k]
  ------------------
  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|  8.55k|      cipher->encrypt(cipher, (uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  208|  8.55k|      memcpy((uint8_t*)data + etm_packet_offset, out, len - etm_packet_offset);
  209|       |
  210|  8.55k|      if (type != SSH_HMAC_NONE) {
  ------------------
  |  Branch (210:11): [True: 0, False: 8.55k]
  ------------------
  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|  8.55k|  }
  238|  8.55k|  ssh_burn(out, len);
  ------------------
  |  |  388|  8.55k|#define ssh_burn(ptr, len) explicit_bzero((ptr), (len))
  ------------------
  239|  8.55k|  SAFE_FREE(out);
  ------------------
  |  |  373|  8.55k|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 8.55k, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 8.55k]
  |  |  ------------------
  ------------------
  240|       |
  241|  8.55k|  return crypto->hmacbuf;
  242|  8.55k|}

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

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

pki_key_clean:
   96|     92|{
   97|     92|    if (key == NULL)
  ------------------
  |  Branch (97:9): [True: 0, False: 92]
  ------------------
   98|      0|        return;
   99|     92|    EVP_PKEY_free(key->key);
  100|       |    key->key = NULL;
  101|     92|}
pki_pubkey_build_ed25519:
  444|      6|{
  445|      6|    EVP_PKEY *pkey = NULL;
  446|       |
  447|      6|    if (ssh_string_len(pubkey) != ED25519_KEY_LEN) {
  ------------------
  |  |   44|      6|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (447:9): [True: 0, False: 6]
  ------------------
  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|      6|    if (ssh_fips_mode()) {
  ------------------
  |  |  115|      6|#define ssh_fips_mode() (FIPS_mode() != 0)
  |  |  ------------------
  |  |  |  Branch (115:25): [True: 0, False: 6]
  |  |  ------------------
  ------------------
  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|      6|    pkey = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519,
  468|      6|                                       NULL,
  469|      6|                                       (const uint8_t *)ssh_string_data(pubkey),
  470|      6|                                       ED25519_KEY_LEN);
  ------------------
  |  |   44|      6|#define ED25519_KEY_LEN 32
  ------------------
  471|      6|    if (pkey == NULL) {
  ------------------
  |  Branch (471:9): [True: 0, False: 6]
  ------------------
  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|      6|    key->key = pkey;
  479|       |
  480|      6|    return SSH_OK;
  ------------------
  |  |  316|      6|#define SSH_OK 0     /* No error */
  ------------------
  481|      6|}
pki_pubkey_build_rsa:
 1416|     77|                         ssh_string n) {
 1417|     77|    int rc;
 1418|     77|    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|     77|    RSA *key_rsa = RSA_new();
 1426|     77|    if (key_rsa == NULL) {
  ------------------
  |  Branch (1426:9): [True: 0, False: 77]
  ------------------
 1427|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1428|      0|    }
 1429|     77|#endif /* OPENSSL_VERSION_NUMBER */
 1430|       |
 1431|     77|    be = ssh_make_string_bn(e);
 1432|     77|    if (be == NULL) {
  ------------------
  |  Branch (1432:9): [True: 0, False: 77]
  ------------------
 1433|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1434|      0|        goto fail;
 1435|      0|    }
 1436|     77|    bn = ssh_make_string_bn(n);
 1437|     77|    if (bn == NULL) {
  ------------------
  |  Branch (1437:9): [True: 0, False: 77]
  ------------------
 1438|      0|        rc = SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 1439|      0|        goto fail;
 1440|      0|    }
 1441|       |
 1442|     77|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1443|     77|    rc = RSA_set0_key(key_rsa, bn, be, NULL);
 1444|     77|    if (rc == 0) {
  ------------------
  |  Branch (1444:9): [True: 0, False: 77]
  ------------------
 1445|      0|        goto fail;
 1446|      0|    }
 1447|       |    /* Memory management of bn and be is transferred to RSA object */
 1448|     77|    bn = NULL;
 1449|     77|    be = NULL;
 1450|       |
 1451|     77|    key->key = EVP_PKEY_new();
 1452|     77|    if (key->key == NULL) {
  ------------------
  |  Branch (1452:9): [True: 0, False: 77]
  ------------------
 1453|      0|        goto fail;
 1454|      0|    }
 1455|       |
 1456|     77|    rc = EVP_PKEY_assign_RSA(key->key, key_rsa);
 1457|     77|    if (rc != 1) {
  ------------------
  |  Branch (1457:9): [True: 0, False: 77]
  ------------------
 1458|      0|        goto fail;
 1459|      0|    }
 1460|       |
 1461|     77|    return SSH_OK;
  ------------------
  |  |  316|     77|#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|     77|}
pki_key_to_blob:
 1493|     71|{
 1494|     71|    ssh_buffer buffer = NULL;
 1495|     71|    ssh_string type_s = NULL;
 1496|     71|    ssh_string str = NULL;
 1497|     71|    ssh_string e = NULL;
 1498|     71|    ssh_string n = NULL;
 1499|     71|    ssh_string p = NULL;
 1500|     71|    ssh_string g = NULL;
 1501|     71|    ssh_string q = NULL;
 1502|     71|    ssh_string d = NULL;
 1503|     71|    ssh_string iqmp = NULL;
 1504|     71|    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|     71|    uint8_t *ed25519_pubkey = NULL;
 1512|     71|    uint8_t *ed25519_privkey = NULL;
 1513|     71|    size_t key_len = 0;
 1514|       |
 1515|     71|    buffer = ssh_buffer_new();
 1516|     71|    if (buffer == NULL) {
  ------------------
  |  Branch (1516:9): [True: 0, False: 71]
  ------------------
 1517|      0|        return NULL;
 1518|      0|    }
 1519|       |    /* The buffer will contain sensitive information. Make sure it is erased */
 1520|     71|    ssh_buffer_set_secure(buffer);
 1521|       |
 1522|     71|    if (key->cert != NULL) {
  ------------------
  |  Branch (1522:9): [True: 2, False: 69]
  ------------------
 1523|      2|        rc = ssh_buffer_add_buffer(buffer, key->cert);
 1524|      2|        if (rc < 0) {
  ------------------
  |  Branch (1524:13): [True: 0, False: 2]
  ------------------
 1525|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  934|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (934:14): [True: 0, False: 0]
  |  |  |  Branch (934:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1526|      0|            return NULL;
 1527|      0|        }
 1528|      2|        goto makestring;
 1529|      2|    }
 1530|       |
 1531|     69|    type_s = ssh_string_from_char(key->type_c);
 1532|     69|    if (type_s == NULL) {
  ------------------
  |  Branch (1532:9): [True: 0, False: 69]
  ------------------
 1533|      0|        SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  934|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (934:14): [True: 0, False: 0]
  |  |  |  Branch (934:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1534|      0|        return NULL;
 1535|      0|    }
 1536|       |
 1537|     69|    rc = ssh_buffer_add_ssh_string(buffer, type_s);
 1538|     69|    SSH_STRING_FREE(type_s);
  ------------------
  |  |  893|     69|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 69, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 69]
  |  |  ------------------
  ------------------
 1539|     69|    if (rc < 0) {
  ------------------
  |  Branch (1539:9): [True: 0, False: 69]
  ------------------
 1540|      0|        SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  934|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (934:14): [True: 0, False: 0]
  |  |  |  Branch (934:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1541|      0|        return NULL;
 1542|      0|    }
 1543|       |
 1544|     69|    switch (key->type) {
 1545|     69|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (1545:5): [True: 69, False: 0]
  ------------------
 1546|     69|    case SSH_KEYTYPE_RSA1: {
  ------------------
  |  Branch (1546:5): [True: 0, False: 69]
  ------------------
 1547|     69|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 1548|     69|        const BIGNUM *be = NULL, *bn = NULL;
 1549|     69|        const RSA *key_rsa = EVP_PKEY_get0_RSA(key->key);
 1550|     69|        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|     69|        e = ssh_make_bignum_string((BIGNUM *)be);
 1577|     69|        if (e == NULL) {
  ------------------
  |  Branch (1577:13): [True: 0, False: 69]
  ------------------
 1578|      0|            goto fail;
 1579|      0|        }
 1580|       |
 1581|     69|        n = ssh_make_bignum_string((BIGNUM *)bn);
 1582|     69|        if (n == NULL) {
  ------------------
  |  Branch (1582:13): [True: 0, False: 69]
  ------------------
 1583|      0|            goto fail;
 1584|      0|        }
 1585|       |
 1586|     69|        if (type == SSH_KEY_PUBLIC) {
  ------------------
  |  Branch (1586:13): [True: 69, False: 0]
  ------------------
 1587|       |            /* The N and E parts are swapped in the public key export ! */
 1588|     69|            rc = ssh_buffer_add_ssh_string(buffer, e);
 1589|     69|            if (rc < 0) {
  ------------------
  |  Branch (1589:17): [True: 0, False: 69]
  ------------------
 1590|      0|                goto fail;
 1591|      0|            }
 1592|     69|            rc = ssh_buffer_add_ssh_string(buffer, n);
 1593|     69|            if (rc < 0) {
  ------------------
  |  Branch (1593:17): [True: 0, False: 69]
  ------------------
 1594|      0|                goto fail;
 1595|      0|            }
 1596|     69|        } 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);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1697|      0|            ssh_string_burn(iqmp);
 1698|      0|            SSH_STRING_FREE(iqmp);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1699|      0|            ssh_string_burn(p);
 1700|      0|            SSH_STRING_FREE(p);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1701|      0|            ssh_string_burn(q);
 1702|      0|            SSH_STRING_FREE(q);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893: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|     69|        ssh_string_burn(e);
 1711|     69|        SSH_STRING_FREE(e);
  ------------------
  |  |  893|     69|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 69, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 69]
  |  |  ------------------
  ------------------
 1712|     69|        ssh_string_burn(n);
 1713|     69|        SSH_STRING_FREE(n);
  ------------------
  |  |  893|     69|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 69, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 69]
  |  |  ------------------
  ------------------
 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|     69|        break;
 1721|     69|    }
 1722|      0|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (1722:5): [True: 0, False: 69]
  ------------------
 1723|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (1723:5): [True: 0, False: 69]
  ------------------
 1724|      0|        rc = EVP_PKEY_get_raw_public_key(key->key, NULL, &key_len);
 1725|      0|        if (rc != 1) {
  ------------------
  |  Branch (1725:13): [True: 0, False: 0]
  ------------------
 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|      0|        if (key_len != ED25519_KEY_LEN) {
  ------------------
  |  |   44|      0|#define ED25519_KEY_LEN 32
  ------------------
  |  Branch (1732:13): [True: 0, False: 0]
  ------------------
 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|      0|        ed25519_pubkey = malloc(key_len);
 1741|      0|        if (ed25519_pubkey == NULL) {
  ------------------
  |  Branch (1741:13): [True: 0, False: 0]
  ------------------
 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|      0|        rc = EVP_PKEY_get_raw_public_key(key->key,
 1747|      0|                                         (uint8_t *)ed25519_pubkey,
 1748|      0|                                         &key_len);
 1749|      0|        if (rc != 1) {
  ------------------
  |  Branch (1749:13): [True: 0, False: 0]
  ------------------
 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|      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)
  |  |  ------------------
  ------------------
 1757|      0|                             "dP",
 1758|      0|                             (uint32_t)ED25519_KEY_LEN,
 1759|      0|                             (size_t)ED25519_KEY_LEN,
 1760|      0|                             ed25519_pubkey);
 1761|      0|        if (rc == SSH_ERROR) {
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
  |  Branch (1761:13): [True: 0, False: 0]
  ------------------
 1762|      0|            goto fail;
 1763|      0|        }
 1764|       |
 1765|      0|        if (type == SSH_KEY_PRIVATE && key->type == SSH_KEYTYPE_ED25519) {
  ------------------
  |  Branch (1765:13): [True: 0, False: 0]
  |  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|      0|        } else if (type == SSH_KEY_PRIVATE &&
  ------------------
  |  Branch (1811:20): [True: 0, False: 0]
  ------------------
 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|      0|        } else if (type == SSH_KEY_PUBLIC &&
  ------------------
  |  Branch (1818:20): [True: 0, False: 0]
  ------------------
 1819|      0|                   key->type == SSH_KEYTYPE_SK_ED25519) {
  ------------------
  |  Branch (1819:20): [True: 0, False: 0]
  ------------------
 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|      0|        SAFE_FREE(ed25519_pubkey);
  ------------------
  |  |  373|      0|#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
  |  |  ------------------
  |  |  |  Branch (373:31): [True: 0, False: 0]
  |  |  |  Branch (373:71): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1828|      0|        break;
 1829|      0|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (1829:5): [True: 0, False: 69]
  ------------------
 1830|      0|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (1830:5): [True: 0, False: 69]
  ------------------
 1831|      0|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (1831:5): [True: 0, False: 69]
  ------------------
 1832|      0|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (1832:5): [True: 0, False: 69]
  ------------------
 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);
  ------------------
  |  |  934|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (934:14): [True: 0, False: 0]
  |  |  |  Branch (934: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);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1856|      0|        if (rc < 0) {
  ------------------
  |  Branch (1856:13): [True: 0, False: 0]
  ------------------
 1857|      0|            SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  934|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (934:14): [True: 0, False: 0]
  |  |  |  Branch (934: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);
  ------------------
  |  |  934|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (934:14): [True: 0, False: 0]
  |  |  |  Branch (934: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);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893: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);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893: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: 69]
  ------------------
 1993|      0|    default:
  ------------------
  |  Branch (1993:5): [True: 0, False: 69]
  ------------------
 1994|      0|        goto fail;
 1995|     69|    }
 1996|       |
 1997|     71|makestring:
 1998|     71|    str = ssh_string_new(ssh_buffer_get_len(buffer));
 1999|     71|    if (str == NULL) {
  ------------------
  |  Branch (1999:9): [True: 0, False: 71]
  ------------------
 2000|      0|        goto fail;
 2001|      0|    }
 2002|       |
 2003|     71|    rc = ssh_string_fill(str, ssh_buffer_get(buffer), ssh_buffer_get_len(buffer));
 2004|     71|    if (rc < 0) {
  ------------------
  |  Branch (2004:9): [True: 0, False: 71]
  ------------------
 2005|      0|        goto fail;
 2006|      0|    }
 2007|     71|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  934|     71|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (934:14): [True: 71, False: 0]
  |  |  |  Branch (934:69): [Folded, False: 71]
  |  |  ------------------
  ------------------
 2008|       |
 2009|     71|    return str;
 2010|      0|fail:
 2011|      0|    SSH_BUFFER_FREE(buffer);
  ------------------
  |  |  934|      0|    do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (934:14): [True: 0, False: 0]
  |  |  |  Branch (934:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2012|      0|    ssh_string_burn(str);
 2013|      0|    SSH_STRING_FREE(str);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2014|      0|    ssh_string_burn(e);
 2015|      0|    SSH_STRING_FREE(e);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2016|      0|    ssh_string_burn(p);
 2017|      0|    SSH_STRING_FREE(p);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2018|      0|    ssh_string_burn(g);
 2019|      0|    SSH_STRING_FREE(g);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2020|      0|    ssh_string_burn(q);
 2021|      0|    SSH_STRING_FREE(q);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2022|      0|    ssh_string_burn(n);
 2023|      0|    SSH_STRING_FREE(n);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2024|      0|    ssh_string_burn(d);
 2025|      0|    SSH_STRING_FREE(d);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893:69): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2026|      0|    ssh_string_burn(iqmp);
 2027|      0|    SSH_STRING_FREE(iqmp);
  ------------------
  |  |  893|      0|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 0]
  |  |  |  Branch (893: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|     71|}
pki_signature_from_blob:
 2393|      8|{
 2394|      8|    ssh_signature sig;
 2395|      8|    int rc;
 2396|       |
 2397|      8|    if (ssh_key_type_plain(pubkey->type) != type) {
  ------------------
  |  Branch (2397:9): [True: 0, False: 8]
  ------------------
 2398|      0|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2399|      0|                "Incompatible public key provided (%d) expecting (%d)",
 2400|      0|                type,
 2401|      0|                pubkey->type);
 2402|      0|        return NULL;
 2403|      0|    }
 2404|       |
 2405|      8|    sig = ssh_signature_new();
 2406|      8|    if (sig == NULL) {
  ------------------
  |  Branch (2406:9): [True: 0, False: 8]
  ------------------
 2407|      0|        return NULL;
 2408|      0|    }
 2409|       |
 2410|      8|    sig->type = type;
 2411|      8|    sig->type_c = ssh_key_signature_to_char(type, hash_type);
 2412|      8|    sig->hash_type = hash_type;
 2413|       |
 2414|      8|    switch(type) {
 2415|      8|        case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2415:9): [True: 8, False: 0]
  ------------------
 2416|      8|        case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2416:9): [True: 0, False: 8]
  ------------------
 2417|      8|            rc = pki_signature_from_rsa_blob(pubkey, sig_blob, sig);
 2418|      8|            if (rc != SSH_OK) {
  ------------------
  |  |  316|      8|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2418:17): [True: 1, False: 7]
  ------------------
 2419|      1|                goto error;
 2420|      1|            }
 2421|      7|            break;
 2422|      7|        case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2422:9): [True: 0, False: 8]
  ------------------
 2423|      0|        case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2423:9): [True: 0, False: 8]
  ------------------
 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: 8]
  ------------------
 2430|      0|        case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2430:9): [True: 0, False: 8]
  ------------------
 2431|      0|        case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2431:9): [True: 0, False: 8]
  ------------------
 2432|      0|        case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2432:9): [True: 0, False: 8]
  ------------------
 2433|      0|        case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2433:9): [True: 0, False: 8]
  ------------------
 2434|      0|        case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2434:9): [True: 0, False: 8]
  ------------------
 2435|      0|        case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2435:9): [True: 0, False: 8]
  ------------------
 2436|      0|        case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2436:9): [True: 0, False: 8]
  ------------------
 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: 8]
  ------------------
 2445|      0|        case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2445:9): [True: 0, False: 8]
  ------------------
 2446|      0|            SSH_LOG(SSH_LOG_TRACE, "Unknown signature type");
  ------------------
  |  |  281|      0|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2447|      0|            goto error;
 2448|      8|    }
 2449|       |
 2450|      7|    return sig;
 2451|       |
 2452|      1|error:
 2453|      1|    ssh_signature_free(sig);
 2454|       |    return NULL;
 2455|      8|}
pki_verify_data_signature:
 2676|      5|{
 2677|      5|    const EVP_MD *md = NULL;
 2678|      5|    EVP_MD_CTX *ctx = NULL;
 2679|      5|    EVP_PKEY *pkey = NULL;
 2680|       |
 2681|      5|    unsigned char *raw_sig_data = NULL;
 2682|      5|    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|      5|    int rc = SSH_ERROR;
  ------------------
  |  |  317|      5|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2689|      5|    int ok;
 2690|       |
 2691|      5|    if (pubkey == NULL || ssh_key_is_private(pubkey) || input == NULL ||
  ------------------
  |  Branch (2691:9): [True: 0, False: 5]
  |  Branch (2691:27): [True: 0, False: 5]
  |  Branch (2691:57): [True: 0, False: 5]
  ------------------
 2692|      5|        signature == NULL || signature->raw_sig == NULL)
  ------------------
  |  Branch (2692:9): [True: 0, False: 5]
  |  Branch (2692:30): [True: 0, False: 5]
  ------------------
 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|      5|    ok = pki_key_check_hash_compatible(pubkey, signature->hash_type);
 2701|      5|    if (ok != SSH_OK) {
  ------------------
  |  |  316|      5|#define SSH_OK 0     /* No error */
  ------------------
  |  Branch (2701:9): [True: 0, False: 5]
  ------------------
 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|      5|    raw_sig_data = ssh_string_data(signature->raw_sig);
 2707|      5|    raw_sig_len = ssh_string_len(signature->raw_sig);
 2708|      5|    if (raw_sig_data == NULL) {
  ------------------
  |  Branch (2708:9): [True: 0, False: 5]
  ------------------
 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|      5|    md = pki_digest_to_md(signature->hash_type);
 2714|      5|    if (md == NULL) {
  ------------------
  |  Branch (2714:9): [True: 0, False: 5]
  ------------------
 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|      5|    pkey = pki_key_to_pkey(pubkey);
 2722|      5|    if (pkey == NULL) {
  ------------------
  |  Branch (2722:9): [True: 0, False: 5]
  ------------------
 2723|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2724|      0|    }
 2725|       |
 2726|       |    /* Create the context */
 2727|      5|    ctx = EVP_MD_CTX_new();
 2728|      5|    if (ctx == NULL) {
  ------------------
  |  Branch (2728:9): [True: 0, False: 5]
  ------------------
 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|      5|    ok = EVP_DigestVerifyInit(ctx, NULL, md, NULL, pkey);
 2737|      5|    if (ok != 1){
  ------------------
  |  Branch (2737:9): [True: 0, False: 5]
  ------------------
 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|      5|    ok = EVP_DigestVerify(ctx, raw_sig_data, raw_sig_len, input, input_len);
 2745|      5|    if (ok != 1) {
  ------------------
  |  Branch (2745:9): [True: 5, False: 0]
  ------------------
 2746|      5|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      5|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2747|      5|                "Signature invalid: %s",
 2748|      5|                ERR_error_string(ERR_get_error(), NULL));
 2749|      5|        goto out;
 2750|      5|    }
 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|      5|out:
 2756|      5|    EVP_MD_CTX_free(ctx);
 2757|      5|    EVP_PKEY_free(pkey);
 2758|      5|    return rc;
 2759|      0|}
ssh_key_size:
 2762|      9|{
 2763|      9|    int bits = 0;
 2764|      9|    EVP_PKEY *pkey = NULL;
 2765|       |
 2766|      9|    switch (key->type) {
 2767|      9|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2767:5): [True: 9, False: 0]
  ------------------
 2768|      9|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (2768:5): [True: 0, False: 9]
  ------------------
 2769|      9|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2769:5): [True: 0, False: 9]
  ------------------
 2770|      9|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2770:5): [True: 0, False: 9]
  ------------------
 2771|      9|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2771:5): [True: 0, False: 9]
  ------------------
 2772|      9|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2772:5): [True: 0, False: 9]
  ------------------
 2773|      9|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2773:5): [True: 0, False: 9]
  ------------------
 2774|      9|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2774:5): [True: 0, False: 9]
  ------------------
 2775|      9|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2775:5): [True: 0, False: 9]
  ------------------
 2776|      9|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2776:5): [True: 0, False: 9]
  ------------------
 2777|      9|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2777:5): [True: 0, False: 9]
  ------------------
 2778|      9|        pkey = pki_key_to_pkey(key);
 2779|      9|        if (pkey == NULL) {
  ------------------
  |  Branch (2779:13): [True: 0, False: 9]
  ------------------
 2780|      0|            return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2781|      0|        }
 2782|      9|        bits = EVP_PKEY_bits(pkey);
 2783|      9|        EVP_PKEY_free(pkey);
 2784|      9|        return bits;
 2785|      0|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2785:5): [True: 0, False: 9]
  ------------------
 2786|      0|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (2786:5): [True: 0, False: 9]
  ------------------
 2787|      0|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2787:5): [True: 0, False: 9]
  ------------------
 2788|      0|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (2788:5): [True: 0, False: 9]
  ------------------
 2789|       |        /* ed25519 keys have fixed size */
 2790|      0|        return 255;
 2791|      0|    case SSH_KEYTYPE_DSS:   /* deprecated */
  ------------------
  |  Branch (2791:5): [True: 0, False: 9]
  ------------------
 2792|      0|    case SSH_KEYTYPE_DSS_CERT01:    /* deprecated */
  ------------------
  |  Branch (2792:5): [True: 0, False: 9]
  ------------------
 2793|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2793:5): [True: 0, False: 9]
  ------------------
 2794|      0|    default:
  ------------------
  |  Branch (2794:5): [True: 0, False: 9]
  ------------------
 2795|      0|        return SSH_ERROR;
  ------------------
  |  |  317|      0|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2796|      9|    }
 2797|      9|}
pki_crypto.c:pki_signature_from_rsa_blob:
 2171|      8|{
 2172|      8|    size_t pad_len = 0;
 2173|      8|    char *blob_orig = NULL;
 2174|      8|    char *blob_padded_data = NULL;
 2175|      8|    ssh_string sig_blob_padded = NULL;
 2176|       |
 2177|      8|    size_t rsalen = 0;
 2178|      8|    size_t len = ssh_string_len(sig_blob);
 2179|       |
 2180|      8|#if OPENSSL_VERSION_NUMBER < 0x30000000L
 2181|      8|    const RSA *rsa = EVP_PKEY_get0_RSA(pubkey->key);
 2182|       |
 2183|      8|    if (rsa == NULL) {
  ------------------
  |  Branch (2183:9): [True: 0, False: 8]
  ------------------
 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|      8|    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|      8|    if (len > rsalen) {
  ------------------
  |  Branch (2197:9): [True: 1, False: 7]
  ------------------
 2198|      1|        SSH_LOG(SSH_LOG_TRACE,
  ------------------
  |  |  281|      1|    _ssh_log(priority, __func__, __VA_ARGS__)
  ------------------
 2199|      1|                "Signature is too big: %lu > %lu",
 2200|      1|                (unsigned long)len,
 2201|      1|                (unsigned long)rsalen);
 2202|      1|        goto errout;
 2203|      1|    }
 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|      7|    if (len == rsalen) {
  ------------------
  |  Branch (2210:9): [True: 3, False: 4]
  ------------------
 2211|      3|        sig->raw_sig = ssh_string_copy(sig_blob);
 2212|      4|    } 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|      7|    return SSH_OK;
  ------------------
  |  |  316|      7|#define SSH_OK 0     /* No error */
  ------------------
 2242|       |
 2243|      1|errout:
 2244|      1|    SSH_STRING_FREE(sig_blob_padded);
  ------------------
  |  |  893|      1|    do { if ((x) != NULL) { ssh_string_free(x); x = NULL; } } while(0)
  |  |  ------------------
  |  |  |  Branch (893:14): [True: 0, False: 1]
  |  |  |  Branch (893:69): [Folded, False: 1]
  |  |  ------------------
  ------------------
 2245|      1|    return SSH_ERROR;
  ------------------
  |  |  317|      1|#define SSH_ERROR -1 /* Error of some kind */
  ------------------
 2246|      7|}
pki_crypto.c:pki_digest_to_md:
 2458|      5|{
 2459|      5|    const EVP_MD *md = NULL;
 2460|       |
 2461|      5|    switch (hash_type) {
 2462|      1|    case SSH_DIGEST_SHA256:
  ------------------
  |  Branch (2462:5): [True: 1, False: 4]
  ------------------
 2463|      1|        md = EVP_sha256();
 2464|      1|        break;
 2465|      0|    case SSH_DIGEST_SHA384:
  ------------------
  |  Branch (2465:5): [True: 0, False: 5]
  ------------------
 2466|      0|        md = EVP_sha384();
 2467|      0|        break;
 2468|      3|    case SSH_DIGEST_SHA512:
  ------------------
  |  Branch (2468:5): [True: 3, False: 2]
  ------------------
 2469|      3|        md = EVP_sha512();
 2470|      3|        break;
 2471|      1|    case SSH_DIGEST_SHA1:
  ------------------
  |  Branch (2471:5): [True: 1, False: 4]
  ------------------
 2472|      1|        md = EVP_sha1();
 2473|      1|        break;
 2474|      0|    case SSH_DIGEST_AUTO:
  ------------------
  |  Branch (2474:5): [True: 0, False: 5]
  ------------------
 2475|      0|        md = NULL;
 2476|      0|        break;
 2477|      0|    default:
  ------------------
  |  Branch (2477:5): [True: 0, False: 5]
  ------------------
 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|      5|    }
 2482|       |
 2483|      5|    return md;
 2484|      5|}
pki_crypto.c:pki_key_to_pkey:
 2487|     14|{
 2488|     14|    EVP_PKEY *pkey = NULL;
 2489|     14|    int rc = 0;
 2490|       |
 2491|     14|    switch (key->type) {
 2492|     14|    case SSH_KEYTYPE_RSA:
  ------------------
  |  Branch (2492:5): [True: 14, False: 0]
  ------------------
 2493|     14|    case SSH_KEYTYPE_RSA1:
  ------------------
  |  Branch (2493:5): [True: 0, False: 14]
  ------------------
 2494|     14|    case SSH_KEYTYPE_RSA_CERT01:
  ------------------
  |  Branch (2494:5): [True: 0, False: 14]
  ------------------
 2495|     14|    case SSH_KEYTYPE_ECDSA_P256:
  ------------------
  |  Branch (2495:5): [True: 0, False: 14]
  ------------------
 2496|     14|    case SSH_KEYTYPE_ECDSA_P384:
  ------------------
  |  Branch (2496:5): [True: 0, False: 14]
  ------------------
 2497|     14|    case SSH_KEYTYPE_ECDSA_P521:
  ------------------
  |  Branch (2497:5): [True: 0, False: 14]
  ------------------
 2498|     14|    case SSH_KEYTYPE_ECDSA_P256_CERT01:
  ------------------
  |  Branch (2498:5): [True: 0, False: 14]
  ------------------
 2499|     14|    case SSH_KEYTYPE_ECDSA_P384_CERT01:
  ------------------
  |  Branch (2499:5): [True: 0, False: 14]
  ------------------
 2500|     14|    case SSH_KEYTYPE_ECDSA_P521_CERT01:
  ------------------
  |  Branch (2500:5): [True: 0, False: 14]
  ------------------
 2501|     14|    case SSH_KEYTYPE_SK_ECDSA:
  ------------------
  |  Branch (2501:5): [True: 0, False: 14]
  ------------------
 2502|     14|    case SSH_KEYTYPE_SK_ECDSA_CERT01:
  ------------------
  |  Branch (2502:5): [True: 0, False: 14]
  ------------------
 2503|     14|    case SSH_KEYTYPE_ED25519:
  ------------------
  |  Branch (2503:5): [True: 0, False: 14]
  ------------------
 2504|     14|    case SSH_KEYTYPE_ED25519_CERT01:
  ------------------
  |  Branch (2504:5): [True: 0, False: 14]
  ------------------
 2505|     14|    case SSH_KEYTYPE_SK_ED25519:
  ------------------
  |  Branch (2505:5): [True: 0, False: 14]
  ------------------
 2506|     14|    case SSH_KEYTYPE_SK_ED25519_CERT01:
  ------------------
  |  Branch (2506:5): [True: 0, False: 14]
  ------------------
 2507|     14|        if (key->key == NULL) {
  ------------------
  |  Branch (2507:13): [True: 0, False: 14]
  ------------------
 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|     14|        rc = EVP_PKEY_up_ref(key->key);
 2512|     14|        if (rc != 1) {
  ------------------
  |  Branch (2512:13): [True: 0, False: 14]
  ------------------
 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|     14|        pkey = key->key;
 2517|     14|        break;
 2518|      0|    case SSH_KEYTYPE_UNKNOWN:
  ------------------
  |  Branch (2518:5): [True: 0, False: 14]
  ------------------
 2519|      0|    default:
  ------------------
  |  Branch (2519:5): [True: 0, False: 14]
  ------------------
 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|     14|    }
 2524|       |
 2525|     14|    return pkey;
 2526|       |
 2527|      0|error:
 2528|      0|    EVP_PKEY_free(pkey);
 2529|       |    return NULL;
 2530|     14|}

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

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

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

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

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

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

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

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

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

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

