-/* $OpenBSD: e_bf.c,v 1.9 2022/09/03 19:43:16 jsing Exp $ */
+/* $OpenBSD: e_bf.c,v 1.10 2022/09/04 13:17:18 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#include "evp_locl.h"
-static int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc);
-
typedef struct {
BF_KEY ks;
} EVP_BF_KEY;
#define data(ctx) ((EVP_BF_KEY *)(ctx)->cipher_data)
+static int
+bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+ const unsigned char *iv, int enc)
+{
+ BF_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key);
+ return 1;
+}
+
static int
bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
{
{
return &bf_ecb;
}
-
-
-static int
-bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc)
-{
- BF_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key);
- return 1;
-}
#endif
-/* $OpenBSD: e_camellia.c,v 1.11 2022/09/04 07:54:59 jsing Exp $ */
+/* $OpenBSD: e_camellia.c,v 1.12 2022/09/04 13:17:18 jsing Exp $ */
/* ====================================================================
* Copyright (c) 2006 The OpenSSL Project. All rights reserved.
*
#include "evp_locl.h"
-static int camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc);
-
/* Camellia subkey Structure */
typedef struct {
CAMELLIA_KEY ks;
/* Attribute operation for Camellia */
#define data(ctx) ((EVP_CAMELLIA_KEY *)(ctx)->cipher_data)
+static int
+camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+ const unsigned char *iv, int enc)
+{
+ int ret;
+
+ ret = Camellia_set_key(key, ctx->key_len * 8, ctx->cipher_data);
+
+ if (ret < 0) {
+ EVPerror(EVP_R_CAMELLIA_KEY_SETUP_FAILED);
+ return 0;
+ }
+
+ return 1;
+}
+
static int
camellia_128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
{
{
return &camellia_256_cfb8;
}
-
-/* The subkey for Camellia is generated. */
-static int
-camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc)
-{
- int ret;
-
- ret = Camellia_set_key(key, ctx->key_len * 8, ctx->cipher_data);
-
- if (ret < 0) {
- EVPerror(EVP_R_CAMELLIA_KEY_SETUP_FAILED);
- return 0;
- }
-
- return 1;
-}
#endif
-/* $OpenBSD: e_cast.c,v 1.8 2022/09/03 19:51:53 jsing Exp $ */
+/* $OpenBSD: e_cast.c,v 1.9 2022/09/04 13:17:18 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#include "evp_locl.h"
-static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc);
-
typedef struct {
CAST_KEY ks;
} EVP_CAST_KEY;
#define data(ctx) ((EVP_CAST_KEY *)(ctx)->cipher_data)
+static int
+cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+ const unsigned char *iv, int enc)
+{
+ CAST_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key);
+ return 1;
+}
+
static int
cast5_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl)
{
{
return &cast5_ecb;
}
-
-static int
-cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc)
-{
- CAST_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key);
- return 1;
-}
#endif
-/* $OpenBSD: e_des.c,v 1.16 2022/09/04 08:18:07 jsing Exp $ */
+/* $OpenBSD: e_des.c,v 1.17 2022/09/04 13:17:18 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#include "evp_locl.h"
-static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc);
-static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
+static int
+des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+ const unsigned char *iv, int enc)
+{
+ DES_cblock *deskey = (DES_cblock *)key;
+
+ DES_set_key_unchecked(deskey, ctx->cipher_data);
+ return 1;
+}
+
+static int
+des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
+{
+ switch (type) {
+ case EVP_CTRL_RAND_KEY:
+ if (DES_random_key((DES_cblock *)ptr) == 0)
+ return 0;
+ return 1;
+
+ default:
+ return -1;
+ }
+}
static int
des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
return &des_ecb;
}
-
static const EVP_CIPHER des_cfb1 = {
.nid = NID_des_cfb1,
.block_size = 1,
return &des_cfb1;
}
-
static const EVP_CIPHER des_cfb8 = {
.nid = NID_des_cfb8,
.block_size = 1,
{
return &des_cfb8;
}
-
-
-static int
-des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc)
-{
- DES_cblock *deskey = (DES_cblock *)key;
-
- DES_set_key_unchecked(deskey, ctx->cipher_data);
- return 1;
-}
-
-static int
-des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
-{
- switch (type) {
- case EVP_CTRL_RAND_KEY:
- if (DES_random_key((DES_cblock *)ptr) == 0)
- return 0;
- return 1;
-
- default:
- return -1;
- }
-}
-
#endif
-/* $OpenBSD: e_des3.c,v 1.22 2022/09/04 08:54:16 jsing Exp $ */
+/* $OpenBSD: e_des3.c,v 1.23 2022/09/04 13:17:18 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#include "evp_locl.h"
-static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc);
-
-static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc);
-
-static int des3_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
-
typedef struct {
DES_key_schedule ks1;/* key schedule */
DES_key_schedule ks2;/* key schedule (for ede) */
#define data(ctx) ((DES_EDE_KEY *)(ctx)->cipher_data)
+static int
+des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+ const unsigned char *iv, int enc)
+{
+ DES_cblock *deskey = (DES_cblock *)key;
+
+ DES_set_key_unchecked(&deskey[0], &data(ctx)->ks1);
+ DES_set_key_unchecked(&deskey[1], &data(ctx)->ks2);
+ memcpy(&data(ctx)->ks3, &data(ctx)->ks1,
+ sizeof(data(ctx)->ks1));
+ return 1;
+}
+
+static int
+des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+ const unsigned char *iv, int enc)
+{
+ DES_cblock *deskey = (DES_cblock *)key;
+
+
+ DES_set_key_unchecked(&deskey[0], &data(ctx)->ks1);
+ DES_set_key_unchecked(&deskey[1], &data(ctx)->ks2);
+ DES_set_key_unchecked(&deskey[2], &data(ctx)->ks3);
+ return 1;
+}
+
+static int
+des3_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
+{
+ DES_cblock *deskey = ptr;
+
+ switch (type) {
+ case EVP_CTRL_RAND_KEY:
+ if (DES_random_key(deskey) == 0)
+ return 0;
+ if (c->key_len >= 16 && DES_random_key(deskey + 1) == 0)
+ return 0;
+ if (c->key_len >= 24 && DES_random_key(deskey + 2) == 0)
+ return 0;
+ return 1;
+
+ default:
+ return -1;
+ }
+}
+
static int
des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t inl)
return &des_ede3_cfb8;
}
-
-static int
-des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc)
-{
- DES_cblock *deskey = (DES_cblock *)key;
-
- DES_set_key_unchecked(&deskey[0], &data(ctx)->ks1);
- DES_set_key_unchecked(&deskey[1], &data(ctx)->ks2);
- memcpy(&data(ctx)->ks3, &data(ctx)->ks1,
- sizeof(data(ctx)->ks1));
- return 1;
-}
-
-static int
-des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc)
-{
- DES_cblock *deskey = (DES_cblock *)key;
-
-
- DES_set_key_unchecked(&deskey[0], &data(ctx)->ks1);
- DES_set_key_unchecked(&deskey[1], &data(ctx)->ks2);
- DES_set_key_unchecked(&deskey[2], &data(ctx)->ks3);
- return 1;
-}
-
-static int
-des3_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
-{
- DES_cblock *deskey = ptr;
-
- switch (type) {
- case EVP_CTRL_RAND_KEY:
- if (DES_random_key(deskey) == 0)
- return 0;
- if (c->key_len >= 16 && DES_random_key(deskey + 1) == 0)
- return 0;
- if (c->key_len >= 24 && DES_random_key(deskey + 2) == 0)
- return 0;
- return 1;
-
- default:
- return -1;
- }
-}
-
const EVP_CIPHER *
EVP_des_ede(void)
{
-/* $OpenBSD: e_gost2814789.c,v 1.6 2022/09/04 09:48:23 jsing Exp $ */
+/* $OpenBSD: e_gost2814789.c,v 1.7 2022/09/04 13:17:18 jsing Exp $ */
/*
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Copyright (c) 2005-2006 Cryptocom LTD
int param_nid;
} EVP_GOST2814789_CTX;
+static int
+gost2814789_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+ const unsigned char *iv, int enc)
+{
+ EVP_GOST2814789_CTX *c = ctx->cipher_data;
+
+ return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8);
+}
+
static int
gost2814789_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
{
}
}
-static int
-gost2814789_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc)
-{
- EVP_GOST2814789_CTX *c = ctx->cipher_data;
-
- return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8);
-}
-
int
gost2814789_set_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
{
return 1;
}
-
static int
gost2814789_cnt_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t inl)
{
return &gost2814789_cnt;
}
-
#endif
-/* $OpenBSD: e_idea.c,v 1.12 2022/09/04 08:57:32 jsing Exp $ */
+/* $OpenBSD: e_idea.c,v 1.13 2022/09/04 13:17:18 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#include "evp_locl.h"
-static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc);
-
/* NB idea_ecb_encrypt doesn't take an 'encrypt' argument so we treat it as a special
* case
*/
+static int
+idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+ const unsigned char *iv, int enc)
+{
+ if (!enc) {
+ if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_OFB_MODE)
+ enc = 1;
+ else if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB_MODE)
+ enc = 1;
+ }
+ if (enc)
+ idea_set_encrypt_key(key, ctx->cipher_data);
+ else {
+ IDEA_KEY_SCHEDULE tmp;
+
+ idea_set_encrypt_key(key, &tmp);
+ idea_set_decrypt_key(&tmp, ctx->cipher_data);
+ explicit_bzero((unsigned char *)&tmp,
+ sizeof(IDEA_KEY_SCHEDULE));
+ }
+ return 1;
+}
+
static int
idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t inl)
{
return &idea_ecb;
}
-
-
-static int
-idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc)
-{
- if (!enc) {
- if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_OFB_MODE)
- enc = 1;
- else if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB_MODE)
- enc = 1;
- }
- if (enc)
- idea_set_encrypt_key(key, ctx->cipher_data);
- else {
- IDEA_KEY_SCHEDULE tmp;
-
- idea_set_encrypt_key(key, &tmp);
- idea_set_decrypt_key(&tmp, ctx->cipher_data);
- explicit_bzero((unsigned char *)&tmp,
- sizeof(IDEA_KEY_SCHEDULE));
- }
- return 1;
-}
-
#endif
-/* $OpenBSD: e_sm4.c,v 1.2 2022/09/03 20:02:17 jsing Exp $ */
+/* $OpenBSD: e_sm4.c,v 1.3 2022/09/04 13:17:18 jsing Exp $ */
/*
* Copyright (c) 2017, 2019 Ribose Inc
*
{
return &sm4_ctr_mode;
}
-
#endif