| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/pem/pem_seal.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | - | |||||||
| 6 | - | |||||||
| 7 | - | |||||||
| 8 | - | |||||||
| 9 | static void | - | ||||||
| 10 | PEM_ENCODE_SEAL_CTX_cleanup(PEM_ENCODE_SEAL_CTX *ctx) | - | ||||||
| 11 | { | - | ||||||
| 12 | EVP_CIPHER_CTX_cleanup(&ctx->cipher); | - | ||||||
| 13 | EVP_MD_CTX_cleanup(&ctx->md); | - | ||||||
| 14 | explicit_bzero(&ctx->encode, sizeof(ctx->encode)); | - | ||||||
| 15 | } never executed: end of block | 0 | ||||||
| 16 | - | |||||||
| 17 | int | - | ||||||
| 18 | PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type, | - | ||||||
| 19 | unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk) | - | ||||||
| 20 | { | - | ||||||
| 21 | unsigned char key[64]; | - | ||||||
| 22 | int ret = -1; | - | ||||||
| 23 | int i, j, max = 0; | - | ||||||
| 24 | char *s = | - | ||||||
| 25 | ((void *)0) | - | ||||||
| 26 | ; | - | ||||||
| 27 | - | |||||||
| 28 | - | |||||||
| 29 | - | |||||||
| 30 | - | |||||||
| 31 | - | |||||||
| 32 | EVP_EncodeInit(&ctx->encode); | - | ||||||
| 33 | EVP_MD_CTX_init(&ctx->md); | - | ||||||
| 34 | EVP_CIPHER_CTX_init(&ctx->cipher); | - | ||||||
| 35 | - | |||||||
| 36 | for (i = 0; i < npubk
| 0 | ||||||
| 37 | if (pubk[i]->type != 6
| 0 | ||||||
| 38 | ERR_put_error(9,(0xfff),(110),__FILE__,100); | - | ||||||
| 39 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||
| 40 | } | - | ||||||
| 41 | j = RSA_size(pubk[i]->pkey.rsa); | - | ||||||
| 42 | if (j > max
| 0 | ||||||
| 43 | max = j; never executed: max = j; | 0 | ||||||
| 44 | } never executed: end of block | 0 | ||||||
| 45 | s = reallocarray( | - | ||||||
| 46 | ((void *)0) | - | ||||||
| 47 | , max, 2); | - | ||||||
| 48 | if (s ==
| 0 | ||||||
| 49 | ((void *)0)
| 0 | ||||||
| 50 | ) { | - | ||||||
| 51 | ERR_put_error(9,(0xfff),((1|64)),__FILE__,109); | - | ||||||
| 52 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||
| 53 | } | - | ||||||
| 54 | - | |||||||
| 55 | if (!EVP_DigestInit(&ctx->md,md_type)
| 0 | ||||||
| 56 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||
| 57 | - | |||||||
| 58 | ret = EVP_SealInit(&ctx->cipher, type, ek, ekl, iv, pubk, npubk); | - | ||||||
| 59 | if (ret <= 0
| 0 | ||||||
| 60 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||
| 61 | - | |||||||
| 62 | - | |||||||
| 63 | for (i = 0; i < npubk
| 0 | ||||||
| 64 | j = EVP_EncodeBlock((unsigned char *)s, ek[i], | - | ||||||
| 65 | RSA_size(pubk[i]->pkey.rsa)); | - | ||||||
| 66 | ekl[i] = j; | - | ||||||
| 67 | memcpy(ek[i], s, j + 1); | - | ||||||
| 68 | } never executed: end of block | 0 | ||||||
| 69 | - | |||||||
| 70 | ret = npubk; | - | ||||||
| 71 | - | |||||||
| 72 | if (0) { | - | ||||||
| 73 | err: | - | ||||||
| 74 | PEM_ENCODE_SEAL_CTX_cleanup(ctx); | - | ||||||
| 75 | } never executed: end of block | 0 | ||||||
| 76 | free(s); | - | ||||||
| 77 | explicit_bzero(key, sizeof(key)); | - | ||||||
| 78 | return never executed: (ret);return (ret);never executed: return (ret); | 0 | ||||||
| 79 | } | - | ||||||
| 80 | - | |||||||
| 81 | void | - | ||||||
| 82 | PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, | - | ||||||
| 83 | unsigned char *in, int inl) | - | ||||||
| 84 | { | - | ||||||
| 85 | unsigned char buffer[1600]; | - | ||||||
| 86 | int i, j; | - | ||||||
| 87 | - | |||||||
| 88 | *outl = 0; | - | ||||||
| 89 | EVP_DigestUpdate(&ctx->md,in,inl); | - | ||||||
| 90 | for (;;) { | - | ||||||
| 91 | if (inl <= 0
| 0 | ||||||
| 92 | break; never executed: break; | 0 | ||||||
| 93 | if (inl > 1200
| 0 | ||||||
| 94 | i = 1200; never executed: i = 1200; | 0 | ||||||
| 95 | else | - | ||||||
| 96 | i = inl; never executed: i = inl; | 0 | ||||||
| 97 | EVP_EncryptUpdate(&ctx->cipher, buffer, &j, in, i); | - | ||||||
| 98 | EVP_EncodeUpdate(&ctx->encode, out, &j, buffer, j); | - | ||||||
| 99 | *outl += j; | - | ||||||
| 100 | out += j; | - | ||||||
| 101 | in += i; | - | ||||||
| 102 | inl -= i; | - | ||||||
| 103 | } never executed: end of block | 0 | ||||||
| 104 | } never executed: end of block | 0 | ||||||
| 105 | - | |||||||
| 106 | int | - | ||||||
| 107 | PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl, | - | ||||||
| 108 | unsigned char *out, int *outl, EVP_PKEY *priv) | - | ||||||
| 109 | { | - | ||||||
| 110 | unsigned char *s = | - | ||||||
| 111 | ((void *)0) | - | ||||||
| 112 | ; | - | ||||||
| 113 | int ret = 0, j; | - | ||||||
| 114 | unsigned int i; | - | ||||||
| 115 | - | |||||||
| 116 | if (priv->type != 6
| 0 | ||||||
| 117 | ERR_put_error(9,(0xfff),(110),__FILE__,173); | - | ||||||
| 118 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||
| 119 | } | - | ||||||
| 120 | i = RSA_size(priv->pkey.rsa); | - | ||||||
| 121 | if (i < 100
| 0 | ||||||
| 122 | i = 100; never executed: i = 100; | 0 | ||||||
| 123 | s = reallocarray( | - | ||||||
| 124 | ((void *)0) | - | ||||||
| 125 | , i, 2); | - | ||||||
| 126 | if (s ==
| 0 | ||||||
| 127 | ((void *)0)
| 0 | ||||||
| 128 | ) { | - | ||||||
| 129 | ERR_put_error(9,(0xfff),((1|64)),__FILE__,181); | - | ||||||
| 130 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||
| 131 | } | - | ||||||
| 132 | - | |||||||
| 133 | if (!EVP_EncryptFinal_ex(&ctx->cipher, s, (int *)&i)
| 0 | ||||||
| 134 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||
| 135 | EVP_EncodeUpdate(&ctx->encode, out, &j, s, i); | - | ||||||
| 136 | *outl = j; | - | ||||||
| 137 | out += j; | - | ||||||
| 138 | EVP_EncodeFinal(&ctx->encode, out, &j); | - | ||||||
| 139 | *outl += j; | - | ||||||
| 140 | - | |||||||
| 141 | if (!EVP_SignFinal(&ctx->md, s, &i, priv)
| 0 | ||||||
| 142 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||
| 143 | *sigl = EVP_EncodeBlock(sig, s, i); | - | ||||||
| 144 | - | |||||||
| 145 | ret = 1; | - | ||||||
| 146 | - | |||||||
| 147 | err: code before this statement never executed: err: | 0 | ||||||
| 148 | PEM_ENCODE_SEAL_CTX_cleanup(ctx); | - | ||||||
| 149 | free(s); | - | ||||||
| 150 | return never executed: (ret);return (ret);never executed: return (ret); | 0 | ||||||
| 151 | } | - | ||||||
| Switch to Source code | Preprocessed file |