| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/rsa/rsa_sign.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | static int encode_pkcs1(unsigned char **out, int *out_len, int type, | - | ||||||||||||
| 2 | const unsigned char *m, unsigned int m_len) | - | ||||||||||||
| 3 | { | - | ||||||||||||
| 4 | X509_SIG sig; | - | ||||||||||||
| 5 | X509_ALGOR algor; | - | ||||||||||||
| 6 | ASN1_TYPE parameter; | - | ||||||||||||
| 7 | ASN1_OCTET_STRING digest; | - | ||||||||||||
| 8 | uint8_t *der = | - | ||||||||||||
| 9 | ((void *)0) | - | ||||||||||||
| 10 | ; | - | ||||||||||||
| 11 | int len; | - | ||||||||||||
| 12 | - | |||||||||||||
| 13 | sig.algor = &algor; | - | ||||||||||||
| 14 | sig.algor->algorithm = OBJ_nid2obj(type); | - | ||||||||||||
| 15 | if (sig.algor->algorithm ==
| 0-1567 | ||||||||||||
| 16 | ((void *)0)
| 0-1567 | ||||||||||||
| 17 | ) { | - | ||||||||||||
| 18 | ERR_put_error(4,(146),(117),__FILE__,44); | - | ||||||||||||
| 19 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 20 | } | - | ||||||||||||
| 21 | if (OBJ_length(sig.algor->algorithm) == 0
| 0-1567 | ||||||||||||
| 22 | ERR_put_error(4,(146),(116),__FILE__,49) | - | ||||||||||||
| 23 | ; | - | ||||||||||||
| 24 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 25 | } | - | ||||||||||||
| 26 | parameter.type = 5; | - | ||||||||||||
| 27 | parameter.value.ptr = | - | ||||||||||||
| 28 | ((void *)0) | - | ||||||||||||
| 29 | ; | - | ||||||||||||
| 30 | sig.algor->parameter = ¶meter; | - | ||||||||||||
| 31 | - | |||||||||||||
| 32 | sig.digest = &digest; | - | ||||||||||||
| 33 | sig.digest->data = (unsigned char *)m; | - | ||||||||||||
| 34 | sig.digest->length = m_len; | - | ||||||||||||
| 35 | - | |||||||||||||
| 36 | len = i2d_X509_SIG(&sig, &der); | - | ||||||||||||
| 37 | if (len < 0
| 0-1567 | ||||||||||||
| 38 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 39 | - | |||||||||||||
| 40 | *out = der; | - | ||||||||||||
| 41 | *out_len = len; | - | ||||||||||||
| 42 | return executed 1567 times by 1 test: 1;return 1;Executed by:
executed 1567 times by 1 test: return 1;Executed by:
| 1567 | ||||||||||||
| 43 | } | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | int RSA_sign(int type, const unsigned char *m, unsigned int m_len, | - | ||||||||||||
| 46 | unsigned char *sigret, unsigned int *siglen, RSA *rsa) | - | ||||||||||||
| 47 | { | - | ||||||||||||
| 48 | int encrypt_len, encoded_len = 0, ret = 0; | - | ||||||||||||
| 49 | unsigned char *tmps = | - | ||||||||||||
| 50 | ((void *)0) | - | ||||||||||||
| 51 | ; | - | ||||||||||||
| 52 | const unsigned char *encoded = | - | ||||||||||||
| 53 | ((void *)0) | - | ||||||||||||
| 54 | ; | - | ||||||||||||
| 55 | - | |||||||||||||
| 56 | if (rsa->meth->rsa_sign
| 0-559 | ||||||||||||
| 57 | return never executed: rsa->meth->rsa_sign(type, m, m_len, sigret, siglen, rsa);return rsa->meth->rsa_sign(type, m, m_len, sigret, siglen, rsa);never executed: return rsa->meth->rsa_sign(type, m, m_len, sigret, siglen, rsa); | 0 | ||||||||||||
| 58 | } | - | ||||||||||||
| 59 | - | |||||||||||||
| 60 | - | |||||||||||||
| 61 | if (type == 114
| 178-381 | ||||||||||||
| 62 | - | |||||||||||||
| 63 | - | |||||||||||||
| 64 | - | |||||||||||||
| 65 | - | |||||||||||||
| 66 | - | |||||||||||||
| 67 | if (m_len != 36
| 0-381 | ||||||||||||
| 68 | ERR_put_error(4,(117),(131),__FILE__,88); | - | ||||||||||||
| 69 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 70 | } | - | ||||||||||||
| 71 | encoded_len = 36; | - | ||||||||||||
| 72 | encoded = m; | - | ||||||||||||
| 73 | } executed 381 times by 1 test: else {end of blockExecuted by:
| 381 | ||||||||||||
| 74 | if (!encode_pkcs1(&tmps, &encoded_len, type, m, m_len)
| 0-178 | ||||||||||||
| 75 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 76 | encoded = tmps; | - | ||||||||||||
| 77 | } executed 178 times by 1 test: end of blockExecuted by:
| 178 | ||||||||||||
| 78 | - | |||||||||||||
| 79 | if (encoded_len > RSA_size(rsa) - 11
| 0-559 | ||||||||||||
| 80 | ERR_put_error(4,(117),(112),__FILE__,100); | - | ||||||||||||
| 81 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 82 | } | - | ||||||||||||
| 83 | encrypt_len = RSA_private_encrypt(encoded_len, encoded, sigret, rsa, | - | ||||||||||||
| 84 | 1); | - | ||||||||||||
| 85 | if (encrypt_len <= 0
| 0-559 | ||||||||||||
| 86 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 87 | - | |||||||||||||
| 88 | *siglen = encrypt_len; | - | ||||||||||||
| 89 | ret = 1; | - | ||||||||||||
| 90 | - | |||||||||||||
| 91 | err: code before this statement executed 559 times by 1 test: err:Executed by:
| 559 | ||||||||||||
| 92 | CRYPTO_clear_free(tmps, (size_t)encoded_len, __FILE__, 112); | - | ||||||||||||
| 93 | return executed 559 times by 1 test: ret;return ret;Executed by:
executed 559 times by 1 test: return ret;Executed by:
| 559 | ||||||||||||
| 94 | } | - | ||||||||||||
| 95 | int int_rsa_verify(int type, const unsigned char *m, unsigned int m_len, | - | ||||||||||||
| 96 | unsigned char *rm, size_t *prm_len, | - | ||||||||||||
| 97 | const unsigned char *sigbuf, size_t siglen, RSA *rsa) | - | ||||||||||||
| 98 | { | - | ||||||||||||
| 99 | int decrypt_len, ret = 0, encoded_len = 0; | - | ||||||||||||
| 100 | unsigned char *decrypt_buf = | - | ||||||||||||
| 101 | ((void *)0) | - | ||||||||||||
| 102 | , *encoded = | - | ||||||||||||
| 103 | ((void *)0) | - | ||||||||||||
| 104 | ; | - | ||||||||||||
| 105 | - | |||||||||||||
| 106 | if (siglen != (size_t)RSA_size(rsa)
| 3-1766 | ||||||||||||
| 107 | ERR_put_error(4,(145),(119),__FILE__,132); | - | ||||||||||||
| 108 | return executed 3 times by 1 test: 0;return 0;Executed by:
executed 3 times by 1 test: return 0;Executed by:
| 3 | ||||||||||||
| 109 | } | - | ||||||||||||
| 110 | - | |||||||||||||
| 111 | - | |||||||||||||
| 112 | decrypt_buf = CRYPTO_malloc(siglen, __FILE__, 137); | - | ||||||||||||
| 113 | if (decrypt_buf ==
| 0-1766 | ||||||||||||
| 114 | ((void *)0)
| 0-1766 | ||||||||||||
| 115 | ) { | - | ||||||||||||
| 116 | ERR_put_error(4,(145),((1|64)),__FILE__,139); | - | ||||||||||||
| 117 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 118 | } | - | ||||||||||||
| 119 | - | |||||||||||||
| 120 | decrypt_len = RSA_public_decrypt((int)siglen, sigbuf, decrypt_buf, rsa, | - | ||||||||||||
| 121 | 1); | - | ||||||||||||
| 122 | if (decrypt_len <= 0
| 23-1743 | ||||||||||||
| 123 | goto executed 23 times by 1 test: err;goto err;Executed by:
executed 23 times by 1 test: goto err;Executed by:
| 23 | ||||||||||||
| 124 | - | |||||||||||||
| 125 | if (type == 114
| 350-1393 | ||||||||||||
| 126 | - | |||||||||||||
| 127 | - | |||||||||||||
| 128 | - | |||||||||||||
| 129 | - | |||||||||||||
| 130 | - | |||||||||||||
| 131 | if (decrypt_len != 36
| 3-347 | ||||||||||||
| 132 | ERR_put_error(4,(145),(104),__FILE__,155); | - | ||||||||||||
| 133 | goto executed 3 times by 1 test: err;goto err;Executed by:
executed 3 times by 1 test: goto err;Executed by:
| 3 | ||||||||||||
| 134 | } | - | ||||||||||||
| 135 | - | |||||||||||||
| 136 | if (rm !=
| 1-346 | ||||||||||||
| 137 | ((void *)0)
| 1-346 | ||||||||||||
| 138 | ) { | - | ||||||||||||
| 139 | memcpy(rm, decrypt_buf, 36); | - | ||||||||||||
| 140 | *prm_len = 36; | - | ||||||||||||
| 141 | } executed 1 time by 1 test: else {end of blockExecuted by:
| 1 | ||||||||||||
| 142 | if (m_len != 36
| 1-345 | ||||||||||||
| 143 | ERR_put_error(4,(145),(131),__FILE__,164); | - | ||||||||||||
| 144 | goto executed 1 time by 1 test: err;goto err;Executed by:
executed 1 time by 1 test: goto err;Executed by:
| 1 | ||||||||||||
| 145 | } | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | if (memcmp(decrypt_buf, m, 36) != 0
| 2-343 | ||||||||||||
| 148 | ERR_put_error(4,(145),(104),__FILE__,169); | - | ||||||||||||
| 149 | goto executed 2 times by 1 test: err;goto err;Executed by:
executed 2 times by 1 test: goto err;Executed by:
| 2 | ||||||||||||
| 150 | } | - | ||||||||||||
| 151 | } executed 343 times by 1 test: end of blockExecuted by:
| 343 | ||||||||||||
| 152 | } else if (type == 95
| 4-1384 | ||||||||||||
| 153 | && decrypt_buf[0] == 0x04
| 0-4 | ||||||||||||
| 154 | - | |||||||||||||
| 155 | - | |||||||||||||
| 156 | - | |||||||||||||
| 157 | - | |||||||||||||
| 158 | if (rm !=
| 1-3 | ||||||||||||
| 159 | ((void *)0)
| 1-3 | ||||||||||||
| 160 | ) { | - | ||||||||||||
| 161 | memcpy(rm, decrypt_buf + 2, 16); | - | ||||||||||||
| 162 | *prm_len = 16; | - | ||||||||||||
| 163 | } executed 1 time by 1 test: else {end of blockExecuted by:
| 1 | ||||||||||||
| 164 | if (m_len != 16
| 1-2 | ||||||||||||
| 165 | ERR_put_error(4,(145),(131),__FILE__,184); | - | ||||||||||||
| 166 | goto executed 1 time by 1 test: err;goto err;Executed by:
executed 1 time by 1 test: goto err;Executed by:
| 1 | ||||||||||||
| 167 | } | - | ||||||||||||
| 168 | - | |||||||||||||
| 169 | if (memcmp(m, decrypt_buf + 2, 16) != 0
| 1 | ||||||||||||
| 170 | ERR_put_error(4,(145),(104),__FILE__,189); | - | ||||||||||||
| 171 | goto executed 1 time by 1 test: err;goto err;Executed by:
executed 1 time by 1 test: goto err;Executed by:
| 1 | ||||||||||||
| 172 | } | - | ||||||||||||
| 173 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 174 | } else { | - | ||||||||||||
| 175 | - | |||||||||||||
| 176 | - | |||||||||||||
| 177 | - | |||||||||||||
| 178 | - | |||||||||||||
| 179 | - | |||||||||||||
| 180 | if (rm !=
| 7-1382 | ||||||||||||
| 181 | ((void *)0)
| 7-1382 | ||||||||||||
| 182 | ) { | - | ||||||||||||
| 183 | const EVP_MD *md = EVP_get_digestbyname(OBJ_nid2sn(type)); | - | ||||||||||||
| 184 | if (md ==
| 0-7 | ||||||||||||
| 185 | ((void *)0)
| 0-7 | ||||||||||||
| 186 | ) { | - | ||||||||||||
| 187 | ERR_put_error(4,(145),(117),__FILE__,202); | - | ||||||||||||
| 188 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 189 | } | - | ||||||||||||
| 190 | - | |||||||||||||
| 191 | m_len = EVP_MD_size(md); | - | ||||||||||||
| 192 | if (m_len > (size_t)decrypt_len
| 0-7 | ||||||||||||
| 193 | ERR_put_error(4,(145),(143),__FILE__,208); | - | ||||||||||||
| 194 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 195 | } | - | ||||||||||||
| 196 | m = decrypt_buf + decrypt_len - m_len; | - | ||||||||||||
| 197 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||
| 198 | - | |||||||||||||
| 199 | - | |||||||||||||
| 200 | if (!encode_pkcs1(&encoded, &encoded_len, type, m, m_len)
| 0-1389 | ||||||||||||
| 201 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 202 | - | |||||||||||||
| 203 | if (encoded_len != decrypt_len
| 11-1378 | ||||||||||||
| 204 | || memcmp(encoded, decrypt_buf, encoded_len) != 0
| 18-1360 | ||||||||||||
| 205 | ERR_put_error(4,(145),(104),__FILE__,220); | - | ||||||||||||
| 206 | goto executed 29 times by 1 test: err;goto err;Executed by:
executed 29 times by 1 test: goto err;Executed by:
| 29 | ||||||||||||
| 207 | } | - | ||||||||||||
| 208 | - | |||||||||||||
| 209 | - | |||||||||||||
| 210 | if (rm !=
| 2-1358 | ||||||||||||
| 211 | ((void *)0)
| 2-1358 | ||||||||||||
| 212 | ) { | - | ||||||||||||
| 213 | memcpy(rm, m, m_len); | - | ||||||||||||
| 214 | *prm_len = m_len; | - | ||||||||||||
| 215 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 216 | } executed 1360 times by 1 test: end of blockExecuted by:
| 1360 | ||||||||||||
| 217 | - | |||||||||||||
| 218 | ret = 1; | - | ||||||||||||
| 219 | - | |||||||||||||
| 220 | err: code before this statement executed 1706 times by 1 test: err:Executed by:
| 1706 | ||||||||||||
| 221 | CRYPTO_clear_free(encoded, (size_t)encoded_len, __FILE__, 234); | - | ||||||||||||
| 222 | CRYPTO_clear_free(decrypt_buf, siglen, __FILE__, 235); | - | ||||||||||||
| 223 | return executed 1766 times by 1 test: ret;return ret;Executed by:
executed 1766 times by 1 test: return ret;Executed by:
| 1766 | ||||||||||||
| 224 | } | - | ||||||||||||
| 225 | - | |||||||||||||
| 226 | int RSA_verify(int type, const unsigned char *m, unsigned int m_len, | - | ||||||||||||
| 227 | const unsigned char *sigbuf, unsigned int siglen, RSA *rsa) | - | ||||||||||||
| 228 | { | - | ||||||||||||
| 229 | - | |||||||||||||
| 230 | if (rsa->meth->rsa_verify
| 0-1758 | ||||||||||||
| 231 | return never executed: rsa->meth->rsa_verify(type, m, m_len, sigbuf, siglen, rsa);return rsa->meth->rsa_verify(type, m, m_len, sigbuf, siglen, rsa);never executed: return rsa->meth->rsa_verify(type, m, m_len, sigbuf, siglen, rsa); | 0 | ||||||||||||
| 232 | } | - | ||||||||||||
| 233 | - | |||||||||||||
| 234 | return executed 1758 times by 1 test: int_rsa_verify(type, m, m_len, return int_rsa_verify(type, m, m_len, ((void *)0) , ((void *)0) , sigbuf, siglen, rsa);Executed by:
executed 1758 times by 1 test: return int_rsa_verify(type, m, m_len, ((void *)0) , ((void *)0) , sigbuf, siglen, rsa);Executed by:
| 1758 | ||||||||||||
| 235 | ((void *)0) executed 1758 times by 1 test: return int_rsa_verify(type, m, m_len, ((void *)0) , ((void *)0) , sigbuf, siglen, rsa);Executed by:
| 1758 | ||||||||||||
| 236 | , executed 1758 times by 1 test: return int_rsa_verify(type, m, m_len, ((void *)0) , ((void *)0) , sigbuf, siglen, rsa);Executed by:
| 1758 | ||||||||||||
| 237 | ((void *)0) executed 1758 times by 1 test: return int_rsa_verify(type, m, m_len, ((void *)0) , ((void *)0) , sigbuf, siglen, rsa);Executed by:
| 1758 | ||||||||||||
| 238 | , sigbuf, siglen, rsa); executed 1758 times by 1 test: return int_rsa_verify(type, m, m_len, ((void *)0) , ((void *)0) , sigbuf, siglen, rsa);Executed by:
| 1758 | ||||||||||||
| 239 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |