| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/ec_print.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||
| 2 | * Copyright 2002-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 <openssl/crypto.h> | - | ||||||
| 11 | #include <openssl/err.h> | - | ||||||
| 12 | #include "ec_lcl.h" | - | ||||||
| 13 | - | |||||||
| 14 | BIGNUM *EC_POINT_point2bn(const EC_GROUP *group, | - | ||||||
| 15 | const EC_POINT *point, | - | ||||||
| 16 | point_conversion_form_t form, | - | ||||||
| 17 | BIGNUM *ret, BN_CTX *ctx) | - | ||||||
| 18 | { | - | ||||||
| 19 | size_t buf_len = 0; | - | ||||||
| 20 | unsigned char *buf; | - | ||||||
| 21 | - | |||||||
| 22 | buf_len = EC_POINT_point2buf(group, point, form, &buf, ctx); | - | ||||||
| 23 | - | |||||||
| 24 | if (buf_len == 0)
| 0-45 | ||||||
| 25 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 26 | - | |||||||
| 27 | ret = BN_bin2bn(buf, buf_len, ret); | - | ||||||
| 28 | - | |||||||
| 29 | OPENSSL_free(buf); | - | ||||||
| 30 | - | |||||||
| 31 | return ret; executed 45 times by 1 test: return ret;Executed by:
| 45 | ||||||
| 32 | } | - | ||||||
| 33 | - | |||||||
| 34 | EC_POINT *EC_POINT_bn2point(const EC_GROUP *group, | - | ||||||
| 35 | const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx) | - | ||||||
| 36 | { | - | ||||||
| 37 | size_t buf_len = 0; | - | ||||||
| 38 | unsigned char *buf; | - | ||||||
| 39 | EC_POINT *ret; | - | ||||||
| 40 | - | |||||||
| 41 | if ((buf_len = BN_num_bytes(bn)) == 0)
| 0 | ||||||
| 42 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 43 | if ((buf = OPENSSL_malloc(buf_len)) == NULL) {
| 0 | ||||||
| 44 | ECerr(EC_F_EC_POINT_BN2POINT, ERR_R_MALLOC_FAILURE); | - | ||||||
| 45 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 46 | } | - | ||||||
| 47 | - | |||||||
| 48 | if (!BN_bn2bin(bn, buf)) {
| 0 | ||||||
| 49 | OPENSSL_free(buf); | - | ||||||
| 50 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 51 | } | - | ||||||
| 52 | - | |||||||
| 53 | if (point == NULL) {
| 0 | ||||||
| 54 | if ((ret = EC_POINT_new(group)) == NULL) {
| 0 | ||||||
| 55 | OPENSSL_free(buf); | - | ||||||
| 56 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 57 | } | - | ||||||
| 58 | } else never executed: end of block | 0 | ||||||
| 59 | ret = point; never executed: ret = point; | 0 | ||||||
| 60 | - | |||||||
| 61 | if (!EC_POINT_oct2point(group, ret, buf, buf_len, ctx)) {
| 0 | ||||||
| 62 | if (ret != point)
| 0 | ||||||
| 63 | EC_POINT_clear_free(ret); never executed: EC_POINT_clear_free(ret); | 0 | ||||||
| 64 | OPENSSL_free(buf); | - | ||||||
| 65 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 66 | } | - | ||||||
| 67 | - | |||||||
| 68 | OPENSSL_free(buf); | - | ||||||
| 69 | return ret; never executed: return ret; | 0 | ||||||
| 70 | } | - | ||||||
| 71 | - | |||||||
| 72 | static const char *HEX_DIGITS = "0123456789ABCDEF"; | - | ||||||
| 73 | - | |||||||
| 74 | /* the return value must be freed (using OPENSSL_free()) */ | - | ||||||
| 75 | char *EC_POINT_point2hex(const EC_GROUP *group, | - | ||||||
| 76 | const EC_POINT *point, | - | ||||||
| 77 | point_conversion_form_t form, BN_CTX *ctx) | - | ||||||
| 78 | { | - | ||||||
| 79 | char *ret, *p; | - | ||||||
| 80 | size_t buf_len = 0, i; | - | ||||||
| 81 | unsigned char *buf = NULL, *pbuf; | - | ||||||
| 82 | - | |||||||
| 83 | buf_len = EC_POINT_point2buf(group, point, form, &buf, ctx); | - | ||||||
| 84 | - | |||||||
| 85 | if (buf_len == 0)
| 0 | ||||||
| 86 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 87 | - | |||||||
| 88 | ret = OPENSSL_malloc(buf_len * 2 + 2); | - | ||||||
| 89 | if (ret == NULL) {
| 0 | ||||||
| 90 | OPENSSL_free(buf); | - | ||||||
| 91 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 92 | } | - | ||||||
| 93 | p = ret; | - | ||||||
| 94 | pbuf = buf; | - | ||||||
| 95 | for (i = buf_len; i > 0; i--) {
| 0 | ||||||
| 96 | int v = (int)*(pbuf++); | - | ||||||
| 97 | *(p++) = HEX_DIGITS[v >> 4]; | - | ||||||
| 98 | *(p++) = HEX_DIGITS[v & 0x0F]; | - | ||||||
| 99 | } never executed: end of block | 0 | ||||||
| 100 | *p = '\0'; | - | ||||||
| 101 | - | |||||||
| 102 | OPENSSL_free(buf); | - | ||||||
| 103 | - | |||||||
| 104 | return ret; never executed: return ret; | 0 | ||||||
| 105 | } | - | ||||||
| 106 | - | |||||||
| 107 | EC_POINT *EC_POINT_hex2point(const EC_GROUP *group, | - | ||||||
| 108 | const char *buf, EC_POINT *point, BN_CTX *ctx) | - | ||||||
| 109 | { | - | ||||||
| 110 | EC_POINT *ret = NULL; | - | ||||||
| 111 | BIGNUM *tmp_bn = NULL; | - | ||||||
| 112 | - | |||||||
| 113 | if (!BN_hex2bn(&tmp_bn, buf))
| 0 | ||||||
| 114 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||
| 115 | - | |||||||
| 116 | ret = EC_POINT_bn2point(group, tmp_bn, point, ctx); | - | ||||||
| 117 | - | |||||||
| 118 | BN_clear_free(tmp_bn); | - | ||||||
| 119 | - | |||||||
| 120 | return ret; never executed: return ret; | 0 | ||||||
| 121 | } | - | ||||||
| Source code | Switch to Preprocessed file |