summaryrefslogtreecommitdiff
path: root/src/lib/libssl/src/crypto/ec/ec_check.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libssl/src/crypto/ec/ec_check.c58
1 files changed, 26 insertions, 32 deletions
diff --git a/src/lib/libssl/src/crypto/ec/ec_check.c b/src/lib/libssl/src/crypto/ec/ec_check.c
index 0e316b4b3f..8f533d5ff8 100644
--- a/src/lib/libssl/src/crypto/ec/ec_check.c
+++ b/src/lib/libssl/src/crypto/ec/ec_check.c
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -56,60 +56,54 @@
56#include "ec_lcl.h" 56#include "ec_lcl.h"
57#include <openssl/err.h> 57#include <openssl/err.h>
58 58
59int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx) 59int
60 { 60EC_GROUP_check(const EC_GROUP * group, BN_CTX * ctx)
61{
61 int ret = 0; 62 int ret = 0;
62 BIGNUM *order; 63 BIGNUM *order;
63 BN_CTX *new_ctx = NULL; 64 BN_CTX *new_ctx = NULL;
64 EC_POINT *point = NULL; 65 EC_POINT *point = NULL;
65 66
66 if (ctx == NULL) 67 if (ctx == NULL) {
67 {
68 ctx = new_ctx = BN_CTX_new(); 68 ctx = new_ctx = BN_CTX_new();
69 if (ctx == NULL) 69 if (ctx == NULL) {
70 {
71 ECerr(EC_F_EC_GROUP_CHECK, ERR_R_MALLOC_FAILURE); 70 ECerr(EC_F_EC_GROUP_CHECK, ERR_R_MALLOC_FAILURE);
72 goto err; 71 goto err;
73 }
74 } 72 }
73 }
75 BN_CTX_start(ctx); 74 BN_CTX_start(ctx);
76 if ((order = BN_CTX_get(ctx)) == NULL) goto err; 75 if ((order = BN_CTX_get(ctx)) == NULL)
76 goto err;
77 77
78 /* check the discriminant */ 78 /* check the discriminant */
79 if (!EC_GROUP_check_discriminant(group, ctx)) 79 if (!EC_GROUP_check_discriminant(group, ctx)) {
80 {
81 ECerr(EC_F_EC_GROUP_CHECK, EC_R_DISCRIMINANT_IS_ZERO); 80 ECerr(EC_F_EC_GROUP_CHECK, EC_R_DISCRIMINANT_IS_ZERO);
82 goto err; 81 goto err;
83 } 82 }
84
85 /* check the generator */ 83 /* check the generator */
86 if (group->generator == NULL) 84 if (group->generator == NULL) {
87 {
88 ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_GENERATOR); 85 ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_GENERATOR);
89 goto err; 86 goto err;
90 } 87 }
91 if (!EC_POINT_is_on_curve(group, group->generator, ctx)) 88 if (!EC_POINT_is_on_curve(group, group->generator, ctx)) {
92 {
93 ECerr(EC_F_EC_GROUP_CHECK, EC_R_POINT_IS_NOT_ON_CURVE); 89 ECerr(EC_F_EC_GROUP_CHECK, EC_R_POINT_IS_NOT_ON_CURVE);
94 goto err; 90 goto err;
95 } 91 }
96
97 /* check the order of the generator */ 92 /* check the order of the generator */
98 if ((point = EC_POINT_new(group)) == NULL) goto err; 93 if ((point = EC_POINT_new(group)) == NULL)
99 if (!EC_GROUP_get_order(group, order, ctx)) goto err; 94 goto err;
100 if (BN_is_zero(order)) 95 if (!EC_GROUP_get_order(group, order, ctx))
101 { 96 goto err;
97 if (BN_is_zero(order)) {
102 ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_ORDER); 98 ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_ORDER);
103 goto err; 99 goto err;
104 } 100 }
105 101 if (!EC_POINT_mul(group, point, order, NULL, NULL, ctx))
106 if (!EC_POINT_mul(group, point, order, NULL, NULL, ctx)) goto err; 102 goto err;
107 if (!EC_POINT_is_at_infinity(group, point)) 103 if (!EC_POINT_is_at_infinity(group, point)) {
108 {
109 ECerr(EC_F_EC_GROUP_CHECK, EC_R_INVALID_GROUP_ORDER); 104 ECerr(EC_F_EC_GROUP_CHECK, EC_R_INVALID_GROUP_ORDER);
110 goto err; 105 goto err;
111 } 106 }
112
113 ret = 1; 107 ret = 1;
114 108
115err: 109err:
@@ -120,4 +114,4 @@ err:
120 if (point) 114 if (point)
121 EC_POINT_free(point); 115 EC_POINT_free(point);
122 return ret; 116 return ret;
123 } 117}