| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/a_sign.c | 
| Switch to Source code | Preprocessed file | 
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | - | |||||||||||||||||||
| 8 | int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2, | - | ||||||||||||||||||
| 9 | ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey, | - | ||||||||||||||||||
| 10 | const EVP_MD *type) | - | ||||||||||||||||||
| 11 | { | - | ||||||||||||||||||
| 12 | EVP_MD_CTX *ctx = EVP_MD_CTX_new(); | - | ||||||||||||||||||
| 13 | unsigned char *p, *buf_in = | - | ||||||||||||||||||
| 14 | ((void *)0) | - | ||||||||||||||||||
| 15 | , *buf_out = | - | ||||||||||||||||||
| 16 | ((void *)0) | - | ||||||||||||||||||
| 17 | ; | - | ||||||||||||||||||
| 18 | int i, inl = 0, outl = 0, outll = 0; | - | ||||||||||||||||||
| 19 | X509_ALGOR *a; | - | ||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 |     if (ctx == 
  | 0 | ||||||||||||||||||
| 22 |               ((void *)0)
  | 0 | ||||||||||||||||||
| 23 | ) { | - | ||||||||||||||||||
| 24 | ERR_put_error(13,(128),((1|64)),__FILE__,36); | - | ||||||||||||||||||
| 25 |         goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 26 | } | - | ||||||||||||||||||
| 27 |     for (i = 0; i < 2
  | 0 | ||||||||||||||||||
| 28 |         if (i == 0
  | 0 | ||||||||||||||||||
| 29 |             a = algor1; never executed:  a = algor1; | 0 | ||||||||||||||||||
| 30 | else | - | ||||||||||||||||||
| 31 |             a = algor2; never executed:  a = algor2; | 0 | ||||||||||||||||||
| 32 |         if (a == 
  | 0 | ||||||||||||||||||
| 33 |                 ((void *)0)
  | 0 | ||||||||||||||||||
| 34 | ) | - | ||||||||||||||||||
| 35 |             continue; never executed:  continue; | 0 | ||||||||||||||||||
| 36 |         if (type->pkey_type == 113
  | 0 | ||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | - | |||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | ASN1_TYPE_free(a->parameter); | - | ||||||||||||||||||
| 42 | a->parameter = | - | ||||||||||||||||||
| 43 | ((void *)0) | - | ||||||||||||||||||
| 44 | ; | - | ||||||||||||||||||
| 45 |         } never executed:   else if ((end of block
 
  | 0 | ||||||||||||||||||
| 46 |                                    ((void *)0)
  | 0 | ||||||||||||||||||
| 47 |                                        )
  | 0 | ||||||||||||||||||
| 48 |                    (
 
  | 0 | ||||||||||||||||||
| 49 | ASN1_TYPE_free(a->parameter); | - | ||||||||||||||||||
| 50 |             if ((
 
  | 0 | ||||||||||||||||||
| 51 |                                                    ((void *)0)
  | 0 | ||||||||||||||||||
| 52 | ) | - | ||||||||||||||||||
| 53 |                 goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 54 | a->parameter->type = 5; | - | ||||||||||||||||||
| 55 |         } never executed:  end of block | 0 | ||||||||||||||||||
| 56 | ASN1_OBJECT_free(a->algorithm); | - | ||||||||||||||||||
| 57 | a->algorithm = OBJ_nid2obj(type->pkey_type); | - | ||||||||||||||||||
| 58 |         if (a->algorithm == 
  | 0 | ||||||||||||||||||
| 59 |                            ((void *)0)
  | 0 | ||||||||||||||||||
| 60 | ) { | - | ||||||||||||||||||
| 61 | ERR_put_error(13,(128),(162),__FILE__,63); | - | ||||||||||||||||||
| 62 |             goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 63 | } | - | ||||||||||||||||||
| 64 |         if (a->algorithm->length == 0
  | 0 | ||||||||||||||||||
| 65 | ERR_put_error(13,(128),(154),__FILE__,68) | - | ||||||||||||||||||
| 66 | ; | - | ||||||||||||||||||
| 67 |             goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 68 | } | - | ||||||||||||||||||
| 69 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 70 | inl = i2d(data, | - | ||||||||||||||||||
| 71 | ((void *)0) | - | ||||||||||||||||||
| 72 | ); | - | ||||||||||||||||||
| 73 | buf_in = CRYPTO_malloc((unsigned int)inl, __FILE__, 73); | - | ||||||||||||||||||
| 74 | outll = outl = EVP_PKEY_size(pkey); | - | ||||||||||||||||||
| 75 | buf_out = CRYPTO_malloc((unsigned int)outl, __FILE__, 75); | - | ||||||||||||||||||
| 76 |     if ((
 
  | 0 | ||||||||||||||||||
| 77 |                   ((void *)0)
  | 0 | ||||||||||||||||||
| 78 |                       )
 
 
  | 0 | ||||||||||||||||||
| 79 |                                        ((void *)0)
  | 0 | ||||||||||||||||||
| 80 |                                            )
  | 0 | ||||||||||||||||||
| 81 | outl = 0; | - | ||||||||||||||||||
| 82 | ERR_put_error(13,(128),((1|64)),__FILE__,78); | - | ||||||||||||||||||
| 83 |         goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 84 | } | - | ||||||||||||||||||
| 85 | p = buf_in; | - | ||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | i2d(data, &p); | - | ||||||||||||||||||
| 88 |     if (!EVP_DigestInit_ex(ctx,type,
  | 0 | ||||||||||||||||||
| 89 |         ((void *)0)
  | 0 | ||||||||||||||||||
| 90 |         )
  | 0 | ||||||||||||||||||
| 91 |         || !EVP_DigestUpdate(ctx,(unsigned char *)buf_in,inl)
  | 0 | ||||||||||||||||||
| 92 |         || !EVP_SignFinal(ctx, (unsigned char *)buf_out,
  | 0 | ||||||||||||||||||
| 93 |                           (unsigned int *)&outl, pkey)
  | 0 | ||||||||||||||||||
| 94 | outl = 0; | - | ||||||||||||||||||
| 95 | ERR_put_error(13,(128),(6),__FILE__,89); | - | ||||||||||||||||||
| 96 |         goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 97 | } | - | ||||||||||||||||||
| 98 | CRYPTO_free(signature->data, __FILE__, 92); | - | ||||||||||||||||||
| 99 | signature->data = buf_out; | - | ||||||||||||||||||
| 100 | buf_out = | - | ||||||||||||||||||
| 101 | ((void *)0) | - | ||||||||||||||||||
| 102 | ; | - | ||||||||||||||||||
| 103 | signature->length = outl; | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | - | |||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | signature->flags &= ~(0x08 | 0x07); | - | ||||||||||||||||||
| 109 | signature->flags |= 0x08; | - | ||||||||||||||||||
| 110 |  err: code before this statement never executed:  err: | 0 | ||||||||||||||||||
| 111 | EVP_MD_CTX_free(ctx); | - | ||||||||||||||||||
| 112 | CRYPTO_clear_free((char *)buf_in, (unsigned int)inl, __FILE__, 104); | - | ||||||||||||||||||
| 113 | CRYPTO_clear_free((char *)buf_out, outll, __FILE__, 105); | - | ||||||||||||||||||
| 114 |     return never executed:   outl;return outl;never executed:  return outl; | 0 | ||||||||||||||||||
| 115 | } | - | ||||||||||||||||||
| 116 | - | |||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, | - | ||||||||||||||||||
| 120 | X509_ALGOR *algor2, ASN1_BIT_STRING *signature, void *asn, | - | ||||||||||||||||||
| 121 | EVP_PKEY *pkey, const EVP_MD *type) | - | ||||||||||||||||||
| 122 | { | - | ||||||||||||||||||
| 123 | int rv; | - | ||||||||||||||||||
| 124 | EVP_MD_CTX *ctx = EVP_MD_CTX_new(); | - | ||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 |     if (ctx == 
  | 0-2 | ||||||||||||||||||
| 127 |               ((void *)0)
  | 0-2 | ||||||||||||||||||
| 128 | ) { | - | ||||||||||||||||||
| 129 | ERR_put_error(13,(195),((1|64)),__FILE__,119); | - | ||||||||||||||||||
| 130 |         return never executed:   0;return 0;never executed:  return 0; | 0 | ||||||||||||||||||
| 131 | } | - | ||||||||||||||||||
| 132 |     if (!EVP_DigestSignInit(ctx, 
  | 0-2 | ||||||||||||||||||
| 133 |                                 ((void *)0)
  | 0-2 | ||||||||||||||||||
| 134 |                                     , type, 
  | 0-2 | ||||||||||||||||||
| 135 |                                             ((void *)0)
  | 0-2 | ||||||||||||||||||
| 136 |                                                 , pkey)
  | 0-2 | ||||||||||||||||||
| 137 | EVP_MD_CTX_free(ctx); | - | ||||||||||||||||||
| 138 |         return never executed:   0;return 0;never executed:  return 0; | 0 | ||||||||||||||||||
| 139 | } | - | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | rv = ASN1_item_sign_ctx(it, algor1, algor2, signature, asn, ctx); | - | ||||||||||||||||||
| 142 | - | |||||||||||||||||||
| 143 | EVP_MD_CTX_free(ctx); | - | ||||||||||||||||||
| 144 |     return executed 2 times by 1 test:   rv;return rv;Executed by: 
 executed 2 times by 1 test:  return rv;Executed by: 
  | 2 | ||||||||||||||||||
| 145 | } | - | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | int ASN1_item_sign_ctx(const ASN1_ITEM *it, | - | ||||||||||||||||||
| 148 | X509_ALGOR *algor1, X509_ALGOR *algor2, | - | ||||||||||||||||||
| 149 | ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx) | - | ||||||||||||||||||
| 150 | { | - | ||||||||||||||||||
| 151 | const EVP_MD *type; | - | ||||||||||||||||||
| 152 | EVP_PKEY *pkey; | - | ||||||||||||||||||
| 153 | unsigned char *buf_in = | - | ||||||||||||||||||
| 154 | ((void *)0) | - | ||||||||||||||||||
| 155 | , *buf_out = | - | ||||||||||||||||||
| 156 | ((void *)0) | - | ||||||||||||||||||
| 157 | ; | - | ||||||||||||||||||
| 158 | size_t inl = 0, outl = 0, outll = 0; | - | ||||||||||||||||||
| 159 | int signid, paramtype; | - | ||||||||||||||||||
| 160 | int rv; | - | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | type = EVP_MD_CTX_md(ctx); | - | ||||||||||||||||||
| 163 | pkey = EVP_PKEY_CTX_get0_pkey(EVP_MD_CTX_pkey_ctx(ctx)); | - | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 |     if (pkey == 
  | 0-22 | ||||||||||||||||||
| 166 |                ((void *)0)
  | 0-22 | ||||||||||||||||||
| 167 | ) { | - | ||||||||||||||||||
| 168 | ERR_put_error(13,(220),(217),__FILE__,148); | - | ||||||||||||||||||
| 169 |         goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 170 | } | - | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 |     if (pkey->ameth == 
  | 0-22 | ||||||||||||||||||
| 173 |                       ((void *)0)
  | 0-22 | ||||||||||||||||||
| 174 | ) { | - | ||||||||||||||||||
| 175 | ERR_put_error(13,(220),(198),__FILE__,153); | - | ||||||||||||||||||
| 176 |         goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 177 | } | - | ||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 |     if (pkey->ameth->item_sign
  | 2-20 | ||||||||||||||||||
| 180 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, signature); | - | ||||||||||||||||||
| 181 |         if (rv == 1
  | 0-20 | ||||||||||||||||||
| 182 |             outl = signature->length; never executed:  outl = signature->length; | 0 | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | - | |||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 |         if (rv <= 0
  | 0-20 | ||||||||||||||||||
| 191 |             ERR_put_error(13,(220),(6),__FILE__,169); never executed:  ERR_put_error(13,(220),(6),__FILE__,169); | 0 | ||||||||||||||||||
| 192 |         if (rv <= 1
  | 0-20 | ||||||||||||||||||
| 193 |             goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 194 |     } executed 20 times by 1 test:   else {end of blockExecuted by: 
  | 20 | ||||||||||||||||||
| 195 | rv = 2; | - | ||||||||||||||||||
| 196 |     } executed 2 times by 1 test:  end of blockExecuted by: 
  | 2 | ||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 |     if (rv == 2
  | 0-22 | ||||||||||||||||||
| 199 |         if (type == 
  | 0-22 | ||||||||||||||||||
| 200 |                    ((void *)0)
  | 0-22 | ||||||||||||||||||
| 201 | ) { | - | ||||||||||||||||||
| 202 | ERR_put_error(13,(220),(217),__FILE__,178); | - | ||||||||||||||||||
| 203 |             goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 204 | } | - | ||||||||||||||||||
| 205 |         if (!OBJ_find_sigid_by_algs(&signid,
  | 0-22 | ||||||||||||||||||
| 206 |                                     EVP_MD_type(type),
  | 0-22 | ||||||||||||||||||
| 207 |                                     pkey->ameth->pkey_id)
  | 0-22 | ||||||||||||||||||
| 208 | ERR_put_error(13,(220),(198),__FILE__,185) | - | ||||||||||||||||||
| 209 | ; | - | ||||||||||||||||||
| 210 |             goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 211 | } | - | ||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 |         if (pkey->ameth->pkey_flags & 0x4
  | 2-20 | ||||||||||||||||||
| 214 |             paramtype = 5; executed 20 times by 1 test:  paramtype = 5;Executed by: 
  | 20 | ||||||||||||||||||
| 215 | else | - | ||||||||||||||||||
| 216 |             paramtype = -1; executed 2 times by 1 test:  paramtype = -1;Executed by: 
  | 2 | ||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 |         if (algor1
  | 0-22 | ||||||||||||||||||
| 219 |             X509_ALGOR_set0(algor1, OBJ_nid2obj(signid), paramtype,  executed 22 times by 1 test:  X509_ALGOR_set0(algor1, OBJ_nid2obj(signid), paramtype, ((void *)0) );Executed by: 
  | 22 | ||||||||||||||||||
| 220 |                                                                    ((void *)0) executed 22 times by 1 test:  X509_ALGOR_set0(algor1, OBJ_nid2obj(signid), paramtype, ((void *)0) );Executed by: 
  | 22 | ||||||||||||||||||
| 221 |                                                                        ); executed 22 times by 1 test:  X509_ALGOR_set0(algor1, OBJ_nid2obj(signid), paramtype, ((void *)0) );Executed by: 
  | 22 | ||||||||||||||||||
| 222 |         if (algor2
  | 9-13 | ||||||||||||||||||
| 223 |             X509_ALGOR_set0(algor2, OBJ_nid2obj(signid), paramtype,  executed 9 times by 1 test:  X509_ALGOR_set0(algor2, OBJ_nid2obj(signid), paramtype, ((void *)0) );Executed by: 
  | 9 | ||||||||||||||||||
| 224 |                                                                    ((void *)0) executed 9 times by 1 test:  X509_ALGOR_set0(algor2, OBJ_nid2obj(signid), paramtype, ((void *)0) );Executed by: 
  | 9 | ||||||||||||||||||
| 225 |                                                                        ); executed 9 times by 1 test:  X509_ALGOR_set0(algor2, OBJ_nid2obj(signid), paramtype, ((void *)0) );Executed by: 
  | 9 | ||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 |     } executed 22 times by 1 test:  end of blockExecuted by: 
  | 22 | ||||||||||||||||||
| 228 | - | |||||||||||||||||||
| 229 | inl = ASN1_item_i2d(asn, &buf_in, it); | - | ||||||||||||||||||
| 230 | outll = outl = EVP_PKEY_size(pkey); | - | ||||||||||||||||||
| 231 | buf_out = CRYPTO_malloc((unsigned int)outl, __FILE__, 203); | - | ||||||||||||||||||
| 232 |     if ((
 
  | 0-22 | ||||||||||||||||||
| 233 |                   ((void *)0)
  | 0-22 | ||||||||||||||||||
| 234 |                       )
 
 
  | 0-22 | ||||||||||||||||||
| 235 |                                        ((void *)0)
  | 0-22 | ||||||||||||||||||
| 236 |                                            )
  | 0-22 | ||||||||||||||||||
| 237 | outl = 0; | - | ||||||||||||||||||
| 238 | ERR_put_error(13,(220),((1|64)),__FILE__,206); | - | ||||||||||||||||||
| 239 |         goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 240 | } | - | ||||||||||||||||||
| 241 | - | |||||||||||||||||||
| 242 |     if (!EVP_DigestSign(ctx, buf_out, &outl, buf_in, inl)
  | 0-22 | ||||||||||||||||||
| 243 | outl = 0; | - | ||||||||||||||||||
| 244 | ERR_put_error(13,(220),(6),__FILE__,212); | - | ||||||||||||||||||
| 245 |         goto never executed:   err;goto err;never executed:  goto err; | 0 | ||||||||||||||||||
| 246 | } | - | ||||||||||||||||||
| 247 | CRYPTO_free(signature->data, __FILE__, 215); | - | ||||||||||||||||||
| 248 | signature->data = buf_out; | - | ||||||||||||||||||
| 249 | buf_out = | - | ||||||||||||||||||
| 250 | ((void *)0) | - | ||||||||||||||||||
| 251 | ; | - | ||||||||||||||||||
| 252 | signature->length = outl; | - | ||||||||||||||||||
| 253 | - | |||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | - | |||||||||||||||||||
| 256 | - | |||||||||||||||||||
| 257 | signature->flags &= ~(0x08 | 0x07); | - | ||||||||||||||||||
| 258 | signature->flags |= 0x08; | - | ||||||||||||||||||
| 259 |  err: code before this statement executed 22 times by 1 test:  err:Executed by: 
  | 22 | ||||||||||||||||||
| 260 | CRYPTO_clear_free((char *)buf_in, (unsigned int)inl, __FILE__, 226); | - | ||||||||||||||||||
| 261 | CRYPTO_clear_free((char *)buf_out, outll, __FILE__, 227); | - | ||||||||||||||||||
| 262 |     return executed 22 times by 1 test:   outl;return outl;Executed by: 
 executed 22 times by 1 test:  return outl;Executed by: 
  | 22 | ||||||||||||||||||
| 263 | } | - | ||||||||||||||||||
| Switch to Source code | Preprocessed file |