diff options
| author | miod <> | 2014-11-09 23:06:52 +0000 |
|---|---|---|
| committer | miod <> | 2014-11-09 23:06:52 +0000 |
| commit | b6d8b8dcb0f5eb1f67698fd5bcb64941d16bfd9a (patch) | |
| tree | b5ab6541799b27d966cb82da9df9e0fb55b9236b /src/lib/libcrypto/evp | |
| parent | 0f21158a0ba59dad2c09ecb37433e5e76240a822 (diff) | |
| download | openbsd-b6d8b8dcb0f5eb1f67698fd5bcb64941d16bfd9a.tar.gz openbsd-b6d8b8dcb0f5eb1f67698fd5bcb64941d16bfd9a.tar.bz2 openbsd-b6d8b8dcb0f5eb1f67698fd5bcb64941d16bfd9a.zip | |
KNF (when not conflicting with other cleanup changes in progress)
Diffstat (limited to 'src/lib/libcrypto/evp')
| -rw-r--r-- | src/lib/libcrypto/evp/e_gost2814789.c | 28 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/m_gost2814789.c | 25 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/m_gostr341194.c | 20 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/m_streebog.c | 32 |
4 files changed, 61 insertions, 44 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 | ||
| 66 | static int gost2814789_ctl(EVP_CIPHER_CTX *ctx,int type,int arg,void *ptr) | 66 | static int |
| 67 | gost2814789_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 | ||
| 140 | int gost2814789_get_asn1_params(EVP_CIPHER_CTX * ctx, ASN1_TYPE * params) | 141 | int |
| 142 | gost2814789_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) | |||
| 179 | BLOCK_CIPHER_func_ecb(gost2814789, Gost2814789, EVP_GOST2814789_CTX, ks) | 180 | BLOCK_CIPHER_func_ecb(gost2814789, Gost2814789, EVP_GOST2814789_CTX, ks) |
| 180 | BLOCK_CIPHER_func_cfb(gost2814789, Gost2814789, 64, EVP_GOST2814789_CTX, ks) | 181 | BLOCK_CIPHER_func_cfb(gost2814789, Gost2814789, 64, EVP_GOST2814789_CTX, ks) |
| 181 | 182 | ||
| 182 | static int gost2814789_cnt_cipher(EVP_CIPHER_CTX * ctx, unsigned char *out, | 183 | static int |
| 183 | const unsigned char *in, size_t inl) | 184 | gost2814789_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 | ||
diff --git a/src/lib/libcrypto/evp/m_gost2814789.c b/src/lib/libcrypto/evp/m_gost2814789.c index ff3f489e46..279af872e0 100644 --- a/src/lib/libcrypto/evp/m_gost2814789.c +++ b/src/lib/libcrypto/evp/m_gost2814789.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: m_gost2814789.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | 1 | /* $OpenBSD: m_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 |
| @@ -56,22 +56,27 @@ | |||
| 56 | #include <openssl/gost.h> | 56 | #include <openssl/gost.h> |
| 57 | #include <openssl/objects.h> | 57 | #include <openssl/objects.h> |
| 58 | 58 | ||
| 59 | static int init(EVP_MD_CTX *ctx) | 59 | static int |
| 60 | gost2814789_init(EVP_MD_CTX *ctx) | ||
| 60 | { | 61 | { |
| 61 | return GOST2814789IMIT_Init(ctx->md_data, NID_id_Gost28147_89_CryptoPro_A_ParamSet); | 62 | return GOST2814789IMIT_Init(ctx->md_data, |
| 63 | NID_id_Gost28147_89_CryptoPro_A_ParamSet); | ||
| 62 | } | 64 | } |
| 63 | 65 | ||
| 64 | static int update(EVP_MD_CTX *ctx, const void *data, size_t count) | 66 | static int |
| 67 | gost2814789_update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
| 65 | { | 68 | { |
| 66 | return GOST2814789IMIT_Update(ctx->md_data, data, count); | 69 | return GOST2814789IMIT_Update(ctx->md_data, data, count); |
| 67 | } | 70 | } |
| 68 | 71 | ||
| 69 | static int final(EVP_MD_CTX *ctx, unsigned char *md) | 72 | static int |
| 73 | gost2814789_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 70 | { | 74 | { |
| 71 | return GOST2814789IMIT_Final(md, ctx->md_data); | 75 | return GOST2814789IMIT_Final(md, ctx->md_data); |
| 72 | } | 76 | } |
| 73 | 77 | ||
| 74 | static int md_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2) | 78 | static int |
| 79 | gost2814789_md_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2) | ||
| 75 | { | 80 | { |
| 76 | GOST2814789IMIT_CTX *gctx = ctx->md_data; | 81 | GOST2814789IMIT_CTX *gctx = ctx->md_data; |
| 77 | 82 | ||
| @@ -89,12 +94,12 @@ static const EVP_MD gost2814789imit_md = { | |||
| 89 | .pkey_type = NID_undef, | 94 | .pkey_type = NID_undef, |
| 90 | .md_size = GOST2814789IMIT_LENGTH, | 95 | .md_size = GOST2814789IMIT_LENGTH, |
| 91 | .flags = 0, | 96 | .flags = 0, |
| 92 | .init = init, | 97 | .init = gost2814789_init, |
| 93 | .update = update, | 98 | .update = gost2814789_update, |
| 94 | .final = final, | 99 | .final = gost2814789_final, |
| 95 | .block_size = GOST2814789IMIT_CBLOCK, | 100 | .block_size = GOST2814789IMIT_CBLOCK, |
| 96 | .ctx_size = sizeof(EVP_MD *) + sizeof(GOST2814789IMIT_CTX), | 101 | .ctx_size = sizeof(EVP_MD *) + sizeof(GOST2814789IMIT_CTX), |
| 97 | .md_ctrl = md_ctrl, | 102 | .md_ctrl = gost2814789_md_ctrl, |
| 98 | }; | 103 | }; |
| 99 | 104 | ||
| 100 | const EVP_MD * | 105 | const EVP_MD * |
diff --git a/src/lib/libcrypto/evp/m_gostr341194.c b/src/lib/libcrypto/evp/m_gostr341194.c index 380d92d508..66d9b4f303 100644 --- a/src/lib/libcrypto/evp/m_gostr341194.c +++ b/src/lib/libcrypto/evp/m_gostr341194.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: m_gostr341194.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | 1 | /* $OpenBSD: m_gostr341194.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 |
| @@ -58,17 +58,21 @@ | |||
| 58 | #include <openssl/gost.h> | 58 | #include <openssl/gost.h> |
| 59 | #include <openssl/objects.h> | 59 | #include <openssl/objects.h> |
| 60 | 60 | ||
| 61 | static int init(EVP_MD_CTX *ctx) | 61 | static int |
| 62 | gostr341194_init(EVP_MD_CTX *ctx) | ||
| 62 | { | 63 | { |
| 63 | return GOSTR341194_Init(ctx->md_data, NID_id_GostR3411_94_CryptoProParamSet); | 64 | return GOSTR341194_Init(ctx->md_data, |
| 65 | NID_id_GostR3411_94_CryptoProParamSet); | ||
| 64 | } | 66 | } |
| 65 | 67 | ||
| 66 | static int update(EVP_MD_CTX *ctx, const void *data, size_t count) | 68 | static int |
| 69 | gostr341194_update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
| 67 | { | 70 | { |
| 68 | return GOSTR341194_Update(ctx->md_data, data, count); | 71 | return GOSTR341194_Update(ctx->md_data, data, count); |
| 69 | } | 72 | } |
| 70 | 73 | ||
| 71 | static int final(EVP_MD_CTX *ctx, unsigned char *md) | 74 | static int |
| 75 | gostr341194_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 72 | { | 76 | { |
| 73 | return GOSTR341194_Final(md, ctx->md_data); | 77 | return GOSTR341194_Final(md, ctx->md_data); |
| 74 | } | 78 | } |
| @@ -78,9 +82,9 @@ static const EVP_MD gostr341194_md = { | |||
| 78 | .pkey_type = NID_undef, | 82 | .pkey_type = NID_undef, |
| 79 | .md_size = GOSTR341194_LENGTH, | 83 | .md_size = GOSTR341194_LENGTH, |
| 80 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, | 84 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, |
| 81 | .init = init, | 85 | .init = gostr341194_init, |
| 82 | .update = update, | 86 | .update = gostr341194_update, |
| 83 | .final = final, | 87 | .final = gostr341194_final, |
| 84 | .block_size = GOSTR341194_CBLOCK, | 88 | .block_size = GOSTR341194_CBLOCK, |
| 85 | .ctx_size = sizeof(EVP_MD *) + sizeof(GOSTR341194_CTX), | 89 | .ctx_size = sizeof(EVP_MD *) + sizeof(GOSTR341194_CTX), |
| 86 | }; | 90 | }; |
diff --git a/src/lib/libcrypto/evp/m_streebog.c b/src/lib/libcrypto/evp/m_streebog.c index cf4b159f43..882c7852bb 100644 --- a/src/lib/libcrypto/evp/m_streebog.c +++ b/src/lib/libcrypto/evp/m_streebog.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: m_streebog.c,v 1.1 2014/11/09 19:17:13 miod Exp $ */ | 1 | /* $OpenBSD: m_streebog.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 |
| @@ -57,32 +57,38 @@ | |||
| 57 | #include <openssl/gost.h> | 57 | #include <openssl/gost.h> |
| 58 | #include <openssl/objects.h> | 58 | #include <openssl/objects.h> |
| 59 | 59 | ||
| 60 | static int init256(EVP_MD_CTX *ctx) | 60 | static int |
| 61 | streebog_init256(EVP_MD_CTX *ctx) | ||
| 61 | { | 62 | { |
| 62 | return STREEBOG256_Init(ctx->md_data); | 63 | return STREEBOG256_Init(ctx->md_data); |
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | static int update256(EVP_MD_CTX *ctx, const void *data, size_t count) | 66 | static int |
| 67 | streebog_update256(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
| 66 | { | 68 | { |
| 67 | return STREEBOG256_Update(ctx->md_data, data, count); | 69 | return STREEBOG256_Update(ctx->md_data, data, count); |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 70 | static int final256(EVP_MD_CTX *ctx, unsigned char *md) | 72 | static int |
| 73 | streebog_final256(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 71 | { | 74 | { |
| 72 | return STREEBOG256_Final(md, ctx->md_data); | 75 | return STREEBOG256_Final(md, ctx->md_data); |
| 73 | } | 76 | } |
| 74 | 77 | ||
| 75 | static int init512(EVP_MD_CTX *ctx) | 78 | static int |
| 79 | streebog_init512(EVP_MD_CTX *ctx) | ||
| 76 | { | 80 | { |
| 77 | return STREEBOG512_Init(ctx->md_data); | 81 | return STREEBOG512_Init(ctx->md_data); |
| 78 | } | 82 | } |
| 79 | 83 | ||
| 80 | static int update512(EVP_MD_CTX *ctx, const void *data, size_t count) | 84 | static int |
| 85 | streebog_update512(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
| 81 | { | 86 | { |
| 82 | return STREEBOG512_Update(ctx->md_data, data, count); | 87 | return STREEBOG512_Update(ctx->md_data, data, count); |
| 83 | } | 88 | } |
| 84 | 89 | ||
| 85 | static int final512(EVP_MD_CTX *ctx, unsigned char *md) | 90 | static int |
| 91 | streebog_final512(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 86 | { | 92 | { |
| 87 | return STREEBOG512_Final(md, ctx->md_data); | 93 | return STREEBOG512_Final(md, ctx->md_data); |
| 88 | } | 94 | } |
| @@ -92,9 +98,9 @@ static const EVP_MD streebog256_md = { | |||
| 92 | .pkey_type = NID_undef, | 98 | .pkey_type = NID_undef, |
| 93 | .md_size = STREEBOG256_LENGTH, | 99 | .md_size = STREEBOG256_LENGTH, |
| 94 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, | 100 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, |
| 95 | .init = init256, | 101 | .init = streebog_init256, |
| 96 | .update = update256, | 102 | .update = streebog_update256, |
| 97 | .final = final256, | 103 | .final = streebog_final256, |
| 98 | .block_size = STREEBOG_CBLOCK, | 104 | .block_size = STREEBOG_CBLOCK, |
| 99 | .ctx_size = sizeof(EVP_MD *) + sizeof(STREEBOG_CTX), | 105 | .ctx_size = sizeof(EVP_MD *) + sizeof(STREEBOG_CTX), |
| 100 | }; | 106 | }; |
| @@ -104,9 +110,9 @@ static const EVP_MD streebog512_md = { | |||
| 104 | .pkey_type = NID_undef, | 110 | .pkey_type = NID_undef, |
| 105 | .md_size = STREEBOG512_LENGTH, | 111 | .md_size = STREEBOG512_LENGTH, |
| 106 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, | 112 | .flags = EVP_MD_FLAG_PKEY_METHOD_SIGNATURE, |
| 107 | .init = init512, | 113 | .init = streebog_init512, |
| 108 | .update = update512, | 114 | .update = streebog_update512, |
| 109 | .final = final512, | 115 | .final = streebog_final512, |
| 110 | .block_size = STREEBOG_CBLOCK, | 116 | .block_size = STREEBOG_CBLOCK, |
| 111 | .ctx_size = sizeof(EVP_MD *) + sizeof(STREEBOG_CTX), | 117 | .ctx_size = sizeof(EVP_MD *) + sizeof(STREEBOG_CTX), |
| 112 | }; | 118 | }; |
