From 096f193c98ffbe23686f10c834b2c42092b65954 Mon Sep 17 00:00:00 2001 From: Dmitry Belyavskiy Date: Sat, 2 Jan 2016 23:06:56 +0300 Subject: [PATCH] Formatting fix --- e_gost_err.h | 16 +++--- gost12sum.c | 33 +++++++------ gost_ameth.c | 3 +- gost_asn1.c | 71 ++++++++++++++------------- gost_crypt.c | 129 +++++++++++++++++++++++------------------------- gost_ec_keyx.c | 5 +- gost_ec_sign.c | 9 ++-- gost_eng.c | 16 +++--- gost_lcl.h | 25 +++++----- gost_md2012.c | 53 ++++++++++---------- gost_pmeth.c | 130 ++++++++++++++++++++++++------------------------- gostsum.c | 12 ++--- gostsum12.c | 2 +- 13 files changed, 247 insertions(+), 257 deletions(-) diff --git a/e_gost_err.h b/e_gost_err.h index 5a60008..c624713 100644 --- a/e_gost_err.h +++ b/e_gost_err.h @@ -53,20 +53,20 @@ */ #ifndef HEADER_GOST_ERR_H -#define HEADER_GOST_ERR_H +# define HEADER_GOST_ERR_H -#ifdef __cplusplus +# ifdef __cplusplus extern "C" { -#endif +# endif /* BEGIN ERROR CODES */ /* * The following lines are auto generated by the script mkerr.pl. Any changes * made after this point may be overwritten when the script is next run. */ -void ERR_load_GOST_strings(void); -void ERR_unload_GOST_strings(void); -void ERR_GOST_error(int function, int reason, char *file, int line); + void ERR_load_GOST_strings(void); + void ERR_unload_GOST_strings(void); + void ERR_GOST_error(int function, int reason, char *file, int line); # define GOSTerr(f,r) ERR_GOST_error((f),(r),__FILE__,__LINE__) /* Error codes for the GOST functions. */ @@ -138,7 +138,7 @@ void ERR_GOST_error(int function, int reason, char *file, int line); # define GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND 126 # define GOST_R_UNSUPPORTED_PARAMETER_SET 127 -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif diff --git a/gost12sum.c b/gost12sum.c index 71d73eb..0fdaf4f 100644 --- a/gost12sum.c +++ b/gost12sum.c @@ -14,7 +14,7 @@ #include #include #ifdef _WIN32 -#include +# include #endif #include #include "gosthash2012.h" @@ -82,9 +82,9 @@ int main(int argc, char **argv) while ((c = getopt(argc, argv, "bxlvc::")) != -1) { switch (c) { - case 'b': - open_mode = open_mode | O_BINARY; - break; + case 'b': + open_mode = open_mode | O_BINARY; + break; case 'v': verbose = 1; break; @@ -111,7 +111,8 @@ int main(int argc, char **argv) } } if (check_file) { - char inhash[MAX_HASH_SIZE+1], calcsum[MAX_HASH_SIZE+1], filename[PATH_MAX]; + char inhash[MAX_HASH_SIZE + 1], calcsum[MAX_HASH_SIZE + 1], + filename[PATH_MAX]; int failcount = 0, count = 0;; if (check_file == stdin && optind < argc) { check_file = fopen(argv[optind], "r"); @@ -124,9 +125,9 @@ int main(int argc, char **argv) count++; if (!hash_file(&ctx, filename, calcsum, open_mode)) { errors++; - continue; + continue; } - if (!strncmp(calcsum, inhash, hashsize/4+1)) { + if (!strncmp(calcsum, inhash, hashsize / 4 + 1)) { if (verbose) { fprintf(stderr, "%s\tOK\n", filename); } @@ -172,9 +173,9 @@ int main(int argc, char **argv) } else if (optind == argc) { char sum[65]; #ifdef _WIN32 - if (open_mode & O_BINARY) { - _setmode(fileno(stdin), O_BINARY); - } + if (open_mode & O_BINARY) { + _setmode(fileno(stdin), O_BINARY); + } #endif if (!hash_stream(&ctx, fileno(stdin), sum)) { perror("stdin"); @@ -213,9 +214,9 @@ int hash_file(gost_hash_ctx * ctx, char *filename, char *sum, int mode) int hash_stream(gost_hash_ctx * ctx, int fd, char *sum) { unsigned char buffer[BUF_SIZE]; - unsigned char reverted_buffer[BUF_SIZE]; + unsigned char reverted_buffer[BUF_SIZE]; ssize_t bytes; - int i,j,k; + int i, j, k; start_hash12(ctx); while ((bytes = read(fd, buffer, BUF_SIZE)) > 0) { hash12_block(ctx, reverted_buffer, bytes); @@ -233,12 +234,12 @@ int hash_stream(gost_hash_ctx * ctx, int fd, char *sum) int get_line(FILE *f, char *hash, char *filename, int verbose) { int i, len; - int hashstrlen = hashsize/4; + int hashstrlen = hashsize / 4; while (!feof(f)) { if (!fgets(filename, PATH_MAX, f)) return 0; len = strlen(filename); - if (len < hashstrlen+2) { + if (len < hashstrlen + 2) { goto nextline; } if (filename[hashstrlen] != ' ') { @@ -255,9 +256,9 @@ int get_line(FILE *f, char *hash, char *filename, int verbose) hash[hashstrlen] = 0; while (filename[--len] == '\n' || filename[len] == '\r') filename[len] = 0; - memmove(filename, filename + hashstrlen+1, len - hashstrlen +1); + memmove(filename, filename + hashstrlen + 1, len - hashstrlen + 1); return 1; - nextline: + nextline: if (verbose) printf(filename); } diff --git a/gost_ameth.c b/gost_ameth.c index ed40fd8..f967283 100644 --- a/gost_ameth.c +++ b/gost_ameth.c @@ -594,7 +594,6 @@ static int param_missing_gost_ec(const EVP_PKEY *pk) return 0; } - static int param_copy_gost_ec(EVP_PKEY *to, const EVP_PKEY *from) { EC_KEY *eto = EVP_PKEY_get0(to); @@ -772,7 +771,7 @@ static int pub_encode_gost_ec(X509_PUBKEY *pub, const EVP_PKEY *pk) ret = i2d_ASN1_OCTET_STRING(octet, &buf); ASN1_BIT_STRING_free(octet); -err: + err: if (X) BN_free(X); if (Y) diff --git a/gost_asn1.c b/gost_asn1.c index 57046a8..fb9792a 100644 --- a/gost_asn1.c +++ b/gost_asn1.c @@ -12,51 +12,52 @@ #include "gost_lcl.h" ASN1_NDEF_SEQUENCE(GOST_KEY_TRANSPORT) = { - ASN1_SIMPLE(GOST_KEY_TRANSPORT, key_info, GOST_KEY_INFO), - ASN1_IMP(GOST_KEY_TRANSPORT, key_agreement_info, GOST_KEY_AGREEMENT_INFO, 0) -} ASN1_NDEF_SEQUENCE_END(GOST_KEY_TRANSPORT) + ASN1_SIMPLE(GOST_KEY_TRANSPORT, key_info, GOST_KEY_INFO), + ASN1_IMP(GOST_KEY_TRANSPORT, key_agreement_info, + GOST_KEY_AGREEMENT_INFO, 0) +} -IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_TRANSPORT) +ASN1_NDEF_SEQUENCE_END(GOST_KEY_TRANSPORT) -ASN1_NDEF_SEQUENCE(GOST_KEY_INFO) = { - ASN1_SIMPLE(GOST_KEY_INFO, encrypted_key, ASN1_OCTET_STRING), - ASN1_SIMPLE(GOST_KEY_INFO, imit, ASN1_OCTET_STRING) -} ASN1_NDEF_SEQUENCE_END(GOST_KEY_INFO) - -IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_INFO) + IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_TRANSPORT) -ASN1_NDEF_SEQUENCE(GOST_KEY_AGREEMENT_INFO) = { - ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, cipher, ASN1_OBJECT), + ASN1_NDEF_SEQUENCE(GOST_KEY_INFO) = +{ + ASN1_SIMPLE(GOST_KEY_INFO, encrypted_key, ASN1_OCTET_STRING), + ASN1_SIMPLE(GOST_KEY_INFO, imit, ASN1_OCTET_STRING) +} ASN1_NDEF_SEQUENCE_END(GOST_KEY_INFO) + IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_INFO) + ASN1_NDEF_SEQUENCE(GOST_KEY_AGREEMENT_INFO) = +{ + ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, cipher, ASN1_OBJECT), ASN1_IMP_OPT(GOST_KEY_AGREEMENT_INFO, ephem_key, X509_PUBKEY, 0), ASN1_SIMPLE(GOST_KEY_AGREEMENT_INFO, eph_iv, ASN1_OCTET_STRING) } ASN1_NDEF_SEQUENCE_END(GOST_KEY_AGREEMENT_INFO) - -IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_AGREEMENT_INFO) - -ASN1_NDEF_SEQUENCE(GOST_KEY_PARAMS) = { - ASN1_SIMPLE(GOST_KEY_PARAMS, key_params, ASN1_OBJECT), + IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_AGREEMENT_INFO) + ASN1_NDEF_SEQUENCE(GOST_KEY_PARAMS) = +{ +ASN1_SIMPLE(GOST_KEY_PARAMS, key_params, ASN1_OBJECT), ASN1_SIMPLE(GOST_KEY_PARAMS, hash_params, ASN1_OBJECT), - ASN1_OPT(GOST_KEY_PARAMS, cipher_params, ASN1_OBJECT), -} ASN1_NDEF_SEQUENCE_END(GOST_KEY_PARAMS) - -IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_PARAMS) - -ASN1_NDEF_SEQUENCE(GOST_CIPHER_PARAMS) = { - ASN1_SIMPLE(GOST_CIPHER_PARAMS, iv, ASN1_OCTET_STRING), - ASN1_SIMPLE(GOST_CIPHER_PARAMS, enc_param_set, ASN1_OBJECT), -} ASN1_NDEF_SEQUENCE_END(GOST_CIPHER_PARAMS) - -IMPLEMENT_ASN1_FUNCTIONS(GOST_CIPHER_PARAMS) - -ASN1_NDEF_SEQUENCE(GOST_CLIENT_KEY_EXCHANGE_PARAMS) = { /* FIXME incomplete */ + ASN1_OPT(GOST_KEY_PARAMS, cipher_params, + ASN1_OBJECT),} ASN1_NDEF_SEQUENCE_END(GOST_KEY_PARAMS) + IMPLEMENT_ASN1_FUNCTIONS(GOST_KEY_PARAMS) + ASN1_NDEF_SEQUENCE(GOST_CIPHER_PARAMS) = +{ +ASN1_SIMPLE(GOST_CIPHER_PARAMS, iv, ASN1_OCTET_STRING), + ASN1_SIMPLE(GOST_CIPHER_PARAMS, enc_param_set, + ASN1_OBJECT),} +ASN1_NDEF_SEQUENCE_END(GOST_CIPHER_PARAMS) + IMPLEMENT_ASN1_FUNCTIONS(GOST_CIPHER_PARAMS) + ASN1_NDEF_SEQUENCE(GOST_CLIENT_KEY_EXCHANGE_PARAMS) = +{ /* FIXME incomplete */ ASN1_SIMPLE(GOST_CLIENT_KEY_EXCHANGE_PARAMS, gkt, GOST_KEY_TRANSPORT) } ASN1_NDEF_SEQUENCE_END(GOST_CLIENT_KEY_EXCHANGE_PARAMS) -IMPLEMENT_ASN1_FUNCTIONS(GOST_CLIENT_KEY_EXCHANGE_PARAMS) + IMPLEMENT_ASN1_FUNCTIONS(GOST_CLIENT_KEY_EXCHANGE_PARAMS) -ASN1_NDEF_SEQUENCE(MASKED_GOST_KEY) = { + ASN1_NDEF_SEQUENCE(MASKED_GOST_KEY) = +{ ASN1_SIMPLE(MASKED_GOST_KEY, masked_priv_key, ASN1_OCTET_STRING), - ASN1_SIMPLE(MASKED_GOST_KEY, public_key, ASN1_OCTET_STRING) + ASN1_SIMPLE(MASKED_GOST_KEY, public_key, ASN1_OCTET_STRING) } ASN1_NDEF_SEQUENCE_END(MASKED_GOST_KEY) - -IMPLEMENT_ASN1_FUNCTIONS(MASKED_GOST_KEY) + IMPLEMENT_ASN1_FUNCTIONS(MASKED_GOST_KEY) diff --git a/gost_crypt.c b/gost_crypt.c index 66e769d..680406f 100644 --- a/gost_crypt.c +++ b/gost_crypt.c @@ -33,8 +33,8 @@ static int gost_cipher_init_cp_12(EVP_CIPHER_CTX *ctx, static int gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl); /* Handles block of data in CBC mode */ -static int gost_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl); +static int gost_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, + const unsigned char *in, size_t inl); /* Handles block of data in CNT mode */ static int gost_cipher_do_cnt(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl); @@ -63,23 +63,22 @@ EVP_CIPHER cipher_gost = { NULL, }; -EVP_CIPHER cipher_gost_cbc = - { +EVP_CIPHER cipher_gost_cbc = { NID_gost89_cbc, - 8,/*block_size*/ - 32,/*key_size*/ - 8,/*iv_len */ - EVP_CIPH_CBC_MODE| - EVP_CIPH_CUSTOM_IV| EVP_CIPH_RAND_KEY | EVP_CIPH_ALWAYS_CALL_INIT, + 8, /*block_size */ + 32, /*key_size */ + 8, /*iv_len */ + EVP_CIPH_CBC_MODE | + EVP_CIPH_CUSTOM_IV | EVP_CIPH_RAND_KEY | EVP_CIPH_ALWAYS_CALL_INIT, gost_cipher_init_cbc, gost_cipher_do_cbc, gost_cipher_cleanup, - sizeof(struct ossl_gost_cipher_ctx),/* ctx_size */ + sizeof(struct ossl_gost_cipher_ctx), /* ctx_size */ gost89_set_asn1_parameters, gost89_get_asn1_parameters, gost_cipher_ctl, NULL, - }; +}; EVP_CIPHER cipher_gost_cpacnt = { NID_gost89_cnt, @@ -313,7 +312,6 @@ int gost_cipher_init_cbc(EVP_CIPHER_CTX *ctx, const unsigned char *key, EVP_CIPH_CBC_MODE); } - /* * Wrapper around gostcrypt function from gost89.c which perform key meshing * when nesseccary @@ -365,45 +363,40 @@ static void gost_cnt_next(void *ctx, unsigned char *iv, unsigned char *buf) /* GOST encryptoon in CBC mode */ int gost_cipher_do_cbc(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl) - { - OPENSSL_assert(inl % 8 ==0); + const unsigned char *in, size_t inl) +{ + OPENSSL_assert(inl % 8 == 0); unsigned char b[8]; - const unsigned char *in_ptr=in; - unsigned char *out_ptr=out; + const unsigned char *in_ptr = in; + unsigned char *out_ptr = out; int i; struct ossl_gost_cipher_ctx *c = ctx->cipher_data; - if (ctx->encrypt) - { - while(inl>0) - { - for (i=0;i<8;i++) - { - b[i]=ctx->iv[i]^in_ptr[i]; - } - gostcrypt(&(c->cctx),b,out_ptr); - memcpy(ctx->iv,out_ptr,8); - out_ptr+=8; - in_ptr+=8; - inl-=8; + if (ctx->encrypt) { + while (inl > 0) { + for (i = 0; i < 8; i++) { + b[i] = ctx->iv[i] ^ in_ptr[i]; } + gostcrypt(&(c->cctx), b, out_ptr); + memcpy(ctx->iv, out_ptr, 8); + out_ptr += 8; + in_ptr += 8; + inl -= 8; } - else - { - while (inl>0) { - gostdecrypt(&(c->cctx),in_ptr,b); - for (i=0;i<8;i++) - { - out_ptr[i]=ctx->iv[i]^b[i]; - } - memcpy(ctx->iv,in_ptr,8); - out_ptr+=8; - in_ptr+=8; - inl-=8; + } else { + while (inl > 0) { + gostdecrypt(&(c->cctx), in_ptr, b); + for (i = 0; i < 8; i++) { + out_ptr[i] = ctx->iv[i] ^ b[i]; } + memcpy(ctx->iv, in_ptr, 8); + out_ptr += 8; + in_ptr += 8; + inl -= 8; } - return 1; } + return 1; +} + /* GOST encryption in CFB mode */ int gost_cipher_do_cfb(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t inl) @@ -766,36 +759,36 @@ int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) return 1; case EVP_MD_CTRL_SET_KEY: { - struct ossl_gost_imit_ctx *gost_imit_ctx = ctx->md_data; + struct ossl_gost_imit_ctx *gost_imit_ctx = ctx->md_data; - if (ctx->digest->init(ctx) <= 0) { - GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_MAC_KEY_NOT_SET); - return 0; - } - ctx->flags |= EVP_MD_CTX_FLAG_NO_INIT; + if (ctx->digest->init(ctx) <= 0) { + GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_MAC_KEY_NOT_SET); + return 0; + } + ctx->flags |= EVP_MD_CTX_FLAG_NO_INIT; if (arg == 0) { - struct gost_mac_key *key = (struct gost_mac_key*) ptr; - if (key->mac_param_nid != NID_undef) { - const struct gost_cipher_info *param = get_encryption_params(OBJ_nid2obj(key->mac_param_nid)); - if (param == NULL) - { - GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_INVALID_MAC_PARAMS); - return 0; - } - gost_init(&(gost_imit_ctx->cctx), param->sblock); - } - gost_key(&(gost_imit_ctx->cctx), key->key); + struct gost_mac_key *key = (struct gost_mac_key *)ptr; + if (key->mac_param_nid != NID_undef) { + const struct gost_cipher_info *param = + get_encryption_params(OBJ_nid2obj + (key->mac_param_nid)); + if (param == NULL) { + GOSTerr(GOST_F_GOST_IMIT_CTRL, + GOST_R_INVALID_MAC_PARAMS); + return 0; + } + gost_init(&(gost_imit_ctx->cctx), param->sblock); + } + gost_key(&(gost_imit_ctx->cctx), key->key); gost_imit_ctx->key_set = 1; - return 1; + return 1; + } else if (arg == 32) { + gost_key(&(gost_imit_ctx->cctx), ptr); + gost_imit_ctx->key_set = 1; + return 1; } - else if (arg == 32) - { - gost_key(&(gost_imit_ctx->cctx), ptr); - gost_imit_ctx->key_set = 1; - return 1; - } GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_INVALID_MAC_KEY_SIZE); return 0; } @@ -806,7 +799,7 @@ int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_INVALID_MAC_SIZE); return 0; } - c->dgst_size=arg; + c->dgst_size = arg; return 1; } diff --git a/gost_ec_keyx.c b/gost_ec_keyx.c index 594329b..7043347 100644 --- a/gost_ec_keyx.c +++ b/gost_ec_keyx.c @@ -61,10 +61,11 @@ static int VKO_compute_key(unsigned char *shared_key, size_t shared_key_size, Y = BN_CTX_get(ctx); EC_GROUP_get_order(EC_KEY_get0_group(priv_key), order, ctx); BN_mod_mul(p, key, UKM, order, ctx); - if(!EC_POINT_mul(EC_KEY_get0_group(priv_key), pnt, NULL, pub_key, p, ctx)) { + if (!EC_POINT_mul + (EC_KEY_get0_group(priv_key), pnt, NULL, pub_key, p, ctx)) { GOSTerr(GOST_F_VKO_COMPUTE_KEY, GOST_R_ERROR_POINT_MUL); goto err; - } + } EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(priv_key), pnt, X, Y, ctx); /* diff --git a/gost_ec_sign.c b/gost_ec_sign.c index 9d542ce..c700ac2 100644 --- a/gost_ec_sign.c +++ b/gost_ec_sign.c @@ -137,7 +137,7 @@ int fill_GOST_EC_params(EC_KEY *eckey, int nid) goto end; } ok = 1; -end: + end: if (P) EC_POINT_free(P); if (grp) @@ -362,8 +362,7 @@ int gost_ec_verify(const unsigned char *dgst, int dgst_len, goto err; } v = BN_mod_inverse(v, e, order, ctx); - if (!v - || !BN_mod_mul(z1, sig->s, v, order, ctx) + if (!v || !BN_mod_mul(z1, sig->s, v, order, ctx) || !BN_sub(tmp, order, sig->r) || !BN_mod_mul(z2, tmp, v, order, ctx)) { GOSTerr(GOST_F_GOST_EC_VERIFY, ERR_R_INTERNAL_ERROR); @@ -513,11 +512,11 @@ int gost_ec_keygen(EC_KEY *ec) } ok = 1; -end: + end: if (d) BN_free(d); if (order) BN_free(order); - + return (ok) ? gost_ec_compute_public(ec) : 0; } diff --git a/gost_eng.c b/gost_eng.c index 88229e6..097563e 100644 --- a/gost_eng.c +++ b/gost_eng.c @@ -62,14 +62,12 @@ static int gost_pkey_meth_nids[] = { static EVP_PKEY_METHOD *pmeth_GostR3410_2001 = NULL, *pmeth_GostR3410_2012_256 = NULL, *pmeth_GostR3410_2012_512 = NULL, - *pmeth_Gost28147_MAC = NULL, - *pmeth_Gost28147_MAC_12 = NULL; + *pmeth_Gost28147_MAC = NULL, *pmeth_Gost28147_MAC_12 = NULL; static EVP_PKEY_ASN1_METHOD *ameth_GostR3410_2001 = NULL, *ameth_GostR3410_2012_256 = NULL, *ameth_GostR3410_2012_512 = NULL, - *ameth_Gost28147_MAC = NULL, - *ameth_Gost28147_MAC_12 = NULL; + *ameth_Gost28147_MAC = NULL, *ameth_Gost28147_MAC_12 = NULL; static int gost_engine_init(ENGINE *e) { @@ -215,7 +213,7 @@ static int gost_digests(ENGINE *e, const EVP_MD **digest, int ok = 1; if (!digest) { *nids = gost_digest_nids; - return sizeof(gost_digest_nids)/sizeof(gost_digest_nids[0]) - 1; + return sizeof(gost_digest_nids) / sizeof(gost_digest_nids[0]) - 1; } if (nid == NID_id_GostR3411_94) { *digest = &digest_gost; @@ -240,7 +238,7 @@ static int gost_ciphers(ENGINE *e, const EVP_CIPHER **cipher, int ok = 1; if (!cipher) { *nids = gost_cipher_nids; - return sizeof(gost_cipher_nids)/sizeof(gost_cipher_nids[0]) - 1; + return sizeof(gost_cipher_nids) / sizeof(gost_cipher_nids[0]) - 1; } if (nid == NID_id_Gost28147_89) { @@ -263,7 +261,8 @@ static int gost_pkey_meths(ENGINE *e, EVP_PKEY_METHOD **pmeth, { if (!pmeth) { *nids = gost_pkey_meth_nids; - return sizeof(gost_pkey_meth_nids)/sizeof(gost_pkey_meth_nids[0]) - 1; + return sizeof(gost_pkey_meth_nids) / sizeof(gost_pkey_meth_nids[0]) - + 1; } switch (nid) { @@ -295,7 +294,8 @@ static int gost_pkey_asn1_meths(ENGINE *e, EVP_PKEY_ASN1_METHOD **ameth, { if (!ameth) { *nids = gost_pkey_meth_nids; - return sizeof(gost_pkey_meth_nids)/sizeof(gost_pkey_meth_nids[0]) - 1; + return sizeof(gost_pkey_meth_nids) / sizeof(gost_pkey_meth_nids[0]) - + 1; } switch (nid) { case NID_id_GostR3410_2001: diff --git a/gost_lcl.h b/gost_lcl.h index 376e39c..b089eb2 100644 --- a/gost_lcl.h +++ b/gost_lcl.h @@ -36,8 +36,7 @@ typedef struct R3410_ec { } R3410_ec_params; extern R3410_ec_params R3410_2001_paramset[], - *R3410_2012_256_paramset, - R3410_2012_512_paramset[]; + *R3410_2012_256_paramset, R3410_2012_512_paramset[]; extern const ENGINE_CMD_DEFN gost_cmds[]; int gost_control_func(ENGINE *e, int cmd, long i, void *p, void (*f) (void)); @@ -72,8 +71,8 @@ struct gost_pmeth_data { struct gost_mac_pmeth_data { short int key_set; - short int mac_size; - int mac_param_nid; + short int mac_size; + int mac_param_nid; EVP_MD *md; unsigned char key[32]; }; @@ -151,14 +150,14 @@ typedef struct { DECLARE_ASN1_FUNCTIONS(MASKED_GOST_KEY) /*============== Message digest and cipher related structures ==========*/ - /* - * Structure used as EVP_MD_CTX-md_data. It allows to avoid storing - * in the md-data pointers to dynamically allocated memory. I - * cannot invent better way to avoid memory leaks, because openssl - * insist on invoking Init on Final-ed digests, and there is no - * reliable way to find out whether pointer in the passed md_data is - * valid or not. - */ + /* + * Structure used as EVP_MD_CTX-md_data. It allows to avoid storing + * in the md-data pointers to dynamically allocated memory. I + * cannot invent better way to avoid memory leaks, because openssl + * insist on invoking Init on Final-ed digests, and there is no + * reliable way to find out whether pointer in the passed md_data is + * valid or not. + */ struct ossl_gost_digest_ctx { gost_hash_ctx dctx; gost_ctx cctx; @@ -193,7 +192,7 @@ struct ossl_gost_imit_ctx { int key_meshing; int bytes_left; int key_set; - int dgst_size; + int dgst_size; }; /* Table which maps parameter NID to S-blocks */ extern struct gost_cipher_info gost_cipher_list[]; diff --git a/gost_md2012.c b/gost_md2012.c index e20e660..098208d 100644 --- a/gost_md2012.c +++ b/gost_md2012.c @@ -19,8 +19,10 @@ static int gost_digest_update(EVP_MD_CTX *ctx, const void *data, static int gost_digest_final(EVP_MD_CTX *ctx, unsigned char *md); static int gost_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from); static int gost_digest_cleanup(EVP_MD_CTX *ctx); -static int gost_digest_ctrl_256(EVP_MD_CTX *ctx, int type, int arg, void *ptr); -static int gost_digest_ctrl_512(EVP_MD_CTX *ctx, int type, int arg, void *ptr); +static int gost_digest_ctrl_256(EVP_MD_CTX *ctx, int type, int arg, + void *ptr); +static int gost_digest_ctrl_512(EVP_MD_CTX *ctx, int type, int arg, + void *ptr); const char micalg_256[] = "gostr3411-2012-256"; const char micalg_512[] = "gostr3411-2012-512"; @@ -102,41 +104,36 @@ static int gost_digest_cleanup(EVP_MD_CTX *ctx) } static int gost_digest_ctrl_256(EVP_MD_CTX *ctx, int type, int arg, void *ptr) - { - switch (type) - { +{ + switch (type) { case EVP_MD_CTRL_MICALG: - { - *((char **)ptr) = OPENSSL_malloc(strlen(micalg_256)+1); - if (*((char **)ptr) != NULL) { - strcpy(*((char **)ptr), micalg_256); - return 1; + *((char **)ptr) = OPENSSL_malloc(strlen(micalg_256) + 1); + if (*((char **)ptr) != NULL) { + strcpy(*((char **)ptr), micalg_256); + return 1; + } + return 0; } - return 0; - } default: - return 0; + return 0; } - } +} static int gost_digest_ctrl_512(EVP_MD_CTX *ctx, int type, int arg, void *ptr) - { - switch (type) - { +{ + switch (type) { case EVP_MD_CTRL_MICALG: - { - *((char **)ptr) = OPENSSL_malloc(strlen(micalg_512)+1); - if (*((char **)ptr) != NULL) { - strcpy(*((char **)ptr), micalg_512); - return 1; + *((char **)ptr) = OPENSSL_malloc(strlen(micalg_512) + 1); + if (*((char **)ptr) != NULL) { + strcpy(*((char **)ptr), micalg_512); + return 1; + } + return 0; } - return 0; - } - return 1; + return 1; default: - return 0; + return 0; } - } - +} diff --git a/gost_pmeth.c b/gost_pmeth.c index f07c4da..de35388 100644 --- a/gost_pmeth.c +++ b/gost_pmeth.c @@ -466,20 +466,20 @@ static int pkey_gost_derive_init(EVP_PKEY_CTX *ctx) static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx) { struct gost_mac_pmeth_data *data = OPENSSL_malloc(sizeof(*data)); - EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); + EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); if (!data) return 0; memset(data, 0, sizeof(*data)); - data->mac_size = 4; - data->mac_param_nid = NID_undef; + data->mac_size = 4; + data->mac_param_nid = NID_undef; - if (pkey) { - struct gost_mac_key *key = EVP_PKEY_get0(pkey); - if (key) { - data->mac_param_nid = key->mac_param_nid; - } - } + if (pkey) { + struct gost_mac_key *key = EVP_PKEY_get0(pkey); + if (key) { + data->mac_param_nid = key->mac_param_nid; + } + } EVP_PKEY_CTX_set_data(ctx, data); return 1; @@ -543,19 +543,19 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) data->key_set = 1; return 1; case EVP_PKEY_CTRL_GOST_PARAMSET: - { - struct gost_cipher_info *param = p2; - data->mac_param_nid = param->nid; - struct gost_mac_key *key = NULL; - EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); - if (pkey) { - key = EVP_PKEY_get0(pkey); - if (key) { - key->mac_param_nid = param->nid; - } - } - return 1; - } + { + struct gost_cipher_info *param = p2; + data->mac_param_nid = param->nid; + struct gost_mac_key *key = NULL; + EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); + if (pkey) { + key = EVP_PKEY_get0(pkey); + if (key) { + key->mac_param_nid = param->nid; + } + } + return 1; + } case EVP_PKEY_CTRL_DIGESTINIT: { EVP_MD_CTX *mctx = p2; @@ -573,23 +573,24 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) GOST_R_MAC_KEY_NOT_SET); return 0; } - return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 0, key); + return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 0, + key); } else { - return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32, &(data->key)); + return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32, + &(data->key)); } return mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_SET_KEY, 32, key); } - case EVP_PKEY_CTRL_MAC_LEN: - { - if (p1<1 || p1>8) - { - - GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL,GOST_R_INVALID_MAC_SIZE); - return 0; - } - data->mac_size = p1; - return 1; - } + case EVP_PKEY_CTRL_MAC_LEN: + { + if (p1 < 1 || p1 > 8) { + + GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_SIZE); + return 0; + } + data->mac_size = p1; + return 1; + } } return -2; } @@ -621,33 +622,32 @@ static int pkey_gost_mac_ctrl_str(EVP_PKEY_CTX *ctx, return ret; } - if (!strcmp(type,maclen_ctrl_string)) { - char *endptr; - long size=strtol(value,&endptr,10); - if (*endptr!='\0') { - GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, - GOST_R_INVALID_MAC_SIZE); - return 0; - } - return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_MAC_LEN,size,NULL); - } - if (strcmp(type, param_ctrl_string) == 0) - { - ASN1_OBJECT *obj = OBJ_txt2obj(value, 0); - const struct gost_cipher_info *param = NULL; - if (obj == NULL) { - GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_PARAMS); - return 0; - } - - param = get_encryption_params(obj); - if (param == NULL) { - GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_PARAMS); - return 0; - } - - return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET, 0, (void *)param); - } + if (!strcmp(type, maclen_ctrl_string)) { + char *endptr; + long size = strtol(value, &endptr, 10); + if (*endptr != '\0') { + GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_SIZE); + return 0; + } + return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_MAC_LEN, size, NULL); + } + if (strcmp(type, param_ctrl_string) == 0) { + ASN1_OBJECT *obj = OBJ_txt2obj(value, 0); + const struct gost_cipher_info *param = NULL; + if (obj == NULL) { + GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_PARAMS); + return 0; + } + + param = get_encryption_params(obj); + if (param == NULL) { + GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL_STR, GOST_R_INVALID_MAC_PARAMS); + return 0; + } + + return pkey_gost_mac_ctrl(ctx, EVP_PKEY_CTRL_GOST_PARAMSET, 0, + (void *)param); + } return -2; } @@ -664,7 +664,7 @@ static int pkey_gost_mac_keygen_base(EVP_PKEY_CTX *ctx, if (keydata == NULL) return 0; memcpy(keydata->key, data->key, 32); - keydata->mac_param_nid = data->mac_param_nid; + keydata->mac_param_nid = data->mac_param_nid; EVP_PKEY_assign(pkey, mac_nid, keydata); return 1; } @@ -689,7 +689,7 @@ static int pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, { unsigned int tmpsiglen; int ret; - struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); + struct gost_mac_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); if (!siglen) return 0; @@ -701,7 +701,7 @@ static int pkey_gost_mac_signctx(EVP_PKEY_CTX *ctx, unsigned char *sig, return 1; } - mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_MAC_LEN, data->mac_size, NULL); + mctx->digest->md_ctrl(mctx, EVP_MD_CTRL_MAC_LEN, data->mac_size, NULL); ret = EVP_DigestFinal_ex(mctx, sig, &tmpsiglen); *siglen = data->mac_size; return ret; diff --git a/gostsum.c b/gostsum.c index 02d5688..aed2a47 100644 --- a/gostsum.c +++ b/gostsum.c @@ -88,8 +88,8 @@ int main(int argc, char **argv) while (get_line(check_file, inhash, filename)) { count++; if (!hash_file(&ctx, filename, calcsum, open_mode)) { - errors ++; - continue; + errors++; + continue; } if (strncmp(calcsum, inhash, 65) == 0) { if (verbose) { @@ -117,14 +117,14 @@ int main(int argc, char **argv) "%s: %d of %d file(f) failed GOST hash sum check\n", argv[0], failcount, count); } - exit((failcount || errors)? 1 : 0); + exit((failcount || errors) ? 1 : 0); } if (optind == argc) { char sum[65]; #ifdef _WIN32 - if (open_mode & O_BINARY) { - _setmode(fileno(stdin),O_BINARY); - } + if (open_mode & O_BINARY) { + _setmode(fileno(stdin), O_BINARY); + } #endif if (!hash_stream(&ctx, fileno(stdin), sum)) { perror("stdin"); diff --git a/gostsum12.c b/gostsum12.c index 3fc5e1a..9eab476 100644 --- a/gostsum12.c +++ b/gostsum12.c @@ -249,7 +249,7 @@ int get_line(FILE *f, char *hash, char *filename, int verbose) filename[len] = 0; memmove(filename, filename + 65, len - 63); return 1; - nextline: + nextline: if (verbose) printf(filename); } -- 2.39.5