OpenCoverage

rsa_asn1.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/rsa/rsa_asn1.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2000-2017 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/bn.h>-
13#include <openssl/x509.h>-
14#include <openssl/asn1t.h>-
15#include "rsa_locl.h"-
16-
17/*-
18 * Override the default free and new methods,-
19 * and calculate helper products for multi-prime-
20 * RSA keys.-
21 */-
22static int rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,-
23 void *exarg)-
24{-
25 if (operation == ASN1_OP_NEW_PRE) {
operation == 0Description
TRUEevaluated 25937 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 57888 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
25937-57888
26 *pval = (ASN1_VALUE *)RSA_new();-
27 if (*pval != NULL)
*pval != ((void *)0)Description
TRUEevaluated 25937 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-25937
28 return 2;
executed 25937 times by 1 test: return 2;
Executed by:
  • libcrypto.so.1.1
25937
29 return 0;
never executed: return 0;
0
30 } else if (operation == ASN1_OP_FREE_PRE) {
operation == 2Description
TRUEevaluated 11115 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 46773 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
11115-46773
31 RSA_free((RSA *)*pval);-
32 *pval = NULL;-
33 return 2;
executed 11115 times by 1 test: return 2;
Executed by:
  • libcrypto.so.1.1
11115
34 } else if (operation == ASN1_OP_D2I_POST) {
operation == 5Description
TRUEevaluated 14923 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 31850 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
14923-31850
35 if (((RSA *)*pval)->version != RSA_ASN1_VERSION_MULTI) {
((RSA *)*pval)->version != 1Description
TRUEevaluated 14755 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 168 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
168-14755
36 /* not a multi-prime key, skip */-
37 return 1;
executed 14755 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
14755
38 }-
39 return (rsa_multip_calc_product((RSA *)*pval) == 1) ? 2 : 0;
executed 168 times by 1 test: return (rsa_multip_calc_product((RSA *)*pval) == 1) ? 2 : 0;
Executed by:
  • libcrypto.so.1.1
(rsa_multip_ca...*)*pval) == 1)Description
TRUEevaluated 166 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-168
40 }-
41 return 1;
executed 31850 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
31850
42}-
43-
44/* Based on definitions in RFC 8017 appendix A.1.2 */-
45ASN1_SEQUENCE(RSA_PRIME_INFO) = {-
46 ASN1_SIMPLE(RSA_PRIME_INFO, r, CBIGNUM),-
47 ASN1_SIMPLE(RSA_PRIME_INFO, d, CBIGNUM),-
48 ASN1_SIMPLE(RSA_PRIME_INFO, t, CBIGNUM),-
49} ASN1_SEQUENCE_END(RSA_PRIME_INFO)-
50-
51ASN1_SEQUENCE_cb(RSAPrivateKey, rsa_cb) = {-
52 ASN1_EMBED(RSA, version, INT32),-
53 ASN1_SIMPLE(RSA, n, BIGNUM),-
54 ASN1_SIMPLE(RSA, e, BIGNUM),-
55 ASN1_SIMPLE(RSA, d, CBIGNUM),-
56 ASN1_SIMPLE(RSA, p, CBIGNUM),-
57 ASN1_SIMPLE(RSA, q, CBIGNUM),-
58 ASN1_SIMPLE(RSA, dmp1, CBIGNUM),-
59 ASN1_SIMPLE(RSA, dmq1, CBIGNUM),-
60 ASN1_SIMPLE(RSA, iqmp, CBIGNUM),-
61 ASN1_SEQUENCE_OF_OPT(RSA, prime_infos, RSA_PRIME_INFO)-
62} ASN1_SEQUENCE_END_cb(RSA, RSAPrivateKey)-
63-
64-
65ASN1_SEQUENCE_cb(RSAPublicKey, rsa_cb) = {-
66 ASN1_SIMPLE(RSA, n, BIGNUM),-
67 ASN1_SIMPLE(RSA, e, BIGNUM),-
68} ASN1_SEQUENCE_END_cb(RSA, RSAPublicKey)-
69-
70/* Free up maskHash */-
71static int rsa_pss_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,-
72 void *exarg)-
73{-
74 if (operation == ASN1_OP_FREE_PRE) {
operation == 2Description
TRUEevaluated 3158 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 12729 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3158-12729
75 RSA_PSS_PARAMS *pss = (RSA_PSS_PARAMS *)*pval;-
76 X509_ALGOR_free(pss->maskHash);-
77 }
executed 3158 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3158
78 return 1;
executed 15887 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
15887
79}-
80-
81ASN1_SEQUENCE_cb(RSA_PSS_PARAMS, rsa_pss_cb) = {-
82 ASN1_EXP_OPT(RSA_PSS_PARAMS, hashAlgorithm, X509_ALGOR,0),-
83 ASN1_EXP_OPT(RSA_PSS_PARAMS, maskGenAlgorithm, X509_ALGOR,1),-
84 ASN1_EXP_OPT(RSA_PSS_PARAMS, saltLength, ASN1_INTEGER,2),-
85 ASN1_EXP_OPT(RSA_PSS_PARAMS, trailerField, ASN1_INTEGER,3)-
86} ASN1_SEQUENCE_END_cb(RSA_PSS_PARAMS, RSA_PSS_PARAMS)-
87-
88IMPLEMENT_ASN1_FUNCTIONS(RSA_PSS_PARAMS)
executed 26233 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
never executed: return (RSA_PSS_PARAMS *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(RSA_PSS_PARAMS_it)));
never executed: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(RSA_PSS_PARAMS_it)));
executed 4 times by 1 test: return (RSA_PSS_PARAMS *)ASN1_item_new((&(RSA_PSS_PARAMS_it)));
Executed by:
  • libcrypto.so.1.1
