| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/dh/dh_asn1.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||||||||
| 2 | * Copyright 2000-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 "internal/cryptlib.h" | - | ||||||||||||||||||
| 12 | #include <openssl/bn.h> | - | ||||||||||||||||||
| 13 | #include "dh_locl.h" | - | ||||||||||||||||||
| 14 | #include <openssl/objects.h> | - | ||||||||||||||||||
| 15 | #include <openssl/asn1t.h> | - | ||||||||||||||||||
| 16 | - | |||||||||||||||||||
| 17 | /* Override the default free and new methods */ | - | ||||||||||||||||||
| 18 | static int dh_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | - | ||||||||||||||||||
| 19 | void *exarg) | - | ||||||||||||||||||
| 20 | { | - | ||||||||||||||||||
| 21 | if (operation == ASN1_OP_NEW_PRE) {
| 5953-12104 | ||||||||||||||||||
| 22 | *pval = (ASN1_VALUE *)DH_new(); | - | ||||||||||||||||||
| 23 | if (*pval != NULL)
| 0-5953 | ||||||||||||||||||
| 24 | return 2; executed 5953 times by 1 test: return 2;Executed by:
| 5953 | ||||||||||||||||||
| 25 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 26 | } else if (operation == ASN1_OP_FREE_PRE) {
| 5909-6195 | ||||||||||||||||||
| 27 | DH_free((DH *)*pval); | - | ||||||||||||||||||
| 28 | *pval = NULL; | - | ||||||||||||||||||
| 29 | return 2; executed 5909 times by 1 test: return 2;Executed by:
| 5909 | ||||||||||||||||||
| 30 | } | - | ||||||||||||||||||
| 31 | return 1; executed 6195 times by 1 test: return 1;Executed by:
| 6195 | ||||||||||||||||||
| 32 | } | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | ASN1_SEQUENCE_cb(DHparams, dh_cb) = { | - | ||||||||||||||||||
| 35 | ASN1_SIMPLE(DH, p, BIGNUM), | - | ||||||||||||||||||
| 36 | ASN1_SIMPLE(DH, g, BIGNUM), | - | ||||||||||||||||||
| 37 | ASN1_OPT_EMBED(DH, length, ZINT32), | - | ||||||||||||||||||
| 38 | } ASN1_SEQUENCE_END_cb(DH, DHparams) | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DH, DHparams, DHparams) executed 3352 times by 1 test: return (DH *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(DHparams_it)));Executed by:
executed 22 times by 1 test: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(DHparams_it)));Executed by:
| 22-3352 | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | /* | - | ||||||||||||||||||
| 43 | * Internal only structures for handling X9.42 DH: this gets translated to or | - | ||||||||||||||||||
| 44 | * from a DH structure straight away. | - | ||||||||||||||||||
| 45 | */ | - | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | typedef struct { | - | ||||||||||||||||||
| 48 | ASN1_BIT_STRING *seed; | - | ||||||||||||||||||
| 49 | BIGNUM *counter; | - | ||||||||||||||||||
| 50 | } int_dhvparams; | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | typedef struct { | - | ||||||||||||||||||
| 53 | BIGNUM *p; | - | ||||||||||||||||||
| 54 | BIGNUM *q; | - | ||||||||||||||||||
| 55 | BIGNUM *g; | - | ||||||||||||||||||
| 56 | BIGNUM *j; | - | ||||||||||||||||||
| 57 | int_dhvparams *vparams; | - | ||||||||||||||||||
| 58 | } int_dhx942_dh; | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | ASN1_SEQUENCE(DHvparams) = { | - | ||||||||||||||||||
| 61 | ASN1_SIMPLE(int_dhvparams, seed, ASN1_BIT_STRING), | - | ||||||||||||||||||
| 62 | ASN1_SIMPLE(int_dhvparams, counter, BIGNUM) | - | ||||||||||||||||||
| 63 | } static_ASN1_SEQUENCE_END_name(int_dhvparams, DHvparams) | - | ||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | ASN1_SEQUENCE(DHxparams) = { | - | ||||||||||||||||||
| 66 | ASN1_SIMPLE(int_dhx942_dh, p, BIGNUM), | - | ||||||||||||||||||
| 67 | ASN1_SIMPLE(int_dhx942_dh, g, BIGNUM), | - | ||||||||||||||||||
| 68 | ASN1_SIMPLE(int_dhx942_dh, q, BIGNUM), | - | ||||||||||||||||||
| 69 | ASN1_OPT(int_dhx942_dh, j, BIGNUM), | - | ||||||||||||||||||
| 70 | ASN1_OPT(int_dhx942_dh, vparams, DHvparams), | - | ||||||||||||||||||
| 71 | } static_ASN1_SEQUENCE_END_name(int_dhx942_dh, DHxparams) | - | ||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | int_dhx942_dh *d2i_int_dhx(int_dhx942_dh **a, | - | ||||||||||||||||||
| 74 | const unsigned char **pp, long length); | - | ||||||||||||||||||
| 75 | int i2d_int_dhx(const int_dhx942_dh *a, unsigned char **pp); | - | ||||||||||||||||||
| 76 | - | |||||||||||||||||||
| 77 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(int_dhx942_dh, DHxparams, int_dhx) executed 5506 times by 1 test: return (int_dhx942_dh *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(DHxparams_it)));Executed by:
executed 31 times by 1 test: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(DHxparams_it)));Executed by:
| 31-5506 | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | /* Application public function: read in X9.42 DH parameters into DH structure */ | - | ||||||||||||||||||
| 80 | - | |||||||||||||||||||
| 81 | DH *d2i_DHxparams(DH **a, const unsigned char **pp, long length) | - | ||||||||||||||||||
| 82 | { | - | ||||||||||||||||||
| 83 | int_dhx942_dh *dhx = NULL; | - | ||||||||||||||||||
| 84 | DH *dh = NULL; | - | ||||||||||||||||||
| 85 | dh = DH_new(); | - | ||||||||||||||||||
| 86 | if (dh == NULL)
| 0-5506 | ||||||||||||||||||
| 87 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 88 | dhx = d2i_int_dhx(NULL, pp, length); | - | ||||||||||||||||||
| 89 | if (dhx == NULL) {
| 331-5175 | ||||||||||||||||||
| 90 | DH_free(dh); | - | ||||||||||||||||||
| 91 | return NULL; executed 5175 times by 1 test: return ((void *)0) ;Executed by:
| 5175 | ||||||||||||||||||
| 92 | } | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | if (a) {
| 0-331 | ||||||||||||||||||
| 95 | DH_free(*a); | - | ||||||||||||||||||
| 96 | *a = dh; | - | ||||||||||||||||||
| 97 | } never executed: end of block | 0 | ||||||||||||||||||
| 98 | - | |||||||||||||||||||
| 99 | dh->p = dhx->p; | - | ||||||||||||||||||
| 100 | dh->q = dhx->q; | - | ||||||||||||||||||
| 101 | dh->g = dhx->g; | - | ||||||||||||||||||
| 102 | dh->j = dhx->j; | - | ||||||||||||||||||
| 103 | - | |||||||||||||||||||
| 104 | if (dhx->vparams) {
| 15-316 | ||||||||||||||||||
| 105 | dh->seed = dhx->vparams->seed->data; | - | ||||||||||||||||||
| 106 | dh->seedlen = dhx->vparams->seed->length; | - | ||||||||||||||||||
| 107 | dh->counter = dhx->vparams->counter; | - | ||||||||||||||||||
| 108 | dhx->vparams->seed->data = NULL; | - | ||||||||||||||||||
| 109 | ASN1_BIT_STRING_free(dhx->vparams->seed); | - | ||||||||||||||||||
| 110 | OPENSSL_free(dhx->vparams); | - | ||||||||||||||||||
| 111 | dhx->vparams = NULL; | - | ||||||||||||||||||
| 112 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | OPENSSL_free(dhx); | - | ||||||||||||||||||
| 115 | return dh; executed 331 times by 1 test: return dh;Executed by:
| 331 | ||||||||||||||||||
| 116 | } | - | ||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | int i2d_DHxparams(const DH *dh, unsigned char **pp) | - | ||||||||||||||||||
| 119 | { | - | ||||||||||||||||||
| 120 | int_dhx942_dh dhx; | - | ||||||||||||||||||
| 121 | int_dhvparams dhv; | - | ||||||||||||||||||
| 122 | ASN1_BIT_STRING bs; | - | ||||||||||||||||||
| 123 | dhx.p = dh->p; | - | ||||||||||||||||||
| 124 | dhx.g = dh->g; | - | ||||||||||||||||||
| 125 | dhx.q = dh->q; | - | ||||||||||||||||||
| 126 | dhx.j = dh->j; | - | ||||||||||||||||||
| 127 | if (dh->counter && dh->seed && dh->seedlen > 0) {
| 0-16 | ||||||||||||||||||
| 128 | bs.flags = ASN1_STRING_FLAG_BITS_LEFT; | - | ||||||||||||||||||
| 129 | bs.data = dh->seed; | - | ||||||||||||||||||
| 130 | bs.length = dh->seedlen; | - | ||||||||||||||||||
| 131 | dhv.seed = &bs; | - | ||||||||||||||||||
| 132 | dhv.counter = dh->counter; | - | ||||||||||||||||||
| 133 | dhx.vparams = &dhv; | - | ||||||||||||||||||
| 134 | } else executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||
| 135 | dhx.vparams = NULL; executed 18 times by 1 test: dhx.vparams = ((void *)0) ;Executed by:
| 18 | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | return i2d_int_dhx(&dhx, pp); executed 31 times by 1 test: return i2d_int_dhx(&dhx, pp);Executed by:
| 31 | ||||||||||||||||||
| 138 | } | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |