ssh_digest_memory: 187| 14|{ 188| 14| const struct ssh_digest *digest = ssh_digest_by_alg(alg); 189| 14| u_int mdlen; 190| | 191| 14| if (digest == NULL) ------------------ | Branch (191:6): [True: 0, False: 14] ------------------ 192| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 193| 14| if (dlen > UINT_MAX) ------------------ | Branch (193:6): [True: 0, False: 14] ------------------ 194| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 195| 14| if (dlen < digest->digest_len) ------------------ | Branch (195:6): [True: 0, False: 14] ------------------ 196| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 197| 14| mdlen = dlen; 198| 14| if (!EVP_Digest(m, mlen, d, &mdlen, digest->mdfunc(), NULL)) ------------------ | Branch (198:6): [True: 0, False: 14] ------------------ 199| 0| return SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 200| 14| return 0; 201| 14|} digest-openssl.c:ssh_digest_by_alg: 70| 14|{ 71| 14| if (alg < 0 || alg >= SSH_DIGEST_MAX) ------------------ | | 31| 14|#define SSH_DIGEST_MAX 6 ------------------ | Branch (71:6): [True: 0, False: 14] | Branch (71:17): [True: 0, False: 14] ------------------ 72| 0| return NULL; 73| 14| if (digests[alg].id != alg) /* sanity */ ------------------ | Branch (73:6): [True: 0, False: 14] ------------------ 74| 0| return NULL; 75| 14| if (digests[alg].mdfunc == NULL) ------------------ | Branch (75:6): [True: 0, False: 14] ------------------ 76| 0| return NULL; 77| 14| return &(digests[alg]); 78| 14|} crypto_sign_ed25519_verify_detached: 180| 143|{ 181| 143| EVP_PKEY *pkey = NULL; 182| 143| EVP_MD_CTX *mdctx = NULL; 183| 143| int ret = -1; 184| | 185| 143| if (mlen > SIZE_MAX) { ------------------ | Branch (185:6): [True: 0, False: 143] ------------------ 186| 0| debug3_f("message too long: %llu", mlen); ------------------ | | 120| 0|#define debug3_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG3, NULL, __VA_ARGS__) ------------------ 187| 0| return -1; 188| 0| } 189| | 190| | /* Create EVP_PKEY from public key */ 191| 143| if ((pkey = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519, NULL, ------------------ | Branch (191:6): [True: 0, False: 143] ------------------ 192| 143| pk, crypto_sign_ed25519_PUBLICKEYBYTES)) == NULL) { ------------------ | | 60| 143|#define crypto_sign_ed25519_PUBLICKEYBYTES 32U ------------------ 193| 0| debug3_f("EVP_PKEY_new_raw_public_key failed"); ------------------ | | 120| 0|#define debug3_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG3, NULL, __VA_ARGS__) ------------------ 194| 0| goto out; 195| 0| } 196| | 197| 143| if ((mdctx = EVP_MD_CTX_new()) == NULL) { ------------------ | Branch (197:6): [True: 0, False: 143] ------------------ 198| 0| debug3_f("EVP_MD_CTX_new failed"); ------------------ | | 120| 0|#define debug3_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG3, NULL, __VA_ARGS__) ------------------ 199| 0| goto out; 200| 0| } 201| 143| if (EVP_DigestVerifyInit(mdctx, NULL, NULL, NULL, pkey) <= 0) { ------------------ | Branch (201:6): [True: 0, False: 143] ------------------ 202| 0| debug3_f("EVP_DigestVerifyInit failed"); ------------------ | | 120| 0|#define debug3_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG3, NULL, __VA_ARGS__) ------------------ 203| 0| goto out; 204| 0| } 205| 143| if (EVP_DigestVerify(mdctx, sig, crypto_sign_ed25519_BYTES, ------------------ | | 62| 143|#define crypto_sign_ed25519_BYTES 64U ------------------ | Branch (205:6): [True: 2, False: 141] ------------------ 206| 143| m, (size_t)mlen) != 1) { 207| 2| debug3_f("EVP_DigestVerify failed"); ------------------ | | 120| 2|#define debug3_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG3, NULL, __VA_ARGS__) ------------------ 208| 2| goto out; 209| 2| } 210| | 211| 141| ret = 0; 212| 143|out: 213| 143| EVP_MD_CTX_free(mdctx); 214| 143| EVP_PKEY_free(pkey); 215| 143| return ret; 216| 141|} sshlog: 437| 4|{ 438| 4| va_list args; 439| | 440| 4| va_start(args, fmt); 441| 4| sshlogv(file, func, line, showfunc, level, suffix, fmt, args); 442| | va_end(args); 443| 4|} sshlogv: 461| 4|{ 462| 4| char tag[128], fmt2[MSGBUFSIZ + 128]; 463| 4| int forced = 0; 464| 4| const char *cp; 465| 4| size_t i; 466| | 467| | /* short circuit processing early if we're not going to log anything */ 468| 4| if (nlog_verbose == 0 && level > log_level) ------------------ | Branch (468:6): [True: 4, False: 0] | Branch (468:27): [True: 4, False: 0] ------------------ 469| 4| return; 470| | 471| 0| snprintf(tag, sizeof(tag), "%.48s:%.48s():%d (bin=%s, pid=%ld)", 472| 0| (cp = strrchr(file, '/')) == NULL ? file : cp + 1, func, line, ------------------ | Branch (472:6): [True: 0, False: 0] ------------------ 473| 0| argv0 == NULL ? "UNKNOWN" : argv0, (long)getpid()); ------------------ | Branch (473:6): [True: 0, False: 0] ------------------ 474| 0| for (i = 0; i < nlog_verbose; i++) { ------------------ | Branch (474:14): [True: 0, False: 0] ------------------ 475| 0| if (match_pattern_list(tag, log_verbose[i], 0) == 1) { ------------------ | Branch (475:7): [True: 0, False: 0] ------------------ 476| 0| forced = 1; 477| 0| break; 478| 0| } 479| 0| } 480| | 481| 0| if (forced) ------------------ | Branch (481:6): [True: 0, False: 0] ------------------ 482| 0| snprintf(fmt2, sizeof(fmt2), "%s: %s", tag, fmt); 483| 0| else if (showfunc) ------------------ | Branch (483:11): [True: 0, False: 0] ------------------ 484| 0| snprintf(fmt2, sizeof(fmt2), "%s: %s", func, fmt); 485| 0| else 486| 0| strlcpy(fmt2, fmt, sizeof(fmt2)); 487| | 488| 0| do_log(level, forced, suffix, fmt2, args); 489| 0|} __b64_ntop: 134| 92|{ 135| 92| size_t datalength = 0; 136| 92| u_char input[3]; 137| 92| u_char output[4]; 138| 92| u_int i; 139| | 140| 207k| while (2 < srclength) { ------------------ | Branch (140:9): [True: 207k, False: 92] ------------------ 141| 207k| input[0] = *src++; 142| 207k| input[1] = *src++; 143| 207k| input[2] = *src++; 144| 207k| srclength -= 3; 145| | 146| 207k| output[0] = input[0] >> 2; 147| 207k| output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); 148| 207k| output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); 149| 207k| output[3] = input[2] & 0x3f; 150| | 151| 207k| if (datalength + 4 > targsize) ------------------ | Branch (151:7): [True: 0, False: 207k] ------------------ 152| 0| return (-1); 153| 207k| target[datalength++] = Base64[output[0]]; 154| 207k| target[datalength++] = Base64[output[1]]; 155| 207k| target[datalength++] = Base64[output[2]]; 156| 207k| target[datalength++] = Base64[output[3]]; 157| 207k| } 158| | 159| | /* Now we worry about padding. */ 160| 92| if (0 != srclength) { ------------------ | Branch (160:6): [True: 78, False: 14] ------------------ 161| | /* Get what's left. */ 162| 78| input[0] = input[1] = input[2] = '\0'; 163| 186| for (i = 0; i < srclength; i++) ------------------ | Branch (163:15): [True: 108, False: 78] ------------------ 164| 108| input[i] = *src++; 165| | 166| 78| output[0] = input[0] >> 2; 167| 78| output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); 168| 78| output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); 169| | 170| 78| if (datalength + 4 > targsize) ------------------ | Branch (170:7): [True: 0, False: 78] ------------------ 171| 0| return (-1); 172| 78| target[datalength++] = Base64[output[0]]; 173| 78| target[datalength++] = Base64[output[1]]; 174| 78| if (srclength == 1) ------------------ | Branch (174:7): [True: 48, False: 30] ------------------ 175| 48| target[datalength++] = Pad64; 176| 30| else 177| 30| target[datalength++] = Base64[output[2]]; 178| 78| target[datalength++] = Pad64; 179| 78| } 180| 92| if (datalength >= targsize) ------------------ | Branch (180:6): [True: 0, False: 92] ------------------ 181| 0| return (-1); 182| 92| target[datalength] = '\0'; /* Returned value doesn't count \0. */ 183| 92| return (datalength); 184| 92|} freezero: 26| 51.5k|{ 27| 51.5k| if (ptr == NULL) ------------------ | Branch (27:6): [True: 14.6k, False: 36.8k] ------------------ 28| 14.6k| return; 29| 36.8k| explicit_bzero(ptr, sz); 30| 36.8k| free(ptr); 31| 36.8k|} recallocarray: 37| 3.75k|{ 38| 3.75k| size_t oldsize, newsize; 39| 3.75k| void *newptr; 40| | 41| 3.75k| if (ptr == NULL) ------------------ | Branch (41:6): [True: 73, False: 3.68k] ------------------ 42| 73| return calloc(newnmemb, size); 43| | 44| 3.68k| if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && ------------------ | | 33| 7.36k|#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) ------------------ if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && ------------------ | | 33| 3.68k|#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) ------------------ | Branch (44:7): [True: 0, False: 3.68k] | Branch (44:38): [True: 0, False: 3.68k] ------------------ 45| 3.68k| newnmemb > 0 && SIZE_MAX / newnmemb < size) { ------------------ | Branch (45:6): [True: 0, False: 0] | Branch (45:22): [True: 0, False: 0] ------------------ 46| 0| errno = ENOMEM; 47| 0| return NULL; 48| 0| } 49| 3.68k| newsize = newnmemb * size; 50| | 51| 3.68k| if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && ------------------ | | 33| 7.36k|#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) ------------------ if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && ------------------ | | 33| 3.68k|#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) ------------------ | Branch (51:7): [True: 0, False: 3.68k] | Branch (51:38): [True: 0, False: 3.68k] ------------------ 52| 3.68k| oldnmemb > 0 && SIZE_MAX / oldnmemb < size) { ------------------ | Branch (52:6): [True: 0, False: 0] | Branch (52:22): [True: 0, False: 0] ------------------ 53| 0| errno = EINVAL; 54| 0| return NULL; 55| 0| } 56| 3.68k| oldsize = oldnmemb * size; 57| | 58| | /* 59| | * Don't bother too much if we're shrinking just a bit, 60| | * we do not shrink for series of small steps, oh well. 61| | */ 62| 3.68k| if (newsize <= oldsize) { ------------------ | Branch (62:6): [True: 33, False: 3.64k] ------------------ 63| 33| size_t d = oldsize - newsize; 64| | 65| 33| if (d < oldsize / 2 && d < (size_t)getpagesize()) { ------------------ | Branch (65:7): [True: 0, False: 33] | Branch (65:26): [True: 0, False: 0] ------------------ 66| 0| memset((char *)ptr + newsize, 0, d); 67| 0| return ptr; 68| 0| } 69| 33| } 70| | 71| 3.68k| newptr = malloc(newsize); 72| 3.68k| if (newptr == NULL) ------------------ | Branch (72:6): [True: 0, False: 3.68k] ------------------ 73| 0| return NULL; 74| | 75| 3.68k| if (newsize > oldsize) { ------------------ | Branch (75:6): [True: 3.64k, False: 33] ------------------ 76| 3.64k| memcpy(newptr, ptr, oldsize); 77| 3.64k| memset((char *)newptr + oldsize, 0, newsize - oldsize); 78| 3.64k| } else 79| 33| memcpy(newptr, ptr, newsize); 80| | 81| 3.68k| explicit_bzero(ptr, oldsize); 82| 3.68k| free(ptr); 83| | 84| 3.68k| return newptr; 85| 3.68k|} timingsafe_bcmp: 25| 12|{ 26| 12| const unsigned char *p1 = b1, *p2 = b2; 27| 12| int ret = 0; 28| | 29| 9.43k| for (; n > 0; n--) ------------------ | Branch (29:9): [True: 9.42k, False: 12] ------------------ 30| 9.42k| ret |= *p1++ ^ *p2++; 31| 12| return (ret != 0); 32| 12|} LLVMFuzzerTestOneInput: 11| 3.08k|{ 12| | struct sshkey *k = NULL; 13| 3.08k| struct sshbuf *b = sshbuf_from(data, size); 14| 3.08k| (void)sshkey_private_deserialize(b, &k); 15| 3.08k| sshkey_free(k); 16| 3.08k| sshbuf_free(b); 17| 3.08k| return 0; 18| 3.08k|} ssh-ecdsa-sk.c:ssh_ecdsa_sk_cleanup: 55| 481|{ 56| 481| sshkey_sk_cleanup(k); 57| 481| sshkey_ecdsa_funcs.cleanup(k); 58| 481|} ssh-ecdsa-sk.c:ssh_ecdsa_sk_deserialize_public: 116| 467|{ 117| 467| int r; 118| | 119| 467| if ((r = sshkey_ecdsa_funcs.deserialize_public(ktype, b, key)) != 0) ------------------ | Branch (119:6): [True: 12, False: 455] ------------------ 120| 12| return r; 121| 455| if ((r = sshkey_deserialize_sk(b, key)) != 0) ------------------ | Branch (121:6): [True: 1, False: 454] ------------------ 122| 1| return r; 123| 454| return 0; 124| 455|} ssh-ecdsa-sk.c:ssh_ecdsa_sk_deserialize_private: 129| 14|{ 130| 14| int r; 131| | 132| 14| if (!sshkey_is_cert(key)) { ------------------ | Branch (132:6): [True: 14, False: 0] ------------------ 133| 14| if ((r = sshkey_ecdsa_funcs.deserialize_public(ktype, ------------------ | Branch (133:7): [True: 5, False: 9] ------------------ 134| 14| b, key)) != 0) 135| 5| return r; 136| 14| } 137| 9| if ((r = sshkey_private_deserialize_sk(b, key)) != 0) ------------------ | Branch (137:6): [True: 6, False: 3] ------------------ 138| 6| return r; 139| | 140| 3| return 0; 141| 9|} ssh-ecdsa-sk.c:ssh_ecdsa_sk_verify: 224| 442|{ 225| 442| ECDSA_SIG *esig = NULL; 226| 442| EVP_MD_CTX *md_ctx = NULL; 227| 442| BIGNUM *sig_r = NULL, *sig_s = NULL; 228| 442| u_char sig_flags; 229| 442| u_char msghash[32], apphash[32]; 230| 442| u_int sig_counter; 231| 442| u_char *sigb = NULL, *cp; 232| 442| int is_webauthn = 0, ret = SSH_ERR_INTERNAL_ERROR, len = 0; ------------------ | | 25| 442|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 233| 442| struct sshbuf *b = NULL, *sigbuf = NULL, *original_signed = NULL; 234| 442| struct sshbuf *webauthn_wrapper = NULL, *webauthn_exts = NULL; 235| 442| char *ktype = NULL, *webauthn_origin = NULL; 236| 442| struct sshkey_sig_details *details = NULL; 237| |#ifdef DEBUG_SK 238| | char *tmp = NULL; 239| |#endif 240| | 241| 442| if (detailsp != NULL) ------------------ | Branch (241:6): [True: 0, False: 442] ------------------ 242| 0| *detailsp = NULL; 243| 442| if (key == NULL || key->pkey == NULL || ------------------ | Branch (243:6): [True: 0, False: 442] | Branch (243:21): [True: 0, False: 442] ------------------ 244| 442| sshkey_type_plain(key->type) != KEY_ECDSA_SK || ------------------ | Branch (244:6): [True: 0, False: 442] ------------------ 245| 442| sig == NULL || siglen == 0) ------------------ | Branch (245:6): [True: 0, False: 442] | Branch (245:21): [True: 0, False: 442] ------------------ 246| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 247| | 248| 442| if (key->ecdsa_nid != NID_X9_62_prime256v1) ------------------ | Branch (248:6): [True: 0, False: 442] ------------------ 249| 0| return SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 0|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 250| | 251| | /* fetch signature */ 252| 442| if ((b = sshbuf_from(sig, siglen)) == NULL) ------------------ | Branch (252:6): [True: 0, False: 442] ------------------ 253| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 254| 442| if ((details = calloc(1, sizeof(*details))) == NULL) { ------------------ | Branch (254:6): [True: 0, False: 442] ------------------ 255| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 256| 0| goto out; 257| 0| } 258| 442| if (sshbuf_get_cstring(b, &ktype, NULL) != 0) { ------------------ | Branch (258:6): [True: 0, False: 442] ------------------ 259| 0| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 0|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 260| 0| goto out; 261| 0| } 262| 442| if (strcmp(ktype, "webauthn-sk-ecdsa-sha2-nistp256@openssh.com") == 0 || ------------------ | Branch (262:6): [True: 131, False: 311] ------------------ 263| 311| strcmp(ktype, "webauthn-sk-ecdsa-sha2-nistp256-cert-v01@openssh.com") ------------------ | Branch (263:6): [True: 1, False: 310] ------------------ 264| 311| == 0) 265| 132| is_webauthn = 1; 266| 310| else if (strcmp(ktype, "sk-ecdsa-sha2-nistp256@openssh.com") != 0) { ------------------ | Branch (266:11): [True: 286, False: 24] ------------------ 267| 286| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 286|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 268| 286| goto out; 269| 286| } 270| 156| if (sshbuf_froms(b, &sigbuf) != 0 || ------------------ | Branch (270:6): [True: 3, False: 153] ------------------ 271| 153| sshbuf_get_u8(b, &sig_flags) != 0 || ------------------ | Branch (271:6): [True: 1, False: 152] ------------------ 272| 152| sshbuf_get_u32(b, &sig_counter) != 0) { ------------------ | Branch (272:6): [True: 1, False: 151] ------------------ 273| 5| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 5|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 274| 5| goto out; 275| 5| } 276| 151| if (is_webauthn) { ------------------ | Branch (276:6): [True: 130, False: 21] ------------------ 277| 130| if (sshbuf_get_cstring(b, &webauthn_origin, NULL) != 0 || ------------------ | Branch (277:7): [True: 2, False: 128] ------------------ 278| 128| sshbuf_froms(b, &webauthn_wrapper) != 0 || ------------------ | Branch (278:7): [True: 3, False: 125] ------------------ 279| 125| sshbuf_froms(b, &webauthn_exts) != 0) { ------------------ | Branch (279:7): [True: 5, False: 120] ------------------ 280| 10| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 10|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 281| 10| goto out; 282| 10| } 283| 130| } 284| 141| if (sshbuf_len(b) != 0) { ------------------ | Branch (284:6): [True: 21, False: 120] ------------------ 285| 21| ret = SSH_ERR_UNEXPECTED_TRAILING_DATA; ------------------ | | 47| 21|#define SSH_ERR_UNEXPECTED_TRAILING_DATA -23 ------------------ 286| 21| goto out; 287| 21| } 288| | 289| | /* parse signature */ 290| 120| if (sshbuf_get_bignum2(sigbuf, &sig_r) != 0 || ------------------ | Branch (290:6): [True: 2, False: 118] ------------------ 291| 118| sshbuf_get_bignum2(sigbuf, &sig_s) != 0) { ------------------ | Branch (291:6): [True: 2, False: 116] ------------------ 292| 4| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 4|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 293| 4| goto out; 294| 4| } 295| 116| if (sshbuf_len(sigbuf) != 0) { ------------------ | Branch (295:6): [True: 13, False: 103] ------------------ 296| 13| ret = SSH_ERR_UNEXPECTED_TRAILING_DATA; ------------------ | | 47| 13|#define SSH_ERR_UNEXPECTED_TRAILING_DATA -23 ------------------ 297| 13| goto out; 298| 13| } 299| | 300| |#ifdef DEBUG_SK 301| | fprintf(stderr, "%s: data: (len %zu)\n", __func__, dlen); 302| | /* sshbuf_dump_data(data, datalen, stderr); */ 303| | fprintf(stderr, "%s: sig_r: %s\n", __func__, (tmp = BN_bn2hex(sig_r))); 304| | free(tmp); 305| | fprintf(stderr, "%s: sig_s: %s\n", __func__, (tmp = BN_bn2hex(sig_s))); 306| | free(tmp); 307| | fprintf(stderr, "%s: sig_flags = 0x%02x, sig_counter = %u\n", 308| | __func__, sig_flags, sig_counter); 309| | if (is_webauthn) { 310| | fprintf(stderr, "%s: webauthn origin: %s\n", __func__, 311| | webauthn_origin); 312| | fprintf(stderr, "%s: webauthn_wrapper:\n", __func__); 313| | sshbuf_dump(webauthn_wrapper, stderr); 314| | } 315| |#endif 316| 103| if ((esig = ECDSA_SIG_new()) == NULL) { ------------------ | Branch (316:6): [True: 0, False: 103] ------------------ 317| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 318| 0| goto out; 319| 0| } 320| 103| if (!ECDSA_SIG_set0(esig, sig_r, sig_s)) { ------------------ | Branch (320:6): [True: 0, False: 103] ------------------ 321| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 322| 0| goto out; 323| 0| } 324| 103| sig_r = sig_s = NULL; /* transferred */ 325| | 326| | /* Reconstruct data that was supposedly signed */ 327| 103| if ((original_signed = sshbuf_new()) == NULL) { ------------------ | | 44| 103|#define sshbuf_new() sshbuf_new_label(__func__) ------------------ | Branch (327:6): [True: 0, False: 103] ------------------ 328| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 329| 0| goto out; 330| 0| } 331| 103| if (is_webauthn) { ------------------ | Branch (331:6): [True: 97, False: 6] ------------------ 332| 97| if ((ret = webauthn_check_prepare_hash(data, dlen, ------------------ | Branch (332:7): [True: 97, False: 0] ------------------ 333| 97| webauthn_origin, webauthn_wrapper, sig_flags, webauthn_exts, 334| 97| msghash, sizeof(msghash))) != 0) 335| 97| goto out; 336| 97| } else if ((ret = ssh_digest_memory(SSH_DIGEST_SHA256, data, dlen, ------------------ | | 27| 6|#define SSH_DIGEST_SHA256 2 ------------------ | Branch (336:13): [True: 0, False: 6] ------------------ 337| 6| msghash, sizeof(msghash))) != 0) 338| 0| goto out; 339| | /* Application value is hashed before signature */ 340| 6| if ((ret = ssh_digest_memory(SSH_DIGEST_SHA256, key->sk_application, ------------------ | | 27| 6|#define SSH_DIGEST_SHA256 2 ------------------ | Branch (340:6): [True: 0, False: 6] ------------------ 341| 6| strlen(key->sk_application), apphash, sizeof(apphash))) != 0) 342| 0| goto out; 343| |#ifdef DEBUG_SK 344| | fprintf(stderr, "%s: hashed application:\n", __func__); 345| | sshbuf_dump_data(apphash, sizeof(apphash), stderr); 346| | fprintf(stderr, "%s: hashed message:\n", __func__); 347| | sshbuf_dump_data(msghash, sizeof(msghash), stderr); 348| |#endif 349| 6| if ((ret = sshbuf_put(original_signed, ------------------ | Branch (349:6): [True: 0, False: 6] ------------------ 350| 6| apphash, sizeof(apphash))) != 0 || 351| 6| (ret = sshbuf_put_u8(original_signed, sig_flags)) != 0 || ------------------ | Branch (351:6): [True: 0, False: 6] ------------------ 352| 6| (ret = sshbuf_put_u32(original_signed, sig_counter)) != 0 || ------------------ | Branch (352:6): [True: 0, False: 6] ------------------ 353| 6| (ret = sshbuf_putb(original_signed, webauthn_exts)) != 0 || ------------------ | Branch (353:6): [True: 0, False: 6] ------------------ 354| 6| (ret = sshbuf_put(original_signed, msghash, sizeof(msghash))) != 0) ------------------ | Branch (354:6): [True: 0, False: 6] ------------------ 355| 0| goto out; 356| 6| details->sk_counter = sig_counter; 357| 6| details->sk_flags = sig_flags; 358| |#ifdef DEBUG_SK 359| | fprintf(stderr, "%s: signed buf:\n", __func__); 360| | sshbuf_dump(original_signed, stderr); 361| |#endif 362| | 363| 6| if ((md_ctx = EVP_MD_CTX_new()) == NULL) { ------------------ | Branch (363:6): [True: 0, False: 6] ------------------ 364| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 365| 0| goto out; 366| 0| } 367| 6| if ((len = i2d_ECDSA_SIG(esig, NULL)) <= 0) { ------------------ | Branch (367:6): [True: 0, False: 6] ------------------ 368| 0| len = 0; 369| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 370| 0| goto out; 371| 0| } 372| 6| if ((sigb = calloc(1, len)) == NULL) { ------------------ | Branch (372:6): [True: 0, False: 6] ------------------ 373| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 374| 0| goto out; 375| 0| } 376| 6| cp = sigb; /* ASN1_item_i2d increments the pointer past the object */ 377| 6| if (i2d_ECDSA_SIG(esig, &cp) != len) { ------------------ | Branch (377:6): [True: 0, False: 6] ------------------ 378| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 379| 0| goto out; 380| 0| } 381| |#ifdef DEBUG_SK 382| | fprintf(stderr, "%s: signed hash:\n", __func__); 383| | sshbuf_dump_data(sigb, len, stderr); 384| |#endif 385| | /* Verify it */ 386| 6| if (EVP_DigestVerifyInit(md_ctx, NULL, EVP_sha256(), NULL, ------------------ | Branch (386:6): [True: 0, False: 6] ------------------ 387| 6| key->pkey) != 1) { 388| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 389| 0| goto out; 390| 0| } 391| 6| switch (EVP_DigestVerify(md_ctx, sigb, len, 392| 6| sshbuf_ptr(original_signed), sshbuf_len(original_signed))) { 393| 0| case 1: ------------------ | Branch (393:2): [True: 0, False: 6] ------------------ 394| 0| ret = 0; 395| 0| break; 396| 6| case 0: ------------------ | Branch (396:2): [True: 6, False: 0] ------------------ 397| 6| ret = SSH_ERR_SIGNATURE_INVALID; ------------------ | | 45| 6|#define SSH_ERR_SIGNATURE_INVALID -21 ------------------ 398| 6| goto out; 399| 0| default: ------------------ | Branch (399:2): [True: 0, False: 6] ------------------ 400| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 401| 0| goto out; 402| 6| } 403| | /* success */ 404| 0| if (detailsp != NULL) { ------------------ | Branch (404:6): [True: 0, False: 0] ------------------ 405| 0| *detailsp = details; 406| 0| details = NULL; 407| 0| } 408| 442| out: 409| 442| explicit_bzero(&sig_flags, sizeof(sig_flags)); 410| 442| explicit_bzero(&sig_counter, sizeof(sig_counter)); 411| 442| explicit_bzero(msghash, sizeof(msghash)); 412| 442| explicit_bzero(apphash, sizeof(apphash)); 413| 442| sshkey_sig_details_free(details); 414| 442| sshbuf_free(webauthn_wrapper); 415| 442| sshbuf_free(webauthn_exts); 416| 442| free(webauthn_origin); 417| 442| sshbuf_free(original_signed); 418| 442| sshbuf_free(sigbuf); 419| 442| sshbuf_free(b); 420| 442| ECDSA_SIG_free(esig); 421| 442| BN_clear_free(sig_r); 422| 442| BN_clear_free(sig_s); 423| 442| free(ktype); 424| 442| freezero(sigb, len); 425| 442| EVP_MD_CTX_free(md_ctx); 426| 442| return ret; 427| 0|} ssh-ecdsa-sk.c:webauthn_check_prepare_hash: 160| 97|{ 161| 97| int r = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 97|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 162| 97| struct sshbuf *chall = NULL, *m = NULL; 163| | 164| 97| if ((m = sshbuf_new()) == NULL || ------------------ | | 44| 97|#define sshbuf_new() sshbuf_new_label(__func__) ------------------ | Branch (164:6): [True: 0, False: 97] ------------------ 165| 97| (chall = sshbuf_from(data, datalen)) == NULL) { ------------------ | Branch (165:6): [True: 0, False: 97] ------------------ 166| 0| r = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 167| 0| goto out; 168| 0| } 169| | /* 170| | * Ensure origin contains no quote character and that the flags are 171| | * consistent with what we received 172| | */ 173| 97| if (strchr(origin, '\"') != NULL || ------------------ | Branch (173:6): [True: 1, False: 96] ------------------ 174| 96| (flags & 0x40) != 0 /* AD */ || ------------------ | Branch (174:6): [True: 1, False: 95] ------------------ 175| 95| ((flags & 0x80) == 0 /* ED */) != (sshbuf_len(extensions) == 0)) { ------------------ | Branch (175:6): [True: 3, False: 92] ------------------ 176| 5| r = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 5|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 177| 5| goto out; 178| 5| } 179| | 180| | /* 181| | * Prepare the preamble to clientData that we expect, poking the 182| | * challenge and origin into their canonical positions in the 183| | * structure. The crossOrigin flag and any additional extension 184| | * fields present are ignored. 185| | */ 186| 92|#define WEBAUTHN_0 "{\"type\":\"webauthn.get\",\"challenge\":\"" 187| 92|#define WEBAUTHN_1 "\",\"origin\":\"" 188| 92|#define WEBAUTHN_2 "\"" 189| 92| if ((r = sshbuf_put(m, WEBAUTHN_0, sizeof(WEBAUTHN_0) - 1)) != 0 || ------------------ | | 186| 92|#define WEBAUTHN_0 "{\"type\":\"webauthn.get\",\"challenge\":\"" ------------------ if ((r = sshbuf_put(m, WEBAUTHN_0, sizeof(WEBAUTHN_0) - 1)) != 0 || ------------------ | | 186| 92|#define WEBAUTHN_0 "{\"type\":\"webauthn.get\",\"challenge\":\"" ------------------ | Branch (189:6): [True: 0, False: 92] ------------------ 190| 92| (r = sshbuf_dtourlb64(chall, m, 0)) != 0 || ------------------ | Branch (190:6): [True: 0, False: 92] ------------------ 191| 92| (r = sshbuf_put(m, WEBAUTHN_1, sizeof(WEBAUTHN_1) - 1)) != 0 || ------------------ | | 187| 92|#define WEBAUTHN_1 "\",\"origin\":\"" ------------------ (r = sshbuf_put(m, WEBAUTHN_1, sizeof(WEBAUTHN_1) - 1)) != 0 || ------------------ | | 187| 92|#define WEBAUTHN_1 "\",\"origin\":\"" ------------------ | Branch (191:6): [True: 0, False: 92] ------------------ 192| 92| (r = sshbuf_put(m, origin, strlen(origin))) != 0 || ------------------ | Branch (192:6): [True: 0, False: 92] ------------------ 193| 92| (r = sshbuf_put(m, WEBAUTHN_2, sizeof(WEBAUTHN_2) - 1)) != 0) ------------------ | | 188| 92|#define WEBAUTHN_2 "\"" ------------------ (r = sshbuf_put(m, WEBAUTHN_2, sizeof(WEBAUTHN_2) - 1)) != 0) ------------------ | | 188| 92|#define WEBAUTHN_2 "\"" ------------------ | Branch (193:6): [True: 0, False: 92] ------------------ 194| 0| goto out; 195| |#ifdef DEBUG_SK 196| | fprintf(stderr, "%s: received origin: %s\n", __func__, origin); 197| | fprintf(stderr, "%s: received clientData:\n", __func__); 198| | sshbuf_dump(wrapper, stderr); 199| | fprintf(stderr, "%s: expected clientData preamble:\n", __func__); 200| | sshbuf_dump(m, stderr); 201| |#endif 202| | /* Check that the supplied clientData has the preamble we expect */ 203| 92| if ((r = sshbuf_cmp(wrapper, 0, sshbuf_ptr(m), sshbuf_len(m))) != 0) ------------------ | Branch (203:6): [True: 92, False: 0] ------------------ 204| 92| goto out; 205| | 206| | /* Prepare hash of clientData */ 207| 0| if ((r = ssh_digest_buffer(SSH_DIGEST_SHA256, wrapper, ------------------ | | 27| 0|#define SSH_DIGEST_SHA256 2 ------------------ | Branch (207:6): [True: 0, False: 0] ------------------ 208| 0| msghash, msghashlen)) != 0) 209| 0| goto out; 210| | 211| | /* success */ 212| 0| r = 0; 213| 97| out: 214| 97| sshbuf_free(chall); 215| 97| sshbuf_free(m); 216| 97| return r; 217| 0|} ssh-ecdsa.c:ssh_ecdsa_cleanup: 116| 963|{ 117| 963| EVP_PKEY_free(k->pkey); 118| | k->pkey = NULL; 119| 963|} ssh-ecdsa.c:ssh_ecdsa_deserialize_public: 230| 962|{ 231| 962| int r; 232| 962| char *curve = NULL; 233| 962| EVP_PKEY *pkey = NULL; 234| 962| EC_KEY *ec = NULL; 235| | 236| 962| if ((key->ecdsa_nid = sshkey_ecdsa_nid_from_name(ktype)) == -1) ------------------ | Branch (236:6): [True: 0, False: 962] ------------------ 237| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 238| 962| if ((r = sshbuf_get_cstring(b, &curve, NULL)) != 0) ------------------ | Branch (238:6): [True: 15, False: 947] ------------------ 239| 15| goto out; 240| 947| if (key->ecdsa_nid != sshkey_curve_name_to_nid(curve)) { ------------------ | Branch (240:6): [True: 126, False: 821] ------------------ 241| 126| r = SSH_ERR_EC_CURVE_MISMATCH; ------------------ | | 39| 126|#define SSH_ERR_EC_CURVE_MISMATCH -15 ------------------ 242| 126| goto out; 243| 126| } 244| 821| if ((ec = EC_KEY_new_by_curve_name(key->ecdsa_nid)) == NULL) { ------------------ | Branch (244:6): [True: 0, False: 821] ------------------ 245| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 246| 0| goto out; 247| 0| } 248| 821| if ((r = sshbuf_get_eckey(b, ec)) != 0) ------------------ | Branch (248:6): [True: 137, False: 684] ------------------ 249| 137| goto out; 250| 684| if (sshkey_ec_validate_public(EC_KEY_get0_group(ec), ------------------ | Branch (250:6): [True: 0, False: 684] ------------------ 251| 684| EC_KEY_get0_public_key(ec)) != 0) { 252| 0| r = SSH_ERR_KEY_INVALID_EC_VALUE; ------------------ | | 44| 0|#define SSH_ERR_KEY_INVALID_EC_VALUE -20 ------------------ 253| 0| goto out; 254| 0| } 255| 684| if ((pkey = EVP_PKEY_new()) == NULL) { ------------------ | Branch (255:6): [True: 0, False: 684] ------------------ 256| 0| r = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 257| 0| goto out; 258| 0| } 259| 684| if (EVP_PKEY_set1_EC_KEY(pkey, ec) != 1) { ------------------ | Branch (259:6): [True: 0, False: 684] ------------------ 260| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 261| 0| goto out; 262| 0| } 263| 684| EVP_PKEY_free(key->pkey); 264| 684| key->pkey = pkey; 265| 684| pkey = NULL; 266| | /* success */ 267| 684| r = 0; 268| |#ifdef DEBUG_PK 269| | sshkey_dump_ec_point( 270| | EC_KEY_get0_group(EVP_PKEY_get0_EC_KEY(key->pkey)), 271| | EC_KEY_get0_public_key(EVP_PKEY_get0_EC_KEY(key->pkey))); 272| |#endif 273| 962| out: 274| 962| EC_KEY_free(ec); 275| 962| EVP_PKEY_free(pkey); 276| 962| free(curve); 277| 962| return r; 278| 684|} ssh-ecdsa.c:ssh_ecdsa_deserialize_private: 283| 300|{ 284| 300| int r; 285| 300| BIGNUM *exponent = NULL; 286| 300| EC_KEY *ec = NULL; 287| | 288| 300| if (!sshkey_is_cert(key)) { ------------------ | Branch (288:6): [True: 300, False: 0] ------------------ 289| 300| if ((r = ssh_ecdsa_deserialize_public(ktype, b, key)) != 0) ------------------ | Branch (289:7): [True: 256, False: 44] ------------------ 290| 256| return r; 291| 300| } 292| 44| if ((r = sshbuf_get_bignum2(b, &exponent)) != 0) ------------------ | Branch (292:6): [True: 5, False: 39] ------------------ 293| 5| goto out; 294| 39| if ((ec = EVP_PKEY_get1_EC_KEY(key->pkey)) == NULL) { ------------------ | Branch (294:6): [True: 0, False: 39] ------------------ 295| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 296| 0| goto out; 297| 0| } 298| 39| if (EC_KEY_set_private_key(ec, exponent) != 1) { ------------------ | Branch (298:6): [True: 0, False: 39] ------------------ 299| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 300| 0| goto out; 301| 0| } 302| 39| if ((r = sshkey_ec_validate_private(ec)) != 0) ------------------ | Branch (302:6): [True: 34, False: 5] ------------------ 303| 34| goto out; 304| 5| if (EVP_PKEY_set1_EC_KEY(key->pkey, ec) != 1) { ------------------ | Branch (304:6): [True: 0, False: 5] ------------------ 305| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 306| 0| goto out; 307| 0| } 308| | /* success */ 309| 5| r = 0; 310| 44| out: 311| 44| BN_clear_free(exponent); 312| 44| EC_KEY_free(ec); 313| 44| return r; 314| 5|} ssh-ecdsa.c:ssh_ecdsa_verify: 410| 174|{ 411| 174| ECDSA_SIG *esig = NULL; 412| 174| BIGNUM *sig_r = NULL, *sig_s = NULL; 413| 174| int hash_alg, len = 0; 414| 174| int ret = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 174|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 415| 174| struct sshbuf *b = NULL, *sigbuf = NULL; 416| 174| char *ktype = NULL; 417| 174| unsigned char *sigb = NULL, *cp; 418| | 419| 174| if (key == NULL || key->pkey == NULL || ------------------ | Branch (419:6): [True: 0, False: 174] | Branch (419:21): [True: 0, False: 174] ------------------ 420| 174| sshkey_type_plain(key->type) != KEY_ECDSA || ------------------ | Branch (420:6): [True: 0, False: 174] ------------------ 421| 174| sig == NULL || siglen == 0) ------------------ | Branch (421:6): [True: 0, False: 174] | Branch (421:21): [True: 0, False: 174] ------------------ 422| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 423| | 424| 174| if ((hash_alg = sshkey_ec_nid_to_hash_alg(key->ecdsa_nid)) == -1) ------------------ | Branch (424:6): [True: 0, False: 174] ------------------ 425| 0| return SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 0|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 426| | 427| | /* fetch signature */ 428| 174| if ((b = sshbuf_from(sig, siglen)) == NULL) ------------------ | Branch (428:6): [True: 0, False: 174] ------------------ 429| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 430| 174| if (sshbuf_get_cstring(b, &ktype, NULL) != 0 || ------------------ | Branch (430:6): [True: 0, False: 174] ------------------ 431| 174| sshbuf_froms(b, &sigbuf) != 0) { ------------------ | Branch (431:6): [True: 5, False: 169] ------------------ 432| 5| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 5|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 433| 5| goto out; 434| 5| } 435| 169| if (strcmp(sshkey_ssh_name_plain(key), ktype) != 0) { ------------------ | Branch (435:6): [True: 141, False: 28] ------------------ 436| 141| ret = SSH_ERR_KEY_TYPE_MISMATCH; ------------------ | | 37| 141|#define SSH_ERR_KEY_TYPE_MISMATCH -13 ------------------ 437| 141| goto out; 438| 141| } 439| 28| if (sshbuf_len(b) != 0) { ------------------ | Branch (439:6): [True: 11, False: 17] ------------------ 440| 11| ret = SSH_ERR_UNEXPECTED_TRAILING_DATA; ------------------ | | 47| 11|#define SSH_ERR_UNEXPECTED_TRAILING_DATA -23 ------------------ 441| 11| goto out; 442| 11| } 443| | 444| | /* parse signature */ 445| 17| if (sshbuf_get_bignum2(sigbuf, &sig_r) != 0 || ------------------ | Branch (445:6): [True: 2, False: 15] ------------------ 446| 15| sshbuf_get_bignum2(sigbuf, &sig_s) != 0) { ------------------ | Branch (446:6): [True: 2, False: 13] ------------------ 447| 4| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 4|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 448| 4| goto out; 449| 4| } 450| 13| if (sshbuf_len(sigbuf) != 0) { ------------------ | Branch (450:6): [True: 6, False: 7] ------------------ 451| 6| ret = SSH_ERR_UNEXPECTED_TRAILING_DATA; ------------------ | | 47| 6|#define SSH_ERR_UNEXPECTED_TRAILING_DATA -23 ------------------ 452| 6| goto out; 453| 6| } 454| | 455| 7| if ((esig = ECDSA_SIG_new()) == NULL) { ------------------ | Branch (455:6): [True: 0, False: 7] ------------------ 456| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 457| 0| goto out; 458| 0| } 459| 7| if (!ECDSA_SIG_set0(esig, sig_r, sig_s)) { ------------------ | Branch (459:6): [True: 0, False: 7] ------------------ 460| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 461| 0| goto out; 462| 0| } 463| 7| sig_r = sig_s = NULL; /* transferred */ 464| | 465| 7| if ((len = i2d_ECDSA_SIG(esig, NULL)) <= 0) { ------------------ | Branch (465:6): [True: 0, False: 7] ------------------ 466| 0| len = 0; 467| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 468| 0| goto out; 469| 0| } 470| 7| if ((sigb = calloc(1, len)) == NULL) { ------------------ | Branch (470:6): [True: 0, False: 7] ------------------ 471| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 472| 0| goto out; 473| 0| } 474| 7| cp = sigb; /* ASN1_item_i2d increments the pointer past the object */ 475| 7| if (i2d_ECDSA_SIG(esig, &cp) != len) { ------------------ | Branch (475:6): [True: 0, False: 7] ------------------ 476| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 477| 0| goto out; 478| 0| } 479| 7| if ((ret = sshkey_pkey_digest_verify(key->pkey, hash_alg, ------------------ | Branch (479:6): [True: 7, False: 0] ------------------ 480| 7| data, dlen, sigb, len)) != 0) 481| 7| goto out; 482| | /* success */ 483| 174| out: 484| 174| freezero(sigb, len); 485| 174| sshbuf_free(sigbuf); 486| 174| sshbuf_free(b); 487| 174| ECDSA_SIG_free(esig); 488| 174| BN_clear_free(sig_r); 489| 174| BN_clear_free(sig_s); 490| 174| free(ktype); 491| 174| return ret; 492| 7|} ssh-ed25519-sk.c:ssh_ed25519_sk_cleanup: 41| 405|{ 42| 405| sshkey_sk_cleanup(k); 43| 405| sshkey_ed25519_funcs.cleanup(k); 44| 405|} ssh-ed25519-sk.c:ssh_ed25519_sk_deserialize_public: 99| 197|{ 100| 197| int r; 101| | 102| 197| if ((r = sshkey_ed25519_funcs.deserialize_public(ktype, b, key)) != 0) ------------------ | Branch (102:6): [True: 2, False: 195] ------------------ 103| 2| return r; 104| 195| if ((r = sshkey_deserialize_sk(b, key)) != 0) ------------------ | Branch (104:6): [True: 2, False: 193] ------------------ 105| 2| return r; 106| 193| return 0; 107| 195|} ssh-ed25519-sk.c:ssh_ed25519_sk_deserialize_private: 112| 207|{ 113| 207| int r; 114| | 115| 207| if ((r = sshkey_ed25519_funcs.deserialize_public(ktype, b, key)) != 0) ------------------ | Branch (115:6): [True: 25, False: 182] ------------------ 116| 25| return r; 117| 182| if ((r = sshkey_private_deserialize_sk(b, key)) != 0) ------------------ | Branch (117:6): [True: 127, False: 55] ------------------ 118| 127| return r; 119| 55| return 0; 120| 182|} ssh-ed25519-sk.c:ssh_ed25519_sk_verify: 127| 155|{ 128| 155| struct sshbuf *b = NULL; 129| 155| struct sshbuf *encoded = NULL; 130| 155| char *ktype = NULL; 131| 155| const u_char *sigblob; 132| 155| u_char apphash[32]; 133| 155| u_char msghash[32]; 134| 155| u_char sig_flags; 135| 155| u_int sig_counter; 136| 155| size_t len; 137| 155| int r = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 155|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 138| 155| int ret; 139| 155| struct sshkey_sig_details *details = NULL; 140| | 141| 155| if (detailsp != NULL) ------------------ | Branch (141:6): [True: 0, False: 155] ------------------ 142| 0| *detailsp = NULL; 143| | 144| 155| if (key == NULL || ------------------ | Branch (144:6): [True: 0, False: 155] ------------------ 145| 155| sshkey_type_plain(key->type) != KEY_ED25519_SK || ------------------ | Branch (145:6): [True: 0, False: 155] ------------------ 146| 155| key->ed25519_pk == NULL || ------------------ | Branch (146:6): [True: 0, False: 155] ------------------ 147| 155| sig == NULL || siglen == 0) ------------------ | Branch (147:6): [True: 0, False: 155] | Branch (147:21): [True: 0, False: 155] ------------------ 148| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 149| | 150| 155| if ((b = sshbuf_from(sig, siglen)) == NULL) ------------------ | Branch (150:6): [True: 0, False: 155] ------------------ 151| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 152| 155| if (sshbuf_get_cstring(b, &ktype, NULL) != 0 || ------------------ | Branch (152:6): [True: 0, False: 155] ------------------ 153| 155| sshbuf_get_string_direct(b, &sigblob, &len) != 0 || ------------------ | Branch (153:6): [True: 10, False: 145] ------------------ 154| 145| sshbuf_get_u8(b, &sig_flags) != 0 || ------------------ | Branch (154:6): [True: 5, False: 140] ------------------ 155| 140| sshbuf_get_u32(b, &sig_counter) != 0) { ------------------ | Branch (155:6): [True: 3, False: 137] ------------------ 156| 18| r = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 18|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 157| 18| goto out; 158| 18| } 159| |#ifdef DEBUG_SK 160| | fprintf(stderr, "%s: data:\n", __func__); 161| | /* sshbuf_dump_data(data, datalen, stderr); */ 162| | fprintf(stderr, "%s: sigblob:\n", __func__); 163| | sshbuf_dump_data(sigblob, len, stderr); 164| | fprintf(stderr, "%s: sig_flags = 0x%02x, sig_counter = %u\n", 165| | __func__, sig_flags, sig_counter); 166| |#endif 167| 137| if (strcmp(sshkey_ssh_name_plain(key), ktype) != 0) { ------------------ | Branch (167:6): [True: 119, False: 18] ------------------ 168| 119| r = SSH_ERR_KEY_TYPE_MISMATCH; ------------------ | | 37| 119|#define SSH_ERR_KEY_TYPE_MISMATCH -13 ------------------ 169| 119| goto out; 170| 119| } 171| 18| if (sshbuf_len(b) != 0) { ------------------ | Branch (171:6): [True: 7, False: 11] ------------------ 172| 7| r = SSH_ERR_UNEXPECTED_TRAILING_DATA; ------------------ | | 47| 7|#define SSH_ERR_UNEXPECTED_TRAILING_DATA -23 ------------------ 173| 7| goto out; 174| 7| } 175| 11| if (len != crypto_sign_ed25519_BYTES) { ------------------ | | 62| 11|#define crypto_sign_ed25519_BYTES 64U ------------------ | Branch (175:6): [True: 10, False: 1] ------------------ 176| 10| r = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 10|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 177| 10| goto out; 178| 10| } 179| 1| if (ssh_digest_memory(SSH_DIGEST_SHA256, key->sk_application, ------------------ | | 27| 1|#define SSH_DIGEST_SHA256 2 ------------------ | Branch (179:6): [True: 0, False: 1] ------------------ 180| 1| strlen(key->sk_application), apphash, sizeof(apphash)) != 0 || 181| 1| ssh_digest_memory(SSH_DIGEST_SHA256, data, dlen, ------------------ | | 27| 1|#define SSH_DIGEST_SHA256 2 ------------------ | Branch (181:6): [True: 0, False: 1] ------------------ 182| 1| msghash, sizeof(msghash)) != 0) { 183| 0| r = SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 184| 0| goto out; 185| 0| } 186| |#ifdef DEBUG_SK 187| | fprintf(stderr, "%s: hashed application:\n", __func__); 188| | sshbuf_dump_data(apphash, sizeof(apphash), stderr); 189| | fprintf(stderr, "%s: hashed message:\n", __func__); 190| | sshbuf_dump_data(msghash, sizeof(msghash), stderr); 191| |#endif 192| 1| if ((details = calloc(1, sizeof(*details))) == NULL) { ------------------ | Branch (192:6): [True: 0, False: 1] ------------------ 193| 0| r = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 194| 0| goto out; 195| 0| } 196| 1| details->sk_counter = sig_counter; 197| 1| details->sk_flags = sig_flags; 198| 1| if ((encoded = sshbuf_new()) == NULL) { ------------------ | | 44| 1|#define sshbuf_new() sshbuf_new_label(__func__) ------------------ | Branch (198:6): [True: 0, False: 1] ------------------ 199| 0| r = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 200| 0| goto out; 201| 0| } 202| 1| if (sshbuf_put(encoded, apphash, sizeof(apphash)) != 0 || ------------------ | Branch (202:6): [True: 0, False: 1] ------------------ 203| 1| sshbuf_put_u8(encoded, sig_flags) != 0 || ------------------ | Branch (203:6): [True: 0, False: 1] ------------------ 204| 1| sshbuf_put_u32(encoded, sig_counter) != 0 || ------------------ | Branch (204:6): [True: 0, False: 1] ------------------ 205| 1| sshbuf_put(encoded, msghash, sizeof(msghash)) != 0) { ------------------ | Branch (205:6): [True: 0, False: 1] ------------------ 206| 0| r = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 207| 0| goto out; 208| 0| } 209| |#ifdef DEBUG_SK 210| | fprintf(stderr, "%s: signed buf:\n", __func__); 211| | sshbuf_dump(encoded, stderr); 212| |#endif 213| 1| if ((ret = crypto_sign_ed25519_verify_detached(sigblob, ------------------ | Branch (213:6): [True: 1, False: 0] ------------------ 214| 1| sshbuf_ptr(encoded), sshbuf_len(encoded), 215| 1| key->ed25519_pk)) != 0) { 216| 1| debug2_f("crypto_sign_ed25519_verify_detached failed: %d", ret); ------------------ | | 121| 1|#define debug2_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG2, NULL, __VA_ARGS__) ------------------ 217| 1| } 218| 1| if (ret != 0) { ------------------ | Branch (218:6): [True: 1, False: 0] ------------------ 219| 1| r = SSH_ERR_SIGNATURE_INVALID; ------------------ | | 45| 1|#define SSH_ERR_SIGNATURE_INVALID -21 ------------------ 220| 1| goto out; 221| 1| } 222| | /* success */ 223| 0| r = 0; 224| 0| if (detailsp != NULL) { ------------------ | Branch (224:6): [True: 0, False: 0] ------------------ 225| 0| *detailsp = details; 226| 0| details = NULL; 227| 0| } 228| 155| out: 229| 155| sshkey_sig_details_free(details); 230| 155| sshbuf_free(b); 231| 155| sshbuf_free(encoded); 232| 155| free(ktype); 233| 155| return r; 234| 0|} ssh-ed25519.c:ssh_ed25519_cleanup: 36| 2.38k|{ 37| 2.38k| freezero(k->ed25519_pk, ED25519_PK_SZ); ------------------ | | 141| 2.38k|#define ED25519_PK_SZ crypto_sign_ed25519_PUBLICKEYBYTES | | ------------------ | | | | 60| 2.38k|#define crypto_sign_ed25519_PUBLICKEYBYTES 32U | | ------------------ ------------------ 38| 2.38k| freezero(k->ed25519_sk, ED25519_SK_SZ); ------------------ | | 140| 2.38k|#define ED25519_SK_SZ crypto_sign_ed25519_SECRETKEYBYTES | | ------------------ | | | | 59| 2.38k|#define crypto_sign_ed25519_SECRETKEYBYTES 64U | | ------------------ ------------------ 39| 2.38k| k->ed25519_pk = NULL; 40| | k->ed25519_sk = NULL; 41| 2.38k|} ssh-ed25519.c:ssh_ed25519_deserialize_public: 107| 2.51k|{ 108| 2.51k| u_char *pk = NULL; 109| 2.51k| size_t len = 0; 110| 2.51k| int r; 111| | 112| 2.51k| if ((r = sshbuf_get_string(b, &pk, &len)) != 0) ------------------ | Branch (112:6): [True: 77, False: 2.44k] ------------------ 113| 77| return r; 114| 2.44k| if (len != ED25519_PK_SZ) { ------------------ | | 141| 2.44k|#define ED25519_PK_SZ crypto_sign_ed25519_PUBLICKEYBYTES | | ------------------ | | | | 60| 2.44k|#define crypto_sign_ed25519_PUBLICKEYBYTES 32U | | ------------------ ------------------ | Branch (114:6): [True: 82, False: 2.35k] ------------------ 115| 82| freezero(pk, len); 116| 82| return SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 82|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 117| 82| } 118| 2.35k| key->ed25519_pk = pk; 119| 2.35k| return 0; 120| 2.44k|} ssh-ed25519.c:ssh_ed25519_deserialize_private: 125| 288|{ 126| 288| int r; 127| 288| size_t sklen = 0; 128| 288| u_char *ed25519_sk = NULL; 129| | 130| 288| if ((r = ssh_ed25519_deserialize_public(NULL, b, key)) != 0) ------------------ | Branch (130:6): [True: 121, False: 167] ------------------ 131| 121| goto out; 132| 167| if ((r = sshbuf_get_string(b, &ed25519_sk, &sklen)) != 0) ------------------ | Branch (132:6): [True: 7, False: 160] ------------------ 133| 7| goto out; 134| 160| if (sklen != ED25519_SK_SZ) { ------------------ | | 140| 160|#define ED25519_SK_SZ crypto_sign_ed25519_SECRETKEYBYTES | | ------------------ | | | | 59| 160|#define crypto_sign_ed25519_SECRETKEYBYTES 64U | | ------------------ ------------------ | Branch (134:6): [True: 27, False: 133] ------------------ 135| 27| r = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 27|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 136| 27| goto out; 137| 27| } 138| 133| key->ed25519_sk = ed25519_sk; 139| 133| ed25519_sk = NULL; /* transferred */ 140| | /* success */ 141| 133| r = 0; 142| 288| out: 143| 288| freezero(ed25519_sk, sklen); 144| 288| return r; 145| 133|} ssh-ed25519.c:ssh_ed25519_verify: 229| 275|{ 230| 275| struct sshbuf *b = NULL; 231| 275| char *ktype = NULL; 232| 275| const u_char *sigblob; 233| 275| size_t len; 234| 275| int r, ret; 235| | 236| 275| if (key == NULL || ------------------ | Branch (236:6): [True: 0, False: 275] ------------------ 237| 275| sshkey_type_plain(key->type) != KEY_ED25519 || ------------------ | Branch (237:6): [True: 0, False: 275] ------------------ 238| 275| key->ed25519_pk == NULL || ------------------ | Branch (238:6): [True: 0, False: 275] ------------------ 239| 275| sig == NULL || siglen == 0) ------------------ | Branch (239:6): [True: 0, False: 275] | Branch (239:21): [True: 0, False: 275] ------------------ 240| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 241| | 242| 275| if ((b = sshbuf_from(sig, siglen)) == NULL) ------------------ | Branch (242:6): [True: 0, False: 275] ------------------ 243| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 244| 275| if ((r = sshbuf_get_cstring(b, &ktype, NULL)) != 0 || ------------------ | Branch (244:6): [True: 0, False: 275] ------------------ 245| 275| (r = sshbuf_get_string_direct(b, &sigblob, &len)) != 0) ------------------ | Branch (245:6): [True: 20, False: 255] ------------------ 246| 20| goto out; 247| 255| if (strcmp("ssh-ed25519", ktype) != 0) { ------------------ | Branch (247:6): [True: 93, False: 162] ------------------ 248| 93| r = SSH_ERR_KEY_TYPE_MISMATCH; ------------------ | | 37| 93|#define SSH_ERR_KEY_TYPE_MISMATCH -13 ------------------ 249| 93| goto out; 250| 93| } 251| 162| if (sshbuf_len(b) != 0) { ------------------ | Branch (251:6): [True: 16, False: 146] ------------------ 252| 16| r = SSH_ERR_UNEXPECTED_TRAILING_DATA; ------------------ | | 47| 16|#define SSH_ERR_UNEXPECTED_TRAILING_DATA -23 ------------------ 253| 16| goto out; 254| 16| } 255| 146| if (len != crypto_sign_ed25519_BYTES) { ------------------ | | 62| 146|#define crypto_sign_ed25519_BYTES 64U ------------------ | Branch (255:6): [True: 4, False: 142] ------------------ 256| 4| r = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 4|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 257| 4| goto out; 258| 4| } 259| 142| if ((ret = crypto_sign_ed25519_verify_detached(sigblob, data, dlen, ------------------ | Branch (259:6): [True: 1, False: 141] ------------------ 260| 142| key->ed25519_pk)) != 0) { 261| 1| debug2_f("crypto_sign_ed25519_verify_detached failed: %d", ret); ------------------ | | 121| 1|#define debug2_f(...) sshlog(__FILE__, __func__, __LINE__, 1, SYSLOG_LEVEL_DEBUG2, NULL, __VA_ARGS__) ------------------ 262| 1| } 263| 142| if (ret != 0) { ------------------ | Branch (263:6): [True: 1, False: 141] ------------------ 264| 1| r = SSH_ERR_SIGNATURE_INVALID; ------------------ | | 45| 1|#define SSH_ERR_SIGNATURE_INVALID -21 ------------------ 265| 1| goto out; 266| 1| } 267| | /* success */ 268| 141| r = 0; 269| 275| out: 270| 275| sshbuf_free(b); 271| 275| free(ktype); 272| 275| return r; 273| 141|} ssh-mldsa-eddsa.c:ssh_mldsa44_ed25519_cleanup: 225| 75|{ 226| 75| freezero(k->mldsa_ed25519_pk, MLDSA44_ED25519_PK_SZ); ------------------ | | 187| 75|#define MLDSA44_ED25519_PK_SZ (MLDSA44_PUBLICKEYBYTES + crypto_sign_ed25519_PUBLICKEYBYTES) | | ------------------ | | | | 113| 75|#define MLDSA44_PUBLICKEYBYTES 1312 | | ------------------ | | #define MLDSA44_ED25519_PK_SZ (MLDSA44_PUBLICKEYBYTES + crypto_sign_ed25519_PUBLICKEYBYTES) | | ------------------ | | | | 60| 75|#define crypto_sign_ed25519_PUBLICKEYBYTES 32U | | ------------------ ------------------ 227| 75| freezero(k->mldsa_ed25519_sk, MLDSA44_ED25519_SK_SZ); ------------------ | | 188| 75|#define MLDSA44_ED25519_SK_SZ (MLDSA44_SEEDBYTES + crypto_sign_ed25519_SEEDBYTES) | | ------------------ | | | | 116| 75|#define MLDSA44_SEEDBYTES 32 | | ------------------ | | #define MLDSA44_ED25519_SK_SZ (MLDSA44_SEEDBYTES + crypto_sign_ed25519_SEEDBYTES) | | ------------------ | | | | 61| 75|#define crypto_sign_ed25519_SEEDBYTES 32U | | ------------------ ------------------ 228| 75| k->mldsa_ed25519_pk = NULL; 229| | k->mldsa_ed25519_sk = NULL; 230| 75|} ssh-mldsa-eddsa.c:ssh_mldsa44_ed25519_deserialize_public: 281| 73|{ 282| 73| u_char *pk = NULL; 283| 73| size_t len = 0; 284| 73| int r; 285| | 286| 73| if ((r = sshbuf_get_string(b, &pk, &len)) != 0) ------------------ | Branch (286:6): [True: 5, False: 68] ------------------ 287| 5| return r; 288| 68| if (len != MLDSA44_ED25519_PK_SZ) { ------------------ | | 187| 68|#define MLDSA44_ED25519_PK_SZ (MLDSA44_PUBLICKEYBYTES + crypto_sign_ed25519_PUBLICKEYBYTES) | | ------------------ | | | | 113| 68|#define MLDSA44_PUBLICKEYBYTES 1312 | | ------------------ | | #define MLDSA44_ED25519_PK_SZ (MLDSA44_PUBLICKEYBYTES + crypto_sign_ed25519_PUBLICKEYBYTES) | | ------------------ | | | | 60| 68|#define crypto_sign_ed25519_PUBLICKEYBYTES 32U | | ------------------ ------------------ | Branch (288:6): [True: 41, False: 27] ------------------ 289| 41| freezero(pk, len); 290| 41| return SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 41|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 291| 41| } 292| 27| key->mldsa_ed25519_pk = pk; 293| 27| return 0; 294| 68|} ssh-mldsa-eddsa.c:ssh_mldsa44_ed25519_deserialize_private: 299| 52|{ 300| 52| int r; 301| 52| size_t sklen = 0; 302| 52| u_char *sk = NULL; 303| | 304| 52| if (!sshkey_is_cert(key)) { ------------------ | Branch (304:6): [True: 52, False: 0] ------------------ 305| 52| if ((r = ssh_mldsa44_ed25519_deserialize_public(ktype, ------------------ | Branch (305:7): [True: 26, False: 26] ------------------ 306| 52| b, key)) != 0) 307| 26| return r; 308| 52| } 309| 26| if ((r = sshbuf_get_string(b, &sk, &sklen)) != 0) ------------------ | Branch (309:6): [True: 2, False: 24] ------------------ 310| 2| goto out; 311| 24| if (sklen != MLDSA44_ED25519_SK_SZ) { ------------------ | | 188| 24|#define MLDSA44_ED25519_SK_SZ (MLDSA44_SEEDBYTES + crypto_sign_ed25519_SEEDBYTES) | | ------------------ | | | | 116| 24|#define MLDSA44_SEEDBYTES 32 | | ------------------ | | #define MLDSA44_ED25519_SK_SZ (MLDSA44_SEEDBYTES + crypto_sign_ed25519_SEEDBYTES) | | ------------------ | | | | 61| 24|#define crypto_sign_ed25519_SEEDBYTES 32U | | ------------------ ------------------ | Branch (311:6): [True: 23, False: 1] ------------------ 312| 23| r = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 23|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 313| 23| goto out; 314| 23| } 315| 1| key->mldsa_ed25519_sk = sk; 316| 1| sk = NULL; /* transferred */ 317| 1| r = 0; 318| 26| out: 319| 26| freezero(sk, sklen); 320| 26| return r; 321| 1|} ssh_rsa_complete_crt_parameters: 396| 11|{ 397| 11| BIGNUM *aux = NULL, *d_consttime = NULL; 398| 11| BN_CTX *ctx = NULL; 399| 11| int r; 400| | 401| 11| *rsa_dmq1 = *rsa_dmp1 = NULL; 402| 11| if ((ctx = BN_CTX_new()) == NULL) ------------------ | Branch (402:6): [True: 0, False: 11] ------------------ 403| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 404| 11| if ((aux = BN_new()) == NULL || ------------------ | Branch (404:6): [True: 0, False: 11] ------------------ 405| 11| (*rsa_dmq1 = BN_new()) == NULL || ------------------ | Branch (405:6): [True: 0, False: 11] ------------------ 406| 11| (*rsa_dmp1 = BN_new()) == NULL) ------------------ | Branch (406:6): [True: 0, False: 11] ------------------ 407| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 408| 11| if ((d_consttime = BN_dup(rsa_d)) == NULL) { ------------------ | Branch (408:6): [True: 0, False: 11] ------------------ 409| 0| r = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 410| 0| goto out; 411| 0| } 412| 11| BN_set_flags(aux, BN_FLG_CONSTTIME); 413| 11| BN_set_flags(d_consttime, BN_FLG_CONSTTIME); 414| | 415| 11| if ((BN_sub(aux, rsa_q, BN_value_one()) == 0) || ------------------ | Branch (415:6): [True: 0, False: 11] ------------------ 416| 11| (BN_mod(*rsa_dmq1, d_consttime, aux, ctx) == 0) || ------------------ | Branch (416:6): [True: 6, False: 5] ------------------ 417| 5| (BN_sub(aux, rsa_p, BN_value_one()) == 0) || ------------------ | Branch (417:6): [True: 0, False: 5] ------------------ 418| 7| (BN_mod(*rsa_dmp1, d_consttime, aux, ctx) == 0)) { ------------------ | Branch (418:6): [True: 1, False: 4] ------------------ 419| 7| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 7|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 420| 7| goto out; 421| 7| } 422| | /* success */ 423| 4| r = 0; 424| 11| out: 425| 11| BN_clear_free(aux); 426| 11| BN_clear_free(d_consttime); 427| 11| BN_CTX_free(ctx); 428| 11| return r; 429| 4|} ssh-rsa.c:rsa_hash_id_from_ident: 361| 208|{ 362| 208| if (strcmp(ident, "ssh-rsa") == 0) ------------------ | Branch (362:6): [True: 27, False: 181] ------------------ 363| 27| return SSH_DIGEST_SHA1; ------------------ | | 26| 27|#define SSH_DIGEST_SHA1 1 ------------------ 364| 181| if (strcmp(ident, "rsa-sha2-256") == 0) ------------------ | Branch (364:6): [True: 2, False: 179] ------------------ 365| 2| return SSH_DIGEST_SHA256; ------------------ | | 27| 2|#define SSH_DIGEST_SHA256 2 ------------------ 366| 179| if (strcmp(ident, "rsa-sha2-512") == 0) ------------------ | Branch (366:6): [True: 1, False: 178] ------------------ 367| 1| return SSH_DIGEST_SHA512; ------------------ | | 29| 1|#define SSH_DIGEST_SHA512 4 ------------------ 368| 178| return -1; 369| 179|} ssh-rsa.c:ssh_rsa_alloc: 47| 554|{ 48| 554| if ((k->pkey = EVP_PKEY_new()) == NULL) ------------------ | Branch (48:6): [True: 0, False: 554] ------------------ 49| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 50| 554| return 0; 51| 554|} ssh-rsa.c:ssh_rsa_cleanup: 55| 554|{ 56| 554| EVP_PKEY_free(k->pkey); 57| | k->pkey = NULL; 58| 554|} ssh-rsa.c:ssh_rsa_deserialize_public: 197| 292|{ 198| 292| int ret = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 292|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 199| 292| BIGNUM *rsa_n = NULL, *rsa_e = NULL; 200| 292| RSA *rsa = NULL; 201| | 202| 292| if ((rsa = RSA_new()) == NULL) ------------------ | Branch (202:6): [True: 0, False: 292] ------------------ 203| 0| return SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 204| | 205| 292| if (sshbuf_get_bignum2(b, &rsa_e) != 0 || ------------------ | Branch (205:6): [True: 6, False: 286] ------------------ 206| 286| sshbuf_get_bignum2(b, &rsa_n) != 0) { ------------------ | Branch (206:6): [True: 5, False: 281] ------------------ 207| 11| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 11|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 208| 11| goto out; 209| 11| } 210| 281| if (!RSA_set0_key(rsa, rsa_n, rsa_e, NULL)) { ------------------ | Branch (210:6): [True: 0, False: 281] ------------------ 211| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 212| 0| goto out; 213| 0| } 214| 281| rsa_n = rsa_e = NULL; /* transferred */ 215| 281| if (EVP_PKEY_set1_RSA(key->pkey, rsa) != 1) { ------------------ | Branch (215:6): [True: 0, False: 281] ------------------ 216| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 217| 0| goto out; 218| 0| } 219| 281| if ((ret = sshkey_check_rsa_length(key, 0)) != 0) ------------------ | Branch (219:6): [True: 20, False: 261] ------------------ 220| 20| goto out; 221| |#ifdef DEBUG_PK 222| | RSA_print_fp(stderr, rsa, 8); 223| |#endif 224| | /* success */ 225| 261| ret = 0; 226| 292| out: 227| 292| RSA_free(rsa); 228| 292| BN_clear_free(rsa_n); 229| 292| BN_clear_free(rsa_e); 230| 292| return ret; 231| 261|} ssh-rsa.c:ssh_rsa_deserialize_private: 236| 211|{ 237| 211| int r; 238| 211| BIGNUM *rsa_n = NULL, *rsa_e = NULL, *rsa_d = NULL; 239| 211| BIGNUM *rsa_iqmp = NULL, *rsa_p = NULL, *rsa_q = NULL; 240| 211| BIGNUM *rsa_dmp1 = NULL, *rsa_dmq1 = NULL, *rsa_pq = NULL; 241| 211| const BIGNUM *n = NULL, *e = NULL; 242| 211| BN_CTX *ctx = NULL; 243| 211| RSA *rsa = NULL; 244| | 245| 211| if (sshkey_is_cert(key)) { ------------------ | Branch (245:6): [True: 1, False: 210] ------------------ 246| | /* sshkey_private_deserialize already has pubkey from cert */ 247| 1| if ((rsa = EVP_PKEY_get1_RSA(key->pkey)) == NULL) { ------------------ | Branch (247:7): [True: 0, False: 1] ------------------ 248| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 249| 0| goto out; 250| 0| } 251| 210| } else { 252| 210| if ((rsa = RSA_new()) == NULL) { ------------------ | Branch (252:7): [True: 0, False: 210] ------------------ 253| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 254| 0| goto out; 255| 0| } 256| | /* Note: can't reuse ssh_rsa_deserialize_public: e,n vs. n,e */ 257| 210| if ((r = sshbuf_get_bignum2(b, &rsa_n)) != 0 || ------------------ | Branch (257:7): [True: 75, False: 135] ------------------ 258| 135| (r = sshbuf_get_bignum2(b, &rsa_e)) != 0) ------------------ | Branch (258:7): [True: 80, False: 55] ------------------ 259| 155| goto out; 260| 55| if (!RSA_set0_key(rsa, rsa_n, rsa_e, NULL)) { ------------------ | Branch (260:7): [True: 0, False: 55] ------------------ 261| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 262| 0| goto out; 263| 0| } 264| 55| rsa_n = rsa_e = NULL; /* transferred */ 265| 55| } 266| 56| if ((r = sshbuf_get_bignum2(b, &rsa_d)) != 0 || ------------------ | Branch (266:6): [True: 11, False: 45] ------------------ 267| 45| (r = sshbuf_get_bignum2(b, &rsa_iqmp)) != 0 || ------------------ | Branch (267:6): [True: 10, False: 35] ------------------ 268| 35| (r = sshbuf_get_bignum2(b, &rsa_p)) != 0 || ------------------ | Branch (268:6): [True: 8, False: 27] ------------------ 269| 27| (r = sshbuf_get_bignum2(b, &rsa_q)) != 0) ------------------ | Branch (269:6): [True: 5, False: 22] ------------------ 270| 34| goto out; 271| | /* 272| | * libcrypto doesn't check that the private values belong to the 273| | * modulus, but the cost of using the key is determined by their 274| | * size, so check them here before they can be used to sign. 275| | */ 276| 22| RSA_get0_key(rsa, &n, &e, NULL); 277| 22| if ((ctx = BN_CTX_new()) == NULL || (rsa_pq = BN_new()) == NULL) { ------------------ | Branch (277:6): [True: 0, False: 22] | Branch (277:38): [True: 0, False: 22] ------------------ 278| 0| r = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 279| 0| goto out; 280| 0| } 281| 22| if (BN_mul(rsa_pq, rsa_p, rsa_q, ctx) != 1) { ------------------ | Branch (281:6): [True: 0, False: 22] ------------------ 282| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 283| 0| goto out; 284| 0| } 285| 22| if (BN_cmp(rsa_pq, n) != 0 || BN_cmp(rsa_d, n) >= 0 || ------------------ | Branch (285:6): [True: 2, False: 20] | Branch (285:32): [True: 5, False: 15] ------------------ 286| 15| BN_cmp(rsa_iqmp, rsa_p) >= 0 || BN_cmp(e, n) >= 0) { ------------------ | Branch (286:6): [True: 2, False: 13] | Branch (286:38): [True: 2, False: 11] ------------------ 287| 11| r = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 11|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 288| 11| goto out; 289| 11| } 290| | /* Same limit on the public exponent as libcrypto's public key ops */ 291| 11| if (BN_num_bits(n) > OPENSSL_RSA_SMALL_MODULUS_BITS && ------------------ | Branch (291:6): [True: 0, False: 11] ------------------ 292| 0| BN_num_bits(e) > OPENSSL_RSA_MAX_PUBEXP_BITS) { ------------------ | Branch (292:6): [True: 0, False: 0] ------------------ 293| 0| r = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 0|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 294| 0| goto out; 295| 0| } 296| 11| if ((r = ssh_rsa_complete_crt_parameters(rsa_d, rsa_p, rsa_q, ------------------ | Branch (296:6): [True: 7, False: 4] ------------------ 297| 11| rsa_iqmp, &rsa_dmp1, &rsa_dmq1)) != 0) 298| 7| goto out; 299| 4| if (!RSA_set0_key(rsa, NULL, NULL, rsa_d)) { ------------------ | Branch (299:6): [True: 0, False: 4] ------------------ 300| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 301| 0| goto out; 302| 0| } 303| 4| rsa_d = NULL; /* transferred */ 304| 4| if (!RSA_set0_factors(rsa, rsa_p, rsa_q)) { ------------------ | Branch (304:6): [True: 0, False: 4] ------------------ 305| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 306| 0| goto out; 307| 0| } 308| 4| rsa_p = rsa_q = NULL; /* transferred */ 309| 4| if (!RSA_set0_crt_params(rsa, rsa_dmp1, rsa_dmq1, rsa_iqmp)) { ------------------ | Branch (309:6): [True: 0, False: 4] ------------------ 310| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 311| 0| goto out; 312| 0| } 313| 4| rsa_dmp1 = rsa_dmq1 = rsa_iqmp = NULL; 314| 4| if (RSA_blinding_on(rsa, NULL) != 1) { ------------------ | Branch (314:6): [True: 1, False: 3] ------------------ 315| 1| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 1|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 316| 1| goto out; 317| 1| } 318| 3| if (EVP_PKEY_set1_RSA(key->pkey, rsa) != 1) { ------------------ | Branch (318:6): [True: 0, False: 3] ------------------ 319| 0| r = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 320| 0| goto out; 321| 0| } 322| 3| if ((r = sshkey_check_rsa_length(key, 0)) != 0) ------------------ | Branch (322:6): [True: 3, False: 0] ------------------ 323| 3| goto out; 324| | /* success */ 325| 0| r = 0; 326| 211| out: 327| 211| RSA_free(rsa); 328| 211| BN_clear_free(rsa_n); 329| 211| BN_clear_free(rsa_e); 330| 211| BN_clear_free(rsa_d); 331| 211| BN_clear_free(rsa_p); 332| 211| BN_clear_free(rsa_q); 333| 211| BN_clear_free(rsa_iqmp); 334| 211| BN_clear_free(rsa_dmp1); 335| 211| BN_clear_free(rsa_dmq1); 336| 211| BN_clear_free(rsa_pq); 337| 211| BN_CTX_free(ctx); 338| 211| return r; 339| 0|} ssh-rsa.c:ssh_rsa_verify: 529| 208|{ 530| 208| char *sigtype = NULL; 531| 208| int hash_alg, want_alg, ret = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 208|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 532| 208| size_t len = 0, diff, modlen, rsasize; 533| 208| struct sshbuf *b = NULL; 534| 208| u_char digest[SSH_DIGEST_MAX_LENGTH], *osigblob, *sigblob = NULL; 535| | 536| 208| if (key == NULL || key->pkey == NULL || ------------------ | Branch (536:6): [True: 0, False: 208] | Branch (536:21): [True: 0, False: 208] ------------------ 537| 208| sshkey_type_plain(key->type) != KEY_RSA || ------------------ | Branch (537:6): [True: 0, False: 208] ------------------ 538| 208| sig == NULL || siglen == 0) ------------------ | Branch (538:6): [True: 0, False: 208] | Branch (538:21): [True: 0, False: 208] ------------------ 539| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 540| 208| if (EVP_PKEY_bits(key->pkey) < SSH_RSA_MINIMUM_MODULUS_SIZE) ------------------ | | 47| 208|#define SSH_RSA_MINIMUM_MODULUS_SIZE 1024 ------------------ | Branch (540:6): [True: 0, False: 208] ------------------ 541| 0| return SSH_ERR_KEY_LENGTH; ------------------ | | 80| 0|#define SSH_ERR_KEY_LENGTH -56 ------------------ 542| | 543| 208| if ((b = sshbuf_from(sig, siglen)) == NULL) ------------------ | Branch (543:6): [True: 0, False: 208] ------------------ 544| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 545| 208| if (sshbuf_get_cstring(b, &sigtype, NULL) != 0) { ------------------ | Branch (545:6): [True: 0, False: 208] ------------------ 546| 0| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 0|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 547| 0| goto out; 548| 0| } 549| 208| if ((hash_alg = rsa_hash_id_from_ident(sigtype)) == -1) { ------------------ | Branch (549:6): [True: 178, False: 30] ------------------ 550| 178| ret = SSH_ERR_KEY_TYPE_MISMATCH; ------------------ | | 37| 178|#define SSH_ERR_KEY_TYPE_MISMATCH -13 ------------------ 551| 178| goto out; 552| 178| } 553| | /* 554| | * Allow ssh-rsa-cert-v01 certs to generate SHA2 signatures for 555| | * legacy reasons, but otherwise the signature type should match. 556| | */ 557| 30| if (alg != NULL && strcmp(alg, "ssh-rsa-cert-v01@openssh.com") != 0) { ------------------ | Branch (557:6): [True: 0, False: 30] | Branch (557:21): [True: 0, False: 0] ------------------ 558| 0| if ((want_alg = ssh_rsa_hash_id_from_keyname(alg)) == -1) { ------------------ | Branch (558:7): [True: 0, False: 0] ------------------ 559| 0| ret = SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 560| 0| goto out; 561| 0| } 562| 0| if (hash_alg != want_alg) { ------------------ | Branch (562:7): [True: 0, False: 0] ------------------ 563| 0| ret = SSH_ERR_SIGNATURE_INVALID; ------------------ | | 45| 0|#define SSH_ERR_SIGNATURE_INVALID -21 ------------------ 564| 0| goto out; 565| 0| } 566| 0| } 567| 30| if (sshbuf_get_string(b, &sigblob, &len) != 0) { ------------------ | Branch (567:6): [True: 3, False: 27] ------------------ 568| 3| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 3|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 569| 3| goto out; 570| 3| } 571| 27| if (sshbuf_len(b) != 0) { ------------------ | Branch (571:6): [True: 8, False: 19] ------------------ 572| 8| ret = SSH_ERR_UNEXPECTED_TRAILING_DATA; ------------------ | | 47| 8|#define SSH_ERR_UNEXPECTED_TRAILING_DATA -23 ------------------ 573| 8| goto out; 574| 8| } 575| | /* RSA_verify expects a signature of RSA_size */ 576| 19| modlen = EVP_PKEY_size(key->pkey); 577| 19| if (len > modlen) { ------------------ | Branch (577:6): [True: 9, False: 10] ------------------ 578| 9| ret = SSH_ERR_KEY_BITS_MISMATCH; ------------------ | | 35| 9|#define SSH_ERR_KEY_BITS_MISMATCH -11 ------------------ 579| 9| goto out; 580| 10| } else if (len < modlen) { ------------------ | Branch (580:13): [True: 9, False: 1] ------------------ 581| 9| diff = modlen - len; 582| 9| osigblob = sigblob; 583| 9| if ((sigblob = realloc(sigblob, modlen)) == NULL) { ------------------ | Branch (583:7): [True: 0, False: 9] ------------------ 584| 0| sigblob = osigblob; /* put it back for clear/free */ 585| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 586| 0| goto out; 587| 0| } 588| 9| memmove(sigblob + diff, sigblob, len); 589| 9| explicit_bzero(sigblob, diff); 590| 9| len = modlen; 591| 9| } 592| | 593| 10| rsasize = EVP_PKEY_size(key->pkey); 594| 10| if (rsasize <= 0 || rsasize > SSHBUF_MAX_BIGNUM || ------------------ | | 41| 20|#define SSHBUF_MAX_BIGNUM (16384 / 8) /* Max bignum *bytes* */ ------------------ | Branch (594:6): [True: 0, False: 10] | Branch (594:22): [True: 0, False: 10] ------------------ 595| 10| len == 0 || len > rsasize) { ------------------ | Branch (595:6): [True: 0, False: 10] | Branch (595:18): [True: 0, False: 10] ------------------ 596| 0| ret = SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 597| 0| goto out; 598| 0| } 599| 10| ret = sshkey_pkey_digest_verify(key->pkey, hash_alg, data, dlen, 600| 10| sigblob, len); 601| | 602| 208| out: 603| 208| freezero(sigblob, len); 604| 208| free(sigtype); 605| 208| sshbuf_free(b); 606| 208| explicit_bzero(digest, sizeof(digest)); 607| 208| return ret; 608| 10|} sshbuf_get: 34| 177|{ 35| 177| const u_char *p = sshbuf_ptr(buf); 36| 177| int r; 37| | 38| 177| if ((r = sshbuf_consume(buf, len)) < 0) ------------------ | Branch (38:6): [True: 0, False: 177] ------------------ 39| 0| return r; 40| 177| if (v != NULL && len != 0) ------------------ | Branch (40:6): [True: 177, False: 0] | Branch (40:19): [True: 101, False: 76] ------------------ 41| 101| memcpy(v, p, len); 42| 177| return 0; 43| 177|} sshbuf_get_u64: 47| 4.38k|{ 48| 4.38k| const u_char *p = sshbuf_ptr(buf); 49| 4.38k| int r; 50| | 51| 4.38k| if ((r = sshbuf_consume(buf, 8)) < 0) ------------------ | Branch (51:6): [True: 15, False: 4.36k] ------------------ 52| 15| return r; 53| 4.36k| if (valp != NULL) ------------------ | Branch (53:6): [True: 4.36k, False: 0] ------------------ 54| 4.36k| *valp = PEEK_U64(p); ------------------ | | 374| 4.36k| (((uint64_t)(((const u_char *)(p))[0]) << 56) | \ | | 375| 4.36k| ((uint64_t)(((const u_char *)(p))[1]) << 48) | \ | | 376| 4.36k| ((uint64_t)(((const u_char *)(p))[2]) << 40) | \ | | 377| 4.36k| ((uint64_t)(((const u_char *)(p))[3]) << 32) | \ | | 378| 4.36k| ((uint64_t)(((const u_char *)(p))[4]) << 24) | \ | | 379| 4.36k| ((uint64_t)(((const u_char *)(p))[5]) << 16) | \ | | 380| 4.36k| ((uint64_t)(((const u_char *)(p))[6]) << 8) | \ | | 381| 4.36k| (uint64_t)(((const u_char *)(p))[7])) ------------------ 55| 4.36k| return 0; 56| 4.38k|} sshbuf_get_u32: 60| 1.94k|{ 61| 1.94k| const u_char *p = sshbuf_ptr(buf); 62| 1.94k| int r; 63| | 64| 1.94k| if ((r = sshbuf_consume(buf, 4)) < 0) ------------------ | Branch (64:6): [True: 6, False: 1.94k] ------------------ 65| 6| return r; 66| 1.94k| if (valp != NULL) ------------------ | Branch (66:6): [True: 1.94k, False: 0] ------------------ 67| 1.94k| *valp = PEEK_U32(p); ------------------ | | 383| 1.94k| (((uint32_t)(((const u_char *)(p))[0]) << 24) | \ | | 384| 1.94k| ((uint32_t)(((const u_char *)(p))[1]) << 16) | \ | | 385| 1.94k| ((uint32_t)(((const u_char *)(p))[2]) << 8) | \ | | 386| 1.94k| (uint32_t)(((const u_char *)(p))[3])) ------------------ 68| 1.94k| return 0; 69| 1.94k|} sshbuf_get_u8: 86| 484|{ 87| 484| const u_char *p = sshbuf_ptr(buf); 88| 484| int r; 89| | 90| 484| if ((r = sshbuf_consume(buf, 1)) < 0) ------------------ | Branch (90:6): [True: 12, False: 472] ------------------ 91| 12| return r; 92| 472| if (valp != NULL) ------------------ | Branch (92:6): [True: 472, False: 0] ------------------ 93| 472| *valp = (uint8_t)*p; 94| 472| return 0; 95| 484|} sshbuf_get_string: 186| 4.24k|{ 187| 4.24k| const u_char *val; 188| 4.24k| size_t len; 189| 4.24k| int r; 190| | 191| 4.24k| if (valp != NULL) ------------------ | Branch (191:6): [True: 4.24k, False: 0] ------------------ 192| 4.24k| *valp = NULL; 193| 4.24k| if (lenp != NULL) ------------------ | Branch (193:6): [True: 4.24k, False: 0] ------------------ 194| 4.24k| *lenp = 0; 195| 4.24k| if ((r = sshbuf_get_string_direct(buf, &val, &len)) < 0) ------------------ | Branch (195:6): [True: 100, False: 4.14k] ------------------ 196| 100| return r; 197| 4.14k| if (valp != NULL) { ------------------ | Branch (197:6): [True: 4.14k, False: 0] ------------------ 198| 4.14k| if ((*valp = malloc(len + 1)) == NULL) { ------------------ | Branch (198:7): [True: 0, False: 4.14k] ------------------ 199| 0| SSHBUF_DBG(("SSH_ERR_ALLOC_FAIL")); 200| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 201| 0| } 202| 4.14k| if (len != 0) ------------------ | Branch (202:7): [True: 4.08k, False: 53] ------------------ 203| 4.08k| memcpy(*valp, val, len); 204| 4.14k| (*valp)[len] = '\0'; 205| 4.14k| } 206| 4.14k| if (lenp != NULL) ------------------ | Branch (206:6): [True: 4.14k, False: 0] ------------------ 207| 4.14k| *lenp = len; 208| 4.14k| return 0; 209| 4.14k|} sshbuf_get_string_direct: 213| 29.8k|{ 214| 29.8k| size_t len; 215| 29.8k| const u_char *p; 216| 29.8k| int r; 217| | 218| 29.8k| if (valp != NULL) ------------------ | Branch (218:6): [True: 4.67k, False: 25.1k] ------------------ 219| 4.67k| *valp = NULL; 220| 29.8k| if (lenp != NULL) ------------------ | Branch (220:6): [True: 4.67k, False: 25.1k] ------------------ 221| 4.67k| *lenp = 0; 222| 29.8k| if ((r = sshbuf_peek_string_direct(buf, &p, &len)) < 0) ------------------ | Branch (222:6): [True: 248, False: 29.5k] ------------------ 223| 248| return r; 224| 29.5k| if (valp != NULL) ------------------ | Branch (224:6): [True: 4.54k, False: 25.0k] ------------------ 225| 4.54k| *valp = p; 226| 29.5k| if (lenp != NULL) ------------------ | Branch (226:6): [True: 4.54k, False: 25.0k] ------------------ 227| 4.54k| *lenp = len; 228| 29.5k| if (sshbuf_consume(buf, len + 4) != 0) { ------------------ | Branch (228:6): [True: 0, False: 29.5k] ------------------ 229| | /* Shouldn't happen */ 230| 0| SSHBUF_DBG(("SSH_ERR_INTERNAL_ERROR")); 231| 0| SSHBUF_ABORT(); 232| 0| return SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 0|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 233| 0| } 234| 29.5k| return 0; 235| 29.5k|} sshbuf_peek_string_direct: 240| 55.3k|{ 241| 55.3k| uint32_t len; 242| 55.3k| const u_char *p = sshbuf_ptr(buf); 243| | 244| 55.3k| if (valp != NULL) ------------------ | Branch (244:6): [True: 55.0k, False: 299] ------------------ 245| 55.0k| *valp = NULL; 246| 55.3k| if (lenp != NULL) ------------------ | Branch (246:6): [True: 55.0k, False: 299] ------------------ 247| 55.0k| *lenp = 0; 248| 55.3k| if (sshbuf_len(buf) < 4) { ------------------ | Branch (248:6): [True: 278, False: 55.1k] ------------------ 249| 278| SSHBUF_DBG(("SSH_ERR_MESSAGE_INCOMPLETE")); 250| 278| return SSH_ERR_MESSAGE_INCOMPLETE; ------------------ | | 27| 278|#define SSH_ERR_MESSAGE_INCOMPLETE -3 ------------------ 251| 278| } 252| 55.1k| len = PEEK_U32(p); ------------------ | | 383| 55.1k| (((uint32_t)(((const u_char *)(p))[0]) << 24) | \ | | 384| 55.1k| ((uint32_t)(((const u_char *)(p))[1]) << 16) | \ | | 385| 55.1k| ((uint32_t)(((const u_char *)(p))[2]) << 8) | \ | | 386| 55.1k| (uint32_t)(((const u_char *)(p))[3])) ------------------ 253| 55.1k| if (len > SSHBUF_SIZE_MAX - 4) { ------------------ | | 39| 55.1k|#define SSHBUF_SIZE_MAX 0x8000000 /* Hard maximum size 128MB */ ------------------ | Branch (253:6): [True: 220, False: 54.8k] ------------------ 254| 220| SSHBUF_DBG(("SSH_ERR_STRING_TOO_LARGE")); 255| 220| return SSH_ERR_STRING_TOO_LARGE; ------------------ | | 30| 220|#define SSH_ERR_STRING_TOO_LARGE -6 ------------------ 256| 220| } 257| 54.8k| if (sshbuf_len(buf) - 4 < len) { ------------------ | Branch (257:6): [True: 412, False: 54.4k] ------------------ 258| 412| SSHBUF_DBG(("SSH_ERR_MESSAGE_INCOMPLETE")); 259| 412| return SSH_ERR_MESSAGE_INCOMPLETE; ------------------ | | 27| 412|#define SSH_ERR_MESSAGE_INCOMPLETE -3 ------------------ 260| 412| } 261| 54.4k| if (valp != NULL) ------------------ | Branch (261:6): [True: 54.3k, False: 177] ------------------ 262| 54.3k| *valp = p + 4; 263| 54.4k| if (lenp != NULL) ------------------ | Branch (263:6): [True: 54.3k, False: 177] ------------------ 264| 54.3k| *lenp = len; 265| 54.4k| return 0; 266| 54.8k|} sshbuf_get_cstring: 270| 14.7k|{ 271| 14.7k| size_t len; 272| 14.7k| const u_char *p, *z; 273| 14.7k| int r; 274| | 275| 14.7k| if (valp != NULL) ------------------ | Branch (275:6): [True: 14.7k, False: 0] ------------------ 276| 14.7k| *valp = NULL; 277| 14.7k| if (lenp != NULL) ------------------ | Branch (277:6): [True: 1.47k, False: 13.3k] ------------------ 278| 1.47k| *lenp = 0; 279| 14.7k| if ((r = sshbuf_peek_string_direct(buf, &p, &len)) != 0) ------------------ | Branch (279:6): [True: 189, False: 14.5k] ------------------ 280| 189| return r; 281| | /* Allow a \0 only at the end of the string */ 282| 14.5k| if (len > 0 && ------------------ | Branch (282:6): [True: 10.1k, False: 4.43k] ------------------ 283| 10.1k| (z = memchr(p , '\0', len)) != NULL && z < p + len - 1) { ------------------ | Branch (283:6): [True: 982, False: 9.17k] | Branch (283:45): [True: 13, False: 969] ------------------ 284| 13| SSHBUF_DBG(("SSH_ERR_INVALID_FORMAT")); 285| 13| return SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 13|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 286| 13| } 287| 14.5k| if ((r = sshbuf_skip_string(buf)) != 0) ------------------ | | 264| 14.5k|#define sshbuf_skip_string(buf) sshbuf_get_string_direct(buf, NULL, NULL) ------------------ | Branch (287:6): [True: 0, False: 14.5k] ------------------ 288| 0| return -1; 289| 14.5k| if (valp != NULL) { ------------------ | Branch (289:6): [True: 14.5k, False: 0] ------------------ 290| 14.5k| if ((*valp = malloc(len + 1)) == NULL) { ------------------ | Branch (290:7): [True: 0, False: 14.5k] ------------------ 291| 0| SSHBUF_DBG(("SSH_ERR_ALLOC_FAIL")); 292| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 293| 0| } 294| 14.5k| if (len != 0) ------------------ | Branch (294:7): [True: 10.1k, False: 4.43k] ------------------ 295| 10.1k| memcpy(*valp, p, len); 296| 14.5k| (*valp)[len] = '\0'; 297| 14.5k| } 298| 14.5k| if (lenp != NULL) ------------------ | Branch (298:6): [True: 1.46k, False: 13.1k] ------------------ 299| 1.46k| *lenp = (size_t)len; 300| 14.5k| return 0; 301| 14.5k|} sshbuf_get_stringb: 305| 299|{ 306| 299| uint32_t len; 307| 299| u_char *p; 308| 299| int r; 309| | 310| | /* 311| | * Use sshbuf_peek_string_direct() to figure out if there is 312| | * a complete string in 'buf' and copy the string directly 313| | * into 'v'. 314| | */ 315| 299| if ((r = sshbuf_peek_string_direct(buf, NULL, NULL)) != 0 || ------------------ | Branch (315:6): [True: 122, False: 177] ------------------ 316| 177| (r = sshbuf_get_u32(buf, &len)) != 0 || ------------------ | Branch (316:6): [True: 0, False: 177] ------------------ 317| 177| (r = sshbuf_reserve(v, len, &p)) != 0 || ------------------ | Branch (317:6): [True: 0, False: 177] ------------------ 318| 177| (r = sshbuf_get(buf, p, len)) != 0) ------------------ | Branch (318:6): [True: 0, False: 177] ------------------ 319| 122| return r; 320| 177| return 0; 321| 299|} sshbuf_put: 325| 4.66k|{ 326| 4.66k| u_char *p; 327| 4.66k| int r; 328| | 329| 4.66k| if ((r = sshbuf_reserve(buf, len, &p)) < 0) ------------------ | Branch (329:6): [True: 0, False: 4.66k] ------------------ 330| 0| return r; 331| 4.66k| if (len != 0) ------------------ | Branch (331:6): [True: 2.09k, False: 2.57k] ------------------ 332| 2.09k| memcpy(p, v, len); 333| 4.66k| return 0; 334| 4.66k|} sshbuf_putb: 338| 4.20k|{ 339| 4.20k| if (v == NULL) ------------------ | Branch (339:6): [True: 6, False: 4.19k] ------------------ 340| 6| return 0; 341| 4.19k| return sshbuf_put(buf, sshbuf_ptr(v), sshbuf_len(v)); 342| 4.20k|} sshbuf_put_u32: 403| 7|{ 404| 7| u_char *p; 405| 7| int r; 406| | 407| 7| if ((r = sshbuf_reserve(buf, 4, &p)) < 0) ------------------ | Branch (407:6): [True: 0, False: 7] ------------------ 408| 0| return r; 409| 7| POKE_U32(p, val); ------------------ | | 404| 7| do { \ | | 405| 7| const uint32_t __v = (v); \ | | 406| 7| ((u_char *)(p))[0] = (__v >> 24) & 0xff; \ | | 407| 7| ((u_char *)(p))[1] = (__v >> 16) & 0xff; \ | | 408| 7| ((u_char *)(p))[2] = (__v >> 8) & 0xff; \ | | 409| 7| ((u_char *)(p))[3] = __v & 0xff; \ | | 410| 7| } while (0) | | ------------------ | | | Branch (410:11): [Folded, False: 7] | | ------------------ ------------------ 410| 7| return 0; 411| 7|} sshbuf_put_u8: 427| 7|{ 428| 7| u_char *p; 429| 7| int r; 430| | 431| 7| if ((r = sshbuf_reserve(buf, 1, &p)) < 0) ------------------ | Branch (431:6): [True: 0, False: 7] ------------------ 432| 0| return r; 433| 7| p[0] = val; 434| 7| return 0; 435| 7|} sshbuf_froms: 546| 8.25k|{ 547| 8.25k| const u_char *p; 548| 8.25k| size_t len; 549| 8.25k| struct sshbuf *ret; 550| 8.25k| int r; 551| | 552| 8.25k| if (buf == NULL || bufp == NULL) ------------------ | Branch (552:6): [True: 0, False: 8.25k] | Branch (552:21): [True: 0, False: 8.25k] ------------------ 553| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 554| 8.25k| *bufp = NULL; 555| 8.25k| if ((r = sshbuf_peek_string_direct(buf, &p, &len)) != 0) ------------------ | Branch (555:6): [True: 99, False: 8.15k] ------------------ 556| 99| return r; 557| 8.15k| if ((ret = sshbuf_from(p, len)) == NULL) ------------------ | Branch (557:6): [True: 0, False: 8.15k] ------------------ 558| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 559| 8.15k| if ((r = sshbuf_consume(buf, len + 4)) != 0 || /* Shouldn't happen */ ------------------ | Branch (559:6): [True: 0, False: 8.15k] ------------------ 560| 8.15k| (r = sshbuf_set_parent(ret, buf)) != 0) { ------------------ | Branch (560:6): [True: 0, False: 8.15k] ------------------ 561| 0| sshbuf_free(ret); 562| 0| return r; 563| 0| } 564| 8.15k| *bufp = ret; 565| 8.15k| return 0; 566| 8.15k|} sshbuf_get_bignum2_bytes_direct: 600| 1.40k|{ 601| 1.40k| const u_char *d; 602| 1.40k| size_t len, olen; 603| 1.40k| int r; 604| | 605| 1.40k| if ((r = sshbuf_peek_string_direct(buf, &d, &olen)) < 0) ------------------ | Branch (605:6): [True: 183, False: 1.21k] ------------------ 606| 183| return r; 607| 1.21k| len = olen; 608| | /* Refuse negative (MSB set) bignums */ 609| 1.21k| if ((len != 0 && (*d & 0x80) != 0)) ------------------ | Branch (609:7): [True: 606, False: 611] | Branch (609:19): [True: 10, False: 596] ------------------ 610| 10| return SSH_ERR_BIGNUM_IS_NEGATIVE; ------------------ | | 29| 10|#define SSH_ERR_BIGNUM_IS_NEGATIVE -5 ------------------ 611| | /* Refuse overlong bignums, allow prepended \0 to avoid MSB set */ 612| 1.20k| if (len > SSHBUF_MAX_BIGNUM + 1 || ------------------ | | 41| 1.20k|#define SSHBUF_MAX_BIGNUM (16384 / 8) /* Max bignum *bytes* */ ------------------ | Branch (612:6): [True: 19, False: 1.18k] ------------------ 613| 1.18k| (len == SSHBUF_MAX_BIGNUM + 1 && *d != 0)) ------------------ | | 41| 1.18k|#define SSHBUF_MAX_BIGNUM (16384 / 8) /* Max bignum *bytes* */ ------------------ | Branch (613:7): [True: 14, False: 1.17k] | Branch (613:39): [True: 1, False: 13] ------------------ 614| 20| return SSH_ERR_BIGNUM_TOO_LARGE; ------------------ | | 31| 20|#define SSH_ERR_BIGNUM_TOO_LARGE -7 ------------------ 615| | /* Trim leading zeros */ 616| 5.51k| while (len > 0 && *d == 0x00) { ------------------ | Branch (616:9): [True: 4.85k, False: 659] | Branch (616:20): [True: 4.32k, False: 528] ------------------ 617| 4.32k| d++; 618| 4.32k| len--; 619| 4.32k| } 620| 1.18k| if (valp != NULL) ------------------ | Branch (620:6): [True: 1.18k, False: 0] ------------------ 621| 1.18k| *valp = d; 622| 1.18k| if (lenp != NULL) ------------------ | Branch (622:6): [True: 1.18k, False: 0] ------------------ 623| 1.18k| *lenp = len; 624| 1.18k| if (sshbuf_consume(buf, olen + 4) != 0) { ------------------ | Branch (624:6): [True: 0, False: 1.18k] ------------------ 625| | /* Shouldn't happen */ 626| 0| SSHBUF_DBG(("SSH_ERR_INTERNAL_ERROR")); 627| 0| SSHBUF_ABORT(); 628| 0| return SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 0|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 629| 0| } 630| 1.18k| return 0; 631| 1.18k|} sshbuf_get_bignum2: 35| 1.40k|{ 36| 1.40k| BIGNUM *v; 37| 1.40k| const u_char *d; 38| 1.40k| size_t len; 39| 1.40k| int r; 40| | 41| 1.40k| if (valp != NULL) ------------------ | Branch (41:6): [True: 1.40k, False: 0] ------------------ 42| 1.40k| *valp = NULL; 43| 1.40k| if ((r = sshbuf_get_bignum2_bytes_direct(buf, &d, &len)) != 0) ------------------ | Branch (43:6): [True: 213, False: 1.18k] ------------------ 44| 213| return r; 45| 1.18k| if (valp != NULL) { ------------------ | Branch (45:6): [True: 1.18k, False: 0] ------------------ 46| 1.18k| if ((v = BN_new()) == NULL || ------------------ | Branch (46:7): [True: 0, False: 1.18k] ------------------ 47| 1.18k| BN_bin2bn(d, len, v) == NULL) { ------------------ | Branch (47:7): [True: 0, False: 1.18k] ------------------ 48| 0| BN_clear_free(v); 49| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 50| 0| } 51| 1.18k| *valp = v; 52| 1.18k| } 53| 1.18k| return 0; 54| 1.18k|} sshbuf_get_eckey: 93| 821|{ 94| 821| EC_POINT *pt = EC_POINT_new(EC_KEY_get0_group(v)); 95| 821| int r; 96| 821| const u_char *d; 97| 821| size_t len; 98| | 99| 821| if (pt == NULL) { ------------------ | Branch (99:6): [True: 0, False: 821] ------------------ 100| 0| SSHBUF_DBG(("SSH_ERR_ALLOC_FAIL")); 101| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 102| 0| } 103| 821| if ((r = sshbuf_peek_string_direct(buf, &d, &len)) < 0) { ------------------ | Branch (103:6): [True: 69, False: 752] ------------------ 104| 69| EC_POINT_free(pt); 105| 69| return r; 106| 69| } 107| 752| if ((r = get_ec(d, len, pt, EC_KEY_get0_group(v))) != 0) { ------------------ | Branch (107:6): [True: 68, False: 684] ------------------ 108| 68| EC_POINT_free(pt); 109| 68| return r; 110| 68| } 111| 684| if (EC_KEY_set_public_key(v, pt) != 1) { ------------------ | Branch (111:6): [True: 0, False: 684] ------------------ 112| 0| EC_POINT_free(pt); 113| 0| return SSH_ERR_ALLOC_FAIL; /* XXX assumption */ ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 114| 0| } 115| 684| EC_POINT_free(pt); 116| | /* Skip string */ 117| 684| if (sshbuf_get_string_direct(buf, NULL, NULL) != 0) { ------------------ | Branch (117:6): [True: 0, False: 684] ------------------ 118| | /* Shouldn't happen */ 119| 0| SSHBUF_DBG(("SSH_ERR_INTERNAL_ERROR")); 120| 0| SSHBUF_ABORT(); 121| 0| return SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 0|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 122| 0| } 123| 684| return 0; 124| 684|} sshbuf-getput-crypto.c:get_ec: 58| 752|{ 59| | /* Refuse overlong bignums */ 60| 752| if (len == 0 || len > SSHBUF_MAX_ECPOINT) ------------------ | | 42| 731|#define SSHBUF_MAX_ECPOINT ((528 * 2 / 8) + 1) /* Max EC point *bytes* */ ------------------ | Branch (60:6): [True: 21, False: 731] | Branch (60:18): [True: 22, False: 709] ------------------ 61| 43| return SSH_ERR_ECPOINT_TOO_LARGE; ------------------ | | 32| 43|#define SSH_ERR_ECPOINT_TOO_LARGE -8 ------------------ 62| | /* Only handle uncompressed points */ 63| 709| if (*d != POINT_CONVERSION_UNCOMPRESSED) ------------------ | Branch (63:6): [True: 22, False: 687] ------------------ 64| 22| return SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 22|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 65| 687| if (v != NULL && EC_POINT_oct2point(g, v, d, len, NULL) != 1) ------------------ | Branch (65:6): [True: 687, False: 0] | Branch (65:19): [True: 3, False: 684] ------------------ 66| 3| return SSH_ERR_INVALID_FORMAT; /* XXX assumption */ ------------------ | | 28| 3|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 67| 684| return 0; 68| 687|} sshbuf_dtob64: 129| 92|{ 130| 92| size_t i, slen = 0; 131| 92| char *s = NULL; 132| 92| int r; 133| | 134| 92| if (d == NULL || b64 == NULL || sshbuf_len(d) >= SIZE_MAX / 2) ------------------ | Branch (134:6): [True: 0, False: 92] | Branch (134:19): [True: 0, False: 92] | Branch (134:34): [True: 0, False: 92] ------------------ 135| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 136| 92| if (sshbuf_len(d) == 0) ------------------ | Branch (136:6): [True: 0, False: 92] ------------------ 137| 0| return 0; 138| 92| slen = ((sshbuf_len(d) + 2) / 3) * 4 + 1; 139| 92| if ((s = malloc(slen)) == NULL) ------------------ | Branch (139:6): [True: 0, False: 92] ------------------ 140| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 141| 92| if (b64_ntop(sshbuf_ptr(d), sshbuf_len(d), s, slen) == -1) { ------------------ | Branch (141:6): [True: 0, False: 92] ------------------ 142| 0| r = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 0|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 143| 0| goto fail; 144| 0| } 145| 92| if (wrap) { ------------------ | Branch (145:6): [True: 0, False: 92] ------------------ 146| 0| for (i = 0; s[i] != '\0'; i++) { ------------------ | Branch (146:15): [True: 0, False: 0] ------------------ 147| 0| if ((r = sshbuf_put_u8(b64, s[i])) != 0) ------------------ | Branch (147:8): [True: 0, False: 0] ------------------ 148| 0| goto fail; 149| 0| if (i % 70 == 69 && (r = sshbuf_put_u8(b64, '\n')) != 0) ------------------ | Branch (149:8): [True: 0, False: 0] | Branch (149:24): [True: 0, False: 0] ------------------ 150| 0| goto fail; 151| 0| } 152| 0| if ((i - 1) % 70 != 69 && (r = sshbuf_put_u8(b64, '\n')) != 0) ------------------ | Branch (152:7): [True: 0, False: 0] | Branch (152:29): [True: 0, False: 0] ------------------ 153| 0| goto fail; 154| 92| } else { 155| 92| if ((r = sshbuf_put(b64, s, strlen(s))) != 0) ------------------ | Branch (155:7): [True: 0, False: 92] ------------------ 156| 0| goto fail; 157| 92| } 158| | /* Success */ 159| 92| r = 0; 160| 92| fail: 161| 92| freezero(s, slen); 162| 92| return r; 163| 92|} sshbuf_dtourlb64: 207| 92|{ 208| 92| int r = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 92|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 209| 92| u_char *p; 210| 92| struct sshbuf *b = NULL; 211| 92| size_t i, l; 212| | 213| 92| if (sshbuf_len(d) == 0) ------------------ | Branch (213:6): [True: 0, False: 92] ------------------ 214| 0| return 0; 215| | 216| 92| if ((b = sshbuf_new()) == NULL) ------------------ | | 44| 92|#define sshbuf_new() sshbuf_new_label(__func__) ------------------ | Branch (216:6): [True: 0, False: 92] ------------------ 217| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 218| | /* Encode using regular base64; we'll transform it once done */ 219| 92| if ((r = sshbuf_dtob64(d, b, wrap)) != 0) ------------------ | Branch (219:6): [True: 0, False: 92] ------------------ 220| 0| goto out; 221| | /* remove padding from end of encoded string*/ 222| 218| for (;;) { 223| 218| l = sshbuf_len(b); 224| 218| if (l <= 1 || sshbuf_ptr(b) == NULL) { ------------------ | Branch (224:7): [True: 0, False: 218] | Branch (224:17): [True: 0, False: 218] ------------------ 225| 0| r = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 0|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 226| 0| goto out; 227| 0| } 228| 218| if (sshbuf_ptr(b)[l - 1] != '=') ------------------ | Branch (228:7): [True: 92, False: 126] ------------------ 229| 92| break; 230| 126| if ((r = sshbuf_consume_end(b, 1)) != 0) ------------------ | Branch (230:7): [True: 0, False: 126] ------------------ 231| 0| goto out; 232| 126| } 233| | /* Replace characters with rfc4648 equivalents */ 234| 92| l = sshbuf_len(b); 235| 92| if ((p = sshbuf_mutable_ptr(b)) == NULL) { ------------------ | Branch (235:6): [True: 0, False: 92] ------------------ 236| 0| r = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 0|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 237| 0| goto out; 238| 0| } 239| 830k| for (i = 0; i < l; i++) { ------------------ | Branch (239:14): [True: 830k, False: 92] ------------------ 240| 830k| if (p[i] == '+') ------------------ | Branch (240:7): [True: 4.42k, False: 826k] ------------------ 241| 4.42k| p[i] = '-'; 242| 826k| else if (p[i] == '/') ------------------ | Branch (242:12): [True: 15.9k, False: 810k] ------------------ 243| 15.9k| p[i] = '_'; 244| 830k| } 245| 92| r = sshbuf_putb(b64, b); 246| 92| out: 247| 92| sshbuf_free(b); 248| 92| return r; 249| 92|} sshbuf_cmp: 277| 92|{ 278| 92| if (sshbuf_ptr(b) == NULL) ------------------ | Branch (278:6): [True: 0, False: 92] ------------------ 279| 0| return SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 0|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 280| 92| if (offset > SSHBUF_SIZE_MAX || len > SSHBUF_SIZE_MAX || len == 0) ------------------ | | 39| 184|#define SSHBUF_SIZE_MAX 0x8000000 /* Hard maximum size 128MB */ ------------------ if (offset > SSHBUF_SIZE_MAX || len > SSHBUF_SIZE_MAX || len == 0) ------------------ | | 39| 184|#define SSHBUF_SIZE_MAX 0x8000000 /* Hard maximum size 128MB */ ------------------ | Branch (280:6): [True: 0, False: 92] | Branch (280:34): [True: 0, False: 92] | Branch (280:59): [True: 0, False: 92] ------------------ 281| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 282| 92| if (offset + len > sshbuf_len(b)) ------------------ | Branch (282:6): [True: 80, False: 12] ------------------ 283| 80| return SSH_ERR_MESSAGE_INCOMPLETE; ------------------ | | 27| 80|#define SSH_ERR_MESSAGE_INCOMPLETE -3 ------------------ 284| 12| if (timingsafe_bcmp(sshbuf_ptr(b) + offset, s, len) != 0) ------------------ | Branch (284:6): [True: 12, False: 0] ------------------ 285| 12| return SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 12|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 286| 0| return 0; 287| 12|} sshbuf_new_label: 118| 5.37k|{ 119| 5.37k| struct sshbuf *ret; 120| | 121| 5.37k| if ((ret = calloc(1, sizeof(*ret))) == NULL) ------------------ | Branch (121:6): [True: 0, False: 5.37k] ------------------ 122| 0| return NULL; 123| 5.37k| ret->alloc = SSHBUF_SIZE_INIT; ------------------ | | 444| 5.37k|# define SSHBUF_SIZE_INIT 256 /* Initial allocation */ ------------------ 124| 5.37k| ret->max_size = SSHBUF_SIZE_MAX; ------------------ | | 39| 5.37k|#define SSHBUF_SIZE_MAX 0x8000000 /* Hard maximum size 128MB */ ------------------ 125| 5.37k| ret->readonly = 0; 126| 5.37k| ret->refcount = 1; 127| 5.37k| ret->parent = NULL; 128| 5.37k| if (label != NULL) ------------------ | Branch (128:6): [True: 5.37k, False: 0] ------------------ 129| 5.37k| strncpy(ret->label, label, MAX_LABEL_LEN-1); ------------------ | | 43| 5.37k|#define MAX_LABEL_LEN 64 /*maximum size of sshbuf label */ ------------------ 130| 5.37k| if ((ret->cd = ret->d = calloc(1, ret->alloc)) == NULL) { ------------------ | Branch (130:6): [True: 0, False: 5.37k] ------------------ 131| 0| free(ret); 132| 0| return NULL; 133| 0| } 134| 5.37k| return ret; 135| 5.37k|} sshbuf_from: 139| 17.2k|{ 140| 17.2k| struct sshbuf *ret; 141| | 142| 17.2k| if (blob == NULL || len > SSHBUF_SIZE_MAX || ------------------ | | 39| 34.4k|#define SSHBUF_SIZE_MAX 0x8000000 /* Hard maximum size 128MB */ ------------------ | Branch (142:6): [True: 0, False: 17.2k] | Branch (142:22): [True: 0, False: 17.2k] ------------------ 143| 17.2k| (ret = calloc(1, sizeof(*ret))) == NULL) ------------------ | Branch (143:6): [True: 0, False: 17.2k] ------------------ 144| 0| return NULL; 145| 17.2k| ret->alloc = ret->size = ret->max_size = len; 146| 17.2k| ret->readonly = 1; 147| 17.2k| ret->refcount = 1; 148| 17.2k| ret->parent = NULL; 149| 17.2k| ret->cd = blob; 150| | ret->d = NULL; 151| 17.2k| return ret; 152| 17.2k|} sshbuf_set_parent: 156| 11.3k|{ 157| 11.3k| int r; 158| | 159| 11.3k| if ((r = sshbuf_check_sanity(child)) != 0 || ------------------ | Branch (159:6): [True: 0, False: 11.3k] ------------------ 160| 11.3k| (r = sshbuf_check_sanity(parent)) != 0) ------------------ | Branch (160:6): [True: 0, False: 11.3k] ------------------ 161| 0| return r; 162| 11.3k| if ((child->parent != NULL && child->parent != parent) || ------------------ | Branch (162:7): [True: 0, False: 11.3k] | Branch (162:32): [True: 0, False: 0] ------------------ 163| 11.3k| child == parent) ------------------ | Branch (163:6): [True: 0, False: 11.3k] ------------------ 164| 0| return SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 0|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 165| 11.3k| child->parent = parent; 166| 11.3k| child->parent->refcount++; 167| 11.3k| return 0; 168| 11.3k|} sshbuf_fromb: 172| 3.23k|{ 173| 3.23k| struct sshbuf *ret; 174| | 175| 3.23k| if (sshbuf_check_sanity(buf) != 0) ------------------ | Branch (175:6): [True: 0, False: 3.23k] ------------------ 176| 0| return NULL; 177| 3.23k| if ((ret = sshbuf_from(sshbuf_ptr(buf), sshbuf_len(buf))) == NULL) ------------------ | Branch (177:6): [True: 0, False: 3.23k] ------------------ 178| 0| return NULL; 179| 3.23k| if (sshbuf_set_parent(ret, buf) != 0) { ------------------ | Branch (179:6): [True: 0, False: 3.23k] ------------------ 180| 0| sshbuf_free(ret); 181| 0| return NULL; 182| 0| } 183| 3.23k| return ret; 184| 3.23k|} sshbuf_free: 188| 48.2k|{ 189| 48.2k| if (buf == NULL) ------------------ | Branch (189:6): [True: 14.2k, False: 33.9k] ------------------ 190| 14.2k| return; 191| | /* 192| | * The following will leak on insane buffers, but this is the safest 193| | * course of action - an invalid pointer or already-freed pointer may 194| | * have been passed to us and continuing to scribble over memory would 195| | * be bad. 196| | */ 197| 33.9k| if (sshbuf_check_sanity(buf) != 0) ------------------ | Branch (197:6): [True: 0, False: 33.9k] ------------------ 198| 0| return; 199| | 200| | /* 201| | * If we are a parent with still-extant children, then don't free just 202| | * yet. The last child's call to sshbuf_free should decrement our 203| | * refcount to 0 and trigger the actual free. 204| | */ 205| 33.9k| buf->refcount--; 206| 33.9k| if (buf->refcount > 0) ------------------ | Branch (206:6): [True: 11.3k, False: 22.6k] ------------------ 207| 11.3k| return; 208| | 209| | /* 210| | * If we are a child, then free our parent to decrement its reference 211| | * count and possibly free it. 212| | */ 213| 22.6k| sshbuf_free(buf->parent); 214| 22.6k| buf->parent = NULL; 215| | 216| 22.6k| if (!buf->readonly) ------------------ | Branch (216:6): [True: 5.37k, False: 17.2k] ------------------ 217| 5.37k| freezero(buf->d, buf->alloc); 218| 22.6k| freezero(buf, sizeof(*buf)); 219| 22.6k|} sshbuf_reset: 223| 55|{ 224| 55| u_char *d; 225| | 226| 55| if (buf->readonly || buf->refcount > 1) { ------------------ | Branch (226:6): [True: 0, False: 55] | Branch (226:23): [True: 0, False: 55] ------------------ 227| | /* Nonsensical. Just make buffer appear empty */ 228| 0| buf->off = buf->size; 229| 0| return; 230| 0| } 231| 55| if (sshbuf_check_sanity(buf) != 0) ------------------ | Branch (231:6): [True: 0, False: 55] ------------------ 232| 0| return; 233| 55| buf->off = buf->size = 0; 234| 55| if (buf->alloc != SSHBUF_SIZE_INIT) { ------------------ | | 444| 55|# define SSHBUF_SIZE_INIT 256 /* Initial allocation */ ------------------ | Branch (234:6): [True: 33, False: 22] ------------------ 235| 33| if ((d = recallocarray(buf->d, buf->alloc, SSHBUF_SIZE_INIT, ------------------ | | 444| 33|# define SSHBUF_SIZE_INIT 256 /* Initial allocation */ ------------------ | Branch (235:7): [True: 33, False: 0] ------------------ 236| 33| 1)) != NULL) { 237| 33| buf->cd = buf->d = d; 238| 33| buf->alloc = SSHBUF_SIZE_INIT; ------------------ | | 444| 33|# define SSHBUF_SIZE_INIT 256 /* Initial allocation */ ------------------ 239| 33| } 240| 33| } 241| 55| explicit_bzero(buf->d, buf->alloc); 242| 55|} sshbuf_len: 308| 179k|{ 309| 179k| if (sshbuf_check_sanity(buf) != 0) ------------------ | Branch (309:6): [True: 0, False: 179k] ------------------ 310| 0| return 0; 311| 179k| return buf->size - buf->off; 312| 179k|} sshbuf_ptr: 338| 71.7k|{ 339| 71.7k| if (sshbuf_check_sanity(buf) != 0) ------------------ | Branch (339:6): [True: 0, False: 71.7k] ------------------ 340| 0| return NULL; 341| 71.7k| return buf->cd + buf->off; 342| 71.7k|} sshbuf_mutable_ptr: 346| 92|{ 347| 92| if (sshbuf_check_sanity(buf) != 0 || buf->readonly || buf->refcount > 1) ------------------ | Branch (347:6): [True: 0, False: 92] | Branch (347:39): [True: 0, False: 92] | Branch (347:56): [True: 0, False: 92] ------------------ 348| 0| return NULL; 349| 92| return buf->d + buf->off; 350| 92|} sshbuf_check_reserve: 354| 6.22k|{ 355| 6.22k| int r; 356| | 357| 6.22k| if ((r = sshbuf_check_sanity(buf)) != 0) ------------------ | Branch (357:6): [True: 0, False: 6.22k] ------------------ 358| 0| return r; 359| 6.22k| if (buf->readonly || buf->refcount > 1) ------------------ | Branch (359:6): [True: 0, False: 6.22k] | Branch (359:23): [True: 0, False: 6.22k] ------------------ 360| 0| return SSH_ERR_BUFFER_READ_ONLY; ------------------ | | 73| 0|#define SSH_ERR_BUFFER_READ_ONLY -49 ------------------ 361| 6.22k| SSHBUF_TELL("check"); 362| | /* Check that len is reasonable and that max_size + available < len */ 363| 6.22k| if (len > buf->max_size || buf->max_size - len < buf->size - buf->off) ------------------ | Branch (363:6): [True: 0, False: 6.22k] | Branch (363:29): [True: 0, False: 6.22k] ------------------ 364| 0| return SSH_ERR_NO_BUFFER_SPACE; ------------------ | | 33| 0|#define SSH_ERR_NO_BUFFER_SPACE -9 ------------------ 365| 6.22k| return 0; 366| 6.22k|} sshbuf_allocate: 370| 4.85k|{ 371| 4.85k| size_t rlen, need; 372| 4.85k| u_char *dp; 373| 4.85k| int r; 374| | 375| 4.85k| SSHBUF_DBG(("allocate buf = %p len = %zu", buf, len)); 376| 4.85k| if ((r = sshbuf_check_reserve(buf, len)) != 0) ------------------ | Branch (376:6): [True: 0, False: 4.85k] ------------------ 377| 0| return r; 378| | /* 379| | * If the requested allocation appended would push us past max_size 380| | * then pack the buffer, zeroing buf->off. 381| | */ 382| 4.85k| sshbuf_maybe_pack(buf, buf->size + len > buf->max_size); 383| 4.85k| SSHBUF_TELL("allocate"); 384| 4.85k| if (len + buf->size <= buf->alloc) ------------------ | Branch (384:6): [True: 3.49k, False: 1.36k] ------------------ 385| 3.49k| return 0; /* already have it. */ 386| | 387| | /* 388| | * Prefer to alloc in SSHBUF_SIZE_INC units, but 389| | * allocate less if doing so would overflow max_size. 390| | */ 391| 1.36k| need = len + buf->size - buf->alloc; 392| 1.36k| rlen = ROUNDUP(buf->alloc + need, SSHBUF_SIZE_INC); ------------------ | | 271| 1.36k|#define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y)) ------------------ 393| | /* With the changes in 8.9 the output buffer end up growing pretty 394| | * slowly. It's knows that it needs to grow but it only does so 32K 395| | * at a time. This means a lot of calls to realloc and memcpy which 396| | * kills performance until the buffer reaches some maximum size. 397| | * So we explicitly test for a buffer that's trying to grow and 398| | * if it is then we push the growth by 4MB at a time. This can result in 399| | * the buffer being over allocated (in terms of actual needs) but the 400| | * process is fast. This significantly reduces overhead 401| | * and improves performance. In this case we look for a buffer that is trying 402| | * to grow larger than BUF_WATERSHED (256*1024 taken from PACKET_MAX_SIZE) 403| | * and explcitly check that the buffer is being used for inbound outbound 404| | * channel buffering. 405| | * Updated for 18.4.1 -cjr 04/20/24 406| | */ 407| 1.36k| if (rlen > BUF_WATERSHED && (buf->type == BUF_CHANNEL_OUTPUT || buf->type == BUF_CHANNEL_INPUT)) { ------------------ | | 32| 2.73k|#define BUF_WATERSHED 256*1024 ------------------ | Branch (407:6): [True: 26, False: 1.34k] | Branch (407:31): [True: 26, False: 0] | Branch (407:66): [True: 0, False: 0] ------------------ 408| | /* debug_f ("Prior: label: %s, %p, rlen is %zu need is %zu max_size is %zu", 409| | buf->label, buf, rlen, need, buf->max_size); */ 410| | /* easiest thing to do is grow the nuffer by 4MB each time. It might end 411| | * up being somewhat overallocated but works quickly */ 412| 26| need = (4*1024*1024); 413| 26| rlen = ROUNDUP(buf->alloc + need, SSHBUF_SIZE_INC); ------------------ | | 271| 26|#define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y)) ------------------ 414| | /* debug_f ("Post: label: %s, %p, rlen is %zu need is %zu max_size is %zu", */ 415| | /* buf->label, buf, rlen, need, buf->max_size); */ 416| 26| } 417| 1.36k| SSHBUF_DBG(("need %zu initial rlen %zu", need, rlen)); 418| | 419| | /* rlen might be above the max allocation */ 420| 1.36k| if (rlen > buf->max_size) ------------------ | Branch (420:6): [True: 0, False: 1.36k] ------------------ 421| 0| rlen = buf->max_size; 422| | 423| 1.36k| SSHBUF_DBG(("adjusted rlen %zu", rlen)); 424| 1.36k| if ((dp = recallocarray(buf->d, buf->alloc, rlen, 1)) == NULL) { ------------------ | Branch (424:6): [True: 0, False: 1.36k] ------------------ 425| 0| SSHBUF_DBG(("realloc fail")); 426| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 427| 0| } 428| 1.36k| buf->alloc = rlen; 429| 1.36k| buf->cd = buf->d = dp; 430| 1.36k| if ((r = sshbuf_check_reserve(buf, len)) < 0) { ------------------ | Branch (430:6): [True: 0, False: 1.36k] ------------------ 431| | /* shouldn't fail */ 432| 0| return r; 433| 0| } 434| 1.36k| SSHBUF_TELL("done"); 435| 1.36k| return 0; 436| 1.36k|} sshbuf_reserve: 440| 4.85k|{ 441| 4.85k| u_char *dp; 442| 4.85k| int r; 443| | 444| 4.85k| if (dpp != NULL) ------------------ | Branch (444:6): [True: 4.85k, False: 0] ------------------ 445| 4.85k| *dpp = NULL; 446| | 447| 4.85k| SSHBUF_DBG(("reserve buf = %p len = %zu", buf, len)); 448| 4.85k| if ((r = sshbuf_allocate(buf, len)) != 0) ------------------ | Branch (448:6): [True: 0, False: 4.85k] ------------------ 449| 0| return r; 450| | 451| 4.85k| dp = buf->d + buf->size; 452| 4.85k| buf->size += len; 453| 4.85k| if (dpp != NULL) ------------------ | Branch (453:6): [True: 4.85k, False: 0] ------------------ 454| 4.85k| *dpp = dp; 455| 4.85k| return 0; 456| 4.85k|} sshbuf_consume: 460| 45.9k|{ 461| 45.9k| int r; 462| | 463| 45.9k| SSHBUF_DBG(("len = %zu", len)); 464| 45.9k| if ((r = sshbuf_check_sanity(buf)) != 0) ------------------ | Branch (464:6): [True: 0, False: 45.9k] ------------------ 465| 0| return r; 466| 45.9k| if (len == 0) ------------------ | Branch (466:6): [True: 76, False: 45.8k] ------------------ 467| 76| return 0; 468| 45.8k| if (len > sshbuf_len(buf)) ------------------ | Branch (468:6): [True: 33, False: 45.8k] ------------------ 469| 33| return SSH_ERR_MESSAGE_INCOMPLETE; ------------------ | | 27| 33|#define SSH_ERR_MESSAGE_INCOMPLETE -3 ------------------ 470| 45.8k| buf->off += len; 471| | /* deal with empty buffer */ 472| 45.8k| if (buf->off == buf->size) ------------------ | Branch (472:6): [True: 5.57k, False: 40.2k] ------------------ 473| 5.57k| buf->off = buf->size = 0; 474| 45.8k| SSHBUF_TELL("done"); 475| 45.8k| return 0; 476| 45.8k|} sshbuf_consume_end: 480| 126|{ 481| 126| int r; 482| | 483| 126| SSHBUF_DBG(("len = %zu", len)); 484| 126| if ((r = sshbuf_check_sanity(buf)) != 0) ------------------ | Branch (484:6): [True: 0, False: 126] ------------------ 485| 0| return r; 486| 126| if (len == 0) ------------------ | Branch (486:6): [True: 0, False: 126] ------------------ 487| 0| return 0; 488| 126| if (len > sshbuf_len(buf)) ------------------ | Branch (488:6): [True: 0, False: 126] ------------------ 489| 0| return SSH_ERR_MESSAGE_INCOMPLETE; ------------------ | | 27| 0|#define SSH_ERR_MESSAGE_INCOMPLETE -3 ------------------ 490| 126| buf->size -= len; 491| 126| SSHBUF_TELL("done"); 492| 126| return 0; 493| 126|} sshbuf.c:sshbuf_check_sanity: 80| 363k|{ 81| 363k| SSHBUF_TELL("sanity"); 82| 363k| if (__predict_false(buf == NULL || ------------------ | | 990| 6.92M|# define __predict_false(exp) __builtin_expect(((exp) != 0), 0) | | ------------------ | | | Branch (990:35): [True: 0, False: 363k] | | | Branch (990:54): [True: 15.8k, False: 347k] | | | Branch (990:54): [True: 0, False: 15.8k] | | | Branch (990:54): [True: 0, False: 363k] | | | Branch (990:54): [True: 0, False: 363k] | | | Branch (990:54): [True: 0, False: 363k] | | | Branch (990:54): [True: 0, False: 363k] | | | Branch (990:54): [True: 0, False: 363k] | | | Branch (990:54): [True: 0, False: 363k] | | | Branch (990:54): [True: 0, False: 363k] | | | Branch (990:54): [True: 0, False: 363k] | | | Branch (990:54): [True: 0, False: 363k] | | ------------------ ------------------ 83| 363k| (!buf->readonly && buf->d != buf->cd) || 84| 363k| buf->parent == buf || 85| 363k| buf->refcount < 1 || buf->refcount > SSHBUF_REFS_MAX || 86| 363k| buf->cd == NULL || 87| 363k| buf->max_size > SSHBUF_SIZE_MAX || 88| 363k| buf->alloc > buf->max_size || 89| 363k| buf->size > buf->alloc || 90| 363k| buf->off > buf->size)) { 91| | /* Do not try to recover from corrupted buffer internals */ 92| 0| SSHBUF_DBG(("SSH_ERR_INTERNAL_ERROR")); 93| 0| ssh_signal(SIGSEGV, SIG_DFL); 94| 0| raise(SIGSEGV); 95| 0| return SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 0|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 96| 0| } 97| 363k| return 0; 98| 363k|} sshbuf.c:sshbuf_maybe_pack: 102| 4.85k|{ 103| 4.85k| SSHBUF_DBG(("force %d", force)); 104| 4.85k| SSHBUF_TELL("pre-pack"); 105| 4.85k| if (buf->off == 0 || buf->readonly || buf->refcount > 1) ------------------ | Branch (105:6): [True: 4.85k, False: 0] | Branch (105:23): [True: 0, False: 0] | Branch (105:40): [True: 0, False: 0] ------------------ 106| 4.85k| return; 107| 0| if (force || ------------------ | Branch (107:6): [True: 0, False: 0] ------------------ 108| 0| (buf->off >= SSHBUF_PACK_MIN && buf->off >= buf->size / 2)) { ------------------ | | 446| 0|# define SSHBUF_PACK_MIN 8192 /* Minimum packable offset */ ------------------ | Branch (108:7): [True: 0, False: 0] | Branch (108:38): [True: 0, False: 0] ------------------ 109| 0| memmove(buf->d, buf->d + buf->off, buf->size - buf->off); 110| 0| buf->size -= buf->off; 111| 0| buf->off = 0; 112| 0| SSHBUF_TELL("packed"); 113| 0| } 114| 0|} sshkey_type_is_cert: 209| 19.5k|{ 210| 19.5k| const struct sshkey_impl *impl; 211| | 212| 19.5k| if ((impl = sshkey_impl_from_type(type)) == NULL) ------------------ | Branch (212:6): [True: 573, False: 18.9k] ------------------ 213| 573| return 0; 214| 18.9k| return impl->cert; 215| 19.5k|} sshkey_ssh_name_plain: 225| 306|{ 226| 306| return sshkey_ssh_name_from_type_nid(sshkey_type_plain(k->type), 227| 306| k->ecdsa_nid); 228| 306|} sshkey_type_from_name: 250| 6.19k|{ 251| 6.19k| return type_from_name(name, 0); 252| 6.19k|} sshkey_ecdsa_nid_from_name: 275| 962|{ 276| 962| int i; 277| | 278| 9.76k| for (i = 0; keyimpls[i] != NULL; i++) { ------------------ | Branch (278:14): [True: 9.76k, False: 0] ------------------ 279| 9.76k| if (!key_type_is_ecdsa_variant(keyimpls[i]->type)) ------------------ | Branch (279:7): [True: 5.77k, False: 3.99k] ------------------ 280| 5.77k| continue; 281| 3.99k| if (keyimpls[i]->name != NULL && ------------------ | Branch (281:7): [True: 3.99k, False: 0] ------------------ 282| 3.99k| strcmp(name, keyimpls[i]->name) == 0) ------------------ | Branch (282:7): [True: 962, False: 3.03k] ------------------ 283| 962| return keyimpls[i]->nid; 284| 3.99k| } 285| 0| return -1; 286| 962|} sshkey_is_cert: 411| 12.0k|{ 412| 12.0k| if (k == NULL) ------------------ | Branch (412:6): [True: 0, False: 12.0k] ------------------ 413| 0| return 0; 414| 12.0k| return sshkey_type_is_cert(k->type); 415| 12.0k|} sshkey_type_plain: 434| 1.56k|{ 435| 1.56k| switch (type) { 436| 0| case KEY_RSA_CERT: ------------------ | Branch (436:2): [True: 0, False: 1.56k] ------------------ 437| 0| return KEY_RSA; 438| 0| case KEY_ECDSA_CERT: ------------------ | Branch (438:2): [True: 0, False: 1.56k] ------------------ 439| 0| return KEY_ECDSA; 440| 0| case KEY_ECDSA_SK_CERT: ------------------ | Branch (440:2): [True: 0, False: 1.56k] ------------------ 441| 0| return KEY_ECDSA_SK; 442| 0| case KEY_ED25519_CERT: ------------------ | Branch (442:2): [True: 0, False: 1.56k] ------------------ 443| 0| return KEY_ED25519; 444| 0| case KEY_MLDSA44_ED25519_CERT: ------------------ | Branch (444:2): [True: 0, False: 1.56k] ------------------ 445| 0| return KEY_MLDSA44_ED25519; 446| 0| case KEY_ED25519_SK_CERT: ------------------ | Branch (446:2): [True: 0, False: 1.56k] ------------------ 447| 0| return KEY_ED25519_SK; 448| 1.56k| default: ------------------ | Branch (448:2): [True: 1.56k, False: 0] ------------------ 449| 1.56k| return type; 450| 1.56k| } 451| 1.56k|} sshkey_pkey_digest_verify: 538| 17|{ 539| 17| EVP_MD_CTX *ctx = NULL; 540| 17| int ret = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 17|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 541| 17| const EVP_MD *evpmd; 542| | 543| 17| if ((evpmd = ssh_digest_to_md(hash_alg)) == NULL) ------------------ | Branch (543:6): [True: 0, False: 17] ------------------ 544| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 545| 17| if ((ctx = EVP_MD_CTX_new()) == NULL) ------------------ | Branch (545:6): [True: 0, False: 17] ------------------ 546| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 547| 17| if (EVP_DigestVerifyInit(ctx, NULL, evpmd, NULL, pkey) != 1) { ------------------ | Branch (547:6): [True: 0, False: 17] ------------------ 548| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 549| 0| goto out; 550| 0| } 551| 17| switch (EVP_DigestVerify(ctx, sigbuf, siglen, data, datalen)) { 552| 0| case 1: ------------------ | Branch (552:2): [True: 0, False: 17] ------------------ 553| 0| ret = 0; 554| 0| break; 555| 17| case 0: ------------------ | Branch (555:2): [True: 17, False: 0] ------------------ 556| 17| ret = SSH_ERR_SIGNATURE_INVALID; ------------------ | | 45| 17|#define SSH_ERR_SIGNATURE_INVALID -21 ------------------ 557| 17| break; 558| 0| default: ------------------ | Branch (558:2): [True: 0, False: 17] ------------------ 559| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 560| 0| break; 561| 17| } 562| | 563| 17| out: 564| 17| EVP_MD_CTX_free(ctx); 565| 17| return ret; 566| 17|} sshkey_curve_name_to_nid: 571| 947|{ 572| 947| if (strcmp(name, "nistp256") == 0) ------------------ | Branch (572:6): [True: 803, False: 144] ------------------ 573| 803| return NID_X9_62_prime256v1; 574| 144| else if (strcmp(name, "nistp384") == 0) ------------------ | Branch (574:11): [True: 11, False: 133] ------------------ 575| 11| return NID_secp384r1; 576| 133| else if (strcmp(name, "nistp521") == 0) ------------------ | Branch (576:11): [True: 11, False: 122] ------------------ 577| 11| return NID_secp521r1; 578| 122| else 579| 122| return -1; 580| 947|} sshkey_curve_nid_to_bits: 584| 174|{ 585| 174| switch (nid) { 586| 174| case NID_X9_62_prime256v1: ------------------ | Branch (586:2): [True: 174, False: 0] ------------------ 587| 174| return 256; 588| 0| case NID_secp384r1: ------------------ | Branch (588:2): [True: 0, False: 174] ------------------ 589| 0| return 384; 590| 0| case NID_secp521r1: ------------------ | Branch (590:2): [True: 0, False: 174] ------------------ 591| 0| return 521; 592| 0| default: ------------------ | Branch (592:2): [True: 0, False: 174] ------------------ 593| 0| return 0; 594| 174| } 595| 174|} sshkey_ec_nid_to_hash_alg: 629| 174|{ 630| 174| int kbits = sshkey_curve_nid_to_bits(nid); 631| | 632| 174| if (kbits <= 0) ------------------ | Branch (632:6): [True: 0, False: 174] ------------------ 633| 0| return -1; 634| | 635| | /* RFC5656 section 6.2.1 */ 636| 174| if (kbits <= 256) ------------------ | Branch (636:6): [True: 174, False: 0] ------------------ 637| 174| return SSH_DIGEST_SHA256; ------------------ | | 27| 174|#define SSH_DIGEST_SHA256 2 ------------------ 638| 0| else if (kbits <= 384) ------------------ | Branch (638:11): [True: 0, False: 0] ------------------ 639| 0| return SSH_DIGEST_SHA384; ------------------ | | 28| 0|#define SSH_DIGEST_SHA384 3 ------------------ 640| 0| else 641| 0| return SSH_DIGEST_SHA512; ------------------ | | 29| 0|#define SSH_DIGEST_SHA512 4 ------------------ 642| 174|} sshkey_new: 686| 4.16k|{ 687| 4.16k| struct sshkey *k; 688| 4.16k| const struct sshkey_impl *impl = NULL; 689| | 690| 4.16k| if (type != KEY_UNSPEC && ------------------ | Branch (690:6): [True: 3.97k, False: 190] ------------------ 691| 3.97k| (impl = sshkey_impl_from_type(type)) == NULL) ------------------ | Branch (691:6): [True: 0, False: 3.97k] ------------------ 692| 0| return NULL; 693| | 694| | /* All non-certificate types may act as CAs */ 695| 4.16k| if ((k = calloc(1, sizeof(*k))) == NULL) ------------------ | Branch (695:6): [True: 0, False: 4.16k] ------------------ 696| 0| return NULL; 697| 4.16k| k->type = type; 698| 4.16k| k->ecdsa_nid = -1; 699| 4.16k| if (impl != NULL && impl->funcs->alloc != NULL) { ------------------ | Branch (699:6): [True: 3.97k, False: 190] | Branch (699:22): [True: 554, False: 3.42k] ------------------ 700| 554| if (impl->funcs->alloc(k) != 0) { ------------------ | Branch (700:7): [True: 0, False: 554] ------------------ 701| 0| free(k); 702| 0| return NULL; 703| 0| } 704| 554| } 705| 4.16k| if (sshkey_is_cert(k)) { ------------------ | Branch (705:6): [True: 1.56k, False: 2.60k] ------------------ 706| 1.56k| if ((k->cert = cert_new()) == NULL) { ------------------ | Branch (706:7): [True: 0, False: 1.56k] ------------------ 707| 0| sshkey_free(k); 708| 0| return NULL; 709| 0| } 710| 1.56k| } 711| | 712| 4.16k| return k; 713| 4.16k|} sshkey_sk_cleanup: 718| 886|{ 719| 886| free(k->sk_application); 720| 886| sshbuf_free(k->sk_key_handle); 721| 886| sshbuf_free(k->sk_reserved); 722| 886| k->sk_application = NULL; 723| | k->sk_key_handle = k->sk_reserved = NULL; 724| 886|} sshkey_free: 786| 10.9k|{ 787| 10.9k| sshkey_free_contents(k); 788| 10.9k| freezero(k, sizeof(*k)); 789| 10.9k|} sshkey_check_rsa_length: 1456| 336|{ 1457| 336|#ifdef WITH_OPENSSL 1458| 336| int r, nbits; 1459| | 1460| 336| if (k == NULL) ------------------ | Branch (1460:6): [True: 52, False: 284] ------------------ 1461| 52| return 0; 1462| | /* A certificate is no stronger than the CA key that signed it */ 1463| 284| if (sshkey_is_cert(k) && k->cert != NULL && ------------------ | Branch (1463:6): [True: 52, False: 232] | Branch (1463:27): [True: 52, False: 0] ------------------ 1464| 52| (r = sshkey_check_rsa_length(k->cert->signature_key, ------------------ | Branch (1464:6): [True: 0, False: 52] ------------------ 1465| 52| min_size)) != 0) 1466| 0| return r; 1467| 284| if (k->pkey == NULL || ------------------ | Branch (1467:6): [True: 0, False: 284] ------------------ 1468| 284| (k->type != KEY_RSA && k->type != KEY_RSA_CERT)) ------------------ | Branch (1468:7): [True: 52, False: 232] | Branch (1468:29): [True: 0, False: 52] ------------------ 1469| 0| return 0; 1470| 284| nbits = EVP_PKEY_bits(k->pkey); 1471| 284| if (nbits < SSH_RSA_MINIMUM_MODULUS_SIZE || ------------------ | | 47| 568|#define SSH_RSA_MINIMUM_MODULUS_SIZE 1024 ------------------ | Branch (1471:6): [True: 23, False: 261] ------------------ 1472| 261| (min_size > 0 && nbits < min_size)) ------------------ | Branch (1472:7): [True: 0, False: 261] | Branch (1472:23): [True: 0, False: 0] ------------------ 1473| 23| return SSH_ERR_KEY_LENGTH; ------------------ | | 80| 23|#define SSH_ERR_KEY_LENGTH -56 ------------------ 1474| 261|#endif /* WITH_OPENSSL */ 1475| 261| return 0; 1476| 284|} sshkey_deserialize_sk: 2006| 650|{ 2007| | /* Parse additional security-key application string */ 2008| 650| if (sshbuf_get_cstring(b, &key->sk_application, NULL) != 0) ------------------ | Branch (2008:6): [True: 3, False: 647] ------------------ 2009| 3| return SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 3|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 2010| 647| return 0; 2011| 650|} sshkey_froms: 2117| 1.89k|{ 2118| 1.89k| struct sshbuf *b; 2119| 1.89k| int r; 2120| | 2121| 1.89k| if ((r = sshbuf_froms(buf, &b)) != 0) ------------------ | Branch (2121:6): [True: 64, False: 1.82k] ------------------ 2122| 64| return r; 2123| 1.82k| r = sshkey_from_blob_internal(b, keyp, 1, NULL, NULL); 2124| 1.82k| sshbuf_free(b); 2125| 1.82k| return r; 2126| 1.89k|} sshkey_get_sigtype: 2130| 1.42k|{ 2131| 1.42k| int r; 2132| 1.42k| struct sshbuf *b = NULL; 2133| 1.42k| char *sigtype = NULL; 2134| | 2135| 1.42k| if (sigtypep != NULL) ------------------ | Branch (2135:6): [True: 1.42k, False: 0] ------------------ 2136| 1.42k| *sigtypep = NULL; 2137| 1.42k| if ((b = sshbuf_from(sig, siglen)) == NULL) ------------------ | Branch (2137:6): [True: 0, False: 1.42k] ------------------ 2138| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 2139| 1.42k| if ((r = sshbuf_get_cstring(b, &sigtype, NULL)) != 0) ------------------ | Branch (2139:6): [True: 19, False: 1.40k] ------------------ 2140| 19| goto out; 2141| | /* success */ 2142| 1.40k| if (sigtypep != NULL) { ------------------ | Branch (2142:6): [True: 1.40k, False: 0] ------------------ 2143| 1.40k| *sigtypep = sigtype; 2144| 1.40k| sigtype = NULL; 2145| 1.40k| } 2146| 1.40k| r = 0; 2147| 1.42k| out: 2148| 1.42k| free(sigtype); 2149| 1.42k| sshbuf_free(b); 2150| 1.42k| return r; 2151| 1.40k|} sshkey_verify: 2268| 1.25k|{ 2269| 1.25k| const struct sshkey_impl *impl; 2270| | 2271| 1.25k| if (detailsp != NULL) ------------------ | Branch (2271:6): [True: 0, False: 1.25k] ------------------ 2272| 0| *detailsp = NULL; 2273| 1.25k| if (siglen == 0 || dlen > SSH_KEY_MAX_SIGN_DATA_SIZE) ------------------ | | 48| 1.25k|#define SSH_KEY_MAX_SIGN_DATA_SIZE (1 << 20) ------------------ | Branch (2273:6): [True: 0, False: 1.25k] | Branch (2273:21): [True: 0, False: 1.25k] ------------------ 2274| 0| return SSH_ERR_INVALID_ARGUMENT; ------------------ | | 34| 0|#define SSH_ERR_INVALID_ARGUMENT -10 ------------------ 2275| 1.25k| if ((impl = sshkey_impl_from_key(key)) == NULL) ------------------ | Branch (2275:6): [True: 0, False: 1.25k] ------------------ 2276| 0| return SSH_ERR_KEY_TYPE_UNKNOWN; ------------------ | | 38| 0|#define SSH_ERR_KEY_TYPE_UNKNOWN -14 /* XXX UNSUPPORTED? */ ------------------ 2277| 1.25k| return impl->funcs->verify(key, sig, siglen, data, dlen, 2278| 1.25k| alg, compat, detailsp); 2279| 1.25k|} sshkey_private_deserialize_sk: 2631| 191|{ 2632| 191| int r; 2633| | 2634| 191| if ((k->sk_key_handle = sshbuf_new()) == NULL || ------------------ | | 44| 191|#define sshbuf_new() sshbuf_new_label(__func__) ------------------ | Branch (2634:6): [True: 0, False: 191] ------------------ 2635| 191| (k->sk_reserved = sshbuf_new()) == NULL) ------------------ | | 44| 191|#define sshbuf_new() sshbuf_new_label(__func__) ------------------ | Branch (2635:6): [True: 0, False: 191] ------------------ 2636| 0| return SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 2637| 191| if ((r = sshbuf_get_cstring(buf, &k->sk_application, NULL)) != 0 || ------------------ | Branch (2637:6): [True: 5, False: 186] ------------------ 2638| 186| (r = sshbuf_get_u8(buf, &k->sk_flags)) != 0 || ------------------ | Branch (2638:6): [True: 6, False: 180] ------------------ 2639| 180| (r = sshbuf_get_stringb(buf, k->sk_key_handle)) != 0 || ------------------ | Branch (2639:6): [True: 61, False: 119] ------------------ 2640| 119| (r = sshbuf_get_stringb(buf, k->sk_reserved)) != 0) ------------------ | Branch (2640:6): [True: 61, False: 58] ------------------ 2641| 133| return r; 2642| | 2643| 58| return 0; 2644| 191|} sshkey_private_deserialize: 2648| 3.08k|{ 2649| 3.08k| const struct sshkey_impl *impl; 2650| 3.08k| char *tname = NULL; 2651| 3.08k| char *expect_sk_application = NULL; 2652| 3.08k| u_char *expect_ed25519_pk = NULL; 2653| 3.08k| struct sshkey *k = NULL; 2654| 3.08k| int type, r = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 3.08k|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 2655| | 2656| 3.08k| if (kp != NULL) ------------------ | Branch (2656:6): [True: 3.08k, False: 0] ------------------ 2657| 3.08k| *kp = NULL; 2658| 3.08k| if ((r = sshbuf_get_cstring(buf, &tname, NULL)) != 0) ------------------ | Branch (2658:6): [True: 66, False: 3.01k] ------------------ 2659| 66| goto out; 2660| 3.01k| type = sshkey_type_from_name(tname); 2661| 3.01k| if (sshkey_type_is_cert(type)) { ------------------ | Branch (2661:6): [True: 1.89k, False: 1.12k] ------------------ 2662| | /* 2663| | * Certificate key private keys begin with the certificate 2664| | * itself. Make sure this matches the type of the enclosing 2665| | * private key. 2666| | */ 2667| 1.89k| if ((r = sshkey_froms(buf, &k)) != 0) ------------------ | Branch (2667:7): [True: 1.74k, False: 148] ------------------ 2668| 1.74k| goto out; 2669| 148| if (k->type != type) { ------------------ | Branch (2669:7): [True: 11, False: 137] ------------------ 2670| 11| r = SSH_ERR_KEY_CERT_MISMATCH; ------------------ | | 69| 11|#define SSH_ERR_KEY_CERT_MISMATCH -45 ------------------ 2671| 11| goto out; 2672| 11| } 2673| | /* For ECDSA keys, the group must match too */ 2674| 137| if (k->type == KEY_ECDSA && ------------------ | Branch (2674:7): [True: 0, False: 137] ------------------ 2675| 0| k->ecdsa_nid != sshkey_ecdsa_nid_from_name(tname)) { ------------------ | Branch (2675:7): [True: 0, False: 0] ------------------ 2676| 0| r = SSH_ERR_KEY_CERT_MISMATCH; ------------------ | | 69| 0|#define SSH_ERR_KEY_CERT_MISMATCH -45 ------------------ 2677| 0| goto out; 2678| 0| } 2679| | /* 2680| | * Several fields are redundant between certificate and 2681| | * private key body, we require these to match. 2682| | */ 2683| 137| expect_sk_application = k->sk_application; 2684| 137| expect_ed25519_pk = k->ed25519_pk; 2685| 137| k->sk_application = NULL; 2686| 137| k->ed25519_pk = NULL; 2687| 1.12k| } else { 2688| 1.12k| if ((k = sshkey_new(type)) == NULL) { ------------------ | Branch (2688:7): [True: 0, False: 1.12k] ------------------ 2689| 0| r = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 2690| 0| goto out; 2691| 0| } 2692| 1.12k| } 2693| 1.26k| if ((impl = sshkey_impl_from_type(type)) == NULL) { ------------------ | Branch (2693:6): [True: 190, False: 1.07k] ------------------ 2694| 190| r = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 190|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 2695| 190| goto out; 2696| 190| } 2697| 1.07k| if ((r = impl->funcs->deserialize_private(tname, buf, k)) != 0) ------------------ | Branch (2697:6): [True: 875, False: 197] ------------------ 2698| 875| goto out; 2699| | 2700| 197| if ((expect_sk_application != NULL && (k->sk_application == NULL || ------------------ | Branch (2700:7): [True: 0, False: 197] | Branch (2700:41): [True: 0, False: 0] ------------------ 2701| 0| strcmp(expect_sk_application, k->sk_application) != 0)) || ------------------ | Branch (2701:6): [True: 0, False: 0] ------------------ 2702| 197| (expect_ed25519_pk != NULL && (k->ed25519_pk == NULL || ------------------ | Branch (2702:7): [True: 132, False: 65] | Branch (2702:37): [True: 0, False: 132] ------------------ 2703| 132| memcmp(expect_ed25519_pk, k->ed25519_pk, ED25519_PK_SZ) != 0))) { ------------------ | | 141| 132|#define ED25519_PK_SZ crypto_sign_ed25519_PUBLICKEYBYTES | | ------------------ | | | | 60| 132|#define crypto_sign_ed25519_PUBLICKEYBYTES 32U | | ------------------ ------------------ | Branch (2703:6): [True: 131, False: 1] ------------------ 2704| 131| r = SSH_ERR_KEY_CERT_MISMATCH; ------------------ | | 69| 131|#define SSH_ERR_KEY_CERT_MISMATCH -45 ------------------ 2705| 131| goto out; 2706| 131| } 2707| | /* success */ 2708| 66| r = 0; 2709| 66| if (kp != NULL) { ------------------ | Branch (2709:6): [True: 66, False: 0] ------------------ 2710| 66| *kp = k; 2711| 66| k = NULL; 2712| 66| } 2713| 3.08k| out: 2714| 3.08k| free(tname); 2715| 3.08k| sshkey_free(k); 2716| 3.08k| free(expect_sk_application); 2717| 3.08k| free(expect_ed25519_pk); 2718| 3.08k| return r; 2719| 66|} sshkey_ec_validate_public: 2724| 684|{ 2725| 684| EC_POINT *nq = NULL; 2726| 684| BIGNUM *order = NULL, *cofactor = NULL; 2727| 684| int ret = SSH_ERR_KEY_INVALID_EC_VALUE; ------------------ | | 44| 684|#define SSH_ERR_KEY_INVALID_EC_VALUE -20 ------------------ 2728| | 2729| | /* 2730| | * NB. This assumes OpenSSL has already verified that the public 2731| | * point lies on the curve and that its coordinates are in [0, p). 2732| | * This is done by EC_POINT_oct2point() on at least OpenSSL >= 1.1, 2733| | * LibreSSL and BoringSSL. 2734| | */ 2735| | 2736| | /* Q != infinity */ 2737| 684| if (EC_POINT_is_at_infinity(group, public)) ------------------ | Branch (2737:6): [True: 0, False: 684] ------------------ 2738| 0| goto out; 2739| | 2740| 684| if ((cofactor = BN_new()) == NULL) { ------------------ | Branch (2740:6): [True: 0, False: 684] ------------------ 2741| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 2742| 0| goto out; 2743| 0| } 2744| 684| if (EC_GROUP_get_cofactor(group, cofactor, NULL) != 1) ------------------ | Branch (2744:6): [True: 0, False: 684] ------------------ 2745| 0| goto out; 2746| | 2747| | /* 2748| | * Verify nQ == infinity (n == order of subgroup) 2749| | * This check may be skipped for curves with cofactor 1, as per 2750| | * NIST SP 800-56A, 5.6.2.3. 2751| | */ 2752| 684| if (!BN_is_one(cofactor)) { ------------------ | Branch (2752:6): [True: 0, False: 684] ------------------ 2753| 0| if ((order = BN_new()) == NULL) { ------------------ | Branch (2753:7): [True: 0, False: 0] ------------------ 2754| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 2755| 0| goto out; 2756| 0| } 2757| 0| if (EC_GROUP_get_order(group, order, NULL) != 1) { ------------------ | Branch (2757:7): [True: 0, False: 0] ------------------ 2758| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 2759| 0| goto out; 2760| 0| } 2761| 0| if ((nq = EC_POINT_new(group)) == NULL) { ------------------ | Branch (2761:7): [True: 0, False: 0] ------------------ 2762| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 2763| 0| goto out; 2764| 0| } 2765| 0| if (EC_POINT_mul(group, nq, NULL, public, order, NULL) != 1) { ------------------ | Branch (2765:7): [True: 0, False: 0] ------------------ 2766| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 2767| 0| goto out; 2768| 0| } 2769| 0| if (EC_POINT_is_at_infinity(group, nq) != 1) ------------------ | Branch (2769:7): [True: 0, False: 0] ------------------ 2770| 0| goto out; 2771| 0| } 2772| | 2773| | /* success */ 2774| 684| ret = 0; 2775| 684| out: 2776| 684| BN_clear_free(cofactor); 2777| 684| BN_clear_free(order); 2778| 684| EC_POINT_free(nq); 2779| 684| return ret; 2780| 684|} sshkey_ec_validate_private: 2784| 39|{ 2785| 39| BIGNUM *order = NULL, *tmp = NULL; 2786| 39| int ret = SSH_ERR_KEY_INVALID_EC_VALUE; ------------------ | | 44| 39|#define SSH_ERR_KEY_INVALID_EC_VALUE -20 ------------------ 2787| | 2788| 39| if ((order = BN_new()) == NULL || (tmp = BN_new()) == NULL) { ------------------ | Branch (2788:6): [True: 0, False: 39] | Branch (2788:36): [True: 0, False: 39] ------------------ 2789| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 2790| 0| goto out; 2791| 0| } 2792| | 2793| | /* log2(private) > log2(order)/2 */ 2794| 39| if (EC_GROUP_get_order(EC_KEY_get0_group(key), order, NULL) != 1) { ------------------ | Branch (2794:6): [True: 0, False: 39] ------------------ 2795| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 2796| 0| goto out; 2797| 0| } 2798| 39| if (BN_num_bits(EC_KEY_get0_private_key(key)) <= ------------------ | Branch (2798:6): [True: 14, False: 25] ------------------ 2799| 39| BN_num_bits(order) / 2) 2800| 14| goto out; 2801| | 2802| | /* private < order - 1 */ 2803| 25| if (!BN_sub(tmp, order, BN_value_one())) { ------------------ | Branch (2803:6): [True: 0, False: 25] ------------------ 2804| 0| ret = SSH_ERR_LIBCRYPTO_ERROR; ------------------ | | 46| 0|#define SSH_ERR_LIBCRYPTO_ERROR -22 ------------------ 2805| 0| goto out; 2806| 0| } 2807| 25| if (BN_cmp(EC_KEY_get0_private_key(key), tmp) >= 0) ------------------ | Branch (2807:6): [True: 20, False: 5] ------------------ 2808| 20| goto out; 2809| 5| ret = 0; 2810| 39| out: 2811| 39| BN_clear_free(order); 2812| 39| BN_clear_free(tmp); 2813| 39| return ret; 2814| 5|} sshkey_sig_details_free: 3751| 597|{ 3752| 597| freezero(details, sizeof(*details)); 3753| 597|} sshkey.c:sshkey_impl_from_key: 181| 1.25k|{ 182| 1.25k| if (k == NULL) ------------------ | Branch (182:6): [True: 0, False: 1.25k] ------------------ 183| 0| return NULL; 184| 1.25k| return sshkey_impl_from_type_nid(k->type, k->ecdsa_nid); 185| 1.25k|} sshkey.c:sshkey_impl_from_type_nid: 168| 1.56k|{ 169| 1.56k| int i; 170| | 171| 12.8k| for (i = 0; keyimpls[i] != NULL; i++) { ------------------ | Branch (171:14): [True: 12.8k, False: 0] ------------------ 172| 12.8k| if (keyimpls[i]->type == type && ------------------ | Branch (172:7): [True: 1.56k, False: 11.2k] ------------------ 173| 1.56k| (keyimpls[i]->nid == 0 || keyimpls[i]->nid == nid)) ------------------ | Branch (173:8): [True: 775, False: 785] | Branch (173:33): [True: 785, False: 0] ------------------ 174| 1.56k| return keyimpls[i]; 175| 12.8k| } 176| 0| return NULL; 177| 1.56k|} sshkey.c:sshkey_impl_from_type: 156| 33.5k|{ 157| 33.5k| int i; 158| | 159| 247k| for (i = 0; keyimpls[i] != NULL; i++) { ------------------ | Branch (159:14): [True: 246k, False: 1.09k] ------------------ 160| 246k| if (keyimpls[i]->type == type) ------------------ | Branch (160:7): [True: 32.4k, False: 214k] ------------------ 161| 32.4k| return keyimpls[i]; 162| 246k| } 163| 1.09k| return NULL; 164| 33.5k|} sshkey.c:sshkey_ssh_name_from_type_nid: 199| 306|{ 200| 306| const struct sshkey_impl *impl; 201| | 202| 306| if ((impl = sshkey_impl_from_type_nid(type, nid)) == NULL) ------------------ | Branch (202:6): [True: 0, False: 306] ------------------ 203| 0| return "ssh-unknown"; 204| 306| return impl->name; 205| 306|} sshkey.c:type_from_name: 232| 6.19k|{ 233| 6.19k| int i; 234| 6.19k| const struct sshkey_impl *impl; 235| | 236| 59.4k| for (i = 0; keyimpls[i] != NULL; i++) { ------------------ | Branch (236:14): [True: 59.1k, False: 327] ------------------ 237| 59.1k| impl = keyimpls[i]; 238| 59.1k| if (impl->name != NULL && strcmp(name, impl->name) == 0) ------------------ | Branch (238:7): [True: 59.1k, False: 0] | Branch (238:29): [True: 5.86k, False: 53.2k] ------------------ 239| 5.86k| return impl->type; 240| | /* Only allow shortname matches for plain key types */ 241| 53.2k| if (allow_short && !impl->cert && impl->shortname != NULL && ------------------ | Branch (241:7): [True: 0, False: 53.2k] | Branch (241:22): [True: 0, False: 0] | Branch (241:37): [True: 0, False: 0] ------------------ 242| 0| strcasecmp(impl->shortname, name) == 0) ------------------ | Branch (242:7): [True: 0, False: 0] ------------------ 243| 0| return impl->type; 244| 53.2k| } 245| 327| return KEY_UNSPEC; 246| 6.19k|} sshkey.c:key_type_is_ecdsa_variant: 262| 9.76k|{ 263| 9.76k| switch (type) { ------------------ | Branch (263:10): [True: 3.99k, False: 5.77k] ------------------ 264| 1.99k| case KEY_ECDSA: ------------------ | Branch (264:2): [True: 1.99k, False: 7.77k] ------------------ 265| 3.50k| case KEY_ECDSA_CERT: ------------------ | Branch (265:2): [True: 1.51k, False: 8.25k] ------------------ 266| 3.99k| case KEY_ECDSA_SK: ------------------ | Branch (266:2): [True: 483, False: 9.28k] ------------------ 267| 3.99k| case KEY_ECDSA_SK_CERT: ------------------ | Branch (267:2): [True: 5, False: 9.76k] ------------------ 268| 3.99k| return 1; 269| 9.76k| } 270| 5.77k| return 0; 271| 9.76k|} sshkey.c:ssh_digest_to_md: 478| 17|{ 479| 17| switch (hash_alg) { ------------------ | Branch (479:10): [True: 17, False: 0] ------------------ 480| 9| case SSH_DIGEST_SHA1: ------------------ | | 26| 9|#define SSH_DIGEST_SHA1 1 ------------------ | Branch (480:2): [True: 9, False: 8] ------------------ 481| 9| return EVP_sha1(); 482| 7| case SSH_DIGEST_SHA256: ------------------ | | 27| 7|#define SSH_DIGEST_SHA256 2 ------------------ | Branch (482:2): [True: 7, False: 10] ------------------ 483| 7| return EVP_sha256(); 484| 0| case SSH_DIGEST_SHA384: ------------------ | | 28| 0|#define SSH_DIGEST_SHA384 3 ------------------ | Branch (484:2): [True: 0, False: 17] ------------------ 485| 0| return EVP_sha384(); 486| 1| case SSH_DIGEST_SHA512: ------------------ | | 29| 1|#define SSH_DIGEST_SHA512 4 ------------------ | Branch (486:2): [True: 1, False: 16] ------------------ 487| 1| return EVP_sha512(); 488| 17| } 489| 0| return NULL; 490| 17|} sshkey.c:cert_new: 666| 1.56k|{ 667| 1.56k| struct sshkey_cert *cert; 668| | 669| 1.56k| if ((cert = calloc(1, sizeof(*cert))) == NULL) ------------------ | Branch (669:6): [True: 0, False: 1.56k] ------------------ 670| 0| return NULL; 671| 1.56k| if ((cert->certblob = sshbuf_new()) == NULL || ------------------ | | 44| 1.56k|#define sshbuf_new() sshbuf_new_label(__func__) ------------------ | Branch (671:6): [True: 0, False: 1.56k] ------------------ 672| 1.56k| (cert->critical = sshbuf_new()) == NULL || ------------------ | | 44| 1.56k|#define sshbuf_new() sshbuf_new_label(__func__) ------------------ | Branch (672:6): [True: 0, False: 1.56k] ------------------ 673| 1.56k| (cert->extensions = sshbuf_new()) == NULL) { ------------------ | | 44| 1.56k|#define sshbuf_new() sshbuf_new_label(__func__) ------------------ | Branch (673:6): [True: 0, False: 1.56k] ------------------ 674| 0| cert_free(cert); 675| 0| return NULL; 676| 0| } 677| 1.56k| cert->key_id = NULL; 678| 1.56k| cert->principals = NULL; 679| 1.56k| cert->signature_key = NULL; 680| | cert->signature_type = NULL; 681| 1.56k| return cert; 682| 1.56k|} sshkey.c:sshkey_free_contents: 768| 10.9k|{ 769| 10.9k| const struct sshkey_impl *impl; 770| | 771| 10.9k| if (k == NULL) ------------------ | Branch (771:6): [True: 6.79k, False: 4.16k] ------------------ 772| 6.79k| return; 773| 4.16k| if ((k->flags & SSHKEY_FLAG_EXT) != 0) ------------------ | | 94| 4.16k|#define SSHKEY_FLAG_EXT 0x0001 ------------------ | Branch (773:6): [True: 0, False: 4.16k] ------------------ 774| 0| pkcs11_key_free(k); 775| 4.16k| if ((impl = sshkey_impl_from_type(k->type)) != NULL && ------------------ | Branch (775:6): [True: 3.97k, False: 190] ------------------ 776| 3.97k| impl->funcs->cleanup != NULL) ------------------ | Branch (776:6): [True: 3.97k, False: 0] ------------------ 777| 3.97k| impl->funcs->cleanup(k); 778| 4.16k| if (sshkey_is_cert(k)) ------------------ | Branch (778:6): [True: 1.56k, False: 2.60k] ------------------ 779| 1.56k| cert_free(k->cert); 780| 4.16k| freezero(k->shielded_private, k->shielded_len); 781| 4.16k| sshkey_prekey_free(k->shield_prekey, k->shield_prekey_len); 782| 4.16k|} sshkey.c:cert_free: 647| 1.56k|{ 648| 1.56k| u_int i; 649| | 650| 1.56k| if (cert == NULL) ------------------ | Branch (650:6): [True: 0, False: 1.56k] ------------------ 651| 0| return; 652| 1.56k| sshbuf_free(cert->certblob); 653| 1.56k| sshbuf_free(cert->critical); 654| 1.56k| sshbuf_free(cert->extensions); 655| 1.56k| free(cert->key_id); 656| 3.91k| for (i = 0; i < cert->nprincipals; i++) ------------------ | Branch (656:14): [True: 2.35k, False: 1.56k] ------------------ 657| 2.35k| free(cert->principals[i]); 658| 1.56k| free(cert->principals); 659| 1.56k| sshkey_free(cert->signature_key); 660| 1.56k| free(cert->signature_type); 661| 1.56k| freezero(cert, sizeof(*cert)); 662| 1.56k|} sshkey.c:sshkey_prekey_free: 756| 4.16k|{ 757| 4.16k|#if defined(HAVE_MMAP) && defined(MAP_ANON) && defined(MAP_PRIVATE) 758| 4.16k| if (prekey == NULL) ------------------ | Branch (758:6): [True: 4.16k, False: 0] ------------------ 759| 4.16k| return; 760| 0| munmap(prekey, len); 761| |#else 762| | free(prekey); 763| |#endif /* HAVE_MMAP et al */ 764| 0|} sshkey.c:sshkey_from_blob_internal: 2016| 3.23k|{ 2017| 3.23k| int type, ret = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 3.23k|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 2018| 3.23k| char *ktype = NULL; 2019| 3.23k| struct sshkey *key = NULL; 2020| 3.23k| struct sshbuf *copy; 2021| 3.23k| const struct sshkey_impl *impl; 2022| | 2023| |#ifdef DEBUG_PK /* XXX */ 2024| | sshbuf_dump(b, stderr); 2025| |#endif 2026| 3.23k| if (keyp != NULL) ------------------ | Branch (2026:6): [True: 3.23k, False: 0] ------------------ 2027| 3.23k| *keyp = NULL; 2028| 3.23k| if ((copy = sshbuf_fromb(b)) == NULL) { ------------------ | Branch (2028:6): [True: 0, False: 3.23k] ------------------ 2029| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 2030| 0| goto out; 2031| 0| } 2032| 3.23k| if (sshbuf_get_cstring(b, &ktype, NULL) != 0) { ------------------ | Branch (2032:6): [True: 49, False: 3.18k] ------------------ 2033| 49| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 49|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 2034| 49| goto out; 2035| 49| } 2036| | 2037| 3.18k| type = sshkey_type_from_name(ktype); 2038| 3.18k| if (!allow_cert && sshkey_type_is_cert(type)) { ------------------ | Branch (2038:6): [True: 1.40k, False: 1.77k] | Branch (2038:21): [True: 2, False: 1.40k] ------------------ 2039| 2| ret = SSH_ERR_KEY_CERT_INVALID_SIGN_KEY; ------------------ | | 43| 2|#define SSH_ERR_KEY_CERT_INVALID_SIGN_KEY -19 ------------------ 2040| 2| goto out; 2041| 2| } 2042| | 2043| 3.17k| if (alg_allowlist != NULL && ------------------ | Branch (2043:6): [True: 0, False: 3.17k] ------------------ 2044| 0| !sshkey_match_keyname_to_sigalgs(ktype, alg_allowlist)) { ------------------ | Branch (2044:6): [True: 0, False: 0] ------------------ 2045| 0| ret = SSH_ERR_KEY_ALG_UNSUPPORTED; ------------------ | | 87| 0|#define SSH_ERR_KEY_ALG_UNSUPPORTED -63 ------------------ 2046| 0| goto out; 2047| 0| } 2048| | 2049| 3.17k| if ((impl = sshkey_impl_from_type(type)) == NULL) { ------------------ | Branch (2049:6): [True: 137, False: 3.04k] ------------------ 2050| 137| ret = SSH_ERR_KEY_TYPE_UNKNOWN; ------------------ | | 38| 137|#define SSH_ERR_KEY_TYPE_UNKNOWN -14 /* XXX UNSUPPORTED? */ ------------------ 2051| 137| goto out; 2052| 137| } 2053| 3.04k| if ((key = sshkey_new(type)) == NULL) { ------------------ | Branch (2053:6): [True: 0, False: 3.04k] ------------------ 2054| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 2055| 0| goto out; 2056| 0| } 2057| 3.04k| if (sshkey_type_is_cert(type)) { ------------------ | Branch (2057:6): [True: 1.56k, False: 1.47k] ------------------ 2058| | /* Skip nonce that precedes all certificates */ 2059| 1.56k| if (sshbuf_get_string_direct(b, NULL, NULL) != 0) { ------------------ | Branch (2059:7): [True: 59, False: 1.50k] ------------------ 2060| 59| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 59|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 2061| 59| goto out; 2062| 59| } 2063| 1.56k| } 2064| 2.98k| if ((ret = impl->funcs->deserialize_public(ktype, b, key)) != 0) ------------------ | Branch (2064:6): [True: 84, False: 2.89k] ------------------ 2065| 84| goto out; 2066| | 2067| | /* Parse certificate potion */ 2068| 2.89k| if (sshkey_is_cert(key) && ------------------ | Branch (2068:6): [True: 1.48k, False: 1.41k] ------------------ 2069| 1.48k| (ret = cert_parse(b, key, copy, ca_sigalg_allowlist)) != 0) ------------------ | Branch (2069:6): [True: 1.34k, False: 141] ------------------ 2070| 1.34k| goto out; 2071| | 2072| 1.55k| if (key != NULL && sshbuf_len(b) != 0) { ------------------ | Branch (2072:6): [True: 1.55k, False: 0] | Branch (2072:21): [True: 18, False: 1.53k] ------------------ 2073| 18| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 18|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 2074| 18| goto out; 2075| 18| } 2076| 1.53k| ret = 0; 2077| 1.53k| if (keyp != NULL) { ------------------ | Branch (2077:6): [True: 1.53k, False: 0] ------------------ 2078| 1.53k| *keyp = key; 2079| 1.53k| key = NULL; 2080| 1.53k| } 2081| 3.23k| out: 2082| 3.23k| sshbuf_free(copy); 2083| 3.23k| sshkey_free(key); 2084| 3.23k| free(ktype); 2085| 3.23k| return ret; 2086| 1.53k|} sshkey.c:cert_parse: 1865| 1.48k|{ 1866| 1.48k| struct sshbuf *principals = NULL, *crit = NULL; 1867| 1.48k| struct sshbuf *exts = NULL, *ca = NULL; 1868| 1.48k| u_char *sig = NULL; 1869| 1.48k| char *sigtype = NULL; 1870| 1.48k| size_t signed_len = 0, slen = 0, kidlen = 0; 1871| 1.48k| int ret = SSH_ERR_INTERNAL_ERROR; ------------------ | | 25| 1.48k|#define SSH_ERR_INTERNAL_ERROR -1 ------------------ 1872| | 1873| | /* Copy the entire key blob for verification and later serialisation */ 1874| 1.48k| if ((ret = sshbuf_putb(key->cert->certblob, certbuf)) != 0) ------------------ | Branch (1874:6): [True: 0, False: 1.48k] ------------------ 1875| 0| return ret; 1876| | 1877| | /* Parse body of certificate up to signature */ 1878| 1.48k| if ((ret = sshbuf_get_u64(b, &key->cert->serial)) != 0 || ------------------ | Branch (1878:6): [True: 7, False: 1.47k] ------------------ 1879| 1.47k| (ret = sshbuf_get_u32(b, &key->cert->type)) != 0 || ------------------ | Branch (1879:6): [True: 2, False: 1.47k] ------------------ 1880| 1.47k| (ret = sshbuf_get_cstring(b, &key->cert->key_id, &kidlen)) != 0 || ------------------ | Branch (1880:6): [True: 15, False: 1.46k] ------------------ 1881| 1.46k| (ret = sshbuf_froms(b, &principals)) != 0 || ------------------ | Branch (1881:6): [True: 8, False: 1.45k] ------------------ 1882| 1.45k| (ret = sshbuf_get_u64(b, &key->cert->valid_after)) != 0 || ------------------ | Branch (1882:6): [True: 5, False: 1.44k] ------------------ 1883| 1.44k| (ret = sshbuf_get_u64(b, &key->cert->valid_before)) != 0 || ------------------ | Branch (1883:6): [True: 3, False: 1.44k] ------------------ 1884| 1.44k| (ret = sshbuf_froms(b, &crit)) != 0 || ------------------ | Branch (1884:6): [True: 3, False: 1.44k] ------------------ 1885| 1.44k| (ret = sshbuf_froms(b, &exts)) != 0 || ------------------ | Branch (1885:6): [True: 5, False: 1.43k] ------------------ 1886| 1.43k| (ret = sshbuf_get_string_direct(b, NULL, NULL)) != 0 || ------------------ | Branch (1886:6): [True: 4, False: 1.43k] ------------------ 1887| 1.43k| (ret = sshbuf_froms(b, &ca)) != 0) { ------------------ | Branch (1887:6): [True: 3, False: 1.42k] ------------------ 1888| | /* XXX debug print error for ret */ 1889| 55| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 55|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 1890| 55| goto out; 1891| 55| } 1892| | 1893| | /* Signature is left in the buffer so we can calculate this length */ 1894| 1.42k| signed_len = sshbuf_len(key->cert->certblob) - sshbuf_len(b); 1895| | 1896| 1.42k| if ((ret = sshbuf_get_string(b, &sig, &slen)) != 0) { ------------------ | Branch (1896:6): [True: 6, False: 1.42k] ------------------ 1897| 6| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 6|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 1898| 6| goto out; 1899| 6| } 1900| | 1901| | /* Is this a signature we're prepared to accept? */ 1902| 1.42k| if ((ret = sshkey_get_sigtype(sig, slen, &sigtype)) != 0) { ------------------ | Branch (1902:6): [True: 19, False: 1.40k] ------------------ 1903| 19| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 19|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 1904| 19| goto out; 1905| 19| } 1906| 1.40k| if (ca_sigalg_allowlist != NULL && ------------------ | Branch (1906:6): [True: 0, False: 1.40k] ------------------ 1907| 0| match_pattern_list(sigtype, ca_sigalg_allowlist, 0) != 1) { ------------------ | Branch (1907:6): [True: 0, False: 0] ------------------ 1908| 0| ret = SSH_ERR_SIGN_ALG_UNSUPPORTED; ------------------ | | 82| 0|#define SSH_ERR_SIGN_ALG_UNSUPPORTED -58 ------------------ 1909| 0| goto out; 1910| 0| } 1911| | 1912| | /* Parse CA key and check whether we might accept it */ 1913| 1.40k| if (sshkey_from_blob_internal(ca, &key->cert->signature_key, 0, ------------------ | Branch (1913:6): [True: 14, False: 1.39k] ------------------ 1914| 1.40k| ca_sigalg_allowlist, NULL) != 0) { 1915| 14| ret = SSH_ERR_KEY_CERT_INVALID_SIGN_KEY; ------------------ | | 43| 14|#define SSH_ERR_KEY_CERT_INVALID_SIGN_KEY -19 ------------------ 1916| 14| goto out; 1917| 14| } 1918| 1.39k| if (!sshkey_type_is_valid_ca(key->cert->signature_key->type)) { ------------------ | Branch (1918:6): [True: 0, False: 1.39k] ------------------ 1919| 0| ret = SSH_ERR_KEY_CERT_INVALID_SIGN_KEY; ------------------ | | 43| 0|#define SSH_ERR_KEY_CERT_INVALID_SIGN_KEY -19 ------------------ 1920| 0| goto out; 1921| 0| } 1922| | 1923| 1.39k| if (key->cert->type != SSH2_CERT_TYPE_USER && ------------------ | | 179| 2.78k|#define SSH2_CERT_TYPE_USER 1 ------------------ | Branch (1923:6): [True: 492, False: 898] ------------------ 1924| 492| key->cert->type != SSH2_CERT_TYPE_HOST) { ------------------ | | 180| 492|#define SSH2_CERT_TYPE_HOST 2 ------------------ | Branch (1924:6): [True: 51, False: 441] ------------------ 1925| 51| ret = SSH_ERR_KEY_CERT_UNKNOWN_TYPE; ------------------ | | 42| 51|#define SSH_ERR_KEY_CERT_UNKNOWN_TYPE -18 ------------------ 1926| 51| goto out; 1927| 51| } 1928| | 1929| | /* Parse principals section */ 1930| 3.69k| while (sshbuf_len(principals) > 0) { ------------------ | Branch (1930:9): [True: 2.38k, False: 1.30k] ------------------ 1931| 2.38k| char *principal = NULL; 1932| 2.38k| char **oprincipals = NULL; 1933| | 1934| 2.38k| if (key->cert->nprincipals >= SSHKEY_CERT_MAX_PRINCIPALS) { ------------------ | | 96| 2.38k|#define SSHKEY_CERT_MAX_PRINCIPALS 256 ------------------ | Branch (1934:7): [True: 2, False: 2.38k] ------------------ 1935| 2| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 2|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 1936| 2| goto out; 1937| 2| } 1938| 2.38k| if ((ret = sshbuf_get_cstring(principals, &principal, ------------------ | Branch (1938:7): [True: 28, False: 2.35k] ------------------ 1939| 2.38k| NULL)) != 0) { 1940| 28| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 28|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 1941| 28| goto out; 1942| 28| } 1943| 2.35k| oprincipals = key->cert->principals; 1944| 2.35k| key->cert->principals = recallocarray(key->cert->principals, 1945| 2.35k| key->cert->nprincipals, key->cert->nprincipals + 1, 1946| 2.35k| sizeof(*key->cert->principals)); 1947| 2.35k| if (key->cert->principals == NULL) { ------------------ | Branch (1947:7): [True: 0, False: 2.35k] ------------------ 1948| 0| free(principal); 1949| 0| key->cert->principals = oprincipals; 1950| 0| ret = SSH_ERR_ALLOC_FAIL; ------------------ | | 26| 0|#define SSH_ERR_ALLOC_FAIL -2 ------------------ 1951| 0| goto out; 1952| 0| } 1953| 2.35k| key->cert->principals[key->cert->nprincipals++] = principal; 1954| 2.35k| } 1955| | 1956| | /* 1957| | * Stash a copies of the critical options and extensions sections 1958| | * for later use. 1959| | */ 1960| 1.30k| if ((ret = sshbuf_putb(key->cert->critical, crit)) != 0 || ------------------ | Branch (1960:6): [True: 0, False: 1.30k] ------------------ 1961| 1.30k| (exts != NULL && ------------------ | Branch (1961:7): [True: 1.30k, False: 0] ------------------ 1962| 1.30k| (ret = sshbuf_putb(key->cert->extensions, exts)) != 0)) ------------------ | Branch (1962:6): [True: 0, False: 1.30k] ------------------ 1963| 0| goto out; 1964| | 1965| | /* 1966| | * Validate critical options and extensions sections format. 1967| | */ 1968| 2.68k| while (sshbuf_len(crit) != 0) { ------------------ | Branch (1968:9): [True: 1.40k, False: 1.28k] ------------------ 1969| 1.40k| if ((ret = sshbuf_get_string_direct(crit, NULL, NULL)) != 0 || ------------------ | Branch (1969:7): [True: 19, False: 1.38k] ------------------ 1970| 1.38k| (ret = sshbuf_get_string_direct(crit, NULL, NULL)) != 0) { ------------------ | Branch (1970:7): [True: 6, False: 1.37k] ------------------ 1971| 25| sshbuf_reset(key->cert->critical); 1972| 25| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 25|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 1973| 25| goto out; 1974| 25| } 1975| 1.40k| } 1976| 3.32k| while (exts != NULL && sshbuf_len(exts) != 0) { ------------------ | Branch (1976:9): [True: 3.32k, False: 0] | Branch (1976:25): [True: 2.06k, False: 1.25k] ------------------ 1977| 2.06k| if ((ret = sshbuf_get_string_direct(exts, NULL, NULL)) != 0 || ------------------ | Branch (1977:7): [True: 20, False: 2.04k] ------------------ 1978| 2.04k| (ret = sshbuf_get_string_direct(exts, NULL, NULL)) != 0) { ------------------ | Branch (1978:7): [True: 10, False: 2.03k] ------------------ 1979| 30| sshbuf_reset(key->cert->extensions); 1980| 30| ret = SSH_ERR_INVALID_FORMAT; ------------------ | | 28| 30|#define SSH_ERR_INVALID_FORMAT -4 ------------------ 1981| 30| goto out; 1982| 30| } 1983| 2.06k| } 1984| | 1985| | /* Finally, validate signature */ 1986| 1.25k| if ((ret = sshkey_verify(key->cert->signature_key, sig, slen, ------------------ | Branch (1986:6): [True: 1.11k, False: 141] ------------------ 1987| 1.25k| sshbuf_ptr(key->cert->certblob), signed_len, NULL, 0, NULL)) != 0) 1988| 1.11k| goto out; 1989| | 1990| | /* Success */ 1991| 141| ret = 0; 1992| 141| key->cert->signature_type = sigtype; 1993| 141| sigtype = NULL; 1994| 1.48k| out: 1995| 1.48k| sshbuf_free(ca); 1996| 1.48k| sshbuf_free(crit); 1997| 1.48k| sshbuf_free(exts); 1998| 1.48k| sshbuf_free(principals); 1999| 1.48k| free(sig); 2000| 1.48k| free(sigtype); 2001| 1.48k| return ret; 2002| 141|} sshkey.c:sshkey_type_is_valid_ca: 400| 1.39k|{ 401| 1.39k| const struct sshkey_impl *impl; 402| | 403| 1.39k| if ((impl = sshkey_impl_from_type(type)) == NULL) ------------------ | Branch (403:6): [True: 0, False: 1.39k] ------------------ 404| 0| return 0; 405| | /* All non-certificate types may act as CAs */ 406| 1.39k| return !impl->cert; 407| 1.39k|}