0-26233
89-
90/* Free up maskHash */-
91static int rsa_oaep_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,-
92 void *exarg)-
93{-
94 if (operation == ASN1_OP_FREE_PRE) {
operation == 2Description
TRUEevaluated 2966 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 11882 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2966-11882
95 RSA_OAEP_PARAMS *oaep = (RSA_OAEP_PARAMS *)*pval;-
96 X509_ALGOR_free(oaep->maskHash);-
97 }
executed 2966 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2966
98 return 1;
executed 14848 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
14848
99}-
100-
101ASN1_SEQUENCE_cb(RSA_OAEP_PARAMS, rsa_oaep_cb) = {-
102 ASN1_EXP_OPT(RSA_OAEP_PARAMS, hashFunc, X509_ALGOR, 0),-
103 ASN1_EXP_OPT(RSA_OAEP_PARAMS, maskGenFunc, X509_ALGOR, 1),-
104 ASN1_EXP_OPT(RSA_OAEP_PARAMS, pSourceFunc, X509_ALGOR, 2),-
105} ASN1_SEQUENCE_END_cb(RSA_OAEP_PARAMS, RSA_OAEP_PARAMS)-
106-
107IMPLEMENT_ASN1_FUNCTIONS(RSA_OAEP_PARAMS)
executed 4 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
never executed: return (RSA_OAEP_PARAMS *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(RSA_OAEP_PARAMS_it)));
never executed: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(RSA_OAEP_PARAMS_it)));
executed 2 times by 1 test: return (RSA_OAEP_PARAMS *)ASN1_item_new((&(RSA_OAEP_PARAMS_it)));
Executed by:
  • libcrypto.so.1.1
0-4
108-
109IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(RSA, RSAPrivateKey, RSAPrivateKey)
executed 6512 times by 1 test: return (RSA *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(RSAPrivateKey_it)));
Executed by:
  • libcrypto.so.1.1
executed 129 times by 1 test: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(RSAPrivateKey_it)));
Executed by:
  • libcrypto.so.1.1
129-6512
110-
111IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(RSA, RSAPublicKey, RSAPublicKey)
executed 14335 times by 1 test: return (RSA *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(RSAPublicKey_it)));
Executed by:
  • libcrypto.so.1.1
executed 1686 times by 1 test: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(RSAPublicKey_it)));
Executed by:
  • libcrypto.so.1.1
1686-14335
112-
113RSA *RSAPublicKey_dup(RSA *rsa)-
114{-
115 return ASN1_item_dup(ASN1_ITEM_rptr(RSAPublicKey), rsa);
never executed: return ASN1_item_dup((&(RSAPublicKey_it)), rsa);
0
116}-
117-
118RSA *RSAPrivateKey_dup(RSA *rsa)-
119{-
120 return ASN1_item_dup(ASN1_ITEM_rptr(RSAPrivateKey), rsa);
never executed: return ASN1_item_dup((&(RSAPrivateKey_it)), rsa);
0
121}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2