OpenCoverage

poly1305_pmeth.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/poly1305/poly1305_pmeth.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2007-2018 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 "internal/cryptlib.h"-
12#include <openssl/x509.h>-
13#include <openssl/x509v3.h>-
14#include <openssl/evp.h>-
15#include <openssl/err.h>-
16#include "internal/poly1305.h"-
17#include "poly1305_local.h"-
18#include "internal/evp_int.h"-
19-
20/* POLY1305 pkey context structure */-
21-
22typedef struct {-
23 ASN1_OCTET_STRING ktmp; /* Temp storage for key */-
24 POLY1305 ctx;-
25} POLY1305_PKEY_CTX;-
26-
27static int pkey_poly1305_init(EVP_PKEY_CTX *ctx)-
28{-
29 POLY1305_PKEY_CTX *pctx;-
30-
31 if ((pctx = OPENSSL_zalloc(sizeof(*pctx))) == NULL) {
(pctx = CRYPTO...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 84 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-84
32 CRYPTOerr(CRYPTO_F_PKEY_POLY1305_INIT, ERR_R_MALLOC_FAILURE);-
33 return 0;
never executed: return 0;
0
34 }-
35 pctx->ktmp.type = V_ASN1_OCTET_STRING;-
36-
37 EVP_PKEY_CTX_set_data(ctx, pctx);-
38 EVP_PKEY_CTX_set0_keygen_info(ctx, NULL, 0);-
39 return 1;
executed 84 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
84
40}-
41-
42static void pkey_poly1305_cleanup(EVP_PKEY_CTX *ctx)-
43{-
44 POLY1305_PKEY_CTX *pctx = EVP_PKEY_CTX_get_data(ctx);-
45-
46 if (pctx != NULL) {
pctx != ((void *)0)Description
TRUEevaluated 84 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-84
47 OPENSSL_clear_free(pctx->ktmp.data, pctx->ktmp.length);-
48 OPENSSL_clear_free(pctx, sizeof(*pctx));-
49 EVP_PKEY_CTX_set_data(ctx, NULL);-
50 }
executed 84 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
84
51}
executed 84 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
84
52-
53static int pkey_poly1305_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)-
54{-
55 POLY1305_PKEY_CTX *sctx, *dctx;-
56-
57 /* allocate memory for dst->data and a new POLY1305_CTX in dst->data->ctx */-
58 if (!pkey_poly1305_init(dst))
!pkey_poly1305_init(dst)Description
TRUEnever evaluated
FALSEevaluated 42 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-42
59 return 0;
never executed: return 0;
0
60 sctx = EVP_PKEY_CTX_get_data(src);-
61 dctx = EVP_PKEY_CTX_get_data(dst);-
62 if (ASN1_STRING_get0_data(&sctx->ktmp) != NULL &&
ASN1_STRING_ge...!= ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 42 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-42
63 !ASN1_STRING_copy(&dctx->ktmp, &sctx->ktmp)) {
!ASN1_STRING_c..., &sctx->ktmp)Description
TRUEnever evaluated
FALSEnever evaluated
0
64 /* cleanup and free the POLY1305_PKEY_CTX in dst->data */-
65 pkey_poly1305_cleanup(dst);-
66 return 0;
never executed: return 0;
0
67 }-
68 memcpy(&dctx->ctx, &sctx->ctx, sizeof(POLY1305));-
69 return 1;
executed 42 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
42
70}-
71-
72static int pkey_poly1305_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)-
73{-
74 ASN1_OCTET_STRING *key;-
75 POLY1305_PKEY_CTX *pctx = EVP_PKEY_CTX_get_data(ctx);-
76-
77 if (ASN1_STRING_get0_data(&pctx->ktmp) == NULL)
ASN1_STRING_ge...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
78 return 0;
never executed: return 0;
0
79 key = ASN1_OCTET_STRING_dup(&pctx->ktmp);-
80 if (key == NULL)
key == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
81 return 0;
never executed: return 0;
0
82 return EVP_PKEY_assign_POLY1305(pkey, key);
never executed: return EVP_PKEY_assign((pkey),1061, (char *)(key));
0
83}-
84-
85static int int_update(EVP_MD_CTX *ctx, const void *data, size_t count)-
86{-
87 POLY1305_PKEY_CTX *pctx = EVP_PKEY_CTX_get_data(EVP_MD_CTX_pkey_ctx(ctx));-
88-
89 Poly1305_Update(&pctx->ctx, data, count);-
90 return 1;
executed 42 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
42
91}-
92-
93static int poly1305_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)-
94{-
95 POLY1305_PKEY_CTX *pctx = ctx->data;-
96 ASN1_OCTET_STRING *key = (ASN1_OCTET_STRING *)ctx->pkey->pkey.ptr;-
97-
98 if (key->length != POLY1305_KEY_SIZE)
key->length != 32Description
TRUEnever evaluated
FALSEevaluated 42 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-42
99 return 0;
never executed: return 0;
0
100 EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_NO_INIT);-
101 EVP_MD_CTX_set_update_fn(mctx, int_update);-
102 Poly1305_Init(&pctx->ctx, key->data);-
103 return 1;
executed 42 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
42
104}-
105static int poly1305_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,-
106 EVP_MD_CTX *mctx)-
107{-
108 POLY1305_PKEY_CTX *pctx = ctx->data;-
109-
110 *siglen = POLY1305_DIGEST_SIZE;-
111 if (sig != NULL)
sig != ((void *)0)Description
TRUEevaluated 42 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 42 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
42
112 Poly1305_Final(&pctx->ctx, sig);
executed 42 times by 1 test: Poly1305_Final(&pctx->ctx, sig);
Executed by:
  • libcrypto.so.1.1
42
113 return 1;
executed 84 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
84
114}-
115-
116static int pkey_poly1305_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)-
117{-
118 POLY1305_PKEY_CTX *pctx = EVP_PKEY_CTX_get_data(ctx);-
119 const unsigned char *key;-
120 size_t len;-
121-
122 switch (type) {-
123-
124 case EVP_PKEY_CTRL_MD:
executed 42 times by 1 test: case 1:
Executed by:
  • libcrypto.so.1.1
42
125 /* ignore */-
126 break;
executed 42 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
42
127-
128 case EVP_PKEY_CTRL_SET_MAC_KEY:
never executed: case 6:
0
129 case EVP_PKEY_CTRL_DIGESTINIT:
never executed: case 7:
0
130 if (type == EVP_PKEY_CTRL_SET_MAC_KEY) {
type == 6Description
TRUEnever evaluated
FALSEnever evaluated
0
131 /* user explicitly setting the key */-
132 key = p2;-
133 len = p1;-
134 } else {
never executed: end of block
0
135 /* user indirectly setting the key via EVP_DigestSignInit */-
136 key = EVP_PKEY_get0_poly1305(EVP_PKEY_CTX_get0_pkey(ctx), &len);-
137 }
never executed: end of block
0
138 if (key == NULL || len != POLY1305_KEY_SIZE ||
key == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
len != 32Description
TRUEnever evaluated
FALSEnever evaluated
0
139 !ASN1_OCTET_STRING_set(&pctx->ktmp, key, len))
!ASN1_OCTET_ST...tmp, key, len)Description
TRUEnever evaluated
FALSEnever evaluated
0
140 return 0;
never executed: return 0;
0
141 Poly1305_Init(&pctx->ctx, ASN1_STRING_get0_data(&pctx->ktmp));-
142 break;
never executed: break;
0
143-
144 default:
never executed: default:
0
145 return -2;
never executed: return -2;
0
146-
147 }-
148 return 1;
executed 42 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
42
149}-
150-
151static int pkey_poly1305_ctrl_str(EVP_PKEY_CTX *ctx,-
152 const char *type, const char *value)-
153{-
154 if (value == NULL)
value == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
155 return 0;
never executed: return 0;
0
156 if (strcmp(type, "key") == 0)
never executed: __result = (((const unsigned char *) (const char *) ( type ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "key" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
157 return EVP_PKEY_CTX_str2ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, value);
never executed: return EVP_PKEY_CTX_str2ctrl(ctx, 6, value);
0
158 if (strcmp(type, "hexkey") == 0)
never executed: __result = (((const unsigned char *) (const char *) ( type ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "hexkey" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
159 return EVP_PKEY_CTX_hex2ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, value);
never executed: return EVP_PKEY_CTX_hex2ctrl(ctx, 6, value);
0
160 return -2;
never executed: return -2;
0
161}-
162-
163const EVP_PKEY_METHOD poly1305_pkey_meth = {-
164 EVP_PKEY_POLY1305,-
165 EVP_PKEY_FLAG_SIGCTX_CUSTOM, /* we don't deal with a separate MD */-
166 pkey_poly1305_init,-
167 pkey_poly1305_copy,-
168 pkey_poly1305_cleanup,-
169-
170 0, 0,-
171-
172 0,-
173 pkey_poly1305_keygen,-
174-
175 0, 0,-
176-
177 0, 0,-
178-
179 0, 0,-
180-
181 poly1305_signctx_init,-
182 poly1305_signctx,-
183-
184 0, 0,-
185-
186 0, 0,-
187-
188 0, 0,-
189-
190 0, 0,-
191-
192 pkey_poly1305_ctrl,-
193 pkey_poly1305_ctrl_str-
194};-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2