summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/e_gost2814789.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/e_gost2814789.c')
-rw-r--r--src/lib/libcrypto/evp/e_gost2814789.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/lib/libcrypto/evp/e_gost2814789.c b/src/lib/libcrypto/evp/e_gost2814789.c
index 678c7af09d..e1437b18d8 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.1 2014/11/09 19:17:13 miod Exp $ */ 1/* $OpenBSD: e_gost2814789.c,v 1.2 2014/11/09 23:06:50 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
@@ -63,13 +63,14 @@ typedef struct {
63 int param_nid; 63 int param_nid;
64} EVP_GOST2814789_CTX; 64} EVP_GOST2814789_CTX;
65 65
66static int gost2814789_ctl(EVP_CIPHER_CTX *ctx,int type,int arg,void *ptr) 66static int
67gost2814789_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
67{ 68{
68 EVP_GOST2814789_CTX *c = ctx->cipher_data; 69 EVP_GOST2814789_CTX *c = ctx->cipher_data;
69 70
70 switch (type) { 71 switch (type) {
71 case EVP_CTRL_PBE_PRF_NID: 72 case EVP_CTRL_PBE_PRF_NID:
72 if (ptr) { 73 if (ptr != NULL) {
73 *((int *)ptr) = NID_id_HMACGostR3411_94; 74 *((int *)ptr) = NID_id_HMACGostR3411_94;
74 return 1; 75 return 1;
75 } else { 76 } else {
@@ -137,7 +138,8 @@ int gost2814789_set_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params)
137 return 1; 138 return 1;
138} 139}
139 140
140int gost2814789_get_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params) 141int
142gost2814789_get_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
141{ 143{
142 int ret = -1; 144 int ret = -1;
143 int len; 145 int len;
@@ -145,20 +147,19 @@ int gost2814789_get_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params)
145 EVP_GOST2814789_CTX *c = ctx->cipher_data; 147 EVP_GOST2814789_CTX *c = ctx->cipher_data;
146 unsigned char *p; 148 unsigned char *p;
147 149
148 if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) { 150 if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE)
149 return ret; 151 return ret;
150 }
151 152
152 p = params->value.sequence->data; 153 p = params->value.sequence->data;
153 154
154 gcp = d2i_GOST_CIPHER_PARAMS(NULL, (const unsigned char **)&p, 155 gcp = d2i_GOST_CIPHER_PARAMS(NULL, (const unsigned char **)&p,
155 params->value.sequence->length); 156 params->value.sequence->length);
156 157
157 len = gcp->iv->length; 158 len = gcp->iv->length;
158 if (len != ctx->cipher->iv_len) { 159 if (len != ctx->cipher->iv_len) {
159 GOST_CIPHER_PARAMS_free(gcp); 160 GOST_CIPHER_PARAMS_free(gcp);
160 GOSTerr(GOST_F_GOST89_GET_ASN1_PARAMETERS, 161 GOSTerr(GOST_F_GOST89_GET_ASN1_PARAMETERS,
161 GOST_R_INVALID_IV_LENGTH); 162 GOST_R_INVALID_IV_LENGTH);
162 return -1; 163 return -1;
163 } 164 }
164 165
@@ -179,22 +180,23 @@ int gost2814789_get_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params)
179BLOCK_CIPHER_func_ecb(gost2814789, Gost2814789, EVP_GOST2814789_CTX, ks) 180BLOCK_CIPHER_func_ecb(gost2814789, Gost2814789, EVP_GOST2814789_CTX, ks)
180BLOCK_CIPHER_func_cfb(gost2814789, Gost2814789, 64, EVP_GOST2814789_CTX, ks) 181BLOCK_CIPHER_func_cfb(gost2814789, Gost2814789, 64, EVP_GOST2814789_CTX, ks)
181 182
182static int gost2814789_cnt_cipher(EVP_CIPHER_CTX * ctx, unsigned char *out, 183static int
183 const unsigned char *in, size_t inl) 184gost2814789_cnt_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
185 const unsigned char *in, size_t inl)
184{ 186{
185 EVP_GOST2814789_CTX *c = ctx->cipher_data; 187 EVP_GOST2814789_CTX *c = ctx->cipher_data;
186 188
187 while (inl >= EVP_MAXCHUNK) { 189 while (inl >= EVP_MAXCHUNK) {
188 Gost2814789_cnt_encrypt(in, out, (long)EVP_MAXCHUNK, &c->ks, 190 Gost2814789_cnt_encrypt(in, out, (long)EVP_MAXCHUNK, &c->ks,
189 ctx->iv, ctx->buf, &ctx->num); 191 ctx->iv, ctx->buf, &ctx->num);
190 inl -= EVP_MAXCHUNK; 192 inl -= EVP_MAXCHUNK;
191 in += EVP_MAXCHUNK; 193 in += EVP_MAXCHUNK;
192 out += EVP_MAXCHUNK; 194 out += EVP_MAXCHUNK;
193 } 195 }
194 196
195 if (inl) 197 if (inl)
196 Gost2814789_cnt_encrypt(in, out, inl, &c->ks, 198 Gost2814789_cnt_encrypt(in, out, inl, &c->ks, ctx->iv, ctx->buf,
197 ctx->iv, ctx->buf, &ctx->num); 199 &ctx->num);
198 return 1; 200 return 1;
199} 201}
200 202