summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormiod <>2014-11-18 05:30:07 +0000
committermiod <>2014-11-18 05:30:07 +0000
commit104370d7faecebe3fdc1f410191dc8dc656e45c9 (patch)
tree9f19205b8efc1d05ff4702a892fd7e8d9bde653b /src
parentd3f6d8aa023c54de8a140fc3586b8e318276e6b2 (diff)
downloadopenbsd-104370d7faecebe3fdc1f410191dc8dc656e45c9.tar.gz
openbsd-104370d7faecebe3fdc1f410191dc8dc656e45c9.tar.bz2
openbsd-104370d7faecebe3fdc1f410191dc8dc656e45c9.zip
More missing error checks I forgot to commit last week, part of the large
cleanup diff.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/evp/e_gost2814789.c35
-rw-r--r--src/lib/libssl/src/crypto/evp/e_gost2814789.c35
2 files changed, 46 insertions, 24 deletions
diff --git a/src/lib/libcrypto/evp/e_gost2814789.c b/src/lib/libcrypto/evp/e_gost2814789.c
index e1437b18d8..e2235a64b5 100644
--- a/src/lib/libcrypto/evp/e_gost2814789.c
+++ b/src/lib/libcrypto/evp/e_gost2814789.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_gost2814789.c,v 1.2 2014/11/09 23:06:50 miod Exp $ */ 1/* $OpenBSD: e_gost2814789.c,v 1.3 2014/11/18 05:30:07 miod Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -87,27 +87,31 @@ gost2814789_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
87 } 87 }
88} 88}
89 89
90static int gost2814789_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 90static int
91 const unsigned char *iv, int enc) 91gost2814789_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
92 const unsigned char *iv, int enc)
92{ 93{
93 EVP_GOST2814789_CTX *c = ctx->cipher_data; 94 EVP_GOST2814789_CTX *c = ctx->cipher_data;
94 95
95 return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8); 96 return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8);
96} 97}
97 98
98int gost2814789_set_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params) 99int
100gost2814789_set_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
99{ 101{
100 int len = 0; 102 int len = 0;
101 unsigned char *buf = NULL; 103 unsigned char *buf = NULL;
102 unsigned char *p = NULL; 104 unsigned char *p = NULL;
103 EVP_GOST2814789_CTX *c = ctx->cipher_data; 105 EVP_GOST2814789_CTX *c = ctx->cipher_data;
104 GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new();
105 ASN1_OCTET_STRING *os = NULL; 106 ASN1_OCTET_STRING *os = NULL;
106 if (!gcp) { 107 GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new();
107 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE); 108
109 if (gcp == NULL) {
110 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS,
111 ERR_R_MALLOC_FAILURE);
108 return 0; 112 return 0;
109 } 113 }
110 if (!ASN1_OCTET_STRING_set(gcp->iv, ctx->iv, ctx->cipher->iv_len)) { 114 if (ASN1_OCTET_STRING_set(gcp->iv, ctx->iv, ctx->cipher->iv_len) == 0) {
111 GOST_CIPHER_PARAMS_free(gcp); 115 GOST_CIPHER_PARAMS_free(gcp);
112 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB); 116 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB);
113 return 0; 117 return 0;
@@ -117,17 +121,24 @@ int gost2814789_set_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params)
117 121
118 len = i2d_GOST_CIPHER_PARAMS(gcp, NULL); 122 len = i2d_GOST_CIPHER_PARAMS(gcp, NULL);
119 p = buf = malloc(len); 123 p = buf = malloc(len);
120 if (!buf) { 124 if (buf == NULL) {
121 GOST_CIPHER_PARAMS_free(gcp); 125 GOST_CIPHER_PARAMS_free(gcp);
122 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE); 126 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS,
127 ERR_R_MALLOC_FAILURE);
123 return 0; 128 return 0;
124 } 129 }
125 i2d_GOST_CIPHER_PARAMS(gcp, &p); 130 i2d_GOST_CIPHER_PARAMS(gcp, &p);
126 GOST_CIPHER_PARAMS_free(gcp); 131 GOST_CIPHER_PARAMS_free(gcp);
127 132
128 os = ASN1_OCTET_STRING_new(); 133 os = ASN1_OCTET_STRING_new();
129 134 if (os == NULL) {
130 if (!os || !ASN1_OCTET_STRING_set(os, buf, len)) { 135 free(buf);
136 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS,
137 ERR_R_MALLOC_FAILURE);
138 return 0;
139 }
140 if (ASN1_OCTET_STRING_set(os, buf, len) == 0) {
141 ASN1_OCTET_STRING_free(os);
131 free(buf); 142 free(buf);
132 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB); 143 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB);
133 return 0; 144 return 0;
diff --git a/src/lib/libssl/src/crypto/evp/e_gost2814789.c b/src/lib/libssl/src/crypto/evp/e_gost2814789.c
index e1437b18d8..e2235a64b5 100644
--- a/src/lib/libssl/src/crypto/evp/e_gost2814789.c
+++ b/src/lib/libssl/src/crypto/evp/e_gost2814789.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_gost2814789.c,v 1.2 2014/11/09 23:06:50 miod Exp $ */ 1/* $OpenBSD: e_gost2814789.c,v 1.3 2014/11/18 05:30:07 miod Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -87,27 +87,31 @@ gost2814789_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
87 } 87 }
88} 88}
89 89
90static int gost2814789_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 90static int
91 const unsigned char *iv, int enc) 91gost2814789_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
92 const unsigned char *iv, int enc)
92{ 93{
93 EVP_GOST2814789_CTX *c = ctx->cipher_data; 94 EVP_GOST2814789_CTX *c = ctx->cipher_data;
94 95
95 return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8); 96 return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8);
96} 97}
97 98
98int gost2814789_set_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params) 99int
100gost2814789_set_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
99{ 101{
100 int len = 0; 102 int len = 0;
101 unsigned char *buf = NULL; 103 unsigned char *buf = NULL;
102 unsigned char *p = NULL; 104 unsigned char *p = NULL;
103 EVP_GOST2814789_CTX *c = ctx->cipher_data; 105 EVP_GOST2814789_CTX *c = ctx->cipher_data;
104 GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new();
105 ASN1_OCTET_STRING *os = NULL; 106 ASN1_OCTET_STRING *os = NULL;
106 if (!gcp) { 107 GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new();
107 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE); 108
109 if (gcp == NULL) {
110 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS,
111 ERR_R_MALLOC_FAILURE);
108 return 0; 112 return 0;
109 } 113 }
110 if (!ASN1_OCTET_STRING_set(gcp->iv, ctx->iv, ctx->cipher->iv_len)) { 114 if (ASN1_OCTET_STRING_set(gcp->iv, ctx->iv, ctx->cipher->iv_len) == 0) {
111 GOST_CIPHER_PARAMS_free(gcp); 115 GOST_CIPHER_PARAMS_free(gcp);
112 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB); 116 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB);
113 return 0; 117 return 0;
@@ -117,17 +121,24 @@ int gost2814789_set_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params)
117 121
118 len = i2d_GOST_CIPHER_PARAMS(gcp, NULL); 122 len = i2d_GOST_CIPHER_PARAMS(gcp, NULL);
119 p = buf = malloc(len); 123 p = buf = malloc(len);
120 if (!buf) { 124 if (buf == NULL) {
121 GOST_CIPHER_PARAMS_free(gcp); 125 GOST_CIPHER_PARAMS_free(gcp);
122 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_MALLOC_FAILURE); 126 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS,
127 ERR_R_MALLOC_FAILURE);
123 return 0; 128 return 0;
124 } 129 }
125 i2d_GOST_CIPHER_PARAMS(gcp, &p); 130 i2d_GOST_CIPHER_PARAMS(gcp, &p);
126 GOST_CIPHER_PARAMS_free(gcp); 131 GOST_CIPHER_PARAMS_free(gcp);
127 132
128 os = ASN1_OCTET_STRING_new(); 133 os = ASN1_OCTET_STRING_new();
129 134 if (os == NULL) {
130 if (!os || !ASN1_OCTET_STRING_set(os, buf, len)) { 135 free(buf);
136 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS,
137 ERR_R_MALLOC_FAILURE);
138 return 0;
139 }
140 if (ASN1_OCTET_STRING_set(os, buf, len) == 0) {
141 ASN1_OCTET_STRING_free(os);
131 free(buf); 142 free(buf);
132 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB); 143 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB);
133 return 0; 144 return 0;