| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ec/ec_oct.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||
| 2 | * Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||
| 3 | * Copyright (c) 2002, Oracle and/or its affiliates. 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 <string.h> | - | ||||||
| 12 | - | |||||||
| 13 | #include <openssl/err.h> | - | ||||||
| 14 | #include <openssl/opensslv.h> | - | ||||||
| 15 | - | |||||||
| 16 | #include "ec_lcl.h" | - | ||||||
| 17 | - | |||||||
| 18 | int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point, | - | ||||||
| 19 | const BIGNUM *x, int y_bit, BN_CTX *ctx) | - | ||||||
| 20 | { | - | ||||||
| 21 | if (group->meth->point_set_compressed_coordinates == NULL
| 0-10571 | ||||||
| 22 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {
| 0-10571 | ||||||
| 23 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES, | - | ||||||
| 24 | ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||
| 25 | return 0; never executed: return 0; | 0 | ||||||
| 26 | } | - | ||||||
| 27 | if (!ec_point_is_compat(point, group)) {
| 0-10571 | ||||||
| 28 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES, | - | ||||||
| 29 | EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||
| 30 | return 0; never executed: return 0; | 0 | ||||||
| 31 | } | - | ||||||
| 32 | if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
| 0-10571 | ||||||
| 33 | if (group->meth->field_type == NID_X9_62_prime_field)
| 4526-6045 | ||||||
| 34 | return ec_GFp_simple_set_compressed_coordinates(group, point, x, executed 4526 times by 1 test: return ec_GFp_simple_set_compressed_coordinates(group, point, x, y_bit, ctx);Executed by:
| 4526 | ||||||
| 35 | y_bit, ctx); executed 4526 times by 1 test: return ec_GFp_simple_set_compressed_coordinates(group, point, x, y_bit, ctx);Executed by:
| 4526 | ||||||
| 36 | else | - | ||||||
| 37 | #ifdef OPENSSL_NO_EC2M | - | ||||||
| 38 | { | - | ||||||
| 39 | ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES, | - | ||||||
| 40 | EC_R_GF2M_NOT_SUPPORTED); | - | ||||||
| 41 | return 0; | - | ||||||
| 42 | } | - | ||||||
| 43 | #else | - | ||||||
| 44 | return ec_GF2m_simple_set_compressed_coordinates(group, point, x, executed 6045 times by 1 test: return ec_GF2m_simple_set_compressed_coordinates(group, point, x, y_bit, ctx);Executed by:
| 6045 | ||||||
| 45 | y_bit, ctx); executed 6045 times by 1 test: return ec_GF2m_simple_set_compressed_coordinates(group, point, x, y_bit, ctx);Executed by:
| 6045 | ||||||
| 46 | #endif | - | ||||||
| 47 | } | - | ||||||
| 48 | return group->meth->point_set_compressed_coordinates(group, point, x, never executed: return group->meth->point_set_compressed_coordinates(group, point, x, y_bit, ctx); | 0 | ||||||
| 49 | y_bit, ctx); never executed: return group->meth->point_set_compressed_coordinates(group, point, x, y_bit, ctx); | 0 | ||||||
| 50 | } | - | ||||||
| 51 | - | |||||||
| 52 | #if OPENSSL_API_COMPAT < 0x10200000L | - | ||||||
| 53 | int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, | - | ||||||
| 54 | EC_POINT *point, const BIGNUM *x, | - | ||||||
| 55 | int y_bit, BN_CTX *ctx) | - | ||||||
| 56 | { | - | ||||||
| 57 | return EC_POINT_set_compressed_coordinates(group, point, x, y_bit, ctx); never executed: return EC_POINT_set_compressed_coordinates(group, point, x, y_bit, ctx); | 0 | ||||||
| 58 | } | - | ||||||
| 59 | - | |||||||
| 60 | # ifndef OPENSSL_NO_EC2M | - | ||||||
| 61 | int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, | - | ||||||
| 62 | EC_POINT *point, const BIGNUM *x, | - | ||||||
| 63 | int y_bit, BN_CTX *ctx) | - | ||||||
| 64 | { | - | ||||||
| 65 | return EC_POINT_set_compressed_coordinates(group, point, x, y_bit, ctx); never executed: return EC_POINT_set_compressed_coordinates(group, point, x, y_bit, ctx); | 0 | ||||||
| 66 | } | - | ||||||
| 67 | # endif | - | ||||||
| 68 | #endif | - | ||||||
| 69 | - | |||||||
| 70 | size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point, | - | ||||||
| 71 | point_conversion_form_t form, unsigned char *buf, | - | ||||||
| 72 | size_t len, BN_CTX *ctx) | - | ||||||
| 73 | { | - | ||||||
| 74 | if (group->meth->point2oct == 0
| 0-41855 | ||||||
| 75 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {
| 0-41855 | ||||||
| 76 | ECerr(EC_F_EC_POINT_POINT2OCT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||
| 77 | return 0; never executed: return 0; | 0 | ||||||
| 78 | } | - | ||||||
| 79 | if (!ec_point_is_compat(point, group)) {
| 0-41855 | ||||||
| 80 | ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||
| 81 | return 0; never executed: return 0; | 0 | ||||||
| 82 | } | - | ||||||
| 83 | if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
| 0-41855 | ||||||
| 84 | if (group->meth->field_type == NID_X9_62_prime_field)
| 201-41654 | ||||||
| 85 | return ec_GFp_simple_point2oct(group, point, form, buf, len, ctx); executed 41654 times by 1 test: return ec_GFp_simple_point2oct(group, point, form, buf, len, ctx);Executed by:
| 41654 | ||||||
| 86 | else | - | ||||||
| 87 | #ifdef OPENSSL_NO_EC2M | - | ||||||
| 88 | { | - | ||||||
| 89 | ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_GF2M_NOT_SUPPORTED); | - | ||||||
| 90 | return 0; | - | ||||||
| 91 | } | - | ||||||
| 92 | #else | - | ||||||
| 93 | return ec_GF2m_simple_point2oct(group, point, executed 201 times by 1 test: return ec_GF2m_simple_point2oct(group, point, form, buf, len, ctx);Executed by:
| 201 | ||||||
| 94 | form, buf, len, ctx); executed 201 times by 1 test: return ec_GF2m_simple_point2oct(group, point, form, buf, len, ctx);Executed by:
| 201 | ||||||
| 95 | #endif | - | ||||||
| 96 | } | - | ||||||
| 97 | - | |||||||
| 98 | return group->meth->point2oct(group, point, form, buf, len, ctx); never executed: return group->meth->point2oct(group, point, form, buf, len, ctx); | 0 | ||||||
| 99 | } | - | ||||||
| 100 | - | |||||||
| 101 | int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point, | - | ||||||
| 102 | const unsigned char *buf, size_t len, BN_CTX *ctx) | - | ||||||
| 103 | { | - | ||||||
| 104 | if (group->meth->oct2point == 0
| 0-34424 | ||||||
| 105 | && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {
| 0-34424 | ||||||
| 106 | ECerr(EC_F_EC_POINT_OCT2POINT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | - | ||||||
| 107 | return 0; never executed: return 0; | 0 | ||||||
| 108 | } | - | ||||||
| 109 | if (!ec_point_is_compat(point, group)) {
| 0-34424 | ||||||
| 110 | ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_INCOMPATIBLE_OBJECTS); | - | ||||||
| 111 | return 0; never executed: return 0; | 0 | ||||||
| 112 | } | - | ||||||
| 113 | if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
| 0-34424 | ||||||
| 114 | if (group->meth->field_type == NID_X9_62_prime_field)
| 9269-25155 | ||||||
| 115 | return ec_GFp_simple_oct2point(group, point, buf, len, ctx); executed 25155 times by 1 test: return ec_GFp_simple_oct2point(group, point, buf, len, ctx);Executed by:
| 25155 | ||||||
| 116 | else | - | ||||||
| 117 | #ifdef OPENSSL_NO_EC2M | - | ||||||
| 118 | { | - | ||||||
| 119 | ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_GF2M_NOT_SUPPORTED); | - | ||||||
| 120 | return 0; | - | ||||||
| 121 | } | - | ||||||
| 122 | #else | - | ||||||
| 123 | return ec_GF2m_simple_oct2point(group, point, buf, len, ctx); executed 9269 times by 1 test: return ec_GF2m_simple_oct2point(group, point, buf, len, ctx);Executed by:
| 9269 | ||||||
| 124 | #endif | - | ||||||
| 125 | } | - | ||||||
| 126 | return group->meth->oct2point(group, point, buf, len, ctx); never executed: return group->meth->oct2point(group, point, buf, len, ctx); | 0 | ||||||
| 127 | } | - | ||||||
| 128 | - | |||||||
| 129 | size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point, | - | ||||||
| 130 | point_conversion_form_t form, | - | ||||||
| 131 | unsigned char **pbuf, BN_CTX *ctx) | - | ||||||
| 132 | { | - | ||||||
| 133 | size_t len; | - | ||||||
| 134 | unsigned char *buf; | - | ||||||
| 135 | - | |||||||
| 136 | len = EC_POINT_point2oct(group, point, form, NULL, 0, NULL); | - | ||||||
| 137 | if (len == 0)
| 2-1285 | ||||||
| 138 | return 0; executed 2 times by 1 test: return 0;Executed by:
| 2 | ||||||
| 139 | if ((buf = OPENSSL_malloc(len)) == NULL) {
| 0-1285 | ||||||
| 140 | ECerr(EC_F_EC_POINT_POINT2BUF, ERR_R_MALLOC_FAILURE); | - | ||||||
| 141 | return 0; never executed: return 0; | 0 | ||||||
| 142 | } | - | ||||||
| 143 | len = EC_POINT_point2oct(group, point, form, buf, len, ctx); | - | ||||||
| 144 | if (len == 0) {
| 0-1285 | ||||||
| 145 | OPENSSL_free(buf); | - | ||||||
| 146 | return 0; never executed: return 0; | 0 | ||||||
| 147 | } | - | ||||||
| 148 | *pbuf = buf; | - | ||||||
| 149 | return len; executed 1285 times by 1 test: return len;Executed by:
| 1285 | ||||||
| 150 | } | - | ||||||
| Source code | Switch to Preprocessed file |