| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/cms/cms_kari.c | 
| Switch to Source code | Preprocessed file | 
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | int CMS_RecipientInfo_kari_get0_alg(CMS_RecipientInfo *ri, | - | ||||||||||||
| 6 | X509_ALGOR **palg, | - | ||||||||||||
| 7 | ASN1_OCTET_STRING **pukm) | - | ||||||||||||
| 8 | { | - | ||||||||||||
| 9 | if (ri->type != 1 
 | 0-13 | ||||||||||||
| 10 | ERR_put_error(46,(175),(181),__FILE__,28) | - | ||||||||||||
| 11 | ; | - | ||||||||||||
| 12 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 13 | } | - | ||||||||||||
| 14 | if (palg 
 | 0-13 | ||||||||||||
| 15 | * executed 13 times by 1 test: palg = ri->d.kari->keyEncryptionAlgorithm; *palg = ri->d.kari->keyEncryptionAlgorithm;Executed by: 
 executed 13 times by 1 test:  *palg = ri->d.kari->keyEncryptionAlgorithm;Executed by: 
 | 13 | ||||||||||||
| 16 | if (pukm 
 | 0-13 | ||||||||||||
| 17 | * executed 13 times by 1 test: pukm = ri->d.kari->ukm; *pukm = ri->d.kari->ukm;Executed by: 
 executed 13 times by 1 test:  *pukm = ri->d.kari->ukm;Executed by: 
 | 13 | ||||||||||||
| 18 | return executed 13 times by 1 test: 1; return 1;Executed by: 
 executed 13 times by 1 test:  return 1;Executed by: 
 | 13 | ||||||||||||
| 19 | } | - | ||||||||||||
| 20 | - | |||||||||||||
| 21 | - | |||||||||||||
| 22 | - | |||||||||||||
| 23 | struct stack_st_CMS_RecipientEncryptedKey | - | ||||||||||||
| 24 | *CMS_RecipientInfo_kari_get0_reks(CMS_RecipientInfo *ri) | - | ||||||||||||
| 25 | { | - | ||||||||||||
| 26 | if (ri->type != 1 
 | 0-6 | ||||||||||||
| 27 | ERR_put_error(46,(172),(181),__FILE__,45) | - | ||||||||||||
| 28 | ; | - | ||||||||||||
| 29 | return never executed:  return ((void *)0) ;never executed:  return ((void *)0) ; | 0 | ||||||||||||
| 30 | ((void *)0) never executed:  return ((void *)0) ; | 0 | ||||||||||||
| 31 | ; never executed:  return ((void *)0) ; | 0 | ||||||||||||
| 32 | } | - | ||||||||||||
| 33 | return executed 6 times by 1 test: ri->d.kari->recipientEncryptedKeys; return ri->d.kari->recipientEncryptedKeys;Executed by: 
 executed 6 times by 1 test:  return ri->d.kari->recipientEncryptedKeys;Executed by: 
 | 6 | ||||||||||||
| 34 | } | - | ||||||||||||
| 35 | - | |||||||||||||
| 36 | int CMS_RecipientInfo_kari_get0_orig_id(CMS_RecipientInfo *ri, | - | ||||||||||||
| 37 | X509_ALGOR **pubalg, | - | ||||||||||||
| 38 | ASN1_BIT_STRING **pubkey, | - | ||||||||||||
| 39 | ASN1_OCTET_STRING **keyid, | - | ||||||||||||
| 40 | X509_NAME **issuer, | - | ||||||||||||
| 41 | ASN1_INTEGER **sno) | - | ||||||||||||
| 42 | { | - | ||||||||||||
| 43 | CMS_OriginatorIdentifierOrKey *oik; | - | ||||||||||||
| 44 | if (ri->type != 1 
 | 0-13 | ||||||||||||
| 45 | ERR_put_error(46,(173),(181),__FILE__,61) | - | ||||||||||||
| 46 | ; | - | ||||||||||||
| 47 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 48 | } | - | ||||||||||||
| 49 | oik = ri->d.kari->originator; | - | ||||||||||||
| 50 | if (issuer 
 | 0-13 | ||||||||||||
| 51 | * never executed: issuer = *issuer = ((void *)0) ;never executed:  *issuer = ((void *)0) ; | 0 | ||||||||||||
| 52 | ((void *)0) never executed:  *issuer = ((void *)0) ; | 0 | ||||||||||||
| 53 | ; never executed:  *issuer = ((void *)0) ; | 0 | ||||||||||||
| 54 | if (sno 
 | 0-13 | ||||||||||||
| 55 | * never executed: sno = *sno = ((void *)0) ;never executed:  *sno = ((void *)0) ; | 0 | ||||||||||||
| 56 | ((void *)0) never executed:  *sno = ((void *)0) ; | 0 | ||||||||||||
| 57 | ; never executed:  *sno = ((void *)0) ; | 0 | ||||||||||||
| 58 | if (keyid 
 | 0-13 | ||||||||||||
| 59 | * never executed: keyid = *keyid = ((void *)0) ;never executed:  *keyid = ((void *)0) ; | 0 | ||||||||||||
| 60 | ((void *)0) never executed:  *keyid = ((void *)0) ; | 0 | ||||||||||||
| 61 | ; never executed:  *keyid = ((void *)0) ; | 0 | ||||||||||||
| 62 | if (pubalg 
 | 0-13 | ||||||||||||
| 63 | * executed 13 times by 1 test: pubalg = *pubalg = ((void *)0) ;Executed by: 
 executed 13 times by 1 test:  *pubalg = ((void *)0) ;Executed by: 
 | 13 | ||||||||||||
| 64 | ((void *)0) executed 13 times by 1 test:  *pubalg = ((void *)0) ;Executed by: 
 | 13 | ||||||||||||
| 65 | ; executed 13 times by 1 test:  *pubalg = ((void *)0) ;Executed by: 
 | 13 | ||||||||||||
| 66 | if (pubkey 
 | 0-13 | ||||||||||||
| 67 | * executed 13 times by 1 test: pubkey = *pubkey = ((void *)0) ;Executed by: 
 executed 13 times by 1 test:  *pubkey = ((void *)0) ;Executed by: 
 | 13 | ||||||||||||
| 68 | ((void *)0) executed 13 times by 1 test:  *pubkey = ((void *)0) ;Executed by: 
 | 13 | ||||||||||||
| 69 | ; executed 13 times by 1 test:  *pubkey = ((void *)0) ;Executed by: 
 | 13 | ||||||||||||
| 70 | if (oik->type == 0 
 | 0-13 | ||||||||||||
| 71 | if (issuer 
 | 0 | ||||||||||||
| 72 | * never executed: issuer = oik->d.issuerAndSerialNumber->issuer; *issuer = oik->d.issuerAndSerialNumber->issuer;never executed:  *issuer = oik->d.issuerAndSerialNumber->issuer; | 0 | ||||||||||||
| 73 | if (sno 
 | 0 | ||||||||||||
| 74 | * never executed: sno = oik->d.issuerAndSerialNumber->serialNumber; *sno = oik->d.issuerAndSerialNumber->serialNumber;never executed:  *sno = oik->d.issuerAndSerialNumber->serialNumber; | 0 | ||||||||||||
| 75 | } never executed: else if (oik->type == 1 end of block
 | 0-13 | ||||||||||||
| 76 | if (keyid 
 | 0 | ||||||||||||
| 77 | * never executed: keyid = oik->d.subjectKeyIdentifier; *keyid = oik->d.subjectKeyIdentifier;never executed:  *keyid = oik->d.subjectKeyIdentifier; | 0 | ||||||||||||
| 78 | } never executed: else if (oik->type == 2 end of block
 | 0-13 | ||||||||||||
| 79 | if (pubalg 
 | 0-13 | ||||||||||||
| 80 | * executed 13 times by 1 test: pubalg = oik->d.originatorKey->algorithm; *pubalg = oik->d.originatorKey->algorithm;Executed by: 
 executed 13 times by 1 test:  *pubalg = oik->d.originatorKey->algorithm;Executed by: 
 | 13 | ||||||||||||
| 81 | if (pubkey 
 | 0-13 | ||||||||||||
| 82 | * executed 13 times by 1 test: pubkey = oik->d.originatorKey->publicKey; *pubkey = oik->d.originatorKey->publicKey;Executed by: 
 executed 13 times by 1 test:  *pubkey = oik->d.originatorKey->publicKey;Executed by: 
 | 13 | ||||||||||||
| 83 | } executed 13 times by 1 test: else end of blockExecuted by: 
 | 13 | ||||||||||||
| 84 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 85 | return executed 13 times by 1 test: 1; return 1;Executed by: 
 executed 13 times by 1 test:  return 1;Executed by: 
 | 13 | ||||||||||||
| 86 | } | - | ||||||||||||
| 87 | - | |||||||||||||
| 88 | int CMS_RecipientInfo_kari_orig_id_cmp(CMS_RecipientInfo *ri, X509 *cert) | - | ||||||||||||
| 89 | { | - | ||||||||||||
| 90 | CMS_OriginatorIdentifierOrKey *oik; | - | ||||||||||||
| 91 | if (ri->type != 1 
 | 0 | ||||||||||||
| 92 | ERR_put_error(46,(174),(181),__FILE__,98) | - | ||||||||||||
| 93 | ; | - | ||||||||||||
| 94 | return never executed: -2; return -2;never executed:  return -2; | 0 | ||||||||||||
| 95 | } | - | ||||||||||||
| 96 | oik = ri->d.kari->originator; | - | ||||||||||||
| 97 | if (oik->type == 0 
 | 0 | ||||||||||||
| 98 | return never executed: cms_ias_cert_cmp(oik->d.issuerAndSerialNumber, cert); return cms_ias_cert_cmp(oik->d.issuerAndSerialNumber, cert);never executed:  return cms_ias_cert_cmp(oik->d.issuerAndSerialNumber, cert); | 0 | ||||||||||||
| 99 | else if (oik->type == 1 
 | 0 | ||||||||||||
| 100 | return never executed: cms_keyid_cert_cmp(oik->d.subjectKeyIdentifier, cert); return cms_keyid_cert_cmp(oik->d.subjectKeyIdentifier, cert);never executed:  return cms_keyid_cert_cmp(oik->d.subjectKeyIdentifier, cert); | 0 | ||||||||||||
| 101 | return never executed: -1; return -1;never executed:  return -1; | 0 | ||||||||||||
| 102 | } | - | ||||||||||||
| 103 | - | |||||||||||||
| 104 | int CMS_RecipientEncryptedKey_get0_id(CMS_RecipientEncryptedKey *rek, | - | ||||||||||||
| 105 | ASN1_OCTET_STRING **keyid, | - | ||||||||||||
| 106 | ASN1_GENERALIZEDTIME **tm, | - | ||||||||||||
| 107 | CMS_OtherKeyAttribute **other, | - | ||||||||||||
| 108 | X509_NAME **issuer, ASN1_INTEGER **sno) | - | ||||||||||||
| 109 | { | - | ||||||||||||
| 110 | CMS_KeyAgreeRecipientIdentifier *rid = rek->rid; | - | ||||||||||||
| 111 | if (rid->type == 0 
 | 0 | ||||||||||||
| 112 | if (issuer 
 | 0 | ||||||||||||
| 113 | * never executed: issuer = rid->d.issuerAndSerialNumber->issuer; *issuer = rid->d.issuerAndSerialNumber->issuer;never executed:  *issuer = rid->d.issuerAndSerialNumber->issuer; | 0 | ||||||||||||
| 114 | if (sno 
 | 0 | ||||||||||||
| 115 | * never executed: sno = rid->d.issuerAndSerialNumber->serialNumber; *sno = rid->d.issuerAndSerialNumber->serialNumber;never executed:  *sno = rid->d.issuerAndSerialNumber->serialNumber; | 0 | ||||||||||||
| 116 | if (keyid 
 | 0 | ||||||||||||
| 117 | * never executed: keyid = *keyid = ((void *)0) ;never executed:  *keyid = ((void *)0) ; | 0 | ||||||||||||
| 118 | ((void *)0) never executed:  *keyid = ((void *)0) ; | 0 | ||||||||||||
| 119 | ; never executed:  *keyid = ((void *)0) ; | 0 | ||||||||||||
| 120 | if (tm 
 | 0 | ||||||||||||
| 121 | * never executed: tm = *tm = ((void *)0) ;never executed:  *tm = ((void *)0) ; | 0 | ||||||||||||
| 122 | ((void *)0) never executed:  *tm = ((void *)0) ; | 0 | ||||||||||||
| 123 | ; never executed:  *tm = ((void *)0) ; | 0 | ||||||||||||
| 124 | if (other 
 | 0 | ||||||||||||
| 125 | * never executed: other = *other = ((void *)0) ;never executed:  *other = ((void *)0) ; | 0 | ||||||||||||
| 126 | ((void *)0) never executed:  *other = ((void *)0) ; | 0 | ||||||||||||
| 127 | ; never executed:  *other = ((void *)0) ; | 0 | ||||||||||||
| 128 | } never executed: else if (rid->type == 1 end of block
 | 0 | ||||||||||||
| 129 | if (keyid 
 | 0 | ||||||||||||
| 130 | * never executed: keyid = rid->d.rKeyId->subjectKeyIdentifier; *keyid = rid->d.rKeyId->subjectKeyIdentifier;never executed:  *keyid = rid->d.rKeyId->subjectKeyIdentifier; | 0 | ||||||||||||
| 131 | if (tm 
 | 0 | ||||||||||||
| 132 | * never executed: tm = rid->d.rKeyId->date; *tm = rid->d.rKeyId->date;never executed:  *tm = rid->d.rKeyId->date; | 0 | ||||||||||||
| 133 | if (other 
 | 0 | ||||||||||||
| 134 | * never executed: other = rid->d.rKeyId->other; *other = rid->d.rKeyId->other;never executed:  *other = rid->d.rKeyId->other; | 0 | ||||||||||||
| 135 | if (issuer 
 | 0 | ||||||||||||
| 136 | * never executed: issuer = *issuer = ((void *)0) ;never executed:  *issuer = ((void *)0) ; | 0 | ||||||||||||
| 137 | ((void *)0) never executed:  *issuer = ((void *)0) ; | 0 | ||||||||||||
| 138 | ; never executed:  *issuer = ((void *)0) ; | 0 | ||||||||||||
| 139 | if (sno 
 | 0 | ||||||||||||
| 140 | * never executed: sno = *sno = ((void *)0) ;never executed:  *sno = ((void *)0) ; | 0 | ||||||||||||
| 141 | ((void *)0) never executed:  *sno = ((void *)0) ; | 0 | ||||||||||||
| 142 | ; never executed:  *sno = ((void *)0) ; | 0 | ||||||||||||
| 143 | } never executed: else end of block | 0 | ||||||||||||
| 144 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 145 | return never executed: 1; return 1;never executed:  return 1; | 0 | ||||||||||||
| 146 | } | - | ||||||||||||
| 147 | - | |||||||||||||
| 148 | int CMS_RecipientEncryptedKey_cert_cmp(CMS_RecipientEncryptedKey *rek, | - | ||||||||||||
| 149 | X509 *cert) | - | ||||||||||||
| 150 | { | - | ||||||||||||
| 151 | CMS_KeyAgreeRecipientIdentifier *rid = rek->rid; | - | ||||||||||||
| 152 | if (rid->type == 0 
 | 1-4 | ||||||||||||
| 153 | return executed 4 times by 1 test: cms_ias_cert_cmp(rid->d.issuerAndSerialNumber, cert); return cms_ias_cert_cmp(rid->d.issuerAndSerialNumber, cert);Executed by: 
 executed 4 times by 1 test:  return cms_ias_cert_cmp(rid->d.issuerAndSerialNumber, cert);Executed by: 
 | 4 | ||||||||||||
| 154 | else if (rid->type == 1 
 | 0-1 | ||||||||||||
| 155 | return executed 1 time by 1 test: cms_keyid_cert_cmp(rid->d.rKeyId->subjectKeyIdentifier, cert); return cms_keyid_cert_cmp(rid->d.rKeyId->subjectKeyIdentifier, cert);Executed by: 
 executed 1 time by 1 test:  return cms_keyid_cert_cmp(rid->d.rKeyId->subjectKeyIdentifier, cert);Executed by: 
 | 1 | ||||||||||||
| 156 | else | - | ||||||||||||
| 157 | return never executed: -1; return -1;never executed:  return -1; | 0 | ||||||||||||
| 158 | } | - | ||||||||||||
| 159 | - | |||||||||||||
| 160 | int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk) | - | ||||||||||||
| 161 | { | - | ||||||||||||
| 162 | EVP_PKEY_CTX *pctx; | - | ||||||||||||
| 163 | CMS_KeyAgreeRecipientInfo *kari = ri->d.kari; | - | ||||||||||||
| 164 | - | |||||||||||||
| 165 | EVP_PKEY_CTX_free(kari->pctx); | - | ||||||||||||
| 166 | kari->pctx = | - | ||||||||||||
| 167 | ((void *)0) | - | ||||||||||||
| 168 | ; | - | ||||||||||||
| 169 | if (!pk 
 | 6 | ||||||||||||
| 170 | return executed 6 times by 1 test: 1; return 1;Executed by: 
 executed 6 times by 1 test:  return 1;Executed by: 
 | 6 | ||||||||||||
| 171 | pctx = EVP_PKEY_CTX_new(pk, | - | ||||||||||||
| 172 | ((void *)0) | - | ||||||||||||
| 173 | ); | - | ||||||||||||
| 174 | if (!pctx 
 
 | 0-6 | ||||||||||||
| 175 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 176 | kari->pctx = pctx; | - | ||||||||||||
| 177 | return executed 6 times by 1 test: 1; return 1;Executed by: 
 executed 6 times by 1 test:  return 1;Executed by: 
 | 6 | ||||||||||||
| 178 | err: | - | ||||||||||||
| 179 | EVP_PKEY_CTX_free(pctx); | - | ||||||||||||
| 180 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 181 | } | - | ||||||||||||
| 182 | - | |||||||||||||
| 183 | EVP_CIPHER_CTX *CMS_RecipientInfo_kari_get0_ctx(CMS_RecipientInfo *ri) | - | ||||||||||||
| 184 | { | - | ||||||||||||
| 185 | if (ri->type == 1 
 | 0-13 | ||||||||||||
| 186 | return executed 13 times by 1 test: ri->d.kari->ctx; return ri->d.kari->ctx;Executed by: 
 executed 13 times by 1 test:  return ri->d.kari->ctx;Executed by: 
 | 13 | ||||||||||||
| 187 | return never executed:  return ((void *)0) ;never executed:  return ((void *)0) ; | 0 | ||||||||||||
| 188 | ((void *)0) never executed:  return ((void *)0) ; | 0 | ||||||||||||
| 189 | ; never executed:  return ((void *)0) ; | 0 | ||||||||||||
| 190 | } | - | ||||||||||||
| 191 | - | |||||||||||||
| 192 | - | |||||||||||||
| 193 | - | |||||||||||||
| 194 | - | |||||||||||||
| 195 | - | |||||||||||||
| 196 | - | |||||||||||||
| 197 | static int cms_kek_cipher(unsigned char **pout, size_t *poutlen, | - | ||||||||||||
| 198 | const unsigned char *in, size_t inlen, | - | ||||||||||||
| 199 | CMS_KeyAgreeRecipientInfo *kari, int enc) | - | ||||||||||||
| 200 | { | - | ||||||||||||
| 201 | - | |||||||||||||
| 202 | unsigned char kek[64]; | - | ||||||||||||
| 203 | size_t keklen; | - | ||||||||||||
| 204 | int rv = 0; | - | ||||||||||||
| 205 | unsigned char *out = | - | ||||||||||||
| 206 | ((void *)0) | - | ||||||||||||
| 207 | ; | - | ||||||||||||
| 208 | int outlen; | - | ||||||||||||
| 209 | keklen = EVP_CIPHER_CTX_key_length(kari->ctx); | - | ||||||||||||
| 210 | if (keklen > 64 
 | 0-13 | ||||||||||||
| 211 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 212 | - | |||||||||||||
| 213 | if (EVP_PKEY_derive(kari->pctx, kek, &keklen) <= 0 
 | 0-13 | ||||||||||||
| 214 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 215 | - | |||||||||||||
| 216 | if (!EVP_CipherInit_ex(kari->ctx, 
 | 0-13 | ||||||||||||
| 217 | ((void *)0) 
 | 0-13 | ||||||||||||
| 218 | , 
 | 0-13 | ||||||||||||
| 219 | ((void *)0) 
 | 0-13 | ||||||||||||
| 220 | , kek, 
 | 0-13 | ||||||||||||
| 221 | ((void *)0) 
 | 0-13 | ||||||||||||
| 222 | , enc) 
 | 0-13 | ||||||||||||
| 223 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 224 | - | |||||||||||||
| 225 | if (!EVP_CipherUpdate(kari->ctx, 
 | 0-13 | ||||||||||||
| 226 | ((void *)0) 
 | 0-13 | ||||||||||||
| 227 | , &outlen, in, inlen) 
 | 0-13 | ||||||||||||
| 228 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 229 | out = CRYPTO_malloc(outlen, __FILE__, 208); | - | ||||||||||||
| 230 | if (out == 
 | 0-13 | ||||||||||||
| 231 | ((void *)0) 
 | 0-13 | ||||||||||||
| 232 | ) | - | ||||||||||||
| 233 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 234 | if (!EVP_CipherUpdate(kari->ctx, out, &outlen, in, inlen) 
 | 0-13 | ||||||||||||
| 235 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 236 | *pout = out; | - | ||||||||||||
| 237 | *poutlen = (size_t)outlen; | - | ||||||||||||
| 238 | rv = 1; | - | ||||||||||||
| 239 | - | |||||||||||||
| 240 | err: code before this statement executed 13 times by 1 test:  err:Executed by: 
 | 13 | ||||||||||||
| 241 | OPENSSL_cleanse(kek, keklen); | - | ||||||||||||
| 242 | if (!rv 
 | 0-13 | ||||||||||||
| 243 | CRYPTO_free(out, __FILE__, 220); never executed:  CRYPTO_free(out, __FILE__, 220); | 0 | ||||||||||||
| 244 | EVP_CIPHER_CTX_reset(kari->ctx); | - | ||||||||||||
| 245 | - | |||||||||||||
| 246 | EVP_PKEY_CTX_free(kari->pctx); | - | ||||||||||||
| 247 | kari->pctx = | - | ||||||||||||
| 248 | ((void *)0) | - | ||||||||||||
| 249 | ; | - | ||||||||||||
| 250 | return executed 13 times by 1 test: rv; return rv;Executed by: 
 executed 13 times by 1 test:  return rv;Executed by: 
 | 13 | ||||||||||||
| 251 | } | - | ||||||||||||
| 252 | - | |||||||||||||
| 253 | int CMS_RecipientInfo_kari_decrypt(CMS_ContentInfo *cms, | - | ||||||||||||
| 254 | CMS_RecipientInfo *ri, | - | ||||||||||||
| 255 | CMS_RecipientEncryptedKey *rek) | - | ||||||||||||
| 256 | { | - | ||||||||||||
| 257 | int rv = 0; | - | ||||||||||||
| 258 | unsigned char *enckey = | - | ||||||||||||
| 259 | ((void *)0) | - | ||||||||||||
| 260 | , *cek = | - | ||||||||||||
| 261 | ((void *)0) | - | ||||||||||||
| 262 | ; | - | ||||||||||||
| 263 | size_t enckeylen; | - | ||||||||||||
| 264 | size_t ceklen; | - | ||||||||||||
| 265 | CMS_EncryptedContentInfo *ec; | - | ||||||||||||
| 266 | enckeylen = rek->encryptedKey->length; | - | ||||||||||||
| 267 | enckey = rek->encryptedKey->data; | - | ||||||||||||
| 268 | - | |||||||||||||
| 269 | if (!cms_env_asn1_ctrl(ri, 1) 
 | 0-6 | ||||||||||||
| 270 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 271 | - | |||||||||||||
| 272 | if (!cms_kek_cipher(&cek, &ceklen, enckey, enckeylen, ri->d.kari, 0) 
 | 0-6 | ||||||||||||
| 273 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 274 | ec = cms->d.envelopedData->encryptedContentInfo; | - | ||||||||||||
| 275 | CRYPTO_clear_free(ec->key, ec->keylen, __FILE__, 246); | - | ||||||||||||
| 276 | ec->key = cek; | - | ||||||||||||
| 277 | ec->keylen = ceklen; | - | ||||||||||||
| 278 | cek = | - | ||||||||||||
| 279 | ((void *)0) | - | ||||||||||||
| 280 | ; | - | ||||||||||||
| 281 | rv = 1; | - | ||||||||||||
| 282 | err: code before this statement executed 6 times by 1 test:  err:Executed by: 
 | 6 | ||||||||||||
| 283 | CRYPTO_free(cek, __FILE__, 252); | - | ||||||||||||
| 284 | return executed 6 times by 1 test: rv; return rv;Executed by: 
 executed 6 times by 1 test:  return rv;Executed by: 
 | 6 | ||||||||||||
| 285 | } | - | ||||||||||||
| 286 | - | |||||||||||||
| 287 | - | |||||||||||||
| 288 | static int cms_kari_create_ephemeral_key(CMS_KeyAgreeRecipientInfo *kari, | - | ||||||||||||
| 289 | EVP_PKEY *pk) | - | ||||||||||||
| 290 | { | - | ||||||||||||
| 291 | EVP_PKEY_CTX *pctx = | - | ||||||||||||
| 292 | ((void *)0) | - | ||||||||||||
| 293 | ; | - | ||||||||||||
| 294 | EVP_PKEY *ekey = | - | ||||||||||||
| 295 | ((void *)0) | - | ||||||||||||
| 296 | ; | - | ||||||||||||
| 297 | int rv = 0; | - | ||||||||||||
| 298 | pctx = EVP_PKEY_CTX_new(pk, | - | ||||||||||||
| 299 | ((void *)0) | - | ||||||||||||
| 300 | ); | - | ||||||||||||
| 301 | if (!pctx 
 | 0-7 | ||||||||||||
| 302 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 303 | if (EVP_PKEY_keygen_init(pctx) <= 0 
 | 0-7 | ||||||||||||
| 304 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 305 | if (EVP_PKEY_keygen(pctx, &ekey) <= 0 
 | 0-7 | ||||||||||||
| 306 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 307 | EVP_PKEY_CTX_free(pctx); | - | ||||||||||||
| 308 | pctx = EVP_PKEY_CTX_new(ekey, | - | ||||||||||||
| 309 | ((void *)0) | - | ||||||||||||
| 310 | ); | - | ||||||||||||
| 311 | if (!pctx 
 | 0-7 | ||||||||||||
| 312 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 313 | if (EVP_PKEY_derive_init(pctx) <= 0 
 | 0-7 | ||||||||||||
| 314 | goto never executed: err; goto err;never executed:  goto err; | 0 | ||||||||||||
| 315 | kari->pctx = pctx; | - | ||||||||||||
| 316 | rv = 1; | - | ||||||||||||
| 317 | err: code before this statement executed 7 times by 1 test:  err:Executed by: 
 | 7 | ||||||||||||
| 318 | if (!rv 
 | 0-7 | ||||||||||||
| 319 | EVP_PKEY_CTX_free(pctx); never executed:  EVP_PKEY_CTX_free(pctx); | 0 | ||||||||||||
| 320 | EVP_PKEY_free(ekey); | - | ||||||||||||
| 321 | return executed 7 times by 1 test: rv; return rv;Executed by: 
 executed 7 times by 1 test:  return rv;Executed by: 
 | 7 | ||||||||||||
| 322 | } | - | ||||||||||||
| 323 | - | |||||||||||||
| 324 | - | |||||||||||||
| 325 | - | |||||||||||||
| 326 | int cms_RecipientInfo_kari_init(CMS_RecipientInfo *ri, X509 *recip, | - | ||||||||||||
| 327 | EVP_PKEY *pk, unsigned int flags) | - | ||||||||||||
| 328 | { | - | ||||||||||||
| 329 | CMS_KeyAgreeRecipientInfo *kari; | - | ||||||||||||
| 330 | CMS_RecipientEncryptedKey *rek = | - | ||||||||||||
| 331 | ((void *)0) | - | ||||||||||||
| 332 | ; | - | ||||||||||||
| 333 | - | |||||||||||||
| 334 | ri->d.kari = (CMS_KeyAgreeRecipientInfo *)ASN1_item_new((&(CMS_KeyAgreeRecipientInfo_it))); | - | ||||||||||||
| 335 | if (!ri->d.kari 
 | 0-7 | ||||||||||||
| 336 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 337 | ri->type = 1; | - | ||||||||||||
| 338 | - | |||||||||||||
| 339 | kari = ri->d.kari; | - | ||||||||||||
| 340 | kari->version = 3; | - | ||||||||||||
| 341 | - | |||||||||||||
| 342 | rek = (CMS_RecipientEncryptedKey *)ASN1_item_new((&(CMS_RecipientEncryptedKey_it))); | - | ||||||||||||
| 343 | if (!sk_CMS_RecipientEncryptedKey_push(kari->recipientEncryptedKeys, rek) 
 | 0-7 | ||||||||||||
| 344 | ASN1_item_free(((void*) (1 ? rek : (CMS_RecipientEncryptedKey*)0)), (&(CMS_RecipientEncryptedKey_it))); | - | ||||||||||||
| 345 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 346 | } | - | ||||||||||||
| 347 | - | |||||||||||||
| 348 | if (flags & 0x10000 
 | 1-6 | ||||||||||||
| 349 | rek->rid->type = 1; | - | ||||||||||||
| 350 | rek->rid->d.rKeyId = (CMS_RecipientKeyIdentifier *)ASN1_item_new((&(CMS_RecipientKeyIdentifier_it))); | - | ||||||||||||
| 351 | if (rek->rid->d.rKeyId == 
 | 0-1 | ||||||||||||
| 352 | ((void *)0) 
 | 0-1 | ||||||||||||
| 353 | ) | - | ||||||||||||
| 354 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 355 | if (!cms_set1_keyid(&rek->rid->d.rKeyId->subjectKeyIdentifier, recip) 
 | 0-1 | ||||||||||||
| 356 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 357 | } executed 1 time by 1 test: else { end of blockExecuted by: 
 | 1 | ||||||||||||
| 358 | rek->rid->type = 0; | - | ||||||||||||
| 359 | if (!cms_set1_ias(&rek->rid->d.issuerAndSerialNumber, recip) 
 | 0-6 | ||||||||||||
| 360 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 361 | } executed 6 times by 1 test:  end of blockExecuted by: 
 | 6 | ||||||||||||
| 362 | - | |||||||||||||
| 363 | - | |||||||||||||
| 364 | if (!cms_kari_create_ephemeral_key(kari, pk) 
 | 0-7 | ||||||||||||
| 365 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 366 | - | |||||||||||||
| 367 | EVP_PKEY_up_ref(pk); | - | ||||||||||||
| 368 | rek->pkey = pk; | - | ||||||||||||
| 369 | return executed 7 times by 1 test: 1; return 1;Executed by: 
 executed 7 times by 1 test:  return 1;Executed by: 
 | 7 | ||||||||||||
| 370 | } | - | ||||||||||||
| 371 | - | |||||||||||||
| 372 | static int cms_wrap_init(CMS_KeyAgreeRecipientInfo *kari, | - | ||||||||||||
| 373 | const EVP_CIPHER *cipher) | - | ||||||||||||
| 374 | { | - | ||||||||||||
| 375 | EVP_CIPHER_CTX *ctx = kari->ctx; | - | ||||||||||||
| 376 | const EVP_CIPHER *kekcipher; | - | ||||||||||||
| 377 | int keylen = EVP_CIPHER_key_length(cipher); | - | ||||||||||||
| 378 | - | |||||||||||||
| 379 | kekcipher = EVP_CIPHER_CTX_cipher(ctx); | - | ||||||||||||
| 380 | - | |||||||||||||
| 381 | if (kekcipher 
 | 0-7 | ||||||||||||
| 382 | if (( 
 
 | 0 | ||||||||||||
| 383 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 384 | return never executed: 1; return 1;never executed:  return 1; | 0 | ||||||||||||
| 385 | } | - | ||||||||||||
| 386 | - | |||||||||||||
| 387 | - | |||||||||||||
| 388 | - | |||||||||||||
| 389 | - | |||||||||||||
| 390 | - | |||||||||||||
| 391 | if (EVP_CIPHER_type(cipher) == 44 
 | 3-4 | ||||||||||||
| 392 | kekcipher = EVP_des_ede3_wrap(); executed 4 times by 1 test:  kekcipher = EVP_des_ede3_wrap();Executed by: 
 | 4 | ||||||||||||
| 393 | else | - | ||||||||||||
| 394 | - | |||||||||||||
| 395 | if (keylen <= 16 
 | 0-3 | ||||||||||||
| 396 | kekcipher = EVP_aes_128_wrap(); executed 3 times by 1 test:  kekcipher = EVP_aes_128_wrap();Executed by: 
 | 3 | ||||||||||||
| 397 | else if (keylen <= 24 
 | 0 | ||||||||||||
| 398 | kekcipher = EVP_aes_192_wrap(); never executed:  kekcipher = EVP_aes_192_wrap(); | 0 | ||||||||||||
| 399 | else | - | ||||||||||||
| 400 | kekcipher = EVP_aes_256_wrap(); never executed:  kekcipher = EVP_aes_256_wrap(); | 0 | ||||||||||||
| 401 | return executed 7 times by 1 test: EVP_EncryptInit_ex(ctx, kekcipher, return EVP_EncryptInit_ex(ctx, kekcipher, ((void *)0) , ((void *)0) , ((void *)0) );Executed by: 
 executed 7 times by 1 test:  return EVP_EncryptInit_ex(ctx, kekcipher, ((void *)0) , ((void *)0) , ((void *)0) );Executed by: 
 | 7 | ||||||||||||
| 402 | ((void *)0) executed 7 times by 1 test:  return EVP_EncryptInit_ex(ctx, kekcipher, ((void *)0) , ((void *)0) , ((void *)0) );Executed by: 
 | 7 | ||||||||||||
| 403 | , executed 7 times by 1 test:  return EVP_EncryptInit_ex(ctx, kekcipher, ((void *)0) , ((void *)0) , ((void *)0) );Executed by: 
 | 7 | ||||||||||||
| 404 | ((void *)0) executed 7 times by 1 test:  return EVP_EncryptInit_ex(ctx, kekcipher, ((void *)0) , ((void *)0) , ((void *)0) );Executed by: 
 | 7 | ||||||||||||
| 405 | , executed 7 times by 1 test:  return EVP_EncryptInit_ex(ctx, kekcipher, ((void *)0) , ((void *)0) , ((void *)0) );Executed by: 
 | 7 | ||||||||||||
| 406 | ((void *)0) executed 7 times by 1 test:  return EVP_EncryptInit_ex(ctx, kekcipher, ((void *)0) , ((void *)0) , ((void *)0) );Executed by: 
 | 7 | ||||||||||||
| 407 | ); executed 7 times by 1 test:  return EVP_EncryptInit_ex(ctx, kekcipher, ((void *)0) , ((void *)0) , ((void *)0) );Executed by: 
 | 7 | ||||||||||||
| 408 | } | - | ||||||||||||
| 409 | - | |||||||||||||
| 410 | - | |||||||||||||
| 411 | - | |||||||||||||
| 412 | int cms_RecipientInfo_kari_encrypt(CMS_ContentInfo *cms, | - | ||||||||||||
| 413 | CMS_RecipientInfo *ri) | - | ||||||||||||
| 414 | { | - | ||||||||||||
| 415 | CMS_KeyAgreeRecipientInfo *kari; | - | ||||||||||||
| 416 | CMS_EncryptedContentInfo *ec; | - | ||||||||||||
| 417 | CMS_RecipientEncryptedKey *rek; | - | ||||||||||||
| 418 | struct stack_st_CMS_RecipientEncryptedKey *reks; | - | ||||||||||||
| 419 | int i; | - | ||||||||||||
| 420 | - | |||||||||||||
| 421 | if (ri->type != 1 
 | 0-7 | ||||||||||||
| 422 | ERR_put_error(46,(178),(181),__FILE__,373); | - | ||||||||||||
| 423 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 424 | } | - | ||||||||||||
| 425 | kari = ri->d.kari; | - | ||||||||||||
| 426 | reks = kari->recipientEncryptedKeys; | - | ||||||||||||
| 427 | ec = cms->d.envelopedData->encryptedContentInfo; | - | ||||||||||||
| 428 | - | |||||||||||||
| 429 | if (!cms_wrap_init(kari, ec->cipher) 
 | 0-7 | ||||||||||||
| 430 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 431 | - | |||||||||||||
| 432 | - | |||||||||||||
| 433 | - | |||||||||||||
| 434 | - | |||||||||||||
| 435 | if (kari->originator->type == -1 
 | 0-7 | ||||||||||||
| 436 | CMS_OriginatorIdentifierOrKey *oik = kari->originator; | - | ||||||||||||
| 437 | oik->type = 2; | - | ||||||||||||
| 438 | oik->d.originatorKey = (CMS_OriginatorPublicKey *)ASN1_item_new((&(CMS_OriginatorPublicKey_it))); | - | ||||||||||||
| 439 | if (!oik->d.originatorKey 
 | 0-7 | ||||||||||||
| 440 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 441 | } executed 7 times by 1 test:  end of blockExecuted by: 
 | 7 | ||||||||||||
| 442 | - | |||||||||||||
| 443 | if (!cms_env_asn1_ctrl(ri, 0) 
 | 0-7 | ||||||||||||
| 444 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 445 | - | |||||||||||||
| 446 | for (i = 0; i < sk_CMS_RecipientEncryptedKey_num(reks) 
 | 7 | ||||||||||||
| 447 | unsigned char *enckey; | - | ||||||||||||
| 448 | size_t enckeylen; | - | ||||||||||||
| 449 | rek = sk_CMS_RecipientEncryptedKey_value(reks, i); | - | ||||||||||||
| 450 | if (EVP_PKEY_derive_set_peer(kari->pctx, rek->pkey) <= 0 
 | 0-7 | ||||||||||||
| 451 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 452 | if (!cms_kek_cipher(&enckey, &enckeylen, ec->key, ec->keylen, 
 | 0-7 | ||||||||||||
| 453 | kari, 1) 
 | 0-7 | ||||||||||||
| 454 | return never executed: 0; return 0;never executed:  return 0; | 0 | ||||||||||||
| 455 | ASN1_STRING_set0(rek->encryptedKey, enckey, enckeylen); | - | ||||||||||||
| 456 | } executed 7 times by 1 test:  end of blockExecuted by: 
 | 7 | ||||||||||||
| 457 | - | |||||||||||||
| 458 | return executed 7 times by 1 test: 1; return 1;Executed by: 
 executed 7 times by 1 test:  return 1;Executed by: 
 | 7 | ||||||||||||
| 459 | - | |||||||||||||
| 460 | } | - | ||||||||||||
| Switch to Source code | Preprocessed file |