| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/rsa/rsa_mp.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||
| 2 | * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||
| 3 | * Copyright 2017 BaishanCloud. All rights reserved. | - | ||||||
| 4 | * | - | ||||||
| 5 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||
| 6 | * this file except in compliance with the License. You can obtain a copy | - | ||||||
| 7 | * in the file LICENSE in the source distribution or at | - | ||||||
| 8 | * https://www.openssl.org/source/license.html | - | ||||||
| 9 | */ | - | ||||||
| 10 | - | |||||||
| 11 | #include <openssl/bn.h> | - | ||||||
| 12 | #include <openssl/err.h> | - | ||||||
| 13 | #include "rsa_locl.h" | - | ||||||
| 14 | - | |||||||
| 15 | void rsa_multip_info_free_ex(RSA_PRIME_INFO *pinfo) | - | ||||||
| 16 | { | - | ||||||
| 17 | /* free pp and pinfo only */ | - | ||||||
| 18 | BN_clear_free(pinfo->pp); | - | ||||||
| 19 | OPENSSL_free(pinfo); | - | ||||||
| 20 | } executed 8639 times by 1 test: end of blockExecuted by:
| 8639 | ||||||
| 21 | - | |||||||
| 22 | void rsa_multip_info_free(RSA_PRIME_INFO *pinfo) | - | ||||||
| 23 | { | - | ||||||
| 24 | /* free a RSA_PRIME_INFO structure */ | - | ||||||
| 25 | BN_clear_free(pinfo->r); | - | ||||||
| 26 | BN_clear_free(pinfo->d); | - | ||||||
| 27 | BN_clear_free(pinfo->t); | - | ||||||
| 28 | rsa_multip_info_free_ex(pinfo); | - | ||||||
| 29 | } executed 8639 times by 1 test: end of blockExecuted by:
| 8639 | ||||||
| 30 | - | |||||||
| 31 | RSA_PRIME_INFO *rsa_multip_info_new(void) | - | ||||||
| 32 | { | - | ||||||
| 33 | RSA_PRIME_INFO *pinfo; | - | ||||||
| 34 | - | |||||||
| 35 | /* create a RSA_PRIME_INFO structure */ | - | ||||||
| 36 | if ((pinfo = OPENSSL_zalloc(sizeof(RSA_PRIME_INFO))) == NULL) {
| 0-13 | ||||||
| 37 | RSAerr(RSA_F_RSA_MULTIP_INFO_NEW, ERR_R_MALLOC_FAILURE); | - | ||||||
| 38 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 39 | } | - | ||||||
| 40 | if ((pinfo->r = BN_secure_new()) == NULL)
| 0-13 | ||||||
| 41 | goto err; never executed: goto err; | 0 | ||||||
| 42 | if ((pinfo->d = BN_secure_new()) == NULL)
| 0-13 | ||||||
| 43 | goto err; never executed: goto err; | 0 | ||||||
| 44 | if ((pinfo->t = BN_secure_new()) == NULL)
| 0-13 | ||||||
| 45 | goto err; never executed: goto err; | 0 | ||||||
| 46 | if ((pinfo->pp = BN_secure_new()) == NULL)
| 0-13 | ||||||
| 47 | goto err; never executed: goto err; | 0 | ||||||
| 48 | - | |||||||
| 49 | return pinfo; executed 13 times by 1 test: return pinfo;Executed by:
| 13 | ||||||
| 50 | - | |||||||
| 51 | err: | - | ||||||
| 52 | BN_free(pinfo->r); | - | ||||||
| 53 | BN_free(pinfo->d); | - | ||||||
| 54 | BN_free(pinfo->t); | - | ||||||
| 55 | BN_free(pinfo->pp); | - | ||||||
| 56 | OPENSSL_free(pinfo); | - | ||||||
| 57 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 58 | } | - | ||||||
| 59 | - | |||||||
| 60 | /* Refill products of primes */ | - | ||||||
| 61 | int rsa_multip_calc_product(RSA *rsa) | - | ||||||
| 62 | { | - | ||||||
| 63 | RSA_PRIME_INFO *pinfo; | - | ||||||
| 64 | BIGNUM *p1 = NULL, *p2 = NULL; | - | ||||||
| 65 | BN_CTX *ctx = NULL; | - | ||||||
| 66 | int i, rv = 0, ex_primes; | - | ||||||
| 67 | - | |||||||
| 68 | if ((ex_primes = sk_RSA_PRIME_INFO_num(rsa->prime_infos)) <= 0) {
| 2-167 | ||||||
| 69 | /* invalid */ | - | ||||||
| 70 | goto err; executed 2 times by 1 test: goto err;Executed by:
| 2 | ||||||
| 71 | } | - | ||||||
| 72 | - | |||||||
| 73 | if ((ctx = BN_CTX_new()) == NULL)
| 0-167 | ||||||
| 74 | goto err; never executed: goto err; | 0 | ||||||
| 75 | - | |||||||
| 76 | /* calculate pinfo->pp = p * q for first 'extra' prime */ | - | ||||||
| 77 | p1 = rsa->p; | - | ||||||
| 78 | p2 = rsa->q; | - | ||||||
| 79 | - | |||||||
| 80 | for (i = 0; i < ex_primes; i++) {
| 167-3947 | ||||||
| 81 | pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i); | - | ||||||
| 82 | if (pinfo->pp == NULL) {
| 1-3946 | ||||||
| 83 | pinfo->pp = BN_secure_new(); | - | ||||||
| 84 | if (pinfo->pp == NULL)
| 0-3946 | ||||||
| 85 | goto err; never executed: goto err; | 0 | ||||||
| 86 | } executed 3946 times by 1 test: end of blockExecuted by:
| 3946 | ||||||
| 87 | if (!BN_mul(pinfo->pp, p1, p2, ctx))
| 0-3947 | ||||||
| 88 | goto err; never executed: goto err; | 0 | ||||||
| 89 | /* save previous one */ | - | ||||||
| 90 | p1 = pinfo->pp; | - | ||||||
| 91 | p2 = pinfo->r; | - | ||||||
| 92 | } executed 3947 times by 1 test: end of blockExecuted by:
| 3947 | ||||||
| 93 | - | |||||||
| 94 | rv = 1; | - | ||||||
| 95 | err: code before this statement executed 167 times by 1 test: err:Executed by:
| 167 | ||||||
| 96 | BN_CTX_free(ctx); | - | ||||||
| 97 | return rv; executed 169 times by 1 test: return rv;Executed by:
| 169 | ||||||
| 98 | } | - | ||||||
| 99 | - | |||||||
| 100 | int rsa_multip_cap(int bits) | - | ||||||
| 101 | { | - | ||||||
| 102 | int cap = 5; | - | ||||||
| 103 | - | |||||||
| 104 | if (bits < 1024)
| 3-23 | ||||||
| 105 | cap = 2; executed 3 times by 1 test: cap = 2;Executed by:
| 3 | ||||||
| 106 | else if (bits < 4096)
| 8-15 | ||||||
| 107 | cap = 3; executed 15 times by 1 test: cap = 3;Executed by:
| 15 | ||||||
| 108 | else if (bits < 8192)
| 4 | ||||||
| 109 | cap = 4; executed 4 times by 1 test: cap = 4;Executed by:
| 4 | ||||||
| 110 | - | |||||||
| 111 | if (cap > RSA_MAX_PRIME_NUM)
| 0-26 | ||||||
| 112 | cap = RSA_MAX_PRIME_NUM; never executed: cap = 5; | 0 | ||||||
| 113 | - | |||||||
| 114 | return cap; executed 26 times by 1 test: return cap;Executed by:
| 26 | ||||||
| 115 | } | - | ||||||
| Source code | Switch to Preprocessed file |