OpenCoverage

a_verify.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/a_verify.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (the "License"). You may not use-
5 * this file except in compliance with the License. You can obtain a copy-
6 * in the file LICENSE in the source distribution or at-
7 * https://www.openssl.org/source/license.html-
8 */-
9-
10#include <stdio.h>-
11#include <time.h>-
12#include <sys/types.h>-
13-
14#include "internal/cryptlib.h"-
15-
16#include <openssl/bn.h>-
17#include <openssl/x509.h>-
18#include <openssl/objects.h>-
19#include <openssl/buffer.h>-
20#include <openssl/evp.h>-
21#include "internal/asn1_int.h"-
22#include "internal/evp_int.h"-
23-
24#ifndef NO_ASN1_OLD-
25-
26int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,-
27 char *data, EVP_PKEY *pkey)-
28{-
29 EVP_MD_CTX *ctx = EVP_MD_CTX_new();-
30 const EVP_MD *type;-
31 unsigned char *p, *buf_in = NULL;-
32 int ret = -1, i, inl;-
33-
34 if (ctx == NULL) {
ctx == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
35 ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_MALLOC_FAILURE);-
36 goto err;
never executed: goto err;
0
37 }-
38 i = OBJ_obj2nid(a->algorithm);-
39 type = EVP_get_digestbyname(OBJ_nid2sn(i));-
40 if (type == NULL) {
type == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
41 ASN1err(ASN1_F_ASN1_VERIFY, ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);-
42 goto err;
never executed: goto err;
0
43 }-
44-
45 if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7) {
signature->type == 3Description
TRUEnever evaluated
FALSEnever evaluated
signature->flags & 0x7Description
TRUEnever evaluated
FALSEnever evaluated
0
46 ASN1err(ASN1_F_ASN1_VERIFY, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);-
47 goto err;
never executed: goto err;
0
48 }-
49-
50 inl = i2d(data, NULL);-
51 buf_in = OPENSSL_malloc((unsigned int)inl);-
52 if (buf_in == NULL) {
buf_in == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
53 ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_MALLOC_FAILURE);-
54 goto err;
never executed: goto err;
0
55 }-
56 p = buf_in;-
57-
58 i2d(data, &p);-
59 ret = EVP_VerifyInit_ex(ctx, type, NULL)
EVP_DigestInit... ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0
60 && EVP_VerifyUpdate(ctx, (unsigned char *)buf_in, inl);
EVP_DigestUpda... *)buf_in,inl)Description
TRUEnever evaluated
FALSEnever evaluated
0
61-
62 OPENSSL_clear_free(buf_in, (unsigned int)inl);-
63-
64 if (!ret) {
!retDescription
TRUEnever evaluated
FALSEnever evaluated
0
65 ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_EVP_LIB);-
66 goto err;
never executed: goto err;
0
67 }-
68 ret = -1;-
69-
70 if (EVP_VerifyFinal(ctx, (unsigned char *)signature->data,
EVP_VerifyFina...th, pkey) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
71 (unsigned int)signature->length, pkey) <= 0) {
EVP_VerifyFina...th, pkey) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
72 ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_EVP_LIB);-
73 ret = 0;-
74 goto err;
never executed: goto err;
0
75 }-
76 ret = 1;-
77 err:
code before this statement never executed: err:
0
78 EVP_MD_CTX_free(ctx);-
79 return ret;
never executed: return ret;
0
80}-
81-
82#endif-
83-
84int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,-
85 ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey)-
86{-
87 EVP_MD_CTX *ctx = NULL;-
88 unsigned char *buf_in = NULL;-
89 int ret = -1, inl = 0;-
90-
91 int mdnid, pknid;-
92-
93 if (!pkey) {
!pkeyDescription
TRUEnever evaluated
FALSEevaluated 1370 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1370
94 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER);-
95 return -1;
never executed: return -1;
0
96 }-
97-
98 if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7) {
signature->type == 3Description
TRUEevaluated 1370 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
signature->flags & 0x7Description
TRUEnever evaluated
FALSEevaluated 1370 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1370
99 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);-
100 return -1;
never executed: return -1;
0
101 }-
102-
103 ctx = EVP_MD_CTX_new();-
104 if (ctx == NULL) {
ctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1370 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1370
105 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_MALLOC_FAILURE);-
106 goto err;
never executed: goto err;
0
107 }-
108-
109 /* Convert signature OID into digest and public key OIDs */-
110 if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) {
!OBJ_find_sigi...mdnid, &pknid)Description
TRUEnever evaluated
FALSEevaluated 1370 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1370
111 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);-
112 goto err;
never executed: goto err;
0
113 }-
114 if (mdnid == NID_undef) {
mdnid == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1366 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4-1366
115 if (!pkey->ameth || !pkey->ameth->item_verify) {
!pkey->amethDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!pkey->ameth->item_verifyDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
116 ASN1err(ASN1_F_ASN1_ITEM_VERIFY,-
117 ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);-
118 goto err;
never executed: goto err;
0
119 }-
120 ret = pkey->ameth->item_verify(ctx, it, asn, a, signature, pkey);-
121 /*-
122 * Return value of 2 means carry on, anything else means we exit-
123 * straight away: either a fatal error of the underlying verification-
124 * routine handles all verification.-
125 */-
126 if (ret != 2)
ret != 2Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
127 goto err;
never executed: goto err;
0
128 ret = -1;-
129 } else {
executed 4 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
4
130 const EVP_MD *type;-
131 type = EVP_get_digestbynid(mdnid);-
132 if (type == NULL) {
type == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1366 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1366
133 ASN1err(ASN1_F_ASN1_ITEM_VERIFY,-
134 ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);-
135 goto err;
never executed: goto err;
0
136 }-
137-
138 /* Check public key OID matches public key type */-
139 if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) {
EVP_PKEY_type(...ameth->pkey_idDescription
TRUEnever evaluated
FALSEevaluated 1366 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1366
140 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ASN1_R_WRONG_PUBLIC_KEY_TYPE);-
141 goto err;
never executed: goto err;
0
142 }-
143-
144 if (!EVP_DigestVerifyInit(ctx, NULL, type, NULL, pkey)) {
!EVP_DigestVer...d *)0) , pkey)Description
TRUEnever evaluated
FALSEevaluated 1366 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1366
145 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB);-
146 ret = 0;-
147 goto err;
never executed: goto err;
0
148 }-
149-
150 }
executed 1366 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1366
151-
152 inl = ASN1_item_i2d(asn, &buf_in, it);-
153-
154 if (buf_in == NULL) {
buf_in == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1370 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1370
155 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_MALLOC_FAILURE);-
156 goto err;
never executed: goto err;
0
157 }-
158-
159 ret = EVP_DigestVerify(ctx, signature->data, (size_t)signature->length,-
160 buf_in, inl);-
161 if (ret <= 0) {
ret <= 0Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1345 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
25-1345
162 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB);-
163 goto err;
executed 25 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
25
164 }-
165 ret = 1;-
166 err:
code before this statement executed 1345 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
1345
167 OPENSSL_clear_free(buf_in, (unsigned int)inl);-
168 EVP_MD_CTX_free(ctx);-
169 return ret;
executed 1370 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
1370
170}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2