| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/engine/eng_openssl.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | - | ||||||
| 6 | const int **nids, int nid); | - | ||||||
| 7 | - | |||||||
| 8 | - | |||||||
| 9 | static int openssl_digests(ENGINE *e, const EVP_MD **digest, | - | ||||||
| 10 | const int **nids, int nid); | - | ||||||
| 11 | - | |||||||
| 12 | - | |||||||
| 13 | - | |||||||
| 14 | static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id, | - | ||||||
| 15 | UI_METHOD *ui_method, void *callback_data); | - | ||||||
| 16 | - | |||||||
| 17 | - | |||||||
| 18 | - | |||||||
| 19 | static const char *engine_openssl_id = "openssl"; | - | ||||||
| 20 | static const char *engine_openssl_name = "Software engine support"; | - | ||||||
| 21 | - | |||||||
| 22 | - | |||||||
| 23 | - | |||||||
| 24 | static int | - | ||||||
| 25 | bind_helper(ENGINE *e) | - | ||||||
| 26 | { | - | ||||||
| 27 | if (!ENGINE_set_id(e, engine_openssl_id)
| 0 | ||||||
| 28 | !ENGINE_set_name(e, engine_openssl_name)
| 0 | ||||||
| 29 | - | |||||||
| 30 | - | |||||||
| 31 | || !ENGINE_set_RSA(e, RSA_get_default_method())
| 0 | ||||||
| 32 | - | |||||||
| 33 | - | |||||||
| 34 | || !ENGINE_set_DSA(e, DSA_get_default_method())
| 0 | ||||||
| 35 | - | |||||||
| 36 | - | |||||||
| 37 | || !ENGINE_set_ECDH(e, ECDH_OpenSSL())
| 0 | ||||||
| 38 | - | |||||||
| 39 | - | |||||||
| 40 | || !ENGINE_set_ECDSA(e, ECDSA_OpenSSL())
| 0 | ||||||
| 41 | - | |||||||
| 42 | - | |||||||
| 43 | || !ENGINE_set_DH(e, DH_get_default_method())
| 0 | ||||||
| 44 | - | |||||||
| 45 | || !ENGINE_set_RAND(e, RAND_SSLeay())
| 0 | ||||||
| 46 | - | |||||||
| 47 | || !ENGINE_set_ciphers(e, openssl_ciphers)
| 0 | ||||||
| 48 | - | |||||||
| 49 | - | |||||||
| 50 | || !ENGINE_set_digests(e, openssl_digests)
| 0 | ||||||
| 51 | - | |||||||
| 52 | - | |||||||
| 53 | - | |||||||
| 54 | || !ENGINE_set_load_privkey_function(e, openssl_load_privkey)
| 0 | ||||||
| 55 | - | |||||||
| 56 | ) | - | ||||||
| 57 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||
| 58 | - | |||||||
| 59 | - | |||||||
| 60 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||
| 61 | } | - | ||||||
| 62 | - | |||||||
| 63 | static ENGINE * | - | ||||||
| 64 | engine_openssl(void) | - | ||||||
| 65 | { | - | ||||||
| 66 | ENGINE *ret = ENGINE_new(); | - | ||||||
| 67 | - | |||||||
| 68 | if (ret ==
| 0 | ||||||
| 69 | ((void *)0)
| 0 | ||||||
| 70 | ) | - | ||||||
| 71 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||
| 72 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||
| 73 | ; never executed: return ((void *)0) ; | 0 | ||||||
| 74 | if (!bind_helper(ret)
| 0 | ||||||
| 75 | ENGINE_free(ret); | - | ||||||
| 76 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||
| 77 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||
| 78 | ; never executed: return ((void *)0) ; | 0 | ||||||
| 79 | } | - | ||||||
| 80 | return never executed: ret;return ret;never executed: return ret; | 0 | ||||||
| 81 | } | - | ||||||
| 82 | - | |||||||
| 83 | void | - | ||||||
| 84 | ENGINE_load_openssl(void) | - | ||||||
| 85 | { | - | ||||||
| 86 | ENGINE *toadd = engine_openssl(); | - | ||||||
| 87 | - | |||||||
| 88 | if (toadd ==
| 0 | ||||||
| 89 | ((void *)0)
| 0 | ||||||
| 90 | ) | - | ||||||
| 91 | return; never executed: return; | 0 | ||||||
| 92 | (void) ENGINE_add(toadd); | - | ||||||
| 93 | - | |||||||
| 94 | - | |||||||
| 95 | ENGINE_free(toadd); | - | ||||||
| 96 | ERR_clear_error(); | - | ||||||
| 97 | } never executed: end of block | 0 | ||||||
| 98 | - | |||||||
| 99 | static int test_cipher_nids[] = {5, 97}; | - | ||||||
| 100 | static int test_cipher_nids_number = 2; | - | ||||||
| 101 | - | |||||||
| 102 | typedef struct { | - | ||||||
| 103 | unsigned char key[16]; | - | ||||||
| 104 | RC4_KEY ks; | - | ||||||
| 105 | } TEST_RC4_KEY; | - | ||||||
| 106 | - | |||||||
| 107 | - | |||||||
| 108 | static int | - | ||||||
| 109 | test_rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | - | ||||||
| 110 | const unsigned char *iv, int enc) | - | ||||||
| 111 | { | - | ||||||
| 112 | - | |||||||
| 113 | fprintf( | - | ||||||
| 114 | stderr | - | ||||||
| 115 | , "(TEST_ENG_OPENSSL_RC4) test_init_key() called\n"); | - | ||||||
| 116 | - | |||||||
| 117 | memcpy(&((TEST_RC4_KEY *)(ctx)->cipher_data)->key[0], key, EVP_CIPHER_CTX_key_length(ctx)); | - | ||||||
| 118 | RC4_set_key(&((TEST_RC4_KEY *)(ctx)->cipher_data)->ks, EVP_CIPHER_CTX_key_length(ctx), | - | ||||||
| 119 | ((TEST_RC4_KEY *)(ctx)->cipher_data)->key); | - | ||||||
| 120 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||
| 121 | } | - | ||||||
| 122 | - | |||||||
| 123 | static int | - | ||||||
| 124 | test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | - | ||||||
| 125 | const unsigned char *in, size_t inl) | - | ||||||
| 126 | { | - | ||||||
| 127 | - | |||||||
| 128 | - | |||||||
| 129 | - | |||||||
| 130 | RC4(&((TEST_RC4_KEY *)(ctx)->cipher_data)->ks, inl, in, out); | - | ||||||
| 131 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||
| 132 | } | - | ||||||
| 133 | - | |||||||
| 134 | static const EVP_CIPHER test_r4_cipher = { | - | ||||||
| 135 | 5, | - | ||||||
| 136 | 1, 16, 0, | - | ||||||
| 137 | 0x8, | - | ||||||
| 138 | test_rc4_init_key, | - | ||||||
| 139 | test_rc4_cipher, | - | ||||||
| 140 | - | |||||||
| 141 | ((void *)0) | - | ||||||
| 142 | , | - | ||||||
| 143 | sizeof(TEST_RC4_KEY), | - | ||||||
| 144 | - | |||||||
| 145 | ((void *)0) | - | ||||||
| 146 | , | - | ||||||
| 147 | - | |||||||
| 148 | ((void *)0) | - | ||||||
| 149 | , | - | ||||||
| 150 | - | |||||||
| 151 | ((void *)0) | - | ||||||
| 152 | , | - | ||||||
| 153 | - | |||||||
| 154 | ((void *)0) | - | ||||||
| 155 | - | |||||||
| 156 | }; | - | ||||||
| 157 | - | |||||||
| 158 | static const EVP_CIPHER test_r4_40_cipher = { | - | ||||||
| 159 | 97, | - | ||||||
| 160 | 1,5 ,0, | - | ||||||
| 161 | 0x8, | - | ||||||
| 162 | test_rc4_init_key, | - | ||||||
| 163 | test_rc4_cipher, | - | ||||||
| 164 | - | |||||||
| 165 | ((void *)0) | - | ||||||
| 166 | , | - | ||||||
| 167 | sizeof(TEST_RC4_KEY), | - | ||||||
| 168 | - | |||||||
| 169 | ((void *)0) | - | ||||||
| 170 | , | - | ||||||
| 171 | - | |||||||
| 172 | ((void *)0) | - | ||||||
| 173 | , | - | ||||||
| 174 | - | |||||||
| 175 | ((void *)0) | - | ||||||
| 176 | , | - | ||||||
| 177 | - | |||||||
| 178 | ((void *)0) | - | ||||||
| 179 | - | |||||||
| 180 | }; | - | ||||||
| 181 | - | |||||||
| 182 | static int | - | ||||||
| 183 | openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid) | - | ||||||
| 184 | { | - | ||||||
| 185 | if (!cipher
| 0 | ||||||
| 186 | - | |||||||
| 187 | *nids = test_cipher_nids; | - | ||||||
| 188 | return never executed: test_cipher_nids_number;return test_cipher_nids_number;never executed: return test_cipher_nids_number; | 0 | ||||||
| 189 | } | - | ||||||
| 190 | - | |||||||
| 191 | if (nid == 5
| 0 | ||||||
| 192 | * never executed: cipher = &test_r4_cipher;*cipher = &test_r4_cipher;never executed: *cipher = &test_r4_cipher; | 0 | ||||||
| 193 | else if (nid == 97
| 0 | ||||||
| 194 | * never executed: cipher = &test_r4_40_cipher;*cipher = &test_r4_40_cipher;never executed: *cipher = &test_r4_40_cipher; | 0 | ||||||
| 195 | else { | - | ||||||
| 196 | - | |||||||
| 197 | - | |||||||
| 198 | - | |||||||
| 199 | - | |||||||
| 200 | *cipher = | - | ||||||
| 201 | ((void *)0) | - | ||||||
| 202 | ; | - | ||||||
| 203 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||
| 204 | } | - | ||||||
| 205 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||
| 206 | } | - | ||||||
| 207 | - | |||||||
| 208 | - | |||||||
| 209 | - | |||||||
| 210 | - | |||||||
| 211 | static int test_digest_nids[] = {64}; | - | ||||||
| 212 | static int test_digest_nids_number = 1; | - | ||||||
| 213 | - | |||||||
| 214 | static int | - | ||||||
| 215 | test_sha1_init(EVP_MD_CTX *ctx) | - | ||||||
| 216 | { | - | ||||||
| 217 | - | |||||||
| 218 | - | |||||||
| 219 | - | |||||||
| 220 | return never executed: SHA1_Init(ctx->md_data);return SHA1_Init(ctx->md_data);never executed: return SHA1_Init(ctx->md_data); | 0 | ||||||
| 221 | } | - | ||||||
| 222 | - | |||||||
| 223 | static int | - | ||||||
| 224 | test_sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count) | - | ||||||
| 225 | { | - | ||||||
| 226 | - | |||||||
| 227 | - | |||||||
| 228 | - | |||||||
| 229 | return never executed: SHA1_Update(ctx->md_data, data, count);return SHA1_Update(ctx->md_data, data, count);never executed: return SHA1_Update(ctx->md_data, data, count); | 0 | ||||||
| 230 | } | - | ||||||
| 231 | - | |||||||
| 232 | static int | - | ||||||
| 233 | test_sha1_final(EVP_MD_CTX *ctx, unsigned char *md) | - | ||||||
| 234 | { | - | ||||||
| 235 | - | |||||||
| 236 | - | |||||||
| 237 | - | |||||||
| 238 | return never executed: SHA1_Final(md, ctx->md_data);return SHA1_Final(md, ctx->md_data);never executed: return SHA1_Final(md, ctx->md_data); | 0 | ||||||
| 239 | } | - | ||||||
| 240 | - | |||||||
| 241 | static const EVP_MD test_sha_md = { | - | ||||||
| 242 | 64, | - | ||||||
| 243 | 65, | - | ||||||
| 244 | 20, | - | ||||||
| 245 | 0, | - | ||||||
| 246 | test_sha1_init, | - | ||||||
| 247 | test_sha1_update, | - | ||||||
| 248 | test_sha1_final, | - | ||||||
| 249 | - | |||||||
| 250 | ((void *)0) | - | ||||||
| 251 | , | - | ||||||
| 252 | - | |||||||
| 253 | ((void *)0) | - | ||||||
| 254 | , | - | ||||||
| 255 | (evp_sign_method *)RSA_sign, (evp_verify_method *)RSA_verify, {6,19,0,0}, | - | ||||||
| 256 | (16*4), | - | ||||||
| 257 | sizeof(EVP_MD *) + sizeof(SHA_CTX), | - | ||||||
| 258 | }; | - | ||||||
| 259 | - | |||||||
| 260 | static int | - | ||||||
| 261 | openssl_digests(ENGINE *e, const EVP_MD **digest, const int **nids, int nid) | - | ||||||
| 262 | { | - | ||||||
| 263 | if (!digest
| 0 | ||||||
| 264 | - | |||||||
| 265 | *nids = test_digest_nids; | - | ||||||
| 266 | return never executed: test_digest_nids_number;return test_digest_nids_number;never executed: return test_digest_nids_number; | 0 | ||||||
| 267 | } | - | ||||||
| 268 | - | |||||||
| 269 | if (nid == 64
| 0 | ||||||
| 270 | * never executed: digest = &test_sha_md;*digest = &test_sha_md;never executed: *digest = &test_sha_md; | 0 | ||||||
| 271 | else { | - | ||||||
| 272 | - | |||||||
| 273 | - | |||||||
| 274 | - | |||||||
| 275 | - | |||||||
| 276 | *digest = | - | ||||||
| 277 | ((void *)0) | - | ||||||
| 278 | ; | - | ||||||
| 279 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||
| 280 | } | - | ||||||
| 281 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||
| 282 | } | - | ||||||
| 283 | - | |||||||
| 284 | - | |||||||
| 285 | - | |||||||
| 286 | static EVP_PKEY * | - | ||||||
| 287 | openssl_load_privkey(ENGINE *eng, const char *key_id, UI_METHOD *ui_method, | - | ||||||
| 288 | void *callback_data) | - | ||||||
| 289 | { | - | ||||||
| 290 | BIO *in; | - | ||||||
| 291 | EVP_PKEY *key; | - | ||||||
| 292 | - | |||||||
| 293 | fprintf( | - | ||||||
| 294 | stderr | - | ||||||
| 295 | , "(TEST_ENG_OPENSSL_PKEY)Loading Private key %s\n", | - | ||||||
| 296 | key_id); | - | ||||||
| 297 | in = BIO_new_file(key_id, "r"); | - | ||||||
| 298 | if (!in
| 0 | ||||||
| 299 | return never executed: return ((void *)0) ;never executed: return ((void *)0) ; | 0 | ||||||
| 300 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||
| 301 | ; never executed: return ((void *)0) ; | 0 | ||||||
| 302 | key = PEM_read_bio_PrivateKey(in, | - | ||||||
| 303 | ((void *)0) | - | ||||||
| 304 | , 0, | - | ||||||
| 305 | ((void *)0) | - | ||||||
| 306 | ); | - | ||||||
| 307 | BIO_free(in); | - | ||||||
| 308 | return never executed: key;return key;never executed: return key; | 0 | ||||||
| 309 | } | - | ||||||
| Switch to Source code | Preprocessed file |