15 const unsigned char *iv,
int enc);
17 const unsigned char *iv,
int enc);
19 static int gost_cipher_do_cfb(
EVP_CIPHER_CTX *ctx,
unsigned char *out,
20 const unsigned char *in,
size_t inl);
22 static int gost_cipher_do_cnt(
EVP_CIPHER_CTX *ctx,
unsigned char *out,
23 const unsigned char *in,
size_t inl);
44 gost89_set_asn1_parameters,
45 gost89_get_asn1_parameters,
62 gost89_set_asn1_parameters,
63 gost89_get_asn1_parameters,
70 static int gost_imit_init_cpa(
EVP_MD_CTX *ctx);
74 static int gost_imit_final(
EVP_MD_CTX *ctx,
unsigned char *md);
129 if (!params || !strlen(params))
130 return &gost_cipher_list[1];
133 if (nid == NID_undef)
144 for (param=gost_cipher_list;param->
sblock!=NULL && param->
nid!=
nid;
159 if (!param)
return 0;
170 const unsigned char *iv,
int enc,
int paramNID,
int mode)
175 if (!gost_cipher_set_param(c,paramNID))
return 0;
184 static int gost_cipher_init_cpa(
EVP_CIPHER_CTX *ctx,
const unsigned char *key,
185 const unsigned char *iv,
int enc)
198 int gost_cipher_init(
EVP_CIPHER_CTX *ctx,
const unsigned char *key,
199 const unsigned char *iv,
int enc)
206 static void gost_crypt_mesh (
void *ctx,
unsigned char *iv,
unsigned char *buf)
217 static void gost_cnt_next (
void *ctx,
unsigned char *iv,
unsigned char *buf)
221 unsigned char buf1[8];
234 g = buf1[0]|(buf1[1]<<8)|(buf1[2]<<16)|(buf1[3]<<24);
236 buf1[0]=(
unsigned char)(g&0xff);
237 buf1[1]=(
unsigned char)((g>>8)&0xff);
238 buf1[2]=(
unsigned char)((g>>16)&0xff);
239 buf1[3]=(
unsigned char)((g>>24)&0xff);
240 g = buf1[4]|(buf1[5]<<8)|(buf1[6]<<16)|(buf1[7]<<24);
245 buf1[4]=(
unsigned char)(g&0xff);
246 buf1[5]=(
unsigned char)((g>>8)&0xff);
247 buf1[6]=(
unsigned char)((g>>16)&0xff);
248 buf1[7]=(
unsigned char)((g>>24)&0xff);
256 const unsigned char *in,
size_t inl)
258 const unsigned char *in_ptr=in;
259 unsigned char *out_ptr=out;
265 for (j=ctx->
num,i=0;j<8 && i<inl;j++,i++,in_ptr++,out_ptr++)
268 *out_ptr=ctx->
buf[j]^(*in_ptr);
273 memcpy(ctx->
iv,ctx->
buf+8,8);
283 for (;i+8<inl;i+=8,in_ptr+=8,out_ptr+=8)
289 if (!ctx->
encrypt) memcpy(ctx->
iv,in_ptr,8);
292 out_ptr[j]=ctx->
buf[j]^in_ptr[j];
296 if (ctx->
encrypt) memcpy(ctx->
iv,out_ptr,8);
302 if (!ctx->
encrypt) memcpy(ctx->
buf+8,in_ptr,inl-i);
303 for (j=0;i<inl;j++,i++)
305 out_ptr[j]=ctx->
buf[j]^in_ptr[j];
308 if (ctx->
encrypt) memcpy(ctx->
buf+8,out_ptr,j);
317 static int gost_cipher_do_cnt(
EVP_CIPHER_CTX *ctx,
unsigned char *out,
318 const unsigned char *in,
size_t inl)
320 const unsigned char *in_ptr=in;
321 unsigned char *out_ptr=out;
327 for (j=ctx->
num,i=0;j<8 && i<inl;j++,i++,in_ptr++,out_ptr++)
329 *out_ptr=ctx->
buf[j]^(*in_ptr);
342 for (;i+8<inl;i+=8,in_ptr+=8,out_ptr+=8)
351 out_ptr[j]=ctx->
buf[j]^in_ptr[j];
358 for (j=0;i<inl;j++,i++)
360 out_ptr[j]=ctx->
buf[j]^in_ptr[j];
380 int gost_cipher_ctl(
EVP_CIPHER_CTX *ctx,
int type,
int arg,
void *ptr)
412 unsigned char *buf=NULL;
413 unsigned char *
p=NULL;
424 GOST_CIPHER_PARAMS_free(gcp);
431 len = i2d_GOST_CIPHER_PARAMS(gcp, NULL);
435 GOST_CIPHER_PARAMS_free(gcp);
439 i2d_GOST_CIPHER_PARAMS(gcp, &p);
440 GOST_CIPHER_PARAMS_free(gcp);
442 os = ASN1_OCTET_STRING_new();
471 gcp = d2i_GOST_CIPHER_PARAMS(NULL, (
const unsigned char **)&p,
477 GOST_CIPHER_PARAMS_free(gcp);
484 GOST_CIPHER_PARAMS_free(gcp);
489 GOST_CIPHER_PARAMS_free(gcp);
522 int gost_imit_update(
EVP_MD_CTX *ctx,
const void *data,
size_t count)
525 const unsigned char *p =
data;
533 for (i=c->
bytes_left;i<8&&bytes>0;bytes--,i++,p++)
561 int gost_imit_final(
EVP_MD_CTX *ctx,
unsigned char *md)
581 int gost_imit_ctrl(
EVP_MD_CTX *ctx,
int type,
int arg,
void *ptr)
586 *((
unsigned int*)(ptr)) = 32;